summaryrefslogtreecommitdiff
path: root/lang/nawk/files/patch-ba
blob: 8c2df0c544cf9c53a3fe8d29ee72b8045649edc1 (plain) (blame)
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
--- b.c.orig	Sun Sep 24 17:18:38 2000
+++ b.c	Fri Nov  3 01:59:32 2000
@@ -27,6 +27,9 @@
 #define	DEBUG
 
 #include <ctype.h>
+#ifdef	__FreeBSD__
+#include <limits.h>
+#endif
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
@@ -75,6 +78,24 @@
 fa	*fatab[NFA];
 int	nfatab	= 0;	/* entries in fatab */
 
+#ifdef	__FreeBSD__
+static int
+collate_range_cmp(a, b)
+int a, b;
+{
+	int r;
+	static char s[2][2];
+
+	if ((unsigned char)a == (unsigned char)b)
+		return 0;
+	s[0][0] = a;
+	s[1][0] = b;
+	if ((r = strcoll(s[0], s[1])) == 0)
+		r = (unsigned char)a - (unsigned char)b;
+	return r;
+}
+#endif
+
 fa *makedfa(char *s, int anchor)	/* returns dfa for reg expr s */
 {
 	int i, use, nuse;
@@ -287,6 +308,9 @@
 	int i, c, c2;
 	uschar *p = (uschar *) argp;
 	uschar *op, *bp;
+#ifdef	__FreeBSD__
+ 	int c3;
+#endif
 	static uschar *buf = 0;
 	static int bufsz = 100;
 
@@ -303,6 +327,22 @@
 				c2 = *p++;
 				if (c2 == '\\')
 					c2 = quoted((char **) &p);
+#ifdef	__FreeBSD__
+ 				if (collate_range_cmp(c, c2) > 0) {
+ 					bp--;
+ 					i--;
+ 					continue;
+ 				}
+ 				for (c3 = 0; c3 < (1 << CHAR_BIT) - 1; c3++) {
+ 					if (collate_range_cmp(c, c3) <= 0 &&
+ 					    collate_range_cmp(c3, c2) <= 0) {
+ 						if (!adjbuf(&buf, &bufsz, bp-buf+2, 100, &bp, 0))
+ 							FATAL("out of space for character class [%.10s...] 2", p);
+ 						*bp++ = c3 + 1;
+ 						i++;
+ 					}
+ 				}
+#else /*FreeBSD*/
 				if (c > c2) {	/* empty; ignore */
 					bp--;
 					i--;
@@ -314,6 +354,7 @@
 					*bp++ = ++c;
 					i++;
 				}
+#endif /*FreeBSD*/
 				continue;
 			}
 		}