libtool-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Add an XSI replacement for func_split_short_opt.


From: Paolo Bonzini
Subject: Re: [PATCH] Add an XSI replacement for func_split_short_opt.
Date: Tue, 29 Jun 2010 10:21:11 +0200
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.10) Gecko/20100621 Fedora/3.0.5-1.fc13 Lightning/1.0b2pre Thunderbird/3.0.5

On 06/29/2010 08:52 AM, Gary V. Vaughan wrote:
Well, really the problem is this:

while $# -gt 0; do
   opt=$1; shift
   case $opt in
     -p) opt_p="$1"; shift ;;
     -q) opt_q="$1"; shift ;;
     -x) opt_x=: ;;
     -y) opt_y=: ;;

     -p*|-q*) # option args
         func_split_short_arg $opt
         set dummy $arg "$rest" ${1+"$@"}; shift ;;

     -x*|-y*) # non-option args
         func_split_short_arg $opt
         set dummy $arg -$rest ${1+"$@"}; shift ;;
   esac
done

So, we know there will always be at least 3 characters available in $1
by the time we reach func_split_short_arg.  Also we don't really discard
the leading '-'.  Which means that this works correctly:

func_split_short_arg ()
{
   arg="$1"; while test ${#arg} -gt 2; do arg="${arg%?}"; done
   rest=${1%??}
}

What about

func_split_short_arg () {
  rest=${1#??};
  arg=${1%"$rest"};
}

The quoting ensures that it works even if a star is present in $1:

$ func_split_short_arg -X*YZ ; echo $arg; echo $rest
-X
*YZ
$ func_split_short_arg -X????YZ ; echo $arg; echo $rest
-X
????YZ

Paolo



reply via email to

[Prev in Thread] Current Thread [Next in Thread]