Skip to content

Commit

Permalink
Improve yesno
Browse files Browse the repository at this point in the history
  • Loading branch information
vaeth committed Aug 29, 2016
1 parent e0d4199 commit 17f50f2
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 23 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Martin Väth <martin at mvath.de>:
- scripts: set -f in loops over lines:
https://bugs.gentoo.org/show_bug.cgi?id=591422
- Improve yesno detection (0 or - is false)

*eix-0.31.8
Martin Väth <martin at mvath.de>:
Expand Down
57 changes: 35 additions & 22 deletions src/eix-functions.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,17 @@ ReadVar() {
eval $1=\${eixf_read%X}
}

ReadBoolean() {
case `PRINT_APPEND=n "${2:-$read_var_prg}" --print "$1"` in
[nNfF]*|[oO][fF]*) return 1;;
yesno() {
case ${1:-n} in
[nNfF0-]*|[oO][fF]*)
return 1;;
esac
return 0
:
}

ReadBoolean() {
eixf_read=`PRINT_APPEND=n "${2:-$read_var_prg}" --print "$1"`
yesno "$eixf_read"
}

eixf_good=
Expand All @@ -54,7 +60,8 @@ StartInList() (
ReadVar startlist $2 || return
for start in $startlist
do case $1 in
"$start"*) return 0;;
"$start"*)
return 0;;
esac
done
return 1
Expand Down Expand Up @@ -229,7 +236,8 @@ Replace() {
eixf_repla=
eixf_replc='break'
case $1 in
-*) eixf_replc=
-*)
eixf_replc=
shift;;
esac
replace_count=
Expand Down Expand Up @@ -258,7 +266,8 @@ Push() {
# The name IFS can be changed if a third (resp. fourth) argument is given.
PushEscaped() {
case $1 in
-*) shift
-*)
shift
eval $1=;;
esac
if [ $# -lt 3 ] || [ -z "${3:++}" ]
Expand All @@ -278,7 +287,8 @@ PushEscaped() {
fi
Replace -g eixf_pex '\\' '\'
[ -n "${replace_tail:++}" ] && case $eixf_pex in
*\\) eixf_pew=$eixf_pew${eixf_pex%?}$eixf_pec
*\\)
eixf_pew=$eixf_pew${eixf_pex%?}$eixf_pec
continue;;
esac
eixf_pew=$eixf_pew$eixf_pex
Expand Down Expand Up @@ -356,8 +366,10 @@ AddLocalMethods() {
ReadVar eixf_al ADD_OVERLAY
PushEscaped eixf_alm "$eixf_al"
case $- in
*f*) eval "set -- a $eixf_alm";;
*) set -f
*f*)
eval "set -- a $eixf_alm";;
*)
set -f
eval "set -- a $eixf_alm"
set +f;;
esac
Expand Down Expand Up @@ -424,8 +436,10 @@ NormalizeNames() {
continue
fi
case $eixf_norma in
/*) :;;
*) relative="$relative $eixf_normc";;
/*)
:;;
*)
relative="$relative $eixf_normc";;
esac
$normalize_resolve && if CheckReadlink
then # Append A to avoid loss of trailing space in `...`
Expand All @@ -434,8 +448,10 @@ NormalizeNames() {
&& Chomp eixf_normb
elif test -d "$eixf_norma"
then eixf_normb=`case $eixf_norma in
/*) cd -P "$eixf_norma";;
*) cd -P "./$eixf_norma";;
/*)
cd -P "$eixf_norma";;
*)
cd -P "./$eixf_norma";;
esac >/dev/null 2>&1 \
&& printf '%sA' "$PWD"` \
&& eixf_normb=${eixf_normb%A}
Expand All @@ -452,13 +468,10 @@ NormalizeNames() {
}

ReadGettext() {
case ${USE_NLS-@USE_NLS@} in
''|[nNfF0]*)
false;;
esac && \
command -v envsubst >/dev/null 2>&1 && \
command -v gettext >/dev/null 2>&1 && {
export TEXTDOMAIN='@TEXTDOMAIN@'
if yesno "${USE_NLS-@USE_NLS@}" && \
command -v envsubst >/dev/null 2>&1 && \
command -v gettext >/dev/null 2>&1
then export TEXTDOMAIN='@TEXTDOMAIN@'
export TEXTDOMAINDIR='@TEXTDOMAINDIR@'
eixf_pgtglue=`printf '\004'`
pgettext() {
Expand Down Expand Up @@ -498,7 +511,7 @@ ReadGettext() {
:
}
return 0
}
fi
gettext() {
printf '%s' "$*"
}
Expand Down
1 change: 1 addition & 0 deletions src/eixrc/eixrc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,7 @@ bool EixRc::istrue(const char *s) {
case 'f':
case 'F':
case '0':
case '-':
return false;
case 'o':
case 'O':
Expand Down
2 changes: 1 addition & 1 deletion zsh/_eix.in
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ case $service in
if ((CURRENT>2))
then is_or=:
case $(PRINT_APPEND=n _call_program default_is_or 'eix --print DEFAULT_IS_OR 2>/dev/null') in
([nNfF0]*|[oO][fF]*)
([nNfF0-]*|[oO][fF]*)
is_or=false;;
esac
for ((i=2;i<CURRENT;++i))
Expand Down

0 comments on commit 17f50f2

Please sign in to comment.