]>
Commit | Line | Data |
---|---|---|
25ed3412 BY |
1 | #ifndef LINE_RANGE_H |
2 | #define LINE_RANGE_H | |
3 | ||
4 | /* | |
5 | * Parse one item in an -L begin,end option w.r.t. the notional file | |
6 | * object 'cb_data' consisting of 'lines' lines. | |
7 | * | |
8 | * The 'nth_line_cb' callback is used to determine the start of the | |
9 | * line 'lno' inside the 'cb_data'. The caller is expected to already | |
10 | * have a suitable map at hand to make this a constant-time lookup. | |
11 | * | |
815834e9 ES |
12 | * 'anchor' is the 1-based line at which relative range specifications |
13 | * should be anchored. Absolute ranges are unaffected by this value. | |
14 | * | |
25ed3412 BY |
15 | * Returns 0 in case of success and -1 if there was an error. The |
16 | * actual range is stored in *begin and *end. The counting starts | |
17 | * at 1! In case of error, the caller should show usage message. | |
18 | */ | |
19 | ||
20 | typedef const char *(*nth_line_fn_t)(void *data, long lno); | |
21 | ||
5146f1f8 NTND |
22 | int parse_range_arg(const char *arg, |
23 | nth_line_fn_t nth_line_cb, | |
24 | void *cb_data, long lines, long anchor, | |
25 | long *begin, long *end, | |
26 | const char *path); | |
25ed3412 | 27 | |
12da1d1f TR |
28 | /* |
29 | * Scan past a range argument that could be parsed by | |
30 | * 'parse_range_arg', to help the caller determine the start of the | |
31 | * filename in '-L n,m:file' syntax. | |
32 | * | |
33 | * Returns a pointer to the first character after the 'n,m' part, or | |
34 | * NULL in case the argument is obviously malformed. | |
35 | */ | |
36 | ||
5146f1f8 | 37 | const char *skip_range_arg(const char *arg); |
12da1d1f | 38 | |
25ed3412 | 39 | #endif /* LINE_RANGE_H */ |