← Commit list

6d07432b2

Glenn L McGrath
Glenn L McGrath
2002-12-12
SOURCE BUG Duration: 6s

Subject

Support the o, f and p options, patch by Magnus M�rtensson

SOURCE BUG

This commit was genuinely broken at the time (not related to our build system): sysdeps/linux/Config.in "fileutils/Config.in" dosyasini kaynak gosteriyor ama bu dosya repoda hic var olmadi (2002-12-05 - 2003-02-15 arasi orijinal yazar hatasi, 3238ea167 ile duzeltildi)

→ Bu hatanin tam hikayesini ve duzeltme diffini gor

Binary

No binary (build failed)

Architecture & Compiler Flags

Architecture: x86_64-linux-gnu Compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0

—

Build Log

(log yok)

Commit Diff GitHub →

include/usage.h+6 -1
@@ -245,7 +245,12 @@
#define dc_full_usage \
"This is a Tiny RPN calculator that understands the\n" \
"following operations: +, -, /, *, and, or, not, eor.\n" \
- "i.e., 'dc 2 2 add' -> 4, and 'dc 8 8 \\* 2 2 + /' -> 16"
+ "i.e., 'dc 2 2 add' -> 4, and 'dc 8 8 \\* 2 2 + /' -> 16" \
+ "p - Prints the value on the top of the stack, without altering the stack.\n" \
+ "f - Prints the entire contents of the stack without altering anything.\n" \
+ "o - Pops the value off the top of the stack and uses it to set the output radix.\n" \
+ " Only 10 and 16 are supported.\n"
+
#define dc_example_usage \
"$ dc 2 2 +\n" \
"4\n" \
miscutils/dc.c+34 -1
@@ -11,6 +11,7 @@
static double stack[100];
static unsigned int pointer;
+static unsigned char base;
static void push(double a)
{
@@ -70,9 +71,38 @@ static void not(void)
push(~(unsigned int) pop());
}
+static void set_output_base(void)
+{
+ base=(unsigned char)pop();
+ if ((base != 10) && (base != 16)) {
+ fprintf(stderr, "Error: base = %d is not supported.\n", base);
+ base=10;
+ }
+}
+
+static void print_base(double print)
+{
+ if (base == 16)
+ printf("%x\n", (unsigned int)print);
+ else
+ printf("%g\n", print);
+}
+
+static void print_stack_no_pop(void)
+{
+ unsigned int i=pointer;
+ while (i)
+ print_base(stack[--i]);
+}
+
+static void print_no_pop(void)
+{
+ print_base(stack[pointer-1]);
+}
+
static void print(void)
{
- printf("%g\n", pop());
+ print_base(pop());
}
struct op {
@@ -93,6 +123,9 @@ static const struct op operators[] = {
{"or", or},
{"not", not},
{"eor", eor},
+ {"p", print_no_pop},
+ {"f", print_stack_no_pop},
+ {"o", set_output_base},
{0, 0}
};