]> mj.ucw.cz Git - libucw.git/blob - build/doc-defs
b0c5a5e8810d5f2c3da8a7f3654be0ae470b50b2
[libucw.git] / build / doc-defs
1 #!/usr/bin/perl
2 # Script for formatting documentation from definition lists
3 # (they get out of extract-doc.pl as a side-product).
4 # (c) 2008 Michal Vaner <vorner@ucw.cz>
5 use strict;
6 use warnings;
7
8 my $head = shift;
9 my $out = shift;
10
11 open OUT, ">$out" or die "Could not write output $out ($!)\n";
12 open HEAD, $head or die "Could not open head $head ($!)\n";
13 print OUT foreach( <HEAD> );
14 close HEAD;
15
16 my $dir = $out;
17 $dir =~ s/\/[^\/]+$//;
18
19 my @dump;
20
21 while( defined( my $line = <> ) ) {
22         chomp $line;
23         push @dump, [ split /,/, $line, 5 ];
24 }
25
26 my %groups = (
27         'enum' => 0,
28         'struct' => 1,
29         'fun' => 2,
30         'var' => 3,
31         'def' => 4
32 );
33
34 my %heads = (
35         'enum' => 'Enums',
36         'struct' => 'Structs',
37         'fun' => 'Functions',
38         'var' => 'Variables',
39         'def' => 'Preprocessor definitions'
40 );
41
42 my $lasttype = '';
43
44 foreach( sort { ( $groups{$a->[2]} <=> $groups{$b->[2]} ) or ( $a->[3] cmp $b->[3] ); } @dump ) {
45         my( $file, $anchor, $type, $name, $text ) = @{$_};
46         if( $lasttype ne $type ) {
47                 $lasttype = $type;
48                 print OUT "\n== $heads{$type} [[$type]]\n\n";
49         }
50         my $dircp = $dir;
51         while( shift @{[ $dircp =~ /([^\/]+)/, "//" ]} eq shift @{[ $file =~ /([^\/]+)/, "///" ]} ) {
52                 $dircp =~ s/[^\/]+\/?//;
53                 $file =~ s/[^\/]+\/?//;
54         }
55         $dircp =~ s/[^\/]+/../g;
56         $file = $dircp."/".$file;
57         $file =~ s/^\///;
58         $file =~ s/\.[^.]+$//;
59         $text =~ s/(\.\.\.)/\\$1/g;
60         print OUT "<<$file:$anchor,`$name`>>:: `$text`\n";
61 }
62
63 close OUT;