Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: zsh 3.0.1 bug? read -c



Vincent Lefevre wrote:
> The first argument after "read -c" seems to be skipped, e.g.
> 
> $ repl () {
>         read -c a0 a1 a2 a3
>         echo
>         echo "a0:" $a0
>         echo "a1:" $a1
>         echo "a2:" $a2
>         echo "a3:" $a3
>         reply=()
> }
> $ compctl -K repl testrepl
> $ testrepl x y z [TAB]   (note: AUTO_MENU and LIST_AMBIGUOUS are set)
> a0:
> a1: testrepl
> a2: x
> a3: y

The patch below should fix it.  It changes the behaviour to behave more
like the the way described in the documentation.  E.g. read -c will read
all words to REPLY and read -c a b c reads the first word to a, the second
to b and the rest to c.

Zoltan


*** Src/builtin.c	1996/10/16 22:47:53	2.95
--- Src/builtin.c	1996/10/30 15:59:07
***************
*** 4980,4985 ****
--- 4980,4987 ----
  
      /* option -c is used in compctl functions */
      if (ops['c']) {
+ 	int i;
+ 
  	/* only allowed to be called by ZLE */
  	if (!inzlefunc) {
  	    zwarnnam(name, "option valid only in functions called from zle",
***************
*** 5006,5012 ****
  	    /* the -A option means that one array is specified, instead of
  	    many parameters */
  	    char **p, **b = (char **)zcalloc((clwnum + 1) * sizeof(char *));
- 	    int i;
  
  	    for (i = 0, p = b; i < clwnum; p++, i++)
  		*p = ztrdup(clwords[i]);
--- 5008,5013 ----
***************
*** 5015,5022 ****
  	    return 0;
  	}
  	if (ops['e'] || ops['E']) {
- 	    int i;
- 
  	    for (i = 0; i < clwnum; i++) {
  		zputs(clwords[i], stdout);
  		putchar('\n');
--- 5016,5021 ----
***************
*** 5025,5037 ****
  	    if (ops['e'])
  		return 0;
  	}
- 	if (*args) {
- 	    int i = 0;
  
! 	    for (; i < clwnum && *args; args++, i++)
! 		setsparam(*args, ztrdup(clwords[i]));
  	} else
! 	    setsparam("REPLY", ztrdup(clwords[clwpos]));
  
  	return 0;
      }
--- 5024,5046 ----
  	    if (ops['e'])
  		return 0;
  	}
  
! 	for (i = 0; i < clwnum && *args; reply = *args++, i++)
! 	    setsparam(reply, ztrdup(clwords[i]));
! 
! 	if (i < clwnum) {
! 	    int j, len;
! 
! 	    for (j = i, len = 0; j < clwnum; len += strlen(clwords[j++]));
! 	    bptr = buf = zalloc(len + j - i);
! 	    while (i < clwnum) {
! 		strucpy(&bptr, clwords[i++]);
! 		*bptr++ = ' ';
! 	    }
! 	    bptr[-1] = '\0';
  	} else
! 	    buf = ztrdup("");
! 	setsparam(reply, buf);
  
  	return 0;
      }



Messages sorted by: Reverse Date, Date, Thread, Author