#! /bin/bash
PATH=$PATH:/usr/local/bin; export PATH # For gunzip on church...
bin=/Users/hallgren/www/bin
#bin=cgi
AUTOHEADER=no
. $bin/cgistart.sh
datefmt=${datefmt-"+%b %d"}
### Locations ##################################################################
self_url=pfe.cgi
#modulesourcefiles=hi/modules # old
modulesourcefiles=hi/ModuleSourceFiles.txt # new
revgraph=hi/ModuleGraphRev.txt
htmldir=hi/html
ifacedir=hi/iface
### Functions ##################################################################
modulelink() {
link "$self_url?$1" "${2-$1}"
}
plainsrclink() {
echo "${2-Plain source file}:"
link "$1" "$1"
wrap small " (`filedate "$datefmt" "$1"`)"
}
cvsloglink() {
if [ -x cvs.cgi ]; then
link "cvs.cgi?$1" "cvs log"
fi
}
optdoclink() {
doc="${1%.hs}.doc"
if [ -n "$manpage_url" ] && [ -r "$doc" ] ; then
sep="
Related manual pages: "
grep '^\$Doc ' <$doc | while read doc manentry rest ; do
echo "$sep"
link "${manpage_url}$manentry.html" "$manentry"
sep=", "
done
fi
}
optifacelink() {
if [ -r "$1" ] ; then
echo_n "$2"
link "$1" "Interface"
echo_n "$3"
if [ -n "$4" ] ; then
wrap small " (`filedate "$datefmt" "$1"`)"
fi
fi
}
generated() {
if [ "$1" = "$3" ] ; then
plainsrclink "$1" "Plain source file for $2"
p
else
wrap code "$1"
echo "is actually generated by $2 from"
wrap code `link "$3" "$3"`
echo "which is shown below."
fi
}
plainfile() {
grep "^$1 " $modulesourcefiles | awk '{print $2}'
}
importedby() {
m="$1"
begin div
if [ -r $revgraph ] ; then
grep "^$m " <$revgraph | { read this imports && {
sep="$m is imported by: ...
" ;;
esac
}
}
else
echo "Don't know who imports this module."
p
fi
end
}
optdocinc() {
srcdir="$(dirname "$1")"
srcfile="${1##*/}"
docinc="$srcdir/doc/${srcfile%.*}_inc.html"
if [ -r "$docinc" ] ; then
#begin div
cat "$docinc"
#end
fi
}
uptodatecheck() {
gen="$1" # existing generated file
src="$2" # maybe missing source file
if [ -r "$src" ] && [ "$src" -nt "$gen" ] ; then
echo "Warning: the plain source file is newer than the generated HTML version shown below!"
fi
}
showsourcefile() {
m="$1"
hm=`echo "$m" | sed 's%/%-%g'`
h="$htmldir/$hm.html"
hgz="$h.gz"
#pfe all2html "$m" >/dev/null
f=`plainfile "$m"`
d=""
if [ -r "$h" ] || [ -r "$hgz" ] ; then
optdocinc "$f"
if [ -r "$f" ] ; then
p
plainsrclink "$f"
optifacelink "$ifacedir/$hm.hs" "
" " (experimental)" d
optdoclink "$f"
#br;cvsloglink "$f"
p;importedby "$m"
else
echo "The plain source file for module $m is not available."
fi
if [ -r "$h" ] ; then
uptodatecheck "$h" "$f"
cat "$h"
d="$(filedate "$datefmt" "$h")"
elif [ -r "$hgz" ] ; then
uptodatecheck "$hgz" "$f"
gunzip <"$hgz"
d="$(filedate "$datefmt" "$hgz")"
fi
else
echo "The source file for module $m is not available."
fi
hr
link "$self_url" Index
p
[ -n "$d" ] && {
begin small
echo "(HTML for this module was generated on $d."
link "http://ogi.altocumulus.org/~hallgren/h2h.html" "About the conversion tool"
echo ".)"
}
}
showsubdirs() {
h2 Subdirectories
begin ol
p="*/"
[ -n "$1" ] && p="$1*/"
for d in $p ; do
li; link "$self_url?$d" $d; nl
done
end
}
adddir() {
while read m d f ; do
[ -n "$f" ] || { f="$d"; d="."; }
echo "$m" "$d" "$f"
done
}
buggymoduleroot() {
if [ -n "$related" ] ; then
echo "$1" | sed "s/\($related\)\$//"
else
echo "$1"
fi
}
moduleroot() {
case "$1" in
*BaseStruct) echo "${1%BaseStruct}" ;;
*RecPretty) echo "${1%RecPretty}" ;;
*Base) echo "${1%Base}" ;;
*Maps) echo "${1%Maps}" ;;
*Pretty) echo "${1%Pretty}" ;;
*Struct) echo "${1%Struct}" ;;
*Util) echo "${1%Util}" ;;
*Rec) echo "${1%Rec}" ;;
*MT) echo "${1%T}" ;;
*) echo "$1"
esac
}
showstructureindex() {
grep " $1" <$modulesourcefiles | sed 's%/\([^/]*\)$% \1%' |
adddir | sort -f -k 2 | {
files=""
d0=""
m0=""
while read m d f; do
h="$htmldir/$m.html"
path="$d/$f"
if [ -r "$path" ] ; then
case "$path" in
hi/libs/*Libraries/*) ;; # exclude Prelude & standard libraries
*) if [ "$d" != "$d0" ] ; then
nl
[ -z "$d0" ] || end
nl
desc=""
if [ -r titles ] ; then
escd=`echo "$d" | sed 's/\./\\\\./g'`
desc="`sed -n "s%^$escd \(.*\)\$%\1%p" /dev/null
#h2 "Modules"
grep " $1" <$modulesourcefiles | sort | {
begin ol
files=""
while read m f; do
h="$htmldir/$m.html"
if [ -r "$f" ] ; then
case "$f" in
hi/libs/*Libraries/*) ;; # exclude Prelude & standard libraries
*) li; modulelink "$m"
#echo "($f)"
nl
files="$files $f"
esac
fi
done
end
filedate "$datefmt" $files
}
}
showindex() {
files="$modulesourcefiles"
[ -r index_inc.html ] && files="$files index_inc.html"
[ -r index_footer.html ] && files="$files index_footer.html"
[ -r cgiconfig.sh ] && files="$files cgiconfig.sh"
[ -r titles ] && files="$files titles"
modtime="`TZ=GMT LANG=C filedate '+%a, %d %b %Y %T %Z' $files`"
#echo "Last-Modified: $modtime"
pagestart "${maintitle-Haskell Files}" "$titleicon ${maintitle-Haskell Files}"
#showsubdirs "$@"
[ -r index_inc.html ] && cat index_inc.html
#showmoduleindex "$@"
showstructureindex "$@"
[ -r index_footer.html ] && cat index_footer.html
}
### Main #######################################################################
if [ -n "$QUERY_STRING" ]; then
contents_url="$self_url";
parent_url="$self_url";parent="Module List"
eval f="$*"
pagestart "$f"
#if [ -d "$f" ] ; then
# showindex "$1"
# show
#else
showsourcefile "$f"
#fi
else
showindex
fi
pageend