#!/bin/ash
#
# Script to generate an HTML index of all C code from the current directory
# downwards (skipping directories ending in ~). The header comment in each
# file is listed, and each function's prototype and comment are given. A
# list of "TODO:" comments is also generated.
#
# Outputs the HTML on standard output.
#
# If a parameter is given, it is the prefix to put before any "view file"
# links, eg ".." to link to "../dir/file.c" instead of "dir/file.c".
#
# Skips any files containing the string !NOINDEX.
#
# Requires ctags and cproto.
#
OFFS=$1
# Convert the given string to HTML-escaped values (<, >, & escaped) on
# stdout.
#
html_safe () {
echo "$*" \
| sed -e 's|&|\&|g;s|<|\<|g;s|>|\>|g'
}
# Convert the given string to HTML-escaped values (<, >, & escaped) on
# stdout, also adding a
to the end of each line.
#
html_safebr () {
echo "$*" \
| sed -e 's|&|\&|g;s|<|\<|g;s|>|\>|g;s/$/
/'
}
ALLFILES=`find . -name '*~' -prune -o -type f -name '*.c' \
-exec grep -FL '!NOINDEX' /dev/null '{}' ';'`
CTAGDATA=`echo "$ALLFILES" \
| ctags -nRf- -L- --c-types=f \
| sed 's/ .\// /;s/;" .*$//'`
FILELIST=`echo "$CTAGDATA" | cut -d ' ' -f 2 | sort | uniq`
echo '
\0
'
echo ''"$FILE"' | '
echo '- | ' echo ''`html_safe "$FILESHORTDESC"`' | ' echo '
' echo "`html_safebr "$FILELONGDESC"`" echo '' if [ -n "$FUNCDEFS" ]; then echo '
Functions defined:
' echo '/;s|$|
[' echo 'Top |' echo 'To Do |' echo 'Functions ]
' done echo ''
echo -n ''"$FUNC"'
'
echo '['"$FILE"'
]'
echo -n ''
echo -n "$FUNC"'
'
echo -n '['
echo "$FILE"'
]'
echo '
'"`html_safe "$FUNCDEF"`"'
' echo "`html_safebr "$FUNCHEAD"`" echo '' echo '
[' echo 'Top |' echo 'To Do |' echo 'Files ]
' done echo ''
echo ''"$FILE"'
'
echo '