]> mj.ucw.cz Git - libucw.git/blob - build/doc-defs
c69885837ffba39524782df9b0cb56ecaee910c3
[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' => 1,
28         'struct' => 1,
29         'function' => 2,
30         'variable' => 3,
31         'define' => 4
32 );
33
34 foreach( sort { ( $groups{$a->[2]} <=> $groups{$b->[2]} ) or ( $a->[3] cmp $b->[3] ); } @dump ) {
35         my( $file, $num, $type, $name, $text ) = @{$_};
36         my $dircp = $dir;
37         while( shift @{[ $dircp =~ /([^\/]+)/, "//" ]} eq shift @{[ $file =~ /([^\/]+)/, "///" ]} ) {
38                 $dircp =~ s/[^\/]+\/?//;
39                 $file =~ s/[^\/]+\/?//;
40         }
41         $dircp =~ s/[^\/]+/../g;
42         $file = $dircp."/".$file;
43         $file =~ s/^\///;
44         $file =~ s/\.[^.]+$//;
45         $text =~ s/\(/!!PARENT_OPEN!!/g;
46         $text =~ s/(\.\.\.)/\\$1/g;
47         print OUT "- <<$file:auto_$num,`$text`>>\n";
48 }
49
50 close OUT;