summaryrefslogtreecommitdiffstats
path: root/usr.bin/awk/b.c.diff
blob: 525fcbc37dc5d2aef70134e1ec6206eb50275ac3 (plain)
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
$FreeBSD$

Index: b.c
===================================================================
RCS file: /home/ncvs/src/contrib/one-true-awk/b.c,v
retrieving revision 1.1.1.8
diff -u -p -r1.1.1.8 b.c
--- b.c	16 May 2005 19:11:31 -0000	1.1.1.8
+++ b.c	16 May 2005 19:12:40 -0000
@@ -282,9 +282,21 @@ int quoted(char **pp)	/* pick up next th
 	return c;
 }
 
+static int collate_range_cmp(int a, int b)
+{
+	static char s[2][2];
+
+	if ((uschar)a == (uschar)b)
+		return 0;
+	s[0][0] = a;
+	s[1][0] = b;
+	return (strcoll(s[0], s[1]));
+}
+
 char *cclenter(const char *argp)	/* add a character class */
 {
 	int i, c, c2;
+	int j;
 	uschar *p = (uschar *) argp;
 	uschar *op, *bp;
 	static uschar *buf = 0;
@@ -303,15 +315,18 @@ char *cclenter(const char *argp)	/* add 
 				c2 = *p++;
 				if (c2 == '\\')
					c2 = quoted((char **) &p);
-				if (c > c2) {	/* empty; ignore */
+				if (collate_range_cmp(c, c2) > 0) {
 					bp--;
 					i--;
 					continue;
 				}
-				while (c < c2) {
+				for (j = 0; j < NCHARS; j++) {
+					if ((collate_range_cmp(c, j) > 0) ||
+					    collate_range_cmp(j, c2) > 0)
+						continue;
					if (!adjbuf((char **) &buf, &bufsz, bp-buf+2, 100, (char **) &bp, "cclenter1"))
						FATAL("out of space for character class [%.10s...] 2", p);
-					*bp++ = ++c;
+					*bp++ = j;
 					i++;
 				}
 				continue;
OpenPOWER on IntegriCloud