new function: format
[calc.git] / calc.c
diff --git a/calc.c b/calc.c
index 1432acc275fb7c496e29b3b024da4db6783364df..bd816b982b0a7a2d2c58ea659e858628f54360b4 100644 (file)
--- a/calc.c
+++ b/calc.c
@@ -130,7 +130,7 @@ int main (int argc, char *argv[])
                 VERBOSE (ERROR, fprintf (stderr, "%s: missing output prompt\n", progname); usage (1));
                 return 1;
             }
-            oprompt = arg;
+            set_prompt (oprompt = arg);
             break;
         case 'p':
             arg = (arg[2]) ? arg + 2 : (--argc > 0) ? *(++argv) : NULL;
@@ -138,7 +138,7 @@ int main (int argc, char *argv[])
                 VERBOSE (ERROR, fprintf (stderr, "%s: missing precision\n", progname); usage (1));
                 return 1;
             }
-            precision = atoi (arg);
+            set_precision (precision = atoi (arg));
             break;
         case 'v':
             arg = (arg[2]) ? arg + 2 : (--argc > 0) ? *(++argv) : NULL;
@@ -155,7 +155,7 @@ int main (int argc, char *argv[])
     }
 
     /* set format */
-    set_format (oprompt, precision);
+    set_format ();
 
     /* completion list*/
     completion_list = generate_completion_list ();
@@ -404,6 +404,12 @@ int main (int argc, char *argv[])
 // test: echo -e 'set (1, 2, -5, 6, -8, 9, -2, 23, 4)\nmin (5, -3)\nmax (-1)\nmin\nmean\nmed\nmax\nord\nprod\nsum\nvar\nquit' | calc.exe -n -v 3 | grep -q bye
 // test: echo -e 'min\nmean\nmed\nmax\nprod\nsum\nvar\nord\nset (1)\nord' | calc.exe -n | grep -c error | xargs test 9 =
 // test: echo -e 'prog (1, cos(pi * arg (1))) / 4' | calc.exe | grep -c error | xargs test 1 = 
+// test: echo -e 'format\n.12345678901' | calc.exe | grep -n '=> 6'
+// test: echo -e 'format (8)\n.12345678901' | calc.exe | grep -n '=> 0.12345679'
+// test: echo -e 'format (12)\n.12345678901' | calc.exe | grep -n '=> 0.12345678901'
+// test: echo -e 'format (4)\n.12345678901\format' | calc.exe | grep -n '=> 4'
+// test: echo -e 'format (0)' | calc.exe | grep -n 'error'
+
 // Gauss sequence
 // test: echo -e '{sto (1, 0), sto (10, 0), while (inc (10) <= 100, {sto (1, rcl (1) + rcl (10)), print (rcl (1))})};' | calc.exe | grep -q '=> 5050'