diff -r 65cbecad22b4 -r 7d87d323c889 docgen.pl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/docgen.pl Mon Feb 23 04:05:05 2009 +0200 @@ -0,0 +1,108 @@ +#! /usr/bin/perl + +use strict; +use warnings; + +my %docs; +my @tags; +my $inside; +my $harvest; +my @values; + +foreach my $file (@ARGV) { + if ( not open SOURCE, '<', $file ) { + print STDERR "Cannot open $file\n"; + next; + } + + my $chunk = 0; + + while () { + if ( $inside ) { + if ( not /^\/\/\// ) { + $inside = 0; + $chunk++; + } elsif ( /^\/\/\/ G:/ ) { + $inside = 0; + $harvest = 'V: ' . substr ( $_, 6 ); + } else { + push @{$docs{$file}[$chunk]}, substr ( $_, 4 ); + } + } elsif ( $harvest ) { + if ( /\{\s*NULL.*\}/ ) { + push @{$docs{$file}[$chunk]}, $harvest . ' ' . join ( ', ', @values ); + $harvest = undef; + @values = (); + $chunk++; + } elsif ( /\{\s*"(.+)".*\}/ ) { + push @values, $1; + } + } else { + next if not /^\/\/\//; + + $inside = 1; + my $tag = substr $_, 4; + chomp $tag; + push @{$docs{$file}[$chunk]}, $tag; + # hack to allow twoword objects be written in text with spaces + # now it matches "lm message" instead of "lm message node" -.- + # and even if tag list will be reverse sorted by length, + # it will produce nested links... + # well, that all is now solved, but in not too impressive way.. + $tag =~ s/_/./g; + push @tags, $tag; + } + } + + close SOURCE; +} + +print <
+lua-loudmouth docs + +HEADER +; + +@tags = reverse sort { length $a <=> length $b } @tags; +# TODO preserve original order +foreach my $file ( sort keys %docs ) { + print "
"; + foreach my $chunk ( @{$docs{$file}} ) { + my $head = shift @$chunk; + my $tag = $head; + my $list = undef; + $tag =~ s/_/./g; + print "

$head

"; + foreach ( @$chunk ) { + s/^A: /Arguments: /; + s/^R: /Return values: /; + s/^V: /Values: /; + if ( $list ) { + if ( /^\* / ) { + s/^\* /<\/li>

  • /; + } else { + s/^/<\/li><\/ul> /; + $list = undef; + } + } elsif ( /^\* / ) { + s/^\* /" if $list; + print "

    " + } + print "
    "; +} + +print "" + +# The end