zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: `print -C' column spacing
@ 2002-12-11 14:33 Peter Stephenson
  2002-12-11 17:07 ` DervishD
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Stephenson @ 2002-12-11 14:33 UTC (permalink / raw)
  To: Zsh hackers list

This improves the output from print -C by ignoring the width of the
final column.  Otherwise, you could end up with silly spacing.  For
example,

typeset -A testass
testass=(m /a/very/very/long/name/which/should/not/have/any/effect
s /another/long/name/which/still/shouldn\'t\ do\ anything.)
print -aC 2 ${(kv)testass}

pushed the long value names to the right unnecessarily.  This means you
can get better spacing if you select the number of columns
yourself rather than relying on print -c; this could be fixed, but it
would have to be iterative.

Index: Src/builtin.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v
retrieving revision 1.91
diff -u -r1.91 builtin.c
--- Src/builtin.c	20 Nov 2002 12:37:45 -0000	1.91
+++ Src/builtin.c	11 Dec 2002 14:28:08 -0000
@@ -3214,20 +3214,6 @@
 	int l, nc, nr, sc, n, t, i;
 	char **ap;
 
-	/*
-	 * 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;
-
-	/*
-	 * sc: column width
-	 * nc: number of columns (at least one)
-	 */
-	sc = l + 2;
 	if (OPT_ISSET(ops,'C')) {
 	    char *eptr, *argptr = OPT_ARG(ops,'C');
 	    nc = (int)zstrtol(argptr, &eptr, 10);
@@ -3239,14 +3225,56 @@
 		zwarnnam(name, "invalid number of columns: %s", argptr, 0);
 		return 1;
 	    }
+	    /*
+	     * n: number of elements
+	     * nc: number of columns
+	     * nr: number of rows
+	     */
+	    n = arrlen(args);
+	    nr = (n + nc - 1) / nc;
+
+	    /*
+	     * 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++) {
+		if (OPT_ISSET(ops, 'a')) {
+		    if ((i % nc) == nc - 1)
+			continue;
+		} else {
+		    if (i >= nr * (nc - 1))
+			break;
+		}
+		if (l < (t = strlen(*ap)))
+		    l = t;
+	    }
+	    sc = l + 2;
 	}
 	else
 	{
+	    /*
+	     * 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;
+
+	    /*
+	     * sc: column width
+	     * nc: number of columns (at least one)
+	     */
+	    sc = l + 2;
 	    nc = (columns + 1) / sc;
 	    if (!nc)
 		nc = 1;
+	    nr = (n + nc - 1) / nc;
 	}
-	nr = (n + nc - 1) / nc;
 
 	if (OPT_ISSET(ops,'a'))	/* print across, i.e. columns first */
 	    ap = args;

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 692070


**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential 
and/or privileged material. 
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by 
persons or entities other than the intended recipient is 
prohibited.  
If you received this in error, please contact the sender and 
delete the material from any computer.
**********************************************************************


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: PATCH: `print -C' column spacing
  2002-12-11 14:33 PATCH: `print -C' column spacing Peter Stephenson
@ 2002-12-11 17:07 ` DervishD
  2002-12-11 17:35   ` Peter Stephenson
  0 siblings, 1 reply; 4+ messages in thread
From: DervishD @ 2002-12-11 17:07 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: Zsh hackers list

    Hi Peter :)

    Just a slightly related question O:). When will be zsh have a new
release with all those cool patches that I've been seeing lately?

    Raúl


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: PATCH: `print -C' column spacing
  2002-12-11 17:07 ` DervishD
@ 2002-12-11 17:35   ` Peter Stephenson
  2002-12-12 12:00     ` DervishD
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Stephenson @ 2002-12-11 17:35 UTC (permalink / raw)
  To: Zsh hackers list

DervishD wrote:
>     Just a slightly related question O:). When will be zsh have a new
> release with all those cool patches that I've been seeing lately?

Very good question.  Very, very good question.  Yes.  Errr...

The original answer was `when we've added all the great new features
we're going to add'.  Since this seems to be infinitely delayed ---
certainly anything I was planning on doing --- we could probably aim to
get out what we have early next year.

I have a pile of scripts as a front end to the tcp stuff which are
reasonably stable since I've been using them every day for months.
However, they need documenting.  Apart from that, there's nothing I'm
likely to get done any time soon.

It would be really nice to sort out the library dependencies, but that
needs thought as well as action.

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 692070


**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential 
and/or privileged material. 
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by 
persons or entities other than the intended recipient is 
prohibited.  
If you received this in error, please contact the sender and 
delete the material from any computer.
**********************************************************************


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: PATCH: `print -C' column spacing
  2002-12-11 17:35   ` Peter Stephenson
@ 2002-12-12 12:00     ` DervishD
  0 siblings, 0 replies; 4+ messages in thread
From: DervishD @ 2002-12-12 12:00 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: Zsh hackers list

    Hi Peter :)

> >     Just a slightly related question O:). When will be zsh have a new
> > release with all those cool patches that I've been seeing lately?
> Very good question.  Very, very good question.  Yes.  Errr...

    Well, you now, there's no need to hurry up. It's just that I'm in
love with this dammit shell ;)) and I'm impatient for a new release
with even more power and cool things O:))

    All zsh-workers are doing a very good job. My Linux have changed
a lot since I dropped bash ;))

    BTW, I still maintain a featureless copy of bash as my /bin/sh,
since all brain-damaged shell scripts from GNU still use non portable
bashisms, although they claim Bourne compatibility... :(( When I
release a shell script, I write it portably, without any -ism, but
I'm sure that if I ever need to write a non-portable one, I'll do
with Zsh. More features, less bloat.

    Raúl


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2002-12-12 12:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-12-11 14:33 PATCH: `print -C' column spacing Peter Stephenson
2002-12-11 17:07 ` DervishD
2002-12-11 17:35   ` Peter Stephenson
2002-12-12 12:00     ` DervishD

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).