E_GSU_EDITOR failed to execute editor
E_GSU_MKDIR failed to create directory
E_GSU_GETOPTS getopts error
+E_GSU_DIALOG dialog error
+E_GSU_MKTEMP mktemp error
+E_GSU_MENU_TREE invalid menu tree
$gsu_errors
"
local a b i=0
_get_geometry
g="$result"
result="$(dialog --inputbox "$text" $g "$init" 3>&1 1>&2 2>&3 3>&-)"
- ret="$?"
+ if (($? != 0)); then
+ ret=-$E_GSU_DIALOG
+ result='inputbox'
+ return
+ fi
+ ret=$GSU_SUCCESS
}
gsu_textbox()
{
- local file="$1"
+ local g file="$1"
_get_geometry
- dialog --textbox "$file" $result
+ g="$result"
+
+ ret=-$E_GSU_DIALOG
+ result='textbox'
+ dialog --textbox "$file" $g || return
+ ret=$GSU_SUCCESS
}
# dialog segfaults if message is too long. Hence we always use a temporary file
local tmp="$(mktemp gsu_msgbox.XXXXXXXXXX)"
if (($? != 0)); then
- dialog --msgbox "mktemp error" 0 0
+ ret=-$E_GSU_MKTEMP
+ result='temp file for textbox'
return
fi
echo "$1" > "$tmp"
gsu_textbox "$tmp"
- rm -f "$tmp"
+ rm -f "$tmp" # ignore errors
}
_gsu_menu()
opts+=" $i $num"
done
result="$(dialog --menu "$gsu_banner_txt ($header)" $opts 3>&1 1>&2 2>&3 3>&-)"
- ret="$?"
+ case $? in
+ 0) ret=$GSU_SUCCESS;;
+ 1) ret=1;; # cancelled
+ *)
+ result="menu error $ret"
+ ret=-$E_GSU_DIALOG
+ esac
}
_get_level()
local tree="$1" root="${2%/}"
local first TAB=' '
- first="$(grep -n "$TAB\{1,\}$root/" <<< "$tree")"
+ ret=-$E_GSU_MENU_TREE
+ result="subtree grep failed"
+ first="$(grep -n "$TAB\{1,\}$root/" <<< "$tree")" || return
[[ -z "$first" ]] && return
line_num="${first%%:*}"
result="$(sed -e "1,${line_num}d;" <<< "$tree" \
| sed -e "/^$TAB\{1,$level\}$_gsu_node_name_pattern/,\$d" \
| sed -e "/^$TAB\{$(($level + 2))\}/d")"
- ret="$level"
+ if (($? != 0)); then
+ ret=-$E_GSU_MENU_TREE
+ result="sed command for subtree $root failed"
+ return
+ fi
+ ret=$GSU_SUCCESS
}
_get_root_nodes()
local tree="$1" TAB=' '
result="$(grep "^${TAB}${_gsu_node_name_pattern}" <<< "$tree")"
+ if (($? != 0)); then
+ ret=-$E_GSU_MENU_TREE
+ result="root node grep failed"
+ return
+ fi
+ ret=$GSU_SUCCESS
}
_browse()
while :; do
_gsu_menu "$header" "$subtree"
- (($ret != 0)) && return
- [[ -z "$result" ]] && return
+ (($ret < 0)) && return
+ [[ -z "$result" ]] && return # menu was cancelled
if [[ "${result%/}" != "$result" ]]; then
old_header="$header"
header="$result"
_get_subtree "$tree" "$header"
+ (($ret < 0)) && return
_browse "$header" "$tree" "$result"
+ (($ret < 0)) && return
header="$old_header"
continue
fi