Bo Yang | 25ed341 | 2013-03-28 17:47:30 +0100 | [diff] [blame] | 1 | #ifndef LINE_RANGE_H |
| 2 | #define LINE_RANGE_H |
| 3 | |
Nguyễn Thái Ngọc Duy | 80e0385 | 2018-09-21 17:57:34 +0200 | [diff] [blame] | 4 | struct index_state; |
| 5 | |
Bo Yang | 25ed341 | 2013-03-28 17:47:30 +0100 | [diff] [blame] | 6 | /* |
| 7 | * Parse one item in an -L begin,end option w.r.t. the notional file |
| 8 | * object 'cb_data' consisting of 'lines' lines. |
| 9 | * |
| 10 | * The 'nth_line_cb' callback is used to determine the start of the |
| 11 | * line 'lno' inside the 'cb_data'. The caller is expected to already |
| 12 | * have a suitable map at hand to make this a constant-time lookup. |
| 13 | * |
Eric Sunshine | 815834e | 2013-08-06 09:59:41 -0400 | [diff] [blame] | 14 | * 'anchor' is the 1-based line at which relative range specifications |
| 15 | * should be anchored. Absolute ranges are unaffected by this value. |
| 16 | * |
Bo Yang | 25ed341 | 2013-03-28 17:47:30 +0100 | [diff] [blame] | 17 | * Returns 0 in case of success and -1 if there was an error. The |
| 18 | * actual range is stored in *begin and *end. The counting starts |
| 19 | * at 1! In case of error, the caller should show usage message. |
| 20 | */ |
| 21 | |
| 22 | typedef const char *(*nth_line_fn_t)(void *data, long lno); |
| 23 | |
Nguyễn Thái Ngọc Duy | 5146f1f | 2018-06-30 11:20:27 +0200 | [diff] [blame] | 24 | int parse_range_arg(const char *arg, |
| 25 | nth_line_fn_t nth_line_cb, |
| 26 | void *cb_data, long lines, long anchor, |
| 27 | long *begin, long *end, |
Nguyễn Thái Ngọc Duy | 80e0385 | 2018-09-21 17:57:34 +0200 | [diff] [blame] | 28 | const char *path, struct index_state *istate); |
Bo Yang | 25ed341 | 2013-03-28 17:47:30 +0100 | [diff] [blame] | 29 | |
Thomas Rast | 12da1d1 | 2013-03-28 17:47:32 +0100 | [diff] [blame] | 30 | /* |
| 31 | * Scan past a range argument that could be parsed by |
| 32 | * 'parse_range_arg', to help the caller determine the start of the |
| 33 | * filename in '-L n,m:file' syntax. |
| 34 | * |
| 35 | * Returns a pointer to the first character after the 'n,m' part, or |
| 36 | * NULL in case the argument is obviously malformed. |
| 37 | */ |
| 38 | |
Nguyễn Thái Ngọc Duy | 80e0385 | 2018-09-21 17:57:34 +0200 | [diff] [blame] | 39 | const char *skip_range_arg(const char *arg, struct index_state *istate); |
Thomas Rast | 12da1d1 | 2013-03-28 17:47:32 +0100 | [diff] [blame] | 40 | |
Bo Yang | 25ed341 | 2013-03-28 17:47:30 +0100 | [diff] [blame] | 41 | #endif /* LINE_RANGE_H */ |