blob: aa393ed1ab8247b803cbbb35ff11e4f167d9e472 [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
Denys Vlasenko701e1272010-09-04 21:21:07 +020010enum {
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 Frysingera4f331d2009-04-07 06:03:22 +000016
Denys Vlasenko701e1272010-09-04 21:21:07 +020017char* FAST_FUNC scan_and_match(char *string, const char *pattern, unsigned flags);
Mike Frysingera4f331d2009-04-07 06:03:22 +000018
Denys Vlasenko701e1272010-09-04 21:21:07 +020019static inline unsigned pick_scan(char op1, char op2)
Mike Frysingera4f331d2009-04-07 06:03:22 +000020{
Denys Vlasenko701e1272010-09-04 21:21:07 +020021 unsigned scan_flags;
Mike Frysingera4f331d2009-04-07 06:03:22 +000022 if (op1 == '#') {
Denys Vlasenko701e1272010-09-04 21:21:07 +020023 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 Frysingera4f331d2009-04-07 06:03:22 +000028 }
Denys Vlasenko701e1272010-09-04 21:21:07 +020029 return scan_flags;
Mike Frysingera4f331d2009-04-07 06:03:22 +000030}
Denis Vlasenkof81e8db2009-04-09 12:35:13 +000031
32POP_SAVED_FUNCTION_VISIBILITY
Denys Vlasenko73067272010-01-12 22:11:24 +010033
34#endif