embellish usage display
[calc.git] / stack.c
diff --git a/stack.c b/stack.c
index 829f8aa6483f9357861680931a49a54d0a045799..f4117f5ce0fd397432933cc8062c219f6e15bbf0 100644 (file)
--- a/stack.c
+++ b/stack.c
@@ -1,3 +1,4 @@
+#include <math.h>
 #include <stdio.h>
 
 #include "debug.h"
@@ -30,7 +31,14 @@ double pop ()
 
 double push (double val)
 {
-    return push_tab (stack, -1, val);
+    double ret = NAN;
+    if (stack) {
+        ret = push_tab (stack, -1, val);
+    } else {
+        stack = resize_tab (stack, 1);
+        ret = set_tab (stack, 1, val);
+    }
+    return ret;
 }
 
 double put (int n, double val)
@@ -54,12 +62,12 @@ double set (int nbops, element_t **ops)
 void show (void)
 {
     int i, n = size_tab (stack);
-    fprintf (stdout, "stack:");
+    printf ("stack:");
     for (i = 0; i < n; i++) {
-        fprintf (stdout, " ");
-        fprintf (stdout, minform, get_tab (stack, i + 1));
+        printf (" ");
+        printl (get_tab (stack, i + 1));
     }
-    fprintf (stdout, "\n");
+    printf ("\n");
 }
 
 /* stack functions */
@@ -116,12 +124,7 @@ double min ()
 
 void order ()
 {
-    int n = size_tab (stack);
-    if (n < 3) {
-        VERBOSE (WARNING, fprintf (stdout, "error not enough element in stack (%d)\n", n));
-    } else {
-        order_tab (stack);
-    }
+    order_tab (stack);
 }
 
 double median ()