line-range.h 1.37 KB
Newer Older
Bo Yang's avatar
Bo Yang committed
1 2 3
#ifndef LINE_RANGE_H
#define LINE_RANGE_H

4 5
struct index_state;

Bo Yang's avatar
Bo Yang committed
6 7 8 9 10 11 12 13
/*
 * Parse one item in an -L begin,end option w.r.t. the notional file
 * object 'cb_data' consisting of 'lines' lines.
 *
 * The 'nth_line_cb' callback is used to determine the start of the
 * line 'lno' inside the 'cb_data'.  The caller is expected to already
 * have a suitable map at hand to make this a constant-time lookup.
 *
14 15 16
 * 'anchor' is the 1-based line at which relative range specifications
 * should be anchored. Absolute ranges are unaffected by this value.
 *
Bo Yang's avatar
Bo Yang committed
17 18 19 20 21 22 23
 * Returns 0 in case of success and -1 if there was an error.  The
 * actual range is stored in *begin and *end.  The counting starts
 * at 1!  In case of error, the caller should show usage message.
 */

typedef const char *(*nth_line_fn_t)(void *data, long lno);

24 25 26 27
int parse_range_arg(const char *arg,
		    nth_line_fn_t nth_line_cb,
		    void *cb_data, long lines, long anchor,
		    long *begin, long *end,
28
		    const char *path, struct index_state *istate);
Bo Yang's avatar
Bo Yang committed
29

30 31 32 33 34 35 36 37 38
/*
 * Scan past a range argument that could be parsed by
 * 'parse_range_arg', to help the caller determine the start of the
 * filename in '-L n,m:file' syntax.
 *
 * Returns a pointer to the first character after the 'n,m' part, or
 * NULL in case the argument is obviously malformed.
 */

39
const char *skip_range_arg(const char *arg, struct index_state *istate);
40

Bo Yang's avatar
Bo Yang committed
41
#endif /* LINE_RANGE_H */