#! /bin/sh
# for "lib4th", (C) 8/2001 berlin h-peter recktenwald <phpr@snafu.de>
# MK-x - html cross-ref. - slow: v1.0.3.x: 65m w/ k6-2/350mcs -
# requires <MK-hx-defs> for inclusion

# assembly cross reference list (since silly "nasm" cannot do so):
# labels at beginning of the rsp line, terminated by a ":" colon char 
# and consisting of strictly, lower case alphanumeric characters.
# generates refs to any active occurrence in the L4 source files.

# the resultant html files biased to the "lynx" browser, the reason of
# which is it's orderly appearance, by the lynx specific <tab> tag, in
# the console display as well as in printed text and, *fast* rendering.
# other, graphic browsers were tested and, despite their very slow text
# (i.e. long tables') processing, were found almost equally 'readable'.
# formatting done for 132 chars/line. printing ca. 137pg, 9000+ lines.

# pse, mailto:phpr@snafu.de for supplemental information, if required...

# # # -------------------------------------------------------------- # # #

# xec from top-dir
[ "$(pwd -P)" = "$(dirname ${0})" ]&&cd ..

# clear cognomina which might be def'd in the environment
unset d u hr hu

# whether echoing to the terminal, "progress monitor", somehow...
[ "${2}" = "xref" -a -n "${3}" ]&&{ u=hu;echo -e "\n\tgenerating cross-reference list">/dev/tty; }||u=hr
hu () { [ -z "${2}" ]||echo -ne "${2} " >/dev/tty; }
hr () { x=; }

# # # pre-requisites tests
# ------------------------

# top dir
cd ..
d=$(pwd|sed -e "s/hd[abcd][0-9a-f][0-9a-f]\?-[vxj]\///g")
# specific to actual host:
# used to cut off leading, linked dir from path names like </hdd-x/usr/src/...>
# whre 1st part is the rsp. HD partition and 2nd, for the rsp. filing system

# PATH should include all files' and utils' directories
PATH=${PATH}:${d}/util:${d}/admin:${d}/inc:${d}/src

# include file names, text, common functions, substitution strings
source MK-hx-defs

# cleanup, in case of interrupted, previous html generation
rm -f ${q}* 2>/dev/null||true

# # # substitutes
# ---------------

# copy references sources
for i in ${s};do cp ${ds}${i} ${dc}${i};done

# # # auxilary shell functions
# ----------------------------

# # # ref. files generation
# -------------------------

# generate xrefs
hh "Label's Cross Reference" > ${q}
echo "<blockquote>HTML links browsable if lib4th source directory available (linked) as <b>$(dirname ${ds})</b></blockquote>">>${q}
echo '<blockquote><ul>'>>${q}

bl2=${bl8}${bl8}'&nbsp;&nbsp;&nbsp;&nbsp;=>    '
d=$(pwd);cd ${dc}
# 'context sensitive' quoterei in der "bash" ist zum kotzen! wenn weichmaenner 'intelligent' werden... das blanke grauen
#	    for n in $(grep -v '^[;%\.]' ${i}|grep -n '^[^;%]*[^\./]\<'"${c}"'\>[^:\./]'|cut -d: -f1)
grep -n '^[^\.;%]\w\+:' ${s}|cut -d: -f-3|sort -bft: -k3,3|while read c
do
	e=${c%%:*};n=${c#*:};c=${n#*:};n=${n%:*}
	echo "<li><a name=\"${c}\" href=\"${ot}#${c}\">${c}</a> <tab to=\"i3\"> <a href=\"file://localhost${ds}${e}\">${e}</a>:${n}<ul>"
	${u} : ${c}
	h=;v=;k=
	for i in ${s}
	do
	    for n in $(grep -n '^[^;%\.]*[^\./]\<'"${c}"'\>[^:\./]' ${i}|cut -d: -f1)
	    do
		n=${n%%;*};n=${n%%:*}
		[ -n "${n}" ]||continue
		[ "${v}" = "${i}" ]||{ h=x;v=${i};echo -ne "\n<li><a href=\"file://localhost${ds}${i}\">${i}</a><ul><li>\n"; }
		echo -n "${n} "
		${u} - ${n}
	    done
	    [ -z "${h}" ]||echo -e "\n</li></ul></li>\n";h=
	done
	echo "</ul></li>"
done>>${q}
cd ${d}
he "</ul>">>${q}
${u} "\n\tXREF dun"

echo -e "\t\a\"$(basename ${0})\" done">/dev/tty

( 
    cd ${dc}||exit 0
    chmod 664 l4*html 2>/dev/null||:
    rm -f ${s} ${r}
    [ -n "${hz}" ]&&${hz}&&wait&&mv l4*html.gz /hpg5/up-sna/&&chmod 664 /hpg5/up-sna/l4*html.gz 2>/dev/null||:
)

# MK-x <eof>
