Merge from vendor branch GDB:
[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 # $DragonFly: src/tools/tools/epfe/Attic/epfe.pl,v 1.2 2003/06/17 04:29:11 dillon Exp $
12
13 $in = 0; @a = ();
14 sub Print { s/\&amp\;/&/g; push(@a,$_); }
15 sub out { 
16     local($name, *lines) = @_;
17     open(F, "> $name") || die "open $_[0]: $!\n"; 
18     print F @lines;
19     close F;
20 }
21
22 while(<>) {
23     if (/^<code>/) {
24         $in = 1;
25     } elsif (m%</code>% && $in > 0) {
26         if ($in > 1) {
27             $name = 'unknown' if !$name;
28             while(1) { if ($d{$name}) { $name .= 'X'; } else { last } }
29             &out("$name", *a);
30             $d{$name} = $name;
31         }
32         $in = 0; $name = ''; @a = ();
33     } elsif ($in == 1 && /^\#\s*!/) {
34         $in++; &Print;
35     } elsif ($in > 1) {
36         $name = $1 if (!$name && /^\#\s+(\S+)\s+-\s+/);
37         $in++; &Print;
38     }
39 }