Browse Source

builtin-grep: allow -<n> and -[ABC]<n> notation for context lines.

Signed-off-by: Junio C Hamano <junkio@cox.net>
maint
Junio C Hamano 19 years ago
parent
commit
f462ebb48b
  1. 28
      builtin-grep.c

28
builtin-grep.c

@ -402,18 +402,34 @@ int cmd_grep(int argc, const char **argv, char **envp)
opt.name_only = 1; opt.name_only = 1;
continue; continue;
} }
if (!strcmp("-A", arg) || if (!strncmp("-A", arg, 2) ||
!strcmp("-B", arg) || !strncmp("-B", arg, 2) ||
!strcmp("-C", arg)) { !strncmp("-C", arg, 2) ||
(arg[0] == '-' && '1' <= arg[1] && arg[1] <= '9')) {
unsigned num; unsigned num;
if (argc <= 1 || const char *scan;
sscanf(*++argv, "%u", &num) != 1) 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); usage(builtin_grep_usage);
argc--;
switch (arg[1]) { switch (arg[1]) {
case 'A': case 'A':
opt.post_context = num; opt.post_context = num;
break; break;
default:
case 'C': case 'C':
opt.post_context = num; opt.post_context = num;
case 'B': case 'B':

Loading…
Cancel
Save