summaryrefslogtreecommitdiff
path: root/builtin-grep.c
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2006-05-02 22:17:05 (GMT)
committerJunio C Hamano <junkio@cox.net>2006-05-02 22:17:05 (GMT)
commitf462ebb48bf9126335671e878336e3faf3914802 (patch)
tree7620d77e06deab04c9720a46d28413b548fafd69 /builtin-grep.c
parenta24f1e254e9dbea80b8173d72e0f75fec25b38a7 (diff)
downloadgit-f462ebb48bf9126335671e878336e3faf3914802.zip
git-f462ebb48bf9126335671e878336e3faf3914802.tar.gz
git-f462ebb48bf9126335671e878336e3faf3914802.tar.bz2
builtin-grep: allow -<n> and -[ABC]<n> notation for context lines.
Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'builtin-grep.c')
-rw-r--r--builtin-grep.c28
1 files changed, 22 insertions, 6 deletions
diff --git a/builtin-grep.c b/builtin-grep.c
index eb821b4..a551d34 100644
--- a/builtin-grep.c
+++ b/builtin-grep.c
@@ -402,18 +402,34 @@ int cmd_grep(int argc, const char **argv, char **envp)
opt.name_only = 1;
continue;
}
- if (!strcmp("-A", arg) ||
- !strcmp("-B", arg) ||
- !strcmp("-C", arg)) {
+ if (!strncmp("-A", arg, 2) ||
+ !strncmp("-B", arg, 2) ||
+ !strncmp("-C", arg, 2) ||
+ (arg[0] == '-' && '1' <= arg[1] && arg[1] <= '9')) {
unsigned num;
- if (argc <= 1 ||
- sscanf(*++argv, "%u", &num) != 1)
+ const char *scan;
+ switch (arg[1]) {
+ case 'A': case 'B': case 'C':
+ if (!arg[2]) {
+ if (argc <= 1)
+ usage(builtin_grep_usage);
+ scan = *++argv;
+ argc--;
+ }
+ else
+ scan = arg + 2;
+ break;
+ default:
+ scan = arg + 1;
+ break;
+ }
+ if (sscanf(scan, "%u", &num) != 1)
usage(builtin_grep_usage);
- argc--;
switch (arg[1]) {
case 'A':
opt.post_context = num;
break;
+ default:
case 'C':
opt.post_context = num;
case 'B':