hush: fix SEGV in % expansion
[oweals/busybox.git] / shell / match.h
1 /* match.h - interface to shell ##/%% matching code */
2
3 PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN
4
5 typedef char *(*scan_t)(char *string, char *match, bool match_at_left);
6
7 char *scanleft(char *string, char *match, bool match_at_left);
8 char *scanright(char *string, char *match, bool match_at_left);
9
10 static inline scan_t pick_scan(char op1, char op2, bool *match_at_left)
11 {
12         /* #  - scanleft
13          * ## - scanright
14          * %  - scanright
15          * %% - scanleft
16          */
17         if (op1 == '#') {
18                 *match_at_left = true;
19                 return op1 == op2 ? scanright : scanleft;
20         } else {
21                 *match_at_left = false;
22                 return op1 == op2 ? scanleft : scanright;
23         }
24 }
25
26 POP_SAVED_FUNCTION_VISIBILITY