#! /bin/sh

# The SGML is inside the code itself: we extract it for the
# documentation here.

tmphelpf=`mktemp /tmp/nfsim_gen-docs.XXXXXX`
tmpusagef=`mktemp /tmp/nfsim_gen-docs.XXXXXX`
trap "rm -f $tmphelpf $tmpusagef" EXIT

for f in `find .. -name '*.c' |
    xargs awk '/\/\*\*\* XML (Help|Argument)/ {print FILENAME":"FNR":"$3; }'`
do
    file=`echo $f | cut -d: -f1`
    line=`echo $f | cut -d: -f2`
    type=`echo $f | cut -d: -f3`

    case "$type" in
    Help|help)
	echo Extracting help from ${file}:$line >&2
	./extract-help $file $line >> $tmphelpf
    ;;
    Argument|argument)
	echo Extracting usage from ${file}:$line >&2
	./extract-help $file $line >> $tmpusagef
    ;;
    esac

done

while read line
do
    case "$line" in
    '<!-- AUTOGENERATED HELP GOES HERE -->')
	cat $tmphelpf
	;;
    '<!-- AUTOGENERATED USAGE GOES HERE -->')
	cat $tmpusagef
	;;
    *)
    	echo "$line"
    esac
done < $1 > $2
