This commit is contained in:
Jephté Clain 2014-09-15 08:12:04 +04:00
parent fa717f818a
commit afbf8fcddf
3 changed files with 383 additions and 26 deletions

View File

@ -52,7 +52,7 @@ function recho_() {
echo -n "$@"
fi
}
function qval() {
function _qval() {
local s="$*"
s="${s//\\/\\\\}"
s="${s//\"/\\\"}"
@ -60,6 +60,18 @@ function qval() {
s="${s//\`/\\\`}"
recho_ "$s"
}
function qval() {
echo -n \"
_qval "$@"
echo \"
}
function qvalr() {
if [ -n "$*" ]; then
echo -n \"
_qval "$@"
echo n \"
fi
}
function should_quote() {
[ -z "$1" ] && return 0
local s="${*//[a-zA-Z0-9]/}"
@ -78,7 +90,7 @@ function qvals() {
[ -z "$first" ] && echo -n " "
if should_quote "$arg"; then
echo -n \"
qval "$arg"
_qval "$arg"
echo -n \"
else
recho_ "$arg"
@ -91,21 +103,134 @@ function qlines() {
}
function setv() {
local __s_var="$1"; shift
eval "$__s_var=\"$(qval "$*")\""
if [[ "$__s_var" == *=* ]]; then
set -- "${__s_var#*=}" "$@"
__s_var="${__s_var%%=*}"
fi
eval "$__s_var=\"$(_qval "$*")\""
}
function _setv() {
local __s_var="$1"; shift
eval "$__s_var=\"$(_qval "$*")\""
}
function setx() {
local __s_var="$1"; shift
eval "$__s_var=\"\$(\"\$@\")\""
if [[ "$__s_var" == *=* ]]; then
set -- "${__s_var#*=}" "$@"
__s_var="${__s_var%%=*}"
fi
eval "$__s_var="'"$("$@")"'
}
function _setx() {
local __s_var="$1"; shift
eval "$__s_var="'"$("$@")"'
}
function seta() {
local __s_array="$1"; shift
if [[ "$__s_array" == *=* ]]; then
set -- "${__s_array#*=}" "$@"
__s_array="${__s_array%%=*}"
fi
eval "$__s_array=($("$@" | qlines))"
}
function e2of() {
"$@" 2>&1
function _seta() {
local __s_array="$1"; shift
eval "$__s_array=($("$@" | qlines))"
}
function nef() {
"$@" | sed '/^$/d'
function evalx() {
local __e_val __e_arg __e_r=0
local -a __e_cmd
local __e_first=1
while [ $# -gt 0 ]; do
__e_cmd=()
while [ $# -gt 0 ]; do
__e_arg="$1"; shift
[ "$__e_arg" == // ] && break
if [ "${__e_arg%//}" != "$__e_arg" ]; then
local __e_tmp="${__e_arg%//}"
if [ -z "${__e_tmp//\\/}" ]; then
__e_arg="${__e_arg#\\}"
__e_cmd=("${__e_cmd[@]}" "$__e_arg")
continue
fi
fi
__e_cmd=("${__e_cmd[@]}" "$__e_arg")
done
if [ -n "$first" ]; then
__e_val="$("${__e_cmd[@]}")" || __e_r=$?
else
__e_val="$("${__e_cmd[@]}" "$__e_val")" || __e_r=$?
fi
__e_first=
done
[ -n "$__e_val" ] && echo "$__e_val"
return $__e_r
}
function setx2() {
local __s_var="$1"; shift
if [[ "$__s_var" == *=* ]]; then
set -- "${__s_var#*=}" "$@"
__s_var="${__s_var%%=*}"
fi
setx "$__s_var" evalx "$@"
}
function evalp() {
local __e_arg __e_cmd
while [ $# -gt 0 ]; do
__e_arg="$1"; shift
if [ "$__e_arg" == // ]; then
__e_cmd="$__e_cmd |"
continue
elif [ "${__e_arg%//}" != "$__e_arg" ]; then
local __e_tmp="${__e_arg%//}"
if [ -z "${__e_tmp//\\/}" ]; then
__e_arg="${__e_arg#\\}"
fi
fi
__e_cmd="${__e_cmd:+$__e_cmd }\"$(_qval "$__e_arg")\""
done
eval "$__e_cmd"
}
function testx() {
local __t_op="$1"; shift
local __t_val="$(evalx "$@")"
[ $__t_op "$__t_val" ]
}
function test2x() {
local __t_val1="$1"; shift
local __t_op="$1"; shift
local __t_val2="$(evalx "$@")"
[ "$__t_val1" $__t_op "$__t_val2" ]
}
function testrx() {
local __t_val1="$1"; shift
local __t_op="$1"; shift
local __t_val2="$(evalx "$@")"
eval '[[ "$__t_val1" '"$__t_op"' "$__t_val2" ]]'
}
function testp() {
local __t_op="$1"; shift
local __t_val="$(evalp "$@")"
[ $__t_op "$__t_val" ]
}
function test2p() {
local __t_val1="$1"; shift
local __t_op="$1"; shift
local __t_val2="$(evalp "$@")"
[ "$__t_val1" $__t_op "$__t_val2" ]
}
function testrp() {
local __t_val1="$1"; shift
local __t_op="$1"; shift
local __t_val2="$(evalp "$@")"
eval '[[ "$__t_val1" '"$__t_op"' "$__t_val2" ]]'
}
function err2out() {
"$@" 2>&1
}
function tolower() {
@ -420,10 +545,12 @@ function array_new() {
eval "$1=()"
}
function array_add() {
eval "$1=(\"\${$1[@]}\" \"$(quote_arg "$2")\")"
local __aa_a="$1"; shift
eval "$__aa_a=(\"\${$__aa_a[@]}\" \"\$@\")"
}
function array_ins() {
eval "$1=(\"$(quote_arg "$2")\" \"\${$1[@]}\")"
local __aa_a="$1"; shift
eval "$__aa_a=(\"\$@\" \"\${$__aa_a[@]}\")"
}
function array_del() {
local __ad_v
@ -1254,6 +1381,9 @@ function array_lsdirs() {
function array_lsfiles() {
__array_ls files "$@"
}
function filter_empty() {
sed '/^$/d'
}
function filter_vcspath() {
sed '
/^.git$/d
@ -2444,7 +2574,7 @@ function pidfile_check() {
}
function page_maybe() {
if isatty; then
less -XF
less -XF "$@"
else
cat
fi
@ -3602,17 +3732,25 @@ if check_sysinfos -s macosx; then
function tolower() { tr A-Z a-z <<<"$*"; }
function toupper() { tr a-z A-Z <<<"$*"; }
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
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 "$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 "$(tolower "$1")" in
n|non|no|f|faux|false|off) return 0;;
esac
isnum "$1" && [ "$1" -eq 0 ] && return 0
return 1
}

View File

@ -96,5 +96,86 @@ function ulibsync() {
local __CPNOVCS_RSYNC_ARGS=(-q --delete)
[ "$destdir/ulib" != "$ULIBDIR" ] && cpdirnovcs "$ULIBDIR" "$destdir/ulib"
}
function __ulibver_parse_version() {
if [ -n "$2" ]; then
local version="${1:-${version:-000000000}}"
local major minor patch pversion
else
version="${1:-${version:-000000000}}"
fi
while [ ${#version} -lt 9 ]; do version="0$version"; done
major="${version:0:3}"; while [ ${#major} -gt 1 -a "${major#0}" != "$major" ]; do major="${major#0}"; done
minor="${version:3:3}"; while [ ${#minor} -gt 1 -a "${minor#0}" != "$minor" ]; do minor="${minor#0}"; done
patch="${version:6:3}"; while [ ${#patch} -gt 1 -a "${patch#0}" != "$patch" ]; do patch="${patch#0}"; done
pversion="$major.$minor.$patch"
[ -n "$2" ] && eval "${2}version=\$version; ${2}major=\$major; ${2}minor=\$minor; ${2}patch=\$patch; ${2}pversion=\$pversion"
}
function __ulibver_format_version() {
local major="${1:-${major:-0}}" minor="${2:-${minor:-0}}" patch="${3:-${patch:-0}}"
while [ ${#major} -lt 3 ]; do major="0$major"; done
while [ ${#minor} -lt 3 ]; do minor="0$minor"; done
while [ ${#patch} -lt 3 ]; do patch="0$patch"; done
echo "$major$minor$patch"
}
function __ulibver_parse_pversion() {
local v M m p
if [[ "$1" == *.* ]]; then
local v="$1"; shift
local M=0 m=0 p=0
if [[ "$v" == *.* ]]; then
p="${v##*.}"; v="${v%.*}"
if [[ "$v" == *.* ]]; then
m="${v##*.}"; v="${v%.*}"
if [[ "$v" == *.* ]]; then M="${v##*.}"; v="${v%.*}"
else M="$v"
fi
else m="$v"
fi
else p="$v"
fi
__ulibver_parse_version "$(__ulibver_format_version "$M" "$m" "$p")" "$@"
else
__ulibver_parse_version "$@"
fi
}
function ulibver() {
[ -f "$ULIBDIR/.ulibver" ] || return 1
local version=000000000 major minor patch pversion
__ulibver_parse_version "$(<"$ULIBDIR/.ulibver")"
if [ -n "$1" ]; then
local minversion=000000000 minmajor minminor minpatch minpversion
__ulibver_parse_pversion "$1" min
if [ "$major" -lt "$minmajor" ]; then
return 1
elif [ "$major" -eq "$minmajor" ]; then
if [ "$minor" -lt "$minminor" ]; then
return 1
elif [ "$minor" -eq "$minminor" ]; then
[ "$patch" -lt "$minpatch" ] && return 1
fi
fi
fi
if [ -n "$2" ]; then
local maxversion=000000000 maxmajor maxmaxor maxpatch maxpversion
__ulibver_parse_pversion "$2" max
if [ "$major" -gt "$maxmajor" ]; then
return 1
elif [ "$major" -eq "$maxmajor" ]; then
if [ "$minor" -gt "$maxminor" ]; then
return 1
elif [ "$minor" -eq "$maxminor" ]; then
[ "$patch" -ge "$maxpatch" ] && return 1
fi
fi
fi
return 0
}
function ulibver_require() {
ulibver "$@" && return 0
eerror "Ce script nécessite ulib version${1:+" >= $1"}${2:+" < $2"}"
return 1
}
##@inc]ulib
uprovide ulibsh

164
ucrontab
View File

@ -140,7 +140,7 @@ function recho_() {
echo -n "$@"
fi
}
function qval() {
function _qval() {
local s="$*"
s="${s//\\/\\\\}"
s="${s//\"/\\\"}"
@ -148,6 +148,18 @@ function qval() {
s="${s//\`/\\\`}"
recho_ "$s"
}
function qval() {
echo -n \"
_qval "$@"
echo \"
}
function qvalr() {
if [ -n "$*" ]; then
echo -n \"
_qval "$@"
echo n \"
fi
}
function should_quote() {
[ -z "$1" ] && return 0
local s="${*//[a-zA-Z0-9]/}"
@ -166,7 +178,7 @@ function qvals() {
[ -z "$first" ] && echo -n " "
if should_quote "$arg"; then
echo -n \"
qval "$arg"
_qval "$arg"
echo -n \"
else
recho_ "$arg"
@ -179,21 +191,134 @@ function qlines() {
}
function setv() {
local __s_var="$1"; shift
eval "$__s_var=\"$(qval "$*")\""
if [[ "$__s_var" == *=* ]]; then
set -- "${__s_var#*=}" "$@"
__s_var="${__s_var%%=*}"
fi
eval "$__s_var=\"$(_qval "$*")\""
}
function _setv() {
local __s_var="$1"; shift
eval "$__s_var=\"$(_qval "$*")\""
}
function setx() {
local __s_var="$1"; shift
eval "$__s_var=\"\$(\"\$@\")\""
if [[ "$__s_var" == *=* ]]; then
set -- "${__s_var#*=}" "$@"
__s_var="${__s_var%%=*}"
fi
eval "$__s_var="'"$("$@")"'
}
function _setx() {
local __s_var="$1"; shift
eval "$__s_var="'"$("$@")"'
}
function seta() {
local __s_array="$1"; shift
if [[ "$__s_array" == *=* ]]; then
set -- "${__s_array#*=}" "$@"
__s_array="${__s_array%%=*}"
fi
eval "$__s_array=($("$@" | qlines))"
}
function e2of() {
"$@" 2>&1
function _seta() {
local __s_array="$1"; shift
eval "$__s_array=($("$@" | qlines))"
}
function nef() {
"$@" | sed '/^$/d'
function evalx() {
local __e_val __e_arg __e_r=0
local -a __e_cmd
local __e_first=1
while [ $# -gt 0 ]; do
__e_cmd=()
while [ $# -gt 0 ]; do
__e_arg="$1"; shift
[ "$__e_arg" == // ] && break
if [ "${__e_arg%//}" != "$__e_arg" ]; then
local __e_tmp="${__e_arg%//}"
if [ -z "${__e_tmp//\\/}" ]; then
__e_arg="${__e_arg#\\}"
__e_cmd=("${__e_cmd[@]}" "$__e_arg")
continue
fi
fi
__e_cmd=("${__e_cmd[@]}" "$__e_arg")
done
if [ -n "$first" ]; then
__e_val="$("${__e_cmd[@]}")" || __e_r=$?
else
__e_val="$("${__e_cmd[@]}" "$__e_val")" || __e_r=$?
fi
__e_first=
done
[ -n "$__e_val" ] && echo "$__e_val"
return $__e_r
}
function setx2() {
local __s_var="$1"; shift
if [[ "$__s_var" == *=* ]]; then
set -- "${__s_var#*=}" "$@"
__s_var="${__s_var%%=*}"
fi
setx "$__s_var" evalx "$@"
}
function evalp() {
local __e_arg __e_cmd
while [ $# -gt 0 ]; do
__e_arg="$1"; shift
if [ "$__e_arg" == // ]; then
__e_cmd="$__e_cmd |"
continue
elif [ "${__e_arg%//}" != "$__e_arg" ]; then
local __e_tmp="${__e_arg%//}"
if [ -z "${__e_tmp//\\/}" ]; then
__e_arg="${__e_arg#\\}"
fi
fi
__e_cmd="${__e_cmd:+$__e_cmd }\"$(_qval "$__e_arg")\""
done
eval "$__e_cmd"
}
function testx() {
local __t_op="$1"; shift
local __t_val="$(evalx "$@")"
[ $__t_op "$__t_val" ]
}
function test2x() {
local __t_val1="$1"; shift
local __t_op="$1"; shift
local __t_val2="$(evalx "$@")"
[ "$__t_val1" $__t_op "$__t_val2" ]
}
function testrx() {
local __t_val1="$1"; shift
local __t_op="$1"; shift
local __t_val2="$(evalx "$@")"
eval '[[ "$__t_val1" '"$__t_op"' "$__t_val2" ]]'
}
function testp() {
local __t_op="$1"; shift
local __t_val="$(evalp "$@")"
[ $__t_op "$__t_val" ]
}
function test2p() {
local __t_val1="$1"; shift
local __t_op="$1"; shift
local __t_val2="$(evalp "$@")"
[ "$__t_val1" $__t_op "$__t_val2" ]
}
function testrp() {
local __t_val1="$1"; shift
local __t_op="$1"; shift
local __t_val2="$(evalp "$@")"
eval '[[ "$__t_val1" '"$__t_op"' "$__t_val2" ]]'
}
function err2out() {
"$@" 2>&1
}
function tolower() {
@ -508,10 +633,12 @@ function array_new() {
eval "$1=()"
}
function array_add() {
eval "$1=(\"\${$1[@]}\" \"$(quote_arg "$2")\")"
local __aa_a="$1"; shift
eval "$__aa_a=(\"\${$__aa_a[@]}\" \"\$@\")"
}
function array_ins() {
eval "$1=(\"$(quote_arg "$2")\" \"\${$1[@]}\")"
local __aa_a="$1"; shift
eval "$__aa_a=(\"\$@\" \"\${$__aa_a[@]}\")"
}
function array_del() {
local __ad_v
@ -1342,6 +1469,9 @@ function array_lsdirs() {
function array_lsfiles() {
__array_ls files "$@"
}
function filter_empty() {
sed '/^$/d'
}
function filter_vcspath() {
sed '
/^.git$/d
@ -2532,7 +2662,7 @@ function pidfile_check() {
}
function page_maybe() {
if isatty; then
less -XF
less -XF "$@"
else
cat
fi
@ -3890,17 +4020,25 @@ if check_sysinfos -s macosx; then
function tolower() { tr A-Z a-z <<<"$*"; }
function toupper() { tr a-z A-Z <<<"$*"; }
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
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 "$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 "$(tolower "$1")" in
n|non|no|f|faux|false|off) return 0;;
esac
isnum "$1" && [ "$1" -eq 0 ] && return 0
return 1
}