Experimental package creation tool for MinGW.org
リビジョン | 6c575bca840b1b8c556fb22ac51036819e3b2148 (tree) |
---|---|
日時 | 2018-05-16 18:09:45 |
作者 | Keith Marshall <keith@user...> |
コミッター | Keith Marshall |
Robustly interpret options with mandatory arguments.
* src/modules/optdefn.sh (optchk) [-*]
(optchk_getopt_long) [-*, --*]: Clear argshift value, when it may
require adjustment to accommodate a detached argument, and then...
(opteval): ...adjust it to 1 or 2, as appropriate; validate...
[argshift == 2 && $# >= 2]: ...else diagnose and abort.
* src/modules/options.sh (arch, option, srcdir): Add...
[requires_argument]: ...this property qualifier.
@@ -202,7 +202,7 @@ | ||
202 | 202 | # upon to support optional option-argument processing). |
203 | 203 | # |
204 | 204 | do opt=`echo "$arg" | cut -c1` arg=`echo "$arg" | cut -c2-` |
205 | - have_optmatch=false | |
205 | + have_optmatch=false argshift=0 | |
206 | 206 | for optchr in $shortopts '??' |
207 | 207 | do $have_optmatch || { |
208 | 208 | # We haven't found a match for the current character... |
@@ -224,6 +224,7 @@ | ||
224 | 224 | # accepts an argument, propagate any residual of this |
225 | 225 | # option string as an argument... |
226 | 226 | # |
227 | + test "x$arg" = x || argshift=1 | |
227 | 228 | have_optmatch=true optmatch=$opt |
228 | 229 | eval '${'$opt'_optional_argument-false}' && |
229 | 230 | optarg=$arg arg= |
@@ -275,12 +276,18 @@ | ||
275 | 276 | # |
276 | 277 | *=*) optarg="`echo "$arg" | sed 's,^[^=]*=,,'`" |
277 | 278 | arg="`IFS='='; set -- $arg; defn_parameter_list $1`" |
279 | + argshift=1 | |
278 | 280 | ;; |
279 | 281 | # North american users don't distinguish "licence" |
280 | 282 | # and "license", and will generally adopt the latter |
281 | 283 | # spelling; accept this, as a special case. |
282 | 284 | # |
283 | - --licens | --license) arg="--licence" | |
285 | + --licens | --license) arg="--licence" ;; | |
286 | + | |
287 | + # For any other possible match, force a $argshift adjustment, | |
288 | + # to accommodate a possibly detached mandatory argument. | |
289 | + # | |
290 | + *) argshift=0 | |
284 | 291 | esac |
285 | 292 | |
286 | 293 | for opt in $longopts |
@@ -318,6 +325,10 @@ | ||
318 | 325 | # with the original "$@" argument vector from "optchk" itself. |
319 | 326 | # |
320 | 327 | test "x$optmatch" = x && optmatch_unknown "$1" |
328 | + test $argshift -eq 0 && eval '${'$optmatch'_requires_argument-false}' && { | |
329 | + test $# -ge 2 || die "option '$optmatch' requires an argument" | |
330 | + optarg="$2" argshift=2 | |
331 | + } || argshift=1 | |
321 | 332 | opteval_$optmatch "$@" |
322 | 333 | } |
323 | 334 |
@@ -45,13 +45,13 @@ | ||
45 | 45 | optdefine c stdout |
46 | 46 | opteval_stdout(){ OUTPUT_STREAMING_OPTION=stdout; } |
47 | 47 | |
48 | - optdefine option | |
48 | + optdefine option requires_argument | |
49 | 49 | opteval_option(){ option $optarg; } |
50 | 50 | |
51 | - optdefine arch | |
51 | + optdefine arch requires_argument | |
52 | 52 | opteval_arch(){ ARCH="$optarg"; } |
53 | 53 | |
54 | - optdefine srcdir | |
54 | + optdefine srcdir requires_argument | |
55 | 55 | opteval_srcdir(){ |
56 | 56 | mkdir -p .$cmd && echo "PACKAGE_SRCDIR=\"$optarg\"" > .$cmd/srcdir.sh |
57 | 57 | PACKAGE_SRCDIR="$optarg" |