[BusyBox] small fix and feature patch to busybox-1.00-pre3's dc

Goetz Bock bock at blacknet.de
Thu Oct 9 16:41:42 UTC 2003


Dear list,

during my quest do pack busybox into an RPM, I've fixed a small bug
(missing \n) in dc's usage. And added two additional operations: mod and
exp/power.

Feel free to drop them.
-- 
/"\ Goetz Bock at blacknet dot de  --  secure mobile Linux everNETting
\ /                     (c) 2003 as GNU FDL 1.1
 X   [ 1. Use descriptive subjects - 2. Edit a reply for brevity -  ]
/ \  [ 3. Reply to the list - 4. Read the archive *before* you post ]
-------------- next part --------------
--- busybox-1.00-pre3/include/usage.h	2003-08-29 16:18:26.000000000 +0200
+++ busybox-1.00-pre3.bn/include/usage.h	2003-10-09 18:25:29.000000000 +0200
@@ -280,8 +280,8 @@
 	"expression ..."
 #define dc_full_usage \
 	"This is a Tiny RPN calculator that understands the\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.\n" \
 	"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" \
-------------- next part --------------
--- busybox-1.00-pre3/include/usage.h	2003-08-29 16:18:26.000000000 +0200
+++ busybox-1.00-pre3.bn/include/usage.h	2003-10-09 18:25:29.000000000 +0200
@@ -280,8 +280,8 @@
 	"expression ..."
 #define dc_full_usage \
 	"This is a Tiny RPN calculator that understands the\n" \
-	"following operations: +, -, /, *, and, or, not, eor.\n" \
+	"following operations: +, add, -, sub, *, mul, /, div, %, mod, **, exp, and, or, not, eor.\n" \
 	"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" \
--- busybox-1.00-pre3/miscutils/dc.c	2003-08-29 00:12:53.000000000 +0200
+++ busybox-1.00-pre3.bn/miscutils/dc.c	2003-10-09 18:30:53.000000000 +0200
@@ -44,6 +44,13 @@
 	push(pop() * pop());
 }
 
+static void power(void)
+{
+	double topower = pop();
+
+	push(pow(pop(), topower));
+}
+
 static void divide(void)
 {
 	double divisor = pop();
@@ -51,6 +58,13 @@
 	push(pop() / divisor);
 }
 
+static void mod(void)
+{
+	unsigned int d = pop();
+
+	push((unsigned int) pop() % d);
+}
+
 static void and(void)
 {
 	push((unsigned int) pop() & (unsigned int) pop());
@@ -119,10 +133,16 @@
 	{"mul", mul},
 	{"/",   divide},
 	{"div", divide},
+	{"**",  power},
+	{"exp", power},
+	{"pow", power},
+	{"%",   mod},
+	{"mod", mod},
 	{"and", and},
 	{"or",  or},
 	{"not", not},
 	{"eor", eor},
+	{"xor", eor},
 	{"p", print_no_pop},
 	{"f", print_stack_no_pop},
 	{"o", set_output_base},


More information about the busybox mailing list