Merge branch 'refs/heads/t/help-a' into pu
[gsu.git] / gui
diff --git a/gui b/gui
index fa3ae48..4297564 100644 (file)
--- a/gui
+++ b/gui
@@ -4,7 +4,7 @@
 
 if [[ "$(type -t _gsu_setup)" != "function" ]]; then
        gsu_dir=${gsu_dir:-${BASH_SOURCE[0]%/*}}
-       . $gsu_dir/common || exit 1
+       . "$gsu_dir/common" || exit 1
        _gsu_setup
 fi
 
@@ -20,7 +20,7 @@ _get_geometry()
        fi
        x="${result#* }"
        y="${result%% *}"
-       (($x > 190)) && x=190
+       ((x > 190)) && x=190
        result="$y $x"
 }
 
@@ -80,15 +80,13 @@ gsu_textbox()
 # This is like gsu_textbox() but the text is passed as a string.
 gsu_msgbox()
 {
+       local tmp
+
        # Some versions of dialog segfault if the text is too long. Hence we
        # always use a temporary file.
-       local tmp="$(mktemp gsu_msgbox.XXXXXXXXXX)"
-
-       if (($? != 0)); then
-               ret=-$E_GSU_MKTEMP
-               result='temp file for textbox'
-               return
-       fi
+       gsu_make_tempfile 'gsu_msgbox.XXXXXXXXXX'
+       ((ret < 0)) && return
+       tmp="$result"
        trap "rm -f $tmp" EXIT
        echo "$1" > "$tmp"
        gsu_textbox "$tmp"
@@ -99,7 +97,7 @@ _gsu_menu()
 {
        local header="${1:-root}"
        local items="$2"
-       local i state opts num=0
+       local i opts num=0
 
        _get_geometry
        opts="$result 16"
@@ -134,7 +132,7 @@ _get_subtree()
        #echo "line: $line_num, root: $root, indent level: $level"
        result="$(sed -e "1,${line_num}d;" <<< "$tree" \
                | sed -e "/^$TAB\{1,$level\}$_gsu_node_name_pattern/,\$d" \
-               | sed -e "/^$TAB\{$(($level + 2))\}/d")"
+               | sed -e "/^$TAB\{$((level + 2))\}/d")"
        if (($? != 0)); then
                ret=-$E_GSU_MENU_TREE
                result="sed command for subtree $root failed"
@@ -163,15 +161,15 @@ _browse()
 
        while :; do
                _gsu_menu "$header" "$subtree"
-               (($ret < 0)) && 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
+                       ((ret < 0)) && return
                        _browse "$header" "$tree" "$result"
-                       (($ret < 0)) && return
+                       ((ret < 0)) && return
                        header="$old_header"
                        continue
                fi