Mike Frysinger | a4f331d | 2009-04-07 06:03:22 +0000 | [diff] [blame] | 1 | /* match.h - interface to shell ##/%% matching code */ |
| 2 | |
Denys Vlasenko | 7306727 | 2010-01-12 22:11:24 +0100 | [diff] [blame^] | 3 | #ifndef SHELL_MATCH_H |
| 4 | #define SHELL_MATCH_H 1 |
| 5 | |
Denis Vlasenko | f81e8db | 2009-04-09 12:35:13 +0000 | [diff] [blame] | 6 | PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN |
| 7 | |
Denis Vlasenko | 5b7589e | 2009-04-26 11:25:19 +0000 | [diff] [blame] | 8 | typedef char *(*scan_t)(char *string, char *match, bool match_at_left); |
Mike Frysinger | a4f331d | 2009-04-07 06:03:22 +0000 | [diff] [blame] | 9 | |
Denis Vlasenko | 5b7589e | 2009-04-26 11:25:19 +0000 | [diff] [blame] | 10 | char *scanleft(char *string, char *match, bool match_at_left); |
| 11 | char *scanright(char *string, char *match, bool match_at_left); |
Mike Frysinger | a4f331d | 2009-04-07 06:03:22 +0000 | [diff] [blame] | 12 | |
Denis Vlasenko | 5b7589e | 2009-04-26 11:25:19 +0000 | [diff] [blame] | 13 | static inline scan_t pick_scan(char op1, char op2, bool *match_at_left) |
Mike Frysinger | a4f331d | 2009-04-07 06:03:22 +0000 | [diff] [blame] | 14 | { |
| 15 | /* # - scanleft |
| 16 | * ## - scanright |
| 17 | * % - scanright |
| 18 | * %% - scanleft |
| 19 | */ |
| 20 | if (op1 == '#') { |
Denis Vlasenko | 5b7589e | 2009-04-26 11:25:19 +0000 | [diff] [blame] | 21 | *match_at_left = true; |
Mike Frysinger | a4f331d | 2009-04-07 06:03:22 +0000 | [diff] [blame] | 22 | return op1 == op2 ? scanright : scanleft; |
| 23 | } else { |
Denis Vlasenko | 5b7589e | 2009-04-26 11:25:19 +0000 | [diff] [blame] | 24 | *match_at_left = false; |
Mike Frysinger | a4f331d | 2009-04-07 06:03:22 +0000 | [diff] [blame] | 25 | return op1 == op2 ? scanleft : scanright; |
| 26 | } |
| 27 | } |
Denis Vlasenko | f81e8db | 2009-04-09 12:35:13 +0000 | [diff] [blame] | 28 | |
| 29 | POP_SAVED_FUNCTION_VISIBILITY |
Denys Vlasenko | 7306727 | 2010-01-12 22:11:24 +0100 | [diff] [blame^] | 30 | |
| 31 | #endif |