aboutsummaryrefslogtreecommitdiff
path: root/findutils/grep.c
diff options
context:
space:
mode:
Diffstat (limited to 'findutils/grep.c')
-rw-r--r--findutils/grep.c63
1 files changed, 58 insertions, 5 deletions
diff --git a/findutils/grep.c b/findutils/grep.c
index dd1a4efc4..ac290a911 100644
--- a/findutils/grep.c
+++ b/findutils/grep.c
@@ -14,13 +14,16 @@
* 2004,2006 (C) Vladimir Oleynik <dzo@simtreas.ru> -
* correction "-e pattern1 -e pattern2" logic and more optimizations.
* precompiled regex
- */
-/*
+ *
* (C) 2006 Jac Goudsmit added -o option
*/
+//applet:IF_GREP(APPLET(grep, _BB_DIR_BIN, _BB_SUID_DROP))
+//applet:IF_FEATURE_GREP_EGREP_ALIAS(APPLET_ODDNAME(egrep, grep, _BB_DIR_BIN, _BB_SUID_DROP, egrep))
+//applet:IF_FEATURE_GREP_FGREP_ALIAS(APPLET_ODDNAME(fgrep, grep, _BB_DIR_BIN, _BB_SUID_DROP, fgrep))
+
//kbuild:lib-$(CONFIG_GREP) += grep.o
-//config:
+
//config:config GREP
//config: bool "grep"
//config: default y
@@ -57,17 +60,67 @@
#include "libbb.h"
#include "xregex.h"
+
/* options */
+//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: "\nOptions:"
+//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 -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:w" \
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# */