2014-09-17 10:53:12 +04:00
|
|
|
##@cooked comments # -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
|
|
|
|
## Fonctions de base: support des fonctions obsolètes et des versions de bash < 4.x
|
|
|
|
##@cooked nocomments
|
2014-10-13 09:30:16 +04:00
|
|
|
##@include base.core
|
|
|
|
##@include base.quote
|
2017-03-01 20:01:02 +04:00
|
|
|
##@include base.string
|
|
|
|
##@include base.bool
|
2014-09-17 10:53:12 +04:00
|
|
|
uprovide base.compat
|
|
|
|
|
2014-09-19 14:54:31 +04:00
|
|
|
## Fonctions obsolètes
|
2014-09-19 14:51:19 +04:00
|
|
|
|
2014-09-19 14:54:31 +04:00
|
|
|
# base.core
|
2017-03-01 20:01:02 +04:00
|
|
|
urequire base.core
|
2014-10-18 20:23:21 +04:00
|
|
|
function setx2() { setxx "$@"; }
|
2014-09-19 14:51:19 +04:00
|
|
|
function rawecho() { recho "$@"; }
|
|
|
|
function rawecho_() { recho_ "$@"; }
|
|
|
|
function quote_arg() { _qval "$@"; }
|
|
|
|
function quoted_arg() { qvalm "$@"; }
|
|
|
|
function quoted_args() { qvals "$@"; }
|
2014-09-19 15:22:55 +04:00
|
|
|
function set_var() { setv "$@"; }
|
|
|
|
function set_var_cmd() { echo_setv "$@"; }
|
|
|
|
function set_var_literal() { eval "$1=$2"; }
|
2014-09-19 14:51:19 +04:00
|
|
|
|
2014-09-19 14:54:31 +04:00
|
|
|
# base.quote
|
2017-03-01 20:01:02 +04:00
|
|
|
urequire base.quote
|
2014-09-19 14:51:19 +04:00
|
|
|
function quote_awk() { _qawk "$@"; }
|
|
|
|
function quoted_awk() { qawk "$@"; }
|
|
|
|
function quote_seds() { qseds "$@"; }
|
|
|
|
function quote_form() { _qform "$@"; }
|
|
|
|
function quoted_form() { qform "$@"; }
|
2014-09-19 14:54:31 +04:00
|
|
|
|
|
|
|
## Compatibilité avec bash >=2.x
|
|
|
|
|
|
|
|
if [ -n "$BASH_VERSINFO" -a "${BASH_VERSINFO[0]}" -lt 4 ]; then
|
|
|
|
# base.string
|
2017-03-01 20:01:02 +04:00
|
|
|
urequire base.string
|
2014-09-19 14:54:31 +04:00
|
|
|
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 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[*]}"
|
|
|
|
}
|
2014-10-13 09:30:16 +04:00
|
|
|
|
|
|
|
# base.bool
|
2017-03-01 20:01:02 +04:00
|
|
|
urequire base.bool
|
2014-09-19 14:54:31 +04:00
|
|
|
function is_yes() {
|
|
|
|
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;;
|
|
|
|
esac
|
|
|
|
isnum "$1" && [ "$1" -ne 0 ] && return 0
|
|
|
|
# pour les perfs, n'utiliser strlower que ici
|
|
|
|
case "$(strlower "$1")" in
|
|
|
|
o|oui|y|yes|v|vrai|t|true|on) return 0;;
|
|
|
|
esac
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
function is_no() {
|
|
|
|
case "$1" in
|
|
|
|
n|non|no|f|faux|false|off) return 0;;
|
|
|
|
N|NON|NO|F|FAUX|FALSE|OFF) return 0;;
|
|
|
|
esac
|
|
|
|
isnum "$1" && [ "$1" -eq 0 ] && return 0
|
|
|
|
case "$(strlower "$1")" in
|
|
|
|
n|non|no|f|faux|false|off) return 0;;
|
|
|
|
esac
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
fi
|