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