diff options
author | Roger A. Faulkner <Roger.Faulkner@Oracle.COM> | 2010-04-03 09:48:44 -0700 |
---|---|---|
committer | Roger A. Faulkner <Roger.Faulkner@Oracle.COM> | 2010-04-03 09:48:44 -0700 |
commit | 3e14f97f673e8a630f076077de35afdd43dc1587 (patch) | |
tree | 9828b6b676f58d7b27dd28e00202d3f3461a5cd8 /usr/src/lib/libcmd/common/wclib.c | |
parent | 4f60987df4dcaa54a88b596f861fbf4f3382c65e (diff) | |
download | illumos-joyent-3e14f97f673e8a630f076077de35afdd43dc1587.tar.gz |
6939349 RFE: Update ksh93 to ast-ksh.2010-03-09
6877392 ksh93 regresses 'uniq -c' performance
6887363 Korn shell 93 sometimes mishandles return value of its child process
6900314 (while true ; do true|true ; done) hang in ioctl() with SIGTTOU
6904557 wc no longer counts number of bytes correctly
6904575 cut -d with multibyte character no longer works
6904597 paste -d no longer works with multibyte characters
6904780 /usr/bin/cksum changed output in snv_128
6904870 uniq -s does not skip multibyte characters correctly
6904878 join -t no longer works with multibyte char separator
6907460 EXIT trap handlers are sometimes executed twice
6909579 libast getopt solaris compatibility broken
6920072 ksh93 tail -f, with unconditional .25s sleep and line parsing, about 37x slower than cat
6932124 mktemp in ksh93 is broken
Contributed by Olga Kryzhanovska <olga.kryzhanovska@gmail.com>
Diffstat (limited to 'usr/src/lib/libcmd/common/wclib.c')
-rw-r--r-- | usr/src/lib/libcmd/common/wclib.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/usr/src/lib/libcmd/common/wclib.c b/usr/src/lib/libcmd/common/wclib.c index c7ce5a338a..77732723ab 100644 --- a/usr/src/lib/libcmd/common/wclib.c +++ b/usr/src/lib/libcmd/common/wclib.c @@ -1,7 +1,7 @@ /*********************************************************************** * * * This software is part of the ast package * -* Copyright (c) 1992-2009 AT&T Intellectual Property * +* Copyright (c) 1992-2010 AT&T Intellectual Property * * and is licensed under the * * Common Public License, Version 1.0 * * by AT&T Intellectual Property * @@ -52,7 +52,7 @@ #define eol(c) ((c)&WC_NL) #define mbc(c) ((c)&WC_MB) #define spc(c) ((c)&WC_SP) -#define mbwc(w,p,n) (*ast.mb_towc)(&w,(char*)p,n) +#define mb2wc(w,p,n) (*ast.mb_towc)(&w,(char*)p,n) Wc_t* wc_init(int mode) { @@ -163,6 +163,7 @@ int wc_count(Wc_t *wp, Sfio_t *fd, const char* file) { register char* type = wp->type; register unsigned char* cp; + register Sfoff_t nbytes; register Sfoff_t nchars; register Sfoff_t nwords; register Sfoff_t nlines; @@ -179,14 +180,14 @@ int wc_count(Wc_t *wp, Sfio_t *fd, const char* file) unsigned char side[32]; sfset(fd,SF_WRITE,1); - nlines = nwords = nchars = 0; + nlines = nwords = nchars = nbytes = 0; wp->longest = 0; if (wp->mb < 0 && (wp->mode & (WC_MBYTE|WC_WORDS))) { cp = buff = endbuff = 0; for (;;) { - if (cp >= endbuff || (n = mbwc(x, cp, endbuff-cp)) < 0) + if (cp >= endbuff || (n = mb2wc(x, cp, endbuff-cp)) < 0) { if ((o = endbuff-cp) < sizeof(side)) { @@ -205,6 +206,7 @@ int wc_count(Wc_t *wp, Sfio_t *fd, const char* file) wp->longest = nchars - longest; break; } + nbytes += n; if ((c = sizeof(side) - o) > n) c = n; if (c) @@ -247,6 +249,8 @@ int wc_count(Wc_t *wp, Sfio_t *fd, const char* file) } nchars++; } + if (!(wp->mode & WC_MBYTE)) + nchars = nbytes; } else if (!wp->mb && !(wp->mode & WC_LONGEST) || wp->mb > 0 && !(wp->mode & (WC_MBYTE|WC_WORDS|WC_LONGEST))) { @@ -343,6 +347,7 @@ int wc_count(Wc_t *wp, Sfio_t *fd, const char* file) xspace = iswspace(0xa0) || iswspace(0x85); while ((cp = buff = (unsigned char*)sfreserve(fd, SF_UNBOUND, 0)) && (c = sfvalue(fd)) > 0) { + nbytes += c; nchars += c; start = cp-lineoff; /* check to see whether first character terminates word */ @@ -487,7 +492,10 @@ int wc_count(Wc_t *wp, Sfio_t *fd, const char* file) nlines++; else if (!lasttype) nwords++; - nchars -= adjust; + if (wp->mode & WC_MBYTE) + nchars -= adjust; + else + nchars = nbytes; } wp->chars = nchars; wp->words = nwords; |