-echo "#/bin/sh
-# PID: $$
-# PID File (this file): $PIDF
-# You can stop the service by deleting this file then making a last
-# connection (which will not be processed) to the service:
-rm \"$PIDF\"
-nc -q0 $ADDR $port 2>/dev/null </dev/null
-" > "$PIDF"
+# can be "-" for no escape sequences
+[ "$LINK_COLOR" = "" ] && LINK_COLOR=2
+
+# Start and end link tags
+SL=
+EL=
+if [ "$LINK_COLOR" != "-" ]; then
+ SL="`tput setf $LINK_COLOR``tput setaf $LINK_COLOR`"
+ EL="`tput init`";
+fi
+
+# $0 [FILE]
+# Display a gopher menu for the given resource
+cat_menu() {
+ i=0
+ cat "$1" | grep '^[i0-9]' | while read ln; do
+ ln="`echo "$ln" | cut -f1`"
+ if echo "$ln" | grep "^i" >/dev/null 2>&1; then
+ echo "$ln" | sed "s:^.: :g"
+ elif echo "$ln" | grep "^[0-9]" >/dev/null 2>&1; then
+ i=`expr $i + 1`
+ i=`printf %2.f $i`
+ field="`echo "$ln" | cut -c1`"
+ case "$field" in
+ 0) typ='TXT';;
+ 1) typ='DIR';;
+ 7) typ='(?)';;
+ 8) typ='TEL';;
+ *) typ='!!!';;
+ esac
+ echo "$ln" | sed "s:^.\\(.*\\):$typ $i $SL\\1$EL:g"
+ #else
+ # Bad line
+ fi
+ done
+}
+
+# $0 [FILE] [INDEX] [FIELD]
+# Get a field from the given-by-index link in FILE
+#
+# Fields:
+# 1 = type/name
+# 2 = selector
+# 3 = server
+# 4 = port
+getsel() {
+ cat "$1" | grep '^[0-9]' | tail -n+"$2" | head -n 1 | cut -f"$3"
+}