TIVI-153: add as dependency for iputils
[profile/ivi/perl-SGMLSpm.git] / skel.pl
1 ########################################################################
2 # skel.pl: an SGMLSPL script for producing scripts (!!).
3 #
4 # Copyright (c) 1995 by David Megginson <dmeggins@aix1.uottawa.ca>
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 #
20 #
21 # Changes:
22 #
23 # $Log: skel.pl,v $
24 # Revision 1.4  1995/11/15  20:21:07  david
25 # Changed "use Output" to "use SGMLS::Output".
26 #
27 # Revision 1.3  1995/08/24  15:04:38  david
28 # Fixed commented-out 're' handler.
29 #
30 # Revision 1.2  1995/08/12  16:16:42  david
31 # Revised version for 1.01 distribution.
32 #
33 # Revision 1.1  1995/04/23  14:49:35  david
34 # Initial revision
35 #
36 ########################################################################
37
38 use SGMLS;
39 use SGMLS::Output;
40
41 $version = '$Id: skel.pl,v 1.4 1995/11/15 20:21:07 david Exp $';
42
43 %subdocs = ();                  # Subdocument entities seen so far.
44 %entities = ();                 # External data entities seen so far.
45 %sdata = ();                    # SDATA strings seen so far.
46 %elements = ();                 # Elements seen so far.
47 $pi = 0;                        # Any processing instructions?
48
49 $intro = 0;                     # Have we printed the banner yet?
50
51 $| = 1;
52
53 sgml('end_element', '');        # Ignore the ends of elements.
54 sgml('end_subdoc', '');         # Ignore the ends of subdocument entities.
55 sgml('cdata', '');              # Ignore CDATA.
56 sgml('re', '');                 # Ignore Record Ends.
57
58                                 # Note any processing instructions.
59 sgml('pi', sub { $pi = 1; });
60
61                                 # Keep track of all subdocument entities.
62 sgml('start_subdoc', sub {
63     my $entity = shift;
64     $entities{$entity->name} = 1;
65 });
66                                 # Keep track of all external data entities.
67 sgml('entity', sub {
68     my $entity = shift;
69     $entities{$entity->name} = 1;
70 });
71                                 # Keep track of all SDATA strings
72 sgml('sdata', sub {
73     my $sdata = shift;
74     $sdata{$sdata} = 1;
75 });
76
77                                 # Display element handlers as they appear.
78 sgml('start_element', sub {
79     my $element = shift;
80     unless ($intro) {
81         $intro = 1;
82         do_intro($element->name);
83     }
84     if (!$elements{$element->name}) {
85         output "# Element: " . $element->name . "\n";
86         output "sgml('<" . $element->name . ">', \"\");\n";
87         output "sgml('</" . $element->name . ">', \"\");\n\n";
88         $elements{$element->name} = 1;
89     }
90 });
91
92 sgml('end', sub {
93                                 # generate subdoc handlers
94     my @keys = keys(%subdocs);
95     if ($#keys > 0) {
96         output "#\n# Subdocument Entity Handlers\n#\n\n";
97         foreach (@keys) {
98             output "# Subdocument Entity: $_\n";
99             output "sgml('{" . $_ . "}', \"\");\n";
100             output "sgml('{/" . $_ . "}', \"\");\n\n";
101         }
102     }
103                                 # generate entity handlers
104     my @keys = keys(%entities);
105     if ($#keys > 0) {
106         output "#\n# External Data Entity Handlers\n#\n\n";
107         foreach (@keys) {
108             output "sgml('&" . $_ . ";', \"\");\n";
109         }
110     }
111                                 # generate sdata handlers
112     my @keys = keys(%sdata);
113     if ($#keys > 0) {
114         output "#\n# SDATA Handlers\n#\n\n";
115         foreach (@keys) {
116             output "sgml('|" . $_ . "|', \"\");\n";
117         }
118     }
119
120     if ($pi) {
121         output "#\n# Processing-Instruction Handler\n#\n";
122         output "sgml('pi', sub {});\n\n";
123     }
124
125     output <<END;
126 #
127 # Default handlers (uncomment these if needed).  Right now, these are set
128 # up to gag on any unrecognised elements, sdata, processing-instructions,
129 # or entities.
130 #
131 # sgml('start_element',sub { die "Unknown element: " . \$_[0]->name; });
132 # sgml('end_element','');
133 # sgml('cdata',sub { output \$_[0]; });
134 # sgml('sdata',sub { die "Unknown SDATA: " . \$_[0]; });
135 # sgml('re',"\\n");
136 # sgml('pi',sub { die "Unknown processing instruction: " . \$_[0]; });
137 # sgml('entity',sub { die "Unknown external entity: " . \$_[0]->name; });
138 # sgml('start_subdoc',sub { die "Unknown subdoc entity: " . \$_[0]->name; });
139 # sgml('end_subdoc','');
140 # sgml('conforming','');
141
142 1;
143 END
144 });
145
146
147
148                                 # Function to print the banner.
149 sub do_intro {
150     my $doctype = shift;
151     output <<END;
152 ########################################################################
153 # SGMLSPL script produced automatically by the script sgmlspl.pl
154 #
155 # Document Type: $doctype
156 # Edited by: 
157 ########################################################################
158
159 use SGMLS;                      # Use the SGMLS package.
160 use SGMLS::Output;              # Use stack-based output.
161
162 #
163 # Document Handlers.
164 #
165 sgml('start', sub {});
166 sgml('end', sub {});
167
168 #
169 # Element Handlers.
170 #
171
172 END
173 }
174
175 1;
176          
177     
178