Debian Codegraph @

en/build/lib/refentry.pl

raw
1 # -*- Perl -*-
2
3 # dtdformat module for RefEntrys for DB:TDG
4
5 my $VERSION = "SF DocBook 1.0";
6
7 my $PUBLIC_ID = "-//OASIS//DTD DocBook XML V4.5//EN";
8 my $SYSTEM_ID = "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd";
9
10 my $prefix = "";
11
12 my @common_attributes = ('xml:base',
13 'wordsize',
14 'dir',
15 'id',
16 'role',
17 'lang',
18 'remap',
19 'xreflabel',
20 'revisionflag',
21 'arch',
22 'conformance',
23 'os',
24 'revision',
25 'userlevel',
26 'vendor',
27 'security',
28 'condition');
29
30 $fileext = ".xml";
31 $libdir = "/sourceforge/docbook/defguide/en/build/lib";
32
33 $config{'expanded-element-index'} = "elements";
34 $config{'unexpanded-element-index'} = "dtdelem";
35 $config{'expanded-entity-index'} = "entities";
36 $config{'unexpanded-entity-index'} = "dtdent";
37 $config{'expanded-entity-dir'} = 'paraments';
38 $config{'unexpanded-entity-dir'} = 'paraments';
39 $config{'notation-index'} = 'notations';
40
41 $option{'base-id'} = 'dbre';
42 $option{'base-dir'} = "$libdir/../../refpages";
43 $option{'seealso'} = 1;
44
45 my %entity_classes = ();
46 my @entity_classes = ();
47 my @entity_pats = ();
48
49 my %revision = ('productionset' => 'EBNF',
50 'production' => 'EBNF',
51 'lhs' => 'EBNF',
52 'rhs' => 'EBNF',
53 'nonterminal' => 'EBNF',
54 'constraint' => 'EBNF',
55 'productionrecap' => 'EBNF',
56 'constraintdef' => 'EBNF',
57
58 'bibliocoverage' => '4.2',
59 'biblioid' => '4.2',
60 'bibliorelation' => '4.2',
61 'bibliosource' => '4.2',
62 'blockinfo' => '4.2',
63 'citebiblioid' => '4.2',
64 'coref' => '4.2',
65 'errortext' => '4.2',
66 'personblurb' => '4.2',
67 'personname' => '4.2',
68 'refsection' => '4.2',
69 'refsectioninfo' => '4.2',
70 'textdata' => '4.2',
71
72 'appendixinfo' => '4.0',
73 'articleinfo' => '4.0',
74 'bibliographyinfo' => '4.0',
75 'chapterinfo' => '4.0',
76 'classsynopsis' => '4.0',
77 'classsynopsisinfo' => '4.0',
78 'constructorsynopsis' => '4.0',
79 'destructorsynopsis' => '4.0',
80 'exceptionname' => '4.0',
81 'fieldsynopsis' => '4.0',
82 'glossaryinfo' => '4.0',
83 'indexinfo' => '4.0',
84 'initializer' => '4.0',
85 'interfacename' => '4.0',
86 'methodname' => '4.0',
87 'methodparam' => '4.0',
88 'methodsynopsis' => '4.0',
89 'modifier' => '4.0',
90 'ooclass' => '4.0',
91 'ooexception' => '4.0',
92 'oointerface' => '4.0',
93 'partinfo' => '4.0',
94 'prefaceinfo' => '4.0',
95 'refentryinfo' => '4.0',
96 'referenceinfo' => '4.0',
97 'remark' => '4.0',
98 'revdescription' => '4.0',
99 'setindexinfo' => '4.0',
100 'sidebarinfo' => '4.0',
101 'simplemsgentry' => '4.0',
102
103 'mediaobject' => '3.1',
104 'mediaobjectco' => '3.1',
105 'inlinemediaobject' => '3.1',
106 'videoobject' => '3.1',
107 'audioobject' => '3.1',
108 'imageobject' => '3.1',
109 'imageobjectco' => '3.1',
110 'textobject' => '3.1',
111 'objectinfo' => '3.1',
112 'videodata' => '3.1',
113 'audiodata' => '3.1',
114 'imagedata' => '3.1',
115 'caption' => '3.1',
116 'informalfigure' => '3.1',
117 'colophon' => '3.1',
118 'section' => '3.1',
119 'sectioninfo' => '3.1',
120 'qandaset' => '3.1',
121 'qandadiv' => '3.1',
122 'qandaentry' => '3.1',
123 'question' => '3.1',
124 'answer' => '3.1',
125 'constant' => '3.1',
126 'varname' => '3.1');
127
128 # ======================================================================
129 {
130 print "\nLoading parament classes...";
131
132 local *F, $_;
133 my $class, $regexp;
134 my %classes = ();
135 open (F, "$libdir/parament.classes");
136 while (<F>) {
137 chop;
138 if (/^\s+(\S+)/) {
139 $entity_classes{$1} = $class;
140 } elsif (/^(\S+)\s+(\S+)/) {
141 $class = $1;
142 $regexp = $2;
143 $regexp =~ s/\./\\\./g;
144 $regexp =~ s/\*/\.\*/g;
145 push(@entity_classes, $class);
146 push(@entity_pats, $regexp);
147 $classes{$class} = 1;
148 } elsif (/^(\S+)\s*$/) {
149 $class = $1;
150 $classes{$class} = 1;
151 } else {
152 warn "Unexpected line in parament.classes: $_\n";
153 }
154 }
155
156 print "\nCleaning up parament class files...";
157
158 foreach $class (keys %classes) {
159 my $basedir = $option{'base-dir'};
160 my $path = $basedir . "/" . $config{'expanded-entity-dir'};
161 unlink("$path/$class.e.gen");
162 $path = $basedir . "/" . $config{'unexpanded-entity-dir'};
163 unlink("$path/$class.u.gen");
164 }
165 }
166
167 END {
168 # Now that we've written out all those parameter entity files,
169 # make sure the entities in them are sorted...
170
171 &status("Sorting entities...",1);
172
173 my $basedir = $option{'base-dir'};
174 my $path = $basedir . "/" . $config{'expanded-entity-dir'};
175 opendir (DIR, $path);
176 while (my $name = readdir(DIR)) {
177 my $file = "$path/$name";
178 next if $name !~ /\.gen$/;
179 next if -d $file;
180 open (F, $file);
181 read (F, $_, -s $file);
182 close (F);
183
184 my %refsects = ();
185 while (/<refsect2.*?id=([\'\"])(.*?)\1.*?<\/refsect2>\s+/s) {
186 my $sect = $&;
187 my $id = $2;
188 $_ = $` . $'; # '
189 die "Duplicate refsect ID: $2\n" if $refsects{$id};
190 $refsects{$id} = $sect;
191 }
192
193 die "Unexpected content in $file: $_\n" if !/^\s*$/s;
194
195 open (F, ">$file");
196 foreach my $id (sort keys %refsects) {
197 print F $refsects{$id};
198 }
199 close (F);
200 }
201 closedir (DIR);
202
203 print "\n";
204
205 }
206
207 # ======================================================================
208
209 sub elementRefpurpose {
210 my $count = shift;
211 my $name = $elements[$count];
212
213 return "&$name.purpose;";
214 }
215
216 sub entityRefpurpose {
217 my $count = shift;
218 my $name = $entities[$count];
219 my $entity = $entities{$name};
220
221 return "&$baseid.purp." . $entity->getAttribute('type') . "." . $name;
222 }
223
224 sub notationRefpurpose {
225 my $count = shift;
226 my $name = $notations[$count];
227
228 return "&$baseid.purp.notn.$name;";
229 }
230
231 sub elementDescription {
232 my $count = shift;
233 my $name = $elements[$count];
234 my $desc = "$descdir/$name.sgm";
235 local $_;
236
237 # return "&" . "desc.elem.$name;";
238
239 open (F, $desc);
240 read (F, $_, -s $desc);
241 close (F);
242
243 return "\n" . $_;
244 }
245
246 sub entityDescription {
247 my $count = shift;
248
249 return "<para>desc</para>\n";
250 }
251
252 sub notationDescription {
253 my $count = shift;
254
255 return "<para>desc</para>\n";
256 }
257
258 # ======================================================================
259
260 sub basenames {
261 my @names = @_;
262 my %basename = ();
263 my %usedname = ();
264
265 foreach my $name (@names) {
266 my $count = 2;
267 my $bname = lc($name);
268
269 if ($usedname{$bname}) {
270 $bname = lc($name) . $count;
271 while ($usedname{$bname}) {
272 $bname++;
273 }
274 }
275
276 $basename{$name} = $bname;
277 $usedname{$name} = 1;
278 }
279
280 return %basename;
281 }
282
283 # ======================================================================
284
285 sub formatElement {
286 my $count = shift;
287 my $html = "";
288
289 my $name = $elements[$count];
290 my $element = $elements{$name};
291
292 my $cmex = undef;
293 my $cmunx = undef;
294 my $incl = undef;
295 my $excl = undef;
296
297 my $node = $element->getFirstChild();
298 while ($node) {
299 if ($node->getNodeType() == XML::DOM::ELEMENT_NODE) {
300 $cmex = $node if $node->getTagName() eq 'content-model-expanded';
301 $cmunx = $node if $node->getTagName() eq 'content-model';
302 $incl = $node if $node->getTagName() eq 'inclusions';
303 $excl = $node if $node->getTagName() eq 'exclusions';
304 }
305 $node = $node->getNextSibling();
306 }
307
308 $html .= &formatElementHeader($count);
309
310 $html .= &formatElementTitle($count);
311
312 if ($option{'synopsis'}) {
313 if ($expanded eq 'expanded') {
314 $html .= &formatElementSynopsis($count, $cmex, $cmex, $incl, $excl);
315 } else {
316 $html .= &formatElementSynopsis($count, $cmunx, $cmex, $incl, $excl);
317 }
318 }
319
320 $html .= &formatElementDescription($count) if $option{'description'};
321
322 $html .= &formatElementAttrDescription($count) if $option{'attributes'};
323
324 $html .= &formatElementSeeAlso($count) if $option{'seealso'};
325
326 $html .= &formatElementExample($count) if $option{'examples'};
327
328 $html .= &formatElementFooter($count);
329 }
330
331 sub formatElementHeader {
332 my $count = shift;
333 my $html = "";
334 my $name = $elements[$count];
335 my $element = $elements{$name};
336
337 my $pub = "-//OASIS//DTD DocBook XML V4.2//EN";
338 my $sys = "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd";
339
340 my $dir = $option{'base-dir'} . "/elements/$name";
341 if (! -d $dir) {
342 mkdir($dir, 0755);
343 }
344
345 my $filename = "reference.e.xml";
346
347 my $rpub = "-//O'Reilly//ENTITIES DocBook RefPurposes V2.0//EN";
348 my $rsys = "../../../entities/refpurps.ent";
349
350 $html = "";
351 $html .= "<!DOCTYPE reference PUBLIC \"$pub\"\n";
352 $html .= " \"$sys\" [\n";
353 $html .= "<!ENTITY % refpurps.ent PUBLIC \"$rpub\" \"$rsys\">\n";
354 $html .= "%refpurps.ent;\n";
355 $html .= "<!ENTITY % entities.ent SYSTEM \"entities.e.ent\">\n";
356 $html .= "%entities.ent;\n";
357 $html .= "<!ENTITY refentry.xml SYSTEM \"refentry.xml\">\n";
358 $html .= "]>\n";
359 $html .= "<reference><title>$name Refentry</title>\n";
360 $html .= "&refentry.xml;\n";
361 $html .= "</reference>\n";
362
363 if (! -f "$dir/$filename") {
364 open (F, ">$dir/$filename");
365 print F $html;
366 close (F);
367 }
368
369 $filename = "reference.u.xml";
370
371 $html = "";
372 $html .= "<!DOCTYPE reference PUBLIC \"$pub\"\n";
373 $html .= " \"$sys\" [\n";
374 $html .= "<!ENTITY % refpurps.ent PUBLIC \"$rpub\" \"$rsys\">\n";
375 $html .= "%refpurps.ent;\n";
376 $html .= "<!ENTITY % entities.ent SYSTEM \"entities.u.ent\">\n";
377 $html .= "%entities.ent;\n";
378 $html .= "<!ENTITY refentry.xml SYSTEM \"refentry.xml\">\n";
379 $html .= "]>\n";
380 $html .= "<reference><title>$name Refentry</title>\n";
381 $html .= "&refentry.xml;\n";
382 $html .= "</reference>\n";
383
384 if (! -f "$dir/$filename") {
385 open (F, ">$dir/$filename");
386 print F $html;
387 close (F);
388 }
389
390 $html = "";
391 $html .= "<refentry id=\"$name.element\"";
392 $html .= " revision='" . $revision{$name} . "'" if $revision{$name};
393 $html .= ">\n";
394 $html .= "<?dbhtml filename=\"$name.html\"?>\n\n";
395
396 return $html;
397 }
398
399 sub formatElementTitle {
400 my $count = shift;
401 my $name = $elements[$count];
402 my $element = $elements{$name};
403 my $html = "";
404
405 $html .= "<refmeta>\n";
406 $html .= "<indexterm><primary>elements</primary>\n";
407 $html .= "<secondary>" . $element->getAttribute('name') . "</secondary></indexterm>\n";
408
409 $html .= "<refentrytitle>";
410 $html .= $element->getAttribute('name');
411 $html .= "</refentrytitle>\n";
412 $html .= "<refmiscinfo>Element</refmiscinfo>\n";
413 $html .= "</refmeta>\n";
414
415 $html .= "<refnamediv>\n";
416 $html .= "<refname>" . $element->getAttribute('name') . "</refname>\n";
417 $html .= "<refpurpose>";
418 $html .= &elementRefpurpose($count);
419 $html .= "</refpurpose>\n";
420 $html .= "</refnamediv>\n\n";
421
422 return $html;
423 }
424
425 sub formatElementSynopsis {
426 my $count = shift;
427 my $name = $elements[$count];
428 my $element = $elements{$name};
429 my $cm = shift;
430 my $cmex = shift;
431 my $incl = shift;
432 my $excl = shift;
433 my $html = "";
434
435 # What are the possibilities: mixed content, element content, or
436 # declared content...
437 my $mixed = $element->getAttribute('content-type') eq 'mixed';
438 my $declared = (!$mixed &&
439 $element->getAttribute('content-type') ne 'element');
440
441 $html .= "<refsynopsisdiv><title>Synopsis</title>\n";
442 $html .= "<informaltable frame='all' role='elemsynop'>\n";
443 $html .= "<tgroup cols='3'>\n";
444 $html .= "<colspec colnum='1' colname='c1'/>\n";
445 $html .= "<colspec colnum='2' colname='c2'/>\n";
446 $html .= "<colspec colnum='3' colname='c3'/>\n";
447 $html .= "<tbody>\n";
448
449 $html .= "<row condition='ref.synopsis' rowsep='0' role='cmtitle'>\n";
450 $html .= "<entry namest='c1' nameend='c3' align='left'\n";
451 $html .= "><emphasis role='bold'>";
452
453 if ($mixed) {
454 $html .= "Mixed Content Model";
455 } elsif ($declared) {
456 $html .= "Declared Content";
457 } else {
458 $html .= "Content Model";
459 }
460
461 $html .= "</emphasis></entry>\n";
462 $html .= "</row>\n";
463
464 $html .= "<row condition='ref.synopsis' rowsep='1' role='cmsynop'>\n";
465 $html .= "<entry namest='c1' nameend='c3' align='left'\n";
466 $html .= "><synopsis>";
467 $html .= $element->getAttribute('name') . " ::=\n";
468 $html .= &formatContentModel($count, $cm);
469
470 $html .= "</synopsis></entry>\n";
471 $html .= "</row>\n";
472
473 $html .= &formatInclusions($count, $incl)
474 if $incl && $option{'inclusions'};
475
476 $html .= &formatExclusions($count, $excl)
477 if $excl && $option{'exclusions'};
478
479 $html .= &formatAttributeList($count) if $option{'attributes'};
480
481 $html .= &formatTagMinimization($count) if $option{'tag-minimization'};
482
483 $html .= &formatElementAppearsIn($count) if $option{'appears-in'};
484
485 $html .= "</tbody>\n";
486 $html .= "</tgroup>\n";
487 $html .= "</informaltable>\n";
488 $html .= "</refsynopsisdiv>\n";
489
490 my $dir = $option{'base-dir'} . "/elements/$name";
491 if (! -d $dir) {
492 mkdir($dir, 0755);
493 }
494
495 my $filename = "synopsis";
496 if ($expanded eq 'expanded') {
497 $filename .= ".e";
498 } else {
499 $filename .= ".u";
500 }
501
502 open (SYNOP, ">$dir/$prefix$filename.gen")
503 || die "Can't open: $dir/$prefix$filename.gen: $!";
504 print SYNOP $html;
505 close (SYNOP);
506
507 $html = "&$name.synopsis.gen;\n";
508
509 return $html;
510 }
511
512 sub formatInclusions {
513 my $count = shift;
514 my $cm = shift;
515 my $name = $elements[$count];
516 my $element = $elements{$name};
517 my $html = "";
518
519 # $html .= "<![ %" . "$baseid.ms.elem.inclusions; [\n";
520 $html .= "<row condition='ref.inclusions' rowsep='0' role='incltitle'>\n";
521 $html .= "<entry namest='c1' nameend='c3' align='left'\n";
522 $html .= "><emphasis role='bold'>Inclusions</emphasis></entry>\n";
523 $html .= "</row>\n";
524
525 $html .= "<row condition='ref.inclusions' rowsep='1' role='inclsynop'>\n";
526 $html .= "<entry namest='c1' nameend='c3' align='left'\n";
527 $html .= "><synopsis>";
528 $html .= &formatContentModel($count, $cm);
529 $html .= "</synopsis></entry>\n";
530 $html .= "</row>\n";
531 # $html .= "]]>\n";
532
533 return $html;
534 }
535
536 sub formatExclusions {
537 my $count = shift;
538 my $cm = shift;
539 my $name = $elements[$count];
540 my $element = $elements{$name};
541 my $html = "";
542
543 # $html .= "<![ %" . "$baseid.ms.elem.exclusions; [\n";
544 $html .= "<row condition='ref.exclusions' rowsep='0' role='excltitle'>\n";
545 $html .= "<entry namest='c1' nameend='c3' align='left'\n";
546 $html .= "><emphasis role='bold'>Exclusions</emphasis></entry>\n";
547 $html .= "</row>\n";
548
549 $html .= "<row condition='ref.exclusions' rowsep='1' role='exclsynop'>\n";
550 $html .= "<entry namest='c1' nameend='c3' align='left'\n";
551 $html .= "><synopsis>";
552 $html .= &formatContentModel($count, $cm);
553 $html .= "</synopsis></entry>\n";
554 $html .= "</row>\n";
555 # $html .= "]]>\n";
556
557 return $html;
558 }
559
560 sub formatAttributeList {
561 my $count = shift;
562 my $html = "";
563 my $name = $elements[$count];
564 my $element = $elements{$name};
565 my $attlist = $attlists{$name};
566 my %attrs = ();
567 my %cmnatt = ();
568 my $common = 1;
569 my $uncommon = 0;
570
571 # Check for DocBook common attributes
572
573 foreach my $attr (@common_attributes) {
574 $cmnatt{$attr} = 0;
575 # print "Common: $attr\n";
576 }
577
578 if (defined($attlist)) {
579 my $attelem = $attlist->getElementsByTagName("attribute");
580
581 for (my $count = 0; $count < $attelem->getLength(); $count++) {
582 my $attr = $attelem->item($count);
583 my $name = $attr->getAttribute('name');
584 # print "Attr: $name\n";
585 $attrs{$name} = 1;
586 if (exists $cmnatt{lc($name)}) {
587 $cmnatt{lc($name)} = 1;
588 } else {
589 $uncommon = 1;
590 }
591 }
592
593 foreach my $attr (keys %cmnatt) {
594 if ($cmnatt{$attr} == 0) {
595 # print "not common: $attr\n";
596 $common = 0;
597 }
598 }
599
600 # print "Common? $common\n";
601
602 if ($common) {
603 foreach my $attr (keys %attrs) {
604 if (exists $cmnatt{lc($attr)}) {
605 # print "Del: $attr\n";
606 delete $attrs{$attr};
607 } else {
608 # print "Keep: $attr\n";
609 }
610 }
611 }
612 }
613
614 # $html .= "<![ %" . "$baseid.ms.elem.refsynopsisdiv.attr; [\n";
615
616 my $rowsep = "1";
617 $rowsep = "0" if defined($attlist) && ($uncommon || !$common);
618
619 $html .= "<row condition='ref.rsdiv.attr' rowsep='$rowsep' role='attrtitle'>\n";
620 $html .= "<entry colsep='0'\n";
621 $html .= "><emphasis role='bold'>Attributes</emphasis></entry>\n";
622
623 if (!defined($attlist)) {
624 $html .= "<entry namest='c2' nameend='c3'>";
625 $html .= "None";
626 $html .= "</entry>\n";
627 } elsif ($common) {
628 $html .= "<entry namest='c2' nameend='c3'>";
629 # $html .= "<phrase role=\"common.attributes\">";
630 # $html .= "Common attributes";
631 # $html .= "</phrase>";
632 $html .= "<link linkend=\"common.attributes\">Common attributes</link>";
633 $html .= "</entry>\n";
634 } else {
635 $html .= "<entry namest='c2' nameend='c3'></entry>\n";
636 }
637
638 $html .= "</row>\n";
639
640 if (defined($attlist) && ($uncommon || !$common)) {
641 $html .= "<row condition='ref.rsdiv.attr' rowsep='1' role='attrheader'>\n";
642 $html .= "<entry role='th'><para\n";
643 $html .= "><emphasis role='bold'>Name</emphasis></para></entry>\n";
644 $html .= "<entry role='th'><para\n";
645 $html .= "><emphasis role='bold'>Type</emphasis></para></entry>\n";
646 $html .= "<entry role='th'><para\n";
647 $html .= "><emphasis role='bold'>Default</emphasis></para></entry>\n";
648 $html .= "</row>\n";
649 $html .= &formatAttributes($attlist, 'ref.rsdiv.attr', %attrs);
650 }
651
652 # $html .= "]]>\n\n";
653
654 return $html;
655 }
656
657 sub formatAttributes {
658 my $attlist = shift;
659 my $condition = shift;
660 my %atthash = @_;
661 my $html = "";
662 my $attrs = $attlist->getElementsByTagName("attribute");
663 my $last = "";
664
665 # figure out the last; have to do it this way because we may
666 # skip some attributes, possibly the one that's last in the
667 # actual list.
668 for (my $count = 0; $count < $attrs->getLength(); $count++) {
669 my $attr = $attrs->item($count);
670 my $name = $attr->getAttribute('name');
671 next if !exists $atthash{$name};
672 $last = $name;
673 }
674
675 for (my $count = 0; $count < $attrs->getLength(); $count++) {
676 my $attr = $attrs->item($count);
677
678 my $name = $attr->getAttribute('name');
679 my $type = $attr->getAttribute('value');
680 my $decltype = $attr->getAttribute('type');
681 my $default = "";
682
683 next if !exists $atthash{$name};
684
685 if ($decltype eq '#IMPLIED') {
686 $default = "<emphasis>None</emphasis>";
687 } elsif ($decltype eq '#REQUIRED') {
688 $default = "<emphasis>Required</emphasis>";
689 } elsif ($decltype eq '#CONREF') {
690 $default = "<emphasis>Content reference</emphasis>";
691 } else {
692 $default = $attr->getAttribute('default');
693 if ($default =~ /\"/) {
694 $default = "'" . $default . "'";
695 } else {
696 $default = "\"" . $default . "\"";
697 }
698 }
699
700 if ($decltype eq '#FIXED') {
701 $default = $default . " <emphasis>(fixed)</emphasis>";
702 }
703
704 if ($name eq $last) {
705 $html .= "<row condition='$condition' rowsep=\"1\" role=\"attr\">\n";
706 } else {
707 $html .= "<row condition='$condition' role=\"attr\">\n";
708 }
709
710 $html .= &formatCell($name);
711 $html .= &formatValues($type, $attr);
712 $html .= &formatCell($default);
713 $html .= "</row>\n";
714 }
715
716 return $html;
717 }
718
719 sub formatCell {
720 my $value = shift;
721
722 return "<entry align='left' valign='top'>$value</entry>\n";
723 }
724
725 sub formatValues {
726 my $values = shift;
727 my $attr = shift;
728 my $enum = $attr->getAttribute('enumeration');
729 my $html = "";
730
731 if ($enum eq 'no' || $enum eq '') {
732 return &formatCell($values);
733 }
734
735 $html .= "<entry align='left' valign='top'>";
736
737 # if ($enum eq 'notation') {
738 # $html .= "<para><emphasis>Enumerated notation:</emphasis>\n</para>";
739 # } else {
740 # $html .= "<para><emphasis>Enumeration:</emphasis>\n</para>";
741 # }
742 #
743 # $html .= "<simplelist>\n";
744
745 $html .= "<simplelist";
746 if ($enum eq 'notation') {
747 $html .= " role='notationenum'";
748 } else {
749 $html .= " role='enum'";
750 }
751 $html .= ">\n";
752
753 foreach my $val (sort { uc($a) cmp uc($b) }
754 split(/\s+/, $attr->getAttribute('value'))) {
755 $html .= "<member>$val</member>\n";
756 }
757 $html .= "</simplelist></entry>\n";
758
759 return $html;
760 }
761
762 sub formatTagMinimization {
763 my $count = shift;
764 my $name = $elements[$count];
765 my $element = $elements{$name};
766 my $html = "";
767 my $stagm = $element->getAttribute('stagm') || "-";
768 my $etagm = $element->getAttribute('etagm') || "-";
769
770 if ($element->getAttribute('stagm')
771 || $element->getAttribute('etagm')) {
772 my (%min) = ('--' => "Both the start- and end-tags are required for this element.",
773 'OO' => "Both the start- and end-tags are optional for this element, if your SGML declaration allows tag minimization.",
774 'O-' => "The start-tag is optional for this element, if your SGML declaration allows tag minimization. The end-tag is required.",
775 '-O' => "The start-tag is required for this element. The end-tag is optional, if your SGML declaration allows minimization."
776 );
777
778 # $html .= "<![ %" . "$baseid.ms.elem.refsynopsisdiv.tagmin; [\n";
779 $html .= "<row condition='ref.rsdiv.tagmin' rowsep='0' role='tmtitle'>\n";
780 $html .= "<entry namest='c1' nameend='c3' align='left'\n";
781 $html .= "><emphasis role='bold'>Tag Minimization</emphasis>";
782 $html .= "</entry>\n";
783 $html .= "</row>\n";
784
785 $html .= "<row condition='ref.rsdiv.tagmin' rowsep='1' role='tmsynop'>\n";
786 $html .= "<entry namest='c1' nameend='c3' align='left'\n";
787 $html .= "><para>";
788 $html .= $min{$stagm . $etagm};
789 $html .= "</para></entry>\n";
790 $html .= "</row>\n";
791 # $html .= "]]>\n\n";
792 }
793
794 return $html;
795 }
796
797 sub formatElementAppearsIn {
798 my $count = shift;
799 my $html = "";
800 my $elementname = $elements[$count];
801 my $element = $elements{$elementname};
802 my %appears = ();
803
804 %appears = %{$APPEARSIN{$elementname}} if exists $APPEARSIN{$elementname};
805
806 if (%appears) {
807 my @ents = sort { uc($a) cmp uc($b) } keys %appears;
808
809 # $html .= "<![ %" . "$baseid.ms.elem.refsynopsisdiv.pe; [\n";
810 $html .= "<row condition='ref.rsdiv.pe' rowsep='0' role='petitle'>\n";
811 $html .= "<entry namest='c1' nameend='c3' align='left'\n";
812 $html .= "><emphasis role='bold'>Parameter Entities</emphasis>";
813 $html .= "</entry>\n";
814 $html .= "</row>\n";
815
816 while (@ents) {
817 $html .= "<row condition='ref.rsdiv.pe' rowsep='0' role='pe'>\n";
818
819 for (my $count = 0; $count < 3; $count++) {
820 my $name = shift @ents;
821 if ($name) {
822 my $entity = $entities{$name};
823 $html .= "<entry colsep='0'>";
824 $html .= "<sgmltag class='paramentity'>";
825 $html .= $entity->getAttribute('name');
826 $html .= "</sgmltag>";
827 $html .= "</entry>\n";
828 } else {
829 $html .= "<entry colsep='0'></entry>\n";
830 }
831 }
832
833 $html .= "</row>\n";
834 }
835
836 # $html .= "]]>\n";
837 }
838
839 return $html;
840 }
841
842 sub formatElementDescription {
843 my $count = shift;
844 my $name = $elements[$count];
845 my $element = $elements{$name};
846 my $desc = &elementDescription($count);
847 my $html = "";
848
849 $html = "<refsect1 condition='ref.description'><title>Description</title>
850
851 <para></para>
852
853 <refsect2><title>Processing expectations</title>
854 <para></para>
855 </refsect2>\n\n";
856
857 $html .= &formatParents($count);
858 $html .= &formatChildren($count);
859
860 $html .= "\n</refsect1>\n\n";
861
862 return $html;
863 }
864
865 sub formatParents {
866 my $count = shift;
867 my $name = $elements[$count];
868 my $element = $elements{$name};
869 my $html = "";
870
871 if (exists $PARENTS{$name}) {
872 $html .= "<refsect2 condition='ref.desc.parents'><title>Parents</title>\n";
873 $html .= "<para>These elements contain ";
874 $html .= $element->getAttribute('name') . ":\n";
875 $html .= "<simplelist type='inline'>";
876
877 my $pname;
878 foreach $pname (sort { uc($a) cmp uc($b) } keys %{$PARENTS{$name}}) {
879 my $child = $elements{$pname};
880 $html .= "<member>";
881 # $html .= "<link linkend=\"$baseid.elem.$pname\">";
882 $html .= "<sgmltag>" . $child->getAttribute('name') . "</sgmltag>";
883 # $html .= "</link>";
884 $html .= "</member>\n";
885 }
886
887 $html .= "</simplelist>.</para>\n";
888 $html .= "</refsect2>\n";
889
890 my $dir = $option{'base-dir'} . "/elements/$name";
891 if (! -d $dir) {
892 mkdir($dir, 0755);
893 }
894
895 my $filename = "parents";
896 if ($expanded eq 'expanded') {
897 open (PAR, ">$dir/$prefix$filename.gen")
898 || die "Can't open: $dir/$prefix$filename.gen: $!";
899 print PAR $html;
900 close (PAR);
901 } else {
902 # unexpanded is exactly the same
903 }
904
905 $html = "&$name.parents.gen;\n";
906 }
907
908 return $html;
909 }
910
911 sub formatChildren {
912 my $count = shift;
913 my $name = $elements[$count];
914 my $element = $elements{$name};
915 my $html = "";
916 my $mixed = $element->getAttribute('content-type') eq 'mixed';
917 my $declared = (!$mixed &&
918 $element->getAttribute('content-type') ne 'element');
919
920 return "" if $declared; # can't be any children...
921
922 if (exists $CHILDREN{$name}
923 || exists $POSSINCL{$name}
924 || exists $POSSEXCL{$name}) {
925 $html .= "<refsect2 condition='ref.desc.children'><title>Children</title>\n";
926 }
927
928 if (exists $CHILDREN{$name}) {
929 $html .= "<para>The following elements occur in ";
930 $html .= $element->getAttribute('name') . ":\n";
931 $html .= "<simplelist type='inline'>";
932
933 my $cname;
934 foreach $cname (sort { uc($a) cmp uc($b) } keys %{$CHILDREN{$name}}) {
935 my $child = $elements{$cname};
936
937 die "Unexpected error (1): can't find element \"$cname\".\n"
938 if !$child;
939
940 $html .= "<member>";
941 # $html .= "<link linkend=\"$baseid.elem.$cname\">";
942 $html .= "<sgmltag>";
943 $html .= $child->getAttribute('name');
944 $html .= "</sgmltag>";
945 # $html .= "</link>";
946 $html .= "</member>\n";
947 }
948
949 $html .= "</simplelist>.</para>\n";
950 }
951
952 if (exists $POSSINCL{$name}) {
953 $html .= "<para>In some contexts, the following elements are\n";
954 $html .= "allowed anywhere:\n";
955 $html .= "<simplelist type='inline'>\n";
956
957 my $cname;
958 foreach $cname (sort { uc($a) cmp uc($b) } keys %{$POSSINCL{$name}}) {
959 my $child = $elements{$cname};
960
961 die "Unexpected error (2): can't find element \"$cname\".\n"
962 if !$child;
963
964 $html .= "<member>";
965 # $html .= "<link linkend=\"$baseid.elem.$cname\">";
966 $html .= "<sgmltag>";
967 $html .= $child->getAttribute('name');
968 $html .= "</sgmltag>";
969 # $html .= "</link>";
970 $html .= "</member>\n";
971 }
972
973 $html .= "</simplelist>.</para>\n\n";
974 }
975
976 if (exists $POSSEXCL{$name}) {
977 $html .= "<para>In some contexts, the following elements are\n";
978 $html .= "excluded:\n";
979 $html .= "<simplelist type='inline'>\n";
980
981 my $cname;
982 foreach $cname (sort { uc($a) cmp uc($b) } keys %{$POSSEXCL{$name}}) {
983 my $element = $elements{$cname};
984 $html .= "<member>";
985 # $html .= "<link linkend=\"$baseid.elem.$cname\">";
986 $html .= "<sgmltag>";
987 $html .= $element->getAttribute('name');
988 $html .= "</sgmltag>";
989 # $html .= "</link>";
990 $html .= "</member>\n";
991 }
992
993 $html .= "</simplelist>.</para>\n\n";
994 }
995
996 if (exists $CHILDREN{$name}
997 || exists $POSSINCL{$name}
998 || exists $POSSEXCL{$name}) {
999 $html .= "</refsect2>\n";
1000
1001 my $dir = $option{'base-dir'} . "/elements/$name";
1002 if (! -d $dir) {
1003 mkdir($dir, 0755);
1004 }
1005
1006 my $filename = "children";
1007 if ($expanded eq 'expanded') {
1008 open (CHD, ">$dir/$prefix$filename.gen")
1009 || die "Can't open: $dir/$prefix$filename.gen: $!";
1010 print CHD $html;
1011 close (CHD);
1012 } else {
1013 # unexpanded is exactly the same
1014 }
1015
1016 $html = "&$name.children.gen;\n";
1017 }
1018
1019 return $html;
1020 }
1021
1022 sub formatElementAttrDescription {
1023 my $count = shift;
1024 my $name = $elements[$count];
1025 my $html = "";
1026 my $attlist = $attlists{$name};
1027 my %attrs = ();
1028 my %cmnatt = ('id' => 0,
1029 'role' => 0,
1030 'lang' => 0,
1031 'remap'=> 0,
1032 'xreflabel' => 0,
1033 'revisionflag' => 0,
1034 'arch' => 0,
1035 'conformance' => 0,
1036 'os' => 0,
1037 'revision' => 0,
1038 'userlevel' => 0,
1039 'vendor' => 0,
1040 'security' => 0,
1041 'condition' => 0);
1042
1043 # Check for DocBook common attributes
1044
1045 if (defined($attlist)) {
1046 my $attelem = $attlist->getElementsByTagName("attribute");
1047
1048 for (my $count = 0; $count < $attelem->getLength(); $count++) {
1049 my $attr = $attelem->item($count);
1050 my $name = $attr->getAttribute('name');
1051 $attrs{$name} = 1 if !defined($cmnatt{lc($name)});
1052 }
1053 }
1054
1055 return $html if !%attrs;
1056
1057 $html .= "<refsect1 condition='ref.elem.attrdesc'><title>Attributes</title>\n";
1058
1059 $html .= "<variablelist>\n";
1060
1061 foreach $attr (sort keys %attrs) {
1062 my $desc = "attr." . lc($attr) . ".$name";
1063
1064 $html .= "<varlistentry><term>$attr</term>\n";
1065 $html .= "<listitem>\n";
1066 $html .= "&$desc;\n";
1067 $html .= "</listitem>\n";
1068 $html .= "</varlistentry>\n";
1069 }
1070
1071 $html .= "</variablelist>\n";
1072
1073 $html .= "</refsect1>\n";
1074
1075 return $html;
1076 }
1077
1078 my %SeeAlso = ();
1079
1080 sub formatElementSeeAlso {
1081 my $count = shift;
1082 my $name = $elements[$count];
1083 my @group = ();
1084 my $html = "";
1085
1086 if (!%SeeAlso) {
1087 my $ingroup = 0;
1088
1089 open (F, "$libdir/seealso") || die "Failed to open: $libdir/seealso\n";
1090 while (<F>) {
1091 chop;
1092 if (/^\s+(\S+)/) {
1093 push(@group, lc($1));
1094 $ingroup = 1;
1095 }
1096
1097 if (/^\S/ && $ingroup) {
1098 $ingroup = 0;
1099 foreach my $elem (@group) {
1100 $SeeAlso{$elem} = {} if ! exists $SeeAlso{$elem};
1101 foreach my $grelem (@group) {
1102 $SeeAlso{$elem}->{$grelem} = 1;
1103 }
1104 }
1105 @group = ();
1106 }
1107
1108 if (/^\S/) {
1109 $title = $_;
1110 }
1111 }
1112 close (F);
1113 }
1114
1115 @group = ();
1116 foreach my $grelem (sort keys %{$SeeAlso{$name}}) {
1117 push (@group, $grelem) unless $name eq $grelem;
1118 }
1119
1120 if (@group) {
1121 $html .= "<para>";
1122 $html .= "<simplelist type=\"inline\">\n";
1123 foreach my $elem (@group) {
1124 my $element = $elements{$elem};
1125 $html .= "<member>";
1126 # $html .= "<link linkend=\"$baseid.elem.$elem\">";
1127 $html .= "<sgmltag>";
1128
1129 if ($element) {
1130 $html .= $element->getAttribute('name');
1131 } else {
1132 print STDERR "No element $elem in formatElementSeeAlso???\n";
1133 $html .= "???";
1134 }
1135
1136 $html .= "</sgmltag>";
1137 # $html .= "</link>";
1138 $html .= "</member>\n";
1139 }
1140 $html .= "</simplelist>.\n</para>\n";
1141
1142 my $dir = $option{'base-dir'} . "/elements/$name";
1143 if (! -d $dir) {
1144 mkdir($dir, 0755);
1145 }
1146
1147 my $filename = "seealso";
1148 if ($expanded eq 'expanded') {
1149 open (SEE, ">$dir/$prefix$filename.gen")
1150 || die "Can't open: $dir/$prefix$filename.gen: $!";
1151 print SEE $html;
1152 close (SEE);
1153 } else {
1154 # unexpanded is exactly the same
1155 }
1156
1157 $html = "<refsect1 condition='ref.elem.seealso'><title>See Also</title>\n";
1158 $html .= "&$name.seealso.gen;\n";
1159 $html .= "</refsect1>\n";
1160 }
1161
1162 return $html;
1163 }
1164
1165 sub formatElementExample {
1166 my $count = shift;
1167 my $name = $elements[$count];
1168 my $element = $elements{$name};
1169 my $examplehead = "<refsect1><title>Examples</title>\n\n";
1170 my $examplefoot = "</refsect1>\n";
1171 my $see = "";
1172 my $example = "";
1173 my $done = 0;
1174 my $excount = 1;
1175
1176 my %format = (
1177 'blockquote' => 1,
1178 'caution' => 1,
1179 'cmdsynopsis' => 1,
1180 'equation' => 1,
1181 'example' => 1,
1182 'figure' => 1,
1183 'formalpara' => 1,
1184 'funcsynopsis' => 1,
1185 'glosslist' => 1,
1186 'important' => 1,
1187 'informalexample' => 1,
1188 'informalfigure' => 1,
1189 'informaltable' => 1,
1190 'itemizedlist' => 1,
1191 'mediaobject' => 1,
1192 'mediaobjectco' => 1,
1193 'msgset' => 1,
1194 'note' => 1,
1195 'orderedlist' => 1,
1196 'para' => 1,
1197 'procedure' => 1,
1198 'programlistingco' => 1,
1199 'qandaset' => 1,
1200 'screen' => 1,
1201 'screenshot' => 1,
1202 'segmentedlist' => 1,
1203 'simpara' => 1,
1204 'simplelist' => 1,
1205 'synopsis' => 1,
1206 'table' => 1,
1207 'tip' => 1,
1208 'variablelist' => 1,
1209 'warning' => 1,
1210 );
1211
1212 local *F, $_;
1213
1214 # this really just makes .txt and .gen versions of the files
1215
1216 my $dir = $option{'base-dir'} . "/elements/$name";
1217 if (! -d $dir) {
1218 mkdir($dir, 0755);
1219 }
1220
1221 while (!$done) {
1222 $done = 1;
1223 my $filename = "$dir/example.$excount";
1224 $file = "$filename.xml";
1225
1226 if (open (F, $file)) {
1227 read (F, $_, -s $file);
1228 close (F);
1229 #$_ .= "\n" if substr($_, length($_), 1) ne "\n";
1230
1231 my $doctype = "";
1232 if (/(<!DOCTYPE[^>]+\[.*?\]\>\s*)(.*)$/s) {
1233 $doctype = $1;
1234 $_ = $2;
1235 } elsif (/(<!DOCTYPE[^>]+>\s*)(.*)$/s) {
1236 $doctype = $1;
1237 $_ = $2;
1238 } else {
1239 warn "No doctype declaration on $filename?\n";
1240 }
1241
1242 my $tag = $1 if /^[^<]*<([a-zA-Z0-9]+)/s;
1243
1244 open (EX, ">$filename.txt") || die "Can't open: $filename.txt: $!";
1245 my $text = $doctype . $_;
1246 $text =~ s/\&/\&amp;/sg;
1247 $text =~ s/\</\&lt;/sg;
1248 $text =~ s/\>/\&gt;/sg;
1249 print EX $text;
1250 close (EX);
1251
1252 if ($format{lc($tag)}) {
1253 open (EX,">$filename.gen") || die "Can't open: $filename.gen $!";
1254 print EX $_;
1255 close (EX);
1256 }
1257
1258 $done = 0;
1259 }
1260
1261 $excount++;
1262 }
1263
1264 $excount -= 2; # yes, two. because of the way that loop works.
1265
1266 my $html = "";
1267
1268 if ($excount > 0) {
1269 $html .= "\n<refsect1 condition='ref.examples'><title>Examples</title>\n\n";
1270 for (my $count = 1; $count <= $excount; $count++) {
1271 $html .= "<informalexample role='example-source'>\n";
1272 $html .= "<programlisting>&$name.example.$count.txt;</programlisting>\n";
1273 $html .= "</informalexample>\n\n";
1274
1275 $html .= "<anchor id='ex.os.$name.$count' role='HACK-ex.out.start'/>\n";
1276 $html .= "&$name.example.$count.gen;\n";
1277 $html .= "<anchor id='ex.oe.$name.$count' role='HACK-ex.out.end'/>\n\n";
1278
1279 $html .= "</refsect1>\n\n";
1280 }
1281 }
1282
1283 return $html;
1284 }
1285
1286 sub formatElementFooter {
1287 my $count = shift;
1288 my $html = "";
1289
1290 $html .= "</refentry>\n\n";
1291
1292 return $html;
1293 }
1294
1295 # ----------------------------------------------------------------------
1296
1297 my $state = 'NONE';
1298 my $depth = 0;
1299 my $col = 0;
1300
1301 sub formatContentModel {
1302 my $count = shift;
1303 my $cm = shift;
1304 my $node = $cm->getFirstChild();
1305 my $html = "";
1306
1307 $state = "NONE";
1308 $depth = 0;
1309 $col = 0;
1310 while ($node) {
1311 if ($node->getNodeType == XML::DOM::ELEMENT_NODE) {
1312 $html .= formatContentModelElement($node);
1313 }
1314 $node = $node->getNextSibling();
1315 }
1316
1317 return $html;
1318 }
1319
1320 sub formatContentModelElement {
1321 my $node = shift;
1322 my $html = "";
1323
1324 if ($node->getNodeType == XML::DOM::ELEMENT_NODE) {
1325 if ($node->getTagName() eq 'sequence-group') {
1326 $html .= &formatCMGroup($node, ",");
1327 } elsif ($node->getTagName() eq 'or-group') {
1328 $html .= &formatCMGroup($node, "|");
1329 } elsif ($node->getTagName() eq 'and-group') {
1330 $html .= &formatCMGroup($node, "&");
1331 } elsif ($node->getTagName() eq 'element-name') {
1332 $html .= &formatCMElement($node);
1333 } elsif ($node->getTagName() eq 'parament-name') {
1334 $html .= &formatCMParament($node);
1335 } elsif ($node->getTagName() eq 'pcdata') {
1336 $html .= &formatCMPCDATA($node);
1337 } elsif ($node->getTagName() eq 'cdata') {
1338 $html .= &formatCMCDATA($node);
1339 } elsif ($node->getTagName() eq 'rcdata') {
1340 $html .= &formatCMRCDATA($node);
1341 } elsif ($node->getTagName() eq 'empty') {
1342 $html .= &formatCMEMPTY($node);
1343 } else {
1344 die "Unexpected node: \"" . $node->getTagName() . "\"\n";
1345 }
1346 $node = $node->getNextSibling();
1347 } else {
1348 die "Unexpected node type.\n";
1349 }
1350
1351 return $html;
1352 }
1353
1354 sub formatCMGroup {
1355 my $group = shift;
1356 my $occur = $group->getAttribute('occurrence');
1357 ;my $sep = shift;
1358 my $first = 1;
1359 my $html = "";
1360
1361 if ($state ne 'NONE' && $state ne 'OPEN') {
1362 $html .= "\n";
1363 $html .= " " x $depth if $depth > 0;
1364 $col = $depth;
1365 $state = 'NEWLINE';
1366 }
1367
1368 $html .= "(";
1369 $state = 'OPEN';
1370 $depth++;
1371 $col++;
1372
1373 my $node = $group->getFirstChild();
1374 while ($node) {
1375 if ($node->getNodeType() == XML::DOM::ELEMENT_NODE) {
1376 if (!$first) {
1377 my $name = $node->getAttribute('name');
1378 my $occur = $node->getAttribute('occurrence');
1379
1380 $html .= $sep;
1381 $col++;
1382
1383 if ($state ne 'NEWLINE'
1384 && ($col + length($name) + length($occur) > 65)) {
1385 $html .= "\n";
1386 $html .= " " x $depth if $depth > 0;
1387 $col = $depth;
1388 $state = 'NEWLINE';
1389 }
1390 }
1391 $html .= &formatContentModelElement($node);
1392 $first = 0;
1393 }
1394 $node = $node->getNextSibling();
1395 }
1396
1397 $html .= ")";
1398 $col++;
1399
1400 if ($occur) {
1401 $html .= $occur;
1402 $col++;
1403 }
1404
1405 $state = 'CLOSE';
1406 $depth--;
1407
1408 return $html;
1409 }
1410
1411 sub formatCMElement {
1412 my $element = shift;
1413 my $name = $element->getAttribute('name');
1414 my $occur = $element->getAttribute('occurrence');
1415 my $html = "";
1416
1417 $name = lc($name) if !$option{'case-sensitive'};
1418
1419 if ($state eq 'CLOSE') {
1420 $html .= "\n";
1421 $html .= " " x $depth if $depth > 0;
1422 $col = $depth;
1423 $state = 'NEWLINE';
1424 }
1425
1426 # $html .= "<link linkend='$baseid.elem.$name'>";
1427 $html .= "<sgmltag>";
1428 $html .= $element->getAttribute('name');
1429 $html .= "</sgmltag>";
1430 # $html .= "</link>";
1431 $col += length($name);
1432
1433 if ($occur) {
1434 $html .= $occur;
1435 $col++;
1436 }
1437
1438 $state = 'ELEMENT';
1439
1440 return $html;
1441 }
1442
1443 sub formatCMParament {
1444 my $element = shift;
1445 my $name = $element->getAttribute('name');
1446 my $html = "";
1447
1448 if ($state eq 'CLOSE') {
1449 $html .= "\n";
1450 $html .= " " x $depth if $depth > 0;
1451 $col = $depth;
1452 $state = 'NEWLINE';
1453 }
1454
1455 # $html .= "<link linkend='$baseid.param.$name'>";
1456 $html .= "<sgmltag class=\"paramentity\">";
1457 $html .= $name;
1458 $html .= "</sgmltag>";
1459 # $html .= "</link>";
1460 $col += length($name) + 2;
1461
1462 $state = 'PARAMENT';
1463
1464 return $html;
1465 }
1466
1467 sub formatCMPCDATA {
1468 my $html = "";
1469
1470 $html .= "#PCDATA";
1471 $col += 7;
1472 $state = 'PCDATA';
1473
1474 return $html;
1475 }
1476
1477 sub formatCMCDATA {
1478 my $html = "";
1479
1480 $html .= "CDATA";
1481 $col += 5;
1482 $state = 'CDATA';
1483
1484 return $html;
1485 }
1486
1487 sub formatCMRCDATA {
1488 my $html = "";
1489
1490 $html .= "RCDATA";
1491 $col += 5;
1492 $state = 'RCDATA';
1493
1494 return $html;
1495 }
1496
1497 sub formatCMEMPTY {
1498 my $html = "";
1499
1500 $html .= "EMPTY";
1501 $col += 5;
1502 $state = 'EMPTY';
1503
1504 return $html;
1505 }
1506
1507 # ======================================================================
1508
1509 sub formatEntity {
1510 my $count = shift;
1511 my $name = $entities[$count];
1512 my $entity = $entities{$name};
1513 my $html = "";
1514
1515 my $textnl, $altnl;
1516
1517 if ($expanded eq 'expanded') {
1518 $textnl = $entity->getElementsByTagName("text-expanded");
1519 $altnl = $entity->getElementsByTagName("text");
1520 } else {
1521 $textnl = $entity->getElementsByTagName("text");
1522 $altnl = $entity->getElementsByTagName("text-expanded");
1523 }
1524
1525 # Hack; we're appending to a single file, just return the VLE synopsis...
1526 return &formatEntityVLESynopsis($count, $textnl, $altnl);
1527
1528 $html .= &formatEntityHeader($count);
1529
1530 $html .= &formatEntityTitle($count);
1531
1532 $html .= &formatEntitySynopsis($count, $textnl, $altnl)
1533 if $option{'synopsis'};
1534
1535 $html .= &formatEntityAppearsIn($count) if $option{'appears-in'};
1536
1537 $html .= &formatEntityDescription($count) if $option{'description'};
1538
1539 $html .= &formatEntityExamples($count) if $option{'examples'};
1540
1541 $html .= &formatEntityFooter($count);
1542
1543 return $html;
1544 }
1545
1546 sub formatEntityHeader {
1547 my $count = shift;
1548 my $html = "";
1549 my $name = $entities[$count];
1550
1551 $html .= "<refentry id=\"$name.parament\">\n";
1552 $html .= "<!-- Generated by DTDParse version $VERSION -->\n";
1553 $html .= "<!-- see http://www.sf.net/projects/dtdparse/ -->\n\n";
1554
1555 return $html;
1556 }
1557
1558 sub formatEntityTitle {
1559 my $count = shift;
1560 my $name = $entities[$count];
1561 my $entity = $entities{$name};
1562 my $type = $entity->getAttribute("type");
1563 my $html = "";
1564
1565 # $html .= "<![ %" . "$baseid.ms.param.refmeta; [\n";
1566 $html .= "<refmeta>\n";
1567 $html .= "<refentrytitle>";
1568 $html .= $entity->getAttribute('name');
1569 $html .= "</refentrytitle>\n";
1570
1571 if ($type eq 'gen') {
1572 $html .= "<refmiscinfo>General Entity</refmiscinfo>\n";
1573 } else {
1574 $html .= "<refmiscinfo>Parameter Entity</refmiscinfo>\n";
1575 }
1576
1577 $html .= "</refmeta>\n";
1578 # $html .= "]]>\n\n";
1579
1580 $html .= "<refnamediv>\n";
1581 $html .= "<refname>" . $entity->getAttribute('name') . "</refname>\n";
1582 $html .= "<refpurpose>";
1583 $html .= &entityRefpurpose($count);
1584 $html .= "</refpurpose>\n";
1585 $html .= "</refnamediv>\n\n";
1586 }
1587
1588 sub formatEntitySynopsis {
1589 my $count = shift;
1590 my $textnl = shift;
1591 my $altnl = shift;
1592 my $name = $entities[$count];
1593 my $entity = $entities{$name};
1594 my $html = "";
1595 my $type = $entity->getAttribute("type");
1596 my $public = $entity->getAttribute("public");
1597 my $system = $entity->getAttribute("system");
1598 my $text = "";
1599
1600 if ($textnl->getLength() > 0) {
1601 my $textnode = $textnl->item(0);
1602 my $content = $textnode->getFirstChild();
1603 if ($content) {
1604 $text = $content->getData();
1605 } else {
1606 $text = "";
1607 }
1608 }
1609
1610 # $html .= "<![ %" . "$baseid.ms.param.refsynopsisdiv; [\n";
1611 $html .= "<refsynopsisdiv>\n";
1612 $html .= "<informaltable frame='all' role='elemsynop'>\n";
1613 $html .= "<tgroup cols='3'>\n";
1614 $html .= "<colspec colnum='1' colname='c1'/>\n";
1615 $html .= "<colspec colnum='2' colname='c2'/>\n";
1616 $html .= "<colspec colnum='3' colname='c3'/>\n";
1617 $html .= "<tbody>\n";
1618
1619 $html .= "<row rowsep='0' role='cmtitle'>\n";
1620 $html .= "<entry namest='c1' nameend='c3' align='left'\n";
1621 $html .= "><emphasis role='bold'>";
1622
1623 if ($type eq 'gen') {
1624 $html .= "General Entity";
1625 $html .= "</emphasis></entry>\n";
1626 $html .= "</row>\n";
1627 $html .= "<row rowsep='1' role='cmsynop'>\n";
1628 $html .= "<entry namest='c1' nameend='c3' align='left'\n";
1629 $html .= "><synopsis>";
1630
1631 if ($text =~ /\"/) {
1632 $html .= "'$text'\n";
1633 } else {
1634 $html .= "\"$text\"\n";
1635 }
1636
1637 $html .= "</synopsis></entry>\n";
1638 $html .= "</row>\n";
1639 }
1640
1641 if ($type eq 'param') {
1642 if ($public || $system) {
1643 $html .= "External Entity";
1644 $html .= "</emphasis></entry>\n";
1645 $html .= "</row>\n";
1646 $html .= "<row rowsep='1' role='cmsynop'>\n";
1647 $html .= "<entry namest='c1' nameend='c3' align='left'\n";
1648 $html .= ">";
1649
1650 $html .= "<para><emphasis role='bold'>Public identifier</emphasis>: $public\n</para>" if $public;
1651 $html .= "<para><emphasis role='bold'>System identifier</emphasis>: $system\n</para>" if $system;
1652
1653 $html .= "</entry>\n";
1654 $html .= "</row>\n";
1655 } else {
1656 $html .= "Parameter Entity\n";
1657 $html .= "</emphasis></entry>\n";
1658 $html .= "</row>\n";
1659 $html .= "<row rowsep='1' role='cmsynop'>\n";
1660 $html .= "<entry namest='c1' nameend='c3' align='left'\n";
1661
1662 if ($text eq '') {
1663 $html .= "><para>";
1664 $html .= "The replacement text for this entity is empty.";
1665 $html .= "</para>";
1666 } else {
1667 $html .= "><synopsis>";
1668 $html .= &formatEntitySynopsisContent($text);
1669 $html .= "</synopsis>";
1670 }
1671
1672 $html .= "</entry>\n";
1673 $html .= "</row>\n";
1674
1675 # output the expanded version as well, in the unexpanded case
1676 if ($expanded eq 'unexpanded') {
1677 if ($altnl->getLength() > 0) {
1678 my $textnode = $altnl->item(0);
1679 my $content = $textnode->getFirstChild();
1680 if ($content) {
1681 $text = $content->getData();
1682 } else {
1683 $text = "";
1684 }
1685 }
1686
1687 $html .= "<row rowsep='0' role='cmtitle'>\n";
1688 $html .= "<entry namest='c1' nameend='c3' align='left'\n";
1689 $html .= "><emphasis role='bold'>";
1690 $html .= "Parameter Entity (Expanded)\n";
1691 $html .= "</emphasis></entry>\n";
1692 $html .= "</row>\n";
1693 $html .= "<row rowsep='1' role='cmsynop'>\n";
1694 $html .= "<entry namest='c1' nameend='c3' align='left'\n";
1695
1696 if ($text eq '') {
1697 $html .= "><para>";
1698 $html .= "The replacement text for this entity is empty.";
1699 $html .= "</para>";
1700 } else {
1701 $html .= "><synopsis>";
1702 $html .= &formatEntitySynopsisContent($text);
1703 $html .= "</synopsis>";
1704 }
1705
1706 $html .= "</entry>\n";
1707 $html .= "</row>\n";
1708 }
1709 }
1710 }
1711
1712 $html .= "</tbody>\n";
1713 $html .= "</tgroup>\n";
1714 $html .= "</informaltable>\n";
1715 $html .= "</refsynopsisdiv>\n\n";
1716
1717 return $html;
1718 }
1719
1720 sub formatEntityVLESynopsis {
1721 my $count = shift;
1722 my $textnl = shift;
1723 my $altnl = shift;
1724 my $name = $entities[$count];
1725 my $entity = $entities{$name};
1726 my $html = "";
1727 my $type = $entity->getAttribute("type");
1728 my $public = $entity->getAttribute("public");
1729 my $system = $entity->getAttribute("system");
1730 my $text = "";
1731 my %attr = ();
1732
1733 if ($textnl->getLength() > 0) {
1734 my $textnode = $textnl->item(0);
1735 my $content = $textnode->getFirstChild();
1736 if ($content) {
1737 $text = $content->getData();
1738 } else {
1739 $text = "";
1740 }
1741 }
1742
1743 $html .= "<informaltable frame='all' role='elemsynop'>\n";
1744 $html .= "<tgroup cols='3'>\n";
1745 $html .= "<colspec colnum='1' colname='c1'/>\n";
1746 $html .= "<colspec colnum='2' colname='c2'/>\n";
1747 $html .= "<colspec colnum='3' colname='c3'/>\n";
1748 $html .= "<tbody>\n";
1749
1750 $html .= "<row rowsep='0' role='vle-cmtitle'>\n";
1751 $html .= "<entry namest='c1' nameend='c3' align='left'\n";
1752 $html .= "><emphasis role='bold'>";
1753
1754 if ($type eq 'gen') {
1755 $html .= "General Entity";
1756 $html .= "</emphasis></entry>\n";
1757 $html .= "</row>\n";
1758 $html .= "<row rowsep='1' role='cmsynop'>\n";
1759 $html .= "<entry namest='c1' nameend='c3' align='left'\n";
1760 $html .= "><synopsis>";
1761
1762 if ($text =~ /\"/) {
1763 $html .= "'$text'\n";
1764 } else {
1765 $html .= "\"$text\"\n";
1766 }
1767
1768 $html .= "</synopsis></entry>\n";
1769 $html .= "</row>\n";
1770 }
1771
1772 if ($type eq 'param') {
1773 if ($public || $system) {
1774 $html .= "External Entity";
1775 $html .= "</emphasis></entry>\n";
1776 $html .= "</row>\n";
1777 $html .= "<row rowsep='1' role='cmsynop'>\n";
1778 $html .= "<entry namest='c1' nameend='c3' align='left'\n";
1779 $html .= ">";
1780
1781 $html .= "<para><emphasis role='bold'>Public identifier</emphasis>: $public\n</para>" if $public;
1782 $html .= "<para><emphasis role='bold'>System identifier</emphasis>: $system\n</para>" if $system;
1783
1784 $html .= "</entry>\n";
1785 $html .= "</row>\n";
1786 } else {
1787 $html .= "Parameter Entity\n";
1788 $html .= "</emphasis></entry>\n";
1789 $html .= "</row>\n";
1790
1791 my $temptext = $text;
1792 $temptext =~ s/--.*?--//sg;
1793
1794 if (($name =~ /\.attrib$/
1795 || $name eq 'bodyatt'
1796 || $name eq 'secur'
1797 || $name eq 'tbl.table.att'
1798 || $name eq 'tbl.tgroup.att')
1799 && ($temptext ne "")
1800 && ($expanded eq 'expanded')) {
1801 my $table;
1802 ($table, %attr) = &formatEntityAttributeContent($temptext);
1803 $html .= $table;
1804 } else {
1805 $html .= "<row rowsep='1' role='cmsynop'>\n";
1806 $html .= "<entry namest='c1' nameend='c3' align='left'\n";
1807
1808 if ($temptext eq '') {
1809 $html .= "><para>";
1810 $html .= "The replacement text for this entity is empty.";
1811 $html .= "</para>";
1812 } else {
1813 $html .= "><synopsis>";
1814 $html .= &formatEntitySynopsisContent($text);
1815 $html .= "</synopsis>";
1816 }
1817
1818 $html .= "</entry>\n";
1819 $html .= "</row>\n";
1820 }
1821
1822 # output the expanded version as well, in the unexpanded case
1823 if ($expanded eq 'unexpanded') {
1824 if ($altnl->getLength() > 0) {
1825 my $textnode = $altnl->item(0);
1826 my $content = $textnode->getFirstChild();
1827 if ($content) {
1828 $text = $content->getData();
1829 } else {
1830 $text = "";
1831 }
1832 }
1833
1834 $html .= "<row rowsep='0' role='cmtitle'>\n";
1835 $html .= "<entry namest='c1' nameend='c3' align='left'\n";
1836 $html .= "><emphasis role='bold'>";
1837 $html .= "Parameter Entity (Expanded)\n";
1838 $html .= "</emphasis></entry>\n";
1839 $html .= "</row>\n";
1840
1841 my $temptext = $text;
1842 $temptext =~ s/--.*?--//sg;
1843
1844 $html .= "<row rowsep='1' role='cmsynop'>\n";
1845 $html .= "<entry namest='c1' nameend='c3' align='left'\n";
1846
1847 if ($temptext eq '') {
1848 $html .= "><para>";
1849 $html .= "The replacement text for this entity is empty.";
1850 $html .= "</para>";
1851 } else {
1852 $html .= "><synopsis>";
1853 $html .= &formatEntitySynopsisContent($text);
1854 $html .= "</synopsis>";
1855 }
1856
1857 $html .= "</entry>\n";
1858 $html .= "</row>\n";
1859 }
1860 }
1861 }
1862
1863 $html .= &formatEntityVLEAppearsIn($name);
1864
1865 $html .= "</tbody>\n";
1866 $html .= "</tgroup>\n";
1867 $html .= "</informaltable>\n";
1868
1869 # On further consideration, don't do this. Let users look at the individual
1870 # elements for attribute description.
1871 # if (%attr) {
1872 # $html .= &formatEntityAttributeDesc($name, %attr);
1873 # }
1874
1875 return $html;
1876 }
1877
1878 sub formatEntityAttributeContent {
1879 my $text = shift;
1880 my $html = "";
1881 my %attrs = ();
1882 my %cmnatt = ('id' => 0,
1883 'role' => 0,
1884 'lang' => 0,
1885 'remap'=> 0,
1886 'xreflabel' => 0,
1887 'revisionflag' => 0,
1888 'arch' => 0,
1889 'conformance' => 0,
1890 'os' => 0,
1891 'revision' => 0,
1892 'userlevel' => 0,
1893 'vendor' => 0,
1894 'security' => 0,
1895 'condition' => 0);
1896
1897 # This function is only called if $text is not empty.
1898 # Interpret it as a well-formed section of an attlist decl
1899 $text =~ s/--.*?--//sg;
1900 # $html .= "<!-- $text -->\n";
1901
1902 $html .= "<row rowsep='1' role='attrheader'>\n";
1903 $html .= "<entry role='th'><para><emphasis role='bold'>Name</emphasis></para></entry>\n";
1904 $html .= "<entry role='th'><para><emphasis role='bold'>Type</emphasis></para></entry>\n";
1905 $html .= "<entry role='th'><para><emphasis role='bold'>Default</emphasis></para></entry>\n";
1906 $html .= "</row>\n";
1907
1908 $text =~ s/\n/ /sg; # make it all one line..
1909
1910 while ($text !~ /^\s*$/) {
1911 $html .= "<row role='attr'>\n";
1912
1913 $text =~ /^\s*(\S+)(.*?)$/;
1914 my $token = $1;
1915 $text = $2;
1916
1917 $attrs{$token} = 1 if !defined($cmnatt{lc($token)});
1918
1919 $html .= "<entry align='left' valign='top'>$token</entry>\n";
1920
1921 $text =~ /^\s*(\S+)(.*?)$/;
1922 $token = $1;
1923 $text = $2;
1924
1925 if ($token =~ /NOTATION/
1926 || $token =~ /^\s*\(/) {
1927 $html .= "<entry align='left' valign='top'><para>";
1928 if ($token =~ /NOTATION/) {
1929 $html .= "<emphasis>Enumerated notation:</emphasis>";
1930 $text =~ /^\s*(\S+)\s+(.*)$/;
1931 $token = $1;
1932 $text = $2;
1933 } else {
1934 $html .= "<emphasis>Enumerated:</emphasis>";
1935 }
1936 $html .= "</para><simplelist>";
1937
1938 if ($token =~ /\)\s*$/) {
1939 # we got the whole thing...
1940 } else {
1941 $text =~ /^(.*?)\)/;
1942 $token .= $1;
1943 $text = $'; # '
1944 }
1945
1946 $token =~ s/[\(\)\|]/ /sg;
1947 $token =~ s/^\s*//sg;
1948 $token =~ s/\s*$//sg;
1949 my @members = split(/\s+/, $token);
1950 foreach my $member (@members) {
1951 $html .= "<member>$member</member>\n";
1952 }
1953
1954 $html .= "</simplelist></entry>\n";
1955 } else {
1956 $html .= "<entry align='left' valign='top'>$token</entry>\n";
1957 }
1958
1959 $text =~ /^\s*(\S+)(.*?)$/s;
1960 $token = $1;
1961 $text = $2;
1962
1963 if ($token eq '#IMPLIED') {
1964 $token = "<emphasis>None</emphasis>";
1965 } elsif ($token eq '#REQUIRED') {
1966 $token = "<emphasis>Required</emphasis>";
1967 } elsif ($token eq '#CONREF') {
1968 $token = "<emphasis>Content reference</emphasis>";
1969 }
1970
1971 $html .= "<entry align='left' valign='top'>$token</entry>\n";
1972 $html .= "</row>\n";
1973 }
1974
1975 return ($html, %attrs);
1976 }
1977
1978 sub formatEntityAttributeDesc {
1979 my $name = shift;
1980 my %attrs = @_;
1981 my $html = "";
1982
1983 # find an element that uses entity %name
1984 if (!defined($EAPPEARSIN{"%$name"})) {
1985 print "No EA for %$name\n";
1986 return $html;
1987 }
1988
1989 my %elem = %{$EAPPEARSIN{"%$name"}};
1990 my @elems = keys %elem;
1991 my $elemname = $elems[0];
1992
1993 $html .= "<para><emphasis role='bold'>Attribute descriptions:";
1994 $html .= "</emphasis></para>\n";
1995
1996 $html .= "<variablelist>\n";
1997 foreach my $attr (sort keys %attrs) {
1998 $html .= "<varlistentry><term>$attr</term>\n";
1999 $html .= "<listitem>\n";
2000 $html .= "&attr." . lc($attr) . ".$elemname;\n";
2001 $html .= "</listitem>\n";
2002 $html .= "</varlistentry>\n";
2003 }
2004 $html .= "</variablelist>\n";
2005
2006 return $html;
2007 }
2008
2009 sub formatEntityVLEAppearsIn {
2010 my $name = shift;
2011 my $html = "";
2012
2013 my %appears = %{$EAPPEARSIN{"%$name"}} if exists $EAPPEARSIN{"%$name"};
2014
2015 if (%appears) {
2016 my @ents = sort { uc($a) cmp uc($b) } keys %appears;
2017
2018 $html .= "<row rowsep='0' role='vle-petitle'>\n";
2019 $html .= "<entry namest='c1' nameend='c3' align='left'\n";
2020 $html .= "><emphasis role='bold'>%$name; appears in:</emphasis>";
2021 $html .= "</entry>\n";
2022 $html .= "</row>\n";
2023
2024 while (@ents) {
2025 $html .= "<row rowsep='0' role='vle-pe'>\n";
2026
2027 for (my $count = 0; $count < 3; $count++) {
2028 my $name = shift @ents;
2029 if ($name) {
2030 my $elem = $elements{$name};
2031 die "Cannot find element $name\n" if !$elem;
2032 $html .= "<entry colsep='0'>";
2033 $html .= "<sgmltag>";
2034 $html .= $elem->getAttribute('name');
2035 $html .= "</sgmltag>";
2036 $html .= "</entry>\n";
2037 } else {
2038 $html .= "<entry colsep='0'></entry>\n";
2039 }
2040 }
2041
2042 $html .= "</row>\n";
2043 }
2044 }
2045
2046 return $html;
2047 }
2048
2049 sub formatEntitySynopsisContent {
2050 my $text = shift;
2051 my $html = "";
2052
2053 # OK, it's a parameter entity. Now, does it look like a
2054 # content model fragment
2055
2056 my $cmfragment = &cmFragment($text);
2057
2058 while ($text =~ /\%?[-a-z0-9.:_]+;?/is) {
2059 my $pre = $`;
2060 my $match = $&;
2061 $text = $'; # '
2062
2063 $html .= $pre;
2064
2065 if ($pre =~ /\#$/) {
2066 # if it comes after a '#', it's a keyword...
2067 $html .= $match;
2068 next;
2069 }
2070
2071 if ($match =~ /\%([^;]+);?/) {
2072 $name = $1;
2073 if (exists $entities{$name}) {
2074 # $html .= "<link linkend=\"$baseid.param.$name\">";
2075 $html .= $match;
2076 # $html .= "</link>";
2077 } else {
2078 $html .= $match;
2079 }
2080 } elsif ($cmfragment) {
2081 $name = $match;
2082 $name = lc($name) if !$option{'case-sensitive'};
2083 if (exists $elements{$name}) {
2084 my $linkend = "$baseid.elem.$name";
2085 # $html .= "<link linkend=\"$linkend\">";
2086 $html .= "$match";
2087 # $html .= "</link>";
2088 } else {
2089 $html .= $match;
2090 }
2091 } else {
2092 $html .= $match;
2093 }
2094 }
2095
2096 return $html;
2097 }
2098
2099 sub formatEntityAppearsIn {
2100 my $count = shift;
2101 my $html = "";
2102 my $entityname = $entities[$count];
2103 my $entity = $entities{$entityname};
2104 my %appears = ();
2105 my $key = "%$entityname";
2106
2107 if (exists $APPEARSIN{$key}) {
2108 %appears = %{$APPEARSIN{$key}};
2109 my @ents = sort { uc($a) cmp uc($b) } keys %appears;
2110
2111 # $html .= "<![ %" . "$baseid.ms.param.refsynopsisdiv.pe; [\n";
2112 $html .= "<refsect1 condition='ref.rsdiv.pe'><title>Parameter Entities</title>\n";
2113 $html .= "<para>The following parameter entities contain ";
2114 $html .= "<sgmltag class=\"paramentity\">";
2115 $html .= $entity->getAttribute('name');
2116 $html .= "</sgmltag>:\n";
2117 $html .= "<simplelist type='inline'>\n";
2118
2119 for (my $count = 0; $count <= $#ents; $count++) {
2120 my $entity = $entities{$ents[$count]};
2121 $html .= "<member>";
2122 # $html .= "<link linkend=\"$baseid.";
2123 # $html .= $entity->getAttribute('type') . ".";
2124 # $html .= $entity->getAttribute('name') . "\">";
2125 $html .= "<sgmltag class=\"paramentity\">";
2126 $html .= $entity->getAttribute('name');
2127 $html .= "</sgmltag>";
2128 # $html .= "</link>";
2129 $html .= "</member>\n";
2130 }
2131 $html .= "</simplelist></para>\n";
2132 $html .= "</refsect1>\n";
2133 # $html .= "]]>\n\n";
2134 }
2135
2136 my $refsect = "refsect1";
2137 if (exists($EAPPEARSIN{$key}) && exists($XAPPEARSIN{$key})) {
2138 $refsect = "refsect2";
2139 # $html .= "<![ %" . "$baseid.ms.param.refsynopsisdiv.pe; [\n";
2140 $html .= "<refsect1 condition='ref.rsdiv.pe'><title>Elements</title>\n";
2141 $html .= "<para>Some element content models are effected both\n";
2142 $html .= "directly and indirectly by the\n";
2143 $html .= "<sgmltag class=\"paramentity\">";
2144 $html .= $entity->getAttribute('name');
2145 $html .= "</sgmltag> parameter entity.</para>\n";
2146 }
2147
2148 if (exists($EAPPEARSIN{$key})) {
2149 %appears = %{$EAPPEARSIN{$key}};
2150
2151 my @elem = sort { uc($a) cmp uc($b) } keys %appears;
2152
2153 if (exists($EAPPEARSIN{$key}) && exists($XAPPEARSIN{$key})) {
2154 $html .= "<refsect2><title>Directly Effected</title>\n";
2155
2156 # print "\n", $entity->getAttribute('name'), " ($key):\n";
2157 # print "\t", $#elem, "\n";
2158 # foreach my $foo (keys %{$EAPPEARSIN{$key}}) {
2159 # print "\t'$foo'='", $EAPPEARSIN{$key}->{$foo}, "'\n";
2160 # }
2161 } else {
2162 $html .= "<refsect1><title>Elements</title>\n";
2163 }
2164
2165 $html .= "<para>The content models of the following elements\n";
2166 $html .= "contain ";
2167 $html .= "<sgmltag class=\"paramentity\">";
2168 $html .= $entity->getAttribute('name');
2169 $html .= "</sgmltag> directly:\n";
2170 $html .= "<simplelist type='inline'>\n";
2171
2172 for (my $count = 0; $count <= $#elem; $count++) {
2173 my $element = $elements{$elem[$count]};
2174 $html .= "<member>";
2175 # $html .= "<link linkend=\"$baseid.elem.";
2176 # $html .= $elem[$count] . "\">";
2177 $html .= "<sgmltag>";
2178 $html .= $element->getAttribute('name');
2179 $html .= "</sgmltag>";
2180 # $html .= "</link>";
2181 $html .= "</member>\n";
2182 }
2183 $html .= "</simplelist></para>\n";
2184 $html .= "</$refsect>\n";
2185 }
2186
2187 if (exists $XAPPEARSIN{$key}) {
2188 %appears = %{$XAPPEARSIN{$key}};
2189
2190 my @elem = sort { uc($a) cmp uc($b) } keys %appears;
2191
2192 if (exists($EAPPEARSIN{$key}) && exists($XAPPEARSIN{$key})) {
2193 $html .= "<refsect2><title>Indirectly Effected</title>\n";
2194 } else {
2195 $html .= "<refsect1><title>Elements</title>\n";
2196 }
2197
2198 $html .= "<para>The content models of the following elements\n";
2199 $html .= "contain ";
2200 $html .= "<sgmltag class=\"paramentity\">";
2201 $html .= $entity->getAttribute('name');
2202 $html .= "</sgmltag> indirectly:\n";
2203 $html .= "<simplelist type='inline'>\n";
2204
2205 for (my $count = 0; $count <= $#elem; $count++) {
2206 my $element = $elements{$elem[$count]};
2207 $html .= "<member>";
2208 # $html .= "<link linkend=\"$baseid.elem.";
2209 # $html .= $elem[$count] . "\">";
2210 $html .= "<sgmltag>";
2211 $html .= $element->getAttribute('name');
2212 $html .= "</sgmltag>";
2213 # $html .= "</link>";
2214 $html .= "</member>\n";
2215 }
2216 $html .= "</simplelist></para>\n";
2217 $html .= "</$refsect>\n";
2218 }
2219
2220 $html .= "</refsect1>\n"
2221 if (exists($EAPPEARSIN{$key}) && exists($XAPPEARSIN{$key}));
2222
2223 # $html .= "]]>\n\n";
2224
2225 return $html;
2226 }
2227
2228 sub formatEntityDescription {
2229 my $count = shift;
2230 my $name = $entities[$count];
2231 my $entity = $entities{$name};
2232 my $desc = &entityDescription($count);
2233 my $html = "";
2234
2235 return "" if !defined($desc);
2236
2237 $html .= "<refsect1><title>Description</title>\n";
2238 $html .= $desc;
2239 $html .= "</refsect1>\n\n";
2240
2241 return $html;
2242 }
2243
2244 sub formatEntityExamples {
2245 my $count = shift;
2246 my $name = $entities[$count];
2247 my $entity = $entities{$name};
2248
2249 return "";
2250 }
2251
2252 sub formatEntityFooter {
2253 my $count = shift;
2254 my $html = "";
2255
2256 $html .= "</refentry>\n";
2257
2258 return $html;
2259 }
2260
2261 # ======================================================================
2262
2263 sub formatNotation {
2264 my $count = shift;
2265 my $html = "";
2266
2267 my $name = $notations[$count];
2268 my $element = $notations{$name};
2269
2270 $html .= &formatNotationHeader($count);
2271
2272 $html .= &formatNotationTitle($count);
2273
2274 if ($option{'synopsis'}) {
2275 $html .= &formatNotationSynopsis($count);
2276 }
2277
2278 $html .= &formatNotationDescription($count)
2279 if $option{'description'};
2280
2281 $html .= &formatNotationExamples($count) if $option{'examples'};
2282
2283 $html .= &formatNotationFooter($count);
2284 }
2285
2286 sub formatNotationHeader {
2287 my $count = shift;
2288 my $html = "";
2289 my $name = $notations[$count];
2290
2291 $html .= "<refentry id=\"$name.notation\">\n";
2292 $html .= "<!-- Generated by DTDParse version $VERSION -->\n";
2293 $html .= "<!-- see http://www.sf.net/projects/dtdparse/ -->\n\n";
2294
2295 return $html;
2296 }
2297
2298 sub formatNotationTitle {
2299 my $count = shift;
2300 my $name = $notations[$count];
2301 my $notation = $notations{$name};
2302 my $html = "";
2303
2304 $html .= "<refmeta>\n";
2305 $html .= "<refentrytitle>";
2306 $html .= $notation->getAttribute('name');
2307 $html .= "</refentrytitle>\n";
2308 $html .= "<refmiscinfo>Notation</refmiscinfo>\n";
2309 $html .= "</refmeta>\n\n";
2310
2311 $html .= "<refnamediv>\n";
2312 $html .= "<refname>" . $notation->getAttribute('name') . "</refname>\n";
2313 $html .= "<refpurpose>";
2314 $html .= &notationRefpurpose($count);
2315 $html .= "</refpurpose>\n";
2316 $html .= "</refnamediv>\n\n";
2317 }
2318
2319 sub formatNotationSynopsis {
2320 my $count = shift;
2321 my $name = $notations[$count];
2322 my $notation = $notations{$name};
2323 my $html = "";
2324 my $public = $notation->getAttribute("public");
2325 my $system = $notation->getAttribute("system");
2326
2327 $html .= "<refsynopsisdiv>\n";
2328
2329 if ($public) {
2330 $html .= "<para>\nPublic identifier:\n";
2331 $html .= "<emphasis>$public</emphasis>.";
2332 $html .= "</para>\n\n";
2333 }
2334
2335 if ($system) {
2336 $html .= "<para>\nSystem identifier:\n";
2337 $html .= "<emphasis>$system</emphasis>.";
2338 $html .= "</para>\n\n";
2339 }
2340
2341 if (!$public && !$system) {
2342 $html .= "<para>\n<quote>System</quote> specified\n";
2343 $html .= "without a system identifier.";
2344 $html .= "</para>\n\n";
2345 }
2346
2347 return $html;
2348 }
2349
2350 sub formatNotationDescription {
2351 my $count = shift;
2352 my $name = $notations[$count];
2353 my $notation = $notations{$name};
2354 my $desc = &notationDescription($count);
2355 my $html = "";
2356
2357 return "" if !defined($desc);
2358
2359 $html .= "<refsect1><title>Description</title>\n";
2360 $html .= $desc;
2361 $html .= "</refsect1>\n\n";
2362
2363 return $html;
2364 }
2365
2366 sub formatNotationExamples {
2367 my $count = shift;
2368 my $name = $notations[$count];
2369 my $element = $notations{$name};
2370
2371 return "";
2372 }
2373
2374 sub formatNotationFooter {
2375 my $count = shift;
2376 my $html = "";
2377
2378 $html .= "</refentry>\n";
2379
2380 return $html;
2381 }
2382
2383 # ======================================================================
2384
2385 sub createDir {
2386 my $dir = shift;
2387 my $mode = shift;
2388 # nop
2389 }
2390
2391 sub checkDir {
2392 my $dir = shift;
2393 # nop
2394 }
2395
2396 sub writeElement {
2397 my $count = shift;
2398 my $path = shift;
2399 my $basename = shift;
2400 my $fileext = shift;
2401 my $html = shift;
2402 my $name = $elements[$count];
2403 my $element = $elements{$name};
2404
2405 my $dir = $option{'base-dir'} . "/elements/$basename";
2406 if (! -d $dir) {
2407 mkdir($dir, 0755);
2408 }
2409
2410 # DON'T OVERWRITE THIS FILE ANYMORE!
2411 if (! -f "$dir/refentry$fileext") {
2412 open (F, ">$dir/refentry$fileext");
2413 print F $html;
2414 close (F);
2415 }
2416
2417 open (F, ">$dir/${prefix}entities.e.ent");
2418 print F "<!ENTITY $name.synopsis.gen SYSTEM \"${prefix}synopsis.e.gen\">\n"
2419 if -f "$dir/${prefix}synopsis.e.gen";
2420
2421 foreach my $f ("children", "parents", "seealso", "example.seealso") {
2422 print F "<!ENTITY $name.$f.gen SYSTEM \"$prefix$f.gen\">\n"
2423 if -f "$dir/$prefix$f.gen";
2424 }
2425
2426 for (my $count = 1; -f "$dir/example.$count.gen"; $count++) {
2427 print F "<!ENTITY $name.example.$count.gen SYSTEM \"example.$count.gen\">\n";
2428 }
2429
2430 for (my $count = 1; -f "$dir/example.$count.txt"; $count++) {
2431 print F "<!ENTITY $name.example.$count.txt SYSTEM \"example.$count.txt\">\n";
2432 }
2433
2434 close (F);
2435
2436 open (F, ">$dir/${prefix}entities.u.ent");
2437 print F "<!ENTITY $name.synopsis.gen SYSTEM \"synopsis.u.gen\">\n"
2438 if -f "$dir/${prefix}synopsis.u.gen";
2439
2440 foreach my $f ("children", "parents", "seealso", "example.seealso") {
2441 print F "<!ENTITY $name.$f.gen SYSTEM \"$prefix$f.gen\">\n"
2442 if -f "$dir/$prefix$f.gen";
2443 }
2444
2445 for (my $count = 1; -f "$dir/example.$count.gen"; $count++) {
2446 print F "<!ENTITY $name.example.$count.gen SYSTEM \"example.$count.gen\">\n";
2447 }
2448
2449 for (my $count = 1; -f "$dir/example.$count.txt"; $count++) {
2450 print F "<!ENTITY $name.example.$count.txt SYSTEM \"example.$count.txt\">\n";
2451 }
2452
2453 close (F);
2454 }
2455
2456 sub writeEntity {
2457 my $count = shift;
2458 my $path = shift;
2459 my $basename = shift;
2460 my $fileext = shift;
2461 my $html = shift;
2462 my $name = $entities[$count];
2463 my $entity = $entities{$name};
2464 my $class = $entity_classes{$name};
2465
2466 # Hack; actually append a subset of the entity to a single file...
2467
2468 if (!defined($class)) {
2469 for (my $cnt = 0; $cnt <= $#entity_classes; $cnt++) {
2470 if ($name =~ /$entity_pats[$cnt]/) {
2471 $class = $entity_classes[$cnt];
2472 last;
2473 }
2474 }
2475 }
2476
2477 if ($class ne '') {
2478 my $bdir = $option{'base-dir'};
2479 my $edir = $config{$expanded . '-entity-dir'};
2480 my $ext = "e.gen";
2481 my $entdir = "$bdir/$edir";
2482 my $bid = $option{'base-id'};
2483 local *F;
2484
2485 if ($expanded ne 'expanded') {
2486 $ext = "u.gen";
2487 }
2488
2489 if ($class ne 'isochars') {
2490 open (F, ">>$entdir/$class.$ext");
2491 print F "<refsect2 id=\"$name.parament\">";
2492 print F "<title>%$name;</title>\n";
2493 print F $html;
2494 print F "</refsect2>\n\n";
2495 close (F);
2496 }
2497 } else {
2498 print "No class defined for entity $name\n";
2499 }
2500 }
2501
2502 sub writeNotation {
2503 my $count = shift;
2504 my $path = shift;
2505 my $basename = shift;
2506 my $fileext = shift;
2507 my $html = shift;
2508
2509 # No, we're not writing individual notation pages.
2510 # But thanks for asking.
2511 }
2512
2513 sub writeElementIndexes {
2514 my $basedir = shift;
2515 my $title = $dtd->getDocumentElement->getAttribute('title');
2516 my ($entfile, $sgmfile, $sysdir);
2517 local (*F, $_);
2518
2519 return;
2520
2521 $entfile = $basedir . "/" . $config{$expanded . "-element-index"} . ".ent";
2522 $sgmfile = $basedir . "/" . $config{$expanded . "-element-index"} . ".sgm";
2523 $sysdir = $config{$expanded . "-element-dir"};
2524
2525 open (F, ">$entfile");
2526 foreach $name (@elements) {
2527 my $basename = $ELEMBASE{$name};
2528 print F "<!ENTITY $baseid.elem.$name ";
2529 print F "SYSTEM \"$sysdir/$basename$fileext\">\n";
2530 print F "<!ENTITY $baseid.purp.elem.$name \"purpose\">\n";
2531 }
2532 close (F);
2533
2534 open (F, ">$sgmfile");
2535 print F "<reference><title>$title Element Reference</title>\n";
2536 foreach $name (@elements) {
2537 print F "&$baseid.elem.$name;\n";
2538 }
2539 print F "</reference>\n";
2540 close (F);
2541 }
2542
2543 sub writeEntityIndexes {
2544 my $basedir = shift;
2545 my $title = $dtd->getDocumentElement->getAttribute('title');
2546 my ($entfile, $sgmfile, $sysdir);
2547 local (*F, $_);
2548
2549 return;
2550
2551 $entfile = $basedir . "/" . $config{$expanded . "-entity-index"} . ".ent";
2552 $sgmfile = $basedir . "/" . $config{$expanded . "-entity-index"} . ".sgm";
2553 $sysdir = $config{$expanded . "-entity-dir"};
2554
2555 open (F, ">$entfile");
2556 foreach $name (@entities) {
2557 my $entity = $entities{$name};
2558 my $basename = $ENTBASE{$name};
2559 print F "<!ENTITY $baseid.param.$name ";
2560 print F "SYSTEM \"$sysdir/$basename$fileext\">\n";
2561 print F "<!ENTITY $baseid.purp.", $entity->getAttribute('type'), ".$name \"purpose\">\n";
2562 }
2563 close (F);
2564
2565 open (F, ">$sgmfile");
2566 print F "<reference><title>$title Entity Reference</title>\n";
2567 foreach $name (@entities) {
2568 print F "&$baseid.param.$name;\n";
2569 }
2570 print F "</reference>\n";
2571 close (F);
2572 }
2573
2574 sub writeNotationIndexes {
2575 my $basedir = shift;
2576 my $basedir = $option{'base-dir'};
2577 my $path = $basedir . "/" . $config{'notation-dir'};
2578 local (*F, $_);
2579
2580 # hack. write the notation .gen file instead of a proper index
2581
2582 $notnfile = "$path/notations.gen";
2583
2584 open (F, ">$notnfile");
2585
2586 foreach $name (sort @notations) {
2587 $notation = $notations{$name};
2588
2589 print F "<varlistentry id=\"$name.notation\">\n";
2590 print F "<term>$name</term>\n";
2591 print F "<listitem>\n";
2592
2593 print F "<para>Public id: ";
2594 if ($notation->getAttribute('public') ne '') {
2595 print F "<literal>";
2596 print F $notation->getAttribute('public');
2597 print F "</literal>\n";
2598 } else {
2599 print F "<emphasis>undefined</emphasis>\n";
2600 }
2601
2602 print F "</para>\n";
2603
2604 print F "<para>System id: ";
2605
2606 if ($notation->getAttribute('system') ne '') {
2607 print F "<literal>";
2608 print F $notation->getAttribute('system');
2609 print F "</literal>\n";
2610 } else {
2611 print F "<emphasis>undefined</emphasis>\n";
2612 }
2613
2614 print F "</para>\n";
2615
2616 print F "</listitem>\n";
2617 print F "</varlistentry>\n";
2618 }
2619 close (F);
2620 }
2621
2622 sub writeIndex {
2623 my $basedir = shift;
2624 my $title = $dtd->getDocumentElement->getAttribute('title');
2625 my $entfile = $config{"expanded-entity-index"};
2626 my $elemfile = $config{"expanded-element-index"};
2627 my $notfile = $config{"notation-index"};
2628 my $root = $dtd->getDocumentElement();
2629 my $elements = $root->getElementsByTagName('element');
2630 my $entities = $root->getElementsByTagName('entity');
2631 my $notations = $root->getElementsByTagName('notation');
2632 my $elemcount = $elements->getLength();
2633 my $entcount = $entities->getLength();
2634 my $notcount = $notations->getLength();
2635 local (*F, $_);
2636
2637 return;
2638
2639 open (F, ">" . $basedir . "/" . $config{'home'});
2640
2641 print F "<HTML>\n<HEAD>\n<TITLE>$title</TITLE>\n";
2642 print F "</HEAD>\n<BODY>\n";
2643
2644 print F "<H1>$title</h1>\n";
2645
2646 print F "[<A HREF=\"$elemfile\">Elements</A>]\n";
2647 print F "[<A HREF=\"$entfile\">Entities</A>]\n";
2648 print F "[<A HREF=\"$notfile\">Notations</A>]\n";
2649
2650 print F "<HR>\n";
2651
2652 print F "<P>";
2653 print F "The $title ";
2654 print F "DTD " if $title !~ / DTD$/i;
2655 print F "is composed of $elemcount elements, ";
2656
2657 if ($entcount == 0) {
2658 print F "no entities, ";
2659 } elsif ($entcount == 1) {
2660 print F "1 entity, ";
2661 } else {
2662 print F "$entcount entities, ";
2663 }
2664
2665 print F "and ";
2666
2667 if ($notcount == 0) {
2668 print F "no notations.\n";
2669 } elsif ($notcount == 1) {
2670 print F "1 notation.\n";
2671 } else {
2672 print F "$notcount notations.\n";
2673 }
2674
2675 my %etypes = ();
2676 for (my $count = 0; $count < $entities->getLength(); $count++) {
2677 my $ent = $entities->item($count);
2678 my $type = &entityType($ent);
2679 $etypes{$type} = 0 if !exists($etypes{$type});
2680 $etypes{$type}++;
2681 }
2682
2683 print F "<UL COMPACT>\n";
2684 print F "<LI>$elemcount elements\n";
2685 print F "<LI>$entcount ", $entcount == 1 ? "entity" : "entities\n";
2686
2687 print F "<UL COMPACT>\n";
2688 print F ("<LI>", $etypes{'param'}, " parameter ",
2689 $etypes{'param'} == 1 ? "entity" : "entities", "\n")
2690 if $etypes{'param'} > 0;
2691 print F ("<LI>", $etypes{'paramext'}, " external ",
2692 $etypes{'paramext'} == 1 ? "entity" : "entities", "\n")
2693 if $etypes{'paramext'} > 0;
2694 print F ("<LI>", $etypes{'sdata'}, " SDATA ",
2695 $etypes{'sdata'} == 1 ? "entity" : "entities", "\n")
2696 if $etypes{'sdata'} > 0;
2697 print F ("<LI>", $etypes{'charent'}, " character ",
2698 $etypes{'charent'} == 1 ? "entity" : "entities", "\n")
2699 if $etypes{'charent'} > 0;
2700 print F ("<LI>", $etypes{'msparam'}, " Marked section ",
2701 $etypes{'msparam'} == 1 ? "entity" : "entities", "\n")
2702 if $etypes{'msparam'} > 0;
2703 print F ("<LI>", $etypes{'gen'}, " general ",
2704 $etypes{'gen'} == 1 ? "entity" : "entities", "\n")
2705 if $etypes{'gen'} > 0;
2706 print F "</UL>\n";
2707
2708 print F "<LI>$notcount ", $notcount == 1 ? "notation" : "notations\n";
2709 print F "</UL>\n";
2710
2711 print F "It ";
2712 if ($root->getAttribute('public-id')) {
2713 print F "has the public identifier \"";
2714 print F $root->getAttribute('public-id');
2715 print F "\" and ";
2716 }
2717
2718 print F "claims to be an ";
2719 if ($root->getAttribute('xml')) {
2720 print F "XML";
2721 } else {
2722 print F "SGML";
2723 }
2724 print F " DTD. Element ";
2725 print F "and notation " if $notcount > 0;
2726 print F "names are ";
2727 print F "not " if $root->getAttribute('namecase-general');
2728 print F "case sensitive. Entity names are ";
2729 print F "not " if $root->getAttribute('namecase-entity');
2730 print F "case sensitive.\n";
2731 print F "</P>\n";
2732
2733 print F "<HR>\n";
2734 print F "HTML Presentation of ";
2735 print F $dtd->getDocumentElement->getAttribute('title');
2736 print F " by <A HREF=\"http://www.sf.net/projects/dtdparse/\">";
2737 print F "DTDParse</A>\n";
2738 print F "</BODY>\n";
2739 print F "</HTML>\n";
2740
2741 close (F);
2742 }
2743
2744 1;