code cleanup -- DEBUG messages isolated

master
KatolaZ 7 years ago
parent 6756f54d52
commit 1abda73794
  1. 19
      gosher

@ -26,6 +26,9 @@ NETCAT=netcat
OPREFIX=/tmp/outf_ OPREFIX=/tmp/outf_
IPREFIX=/tmp/inf_ IPREFIX=/tmp/inf_
DEBUG=
##DEBUG=yes
## function ## function
cleanup(){ cleanup(){
@ -67,7 +70,7 @@ fi
## function ## function
invalid_selector(){ invalid_selector(){
sel="$1" sel="$1"
echo "iInvalid selector: \"$sel\"" echo "3Error: Invalid selector: \"$sel\""
echo "." echo "."
exit 1 exit 1
} }
@ -77,7 +80,6 @@ serve_selector(){
sel="$1" sel="$1"
cat "${sel}" cat "${sel}"
echo "."
exit 0 exit 0
} }
@ -101,6 +103,7 @@ serve_index(){
echo $line echo $line
esac esac
done < $IDX done < $IDX
printf ".\r\n"
exit 0 exit 0
} }
@ -112,16 +115,19 @@ read selector
selector=$(echo $selector | sed -r 's:\r::g' ) selector=$(echo $selector | sed -r 's:\r::g' )
[ -n "$DEBUG" ] && {
echo "iGOPHERDIR: ${GOPHERDIR}" echo "iGOPHERDIR: ${GOPHERDIR}"
echo "iselector: \"${selector}\"" echo "iselector: \"${selector}\""
}
case $selector in case $selector in
/*|"") /*|"")
RP1=$(realpath "${GOPHERDIR}"/"${selector}" || "") RP1=$(realpath "${GOPHERDIR}"/"${selector}" || "")
RP2=$(realpath "${GOPHERDIR}")"${selector}" RP2=$(realpath $(realpath "${GOPHERDIR}")"${selector}")
[ -n "$DEBUG" ] && {
echo "iRP1: ${RP1}" echo "iRP1: ${RP1}"
echo "iRP2: ${RP2}" echo "iRP2: ${RP2}"
#echo "." }
if [ "${RP1}" = "${RP2}" ]; then if [ "${RP1}" = "${RP2}" ]; then
if [ -f "${RP1}" ]; then if [ -f "${RP1}" ]; then
@ -129,14 +135,13 @@ case $selector in
elif [ -d "${RP1}" ]; then elif [ -d "${RP1}" ]; then
[ -f "${RP1}/gophermap" ] && serve_selector "${RP1}/gophermap" [ -f "${RP1}/gophermap" ] && serve_selector "${RP1}/gophermap"
[ -f "${RP1}/index.gph" ] && serve_index "${RP1}/index.gph" [ -f "${RP1}/index.gph" ] && serve_index "${RP1}/index.gph"
else
echo "3Err Unable to find file ${selector}"
fi fi
fi fi
invalid_selector "$selector" invalid_selector "$selector"
;; ;;
*) *)
[ -f "${GOPHERDIR}/gophermap" ] && cat "${GOPHERDIR}/gophermap" && echo "." && exit 0 [ -f "${GOPHERDIR}/gophermap" ] && serve_selector "${GOPHERDIR}/gophermap"
[ -f "${GOPHERDIR}/index.gph" ] && serve_index "${GOPHERDIR}/index.gph"
invalid_selector "/" invalid_selector "/"
;; ;;
esac esac

Loading…
Cancel
Save