This commit is contained in:
Jephté Clain 2014-09-19 14:54:31 +04:00
parent 4d40820308
commit e4ce6c5d18
1 changed files with 58 additions and 56 deletions

View File

@ -2,72 +2,74 @@
## Fonctions de base: support des fonctions obsolètes et des versions de bash < 4.x
##@cooked nocomments
uprovide base.compat
urequire base.string
if [ -n "$BASH_VERSINFO" -a "${BASH_VERSINFO[0]}" -lt 4 ]; then
if uprovided base.string; then
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[*]}"
}
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
fi
## Fonctions obsolètes
## base.core
# base.core
function rawecho() { recho "$@"; }
function rawecho_() { recho_ "$@"; }
function quote_arg() { _qval "$@"; }
function quoted_arg() { qvalm "$@"; }
function quoted_args() { qvals "$@"; }
## base.quote
# base.quote
function quote_awk() { _qawk "$@"; }
function quoted_awk() { qawk "$@"; }
function quote_seds() { qseds "$@"; }
function quote_form() { _qform "$@"; }
function quoted_form() { qform "$@"; }
## Compatibilité avec bash >=2.x
if [ -n "$BASH_VERSINFO" -a "${BASH_VERSINFO[0]}" -lt 4 ]; then
# base.string
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[*]}"
}
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