summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xhtgen38
1 files changed, 26 insertions, 12 deletions
diff --git a/htgen b/htgen
index 78696be..ba6976b 100755
--- a/htgen
+++ b/htgen
@@ -4,18 +4,32 @@ set -euf
Server=htgen
-## htgen --serve {{{
-case $# in
- (1)
- case "$1" in
- (--serve)
- HTGEN_HOST=${HTGEN_HOST-0.0.0.0}
- HTGEN_PORT=${HTGEN_PORT-42380}
- HTGEN_SCRIPT=${HTGEN_SCRIPT-:}
- TCPSERVER_OPTS='-c 423 -t 2 -D'
- echo "#### $Server $HTGEN_HOST:$HTGEN_PORT" >&2
- exec tcpserver $TCPSERVER_OPTS "$HTGEN_HOST" "$HTGEN_PORT" "$0"
- esac
+## parse arguments {{{
+action=handle_request
+while test $# -gt 0; do
+ case $1 in)
+ --serve) action=serve; shift; continue;;
+ *) echo "$0: error: bad argument: $1" >&2; exit 1;;
+ esac
+done
+## }}}
+## dispatch on $action {{
+case $action in
+ handle_request)
+ : # fall through for handling the request
+ ;;
+ serve)
+ HTGEN_HOST=${HTGEN_HOST-0.0.0.0}
+ HTGEN_PORT=${HTGEN_PORT-42380}
+ HTGEN_SCRIPT=${HTGEN_SCRIPT-:}
+ TCPSERVER_OPTS='-c 423 -t 2 -D'
+ echo "#### $Server $HTGEN_HOST:$HTGEN_PORT" >&2
+ exec tcpserver $TCPSERVER_OPTS "$HTGEN_HOST" "$HTGEN_PORT" "$0"
+ ;;
+ *)
+ echo "$0: error: bad action: $action" >&2
+ exit 2
+ ;;
esac
## }}}