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

Re: zargs error with some combinations of arguments



I think we're both proposing basically the same change. It looks like
the format of my context diff hid the use of the calculated 'a' value
later in the code. Here's the diff listing from git:

diff --git a/Functions/Misc/zargs b/Functions/Misc/zargs
index 782d681..c7e96b8 100644
--- a/Functions/Misc/zargs
+++ b/Functions/Misc/zargs
@@ -194,7 +194,7 @@ else
     return 1
 fi

-local -i end c=0
+local -i end a c=0
 if [[ $eof == -(e|-eof) ]]; then ((end=ARGC+1))
 elif (( $#eof )); then end=$argv[(i)${eof##-(e|-eof=)}]
 else end=$argv[(i)--]
@@ -265,6 +265,13 @@ then
     return 1
 fi

+(( a = s - ${#:-"$command "} ))
+if (( a <= 0 ))
+then
+    print -u2 'zargs: value for max-chars must be >= command length'
+    return 1
+fi
+
 l=${${${l##*-(l|L|-max-lines(=|))}[-1]}:-${${l[1]:+1}:-$ARGC}}
 if (( l <= 0 ))
 then
@@ -305,7 +312,7 @@ do
     repeat $P
     do
        ((ARGC)) || break
-       for (( end=l; end && ${(c)#argv[1,end]} > s; end/=2 )) { }
+       for (( end=l; end && ${(c)#argv[1,end]} > a; end/=2 )) { }
        (( end > n && ( end = n ) ))
        args=( "${(@)argv[1,end]}" )
        shift $((end > ARGC ? ARGC : end))


In this line:
  (( a = s - ${#:-"$command "} ))
's' is the max size of the total command line. The calculated value
'a' represents the maximum number of characters that can be used for
arguments to the command. It's stored in a variable to avoid
recalculating it each time in the primary nested loop.

The 'command' variable is an array, and we also need a space for the
separator between the command and the parameters. ${#:-"$command "}
was my (possibly too cute) way of calculating the total length of the
command plus the space. This should give the same result:
  (( a = s - ${(c)#command} - 1 ))


The error message after the 'a <= 0' test is only going to occur
with some edge cases and nonsensical parameters, e.g.:

  zargs -s 10 -- a b c -- somelongcmd

It's not really needed. If the command is too large, the 'cannot fit
single argument within size limit' error message will do the job.


Thanks for looking into this,
Awk




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