groups: make it NOEXEC
[oweals/busybox.git] / coreutils / expr.c
index 54c2ee1655510614319d1f4b49ac4b80c683065e..24e75b5565a8f31985bb9233abd0a8072ebb8141 100644 (file)
@@ -11,7 +11,7 @@
  *  - reduced 464 bytes.
  *  - 64 math support
  *
- * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
+ * Licensed under GPLv2 or later, see file LICENSE in this source tree.
  */
 
 /* This program evaluates expressions.  Each token (operator, operand,
 
 /* no getopt needed */
 
+//usage:#define expr_trivial_usage
+//usage:       "EXPRESSION"
+//usage:#define expr_full_usage "\n\n"
+//usage:       "Print the value of EXPRESSION to stdout\n"
+//usage:    "\n"
+//usage:       "EXPRESSION may be:\n"
+//usage:       "       ARG1 | ARG2     ARG1 if it is neither null nor 0, otherwise ARG2\n"
+//usage:       "       ARG1 & ARG2     ARG1 if neither argument is null or 0, otherwise 0\n"
+//usage:       "       ARG1 < ARG2     1 if ARG1 is less than ARG2, else 0. Similarly:\n"
+//usage:       "       ARG1 <= ARG2\n"
+//usage:       "       ARG1 = ARG2\n"
+//usage:       "       ARG1 != ARG2\n"
+//usage:       "       ARG1 >= ARG2\n"
+//usage:       "       ARG1 > ARG2\n"
+//usage:       "       ARG1 + ARG2     Sum of ARG1 and ARG2. Similarly:\n"
+//usage:       "       ARG1 - ARG2\n"
+//usage:       "       ARG1 * ARG2\n"
+//usage:       "       ARG1 / ARG2\n"
+//usage:       "       ARG1 % ARG2\n"
+//usage:       "       STRING : REGEXP         Anchored pattern match of REGEXP in STRING\n"
+//usage:       "       match STRING REGEXP     Same as STRING : REGEXP\n"
+//usage:       "       substr STRING POS LENGTH Substring of STRING, POS counted from 1\n"
+//usage:       "       index STRING CHARS      Index in STRING where any CHARS is found, or 0\n"
+//usage:       "       length STRING           Length of STRING\n"
+//usage:       "       quote TOKEN             Interpret TOKEN as a string, even if\n"
+//usage:       "                               it is a keyword like 'match' or an\n"
+//usage:       "                               operator like '/'\n"
+//usage:       "       (EXPRESSION)            Value of EXPRESSION\n"
+//usage:       "\n"
+//usage:       "Beware that many operators need to be escaped or quoted for shells.\n"
+//usage:       "Comparisons are arithmetic if both ARGs are numbers, else\n"
+//usage:       "lexicographical. Pattern matches return the string matched between\n"
+//usage:       "\\( and \\) or null; if \\( and \\) are not used, they return the number\n"
+//usage:       "of characters matched or 0."
+
 #include "libbb.h"
 #include "xregex.h"
 
@@ -63,7 +98,7 @@ typedef struct valinfo VALUE;
 /* The arguments given to the program, minus the program name.  */
 struct globals {
        char **args;
-};
+} FIX_ALIASING;
 #define G (*(struct globals*)&bb_common_bufsiz1)
 
 /* forward declarations */
@@ -214,9 +249,9 @@ static arith_t arithmetic_common(VALUE *l, VALUE *r, int op)
 
 static VALUE *docolon(VALUE *sv, VALUE *pv)
 {
+       enum { NMATCH = 2 };
        VALUE *v;
        regex_t re_buffer;
-       const int NMATCH = 2;
        regmatch_t re_regs[NMATCH];
 
        tostring(sv);
@@ -341,7 +376,6 @@ static VALUE *eval6(void)
                freev(i2);
        }
        return v;
-
 }
 
 /* Handle : operator (pattern matching).