glob_internal.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* Shared definition for glob and glob_pattern_p.
  2. Copyright (C) 2017-2021 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public
  6. License as published by the Free Software Foundation; either
  7. version 3 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public
  13. License along with the GNU C Library; if not, see
  14. <https://www.gnu.org/licenses/>. */
  15. #ifndef GLOB_INTERNAL_H
  16. # define GLOB_INTERNAL_H
  17. enum
  18. {
  19. GLOBPAT_NONE = 0x0,
  20. GLOBPAT_SPECIAL = 0x1,
  21. GLOBPAT_BACKSLASH = 0x2,
  22. GLOBPAT_BRACKET = 0x4
  23. };
  24. static inline int
  25. __glob_pattern_type (const char *pattern, int quote)
  26. {
  27. const char *p;
  28. int ret = GLOBPAT_NONE;
  29. for (p = pattern; *p != '\0'; ++p)
  30. switch (*p)
  31. {
  32. case '?':
  33. case '*':
  34. return GLOBPAT_SPECIAL;
  35. case '\\':
  36. if (quote)
  37. {
  38. if (p[1] != '\0')
  39. ++p;
  40. ret |= GLOBPAT_BACKSLASH;
  41. }
  42. break;
  43. case '[':
  44. ret |= GLOBPAT_BRACKET;
  45. break;
  46. case ']':
  47. if (ret & 4)
  48. return GLOBPAT_SPECIAL;
  49. break;
  50. }
  51. return ret;
  52. }
  53. #endif /* GLOB_INTERNAL_H */