1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
Allow sh to use POSIX character classes, as specified in
sections 2.13.1 and 9.3.5
http://www.freebsd.org/cgi/query-pr.cgi?pr=116826
diff -u a/sh/expand.c b/sh/expand.c
--- a/sh/expand.c 2005-11-06 20:39:47 +0000
+++ b/sh/expand.c 2007-10-02 13:46:28 +0100
@@ -1320,6 +1320,42 @@
}
+STATIC int ccmatch(char *p, int chr, char **r)
+{
+ static const struct class {
+ char name[10];
+ int (*fn)(int);
+ } classes[] = {
+ { .name = ":alnum:]", .fn = isalnum },
+ { .name = ":cntrl:]", .fn = iscntrl },
+ { .name = ":lower:]", .fn = islower },
+ { .name = ":space:]", .fn = isspace },
+ { .name = ":alpha:]", .fn = isalpha },
+ { .name = ":digit:]", .fn = isdigit },
+ { .name = ":print:]", .fn = isprint },
+ { .name = ":upper:]", .fn = isupper },
+ { .name = ":blank:]", .fn = isblank },
+ { .name = ":graph:]", .fn = isgraph },
+ { .name = ":punct:]", .fn = ispunct },
+ { .name = ":xdigit:]", .fn = isxdigit },
+ };
+ const struct class *class, *end;
+ char *q;
+
+ end = classes + sizeof(classes) / sizeof(classes[0]);
+ for (class = classes; class < end; class++) {
+ q = prefix(class->name, p);
+ if (!q)
+ continue;
+ *r = q;
+ return class->fn(chr);
+ }
+
+ *r = 0;
+ return 0;
+}
+
+
STATIC int
pmatch(char *pattern, char *string, int squoted)
{
@@ -1405,6 +1441,15 @@
continue;
if (c == CTLESC)
c = *p++;
+ else if (c == '[') {
+ char *r;
+
+ found |= ccmatch(p, chr, &r);
+ if (r) {
+ p = r;
+ continue;
+ }
+ }
if (*p == '-' && p[1] != ']') {
p++;
while (*p == CTLQUOTEMARK)
diff -u a/sh/mystring.c b/sh/mystring.c
--- a/sh/mystring.c 2004-04-06 21:06:51 +0100
+++ b/sh/mystring.c 2007-10-02 13:45:31 +0100
@@ -88,14 +88,14 @@
* prefix -- see if pfx is a prefix of string.
*/
-int
+char *
prefix(const char *pfx, const char *string)
{
while (*pfx) {
if (*pfx++ != *string++)
return 0;
}
- return 1;
+ return (char *)string;
}
diff -u a/sh/mystring.h b/sh/mystring.h
--- a/sh/mystring.h 2004-04-06 21:06:51 +0100
+++ b/sh/mystring.h 2007-10-02 13:45:35 +0100
@@ -36,7 +36,7 @@
#include <string.h>
void scopyn(const char *, char *, int);
-int prefix(const char *, const char *);
+char *prefix(const char *, const char *);
int number(const char *);
int is_number(const char *);
|