summaryrefslogtreecommitdiff
path: root/tools/progdoc
blob: ebb97db38361d6d57771fb9ae8a45f0d2ff77cb0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/perl

$srcdir = $ARGV[0];

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

sub process {
  my $dir = shift @_;
  print "$dir/Doc\n";
  open(IN, "$srcdir/$dir/Doc") || die "Unable to read $dir/Doc";
  my @docfile = <IN>;
  my @stack = ();
  close IN;
  push @docfile, "X\n";
  foreach $_ (@docfile) {
    chomp;
    /^#/ && next;
    /^(\.*)([A-Z]+)\s*(.*)/ || die "Parse error: $_";
    $indent = length $1;
    $cmd = $2;
    $arg = $3;
    while (@stack > $indent) {
      $x = pop @stack;
      if ($x eq "H") { print OUT "</UL>\n"; }
      elsif ($x eq "F") { html_footer(*AUX{IO}); close AUX; }
      else { print STDERR "Unknown stack element $x\n"; }
    }
    (@stack == $indent) or die "Invalid nesting: $_";
    if ($cmd eq "C") { process("$dir/$arg"); }
    elsif ($cmd eq "H") {
      push @stack, "H";
      print OUT "<LI>$arg";
      print OUT "<UL>\n";
    } elsif ($cmd eq "F") {
      $arg =~ /^(\S+)\s+(.*)$/ || die "Invalid command: $_";
      push @stack, "F";
      print "  $1\n";
      open(AUX, ">prog/$1.html") || die "Unable to create output file";
      print OUT "<LI><A HREF=\"$1.html\">$2</A>\n";
      html_header(*AUX{IO}, "BIRD: $2");
    } elsif ($cmd eq "S") {
      print "    $arg\n";
      open(DOC, "cd $srcdir/$dir ; $srcdir/doc/kernel-doc -html $arg |") || die "Unable to start kernel-doc";
      while (<DOC>) { print AUX; }
      close DOC;
    } elsif ($cmd eq "X") {
    } else { die "Unknown command: $cmd"; }
  }
}

sub html_header {
  my $out = shift @_;
  my $title = shift @_;
  print $out <<EOF
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<HTML><HEAD><TITLE>$title</TITLE>
<LINK REV=MADE HREF="mailto:bird\@atrey.karlin.mff.cuni.cz">
</HEAD><BODY>
EOF
;
}

sub html_footer {
  my $out = shift @_;
  print $out <<EOF
</BODY></HTML>
EOF
;
}