Revision 6be13de7 tools/progdoc

View differences:

tools/progdoc
2 2

  
3 3
$srcdir = $ARGV[0];
4 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";
5
open(OUT, ">prog.sgml") || die "Cannot create output file";
6
include("prog-head.sgml");
9 7
process("");
10
html_footer(*OUT{IO});
11
print OUT "</UL>\n";
8
include("prog-foot.sgml");
12 9
close OUT;
13 10
exit 0;
14 11

  
12
sub include {
13
  my $f = shift @_;
14
  open(IN, "$srcdir/doc/$f") || die "Unable to find $f";
15
  while (<IN>) {
16
    print OUT;
17
  }
18
  close IN;
19
}
20

  
15 21
sub process {
16 22
  my $dir = shift @_;
17 23
  print "$dir/Doc\n";
18 24
  open(IN, "$srcdir/$dir/Doc") || die "Unable to read $dir/Doc";
19 25
  my @docfile = <IN>;
20
  my @stack = ();
21 26
  close IN;
22
  push @docfile, "X\n";
23 27
  foreach $_ (@docfile) {
24 28
    chomp;
25 29
    /^#/ && 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: $_";
30
    /^([A-Z]+)\s*(.*)/ || die "Parse error: $_";
31
    $cmd = $1;
32
    $arg = $2;
37 33
    if ($cmd eq "C") { process("$dir/$arg"); }
38 34
    elsif ($cmd eq "H") {
39 35
      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");
36
      print OUT "<sect>$arg\n";
49 37
    } elsif ($cmd eq "S") {
50 38
      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; }
39
      open(DOC, "cd $srcdir/$dir ; $srcdir/doc/kernel-doc -bird $arg |") || die "Unable to start kernel-doc";
40
      while (<DOC>) { print OUT; }
53 41
      close DOC;
54
    } elsif ($cmd eq "X") {
42
    } elsif ($cmd eq "D") {
43
      print "    $arg\n";
44
      include($arg);
55 45
    } else { die "Unknown command: $cmd"; }
56 46
  }
57 47
}
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
}

Also available in: Unified diff