• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

タグ
未設定

よく使われているワード(クリックで追加)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

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.

変更サマリ

差分

--- a/src/modules/optdefn.sh
+++ b/src/modules/optdefn.sh
@@ -202,7 +202,7 @@
202202 # upon to support optional option-argument processing).
203203 #
204204 do opt=`echo "$arg" | cut -c1` arg=`echo "$arg" | cut -c2-`
205- have_optmatch=false
205+ have_optmatch=false argshift=0
206206 for optchr in $shortopts '??'
207207 do $have_optmatch || {
208208 # We haven't found a match for the current character...
@@ -224,6 +224,7 @@
224224 # accepts an argument, propagate any residual of this
225225 # option string as an argument...
226226 #
227+ test "x$arg" = x || argshift=1
227228 have_optmatch=true optmatch=$opt
228229 eval '${'$opt'_optional_argument-false}' &&
229230 optarg=$arg arg=
@@ -275,12 +276,18 @@
275276 #
276277 *=*) optarg="`echo "$arg" | sed 's,^[^=]*=,,'`"
277278 arg="`IFS='='; set -- $arg; defn_parameter_list $1`"
279+ argshift=1
278280 ;;
279281 # North american users don't distinguish "licence"
280282 # and "license", and will generally adopt the latter
281283 # spelling; accept this, as a special case.
282284 #
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
284291 esac
285292
286293 for opt in $longopts
@@ -318,6 +325,10 @@
318325 # with the original "$@" argument vector from "optchk" itself.
319326 #
320327 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
321332 opteval_$optmatch "$@"
322333 }
323334
--- a/src/modules/options.sh
+++ b/src/modules/options.sh
@@ -45,13 +45,13 @@
4545 optdefine c stdout
4646 opteval_stdout(){ OUTPUT_STREAMING_OPTION=stdout; }
4747
48- optdefine option
48+ optdefine option requires_argument
4949 opteval_option(){ option $optarg; }
5050
51- optdefine arch
51+ optdefine arch requires_argument
5252 opteval_arch(){ ARCH="$optarg"; }
5353
54- optdefine srcdir
54+ optdefine srcdir requires_argument
5555 opteval_srcdir(){
5656 mkdir -p .$cmd && echo "PACKAGE_SRCDIR=\"$optarg\"" > .$cmd/srcdir.sh
5757 PACKAGE_SRCDIR="$optarg"