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 | |
Denys Vlasenko | 03dad22 | 2010-01-12 23:29:57 +0100 | [diff] [blame] | 8 | //TODO! Why ash.c still uses internal version?! |
| 9 | |
Denys Vlasenko | 701e127 | 2010-09-04 21:21:07 +0200 | [diff] [blame] | 10 | enum { |
| 11 | SCAN_MOVE_FROM_LEFT = (1 << 0), |
| 12 | SCAN_MOVE_FROM_RIGHT = (1 << 1), |
| 13 | SCAN_MATCH_LEFT_HALF = (1 << 2), |
| 14 | SCAN_MATCH_RIGHT_HALF = (1 << 3), |
| 15 | }; |
Mike Frysinger | a4f331d | 2009-04-07 06:03:22 +0000 | [diff] [blame] | 16 | |
Denys Vlasenko | 701e127 | 2010-09-04 21:21:07 +0200 | [diff] [blame] | 17 | char* FAST_FUNC scan_and_match(char *string, const char *pattern, unsigned flags); |
Mike Frysinger | a4f331d | 2009-04-07 06:03:22 +0000 | [diff] [blame] | 18 | |
Denys Vlasenko | 701e127 | 2010-09-04 21:21:07 +0200 | [diff] [blame] | 19 | static inline unsigned pick_scan(char op1, char op2) |
Mike Frysinger | a4f331d | 2009-04-07 06:03:22 +0000 | [diff] [blame] | 20 | { |
Denys Vlasenko | 701e127 | 2010-09-04 21:21:07 +0200 | [diff] [blame] | 21 | unsigned scan_flags; |
Mike Frysinger | a4f331d | 2009-04-07 06:03:22 +0000 | [diff] [blame] | 22 | if (op1 == '#') { |
Denys Vlasenko | 701e127 | 2010-09-04 21:21:07 +0200 | [diff] [blame] | 23 | scan_flags = SCAN_MATCH_LEFT_HALF + |
| 24 | (op1 == op2 ? SCAN_MOVE_FROM_RIGHT : SCAN_MOVE_FROM_LEFT); |
| 25 | } else { /* % */ |
| 26 | scan_flags = SCAN_MATCH_RIGHT_HALF + |
| 27 | (op1 == op2 ? SCAN_MOVE_FROM_LEFT : SCAN_MOVE_FROM_RIGHT); |
Mike Frysinger | a4f331d | 2009-04-07 06:03:22 +0000 | [diff] [blame] | 28 | } |
Denys Vlasenko | 701e127 | 2010-09-04 21:21:07 +0200 | [diff] [blame] | 29 | return scan_flags; |
Mike Frysinger | a4f331d | 2009-04-07 06:03:22 +0000 | [diff] [blame] | 30 | } |
Denis Vlasenko | f81e8db | 2009-04-09 12:35:13 +0000 | [diff] [blame] | 31 | |
| 32 | POP_SAVED_FUNCTION_VISIBILITY |
Denys Vlasenko | 7306727 | 2010-01-12 22:11:24 +0100 | [diff] [blame] | 33 | |
| 34 | #endif |