From f9fe4d605fdc9a299101daa30a9b96e852f16552 Mon Sep 17 00:00:00 2001 From: Ruslan Ermilov Date: Tue, 17 May 2005 14:54:33 +0000 Subject: [PATCH] Add temporary patches to make one-true-awk respect locale's collating order in [a-z] bracket expressions, until a more complete fix (like handing BREs) is ready. Prodded by: ache OK'ed by: tjr --- usr.bin/awk/Makefile | 6 +++++ usr.bin/awk/b.c.diff | 53 +++++++++++++++++++++++++++++++++++++++++ usr.bin/awk/main.c.diff | 26 ++++++++++++++++++++ usr.bin/awk/run.c.diff | 18 ++++++++++++++ 4 files changed, 103 insertions(+) create mode 100644 usr.bin/awk/b.c.diff create mode 100644 usr.bin/awk/main.c.diff create mode 100644 usr.bin/awk/run.c.diff diff --git a/usr.bin/awk/Makefile b/usr.bin/awk/Makefile index 1d3642b6a832..87eaa4166b86 100644 --- a/usr.bin/awk/Makefile +++ b/usr.bin/awk/Makefile @@ -29,4 +29,10 @@ CLEANFILES+= nawk.1 nawk.1: awk.1 cat ${.ALLSRC} > ${.TARGET} +.for f in b.c main.c run.c +${f}: ${AWKSRC}/${f} ${.CURDIR}/${f}.diff + patch -s -b .orig -o ${.TARGET} < ${.CURDIR}/${f}.diff ${AWKSRC}/${f} +CLEANFILES+= ${f} +.endfor + .include diff --git a/usr.bin/awk/b.c.diff b/usr.bin/awk/b.c.diff new file mode 100644 index 000000000000..2f6b2225c9ec --- /dev/null +++ b/usr.bin/awk/b.c.diff @@ -0,0 +1,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, 0)) + FATAL("out of space for character class [%.10s...] 2", p); +- *bp++ = ++c; ++ *bp++ = j; + i++; + } + continue; diff --git a/usr.bin/awk/main.c.diff b/usr.bin/awk/main.c.diff new file mode 100644 index 000000000000..a9d23260cf8b --- /dev/null +++ b/usr.bin/awk/main.c.diff @@ -0,0 +1,26 @@ +$FreeBSD$ + +Index: main.c +=================================================================== +RCS file: /home/ncvs/src/contrib/one-true-awk/main.c,v +retrieving revision 1.1.1.10 +diff -u -p -r1.1.1.10 main.c +--- main.c 16 May 2005 19:11:31 -0000 1.1.1.10 ++++ main.c 17 May 2005 14:41:20 -0000 +@@ -22,7 +22,7 @@ ARISING OUT OF OR IN CONNECTION WITH THE + THIS SOFTWARE. + ****************************************************************/ + +-const char *version = "version 20050424"; ++const char *version = "version 20050424 (FreeBSD)"; + + #define DEBUG + #include +@@ -58,6 +58,7 @@ int main(int argc, char *argv[]) + const char *fs = NULL; + + setlocale(LC_CTYPE, ""); ++ setlocale(LC_COLLATE, ""); + setlocale(LC_NUMERIC, "C"); /* for parsing cmdline & prog */ + cmdname = argv[0]; + if (argc == 1) { diff --git a/usr.bin/awk/run.c.diff b/usr.bin/awk/run.c.diff new file mode 100644 index 000000000000..d4912507ee5c --- /dev/null +++ b/usr.bin/awk/run.c.diff @@ -0,0 +1,18 @@ +$FreeBSD$ + +Index: run.c +=================================================================== +RCS file: /home/ncvs/src/contrib/one-true-awk/run.c,v +retrieving revision 1.1.1.8 +diff -u -p -r1.1.1.8 run.c +--- run.c 16 May 2005 19:11:35 -0000 1.1.1.8 ++++ run.c 16 May 2005 19:12:47 -0000 +@@ -651,7 +651,7 @@ Cell *relop(Node **a, int n) /* a[0 < a[ + j = x->fval - y->fval; + i = j<0? -1: (j>0? 1: 0); + } else { +- i = strcmp(getsval(x), getsval(y)); ++ i = strcoll(getsval(x), getsval(y)); + } + tempfree(x); + tempfree(y);