#!/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 '' echo 'Source Code Index' echo '' echo '

Source Code Index

' echo '

' echo '

File Listing

' echo '

' for FILE in $FILELIST; do DIR=`dirname $FILE` FUNCDEFS=`cproto -f1 -I. -Isrc/include -I$DIR $FILE 2>/dev/null \ | sed -n 's/^.*[ *]\([^ *(]*\)(.*$/\1/p'` FILEHEAD="`sed -n -e \ '1,/\*\//{/\/\*/,/\*\//{s/^[\/ *]//;s/^\*[\/]*//;p;};}' \ < $FILE`" FILESHORTDESC=`echo "$FILEHEAD" | sed -n '1,/^ *$/{/^ *[^ ]*/p;}'` FILELONGDESC=`echo "$FILEHEAD" | sed '1,/^ *$/d'` echo '


' echo '

' echo '' echo '' echo '' echo '
' echo ''"$FILE"' - '`html_safe "$FILESHORTDESC"`'

' echo '

[View File]

' echo '

' echo "`html_safebr "$FILELONGDESC"`" echo '

' if [ -n "$FUNCDEFS" ]; then echo '

Functions defined:

' echo '

' fi echo '

[' echo 'Top |' echo 'To Do |' echo 'Functions ]

' done echo '

Function Listing

' echo '

' echo "$CTAGDATA" | while read FUNC FILE LINENUM REST; do FUNCDEF=`sed -n "$LINENUM,/{/p" < $FILE \ | tr '\n' ' ' \ | tr -d '{'` LASTCOMLINE=`sed -n '1,'"$LINENUM"'{/\/\*/=;}' < $FILE | sed -n '$p'` [ -z "$LASTCOMLINE" ] && LASTCOMLINE=1 LASTENDFUNCLINE=`sed -n '1,'"$LINENUM"'{/}/=;}' < $FILE | sed -n '$p'` [ -z "$LASTENDFUNCLINE" ] && LASTENDFUNCLINE=1 FUNCHEAD="`sed -n -e \ "$LASTCOMLINE,"'/\*\//{h;s/^[\/ *]//;s/^\*[\/]*//;p;x;/\*\//q;}' \ < $FILE`" [ "$LASTCOMLINE" -le "$LASTENDFUNCLINE" ] && FUNCHEAD="" echo '


' echo '

' echo -n '' echo -n "$FUNC"' ' echo -n '[' echo "$FILE"']' echo '

' echo '

'"`html_safe "$FUNCDEF"`"'

' echo '

' echo "`html_safebr "$FUNCHEAD"`" echo '

' echo '

[' echo 'Top |' echo 'To Do |' echo 'Files ]

' done echo '

To Do Listing

' echo '