match.h 806 B

12345678910111213141516171819202122232425262728293031323334
  1. /* match.h - interface to shell ##/%% matching code */
  2. #ifndef SHELL_MATCH_H
  3. #define SHELL_MATCH_H 1
  4. PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN
  5. //TODO! Why ash.c still uses internal version?!
  6. enum {
  7. SCAN_MOVE_FROM_LEFT = (1 << 0),
  8. SCAN_MOVE_FROM_RIGHT = (1 << 1),
  9. SCAN_MATCH_LEFT_HALF = (1 << 2),
  10. SCAN_MATCH_RIGHT_HALF = (1 << 3),
  11. };
  12. char* FAST_FUNC scan_and_match(char *string, const char *pattern, unsigned flags);
  13. static inline unsigned pick_scan(char op1, char op2)
  14. {
  15. unsigned scan_flags;
  16. if (op1 == '#') {
  17. scan_flags = SCAN_MATCH_LEFT_HALF +
  18. (op1 == op2 ? SCAN_MOVE_FROM_RIGHT : SCAN_MOVE_FROM_LEFT);
  19. } else { /* % */
  20. scan_flags = SCAN_MATCH_RIGHT_HALF +
  21. (op1 == op2 ? SCAN_MOVE_FROM_LEFT : SCAN_MOVE_FROM_RIGHT);
  22. }
  23. return scan_flags;
  24. }
  25. POP_SAVED_FUNCTION_VISIBILITY
  26. #endif