build-docdep.perl 968 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/usr/bin/perl
  2. my %include = ();
  3. my %included = ();
  4. for my $text (<*.txt>) {
  5. open I, '<', $text || die "cannot read: $text";
  6. while (<I>) {
  7. if (/^include::/) {
  8. chomp;
  9. s/^include::\s*//;
  10. s/\[\]//;
  11. $include{$text}{$_} = 1;
  12. $included{$_} = 1;
  13. }
  14. }
  15. close I;
  16. }
  17. # Do we care about chained includes???
  18. my $changed = 1;
  19. while ($changed) {
  20. $changed = 0;
  21. while (my ($text, $included) = each %include) {
  22. for my $i (keys %$included) {
  23. # $text has include::$i; if $i includes $j
  24. # $text indirectly includes $j.
  25. if (exists $include{$i}) {
  26. for my $j (keys %{$include{$i}}) {
  27. if (!exists $include{$text}{$j}) {
  28. $include{$text}{$j} = 1;
  29. $included{$j} = 1;
  30. $changed = 1;
  31. }
  32. }
  33. }
  34. }
  35. }
  36. }
  37. while (my ($text, $included) = each %include) {
  38. if (! exists $included{$text} &&
  39. (my $base = $text) =~ s/\.txt$//) {
  40. print "$base.html $base.xml : ", join(" ", keys %$included), "\n";
  41. }
  42. }