support de bash 3.x sur macosx: ajout d'une fonction tolower() pour abstraire le passage d'une valeur en minuscule
This commit is contained in:
parent
9d68a96138
commit
fcf60b2bca
|
@ -1 +1 @@
|
||||||
001002000
|
001003000
|
||||||
|
|
|
@ -132,6 +132,14 @@ function nef() {
|
||||||
}
|
}
|
||||||
|
|
||||||
## valeurs
|
## valeurs
|
||||||
|
function tolower() {
|
||||||
|
# afficher en minuscule la valeur $1..*
|
||||||
|
echo ${*,,}
|
||||||
|
}
|
||||||
|
function toupper() {
|
||||||
|
# afficher en majuscule la valeur $1..*
|
||||||
|
echo ${*^^}
|
||||||
|
}
|
||||||
function isnum() {
|
function isnum() {
|
||||||
# retourner vrai si $1 est une valeur numérique entière (positive ou négative)
|
# retourner vrai si $1 est une valeur numérique entière (positive ou négative)
|
||||||
[ ${#1} -gt 0 ] || return 1
|
[ ${#1} -gt 0 ] || return 1
|
||||||
|
@ -2909,8 +2917,7 @@ function __po_process_options() {
|
||||||
function __genparse_shortopt() {
|
function __genparse_shortopt() {
|
||||||
local LC_COLLATE=C
|
local LC_COLLATE=C
|
||||||
local shortopt="${1//[^A-Z]}"
|
local shortopt="${1//[^A-Z]}"
|
||||||
shortopt="${shortopt:0:1}"
|
shortopt="$(tolower "${shortopt:0:1}")"
|
||||||
shortopt="${shortopt,,}"
|
|
||||||
[ -n "$shortopt" ] && echo "$shortopt"
|
[ -n "$shortopt" ] && echo "$shortopt"
|
||||||
}
|
}
|
||||||
HELP_DESC=
|
HELP_DESC=
|
||||||
|
@ -2977,7 +2984,7 @@ function genparse() {
|
||||||
if [[ "$var" == *=* ]]; then
|
if [[ "$var" == *=* ]]; then
|
||||||
splitvar "$var" name value
|
splitvar "$var" name value
|
||||||
shortopt="$(__genparse_shortopt "$name")"
|
shortopt="$(__genparse_shortopt "$name")"
|
||||||
option="${name,,}"
|
option="$(tolower "$name")"
|
||||||
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"
|
||||||
|
@ -2986,7 +2993,7 @@ function genparse() {
|
||||||
else
|
else
|
||||||
name="$var"
|
name="$var"
|
||||||
shortopt="$(__genparse_shortopt "$name")"
|
shortopt="$(__genparse_shortopt "$name")"
|
||||||
option="${name,,}"
|
option="$(tolower "$name")"
|
||||||
name="${option//-/_}"
|
name="${option//-/_}"
|
||||||
array_add names "$name"
|
array_add names "$name"
|
||||||
array_add descs "${shortopt:+-$shortopt, }--$option"
|
array_add descs "${shortopt:+-$shortopt, }--$option"
|
||||||
|
|
|
@ -16,6 +16,23 @@ if check_sysinfos -s macosx; then
|
||||||
function _nl2cr() { _nl2lf | awk 'BEGIN { ORS="" } { print $0 "\r" }'; }
|
function _nl2cr() { _nl2lf | awk 'BEGIN { ORS="" } { print $0 "\r" }'; }
|
||||||
# sed -i demande un argument
|
# sed -i demande un argument
|
||||||
function sedi() { sed -i '' "$@"; }
|
function sedi() { sed -i '' "$@"; }
|
||||||
|
# Sous MacOSX, la version de bash (3.x) ne supporte pas les opérateurs ,, et ^^
|
||||||
|
function tolower() { tr A-Z a-z <<<"$*"; }
|
||||||
|
function toupper() { tr a-z A-Z <<<"$*"; }
|
||||||
|
function is_yes() {
|
||||||
|
case "$(tolower "$1")" in
|
||||||
|
o|oui|y|yes|v|vrai|t|true|on) return 0;;
|
||||||
|
esac
|
||||||
|
isnum "$1" && [ "$1" -ne 0 ] && return 0
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
function is_no() {
|
||||||
|
case "$(tolower "$1")" in
|
||||||
|
n|non|no|f|faux|false|off) return 0;;
|
||||||
|
esac
|
||||||
|
isnum "$1" && [ "$1" -eq 0 ] && return 0
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
## gestion des arguments
|
## gestion des arguments
|
||||||
function __po_check_options() {
|
function __po_check_options() {
|
||||||
|
|
Loading…
Reference in New Issue