blob: c022ceb25a4900ff6a033bd87dfe2850d6ec38f0 [file] [log] [blame]
Mike Frysingera4f331d2009-04-07 06:03:22 +00001/* match.h - interface to shell ##/%% matching code */
2
Denys Vlasenko73067272010-01-12 22:11:24 +01003#ifndef SHELL_MATCH_H
4#define SHELL_MATCH_H 1
5
Denis Vlasenkof81e8db2009-04-09 12:35:13 +00006PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN
7
Denys Vlasenko03dad222010-01-12 23:29:57 +01008//TODO! Why ash.c still uses internal version?!
9
Denis Vlasenko5b7589e2009-04-26 11:25:19 +000010typedef char *(*scan_t)(char *string, char *match, bool match_at_left);
Mike Frysingera4f331d2009-04-07 06:03:22 +000011
Denis Vlasenko5b7589e2009-04-26 11:25:19 +000012char *scanleft(char *string, char *match, bool match_at_left);
13char *scanright(char *string, char *match, bool match_at_left);
Mike Frysingera4f331d2009-04-07 06:03:22 +000014
Denis Vlasenko5b7589e2009-04-26 11:25:19 +000015static inline scan_t pick_scan(char op1, char op2, bool *match_at_left)
Mike Frysingera4f331d2009-04-07 06:03:22 +000016{
17 /* # - scanleft
18 * ## - scanright
19 * % - scanright
20 * %% - scanleft
21 */
22 if (op1 == '#') {
Denis Vlasenko5b7589e2009-04-26 11:25:19 +000023 *match_at_left = true;
Mike Frysingera4f331d2009-04-07 06:03:22 +000024 return op1 == op2 ? scanright : scanleft;
25 } else {
Denis Vlasenko5b7589e2009-04-26 11:25:19 +000026 *match_at_left = false;
Mike Frysingera4f331d2009-04-07 06:03:22 +000027 return op1 == op2 ? scanleft : scanright;
28 }
29}
Denis Vlasenkof81e8db2009-04-09 12:35:13 +000030
31POP_SAVED_FUNCTION_VISIBILITY
Denys Vlasenko73067272010-01-12 22:11:24 +010032
33#endif