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_}"
|
name_="names_[$i_]"; name_="${!name_}"
|
||||||
flag_="flags_[$i_]"; flag_="${!flag_}"
|
flag_="flags_[$i_]"; flag_="${!flag_}"
|
||||||
function inc@ { eval "let $1=\$$1+1"; }
|
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}"; }
|
function add@ { array_add "$1" "${value_:-$2}"; }
|
||||||
if [ -z "$name_" ]; then
|
if [ -z "$name_" ]; then
|
||||||
# option non reconnue. ce cas aurait dû être traité par
|
# option non reconnue. ce cas aurait dû être traité par
|
||||||
|
@ -198,16 +198,16 @@ function __po_process_options() {
|
||||||
eval "${name_#\$}"
|
eval "${name_#\$}"
|
||||||
elif [ "$flag_" == "" ]; then
|
elif [ "$flag_" == "" ]; then
|
||||||
if [[ "$name_" == *=* ]]; then
|
if [[ "$name_" == *=* ]]; then
|
||||||
set_var "${name_%%=*}" "${name_#*=}"
|
setv "${name_%%=*}" "${name_#*=}"
|
||||||
else
|
else
|
||||||
inc@ "$name_"
|
inc@ "$name_"
|
||||||
fi
|
fi
|
||||||
elif [ "$flag_" == ":" -o "$flag_" == "::" ]; then
|
elif [ "$flag_" == ":" -o "$flag_" == "::" ]; then
|
||||||
value_="$2"; shift
|
value_="$2"; shift
|
||||||
if [ "${name_%=}" != "$name_" ]; then
|
if [ "${name_%=}" != "$name_" ]; then
|
||||||
set_var "${name_%=}" "$value_"
|
setv "${name_%=}" "$value_"
|
||||||
elif [[ "$name_" == *=* ]]; then
|
elif [[ "$name_" == *=* ]]; then
|
||||||
set_var "${name_%%=*}" "${name_#*=}"
|
setv "${name_%%=*}" "${name_#*=}"
|
||||||
else
|
else
|
||||||
array_add "$name_" "$value_"
|
array_add "$name_" "$value_"
|
||||||
fi
|
fi
|
||||||
|
@ -296,7 +296,7 @@ function parse_opts() {
|
||||||
eval "set -- $args_"
|
eval "set -- $args_"
|
||||||
__po_process_options "$@"
|
__po_process_options "$@"
|
||||||
else
|
else
|
||||||
[ -n "$destargs_" ] && set_var "$destargs_" "$args_"
|
[ -n "$destargs_" ] && setv "$destargs_" "$args_"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
@ -394,7 +394,7 @@ function genparse() {
|
||||||
name="${option//-/_}"
|
name="${option//-/_}"
|
||||||
array_add names "$name"
|
array_add names "$name"
|
||||||
array_add descs "${shortopt:+-$shortopt, }--$option VALUE"
|
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="
|
array_add options "${shortopt:+-$shortopt:,}--$option: $name="
|
||||||
else
|
else
|
||||||
name="$var"
|
name="$var"
|
||||||
|
|
|
@ -45,7 +45,10 @@ function _qval() {
|
||||||
}
|
}
|
||||||
function should_quote() {
|
function should_quote() {
|
||||||
# Tester si la chaine $* doit être mise entre quotes
|
# 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]/}"
|
local s="${*//[a-zA-Z0-9]/}"
|
||||||
s="${s//,/}"
|
s="${s//,/}"
|
||||||
s="${s//./}"
|
s="${s//./}"
|
||||||
|
@ -115,13 +118,13 @@ function setv() {
|
||||||
set -- "${__s_var#*=}" "$@"
|
set -- "${__s_var#*=}" "$@"
|
||||||
__s_var="${__s_var%%=*}"
|
__s_var="${__s_var%%=*}"
|
||||||
fi
|
fi
|
||||||
eval "$__s_var=\"$(_qval "$*")\""
|
eval "$__s_var=\"\$*\""
|
||||||
}
|
}
|
||||||
function _setv() {
|
function _setv() {
|
||||||
# Comme la fonction setv() mais ne supporte que la syntaxe '_setv var values...'
|
# Comme la fonction setv() mais ne supporte que la syntaxe '_setv var values...'
|
||||||
# Cette fonction est légèrement plus rapide que setv()
|
# Cette fonction est légèrement plus rapide que setv()
|
||||||
local __s_var="$1"; shift
|
local __s_var="$1"; shift
|
||||||
eval "$__s_var=\"$(_qval "$*")\""
|
eval "$__s_var=\"\$*\""
|
||||||
}
|
}
|
||||||
function echo_setv() {
|
function echo_setv() {
|
||||||
# Afficher la commande qui serait lancée par setv "$@"
|
# Afficher la commande qui serait lancée par setv "$@"
|
||||||
|
|
Loading…
Reference in New Issue