rewrite help message
[calc.git] / parser.c
index aecaae3d3b3a9bcefc7db4e39a93e397cbbaad0b..f88da5d28a7cde05bf79f1526d439e785ec3206a 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -130,7 +130,7 @@ keyword_t operators[NB_OPERATORS] = {
     { "|",   Or, 2, 1, -2}
 };
 
-#define NB_FUNCTIONS 31
+#define NB_FUNCTIONS 32
 keyword_t functions[NB_FUNCTIONS] = {
     { "sqrt", Sqr, 1, 4, 5},
     { "pow",  Pow, 2, 3, 5},
@@ -140,6 +140,7 @@ keyword_t functions[NB_FUNCTIONS] = {
     { "acos", Acos, 1, 4, 5},
     { "asin", Asin, 1, 4, 5},
     { "atan", Atan, 1, 4, 5},
+    { "ln",   Ln, 1, 2, 5},
     { "log",  Log, 1, 3, 5},
     { "exp",  Exp, 1, 3, 5},
     { "abs",  Abs, 1, 3, 5},
@@ -513,7 +514,8 @@ void print_element (element_t *root, int level)
     case Acos: func = "Arc Cosine"; break;
     case Asin: func = "Arc Sine"; break;
     case Atan: func = "Arc Tangent"; break;
-    case Log: func = "Logarithm"; break;
+    case Ln: func = "Logarithm (e base)"; break;
+    case Log: func = "Logarithm (10 base)"; break;
     case Exp: func = "Exponantial"; break;
     case Abs: func = "Absolute value"; break;
     case Ceil: func = "Ceil value"; break;
@@ -955,27 +957,27 @@ void del (int id)
 void help (void)
 {
     fprintf (stdout, "calc is a simple calculator\n\n");
-    fprintf (stdout, "supported operators:");
+    fprintf (stdout, "arithmetic op.:");
     fprintf (stdout, " + - * / %% ^\n");
-    fprintf (stdout, "camparison operators:");
+    fprintf (stdout, "comparison op.:");
     fprintf (stdout, " == != >= <= > <\n");
-    fprintf (stdout, "logical operators:");
+    fprintf (stdout, "logical op.:");
     fprintf (stdout, " & | !\n");
-    fprintf (stdout, "mathematic functions:");
+    fprintf (stdout, "mathematic func.:");
     fprintf (stdout, " exp ln log pow sqrt\n");
-    fprintf (stdout, "trig. func.:");
+    fprintf (stdout, "trigonometric func.:");
     fprintf (stdout, " acos asin atan cos sin tan\n");
-    fprintf (stdout, "supported functions:");
+    fprintf (stdout, "miscellaneous func.:");
     fprintf (stdout, " abs ceil floor\n");
-    fprintf (stdout, "stor. functions:");
+    fprintf (stdout, "storage func.:");
     fprintf (stdout, " clear dec disp inc mem rcl sto\n");
-    fprintf (stdout, "cond. functions:");
+    fprintf (stdout, "control flow prim.:");
     fprintf (stdout, " cond print while {} ;\n");
-    fprintf (stdout, "prog. functions:");
+    fprintf (stdout, "program management:");
     fprintf (stdout, " call del edit ls prog\n");
-    fprintf (stdout, "misc. functions:");
+    fprintf (stdout, "control management:");
     fprintf (stdout, " help quit\n");
-    fprintf (stdout, "supported constants:");
+    fprintf (stdout, "constants:");
     fprintf (stdout, " ans e pi\n");
 }
 
@@ -1050,6 +1052,7 @@ double evaluate_element (element_t *root, char mask)
     case Acos:
     case Asin:
     case Atan:
+    case Ln:
     case Log:
     case Exp:
     case Abs:
@@ -1108,7 +1111,8 @@ double evaluate_element (element_t *root, char mask)
     case Acos: return acos (op0);
     case Asin: return asin (op0);
     case Atan: return atan (op0);
-    case Log: return log (op0);
+    case Ln: return log (op0);
+    case Log: return log10 (op0);
     case Exp: return exp (op0);
     case Abs: return fabs (op0);
     case Ceil: return ceil (op0);