use tmpfile() and revert my previous changes... convert() belongs here
[oweals/busybox.git] / coreutils / expr.c
index 9e3c04a11e7c02900b35b089a0c58b93498743a0..4a537bf33077d5490b6f3793a25d0a5f5ab0541e 100644 (file)
  * One function can handle multiple operators all of equal precedence,
  * provided they all associate ((x op x) op x). */
 
-#include "internal.h"
+/* no getopt needed */
+
 #include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <regex.h>
 #include <sys/types.h>
+#include "busybox.h"
 
-#include <regex.h>
 
 /* The kinds of value we can have.  */
 enum valtype {
@@ -74,14 +78,14 @@ int expr_main (int argc, char **argv)
        VALUE *v;
 
        if (argc == 1) {
-               fatalError("too few arguments\n");
+               error_msg_and_die("too few arguments");
        }
 
        args = argv + 1;
 
        v = eval ();
        if (*args)
-               fatalError ("syntax error\n");
+               error_msg_and_die ("syntax error");
 
        if (v->type == integer)
                printf ("%d\n", v->u.i);
@@ -216,17 +220,17 @@ static                                            \
 int name (l, r) VALUE *l; VALUE *r;            \
 {                                              \
   if (!toarith (l) || !toarith (r))            \
-    fatalError ("non-numeric argument\n");     \
+    error_msg_and_die ("non-numeric argument");        \
   return l->u.i op r->u.i;                     \
 }
 
 #define arithdivf(name, op)                    \
-int name (l, r) VALUE *l; VALUE *r;            \
+static int name (l, r) VALUE *l; VALUE *r;             \
 {                                              \
   if (!toarith (l) || !toarith (r))            \
-    fatalError ( "non-numeric argument\n");    \
+    error_msg_and_die ( "non-numeric argument");       \
   if (r->u.i == 0)                             \
-    fatalError ( "division by zero\n");                \
+    error_msg_and_die ( "division by zero");           \
   return l->u.i op r->u.i;                     \
 }
 
@@ -270,7 +274,7 @@ of a basic regular expression is not portable; it is being ignored",
        re_syntax_options = RE_SYNTAX_POSIX_BASIC;
        errmsg = re_compile_pattern (pv->u.s, len, &re_buffer);
        if (errmsg) {
-               fatalError("%s\n", errmsg);
+               error_msg_and_die("%s", errmsg);
        }
 
        len = re_match (&re_buffer, sv->u.s, strlen (sv->u.s), 0, &re_regs);
@@ -301,19 +305,19 @@ static VALUE *eval7 (void)
        VALUE *v;
 
        if (!*args)
-               fatalError ( "syntax error\n");
+               error_msg_and_die ( "syntax error");
 
        if (nextarg ("(")) {
                args++;
                v = eval ();
                if (!nextarg (")"))
-                       fatalError ( "syntax error\n");
+                       error_msg_and_die ( "syntax error");
                        args++;
                        return v;
                }
 
        if (nextarg (")"))
-               fatalError ( "syntax error\n");
+               error_msg_and_die ( "syntax error");
 
        return str_value (*args++);
 }
@@ -327,7 +331,7 @@ static VALUE *eval6 (void)
        if (nextarg ("quote")) {
                args++;
                if (!*args)
-                       fatalError ( "syntax error\n");
+                       error_msg_and_die ( "syntax error");
                return str_value (*args++);
        }
        else if (nextarg ("length")) {