summaryrefslogtreecommitdiffhomepage
path: root/math.c
diff options
context:
space:
mode:
authorErik Andersen <andersen@codepoet.org>2000-04-15 16:34:54 +0000
committerErik Andersen <andersen@codepoet.org>2000-04-15 16:34:54 +0000
commit5e1189e187f6a7957dadb8eda2c271c4a0777a23 (patch)
tree140cd30d77342c730afbc1df863bec93c63978a8 /math.c
parent95c1c1e05f290ccbcc2ff863a62bcee5d57bf5c8 (diff)
More documentation updates, and minor fixes to make things sync
up with the docs. -Erik
Diffstat (limited to 'math.c')
-rw-r--r--math.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/math.c b/math.c
index 75b4cdeb5..3b459f62e 100644
--- a/math.c
+++ b/math.c
@@ -7,7 +7,10 @@
/* Tiny RPN calculator, because "expr" didn't give me bitwise operations. */
-static const char math_usage[] = "math expression ...";
+static const char math_usage[] = "math expression ...\n\n"
+ "This is a Tiny RPN calculator that understands the\n"
+ "following operations: +, -, /, *, and, or, not, eor.\n"
+ "i.e. 'math 2 2 add' -> 4, and 'math 8 8 \\* 2 2 + /' -> 16\n";
static double stack[100];
static unsigned int pointer;
@@ -85,14 +88,14 @@ struct op {
};
static const struct op operators[] = {
- {"add", add},
+ {"+", add},
+ {"-", sub},
+ {"*", mul},
+ {"/", divide},
{"and", and},
- {"div", divide},
- {"eor", eor},
- {"mul", mul},
- {"not", not},
{"or", or},
- {"sub", sub},
+ {"not", not},
+ {"eor", eor},
{0, 0}
};
@@ -127,11 +130,13 @@ static void stack_machine(const char *argument)
int math_main(int argc, char **argv)
{
+ if (argc < 1 || *argv[1]=='-')
+ usage(math_usage);
while (argc >= 2) {
stack_machine(argv[1]);
argv++;
argc--;
}
stack_machine(0);
- return 0;
+ exit( TRUE);
}