Change NUL char handling of isspecial()
Replace isspecial() by the new macro is_glob_special(), which is more, well, specialized. The former included the NUL char in its character class, while the letter only included characters that are special to file name globbing. The new name contains underscores because they enhance readability considerably now that it's made up of three words. Renaming the function is necessary to document its changed scope. The call sites of isspecial() are updated to check explicitly for NUL. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Jan 17, 2009 at 16:50 UTC
8cc32992624ed4140fb136d98675f0f19b20ba09
5 files changed
+15
-8
ctype.c
+2
-2
@@ -9,11 +9,11 @@ enum {
9
S = GIT_SPACE,
10
A = GIT_ALPHA,
11
D = GIT_DIGIT,
12
- G = GIT_SPECIAL, /* \0, *, ?, [, \\ */
12
+ G = GIT_GLOB_SPECIAL, /* *, ?, [, \\ */
13
};
14
15
unsigned char sane_ctype[256] = {
16
- G, 0, 0, 0, 0, 0, 0, 0, 0, S, S, 0, 0, S, 0, 0, /* 0.. 15 */
16
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, S, S, 0, 0, S, 0, 0, /* 0.. 15 */
17
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 16.. 31 */
18
S, 0, 0, 0, 0, 0, 0, 0, 0, 0, G, 0, 0, 0, 0, 0, /* 32.. 47 */
19
D, D, D, D, D, D, D, D, D, D, 0, 0, 0, 0, 0, G, /* 48.. 63 */
dir.c
+2
-2
@@ -75,7 +75,7 @@ static int match_one(const char *match, const char *name, int namelen)
75
for (;;) {
76
unsigned char c1 = *match;
77
unsigned char c2 = *name;
78
- if (isspecial(c1))
78
+ if (c1 == '\0' || is_glob_special(c1))
79
break;
80
if (c1 != c2)
81
return 0;
@@ -680,7 +680,7 @@ static int simple_length(const char *match)
680
for (;;) {
681
unsigned char c = *match++;
682
len++;
683
- if (isspecial(c))
683
+ if (c == '\0' || is_glob_special(c))
684
return len;
685
}
686
}
git-compat-util.h
+2
-2
@@ -327,13 +327,13 @@ extern unsigned char sane_ctype[256];
327
#define GIT_SPACE 0x01
328
#define GIT_DIGIT 0x02
329
#define GIT_ALPHA 0x04
330
-#define GIT_SPECIAL 0x08
330
+#define GIT_GLOB_SPECIAL 0x08
331
#define sane_istest(x,mask) ((sane_ctype[(unsigned char)(x)] & (mask)) != 0)
332
#define isspace(x) sane_istest(x,GIT_SPACE)
333
#define isdigit(x) sane_istest(x,GIT_DIGIT)
334
#define isalpha(x) sane_istest(x,GIT_ALPHA)
335
#define isalnum(x) sane_istest(x,GIT_ALPHA | GIT_DIGIT)
336
-#define isspecial(x) sane_istest(x,GIT_SPECIAL)
336
+#define is_glob_special(x) sane_istest(x,GIT_GLOB_SPECIAL)
337
#define tolower(x) sane_case((unsigned char)(x), 0x20)
338
#define toupper(x) sane_case((unsigned char)(x), 0)
339
grep.c
+3
-2
@@ -30,8 +30,9 @@ void append_grep_pattern(struct grep_opt *opt, const char *pat,
30
31
static int isregexspecial(int c)
32
{
33
- return isspecial(c) || c == '$' || c == '(' || c == ')' || c == '+' ||
34
- c == '.' || c == '^' || c == '{' || c == '|';
33
+ return c == '\0' || is_glob_special(c) ||
34
+ c == '$' || c == '(' || c == ')' || c == '+' ||
35
+ c == '.' || c == '^' || c == '{' || c == '|';
36
}
37
38
static int is_fixed(const char *s)
test-ctype.c
+6
@@ -21,6 +21,11 @@ static int test_isalnum(int c)
21
return isalnum(c);
22
}
23
24
+static int test_is_glob_special(int c)
25
+{
26
+ return is_glob_special(c);
27
+}
28
+
29
#define DIGIT "0123456789"
30
#define LOWER "abcdefghijklmnopqrstuvwxyz"
31
#define UPPER "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
@@ -34,6 +39,7 @@ static const struct ctype_class {
39
{ "isspace", test_isspace, " \n\r\t" },
40
{ "isalpha", test_isalpha, LOWER UPPER },
41
{ "isalnum", test_isalnum, LOWER UPPER DIGIT },
42
+ { "is_glob_special", test_is_glob_special, "*?[\\" },
43
{ NULL }
44
};
45