blob: 98ff8745abe3070ae775bf9afc0dc6cb85b9a9bb [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
Denis Vlasenko5b7589e2009-04-26 11:25:19 +00008typedef char *(*scan_t)(char *string, char *match, bool match_at_left);
Mike Frysingera4f331d2009-04-07 06:03:22 +00009
Denis Vlasenko5b7589e2009-04-26 11:25:19 +000010char *scanleft(char *string, char *match, bool match_at_left);
11char *scanright(char *string, char *match, bool match_at_left);
Mike Frysingera4f331d2009-04-07 06:03:22 +000012
Denis Vlasenko5b7589e2009-04-26 11:25:19 +000013static inline scan_t pick_scan(char op1, char op2, bool *match_at_left)
Mike Frysingera4f331d2009-04-07 06:03:22 +000014{
15 /* # - scanleft
16 * ## - scanright
17 * % - scanright
18 * %% - scanleft
19 */
20 if (op1 == '#') {
Denis Vlasenko5b7589e2009-04-26 11:25:19 +000021 *match_at_left = true;
Mike Frysingera4f331d2009-04-07 06:03:22 +000022 return op1 == op2 ? scanright : scanleft;
23 } else {
Denis Vlasenko5b7589e2009-04-26 11:25:19 +000024 *match_at_left = false;
Mike Frysingera4f331d2009-04-07 06:03:22 +000025 return op1 == op2 ? scanleft : scanright;
26 }
27}
Denis Vlasenkof81e8db2009-04-09 12:35:13 +000028
29POP_SAVED_FUNCTION_VISIBILITY
Denys Vlasenko73067272010-01-12 22:11:24 +010030
31#endif