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