1 #!/bin/sh 2 3 # Generate a Moin syntax table for header file documentation. 4 5 DN=$1 6 7 if [ ! -e "$DN" ] ; then 8 cat 1>&2 <<EOF 9 Usage: $0 <directory> 10 11 Obtain header file details from within a given include directory. 12 EOF 13 exit 1 14 fi 15 16 # Obtain the description from the top of a file. 17 18 get_description() 19 { 20 ENDLINE=$(grep -n -m 1 '^ \*$' "$1" | cut -f 1 -d :) 21 head -n "$ENDLINE" "$1" | tail -n +2 | head -n -1 | sed 's/^ \* //' | concat_lines 22 } 23 24 # Concatenate lines. 25 26 concat_lines() 27 { 28 while read LINE ; do 29 echo -n "$LINE " 30 done 31 } 32 33 # Format a table of header filenames and descriptions. 34 35 make_table() 36 { 37 for FN in "$1/"*"/"*".h" ; do 38 39 # Detect non-matching patterns. 40 41 if [ ! -e "$FN" ] ; then 42 break 43 44 # Emit the header at the start. 45 46 elif [ ! "$HEADER" ] ; then 47 echo "|| '''Header File''' ??|| '''Contents''' ??||" 48 HEADER=1 49 fi 50 51 PARENT=$(dirname "$FN") 52 SECTION=$(basename "$PARENT") 53 FILENAME=$(basename "$FN") 54 55 echo -n '|| `'"$SECTION/$FILENAME"'` ??|| ' 56 get_description "$FN" 57 echo ' ??||' 58 done 59 } 60 61 make_table "$DN" | column -s '??' -t 62 63 # vim: tabstop=4 expandtab shiftwidth=4