optimiser pour les chaines longues
This commit is contained in:
parent
7cf63355fd
commit
4b11d231c1
|
@ -1 +1 @@
|
|||
007008000
|
||||
007009000
|
||||
|
|
|
@ -181,7 +181,7 @@ function __po_process_options() {
|
|||
name_="names_[$i_]"; name_="${!name_}"
|
||||
flag_="flags_[$i_]"; flag_="${!flag_}"
|
||||
function inc@ { eval "let $1=\$$1+1"; }
|
||||
function res@ { set_var "$1" "${value_:-$2}"; }
|
||||
function res@ { setv "$1" "${value_:-$2}"; }
|
||||
function add@ { array_add "$1" "${value_:-$2}"; }
|
||||
if [ -z "$name_" ]; then
|
||||
# option non reconnue. ce cas aurait dû être traité par
|
||||
|
@ -198,16 +198,16 @@ function __po_process_options() {
|
|||
eval "${name_#\$}"
|
||||
elif [ "$flag_" == "" ]; then
|
||||
if [[ "$name_" == *=* ]]; then
|
||||
set_var "${name_%%=*}" "${name_#*=}"
|
||||
setv "${name_%%=*}" "${name_#*=}"
|
||||
else
|
||||
inc@ "$name_"
|
||||
fi
|
||||
elif [ "$flag_" == ":" -o "$flag_" == "::" ]; then
|
||||
value_="$2"; shift
|
||||
if [ "${name_%=}" != "$name_" ]; then
|
||||
set_var "${name_%=}" "$value_"
|
||||
setv "${name_%=}" "$value_"
|
||||
elif [[ "$name_" == *=* ]]; then
|
||||
set_var "${name_%%=*}" "${name_#*=}"
|
||||
setv "${name_%%=*}" "${name_#*=}"
|
||||
else
|
||||
array_add "$name_" "$value_"
|
||||
fi
|
||||
|
@ -296,7 +296,7 @@ function parse_opts() {
|
|||
eval "set -- $args_"
|
||||
__po_process_options "$@"
|
||||
else
|
||||
[ -n "$destargs_" ] && set_var "$destargs_" "$args_"
|
||||
[ -n "$destargs_" ] && setv "$destargs_" "$args_"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
@ -394,7 +394,7 @@ function genparse() {
|
|||
name="${option//-/_}"
|
||||
array_add names "$name"
|
||||
array_add descs "${shortopt:+-$shortopt, }--$option VALUE"
|
||||
array_add vars "$(set_var_cmd "$name" "$value")"
|
||||
array_add vars "$(echo_setv "$name" "$value")"
|
||||
array_add options "${shortopt:+-$shortopt:,}--$option: $name="
|
||||
else
|
||||
name="$var"
|
||||
|
|
|
@ -45,7 +45,10 @@ function _qval() {
|
|||
}
|
||||
function should_quote() {
|
||||
# Tester si la chaine $* doit être mise entre quotes
|
||||
[ -z "$1" ] && return 0
|
||||
local l="${#1}"
|
||||
# pour optimiser, toujours mettre entre quotes une chaine vide ou de plus de 80 caractères
|
||||
[ $l -eq 0 -o $l -gt 80 ] && return 0
|
||||
# sinon, tester si la chaine contient des caractères spéciaux
|
||||
local s="${*//[a-zA-Z0-9]/}"
|
||||
s="${s//,/}"
|
||||
s="${s//./}"
|
||||
|
@ -115,13 +118,13 @@ function setv() {
|
|||
set -- "${__s_var#*=}" "$@"
|
||||
__s_var="${__s_var%%=*}"
|
||||
fi
|
||||
eval "$__s_var=\"$(_qval "$*")\""
|
||||
eval "$__s_var=\"\$*\""
|
||||
}
|
||||
function _setv() {
|
||||
# Comme la fonction setv() mais ne supporte que la syntaxe '_setv var values...'
|
||||
# Cette fonction est légèrement plus rapide que setv()
|
||||
local __s_var="$1"; shift
|
||||
eval "$__s_var=\"$(_qval "$*")\""
|
||||
eval "$__s_var=\"\$*\""
|
||||
}
|
||||
function echo_setv() {
|
||||
# Afficher la commande qui serait lancée par setv "$@"
|
||||
|
|
Loading…
Reference in New Issue