clean printf for %f
[calc.git] / calc.c
diff --git a/calc.c b/calc.c
index 1c4099f13d7df7b11da1a4fc99f440df967c9921..ba187005fa321f27c8514a32514c225275207f48 100644 (file)
--- a/calc.c
+++ b/calc.c
@@ -1,6 +1,6 @@
 /* depend: */
 /* cflags: */
-/* linker: atoi.o fdprintf.o parser.o */
+/* linker: atoi.o debug.o fdprintf.o parser.o */
 
 //#include <malloc.h>
 #include <stddef.h>
@@ -26,7 +26,6 @@
 /* gobal variables */
 
 char *progname = NULL;
-int verbose = 2;
 
 /* help function */
 
@@ -47,6 +46,7 @@ int main (int argc, char *argv[])
     char buffer[BUFFER_SIZE + 1] = {0};
     char *pt = buffer;
     int i = 0, j = 0, n;
+    int ret = 0;
 
     /* program name */
 
@@ -87,7 +87,7 @@ int main (int argc, char *argv[])
     /* read from input stream */
 
     while ((n = read (stdfdin, pt, BUFFER_SIZE - (pt - buffer))) != 0) {
-        VERBOSE (DEBUG, PRINTOUT ("read %d bytes\n", n));
+        VERBOSE (INFO, PRINTOUT ("read %d bytes\n", n));
         n += (pt - buffer);
         if ((n == 2) && (buffer[0] == '.')) {
             return 0;
@@ -97,12 +97,14 @@ int main (int argc, char *argv[])
         for (i = 0, j = 0; i < n; i++) {
             if (buffer[i] == '\n') {
                 buffer[i] = 0;
-                VERBOSE (DEBUG, PRINTOUT ("line(%d): %s\n", j, buffer + j));
+                VERBOSE (INFO, PRINTOUT ("line(%d): %s\n", j, buffer + j));
                 element_t *element = parser (buffer, NULL);
                 if (element == (void *)(-1)) {
                     VERBOSE (WARNING, PRINTOUT ("error while parsing: %s\n", buffer));
+                    ret = 1;
                } else {
                     print_element (element, 0);
+                    ret = 0;
                 }
                 //fsync (stdfdout);
                 j = i + 1;
@@ -121,13 +123,34 @@ int main (int argc, char *argv[])
         }
     }
 
-    return 0;
+    return ret;
 }
 
 // test: calc.exe -h
 // test: calc.exe -h | awk '/usage:/ { rc=1 } END { exit (1-rc) }'
 // test: calc.exe -_ 2> /dev/null | awk 'END { if (NR == 0) { exit(0) } else exit (1) }'
 // test: calc.exe -_ 2>&1 | awk '/usage:/ { rc=1 } END { exit (1-rc) }'
-// test: echo "foo\nbar\nfoobar" | calc.exe -v3
+// test: echo "1 + 2" | calc.exe
+// test: echo "1 - 2" | calc.exe
+// test: echo "1 * 2" | calc.exe
+// test: echo "1 / 2" | calc.exe
+// test: echo "2 ^ 3" | calc.exe
+// test: echo "1e-1 + 2.34e5" | calc.exe
+// test: echo "sqrt (2)" | calc.exe
+// test: echo "pow (2, 3)" | calc.exe
+// test: echo "cos (2)" | calc.exe
+// test: echo "sin (2)" | calc.exe
+// test: echo "atan (2)" | calc.exe
+// test: echo "exp (2)" | calc.exe
+// test: echo "log (2)" | calc.exe
+// test: echo "1 + 2 - 3" | calc.exe
+// test: echo "1 + cos (2 - 3)" | calc.exe
+// test: echo "1 + 4 * (2 - 3)" | calc.exe
+// test: echo "(2 - 3) / 4" | calc.exe
+// test: echo "pow (2 - 3, 8 / 3)" | calc.exe
+// test: echo "1 + -2" | calc.exe
+// test: echo "1 - +2" | calc.exe
+// test: echo "-1 + +2" | calc.exe
+// test: echo "-1 +2" | calc.exe
 
 /* vim: set ts=4 sw=4 et: */