diff options
author | ru <ru@FreeBSD.org> | 2010-01-10 08:02:07 +0000 |
---|---|---|
committer | ru <ru@FreeBSD.org> | 2010-01-10 08:02:07 +0000 |
commit | 270ba02de1ffa85c9293d73669cae997f42c62b1 (patch) | |
tree | f4923317980c5c94957c3b5a4b1c4906654e92d1 /contrib/one-true-awk/b.c | |
parent | dd1716139623593608ab5a62cd153c48b97bd043 (diff) | |
download | FreeBSD-src-270ba02de1ffa85c9293d73669cae997f42c62b1.zip FreeBSD-src-270ba02de1ffa85c9293d73669cae997f42c62b1.tar.gz |
Apply patches directly to sources. Their effect is as follows:
- Make one-true-awk respect locale's collating order in [a-z]
bracket expressions, until a more complete fix (like handing
BREs) is ready.
- Don't require a space between -[fv] and its argument.
Diffstat (limited to 'contrib/one-true-awk/b.c')
-rw-r--r-- | contrib/one-true-awk/b.c | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/contrib/one-true-awk/b.c b/contrib/one-true-awk/b.c index 4c6d61b..baefe6f 100644 --- a/contrib/one-true-awk/b.c +++ b/contrib/one-true-awk/b.c @@ -24,6 +24,9 @@ THIS SOFTWARE. /* lasciate ogne speranza, voi ch'intrate. */ +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + #define DEBUG #include <ctype.h> @@ -285,9 +288,21 @@ int quoted(char **pp) /* pick up next thing after a \\ */ 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; @@ -306,15 +321,18 @@ char *cclenter(const char *argp) /* add a character class */ 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; |