maj ulib/base

This commit is contained in:
Jephte CLAIN 2014-01-03 00:01:32 +04:00
parent f7168a4a74
commit a362dd3d72
3 changed files with 101 additions and 31 deletions

View File

@ -732,10 +732,14 @@ function uaddpath() {
local _qdir="${1//\//\\/}" local _qdir="${1//\//\\/}"
eval "export ${2:-PATH}; "'[ "${'"${2:-PATH}"'#$1:}" == "$'"${2:-PATH}"'" -a "${'"${2:-PATH}"'%:$1}" == "$'"${2:-PATH}"'" -a "${'"${2:-PATH}"'//:$_qdir:/:}" == "$'"${2:-PATH}"'" -a "$'"${2:-PATH}"'" != "$1" ] && '"${2:-PATH}"'="${'"${2:-PATH}"':+$'"${2:-PATH}"':}$1"' eval "export ${2:-PATH}; "'[ "${'"${2:-PATH}"'#$1:}" == "$'"${2:-PATH}"'" -a "${'"${2:-PATH}"'%:$1}" == "$'"${2:-PATH}"'" -a "${'"${2:-PATH}"'//:$_qdir:/:}" == "$'"${2:-PATH}"'" -a "$'"${2:-PATH}"'" != "$1" ] && '"${2:-PATH}"'="${'"${2:-PATH}"':+$'"${2:-PATH}"':}$1"'
} }
function uinspath() { function uinspathm() {
local _qdir="${1//\//\\/}" local _qdir="${1//\//\\/}"
eval "export ${2:-PATH}; "'[ "${'"${2:-PATH}"'#$1:}" == "$'"${2:-PATH}"'" -a "${'"${2:-PATH}"'%:$1}" == "$'"${2:-PATH}"'" -a "${'"${2:-PATH}"'//:$_qdir:/:}" == "$'"${2:-PATH}"'" -a "$'"${2:-PATH}"'" != "$1" ] && '"${2:-PATH}"'="$1${'"${2:-PATH}"':+:$'"${2:-PATH}"'}"' eval "export ${2:-PATH}; "'[ "${'"${2:-PATH}"'#$1:}" == "$'"${2:-PATH}"'" -a "${'"${2:-PATH}"'%:$1}" == "$'"${2:-PATH}"'" -a "${'"${2:-PATH}"'//:$_qdir:/:}" == "$'"${2:-PATH}"'" -a "$'"${2:-PATH}"'" != "$1" ] && '"${2:-PATH}"'="$1${'"${2:-PATH}"':+:$'"${2:-PATH}"'}"'
} }
function uinspath() {
udelpath "$@"
uinspathm "$@"
}
function withpath() { function withpath() {
[ "${1#./}" != "$1" -o "${1#../}" != "$1" -o "${1#/}" != "$1" ] [ "${1#./}" != "$1" -o "${1#../}" != "$1" -o "${1#/}" != "$1" ]
@ -902,6 +906,7 @@ function deref() {
local max_deref=50 local max_deref=50
local file="$1" local file="$1"
local basedir link
while [ -L "$file" ]; do while [ -L "$file" ]; do
basedir="$(dirname "$file")" basedir="$(dirname "$file")"
link="$(readlink "$file")" link="$(readlink "$file")"
@ -916,6 +921,9 @@ function deref() {
done done
abspath "$file" abspath "$file"
} }
function readlinkm() {
readlink -m "$1"
}
function path_if_test() { function path_if_test() {
local op="$1"; shift local op="$1"; shift
local file="$1"; shift local file="$1"; shift
@ -2011,17 +2019,22 @@ function awkdef() {
__ad_value="${1:$__ad_vpos}" __ad_value="${1:$__ad_vpos}"
[ ${#__ad_value} -ne 0 ] || __ad_value="$__ad_name" [ ${#__ad_value} -ne 0 ] || __ad_value="$__ad_name"
elif [[ "$__ad_arg" == *=* ]]; then elif [[ "$__ad_arg" == *=* ]]; then
local __ad_int= local __ad_int= __ad_str=
__ad_name="${__ad_arg%%=*}" __ad_name="${__ad_arg%%=*}"
__ad_vpos=$((${#__ad_name} + 1)) __ad_vpos=$((${#__ad_name} + 1))
[ "${__ad_name%:int}" != "$__ad_name" ] && { if [ "${__ad_name%:int}" != "$__ad_name" ]; then
__ad_int=1 __ad_int=1
__ad_name="${__ad_name%:int}" __ad_name="${__ad_name%:int}"
} elif [ "${__ad_name%:str}" != "$__ad_name" ]; then
__ad_str=1
__ad_name="${__ad_name%:str}"
fi
[ -z "${__ad_name//[a-zA-Z0-9_]/}" ] || break [ -z "${__ad_name//[a-zA-Z0-9_]/}" ] || break
__ad_value="${1:$__ad_vpos}" __ad_value="${1:$__ad_vpos}"
if [ -n "$__ad_int" ]; then if [ -n "$__ad_int" ]; then
echo "$__ad_name = int($(quoted_awk "$__ad_value") + 0)" echo "$__ad_name = int($(quoted_awk "$__ad_value") + 0)"
elif [ -n "$__ad_str" ]; then
echo "$__ad_name = $(quoted_awk "$__ad_value")"
elif [ ${#__ad_value} -lt 256 ] && isnum "$__ad_value"; then elif [ ${#__ad_value} -lt 256 ] && isnum "$__ad_value"; then
echo "$__ad_name = $__ad_value" echo "$__ad_name = $__ad_value"
else else
@ -2255,10 +2268,13 @@ function __genparse_shortopt() {
shortopt="${shortopt,,}" shortopt="${shortopt,,}"
[ -n "$shortopt" ] && echo "$shortopt" [ -n "$shortopt" ] && echo "$shortopt"
} }
HELP_DESC=
HELP_USAGE=
HELP_OPTIONS=
function genparse() { function genparse() {
local -a descs vars options local -a names descs vars options
local desc var option name value shortopt local i desc var option name value shortopt
for var in "$@"; do for var in "$@"; do
if [[ "$var" == *=* ]]; then if [[ "$var" == *=* ]]; then
@ -2266,6 +2282,7 @@ function genparse() {
shortopt="$(__genparse_shortopt "$name")" shortopt="$(__genparse_shortopt "$name")"
option="${name,,}" option="${name,,}"
name="${option//-/_}" name="${option//-/_}"
array_add names "$name"
array_add descs "${shortopt:+-$shortopt, }--$option VALUE" array_add descs "${shortopt:+-$shortopt, }--$option VALUE"
array_add vars "$(set_var_cmd "$name" "$value")" array_add vars "$(set_var_cmd "$name" "$value")"
array_add options "${shortopt:+-$shortopt:,}--$option: $name=" array_add options "${shortopt:+-$shortopt:,}--$option: $name="
@ -2274,6 +2291,7 @@ function genparse() {
shortopt="$(__genparse_shortopt "$name")" shortopt="$(__genparse_shortopt "$name")"
option="${name,,}" option="${name,,}"
name="${option//-/_}" name="${option//-/_}"
array_add names "$name"
array_add descs "${shortopt:+-$shortopt, }--$option" array_add descs "${shortopt:+-$shortopt, }--$option"
array_add vars "$name=" array_add vars "$name="
array_add options "${shortopt:+-$shortopt,}--$option $name=1" array_add options "${shortopt:+-$shortopt,}--$option $name=1"
@ -2281,19 +2299,30 @@ function genparse() {
done done
echo -n 'function display_help() { echo -n 'function display_help() {
uecho "\ [ -n "$HELP_USAGE" ] || HELP_USAGE="USAGE
USAGE
$scriptname' $scriptname'
[ -n "$descs" ] && echo -n ' [options]'
echo '"'
if [ -n "$descs" ]; then if [ -n "$descs" ]; then
echo -n ' [options] echo -n ' [ -n "$HELP_OPTIONS" ] || HELP_OPTIONS="OPTIONS'
i=0
OPTIONS' while [ $i -lt ${#descs[*]} ]; do
for desc in "${descs[@]}"; do name="${names[$i]}"
desc="${descs[$i]}"
echo -n " echo -n "
$desc" \${HELP_${name^^}_OPTION:- $desc\${HELP_${name^^}_DESC:+
\${HELP_${name^^}_DESC//
/
}}}"
i=$(($i + 1))
done done
echo '"'
fi fi
echo '" echo ' uecho "${HELP_DESC:+$HELP_DESC
}$HELP_USAGE${HELP_OPTIONS:+
$HELP_OPTIONS}"
} }
' '
for var in "${vars[@]}"; do for var in "${vars[@]}"; do
@ -3720,6 +3749,8 @@ uprovide compat
urequire base sysinfos urequire base sysinfos
if check_sysinfos -s macosx; then if check_sysinfos -s macosx; then
function __rlnp() { local p="$1" np f; [ "${p#/}" == "$p" ] && p="$(pwd)/$p"; while [[ "$p" == *//* ]]; do p="${p//\/\///}"; done; p="${p%/}"; p="${p#/}"; np=; while [ -n "$p" ]; do if [[ "$p" == */* ]]; then f="${p%%/*}"; p="${p#*/}"; else f="$p"; p=; fi; if [ "$f" == . ]; then :; elif [ "$f" == .. ]; then if [[ "$np" == */* ]]; then np="${np%/*}"; else np=; fi; else [ -n "$np" ] && np="$np/"; np="$np$f"; fi; done; echo "/$np"; }
function readlinkm() { local p="$(__rlnp "$1")" np n; while [ -n "$p" ]; do local max=50; while [ -L "$p" -a $max -gt 0 ]; do n="$(readlink "$p")"; if [ "${n#/}" != "$n" ]; then p="$n"; else p="${p%/*}/$n"; fi; p="$(__rlnp "$p")"; max=$(($max-1)); done; [ -n "$np" ] && np="/$np"; if [[ "$p" == */* ]]; then np="${p##*/}$np"; p="${p%/*}"; else np="$p$np"; p=; fi; done; echo "/$np"; }
function _nl2lf() { awk '{ sub(/\r$/, ""); gsub(/\r/, "\n"); print }'; } function _nl2lf() { awk '{ sub(/\r$/, ""); gsub(/\r/, "\n"); print }'; }
function _nl2crlf() { _nl2lf | awk '{ print $0 "\r" }'; } function _nl2crlf() { _nl2lf | awk '{ print $0 "\r" }'; }
function _nl2cr() { _nl2lf | awk 'BEGIN { ORS="" } { print $0 "\r" }'; } function _nl2cr() { _nl2lf | awk 'BEGIN { ORS="" } { print $0 "\r" }'; }
@ -4175,8 +4206,16 @@ BEGIN {
next next
} }
/^\$.+/ { /^\$.+/ {
if ($0 ~ /^\$\{([ \t]*(#.*)?)?$/) {
getline
while ($0 !~ /^\$\}([ \t]*(#.*)?)?$/) {
print
if (getline <= 0) break
}
} else {
sub(/^\$/, "", $0) sub(/^\$/, "", $0)
print print
}
next next
} }
/^[ \t]*[-0-9/*,]+[ ]*[-0-9/*,]+[ ]*[-0-9/*,]+[ ]*[-0-9/*,]+[ ]*[-0-9/*,]+/ { /^[ \t]*[-0-9/*,]+[ ]*[-0-9/*,]+[ ]*[-0-9/*,]+[ ]*[-0-9/*,]+[ ]*[-0-9/*,]+/ {

View File

@ -1 +1 @@
15 16

View File

@ -645,10 +645,14 @@ function uaddpath() {
local _qdir="${1//\//\\/}" local _qdir="${1//\//\\/}"
eval "export ${2:-PATH}; "'[ "${'"${2:-PATH}"'#$1:}" == "$'"${2:-PATH}"'" -a "${'"${2:-PATH}"'%:$1}" == "$'"${2:-PATH}"'" -a "${'"${2:-PATH}"'//:$_qdir:/:}" == "$'"${2:-PATH}"'" -a "$'"${2:-PATH}"'" != "$1" ] && '"${2:-PATH}"'="${'"${2:-PATH}"':+$'"${2:-PATH}"':}$1"' eval "export ${2:-PATH}; "'[ "${'"${2:-PATH}"'#$1:}" == "$'"${2:-PATH}"'" -a "${'"${2:-PATH}"'%:$1}" == "$'"${2:-PATH}"'" -a "${'"${2:-PATH}"'//:$_qdir:/:}" == "$'"${2:-PATH}"'" -a "$'"${2:-PATH}"'" != "$1" ] && '"${2:-PATH}"'="${'"${2:-PATH}"':+$'"${2:-PATH}"':}$1"'
} }
function uinspath() { function uinspathm() {
local _qdir="${1//\//\\/}" local _qdir="${1//\//\\/}"
eval "export ${2:-PATH}; "'[ "${'"${2:-PATH}"'#$1:}" == "$'"${2:-PATH}"'" -a "${'"${2:-PATH}"'%:$1}" == "$'"${2:-PATH}"'" -a "${'"${2:-PATH}"'//:$_qdir:/:}" == "$'"${2:-PATH}"'" -a "$'"${2:-PATH}"'" != "$1" ] && '"${2:-PATH}"'="$1${'"${2:-PATH}"':+:$'"${2:-PATH}"'}"' eval "export ${2:-PATH}; "'[ "${'"${2:-PATH}"'#$1:}" == "$'"${2:-PATH}"'" -a "${'"${2:-PATH}"'%:$1}" == "$'"${2:-PATH}"'" -a "${'"${2:-PATH}"'//:$_qdir:/:}" == "$'"${2:-PATH}"'" -a "$'"${2:-PATH}"'" != "$1" ] && '"${2:-PATH}"'="$1${'"${2:-PATH}"':+:$'"${2:-PATH}"'}"'
} }
function uinspath() {
udelpath "$@"
uinspathm "$@"
}
function withpath() { function withpath() {
[ "${1#./}" != "$1" -o "${1#../}" != "$1" -o "${1#/}" != "$1" ] [ "${1#./}" != "$1" -o "${1#../}" != "$1" -o "${1#/}" != "$1" ]
@ -815,6 +819,7 @@ function deref() {
local max_deref=50 local max_deref=50
local file="$1" local file="$1"
local basedir link
while [ -L "$file" ]; do while [ -L "$file" ]; do
basedir="$(dirname "$file")" basedir="$(dirname "$file")"
link="$(readlink "$file")" link="$(readlink "$file")"
@ -829,6 +834,9 @@ function deref() {
done done
abspath "$file" abspath "$file"
} }
function readlinkm() {
readlink -m "$1"
}
function path_if_test() { function path_if_test() {
local op="$1"; shift local op="$1"; shift
local file="$1"; shift local file="$1"; shift
@ -1924,17 +1932,22 @@ function awkdef() {
__ad_value="${1:$__ad_vpos}" __ad_value="${1:$__ad_vpos}"
[ ${#__ad_value} -ne 0 ] || __ad_value="$__ad_name" [ ${#__ad_value} -ne 0 ] || __ad_value="$__ad_name"
elif [[ "$__ad_arg" == *=* ]]; then elif [[ "$__ad_arg" == *=* ]]; then
local __ad_int= local __ad_int= __ad_str=
__ad_name="${__ad_arg%%=*}" __ad_name="${__ad_arg%%=*}"
__ad_vpos=$((${#__ad_name} + 1)) __ad_vpos=$((${#__ad_name} + 1))
[ "${__ad_name%:int}" != "$__ad_name" ] && { if [ "${__ad_name%:int}" != "$__ad_name" ]; then
__ad_int=1 __ad_int=1
__ad_name="${__ad_name%:int}" __ad_name="${__ad_name%:int}"
} elif [ "${__ad_name%:str}" != "$__ad_name" ]; then
__ad_str=1
__ad_name="${__ad_name%:str}"
fi
[ -z "${__ad_name//[a-zA-Z0-9_]/}" ] || break [ -z "${__ad_name//[a-zA-Z0-9_]/}" ] || break
__ad_value="${1:$__ad_vpos}" __ad_value="${1:$__ad_vpos}"
if [ -n "$__ad_int" ]; then if [ -n "$__ad_int" ]; then
echo "$__ad_name = int($(quoted_awk "$__ad_value") + 0)" echo "$__ad_name = int($(quoted_awk "$__ad_value") + 0)"
elif [ -n "$__ad_str" ]; then
echo "$__ad_name = $(quoted_awk "$__ad_value")"
elif [ ${#__ad_value} -lt 256 ] && isnum "$__ad_value"; then elif [ ${#__ad_value} -lt 256 ] && isnum "$__ad_value"; then
echo "$__ad_name = $__ad_value" echo "$__ad_name = $__ad_value"
else else
@ -2168,10 +2181,13 @@ function __genparse_shortopt() {
shortopt="${shortopt,,}" shortopt="${shortopt,,}"
[ -n "$shortopt" ] && echo "$shortopt" [ -n "$shortopt" ] && echo "$shortopt"
} }
HELP_DESC=
HELP_USAGE=
HELP_OPTIONS=
function genparse() { function genparse() {
local -a descs vars options local -a names descs vars options
local desc var option name value shortopt local i desc var option name value shortopt
for var in "$@"; do for var in "$@"; do
if [[ "$var" == *=* ]]; then if [[ "$var" == *=* ]]; then
@ -2179,6 +2195,7 @@ function genparse() {
shortopt="$(__genparse_shortopt "$name")" shortopt="$(__genparse_shortopt "$name")"
option="${name,,}" option="${name,,}"
name="${option//-/_}" name="${option//-/_}"
array_add names "$name"
array_add descs "${shortopt:+-$shortopt, }--$option VALUE" array_add descs "${shortopt:+-$shortopt, }--$option VALUE"
array_add vars "$(set_var_cmd "$name" "$value")" array_add vars "$(set_var_cmd "$name" "$value")"
array_add options "${shortopt:+-$shortopt:,}--$option: $name=" array_add options "${shortopt:+-$shortopt:,}--$option: $name="
@ -2187,6 +2204,7 @@ function genparse() {
shortopt="$(__genparse_shortopt "$name")" shortopt="$(__genparse_shortopt "$name")"
option="${name,,}" option="${name,,}"
name="${option//-/_}" name="${option//-/_}"
array_add names "$name"
array_add descs "${shortopt:+-$shortopt, }--$option" array_add descs "${shortopt:+-$shortopt, }--$option"
array_add vars "$name=" array_add vars "$name="
array_add options "${shortopt:+-$shortopt,}--$option $name=1" array_add options "${shortopt:+-$shortopt,}--$option $name=1"
@ -2194,19 +2212,30 @@ function genparse() {
done done
echo -n 'function display_help() { echo -n 'function display_help() {
uecho "\ [ -n "$HELP_USAGE" ] || HELP_USAGE="USAGE
USAGE
$scriptname' $scriptname'
[ -n "$descs" ] && echo -n ' [options]'
echo '"'
if [ -n "$descs" ]; then if [ -n "$descs" ]; then
echo -n ' [options] echo -n ' [ -n "$HELP_OPTIONS" ] || HELP_OPTIONS="OPTIONS'
i=0
OPTIONS' while [ $i -lt ${#descs[*]} ]; do
for desc in "${descs[@]}"; do name="${names[$i]}"
desc="${descs[$i]}"
echo -n " echo -n "
$desc" \${HELP_${name^^}_OPTION:- $desc\${HELP_${name^^}_DESC:+
\${HELP_${name^^}_DESC//
/
}}}"
i=$(($i + 1))
done done
echo '"'
fi fi
echo '" echo ' uecho "${HELP_DESC:+$HELP_DESC
}$HELP_USAGE${HELP_OPTIONS:+
$HELP_OPTIONS}"
} }
' '
for var in "${vars[@]}"; do for var in "${vars[@]}"; do
@ -3433,6 +3462,8 @@ uprovide compat
urequire base sysinfos urequire base sysinfos
if check_sysinfos -s macosx; then if check_sysinfos -s macosx; then
function __rlnp() { local p="$1" np f; [ "${p#/}" == "$p" ] && p="$(pwd)/$p"; while [[ "$p" == *//* ]]; do p="${p//\/\///}"; done; p="${p%/}"; p="${p#/}"; np=; while [ -n "$p" ]; do if [[ "$p" == */* ]]; then f="${p%%/*}"; p="${p#*/}"; else f="$p"; p=; fi; if [ "$f" == . ]; then :; elif [ "$f" == .. ]; then if [[ "$np" == */* ]]; then np="${np%/*}"; else np=; fi; else [ -n "$np" ] && np="$np/"; np="$np$f"; fi; done; echo "/$np"; }
function readlinkm() { local p="$(__rlnp "$1")" np n; while [ -n "$p" ]; do local max=50; while [ -L "$p" -a $max -gt 0 ]; do n="$(readlink "$p")"; if [ "${n#/}" != "$n" ]; then p="$n"; else p="${p%/*}/$n"; fi; p="$(__rlnp "$p")"; max=$(($max-1)); done; [ -n "$np" ] && np="/$np"; if [[ "$p" == */* ]]; then np="${p##*/}$np"; p="${p%/*}"; else np="$p$np"; p=; fi; done; echo "/$np"; }
function _nl2lf() { awk '{ sub(/\r$/, ""); gsub(/\r/, "\n"); print }'; } function _nl2lf() { awk '{ sub(/\r$/, ""); gsub(/\r/, "\n"); print }'; }
function _nl2crlf() { _nl2lf | awk '{ print $0 "\r" }'; } function _nl2crlf() { _nl2lf | awk '{ print $0 "\r" }'; }
function _nl2cr() { _nl2lf | awk 'BEGIN { ORS="" } { print $0 "\r" }'; } function _nl2cr() { _nl2lf | awk 'BEGIN { ORS="" } { print $0 "\r" }'; }