+if [ $MODE = 1 ]; then
+ sed --in-place 's:\r\n:\n:g;s:\r::g' "$tmp"
+fi
+
+# Process page content
+case "$MODE" in
+download)
+ # Special, fake mode, only from top-level
+ cat "$tmp"
+;;
+0)
+ cat "$tmp" | less
+;;
+1|+)
+ CHOICE=0
+ while [ "$CHOICE" != "" ]; do
+ if [ "$USE_DIALOG" = 1 ]; then
+ > "$tmp.menu"
+ cat_menu "$tmp" dialog | while read ln; do
+ echo -n " $ln" >> "$tmp.menu"
+ done
+ [ "$LINES" = "" ] && LINES=`tput lines`
+ [ "$COLUMNS" = "" ] && COLUMNS=`tput cols`
+ title="$SERVER: $SELECTOR"
+ dialog --extra-button --extra-label Back \
+ --cancel-label Exit \
+ --no-shadow \
+ --menu "$title" \
+ "$LINES" "$COLUMNS" "$LINES" \
+ --file "$tmp.menu" 2>"$tmp.choice"
+ val=$?
+ clear
+
+ if [ $val = 3 ]; then
+ CHOICE=""
+ elif [ $val = 1 ]; then
+ CHOICE="q"
+ else
+ CHOICE="`cat "$tmp.choice" | cut -c5-`"
+ fi
+
+ rm "$tmp.menu"
+ rm "$tmp.choice"
+ else
+ cat_menu "$tmp" | less
+ read -p "[$SELECTOR]: " NEW_CHOICE
+ if [ "$NEW_CHOICE" = p ]; then
+ CHOICE=`expr "$CHOICE" - 1 2>/dev/null`
+ if [ "$CHOICE" -lt 0 ]; then
+ CHOICE=`cat "$tmp" | grep "^$PREFIX" | wc --lines`
+ fi
+ elif [ "$NEW_CHOICE" = n ]; then
+ CHOICE=`expr "$CHOICE" + 1 2>/dev/null`
+ else
+ CHOICE="$NEW_CHOICE"
+ fi
+ fi
+
+ [ "$CHOICE" = q ] && exit 255 # force-quit
+ index="`expr 1 \* "$CHOICE" 2>/dev/null`"
+ if [ "$index" != "" ]; then
+ goto_server="`getsel "$tmp" $index 3`"
+ goto_sel="`getsel "$tmp" $index 2`"
+ goto_port="`getsel "$tmp" $index 4`"
+ goto_mode="`getsel "$tmp" $index 1 | cut -c1`"
+ echo "Digging to [$goto_server:$goto_port] $index [$goto_sel]..."
+ sh "$0" "$goto_server:$goto_port/$goto_mode/$goto_sel"
+ [ $? = 255 ] && exit 255 # force-quit
+ fi
+ done
+;;
+7)
+ read -p "Query: " SEARCH
+ selQuery="$SELECTOR $SEARCH"
+
+ exec sh "$0" "$SERVER" "$selQuery" "$PORT" 1
+;;
+8)
+ telnet -l "$SELECTOR" "$SERVER" "$PORT"
+ read DUMMY
+;;
+9)
+ echo "<BINARY FILE>" | less
+;;
+g|I)
+ if img2aa --help >/dev/null 2>&1; then
+ img2aa --mode=DITHERING \
+ $INVERT \
+ --width=74 "$tmp" | less
+ elif jp2a -h >/dev/null 2>&1; then
+ if convert -h >/dev/null 2>&1; then
+ convert "$tmp" "$tmp.jpg"
+ jp2a --border --chars=" .-+=o8#"\
+ $INVERT \
+ --width=74 "$tmp.jpg" | less
+ else
+ echo "required program not found to view images: convert" \
+ | less
+ fi
+ else
+ echo "required program not found to view images:" \
+ jp2a or img2aa | less
+ fi
+;;
+*)
+ echo "unknwon selector mode: <$MODE>" | less
+ exit 3
+;;
+esac
+