From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3395 invoked from network); 10 Dec 2006 23:18:13 -0000 X-Spam-Checker-Version: SpamAssassin 3.1.7 (2006-10-05) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00, FORGED_RCVD_HELO autolearn=ham version=3.1.7 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 10 Dec 2006 23:18:13 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 41458 invoked from network); 10 Dec 2006 23:18:02 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 10 Dec 2006 23:18:02 -0000 Received: (qmail 202 invoked by alias); 10 Dec 2006 23:17:59 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 23044 Received: (qmail 192 invoked from network); 10 Dec 2006 23:17:58 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 10 Dec 2006 23:17:58 -0000 Received: (qmail 41144 invoked from network); 10 Dec 2006 23:17:58 -0000 Received: from mtaout01-winn.ispmail.ntl.com (81.103.221.47) by a.mx.sunsite.dk with SMTP; 10 Dec 2006 23:17:51 -0000 Received: from aamtaout03-winn.ispmail.ntl.com ([81.103.221.35]) by mtaout01-winn.ispmail.ntl.com with ESMTP id <20061210231833.CVSH15018.mtaout01-winn.ispmail.ntl.com@aamtaout03-winn.ispmail.ntl.com> for ; Sun, 10 Dec 2006 23:18:33 +0000 Received: from pwslaptop.csr.com ([81.107.41.185]) by aamtaout03-winn.ispmail.ntl.com with SMTP id <20061210231927.CIWT26699.aamtaout03-winn.ispmail.ntl.com@pwslaptop.csr.com> for ; Sun, 10 Dec 2006 23:19:27 +0000 Date: Sun, 10 Dec 2006 23:17:43 +0000 From: Peter Stephenson To: zsh-workers@sunsite.dk Subject: Re: Multibyte output confuses "print -c" ? Message-Id: <20061210231743.25a463bc.p.w.stephenson@ntlworld.com> In-Reply-To: <061210133500.ZM16552@torch.brasslantern.com> References: <061210133500.ZM16552@torch.brasslantern.com> X-Mailer: Sylpheed version 2.2.10 (GTK+ 2.10.4; i386-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Sun, 10 Dec 2006 13:34:59 -0800 Bart Schaefer wrote: > Comparing the output of "print -C 1" and "print -l" on that same expansion, > there appears first to be a problem with columnation of strings containing > a nul byte. > > zsh% print -c '<\U0000000T>' > < > zsh% print '<\U0000000T>' | cat -v > <^@T> I don't think I followed everything here, but output in columns is yet another of the seemingly infinite variants of print that no one bothered to fix up when print was altered to use unmetafied bytes with a separate length. The same seems to be true of -o and -O; I've made a note but not altered that. Index: Src/builtin.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v retrieving revision 1.170 diff -u -r1.170 builtin.c --- Src/builtin.c 11 Nov 2006 13:16:10 -0000 1.170 +++ Src/builtin.c 10 Dec 2006 23:12:52 -0000 @@ -3603,6 +3603,13 @@ } /* -o and -O -- sort the arguments */ + /* + * TODO: this appears to be yet another of the endless + * chunks of code that didn't get fixed up properly + * to reflect the fact that args contains unmetafied + * strings that may contain NULs with the lengths in + * len. + */ if (OPT_ISSET(ops,'o')) { if (fmt && !*args) return 0; if (OPT_ISSET(ops,'i')) @@ -3624,7 +3631,6 @@ /* -c -- output in columns */ if (!fmt && (OPT_ISSET(ops,'c') || OPT_ISSET(ops,'C'))) { int l, nc, nr, sc, n, t, i; - char **ap; if (OPT_ISSET(ops,'C')) { char *eptr, *argptr = OPT_ARG(ops,'C'); @@ -3647,13 +3653,12 @@ /* * i: loop counter - * ap: array iterator * l: maximum length seen * * Ignore lengths in last column since they don't affect * the separation. */ - for (i = l = 0, ap = args; *ap; ap++, i++) { + for (i = l = 0; i < argc; i++) { if (OPT_ISSET(ops, 'a')) { if ((i % nc) == nc - 1) continue; @@ -3661,8 +3666,8 @@ if (i >= nr * (nc - 1)) break; } - if (l < (t = strlen(*ap))) - l = t; + if (l < len[i]) + l = len[i]; } sc = l + 2; } @@ -3670,12 +3675,11 @@ { /* * n: loop counter - * ap: array iterator * l: maximum length seen */ - for (n = l = 0, ap = args; *ap; ap++, n++) - if (l < (t = strlen(*ap))) - l = t; + for (n = l = 0; n < argc; n++) + if (l < len[n]) + l = len[n]; /* * sc: column width @@ -3689,31 +3693,31 @@ } if (OPT_ISSET(ops,'a')) /* print across, i.e. columns first */ - ap = args; + n = 0; for (i = 0; i < nr; i++) { if (OPT_ISSET(ops,'a')) { int ic; - for (ic = 0; ic < nc && *ap; ic++, ap++) + for (ic = 0; ic < nc && n < argc; ic++, n++) { - l = strlen(*ap); - fprintf(fout, "%s", *ap); - if (*ap) + l = len[n]; + fwrite(args[n], l, 1, fout); + if (n < argc) for (; l < sc; l++) fputc(' ', fout); } } else { - ap = args + i; + n = i; do { - l = strlen(*ap); - fprintf(fout, "%s", *ap); - for (t = nr; t && *ap; t--, ap++); - if (*ap) + l = len[n]; + fwrite(args[n], l, 1, fout); + for (t = nr; t && n < argc; t--, n++); + if (n < argc) for (; l < sc; l++) fputc(' ', fout); - } while (*ap); + } while (n < argc); } fputc(OPT_ISSET(ops,'N') ? '\0' : '\n', fout); } -- Peter Stephenson Web page now at http://homepage.ntlworld.com/p.w.stephenson/