summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: a24f1e2)
raw | patch | inline | side by side (parent: a24f1e2)
author | Junio C Hamano <junkio@cox.net> | |
Tue, 2 May 2006 22:17:05 +0000 (15:17 -0700) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Tue, 2 May 2006 22:17:05 +0000 (15:17 -0700) |
Signed-off-by: Junio C Hamano <junkio@cox.net>
builtin-grep.c | patch | blob | history |
diff --git a/builtin-grep.c b/builtin-grep.c
index eb821b41b95ad128d12e2362f9048ff810fa225e..a551d3402171878ea0b82263529c015caa850380 100644 (file)
--- a/builtin-grep.c
+++ b/builtin-grep.c
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':