#!/bin/sh

m=$(printf %s "$QUERY_STRING" | sed -e "s/m=//" -e "s/+/ /g")
manfile=$(man -w $m)

if [ -z "$m" ]; then
    printf "Content-type: text/plain\r\n"
    printf "\r\n"
    printf "provide a manpage to find in the ?m= parameter\n"
    exit 1
fi

if [ ! -f "$manfile" ]; then
    printf "Content-type: text/plain\r\n"
    printf "\r\n"
    printf "manpage for %s not found\n" "$m"
    exit 1
fi

zcat -f "$manfile" \
    | man2html -M /~ben/cgi-bin/man.sh

exit 0
