Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/findutils/grep.c


Ignore:
Timestamp:
Dec 20, 2016, 4:07:32 PM (7 years ago)
Author:
Bruno Cornec
Message:

New 3?3 banch for incorporation of latest busybox 1.25. Changing minor version to handle potential incompatibilities.

Location:
branches/3.3
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/3.3/mindi-busybox/findutils/grep.c

    r3232 r3621  
    5959
    6060#include "libbb.h"
     61#include "common_bufsiz.h"
    6162#include "xregex.h"
    6263
     
    202203    const char *cur_file;    /* the current file we are reading */
    203204} FIX_ALIASING;
    204 #define G (*(struct globals*)&bb_common_bufsiz1)
     205#define G (*(struct globals*)bb_common_bufsiz1)
    205206#define INIT_G() do { \
    206     struct G_sizecheck { \
    207         char G_sizecheck[sizeof(G) > COMMON_BUFSIZE ? -1 : 1]; \
    208     }; \
     207    setup_common_bufsiz(); \
     208    BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \
    209209} while (0)
    210210#define max_matches       (G.max_matches         )
     
    374374                }
    375375            } else {
     376#if ENABLE_EXTRA_COMPAT
     377                unsigned start_pos;
     378#else
     379                int match_flg;
     380#endif
     381                char *match_at;
     382
    376383                if (!(gl->flg_mem_alocated_compiled & COMPILED)) {
    377384                    gl->flg_mem_alocated_compiled |= COMPILED;
     
    388395                gl->matched_range.rm_so = 0;
    389396                gl->matched_range.rm_eo = 0;
    390 #endif
     397                match_flg = 0;
     398#else
     399                start_pos = 0;
     400#endif
     401                match_at = line;
     402 opt_w_again:
     403//bb_error_msg("'%s' start_pos:%d line_len:%d", match_at, start_pos, line_len);
    391404                if (
    392405#if !ENABLE_EXTRA_COMPAT
    393                     regexec(&gl->compiled_regex, line, 1, &gl->matched_range, 0) == 0
    394 #else
    395                     re_search(&gl->compiled_regex, line, line_len,
    396                             /*start:*/ 0, /*range:*/ line_len,
     406                    regexec(&gl->compiled_regex, match_at, 1, &gl->matched_range, match_flg) == 0
     407#else
     408                    re_search(&gl->compiled_regex, match_at, line_len,
     409                            start_pos, /*range:*/ line_len,
    397410                            &gl->matched_range) >= 0
    398411#endif
     
    400413                    if (option_mask32 & OPT_x) {
    401414                        found = (gl->matched_range.rm_so == 0
    402                                  && line[gl->matched_range.rm_eo] == '\0');
     415                                 && match_at[gl->matched_range.rm_eo] == '\0');
    403416                    } else
    404417                    if (!(option_mask32 & OPT_w)) {
     
    406419                    } else {
    407420                        char c = ' ';
    408                         if (gl->matched_range.rm_so)
    409                             c = line[gl->matched_range.rm_so - 1];
     421                        if (match_at > line || gl->matched_range.rm_so != 0) {
     422                            c = match_at[gl->matched_range.rm_so - 1];
     423                        }
    410424                        if (!isalnum(c) && c != '_') {
    411                             c = line[gl->matched_range.rm_eo];
    412                             if (!c || (!isalnum(c) && c != '_'))
    413                                 found = 1;
     425                            c = match_at[gl->matched_range.rm_eo];
    414426                        }
    415 //BUG: "echo foop foo | grep -w foo" should match, but doesn't:
    416 //we bail out on first "mismatch" because it's not a word.
     427                        if (!isalnum(c) && c != '_') {
     428                            found = 1;
     429                        } else {
     430            /*
     431             * Why check gl->matched_range.rm_eo?
     432             * Zero-length match makes -w skip the line:
     433             * "echo foo | grep ^" prints "foo",
     434             * "echo foo | grep -w ^" prints nothing.
     435             * Without such check, we can loop forever.
     436             */
     437#if !ENABLE_EXTRA_COMPAT
     438                            if (gl->matched_range.rm_eo != 0) {
     439                                match_at += gl->matched_range.rm_eo;
     440                                match_flg |= REG_NOTBOL;
     441                                goto opt_w_again;
     442                            }
     443#else
     444                            if (gl->matched_range.rm_eo > start_pos) {
     445                                start_pos = gl->matched_range.rm_eo;
     446                                goto opt_w_again;
     447                            }
     448#endif
     449                        }
    417450                    }
    418451                }
     
    636669    recursive_action(dir,
    637670        /* recurse=yes */ ACTION_RECURSE |
    638         /* followLinks=no */
     671        /* followLinks=command line only */ ACTION_FOLLOWLINKS_L0 |
    639672        /* depthFirst=yes */ ACTION_DEPTHFIRST,
    640673        /* fileAction= */ file_action_grep,
     
    651684    int matched;
    652685    llist_t *fopt = NULL;
     686#if ENABLE_FEATURE_GREP_CONTEXT
     687    int Copt, opts;
     688#endif
     689    INIT_G();
     690
     691    /* For grep, exitcode of 1 is "not found". Other errors are 2: */
     692    xfunc_error_retval = 2;
    653693
    654694    /* do normal option parsing */
    655695#if ENABLE_FEATURE_GREP_CONTEXT
    656     int Copt, opts;
    657 
    658696    /* -H unsets -h; -C unsets -A,-B; -e,-f are lists;
    659697     * -m,-A,-B,-C have numeric param */
     
    711749
    712750#if !ENABLE_EXTRA_COMPAT
    713     if (!(option_mask32 & (OPT_o | OPT_w)))
     751    if (!(option_mask32 & (OPT_o | OPT_w | OPT_x)))
    714752        reflags = REG_NOSUB;
    715753#endif
Note: See TracChangeset for help on using the changeset viewer.