#!/bin/sh
# genhelp.sh -- f0rked (http://f0rked.com)
# Generate a full HTML listing of irssi's commands in /HELP
# "See also" lines are xref'd as well

cd help # run this script from one dir above the "help" dir
of="../irssi-help.php" # output file. Note this is relative to inside of the help dir
###
rm -f $of
function writeout() {
	echo $@ >> $of
}
#writeout "<html>"
#writeout "<head>"
#writeout " <title>Irssi Help</title>"
#writeout " <style type=\"text/css\">"
#writeout "  <!-- body { } -->"
#writeout " </style>"
#writeout "</head>"
#writeout "<body>"
#writeout "<tt>"
writeout "{format:no}"

# add this below to do some buggy xrefing from within the help files
#| perl -ple '$foo=<>; foreach $item ($foo=~m/\/([A-Z]+)[ \.]/g) {$foo=~s/$item/<a href=\"#$item\">$item<\/a>/ if $item ne "COMMAND";} chomp $foo; print $foo;' \


for i in *; do 
	if [ ! `echo "$i"|grep "\."` ]; then
		if [ ! -d $i ]; then
			#echo "$i .."
			upper=`echo "$i" | tr [:lower:] [:upper:]`
			writeout "<u><a href=\"#$upper\" name=\"$upper\">$i</a></u><br />"
			writeout "<p>"
			cat $i | perl -ple 's/</\&lt;/g' \
				| perl -ple 's/>/\&gt;/g;' \
				| perl -ple 's/%\|//;' \
				| perl -ple 's/([:,] )([^, ]+)([^,]*)/$1<a href=\"#$2\">$2$3<\/a>/g if /^See also:/;' \
				| perl -ple 's/^[ ]/&nbsp;/g' \
				| perl -ple 's/$/<br \/>/;' >> $of
			writeout "</p>"
			writeout "<hr />"
		fi
	fi
done

#writeout "</tt>"
writeout "<p>This file automatically generated from Irssi's actual 'help' documentation.</p>"
#writeout "</body>"
#writeout "</html>"

