strings: implement -t radix
[oweals/busybox.git] / findutils / grep.c
index dece90c580234deca1adf71b7f9a92f6a76addde..1fa605f6f518ba4be5a76694746c8728af282d6a 100644 (file)
@@ -58,6 +58,7 @@
 //config:        Print the specified number of context lines (-C).
 
 #include "libbb.h"
+#include "common_bufsiz.h"
 #include "xregex.h"
 
 
 //usage:#define fgrep_full_usage ""
 
 #define OPTSTR_GREP \
-       "lnqvscFiHhe:f:Lorm:wx" \
-       IF_FEATURE_GREP_CONTEXT("A:B:C:") \
+       "lnqvscFiHhe:*f:*Lorm:+wx" \
+       IF_FEATURE_GREP_CONTEXT("A:+B:+C:+") \
        IF_FEATURE_GREP_EGREP_ALIAS("E") \
        IF_EXTRA_COMPAT("z") \
        "aI"
@@ -201,8 +202,9 @@ struct globals {
        llist_t *pattern_head;   /* growable list of patterns to match */
        const char *cur_file;    /* the current file we are reading */
 } FIX_ALIASING;
-#define G (*(struct globals*)&bb_common_bufsiz1)
+#define G (*(struct globals*)bb_common_bufsiz1)
 #define INIT_G() do { \
+       setup_common_bufsiz(); \
        BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \
 } while (0)
 #define max_matches       (G.max_matches         )
@@ -245,7 +247,7 @@ typedef struct grep_list_data_t {
 #endif
 #define ALLOCATED 1
 #define COMPILED 2
-       int flg_mem_alocated_compiled;
+       int flg_mem_allocated_compiled;
 } grep_list_data_t;
 
 #if !ENABLE_EXTRA_COMPAT
@@ -378,8 +380,8 @@ static int grep_file(FILE *file)
 #endif
                                char *match_at;
 
-                               if (!(gl->flg_mem_alocated_compiled & COMPILED)) {
-                                       gl->flg_mem_alocated_compiled |= COMPILED;
+                               if (!(gl->flg_mem_allocated_compiled & COMPILED)) {
+                                       gl->flg_mem_allocated_compiled |= COMPILED;
 #if !ENABLE_EXTRA_COMPAT
                                        xregcomp(&gl->compiled_regex, gl->pattern, reflags);
 #else
@@ -617,9 +619,9 @@ static char *add_grep_list_data(char *pattern)
        grep_list_data_t *gl = xzalloc(sizeof(*gl));
        gl->pattern = pattern;
 #if ENABLE_FEATURE_CLEAN_UP
-       gl->flg_mem_alocated_compiled = flg_used_mem;
+       gl->flg_mem_allocated_compiled = flg_used_mem;
 #else
-       /*gl->flg_mem_alocated_compiled = 0;*/
+       /*gl->flg_mem_allocated_compiled = 0;*/
 #endif
        return (char *)gl;
 }
@@ -684,6 +686,7 @@ int grep_main(int argc UNUSED_PARAM, char **argv)
 #if ENABLE_FEATURE_GREP_CONTEXT
        int Copt, opts;
 #endif
+       INIT_G();
 
        /* For grep, exitcode of 1 is "not found". Other errors are 2: */
        xfunc_error_retval = 2;
@@ -692,7 +695,7 @@ int grep_main(int argc UNUSED_PARAM, char **argv)
 #if ENABLE_FEATURE_GREP_CONTEXT
        /* -H unsets -h; -C unsets -A,-B; -e,-f are lists;
         * -m,-A,-B,-C have numeric param */
-       opt_complementary = "H-h:C-AB:e::f::m+:A+:B+:C+";
+       opt_complementary = "H-h:C-AB";
        opts = getopt32(argv,
                OPTSTR_GREP,
                &pattern_head, &fopt, &max_matches,
@@ -721,7 +724,7 @@ int grep_main(int argc UNUSED_PARAM, char **argv)
 #else
        /* with auto sanity checks */
        /* -H unsets -h; -c,-q or -l unset -n; -e,-f are lists; -m N */
-       opt_complementary = "H-h:c-n:q-n:l-n:e::f::m+";
+       opt_complementary = "H-h:c-n:q-n:l-n:";
        getopt32(argv, OPTSTR_GREP,
                &pattern_head, &fopt, &max_matches);
 #endif
@@ -834,9 +837,9 @@ int grep_main(int argc UNUSED_PARAM, char **argv)
                        grep_list_data_t *gl = (grep_list_data_t *)pattern_head_ptr->data;
 
                        pattern_head = pattern_head->link;
-                       if (gl->flg_mem_alocated_compiled & ALLOCATED)
+                       if (gl->flg_mem_allocated_compiled & ALLOCATED)
                                free(gl->pattern);
-                       if (gl->flg_mem_alocated_compiled & COMPILED)
+                       if (gl->flg_mem_allocated_compiled & COMPILED)
                                regfree(&gl->compiled_regex);
                        free(gl);
                        free(pattern_head_ptr);