From 4b11d231c1c54e515e93f605bdf88f333889ca98 Mon Sep 17 00:00:00 2001 From: Jephte CLAIN Date: Wed, 17 Dec 2014 11:25:17 +0400 Subject: [PATCH] optimiser pour les chaines longues --- lib/ulib/.ulibver | 2 +- lib/ulib/base.args | 12 ++++++------ lib/ulib/base.core | 9 ++++++--- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/ulib/.ulibver b/lib/ulib/.ulibver index b2ea0de..e1a1aeb 100644 --- a/lib/ulib/.ulibver +++ b/lib/ulib/.ulibver @@ -1 +1 @@ -007008000 +007009000 diff --git a/lib/ulib/base.args b/lib/ulib/base.args index 341bd9d..6dc0c27 100644 --- a/lib/ulib/base.args +++ b/lib/ulib/base.args @@ -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" diff --git a/lib/ulib/base.core b/lib/ulib/base.core index 11e75ce..1a6bb0f 100644 --- a/lib/ulib/base.core +++ b/lib/ulib/base.core @@ -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 "$@"