zsh-users
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@csr.com>
To: Mariusz Gniazdowski <cellsan@interia.pl>, zsh-users@sunsite.dk
Subject: Re: while read; problems
Date: Mon, 25 Apr 2005 11:14:50 +0100	[thread overview]
Message-ID: <200504251014.j3PAEoF5010900@news01.csr.com> (raw)
In-Reply-To: <20050422122206.GA11327@globtel.pl>

Mariusz Gniazdowski wrote:
> function count {
>         local line max=0 idx=0 maxidx=0
>         while read line; do
>                 line=${#line}
>                 (( idx++ ))
>                 [[ $max -lt $line ]] && { max=$line; maxidx=$idx; }
>         done < "$1"
>         echo "$max in line nr: $maxidx" 
> }                         
> 
> Second problem: zsh results differ from run to run. I had results like:
> 6097 in line nr: 169
> 6553 in line nr: 300
> etc.

Luckily, with debugging turned on, this output an error message
so I could find it without too much trouble.  It's yet another problem
with Meta characters.  (If this doesn't fix it report it again.)

Note that the bug turned up in the code which strips trailing whitespace
from the line.  This is the correct behaviour, but it's a not clear it's
what you want in a binary file.  You may need to set IFS to empty, as
DervishD mentioned.

Further discussion on the bug should go to zsh-workers.

Index: Src/builtin.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v
retrieving revision 1.136
diff -u -r1.136 builtin.c
--- Src/builtin.c	9 Mar 2005 17:14:06 -0000	1.136
+++ Src/builtin.c	25 Apr 2005 10:09:21 -0000
@@ -4747,8 +4747,17 @@
 	}
 	signal_setmask(s);
     }
-    while (bptr > buf && iwsep(bptr[-1]))
-	bptr--;
+    while (bptr > buf) {
+	if (bptr > buf + 1 && bptr[-2] == Meta) {
+	    if (iwsep(bptr[-1] ^ 32))
+		bptr -= 2;
+	    else
+		break;
+	} else if (iwsep(bptr[-1]))
+	    bptr--;
+	else
+	    break;
+    }
     *bptr = '\0';
     if (resettty && SHTTY != -1)
 	settyinfo(&saveti);

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

**********************************************************************


      parent reply	other threads:[~2005-04-25 10:15 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-04-22 12:22 Mariusz Gniazdowski
2005-04-22 14:36 ` DervishD
2005-04-25 10:14 ` Peter Stephenson [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200504251014.j3PAEoF5010900@news01.csr.com \
    --to=pws@csr.com \
    --cc=cellsan@interia.pl \
    --cc=zsh-users@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).