-#define GREP_OPTS "lnqvscFiHhe:f:Lor"
-#define GREP_OPT_l (1<<0)
-#define PRINT_FILES_WITH_MATCHES (option_mask32 & GREP_OPT_l)
-#define GREP_OPT_n (1<<1)
-#define PRINT_LINE_NUM (option_mask32 & GREP_OPT_n)
-#define GREP_OPT_q (1<<2)
-#define BE_QUIET (option_mask32 & GREP_OPT_q)
-#define GREP_OPT_v (1<<3)
-#define GREP_OPT_s (1<<4)
-#define SUPPRESS_ERR_MSGS (option_mask32 & GREP_OPT_s)
-#define GREP_OPT_c (1<<5)
-#define PRINT_MATCH_COUNTS (option_mask32 & GREP_OPT_c)
-#define GREP_OPT_F (1<<6)
-#define FGREP_FLAG (option_mask32 & GREP_OPT_F)
-#define GREP_OPT_i (1<<7)
-#define GREP_OPT_H (1<<8)
-#define GREP_OPT_h (1<<9)
-#define GREP_OPT_e (1<<10)
-#define GREP_OPT_f (1<<11)
-#define GREP_OPT_L (1<<12)
-#define PRINT_FILES_WITHOUT_MATCHES (option_mask32 & GREP_OPT_L)
-#define GREP_OPT_o (1<<13)
-#define GREP_OPT_r (1<<14)
-#if ENABLE_FEATURE_GREP_CONTEXT
-# define GREP_OPT_CONTEXT "A:B:C:"
-# define GREP_OPT_A (1<<15)
-# define GREP_OPT_B (1<<16)
-# define GREP_OPT_C (1<<17)
-# define GREP_OPT_E (1<<18)
+//usage:#define grep_trivial_usage
+//usage: "[-HhnlLoqvsriw"
+//usage: "F"
+//usage: IF_FEATURE_GREP_EGREP_ALIAS("E")
+//usage: IF_EXTRA_COMPAT("z")
+//usage: "] [-m N] "
+//usage: IF_FEATURE_GREP_CONTEXT("[-A/B/C N] ")
+//usage: "PATTERN/-e PATTERN.../-f FILE [FILE]..."
+//usage:#define grep_full_usage "\n\n"
+//usage: "Search for PATTERN in FILEs (or stdin)\n"
+//usage: "\n -H Add 'filename:' prefix"
+//usage: "\n -h Do not add 'filename:' prefix"
+//usage: "\n -n Add 'line_no:' prefix"
+//usage: "\n -l Show only names of files that match"
+//usage: "\n -L Show only names of files that don't match"
+//usage: "\n -c Show only count of matching lines"
+//usage: "\n -o Show only the matching part of line"
+//usage: "\n -q Quiet. Return 0 if PATTERN is found, 1 otherwise"
+//usage: "\n -v Select non-matching lines"
+//usage: "\n -s Suppress open and read errors"
+//usage: "\n -r Recurse"
+//usage: "\n -i Ignore case"
+//usage: "\n -w Match whole words only"
+//usage: "\n -x Match whole lines only"
+//usage: "\n -F PATTERN is a literal (not regexp)"
+//usage: IF_FEATURE_GREP_EGREP_ALIAS(
+//usage: "\n -E PATTERN is an extended regexp"
+//usage: )
+//usage: IF_EXTRA_COMPAT(
+//usage: "\n -z Input is NUL terminated"
+//usage: )
+//usage: "\n -m N Match up to N times per file"
+//usage: IF_FEATURE_GREP_CONTEXT(
+//usage: "\n -A N Print N lines of trailing context"
+//usage: "\n -B N Print N lines of leading context"
+//usage: "\n -C N Same as '-A N -B N'"
+//usage: )
+//usage: "\n -e PTRN Pattern to match"
+//usage: "\n -f FILE Read pattern from file"
+//usage:
+//usage:#define grep_example_usage
+//usage: "$ grep root /etc/passwd\n"
+//usage: "root:x:0:0:root:/root:/bin/bash\n"
+//usage: "$ grep ^[rR]oo. /etc/passwd\n"
+//usage: "root:x:0:0:root:/root:/bin/bash\n"
+//usage:
+//usage:#define egrep_trivial_usage NOUSAGE_STR
+//usage:#define egrep_full_usage ""
+//usage:#define fgrep_trivial_usage NOUSAGE_STR
+//usage:#define fgrep_full_usage ""
+
+#define OPTSTR_GREP \
+ "lnqvscFiHhe:f:Lorm:wx" \
+ IF_FEATURE_GREP_CONTEXT("A:B:C:") \
+ IF_FEATURE_GREP_EGREP_ALIAS("E") \
+ IF_EXTRA_COMPAT("z") \
+ "aI"
+/* ignored: -a "assume all files to be text" */
+/* ignored: -I "assume binary files have no matches" */
+enum {
+ OPTBIT_l, /* list matched file names only */
+ OPTBIT_n, /* print line# */
+ OPTBIT_q, /* quiet - exit(EXIT_SUCCESS) of first match */
+ OPTBIT_v, /* invert the match, to select non-matching lines */
+ OPTBIT_s, /* suppress errors about file open errors */
+ OPTBIT_c, /* count matches per file (suppresses normal output) */
+ OPTBIT_F, /* literal match */
+ OPTBIT_i, /* case-insensitive */
+ OPTBIT_H, /* force filename display */
+ OPTBIT_h, /* inhibit filename display */
+ OPTBIT_e, /* -e PATTERN */
+ OPTBIT_f, /* -f FILE_WITH_PATTERNS */
+ OPTBIT_L, /* list unmatched file names only */
+ OPTBIT_o, /* show only matching parts of lines */
+ OPTBIT_r, /* recurse dirs */
+ OPTBIT_m, /* -m MAX_MATCHES */
+ OPTBIT_w, /* -w whole word match */
+ OPTBIT_x, /* -x whole line match */
+ IF_FEATURE_GREP_CONTEXT( OPTBIT_A ,) /* -A NUM: after-match context */
+ IF_FEATURE_GREP_CONTEXT( OPTBIT_B ,) /* -B NUM: before-match context */
+ IF_FEATURE_GREP_CONTEXT( OPTBIT_C ,) /* -C NUM: -A and -B combined */
+ IF_FEATURE_GREP_EGREP_ALIAS(OPTBIT_E ,) /* extended regexp */
+ IF_EXTRA_COMPAT( OPTBIT_z ,) /* input is NUL terminated */
+ OPT_l = 1 << OPTBIT_l,
+ OPT_n = 1 << OPTBIT_n,
+ OPT_q = 1 << OPTBIT_q,
+ OPT_v = 1 << OPTBIT_v,
+ OPT_s = 1 << OPTBIT_s,
+ OPT_c = 1 << OPTBIT_c,
+ OPT_F = 1 << OPTBIT_F,
+ OPT_i = 1 << OPTBIT_i,
+ OPT_H = 1 << OPTBIT_H,
+ OPT_h = 1 << OPTBIT_h,
+ OPT_e = 1 << OPTBIT_e,
+ OPT_f = 1 << OPTBIT_f,
+ OPT_L = 1 << OPTBIT_L,
+ OPT_o = 1 << OPTBIT_o,
+ OPT_r = 1 << OPTBIT_r,
+ OPT_m = 1 << OPTBIT_m,
+ OPT_w = 1 << OPTBIT_w,
+ OPT_x = 1 << OPTBIT_x,
+ OPT_A = IF_FEATURE_GREP_CONTEXT( (1 << OPTBIT_A)) + 0,
+ OPT_B = IF_FEATURE_GREP_CONTEXT( (1 << OPTBIT_B)) + 0,
+ OPT_C = IF_FEATURE_GREP_CONTEXT( (1 << OPTBIT_C)) + 0,
+ OPT_E = IF_FEATURE_GREP_EGREP_ALIAS((1 << OPTBIT_E)) + 0,
+ OPT_z = IF_EXTRA_COMPAT( (1 << OPTBIT_z)) + 0,
+};
+
+#define PRINT_FILES_WITH_MATCHES (option_mask32 & OPT_l)
+#define PRINT_LINE_NUM (option_mask32 & OPT_n)
+#define BE_QUIET (option_mask32 & OPT_q)
+#define SUPPRESS_ERR_MSGS (option_mask32 & OPT_s)
+#define PRINT_MATCH_COUNTS (option_mask32 & OPT_c)
+#define FGREP_FLAG (option_mask32 & OPT_F)
+#define PRINT_FILES_WITHOUT_MATCHES (option_mask32 & OPT_L)
+#define NUL_DELIMITED (option_mask32 & OPT_z)
+
+struct globals {
+ int max_matches;
+#if !ENABLE_EXTRA_COMPAT
+ int reflags;