File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / bird2 / tools / progdoc
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Mon Oct 21 16:03:56 2019 UTC (4 years, 7 months ago) by misho
Branches: bird2, MAIN
CVS tags: v2_0_7p0, HEAD
bird2 ver 2.0.7

#!/usr/bin/perl

$srcdir = $ARGV[0];
$out = $ARGV[1];

open(OUT, ">", $out) || die "Cannot create output file";
process($srcdir, "doc/prog-root");
close OUT;
gen_deps();
exit 0;

sub include {
  my $f = shift @_;
  open(IN, "$f") || die "Unable to find $f";
  push(@deps, "$f");
  while (<IN>) {
    print OUT;
  }
  close IN;
}

sub process {
  my $dir = shift @_;
  my $doc = "$dir/" . shift @_;
  print "$doc\n";
  open(IN, $doc) || die "Unable to read $doc";
  push(@deps, $doc);
  my @docfile = <IN>;
  close IN;
  foreach $_ (@docfile) {
    chomp;
    /^#/ && next;
    /^([A-Z]+)\s*(.*)/ || die "Parse error: $_";
    $cmd = $1;
    $arg = $2;
    if ($cmd eq "C") { process("$dir/$arg", "Doc"); }
    elsif ($cmd eq "H") {
      push @stack, "H";
      print OUT "<chapt>$arg\n";
    } elsif ($cmd eq "S") {
      print "    $arg\n";
      my @files = map("$dir/$_", split(' ', $arg));
      my $fargs = join(' ', @files);
      open(DOC, "$srcdir/doc/kernel-doc -bird $fargs |") || die "Unable to start kernel-doc";
      push(@deps, @files);
      while (<DOC>) { print OUT; }
      close DOC;
    } elsif ($cmd eq "D") {
      print "    $arg\n";
      include("$dir/$arg");
    } else { die "Unknown command: $cmd"; }
  }
}

sub gen_deps {
  open(DEP, ">", "$out.d");
  print DEP "$out:";
  foreach $f (@deps) {
    print DEP " \\\n  $f";
  }
  print DEP "\n\n";

  foreach $f (@deps) {
    print DEP "$f:\n\n";
  }
  close DEP;
}

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>