//config: Print the specified number of context lines (-C).
#include "libbb.h"
+#include "common_bufsiz.h"
#include "xregex.h"
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 { \
- struct G_sizecheck { \
- char G_sizecheck[sizeof(G) > COMMON_BUFSIZE ? -1 : 1]; \
- }; \
+ setup_common_bufsiz(); \
+ BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \
} while (0)
#define max_matches (G.max_matches )
#if !ENABLE_EXTRA_COMPAT
found = 1;
} else {
char c = ' ';
- if (match_at > line || gl->matched_range.rm_so != 0)
+ if (match_at > line || gl->matched_range.rm_so != 0) {
c = match_at[gl->matched_range.rm_so - 1];
+ }
if (!isalnum(c) && c != '_') {
c = match_at[gl->matched_range.rm_eo];
- if (!c || (!isalnum(c) && c != '_')) {
- found = 1;
- } else {
+ }
+ if (!isalnum(c) && c != '_') {
+ found = 1;
+ } else {
/*
* Why check gl->matched_range.rm_eo?
* Zero-length match makes -w skip the line:
* Without such check, we can loop forever.
*/
#if !ENABLE_EXTRA_COMPAT
- if (gl->matched_range.rm_eo != 0) {
- match_at += gl->matched_range.rm_eo;
- match_flg |= REG_NOTBOL;
- goto opt_w_again;
- }
+ if (gl->matched_range.rm_eo != 0) {
+ match_at += gl->matched_range.rm_eo;
+ match_flg |= REG_NOTBOL;
+ goto opt_w_again;
+ }
#else
- if (gl->matched_range.rm_eo > start_pos) {
- start_pos = gl->matched_range.rm_eo;
- goto opt_w_again;
- }
-#endif
+ if (gl->matched_range.rm_eo > start_pos) {
+ start_pos = gl->matched_range.rm_eo;
+ goto opt_w_again;
}
+#endif
}
}
}
int matched = 0;
recursive_action(dir,
/* recurse=yes */ ACTION_RECURSE |
- /* followLinks=no */
+ /* followLinks=command line only */ ACTION_FOLLOWLINKS_L0 |
/* depthFirst=yes */ ACTION_DEPTHFIRST,
/* fileAction= */ file_action_grep,
/* dirAction= */ NULL,
FILE *file;
int matched;
llist_t *fopt = NULL;
-
- /* do normal option parsing */
#if ENABLE_FEATURE_GREP_CONTEXT
int Copt, opts;
+#endif
+ /* For grep, exitcode of 1 is "not found". Other errors are 2: */
+ xfunc_error_retval = 2;
+
+ /* do normal option parsing */
+#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+";