#!/usr/bin/perl # Script for formatting documentation from definition lists # (they get out of extract-doc.pl as a side-product). # (c) 2008 Michal Vaner use strict; use warnings; my $head = shift; my $out = shift; open OUT, ">$out" or die "Could not write output $out ($!)\n"; open HEAD, $head or die "Could not open head $head ($!)\n"; print OUT foreach( ); close HEAD; my $dir = $out; $dir =~ s/\/[^\/]+$//; my @dump; while( defined( my $line = <> ) ) { chomp $line; push @dump, [ split /,/, $line, 5 ]; } my %groups = ( 'enum' => 0, 'struct' => 1, 'fun' => 2, 'var' => 3, 'def' => 4 ); my %heads = ( 'enum' => 'Enums', 'struct' => 'Structs', 'fun' => 'Functions', 'var' => 'Variables', 'def' => 'Preprocessor definitions' ); my $lasttype = ''; foreach( sort { ( $groups{$a->[2]} <=> $groups{$b->[2]} ) or ( $a->[3] cmp $b->[3] ); } @dump ) { my( $file, $anchor, $type, $name, $text ) = @{$_}; if( $lasttype ne $type ) { $lasttype = $type; print OUT "\n== $heads{$type} [[$type]]\n\n"; } my $dircp = $dir; while( shift @{[ $dircp =~ /([^\/]+)/, "//" ]} eq shift @{[ $file =~ /([^\/]+)/, "///" ]} ) { $dircp =~ s/[^\/]+\/?//; $file =~ s/[^\/]+\/?//; } $dircp =~ s/[^\/]+/../g; $file = $dircp."/".$file; $file =~ s/^\///; $file =~ s/\.[^.]+$//; $text =~ s/\(/!!PARENT_OPEN!!/g; $text =~ s/(\.\.\.)/\\$1/g; print OUT "- <<$file:$anchor,`$name`>> +\n`$text`\n"; } close OUT;