mirror of
https://github.com/sbopkg/sbopkg
synced 2025-01-18 10:26:27 +01:00
Use return values to implement the jump back to the main menu.
sbopkg 'touch'es a file (sbopkg_return_main_menu) to track that the user asked to jump back to the main menu from a "deep" menu level (such as info_item). This patch converts it to the usage of function return values, which makes the code smaller and easier to read. Signed-off-by: Mauro Giachero <mauro.giachero@gmail.com>
This commit is contained in:
parent
31ce00b3d1
commit
a24462f13f
1 changed files with 14 additions and 27 deletions
|
@ -954,6 +954,7 @@ view_app_file() {
|
||||||
info_item() {
|
info_item() {
|
||||||
# This function shows the menu for each package where the user can see
|
# This function shows the menu for each package where the user can see
|
||||||
# certain information or build the package.
|
# certain information or build the package.
|
||||||
|
# Returns 0 unless the user asked to jump back to the main menu.
|
||||||
|
|
||||||
local OLDPKG CATEGORY SHORTPATH CURVERSION CURARCH CURBUILD
|
local OLDPKG CATEGORY SHORTPATH CURVERSION CURARCH CURBUILD
|
||||||
local CURAPP LONGAPP SHORTAPP
|
local CURAPP LONGAPP SHORTAPP
|
||||||
|
@ -1049,8 +1050,7 @@ info_item() {
|
||||||
rm -f $SBOPKGTMP/sbopkg_info_selection
|
rm -f $SBOPKGTMP/sbopkg_info_selection
|
||||||
rm -f $SBOPKGTMP/sbopkg_item_selection
|
rm -f $SBOPKGTMP/sbopkg_item_selection
|
||||||
rm -f $SBOPKGTMP/sbopkg_search_*
|
rm -f $SBOPKGTMP/sbopkg_search_*
|
||||||
> $SBOPKGTMP/sbopkg_return_main_menu
|
return 1
|
||||||
return 0
|
|
||||||
;;
|
;;
|
||||||
3 ) return 0 ;; # Back
|
3 ) return 0 ;; # Back
|
||||||
0 ) # OK
|
0 ) # OK
|
||||||
|
@ -1159,10 +1159,7 @@ browse_categories() {
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
DEFAULTITEM=$(< $SBOPKGTMP/sbopkg_category_manual_selection)
|
DEFAULTITEM=$(< $SBOPKGTMP/sbopkg_category_manual_selection)
|
||||||
gen_search_package '*' $DEFAULTITEM
|
gen_search_package '*' $DEFAULTITEM || return 0
|
||||||
if [[ -e $SBOPKGTMP/sbopkg_return_main_menu ]]; then
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1859,11 +1856,11 @@ search_package() {
|
||||||
gen_search_package() {
|
gen_search_package() {
|
||||||
# Search for package name glob generally using grep. In dialog interface,
|
# Search for package name glob generally using grep. In dialog interface,
|
||||||
# jump to selected package.
|
# jump to selected package.
|
||||||
|
# Returns 0 unless the user asked to jump back to the main menu.
|
||||||
|
|
||||||
cd $REPO_DIR
|
cd $REPO_DIR
|
||||||
local PKG=$1
|
local PKG=$1
|
||||||
local CATEGORY=${2:-\*}
|
local CATEGORY=${2:-\*}
|
||||||
local RETURN_MAIN_MENU=$SBOPKGTMP/sbopkg_return_main_menu
|
|
||||||
local CAT_SELECTION=$SBOPKGTMP/sbopkg_category_selection
|
local CAT_SELECTION=$SBOPKGTMP/sbopkg_category_selection
|
||||||
local ITEM_SELECTION=$SBOPKGTMP/sbopkg_item_selection
|
local ITEM_SELECTION=$SBOPKGTMP/sbopkg_item_selection
|
||||||
local SEARCH_CHOICE=$SBOPKGTMP/sbopkg_search_choice
|
local SEARCH_CHOICE=$SBOPKGTMP/sbopkg_search_choice
|
||||||
|
@ -1908,8 +1905,7 @@ gen_search_package() {
|
||||||
elif [[ $CHOICE == 2 ]]; then
|
elif [[ $CHOICE == 2 ]]; then
|
||||||
# Main Menu
|
# Main Menu
|
||||||
rm -f $SEARCH_RESULTS
|
rm -f $SEARCH_RESULTS
|
||||||
touch $RETURN_MAIN_MENU
|
return 1
|
||||||
return 0
|
|
||||||
fi
|
fi
|
||||||
SRCHPICK="$(< $SEARCH_CHOICE)"
|
SRCHPICK="$(< $SEARCH_CHOICE)"
|
||||||
if [[ $CATEGORY == '*' ]]; then
|
if [[ $CATEGORY == '*' ]]; then
|
||||||
|
@ -1927,10 +1923,7 @@ gen_search_package() {
|
||||||
if [[ $CHOICE == 0 ]]; then
|
if [[ $CHOICE == 0 ]]; then
|
||||||
echo $SRCHPKG > $ITEM_SELECTION
|
echo $SRCHPKG > $ITEM_SELECTION
|
||||||
cd $REPO_DIR
|
cd $REPO_DIR
|
||||||
info_item
|
info_item || return 1
|
||||||
if [[ -e $RETURN_MAIN_MENU ]]; then
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
else # $CHOICE = 3
|
else # $CHOICE = 3
|
||||||
add_item_to_queue $SRCHPKG $RVERSION-$RBUILD ON
|
add_item_to_queue $SRCHPKG $RVERSION-$RBUILD ON
|
||||||
continue
|
continue
|
||||||
|
@ -1947,7 +1940,7 @@ gen_search_package() {
|
||||||
else
|
else
|
||||||
if [[ $DIAG ]]; then
|
if [[ $DIAG ]]; then
|
||||||
dialog --title "ERROR" --msgbox "No match for $PKG found" 8 30
|
dialog --title "ERROR" --msgbox "No match for $PKG found" 8 30
|
||||||
return 1
|
return 0
|
||||||
else
|
else
|
||||||
echo "$SCRIPT: No match for $PKG found." >&2
|
echo "$SCRIPT: No match for $PKG found." >&2
|
||||||
continue
|
continue
|
||||||
|
@ -1961,6 +1954,7 @@ string_search() {
|
||||||
# generates a potentially huge path consisting only of installed *SBo
|
# generates a potentially huge path consisting only of installed *SBo
|
||||||
# packages to hand to find. Otherwise, just search for $1 in REPO as
|
# packages to hand to find. Otherwise, just search for $1 in REPO as
|
||||||
# usual.
|
# usual.
|
||||||
|
# Returns 0 unless the user asked to jump back to the main menu.
|
||||||
|
|
||||||
if [[ ${SEARCH_TERM%%:*} == "inst" ]]; then
|
if [[ ${SEARCH_TERM%%:*} == "inst" ]]; then
|
||||||
local SEARCH_TERM="${SEARCH_TERM#*:}"
|
local SEARCH_TERM="${SEARCH_TERM#*:}"
|
||||||
|
@ -1975,7 +1969,6 @@ string_search() {
|
||||||
local SEARCH_TERM="$1"
|
local SEARCH_TERM="$1"
|
||||||
local FIND_PATH="$REPO"
|
local FIND_PATH="$REPO"
|
||||||
fi
|
fi
|
||||||
local RETURN_MAIN_MENU=$SBOPKGTMP/sbopkg_return_main_menu
|
|
||||||
local CAT_SELECTION=$SBOPKGTMP/sbopkg_category_selection
|
local CAT_SELECTION=$SBOPKGTMP/sbopkg_category_selection
|
||||||
local ITEM_SELECTION=$SBOPKGTMP/sbopkg_item_selection
|
local ITEM_SELECTION=$SBOPKGTMP/sbopkg_item_selection
|
||||||
local MENU_FILE=$SBOPKGTMP/sbopkg_menu-file
|
local MENU_FILE=$SBOPKGTMP/sbopkg_menu-file
|
||||||
|
@ -1998,7 +1991,7 @@ string_search() {
|
||||||
|
|
||||||
if [[ ! -s $MENU_FILE ]]; then
|
if [[ ! -s $MENU_FILE ]]; then
|
||||||
dialog --title "ERROR" --msgbox "No match for $SEARCH_TERM found" 8 30
|
dialog --title "ERROR" --msgbox "No match for $SEARCH_TERM found" 8 30
|
||||||
return 1
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cd $REPO_DIR
|
cd $REPO_DIR
|
||||||
|
@ -2023,8 +2016,7 @@ string_search() {
|
||||||
case $BUTTON in
|
case $BUTTON in
|
||||||
0)
|
0)
|
||||||
echo $SRCHPKG > $ITEM_SELECTION
|
echo $SRCHPKG > $ITEM_SELECTION
|
||||||
info_item
|
info_item || return 1
|
||||||
[[ -e $RETURN_MAIN_MENU ]] && return 0
|
|
||||||
;;
|
;;
|
||||||
3)
|
3)
|
||||||
SHORTPATH=$REPO_DIR/$SRCHCAT/$SRCHPKG
|
SHORTPATH=$REPO_DIR/$SRCHCAT/$SRCHPKG
|
||||||
|
@ -3231,12 +3223,10 @@ main_search() {
|
||||||
# FIXME *search*() functions use "continue" to influence this loop!
|
# FIXME *search*() functions use "continue" to influence this loop!
|
||||||
# There's too much stuff outside my 1/3 to fix this now.
|
# There's too much stuff outside my 1/3 to fix this now.
|
||||||
if [[ $PKG ]]; then
|
if [[ $PKG ]]; then
|
||||||
gen_search_package "$SEARCH_TERM"
|
gen_search_package "$SEARCH_TERM" || return
|
||||||
elif [[ $STRING ]]; then
|
elif [[ $STRING ]]; then
|
||||||
string_search "$SEARCH_TERM"
|
string_search "$SEARCH_TERM" || return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[[ -f $SBOPKGTMP/sbopkg_return_main_menu ]] && return
|
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3272,7 +3262,6 @@ main_menu() {
|
||||||
|
|
||||||
local DEFAULTITEM
|
local DEFAULTITEM
|
||||||
local ANSWER_FILE=$SBOPKGTMP/sbopkg_main_menu_answer
|
local ANSWER_FILE=$SBOPKGTMP/sbopkg_main_menu_answer
|
||||||
local RETURN_MAIN_MENU=$SBOPKGTMP/sbopkg_return_main_menu
|
|
||||||
|
|
||||||
while :; do
|
while :; do
|
||||||
dialog --cancel-label "Exit" --default-item "$DEFAULTITEM" --title \
|
dialog --cancel-label "Exit" --default-item "$DEFAULTITEM" --title \
|
||||||
|
@ -3303,13 +3292,11 @@ main_menu() {
|
||||||
"Updates" )
|
"Updates" )
|
||||||
main_updates ;;
|
main_updates ;;
|
||||||
"Browse" )
|
"Browse" )
|
||||||
browse_categories
|
browse_categories ;;
|
||||||
rm -f $RETURN_MAIN_MENU ;;
|
|
||||||
"Search" )
|
"Search" )
|
||||||
main_search
|
main_search
|
||||||
# FIXME main_search should delete this
|
# FIXME main_search should delete this
|
||||||
rm -f $SBOPKGTMP/sbopkg_search_*
|
rm -f $SBOPKGTMP/sbopkg_search_* ;;
|
||||||
rm -f $RETURN_MAIN_MENU ;;
|
|
||||||
"Utilities" )
|
"Utilities" )
|
||||||
utilities_menu ;;
|
utilities_menu ;;
|
||||||
"Queue" )
|
"Queue" )
|
||||||
|
|
Loading…
Reference in a new issue