diff options
Diffstat (limited to 'line-range.c')
-rw-r--r-- | line-range.c | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/line-range.c b/line-range.c index 5a226abdd0..7a7ca3c2bd 100644 --- a/line-range.c +++ b/line-range.c @@ -21,6 +21,8 @@ static const char *parse_loc(const char *spec, nth_line_fn_t nth_line, if (1 < begin && (spec[0] == '+' || spec[0] == '-')) { num = strtol(spec + 1, &term, 10); if (term != spec + 1) { + if (!ret) + return term; if (spec[0] == '-') num = 0 - num; if (0 < num) @@ -35,7 +37,8 @@ static const char *parse_loc(const char *spec, nth_line_fn_t nth_line, } num = strtol(spec, &term, 10); if (term != spec) { - *ret = num; + if (ret) + *ret = num; return term; } if (spec[0] != '/') @@ -49,6 +52,10 @@ static const char *parse_loc(const char *spec, nth_line_fn_t nth_line, if (*term != '/') return spec; + /* in the scan-only case we are not interested in the regex */ + if (!ret) + return term+1; + /* try [spec+1 .. term-1] as regexp */ *term = 0; begin--; /* input is in human terms */ @@ -90,3 +97,13 @@ int parse_range_arg(const char *arg, nth_line_fn_t nth_line_cb, return 0; } + +const char *skip_range_arg(const char *arg) +{ + arg = parse_loc(arg, NULL, NULL, 0, -1, NULL); + + if (*arg == ',') + arg = parse_loc(arg+1, NULL, NULL, 0, 0, NULL); + + return arg; +} |