[BusyBox-cvs] busybox/miscutils dc.c,1.13,1.14
Glenn McGrath
bug1 at busybox.net
Thu Dec 12 10:31:57 UTC 2002
Update of /var/cvs/busybox/miscutils
In directory winder:/tmp/cvs-serv5674/miscutils
Modified Files:
dc.c
Log Message:
Support the o, f and p options, patch by Magnus Mårtensson
Index: dc.c
===================================================================
RCS file: /var/cvs/busybox/miscutils/dc.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- dc.c 6 Dec 2001 03:29:37 -0000 1.13
+++ dc.c 12 Dec 2002 10:31:53 -0000 1.14
@@ -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 @@
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 @@
{"or", or},
{"not", not},
{"eor", eor},
+ {"p", print_no_pop},
+ {"f", print_stack_no_pop},
+ {"o", set_output_base},
{0, 0}
};
More information about the busybox-cvs
mailing list