#! /usr/local/bin/perl -w

# called by bin/mkdocfromc.
# $Id: onefile,v 1.3 95/10/10 00:04:37 lee Exp Locker: lee $

while (<>) {
    if (/<Function>/ .. /^{/) {

	s@^/\* *@@; # delete the comment open 
	s@^ \*\t@@; # delete the start of the comment

	# keep leading whitespace only within examples:
	if (/<Example/i .. /<\/example/i) {
	    if (/<\/*Example/i) {
		# the actual tag lines are normal...
		s@^ \*[ 	]*@@;
	    } else {
		# but within an example,
		# delete only <space> <star> <tab>
		s@^ \*	@@;
	    }
	    ## print STDERR "Example $_\n";
	} else {
	    if (/^ *\*\//) {
		s@^ *\*/ *@<Decl>@;
		print;
		next;
	    }

	    s@^[ \t]*\*[ \t]*@@;

	    if (/<Name>.*[^>]$/) {
		s@$@</Name>@;
	    } else {
		if (/<F/) {
		    s/<Function/<Function File="$ARGV"/;
		} else {
		    if (/\/\*VARARGS[0-9]*\*\//) {
			next;
		    }

		    if (/\/\*ARGSUSED[0-9]*\*\//) {
			next;
		    }

		    if (/^{/) {
			s@^{@</Decl>@;
			print;
			next;
		    }
		}

	    }
	}
	s/<([a-z][a-z0-9]*\.h)>/\&lt;$1\&gt;/g;
	print;
    }
}
