Initial import from FreeBSD RELENG_4:
[dragonfly.git] / tools / tools / epfe / epfe.pl
1 #!/usr/bin/perl
2 # Copyright (c) 1996 Wolfram Schneider <wosch@FreeBSD.org>. Berlin.
3 #
4 # epfe - extract printing filter examples from printing.sgml
5 #
6 # usage: 
7 #       $ cd /usr/share/examples/printing
8 #       $ epfe < ../../doc/handbook/printing.sgml
9 #
10 # $FreeBSD: src/tools/tools/epfe/epfe.pl,v 1.4 1999/08/28 00:54:26 peter Exp $
11
12 $in = 0; @a = ();
13 sub Print { s/\&amp\;/&/g; push(@a,$_); }
14 sub out { 
15     local($name, *lines) = @_;
16     open(F, "> $name") || die "open $_[0]: $!\n"; 
17     print F @lines;
18     close F;
19 }
20
21 while(<>) {
22     if (/^<code>/) {
23         $in = 1;
24     } elsif (m%</code>% && $in > 0) {
25         if ($in > 1) {
26             $name = 'unknown' if !$name;
27             while(1) { if ($d{$name}) { $name .= 'X'; } else { last } }
28             &out("$name", *a);
29             $d{$name} = $name;
30         }
31         $in = 0; $name = ''; @a = ();
32     } elsif ($in == 1 && /^\#\s*!/) {
33         $in++; &Print;
34     } elsif ($in > 1) {
35         $name = $1 if (!$name && /^\#\s+(\S+)\s+-\s+/);
36         $in++; &Print;
37     }
38 }