maj des inclusions

This commit is contained in:
Jephte CLAIN 2014-09-29 21:00:07 +04:00
parent c56203afef
commit 6be3597698
3 changed files with 490 additions and 534 deletions

View File

@ -63,11 +63,15 @@ export TMPDIR="${TMPDIR:-${TMP:-${TEMP:-/tmp}}}"
[ -f /etc/nutoolsrc ] && . /etc/nutoolsrc [ -f /etc/nutoolsrc ] && . /etc/nutoolsrc
[ -f ~/.nutoolsrc ] && . ~/.nutoolsrc [ -f ~/.nutoolsrc ] && . ~/.nutoolsrc
true
##@inc]base.init ##@inc]base.init
##@inc[base.core ##@inc[base.core
## Fonctions de base: fondement ## Fonctions de base: fondement
uprovide base.core uprovide base.core
function echo_() {
echo -n "$*"
}
function recho() { function recho() {
if [[ "${1:0:2}" == -[eEn] ]]; then if [[ "${1:0:2}" == -[eEn] ]]; then
echo -n - echo -n -
@ -94,18 +98,6 @@ function _qval() {
s="${s//\`/\\\`}" s="${s//\`/\\\`}"
recho_ "$s" recho_ "$s"
} }
function qval() {
echo -n \"
_qval "$@"
echo \"
}
function qvalr() {
if [ -n "$*" ]; then
echo -n \"
_qval "$@"
echo n \"
fi
}
function should_quote() { function should_quote() {
[ -z "$1" ] && return 0 [ -z "$1" ] && return 0
local s="${*//[a-zA-Z0-9]/}" local s="${*//[a-zA-Z0-9]/}"
@ -118,6 +110,31 @@ function should_quote() {
s="${s//=/}" s="${s//=/}"
[ -n "$s" ] [ -n "$s" ]
} }
function qval() {
echo -n \"
_qval "$@"
echo \"
}
function qvalm() {
if should_quote "$*"; then
echo -n \"
_qval "$@"
echo \"
else
recho "$*"
fi
}
function qvalr() {
if [ -z "$*" ]; then
:
elif should_quote "$*"; then
echo -n \"
_qval "$@"
echo \"
else
recho "$*"
fi
}
function qvals() { function qvals() {
local arg first=1 local arg first=1
for arg in "$@"; do for arg in "$@"; do
@ -131,6 +148,7 @@ function qvals() {
fi fi
first= first=
done done
[ -z "$first" ] && echo
} }
function qlines() { function qlines() {
sed "s/'/'\\\\''/g; s/.*/'&'/g" sed "s/'/'\\\\''/g; s/.*/'&'/g"
@ -147,6 +165,14 @@ function _setv() {
local __s_var="$1"; shift local __s_var="$1"; shift
eval "$__s_var=\"$(_qval "$*")\"" eval "$__s_var=\"$(_qval "$*")\""
} }
function echo_setv() {
local __s_var="$1"; shift
if [[ "$__s_var" == *=* ]]; then
set -- "${__s_var#*=}" "$@"
__s_var="${__s_var%%=*}"
fi
echo "$__s_var=$(qvalr "$*")"
}
function setx() { function setx() {
if [ "$1" == -a ]; then if [ "$1" == -a ]; then
shift shift
@ -277,12 +303,96 @@ function err2out() {
uprovide base.string uprovide base.string
urequire base.core urequire base.core
function straddp() {
local p="$1"; shift
echo "$p$*"
}
function strdelp() {
local p="$1"; shift
local str="$*"
echo "${str#$p}"
}
function strdelp2() {
local p="$1"; shift
local str="$*"
echo "${str##$p}"
}
function stradds() {
local s="$1"; shift
echo "$*$s"
}
function strdels() {
local s="$1"; shift
local str="$*"
echo "${str%$s}"
}
function strdels2() {
local s="$1"; shift
local str="$*"
echo "${str%%$s}"
}
function strlower() { function strlower() {
echo ${*,,} local str="$*"
echo "${str,,}"
}
function strlower1() {
local str="$*"
echo "${str,}"
}
function strlowers() {
local str="$*"
echo "${*,}"
} }
function strupper() { function strupper() {
echo ${*^^} local str="$*"
echo "${str^^}"
} }
function strupper1() {
local str="$*"
echo "${str^}"
}
function struppers() {
echo "${*^}"
}
function strmid() {
local range="$1"; shift
local str="$*"
if [[ "$range" == *:-* ]]; then
local max=${#str}
[ $max -eq 0 ] && return
local start="${range%%:*}"
[ -n "$start" ] || start=0
while [ "$start" -lt 0 ]; do
start=$(($max$start))
done
max=$(($max-$start))
local length="${range#*:}"
while [ "$length" -lt 0 ]; do
length=$(($max$length))
done
range="$start:$length"
fi
eval 'echo "${str:'" $range"'}"'
}
function strrepl() {
local pattern="$1"; shift
local repl="$1"; shift
local str="$*"
local cmd='echo "${str/'
if [ "${pattern#/}" != "$pattern" ]; then
pattern="${pattern#/}"
cmd="$cmd/"
elif [ "${pattern#\#}" != "$pattern" ]; then
pattern="${pattern#\#}"
cmd="$cmd#"
elif [ "${pattern#%}" != "$pattern" ]; then
pattern="${pattern#%}"
cmd="$cmd%"
fi
cmd="$cmd"'$pattern/$repl}"'
eval "$cmd"
}
function isnum() { function isnum() {
[ ${#1} -gt 0 ] || return 1 [ ${#1} -gt 0 ] || return 1
local v="$1" local v="$1"
@ -319,6 +429,40 @@ function is_no() {
isnum "$1" && [ "$1" -eq 0 ] && return 0 isnum "$1" && [ "$1" -eq 0 ] && return 0
return 1 return 1
} }
function yesval() {
is_yes "$1" && echo 1
}
function first_char() {
local str="$*"
echo "${str:0:1}"
}
function last_char() {
local str="$*"
echo "${str: -1:1}"
}
function first_chars() {
local str="$*"
recho "${str:0:$((${#1}-1))}"
}
function last_chars() {
local str="$*"
recho "${str:1}"
}
function first_char_is() {
[ "${1:0:1}" == "$2" ]
}
function last_char_is() {
[ "${1:$((-1)):1}" == "$2" ]
}
function beginswith() {
local str="$1" pattern="$2"
eval '[ "${str#$pattern}" != "$str" ]'
}
function endswith() {
local str="$1" pattern="$2"
eval '[ "${str%$pattern}" != "$str" ]'
}
##@inc]base.string ##@inc]base.string
##@inc[base.array ##@inc[base.array
## Fonctions de base: gestion des tableaux ## Fonctions de base: gestion des tableaux
@ -328,12 +472,51 @@ urequire base.core
##@inc[base.compat ##@inc[base.compat
## Fonctions de base: support des fonctions obsolètes et des versions de bash < 4.x ## Fonctions de base: support des fonctions obsolètes et des versions de bash < 4.x
uprovide base.compat uprovide base.compat
urequire base.string
function rawecho() { recho "$@"; }
function rawecho_() { recho_ "$@"; }
function quote_arg() { _qval "$@"; }
function quoted_arg() { qvalm "$@"; }
function quoted_args() { qvals "$@"; }
function set_var() { setv "$@"; }
function set_var_cmd() { echo_setv "$@"; }
function set_var_literal() { eval "$1=$2"; }
function quote_awk() { _qawk "$@"; }
function quoted_awk() { qawk "$@"; }
function quote_seds() { qseds "$@"; }
function quote_form() { _qform "$@"; }
function quoted_form() { qform "$@"; }
if [ -n "$BASH_VERSINFO" -a "${BASH_VERSINFO[0]}" -lt 4 ]; then if [ -n "$BASH_VERSINFO" -a "${BASH_VERSINFO[0]}" -lt 4 ]; then
if uprovided base.string; then
function strlower() { tr A-Z a-z <<<"$*"; } function strlower() { tr A-Z a-z <<<"$*"; }
function strlower1() {
local str="$*"
local h="${str:0:1}" r="${str:1}"
echo "$(tr A-Z a-z <<<"$h")$r"
}
function strlowers() {
local -a vs; local v
for v in "$@"; do
vs=("${vs[@]}" "$(strlower1 "$v")")
done
echo "${vs[*]}"
}
function strupper() { tr a-z A-Z <<<"$*"; } function strupper() { tr a-z A-Z <<<"$*"; }
function strupper1() {
local str="$*"
local h="${str:0:1}" r="${str:1}"
echo "$(tr a-z A-Z <<<"$h")$r"
}
function struppers() {
local -a vs; local v
for v in "$@"; do
vs=("${vs[@]}" "$(strupper1 "$v")")
done
echo "${vs[*]}"
}
function is_yes() { function is_yes() {
case "$1" in case "$1" in
o|oui|y|yes|v|vrai|t|true|on) return 0;; o|oui|y|yes|v|vrai|t|true|on) return 0;;
@ -356,15 +539,20 @@ if [ -n "$BASH_VERSINFO" -a "${BASH_VERSINFO[0]}" -lt 4 ]; then
esac esac
return 1 return 1
} }
fi
fi fi
##@inc]base.compat ##@inc]base.compat
uprovide base uprovide base
urequire base.init base.core base.string base.array base.compat urequire base.init base.core base.string base.quote base.split base.array base.compat
UNAME_SYSTEM=`uname -s`
[ "${UNAME_SYSTEM#CYGWIN}" != "$UNAME_SYSTEM" ] && UNAME_SYSTEM=Cygwin
[ "${UNAME_SYSTEM#MINGW32}" != "$UNAME_SYSTEM" ] && UNAME_SYSTEM=Mingw
UNAME_MACHINE=`uname -m`
if [ -n "$UTOOLS_CHROOT" ]; then
[ -n "$UTOOLS_UNAME_SYSTEM" ] && eval "UNAME_SYSTEM=$UTOOLS_UNAME_SYSTEM"
[ -n "$UTOOLS_UNAME_MACHINE" ] && eval "UNAME_MACHINE=$UTOOLS_UNAME_MACHINE"
fi
function yesval() {
is_yes "$1" && echo 1
}
function setyesval() { function setyesval() {
is_yes "$2" && set_var "$1" 1 || set_var "$1" "" is_yes "$2" && set_var "$1" 1 || set_var "$1" ""
} }
@ -377,35 +565,6 @@ function normyesvals() {
is_yes "${!__nyv_yesvar}" && set_var "$__nyv_yesvar" 1 || set_var "$__nyv_yesvar" "" is_yes "${!__nyv_yesvar}" && set_var "$__nyv_yesvar" 1 || set_var "$__nyv_yesvar" ""
done done
} }
function rawecho() {
local first
while [ "${1:0:1}" == "-" ]; do
echo_ -
first="${1:1}"; shift
set -- "$first" "$@"
done
echo "$*"
}
function rawecho_() {
local first
while [ "${1:0:1}" == "-" ]; do
echo_ -
first="${1:1}"; shift
set -- "$first" "$@"
done
echo_ "$*"
}
function quote_arg() {
local s="$1"
s="${s//\\/\\\\}"
s="${s//\"/\\\"}"
s="${s//\$/\\\$}"
s="${s//\`/\\\`}"
rawecho "$s"
}
function quoted_arg() {
should_quote "$1" && echo "\"$(quote_arg "$1")\"" || quote_arg "$1"
}
function quote_in() { function quote_in() {
sed 's/\\/\\\\/g sed 's/\\/\\\\/g
s/"/\\"/g s/"/\\"/g
@ -421,13 +580,6 @@ function quote_sarg() {
function quoted_sarg() { function quoted_sarg() {
echo "'$(quote_sarg "$1")'" echo "'$(quote_sarg "$1")'"
} }
function quoted_args() {
local a s
for a in "$@"; do
s="${s:+$s }$(quoted_arg "$a")"
done
rawecho "$s"
}
function quoted_sargs() { function quoted_sargs() {
local a s local a s
for a in "$@"; do for a in "$@"; do
@ -435,172 +587,6 @@ function quoted_sargs() {
done done
rawecho "$s" rawecho "$s"
} }
function quote_awk() {
local s="$1"
s="${s//\\/\\\\}"
s="${s//\"/\\\"}"
s="${s//
/\\n}"
rawecho "$s"
}
function quoted_awk() {
rawecho "\"$(quote_awk "$1")\""
}
function quote_seds() {
local s="$1"
s="${s//\\/\\\\}"
s="${s//\//\\/}"
rawecho "$s"
}
function quote_form() {
local s="$1"
s="${s//\%/%25}"
s="${s//+/%2B}"
s="${s//&/%26}"
s="${s//=/%3D}"
s="${s// /+}"
rawecho "$s"
}
function quoted_form() {
local n="${1%%=*}"
if [ "$n" != "$1" ]; then
local v="${1#*=}"
rawecho "$(quote_form "$n")=$(quote_form "$v")"
else
quote_form "$1"
fi
}
function first_char() {
rawecho "${1:0:1}"
}
function last_char() {
rawecho "${1:$((-1)):1}"
}
function first_chars() {
rawecho "${1:0:$((${#1}-1))}"
}
function last_chars() {
rawecho "${1:1}"
}
function first_char_is() {
[ "${1:0:1}" == "$2" ]
}
function last_char_is() {
[ "${1:$((-1)):1}" == "$2" ]
}
function beginswith() {
eval '[ "${1#'"$(quote_arg "$2")"'}" != "$1" ]'
}
function endswith() {
eval '[ "${1%'"$(quote_arg "$2")"'}" != "$1" ]'
}
function splitfsep() {
if [[ "$1" == *"$2"* ]]; then
set_var "${3:-first}" "${1%%$2*}"
set_var "${4:-second}" "${1#*$2}"
else
set_var "${3:-first}" "$1"
set_var "${4:-second}"
fi
}
function splitfsep2() {
if [[ "$1" == *"$2"* ]]; then
set_var "${3:-first}" "${1%%$2*}"
set_var "${4:-second}" "${1#*$2}"
else
set_var "${3:-first}"
set_var "${4:-second}" "$1"
fi
}
function splitlsep() {
if [[ "$1" == *"$2"* ]]; then
set_var "${3:-first}" "${1%$2*}"
set_var "${4:-second}" "${1##*$2}"
else
set_var "${3:-first}" "$1"
set_var "${4:-second}"
fi
}
function splitlsep2() {
if [[ "$1" == *"$2"* ]]; then
set_var "${3:-first}" "${1%$2*}"
set_var "${4:-second}" "${1##*$2}"
else
set_var "${3:-first}"
set_var "${4:-second}" "$1"
fi
}
function splitvar() {
splitfsep "$1" = "${2:-name}" "${3:-value}"
}
function splitname() {
splitlsep "$1" . "${2:-basename}" "${3:-ext}"
}
function splithost() {
splitfsep "$1" . "${2:-hostname}" "${3:-domain}"
}
function splituserhost() {
splitfsep2 "$1" @ "${2:-user}" "${3:-host}"
}
function splitpair() {
splitfsep "$1" : "${2:-src}" "${3:-dest}"
}
function splitproxy() {
local __sp_tmp __sp_host __sp_port __sp_creds __sp_user __sp_password
__sp_tmp="${1#http://}"
if [[ "$__sp_tmp" == *@* ]]; then
__sp_creds="${__sp_tmp%%@*}"
__sp_tmp="${__sp_tmp#${__sp_creds}@}"
splitpair "$__sp_creds" __sp_user __sp_password
fi
__sp_tmp="${__sp_tmp%%/*}"
splitpair "$__sp_tmp" __sp_host __sp_port
[ -n "$__sp_port" ] || __sp_port=3128
set_var "${2:-host}" "$__sp_host"
set_var "${3:-port}" "$__sp_port"
set_var "${4:-user}" "$__sp_user"
set_var "${5:-password}" "$__sp_password"
}
function spliturl() {
local __su_tmp __su_scheme __su_creds __su_user __su_password __su_host __su_port __su_path
__su_scheme="${1%%:*}"
__su_tmp="${1#${__su_scheme}://}"
if [[ "$__su_tmp" == */* ]]; then
__su_path="${__su_tmp#*/}"
__su_tmp="${__su_tmp%%/*}"
fi
if [[ "$__su_tmp" == *@* ]]; then
__su_creds="${__su_tmp%%@*}"
__su_tmp="${__su_tmp#${__su_creds}@}"
splitpair "$__su_creds" __su_user __su_password
fi
splitpair "$__su_tmp" __su_host __su_port
if [ -z "$__su_port" ]; then
[ "$__su_scheme" == "http" ] && __su_port=80
[ "$__su_scheme" == "https" ] && __su_port=443
[ "$__su_scheme" == "ftp" ] && __su_port=21
fi
set_var "${2:-scheme}" "$__su_scheme"
set_var "${3:-user}" "$__su_user"
set_var "${4:-password}" "$__su_password"
set_var "${5:-host}" "$__su_host"
set_var "${6:-port}" "$__su_port"
set_var "${7:-path}" "$__su_path"
}
function set_var_cmd() {
echo "$1=$(quoted_arg "$2")"
}
function set_var() {
eval "$(set_var_cmd "$@")"
}
function set_var_literal() {
eval "$1=$2"
}
function set_array_cmd() { function set_array_cmd() {
[ $# -eq 1 ] && set -- "$1" "$1" [ $# -eq 1 ] && set -- "$1" "$1"
@ -1840,6 +1826,7 @@ function array_new(dest) {
function array_newsize(dest, size, i) { function array_newsize(dest, size, i) {
dest[0] = 0 # forcer awk à considérer dest comme un tableau dest[0] = 0 # forcer awk à considérer dest comme un tableau
delete dest delete dest
size = int(size)
for (i = 1; i <= size; i++) { for (i = 1; i <= size; i++) {
dest[i] = "" dest[i] = ""
} }
@ -1869,11 +1856,12 @@ function array_add(dest, value, lastindex) {
dest[lastindex + 1] = value dest[lastindex + 1] = value
} }
function array_deli(dest, i, l) { function array_deli(dest, i, l) {
i = int(i)
if (i == 0) return if (i == 0) return
l = length(dest) l = length(dest)
while (i < l) { while (i < l) {
dest[i] = dest[i + 1] dest[i] = dest[i + 1]
i = i + 1 i++
} }
delete dest[l] delete dest[l]
} }
@ -1929,11 +1917,11 @@ function key_index(value, values, ignoreCase, i) {
if (ignoreCase) { if (ignoreCase) {
value = tolower(value) value = tolower(value)
for (i in values) { for (i in values) {
if (tolower(values[i]) == value) return i if (tolower(values[i]) == value) return int(i)
} }
} else { } else {
for (i in values) { for (i in values) {
if (values[i] == value) return i if (values[i] == value) return int(i)
} }
} }
return 0 return 0
@ -1948,7 +1936,7 @@ function array2s(values, prefix, sep, suffix, noindices, first, i, s) {
if (first) first = 0 if (first) first = 0
else s = s sep else s = s sep
if (!noindices) s = s "[" i "]=" if (!noindices) s = s "[" i "]="
s = values[i] s = s values[i]
} }
s = s suffix s = s suffix
return s return s
@ -2515,7 +2503,7 @@ HELP_OPTIONS=
function genparse() { function genparse() {
local -a names descs vars options local -a names descs vars options
local i desc var option name value shortopt local i desc var option name uname value shortopt
for var in "$@"; do for var in "$@"; do
if [[ "$var" == *=* ]]; then if [[ "$var" == *=* ]]; then
@ -2549,10 +2537,11 @@ function genparse() {
i=0 i=0
while [ $i -lt ${#descs[*]} ]; do while [ $i -lt ${#descs[*]} ]; do
name="${names[$i]}" name="${names[$i]}"
uname="$(strupper "$name")"
desc="${descs[$i]}" desc="${descs[$i]}"
echo -n " echo -n "
\${HELP_${name^^}_OPTION:- $desc\${HELP_${name^^}_DESC:+ \${HELP_${uname}_OPTION:- $desc\${HELP_${uname}_DESC:+
\${HELP_${name^^}_DESC// \${HELP_${uname}_DESC//
/ /
}}}" }}}"
i=$(($i + 1)) i=$(($i + 1))
@ -2690,9 +2679,6 @@ function utools_local() {
done done
} }
function echo_() {
echo -n "$*"
}
function isatty() { function isatty() {
tty -s <&1 tty -s <&1
} }
@ -3436,15 +3422,6 @@ function myhost() {
function myhostname() { function myhostname() {
hostname -s 2>/dev/null || echo "$MYHOSTNAME" hostname -s 2>/dev/null || echo "$MYHOSTNAME"
} }
UNAME_SYSTEM=`uname -s`
[ "${UNAME_SYSTEM#CYGWIN}" != "$UNAME_SYSTEM" ] && UNAME_SYSTEM=Cygwin
[ "${UNAME_SYSTEM#MINGW32}" != "$UNAME_SYSTEM" ] && UNAME_SYSTEM=Mingw
UNAME_MACHINE=`uname -m`
if [ -n "$UTOOLS_CHROOT" ]; then
[ -n "$UTOOLS_UNAME_SYSTEM" ] && eval "UNAME_SYSTEM=$UTOOLS_UNAME_SYSTEM"
[ -n "$UTOOLS_UNAME_MACHINE" ] && eval "UNAME_MACHINE=$UTOOLS_UNAME_MACHINE"
fi
##@inc]../base ##@inc]../base
##@inc[../sysinfos ##@inc[../sysinfos
## Gestion des informations sur l'hôte local ## Gestion des informations sur l'hôte local

View File

@ -59,6 +59,8 @@ function uprovide() {
ULIBPROVIDED=("${ULIBPROVIDED[@]}" "$1") ULIBPROVIDED=("${ULIBPROVIDED[@]}" "$1")
} }
__ULIB_FORCE_RELOAD=
function urequire() { function urequire() {
local __u_module __u_ulibdir __u_found local __u_module __u_ulibdir __u_found
[ -n "$*" ] || set DEFAULTS [ -n "$*" ] || set DEFAULTS
@ -67,7 +69,7 @@ function urequire() {
for __u_ulibdir in "${ULIBDIRS[@]}"; do for __u_ulibdir in "${ULIBDIRS[@]}"; do
if [ -f "$__u_ulibdir/$__u_module" ]; then if [ -f "$__u_ulibdir/$__u_module" ]; then
__u_found=1 __u_found=1
if ! uprovided "$__u_module"; then if [ -n "$__ULIB_FORCE_RELOAD" ] || ! uprovided "$__u_module"; then
uprovide "$__u_module" uprovide "$__u_module"
source "$__u_ulibdir/$__u_module" || die source "$__u_ulibdir/$__u_module" || die
fi fi
@ -77,7 +79,7 @@ function urequire() {
if [ -z "$__u_found" -a "$__u_module" == DEFAULTS ]; then if [ -z "$__u_found" -a "$__u_module" == DEFAULTS ]; then
__u_found=1 __u_found=1
for __u_module in base pretty sysinfos compat; do for __u_module in base pretty sysinfos compat; do
if ! uprovided "$__u_module"; then if [ -n "$__ULIB_FORCE_RELOAD" ] || ! uprovided "$__u_module"; then
uprovide "$__u_module" uprovide "$__u_module"
source "$__u_ulibdir/$__u_module" || die source "$__u_ulibdir/$__u_module" || die
fi fi

461
ucrontab
View File

@ -151,11 +151,15 @@ export TMPDIR="${TMPDIR:-${TMP:-${TEMP:-/tmp}}}"
[ -f /etc/nutoolsrc ] && . /etc/nutoolsrc [ -f /etc/nutoolsrc ] && . /etc/nutoolsrc
[ -f ~/.nutoolsrc ] && . ~/.nutoolsrc [ -f ~/.nutoolsrc ] && . ~/.nutoolsrc
true
##@inc]base.init ##@inc]base.init
##@inc[base.core ##@inc[base.core
## Fonctions de base: fondement ## Fonctions de base: fondement
uprovide base.core uprovide base.core
function echo_() {
echo -n "$*"
}
function recho() { function recho() {
if [[ "${1:0:2}" == -[eEn] ]]; then if [[ "${1:0:2}" == -[eEn] ]]; then
echo -n - echo -n -
@ -182,18 +186,6 @@ function _qval() {
s="${s//\`/\\\`}" s="${s//\`/\\\`}"
recho_ "$s" recho_ "$s"
} }
function qval() {
echo -n \"
_qval "$@"
echo \"
}
function qvalr() {
if [ -n "$*" ]; then
echo -n \"
_qval "$@"
echo n \"
fi
}
function should_quote() { function should_quote() {
[ -z "$1" ] && return 0 [ -z "$1" ] && return 0
local s="${*//[a-zA-Z0-9]/}" local s="${*//[a-zA-Z0-9]/}"
@ -206,6 +198,31 @@ function should_quote() {
s="${s//=/}" s="${s//=/}"
[ -n "$s" ] [ -n "$s" ]
} }
function qval() {
echo -n \"
_qval "$@"
echo \"
}
function qvalm() {
if should_quote "$*"; then
echo -n \"
_qval "$@"
echo \"
else
recho "$*"
fi
}
function qvalr() {
if [ -z "$*" ]; then
:
elif should_quote "$*"; then
echo -n \"
_qval "$@"
echo \"
else
recho "$*"
fi
}
function qvals() { function qvals() {
local arg first=1 local arg first=1
for arg in "$@"; do for arg in "$@"; do
@ -219,6 +236,7 @@ function qvals() {
fi fi
first= first=
done done
[ -z "$first" ] && echo
} }
function qlines() { function qlines() {
sed "s/'/'\\\\''/g; s/.*/'&'/g" sed "s/'/'\\\\''/g; s/.*/'&'/g"
@ -235,6 +253,14 @@ function _setv() {
local __s_var="$1"; shift local __s_var="$1"; shift
eval "$__s_var=\"$(_qval "$*")\"" eval "$__s_var=\"$(_qval "$*")\""
} }
function echo_setv() {
local __s_var="$1"; shift
if [[ "$__s_var" == *=* ]]; then
set -- "${__s_var#*=}" "$@"
__s_var="${__s_var%%=*}"
fi
echo "$__s_var=$(qvalr "$*")"
}
function setx() { function setx() {
if [ "$1" == -a ]; then if [ "$1" == -a ]; then
shift shift
@ -365,12 +391,96 @@ function err2out() {
uprovide base.string uprovide base.string
urequire base.core urequire base.core
function straddp() {
local p="$1"; shift
echo "$p$*"
}
function strdelp() {
local p="$1"; shift
local str="$*"
echo "${str#$p}"
}
function strdelp2() {
local p="$1"; shift
local str="$*"
echo "${str##$p}"
}
function stradds() {
local s="$1"; shift
echo "$*$s"
}
function strdels() {
local s="$1"; shift
local str="$*"
echo "${str%$s}"
}
function strdels2() {
local s="$1"; shift
local str="$*"
echo "${str%%$s}"
}
function strlower() { function strlower() {
echo ${*,,} local str="$*"
echo "${str,,}"
}
function strlower1() {
local str="$*"
echo "${str,}"
}
function strlowers() {
local str="$*"
echo "${*,}"
} }
function strupper() { function strupper() {
echo ${*^^} local str="$*"
echo "${str^^}"
} }
function strupper1() {
local str="$*"
echo "${str^}"
}
function struppers() {
echo "${*^}"
}
function strmid() {
local range="$1"; shift
local str="$*"
if [[ "$range" == *:-* ]]; then
local max=${#str}
[ $max -eq 0 ] && return
local start="${range%%:*}"
[ -n "$start" ] || start=0
while [ "$start" -lt 0 ]; do
start=$(($max$start))
done
max=$(($max-$start))
local length="${range#*:}"
while [ "$length" -lt 0 ]; do
length=$(($max$length))
done
range="$start:$length"
fi
eval 'echo "${str:'" $range"'}"'
}
function strrepl() {
local pattern="$1"; shift
local repl="$1"; shift
local str="$*"
local cmd='echo "${str/'
if [ "${pattern#/}" != "$pattern" ]; then
pattern="${pattern#/}"
cmd="$cmd/"
elif [ "${pattern#\#}" != "$pattern" ]; then
pattern="${pattern#\#}"
cmd="$cmd#"
elif [ "${pattern#%}" != "$pattern" ]; then
pattern="${pattern#%}"
cmd="$cmd%"
fi
cmd="$cmd"'$pattern/$repl}"'
eval "$cmd"
}
function isnum() { function isnum() {
[ ${#1} -gt 0 ] || return 1 [ ${#1} -gt 0 ] || return 1
local v="$1" local v="$1"
@ -407,6 +517,40 @@ function is_no() {
isnum "$1" && [ "$1" -eq 0 ] && return 0 isnum "$1" && [ "$1" -eq 0 ] && return 0
return 1 return 1
} }
function yesval() {
is_yes "$1" && echo 1
}
function first_char() {
local str="$*"
echo "${str:0:1}"
}
function last_char() {
local str="$*"
echo "${str: -1:1}"
}
function first_chars() {
local str="$*"
recho "${str:0:$((${#1}-1))}"
}
function last_chars() {
local str="$*"
recho "${str:1}"
}
function first_char_is() {
[ "${1:0:1}" == "$2" ]
}
function last_char_is() {
[ "${1:$((-1)):1}" == "$2" ]
}
function beginswith() {
local str="$1" pattern="$2"
eval '[ "${str#$pattern}" != "$str" ]'
}
function endswith() {
local str="$1" pattern="$2"
eval '[ "${str%$pattern}" != "$str" ]'
}
##@inc]base.string ##@inc]base.string
##@inc[base.array ##@inc[base.array
## Fonctions de base: gestion des tableaux ## Fonctions de base: gestion des tableaux
@ -416,12 +560,51 @@ urequire base.core
##@inc[base.compat ##@inc[base.compat
## Fonctions de base: support des fonctions obsolètes et des versions de bash < 4.x ## Fonctions de base: support des fonctions obsolètes et des versions de bash < 4.x
uprovide base.compat uprovide base.compat
urequire base.string
function rawecho() { recho "$@"; }
function rawecho_() { recho_ "$@"; }
function quote_arg() { _qval "$@"; }
function quoted_arg() { qvalm "$@"; }
function quoted_args() { qvals "$@"; }
function set_var() { setv "$@"; }
function set_var_cmd() { echo_setv "$@"; }
function set_var_literal() { eval "$1=$2"; }
function quote_awk() { _qawk "$@"; }
function quoted_awk() { qawk "$@"; }
function quote_seds() { qseds "$@"; }
function quote_form() { _qform "$@"; }
function quoted_form() { qform "$@"; }
if [ -n "$BASH_VERSINFO" -a "${BASH_VERSINFO[0]}" -lt 4 ]; then if [ -n "$BASH_VERSINFO" -a "${BASH_VERSINFO[0]}" -lt 4 ]; then
if uprovided base.string; then
function strlower() { tr A-Z a-z <<<"$*"; } function strlower() { tr A-Z a-z <<<"$*"; }
function strlower1() {
local str="$*"
local h="${str:0:1}" r="${str:1}"
echo "$(tr A-Z a-z <<<"$h")$r"
}
function strlowers() {
local -a vs; local v
for v in "$@"; do
vs=("${vs[@]}" "$(strlower1 "$v")")
done
echo "${vs[*]}"
}
function strupper() { tr a-z A-Z <<<"$*"; } function strupper() { tr a-z A-Z <<<"$*"; }
function strupper1() {
local str="$*"
local h="${str:0:1}" r="${str:1}"
echo "$(tr a-z A-Z <<<"$h")$r"
}
function struppers() {
local -a vs; local v
for v in "$@"; do
vs=("${vs[@]}" "$(strupper1 "$v")")
done
echo "${vs[*]}"
}
function is_yes() { function is_yes() {
case "$1" in case "$1" in
o|oui|y|yes|v|vrai|t|true|on) return 0;; o|oui|y|yes|v|vrai|t|true|on) return 0;;
@ -444,15 +627,20 @@ if [ -n "$BASH_VERSINFO" -a "${BASH_VERSINFO[0]}" -lt 4 ]; then
esac esac
return 1 return 1
} }
fi
fi fi
##@inc]base.compat ##@inc]base.compat
uprovide base uprovide base
urequire base.init base.core base.string base.array base.compat urequire base.init base.core base.string base.quote base.split base.array base.compat
UNAME_SYSTEM=`uname -s`
[ "${UNAME_SYSTEM#CYGWIN}" != "$UNAME_SYSTEM" ] && UNAME_SYSTEM=Cygwin
[ "${UNAME_SYSTEM#MINGW32}" != "$UNAME_SYSTEM" ] && UNAME_SYSTEM=Mingw
UNAME_MACHINE=`uname -m`
if [ -n "$UTOOLS_CHROOT" ]; then
[ -n "$UTOOLS_UNAME_SYSTEM" ] && eval "UNAME_SYSTEM=$UTOOLS_UNAME_SYSTEM"
[ -n "$UTOOLS_UNAME_MACHINE" ] && eval "UNAME_MACHINE=$UTOOLS_UNAME_MACHINE"
fi
function yesval() {
is_yes "$1" && echo 1
}
function setyesval() { function setyesval() {
is_yes "$2" && set_var "$1" 1 || set_var "$1" "" is_yes "$2" && set_var "$1" 1 || set_var "$1" ""
} }
@ -465,35 +653,6 @@ function normyesvals() {
is_yes "${!__nyv_yesvar}" && set_var "$__nyv_yesvar" 1 || set_var "$__nyv_yesvar" "" is_yes "${!__nyv_yesvar}" && set_var "$__nyv_yesvar" 1 || set_var "$__nyv_yesvar" ""
done done
} }
function rawecho() {
local first
while [ "${1:0:1}" == "-" ]; do
echo_ -
first="${1:1}"; shift
set -- "$first" "$@"
done
echo "$*"
}
function rawecho_() {
local first
while [ "${1:0:1}" == "-" ]; do
echo_ -
first="${1:1}"; shift
set -- "$first" "$@"
done
echo_ "$*"
}
function quote_arg() {
local s="$1"
s="${s//\\/\\\\}"
s="${s//\"/\\\"}"
s="${s//\$/\\\$}"
s="${s//\`/\\\`}"
rawecho "$s"
}
function quoted_arg() {
should_quote "$1" && echo "\"$(quote_arg "$1")\"" || quote_arg "$1"
}
function quote_in() { function quote_in() {
sed 's/\\/\\\\/g sed 's/\\/\\\\/g
s/"/\\"/g s/"/\\"/g
@ -509,13 +668,6 @@ function quote_sarg() {
function quoted_sarg() { function quoted_sarg() {
echo "'$(quote_sarg "$1")'" echo "'$(quote_sarg "$1")'"
} }
function quoted_args() {
local a s
for a in "$@"; do
s="${s:+$s }$(quoted_arg "$a")"
done
rawecho "$s"
}
function quoted_sargs() { function quoted_sargs() {
local a s local a s
for a in "$@"; do for a in "$@"; do
@ -523,172 +675,6 @@ function quoted_sargs() {
done done
rawecho "$s" rawecho "$s"
} }
function quote_awk() {
local s="$1"
s="${s//\\/\\\\}"
s="${s//\"/\\\"}"
s="${s//
/\\n}"
rawecho "$s"
}
function quoted_awk() {
rawecho "\"$(quote_awk "$1")\""
}
function quote_seds() {
local s="$1"
s="${s//\\/\\\\}"
s="${s//\//\\/}"
rawecho "$s"
}
function quote_form() {
local s="$1"
s="${s//\%/%25}"
s="${s//+/%2B}"
s="${s//&/%26}"
s="${s//=/%3D}"
s="${s// /+}"
rawecho "$s"
}
function quoted_form() {
local n="${1%%=*}"
if [ "$n" != "$1" ]; then
local v="${1#*=}"
rawecho "$(quote_form "$n")=$(quote_form "$v")"
else
quote_form "$1"
fi
}
function first_char() {
rawecho "${1:0:1}"
}
function last_char() {
rawecho "${1:$((-1)):1}"
}
function first_chars() {
rawecho "${1:0:$((${#1}-1))}"
}
function last_chars() {
rawecho "${1:1}"
}
function first_char_is() {
[ "${1:0:1}" == "$2" ]
}
function last_char_is() {
[ "${1:$((-1)):1}" == "$2" ]
}
function beginswith() {
eval '[ "${1#'"$(quote_arg "$2")"'}" != "$1" ]'
}
function endswith() {
eval '[ "${1%'"$(quote_arg "$2")"'}" != "$1" ]'
}
function splitfsep() {
if [[ "$1" == *"$2"* ]]; then
set_var "${3:-first}" "${1%%$2*}"
set_var "${4:-second}" "${1#*$2}"
else
set_var "${3:-first}" "$1"
set_var "${4:-second}"
fi
}
function splitfsep2() {
if [[ "$1" == *"$2"* ]]; then
set_var "${3:-first}" "${1%%$2*}"
set_var "${4:-second}" "${1#*$2}"
else
set_var "${3:-first}"
set_var "${4:-second}" "$1"
fi
}
function splitlsep() {
if [[ "$1" == *"$2"* ]]; then
set_var "${3:-first}" "${1%$2*}"
set_var "${4:-second}" "${1##*$2}"
else
set_var "${3:-first}" "$1"
set_var "${4:-second}"
fi
}
function splitlsep2() {
if [[ "$1" == *"$2"* ]]; then
set_var "${3:-first}" "${1%$2*}"
set_var "${4:-second}" "${1##*$2}"
else
set_var "${3:-first}"
set_var "${4:-second}" "$1"
fi
}
function splitvar() {
splitfsep "$1" = "${2:-name}" "${3:-value}"
}
function splitname() {
splitlsep "$1" . "${2:-basename}" "${3:-ext}"
}
function splithost() {
splitfsep "$1" . "${2:-hostname}" "${3:-domain}"
}
function splituserhost() {
splitfsep2 "$1" @ "${2:-user}" "${3:-host}"
}
function splitpair() {
splitfsep "$1" : "${2:-src}" "${3:-dest}"
}
function splitproxy() {
local __sp_tmp __sp_host __sp_port __sp_creds __sp_user __sp_password
__sp_tmp="${1#http://}"
if [[ "$__sp_tmp" == *@* ]]; then
__sp_creds="${__sp_tmp%%@*}"
__sp_tmp="${__sp_tmp#${__sp_creds}@}"
splitpair "$__sp_creds" __sp_user __sp_password
fi
__sp_tmp="${__sp_tmp%%/*}"
splitpair "$__sp_tmp" __sp_host __sp_port
[ -n "$__sp_port" ] || __sp_port=3128
set_var "${2:-host}" "$__sp_host"
set_var "${3:-port}" "$__sp_port"
set_var "${4:-user}" "$__sp_user"
set_var "${5:-password}" "$__sp_password"
}
function spliturl() {
local __su_tmp __su_scheme __su_creds __su_user __su_password __su_host __su_port __su_path
__su_scheme="${1%%:*}"
__su_tmp="${1#${__su_scheme}://}"
if [[ "$__su_tmp" == */* ]]; then
__su_path="${__su_tmp#*/}"
__su_tmp="${__su_tmp%%/*}"
fi
if [[ "$__su_tmp" == *@* ]]; then
__su_creds="${__su_tmp%%@*}"
__su_tmp="${__su_tmp#${__su_creds}@}"
splitpair "$__su_creds" __su_user __su_password
fi
splitpair "$__su_tmp" __su_host __su_port
if [ -z "$__su_port" ]; then
[ "$__su_scheme" == "http" ] && __su_port=80
[ "$__su_scheme" == "https" ] && __su_port=443
[ "$__su_scheme" == "ftp" ] && __su_port=21
fi
set_var "${2:-scheme}" "$__su_scheme"
set_var "${3:-user}" "$__su_user"
set_var "${4:-password}" "$__su_password"
set_var "${5:-host}" "$__su_host"
set_var "${6:-port}" "$__su_port"
set_var "${7:-path}" "$__su_path"
}
function set_var_cmd() {
echo "$1=$(quoted_arg "$2")"
}
function set_var() {
eval "$(set_var_cmd "$@")"
}
function set_var_literal() {
eval "$1=$2"
}
function set_array_cmd() { function set_array_cmd() {
[ $# -eq 1 ] && set -- "$1" "$1" [ $# -eq 1 ] && set -- "$1" "$1"
@ -1928,6 +1914,7 @@ function array_new(dest) {
function array_newsize(dest, size, i) { function array_newsize(dest, size, i) {
dest[0] = 0 # forcer awk à considérer dest comme un tableau dest[0] = 0 # forcer awk à considérer dest comme un tableau
delete dest delete dest
size = int(size)
for (i = 1; i <= size; i++) { for (i = 1; i <= size; i++) {
dest[i] = "" dest[i] = ""
} }
@ -1957,11 +1944,12 @@ function array_add(dest, value, lastindex) {
dest[lastindex + 1] = value dest[lastindex + 1] = value
} }
function array_deli(dest, i, l) { function array_deli(dest, i, l) {
i = int(i)
if (i == 0) return if (i == 0) return
l = length(dest) l = length(dest)
while (i < l) { while (i < l) {
dest[i] = dest[i + 1] dest[i] = dest[i + 1]
i = i + 1 i++
} }
delete dest[l] delete dest[l]
} }
@ -2017,11 +2005,11 @@ function key_index(value, values, ignoreCase, i) {
if (ignoreCase) { if (ignoreCase) {
value = tolower(value) value = tolower(value)
for (i in values) { for (i in values) {
if (tolower(values[i]) == value) return i if (tolower(values[i]) == value) return int(i)
} }
} else { } else {
for (i in values) { for (i in values) {
if (values[i] == value) return i if (values[i] == value) return int(i)
} }
} }
return 0 return 0
@ -2036,7 +2024,7 @@ function array2s(values, prefix, sep, suffix, noindices, first, i, s) {
if (first) first = 0 if (first) first = 0
else s = s sep else s = s sep
if (!noindices) s = s "[" i "]=" if (!noindices) s = s "[" i "]="
s = values[i] s = s values[i]
} }
s = s suffix s = s suffix
return s return s
@ -2603,7 +2591,7 @@ HELP_OPTIONS=
function genparse() { function genparse() {
local -a names descs vars options local -a names descs vars options
local i desc var option name value shortopt local i desc var option name uname value shortopt
for var in "$@"; do for var in "$@"; do
if [[ "$var" == *=* ]]; then if [[ "$var" == *=* ]]; then
@ -2637,10 +2625,11 @@ function genparse() {
i=0 i=0
while [ $i -lt ${#descs[*]} ]; do while [ $i -lt ${#descs[*]} ]; do
name="${names[$i]}" name="${names[$i]}"
uname="$(strupper "$name")"
desc="${descs[$i]}" desc="${descs[$i]}"
echo -n " echo -n "
\${HELP_${name^^}_OPTION:- $desc\${HELP_${name^^}_DESC:+ \${HELP_${uname}_OPTION:- $desc\${HELP_${uname}_DESC:+
\${HELP_${name^^}_DESC// \${HELP_${uname}_DESC//
/ /
}}}" }}}"
i=$(($i + 1)) i=$(($i + 1))
@ -2778,9 +2767,6 @@ function utools_local() {
done done
} }
function echo_() {
echo -n "$*"
}
function isatty() { function isatty() {
tty -s <&1 tty -s <&1
} }
@ -3524,15 +3510,6 @@ function myhost() {
function myhostname() { function myhostname() {
hostname -s 2>/dev/null || echo "$MYHOSTNAME" hostname -s 2>/dev/null || echo "$MYHOSTNAME"
} }
UNAME_SYSTEM=`uname -s`
[ "${UNAME_SYSTEM#CYGWIN}" != "$UNAME_SYSTEM" ] && UNAME_SYSTEM=Cygwin
[ "${UNAME_SYSTEM#MINGW32}" != "$UNAME_SYSTEM" ] && UNAME_SYSTEM=Mingw
UNAME_MACHINE=`uname -m`
if [ -n "$UTOOLS_CHROOT" ]; then
[ -n "$UTOOLS_UNAME_SYSTEM" ] && eval "UNAME_SYSTEM=$UTOOLS_UNAME_SYSTEM"
[ -n "$UTOOLS_UNAME_MACHINE" ] && eval "UNAME_MACHINE=$UTOOLS_UNAME_MACHINE"
fi
##@inc]base ##@inc]base
##@inc[pretty ##@inc[pretty
## Affichage en couleur, et support de niveaux de "verbosité" et d'interaction ## Affichage en couleur, et support de niveaux de "verbosité" et d'interaction