Statistics
| Branch: | Revision:

iof-bird-daemon / tools / progdoc @ c7d7794b

History | View | Annotate | Download (1.98 KB)

1
#!/usr/bin/perl
2

    
3
$srcdir = $ARGV[0];
4

    
5
open(OUT, ">prog/index.html") || die "Cannot create output file";
6
html_header(*OUT{IO}, "BIRD: The Developer's Guide");
7
print OUT "<H1>BIRD: The Developer's Guide</H1>\n";
8
print OUT "<UL>\n";
9
process("");
10
html_footer(*OUT{IO});
11
print OUT "</UL>\n";
12
close OUT;
13
exit 0;
14

    
15
sub process {
16
  my $dir = shift @_;
17
  print "$dir/Doc\n";
18
  open(IN, "$srcdir/$dir/Doc") || die "Unable to read $dir/Doc";
19
  my @docfile = <IN>;
20
  my @stack = ();
21
  close IN;
22
  push @docfile, "X\n";
23
  foreach $_ (@docfile) {
24
    chomp;
25
    /^#/ && next;
26
    /^(\.*)([A-Z]+)\s*(.*)/ || die "Parse error: $_";
27
    $indent = length $1;
28
    $cmd = $2;
29
    $arg = $3;
30
    while (@stack > $indent) {
31
      $x = pop @stack;
32
      if ($x eq "H") { print OUT "</UL>\n"; }
33
      elsif ($x eq "F") { html_footer(*AUX{IO}); close AUX; }
34
      else { print STDERR "Unknown stack element $x\n"; }
35
    }
36
    (@stack == $indent) or die "Invalid nesting: $_";
37
    if ($cmd eq "C") { process("$dir/$arg"); }
38
    elsif ($cmd eq "H") {
39
      push @stack, "H";
40
      print OUT "<LI>$arg";
41
      print OUT "<UL>\n";
42
    } elsif ($cmd eq "F") {
43
      $arg =~ /^(\S+)\s+(.*)$/ || die "Invalid command: $_";
44
      push @stack, "F";
45
      print "  $1\n";
46
      open(AUX, ">prog/$1.html") || die "Unable to create output file";
47
      print OUT "<LI><A HREF=\"$1.html\">$2</A>\n";
48
      html_header(*AUX{IO}, "BIRD: $2");
49
    } elsif ($cmd eq "S") {
50
      print "    $arg\n";
51
      open(DOC, "cd $srcdir/$dir ; $srcdir/doc/kernel-doc -html $arg |") || die "Unable to start kernel-doc";
52
      while (<DOC>) { print AUX; }
53
      close DOC;
54
    } elsif ($cmd eq "X") {
55
    } else { die "Unknown command: $cmd"; }
56
  }
57
}
58

    
59
sub html_header {
60
  my $out = shift @_;
61
  my $title = shift @_;
62
  print $out <<EOF
63
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
64
<HTML><HEAD><TITLE>$title</TITLE>
65
<LINK REV=MADE HREF="mailto:bird\@atrey.karlin.mff.cuni.cz">
66
</HEAD><BODY>
67
EOF
68
;
69
}
70

    
71
sub html_footer {
72
  my $out = shift @_;
73
  print $out <<EOF
74
</BODY></HTML>
75
EOF
76
;
77
}