1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095
|
#! /usr/local/bin/perl
##---------------------------------------------------------------------------##
## File:
## @(#) dtd2html 1.5 96/10/07 @(#)
## Author:
## Earl Hood ehood@medusa.acs.uci.edu
## Description:
## dtd2html is a Perl program to generate HTML documents to allow
## people to navigate thru an SGML dtd. This program requires the
## use of the "dtd" package.
##---------------------------------------------------------------------------##
## Copyright (C) 1994-1996 Earl Hood, ehood@medusa.acs.uci.edu
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
##---------------------------------------------------------------------------##
package main;
##---------------------------------------------------------------------------##
## Store name of program ##
($PROG = $0) =~ s%.*(/|\\|:)%%;
$VERSION = "1.5.1";
$HomeDesc = "-home-";
$EntsDesc = "-ents-";
$dfilecnt = 0;
%ElemDesc = (); # Element descriptions
%SharedDesc = (); # Shared element descriptions
%SharedId = (); # Tell is element description is shared
## Require libraries ##
unshift(@INC, 'lib');
require "dtd.pl" || die "Unable to require dtd.pl\n";
require "newgetopt.pl" || die "Unable to require newgetopt.pl\n";
## Import dtd variables ##
$rni = $dtd'rni;
$PCDATA = $dtd'PCDATA;
$RCDATA = $dtd'RCDATA;
$SDATA = $dtd'SDATA;
$CDATA = $dtd'CDATA;
$EMPTY = $dtd'EMPTY;
$FIXED = $dtd'FIXED;
$NOTATION = $dtd'NOTATION;
## Register tree callback to htmlize entries
&'DTDset_tree_callback("main'htmlize_tree_entry");
##---------------------------------------------------------------------------##
##------------##
## MAIN BLOCK ##
##------------##
{
&get_cli_opts();
print STDERR "Reading $MAPFILE ...\n" if $VERBOSE;
&DTDread_catalog_files($MAPFILE);
print STDERR "Finished $MAPFILE\n" if $VERBOSE;
print STDERR "Reading $DTDFILE ...\n" if $VERBOSE;
&DTDread_dtd($DTD);
print STDERR "Finished $DTDFILE\n" if $VERBOSE;
if ($UPDATEEL) { &update_elemdesc(); exit 0; }
if ($ELEMLIST) { &print_elemdescfile(); exit 0; }
if ($ENTSLIST) { &print_entsdescfile(); exit 0; }
if ($QREF) { &write_qref(); exit 0; }
if ($TREE) { &write_tree_page(); }
if (!$TREEONLY) {
&read_descfile($DESCFILE);
&write_home_page();
&write_topelem_page();
&write_allelem_page();
if ($ENTS) { &write_ents_page(); }
foreach (&DTDget_elements()) {
&write_elem_page($_);
}
}
exit 0;
}
##----------##
## END MAIN ##
##----------##
##---------------------------------------------------------------------------##
## SubRoutines ##
##---------------------------------------------------------------------------##
sub get_cli_opts {
local($tmp);
&usage() unless
&NGetOpt(
"allfile=s", # Name of all element list page
"catalog=s", # Entity map file
"contnosort", # Base content list is in order of model declaration
"descfile=s", # Element description file
"docurl=s", # URL to dtd2html HTML document
"dtdname=s", # Name of DTD
"elemlist", # Flag to generate empty element list
"ents", # Create a general entities page
"entsfile=s", # Name of general entities page
"entslist", # Flag to generate empty entity list
"homefile=s", # Name of home page
"keepold", # Keep old descriptions if -updateel specified
"level=i", # Cutoff level for tree
"modelwidth=i", # Maximum output width for <elem>.cont pages
"nodocurl", # Flag for not putting link to dtd2html docs
"noreport", # No report generated if -updateel specified
"outdir=s", # Destination directory for files
"qref", # Output quick reference
"qrefdl", # Output quick reference in a <DL>
"qrefhtag=s", # Header tag for element name in quick reference
"reportonly", # Only output report -updateel specified
"topfile=s", # Name of top element list page
"tree", # Create tree file
"treelink", # Create link to tree in HTML pages, regardless
"treefile=s", # Name of tree page
"treeonly", # Create only the tree file
"treetop=s", # Comma separated list of top elements for tree
"updateel=s", # Update an element description file
"verbose", # Flag to print out what's going on
"help" # Print usage
);
&usage() if defined($opt_help);
$ANNOTATE = (defined($opt_contnosort) ? 1 : 0);
$ENTS = (defined($opt_ents) ? 1 : 0);
$TREE = (defined($opt_tree) ? 1 : 0);
$TREELINK = (defined($opt_treelink) ? 1 : 0);
$TREEONLY = (defined($opt_treeonly) ? 1 : 0);
$TREE = 1 if $TREEONLY;
$ELEMLIST = (defined($opt_elemlist) ? 1 : 0);
$ENTSLIST = (defined($opt_entslist) ? 1 : 0);
$KEEPOLD = (defined($opt_keepold) ? 1 : 0);
$NODOCURL = (defined($opt_nodocurl) ? 1 : 0);
$NOREPORT = (defined($opt_noreport) ? 1 : 0);
$RPRTONLY = (defined($opt_reportonly) ? 1 : 0);
$QREF = (defined($opt_qref) ? 1 : 0);
$QREFDL = (defined($opt_qrefdl) ? 1 : 0);
$QREF = 1 if $QREFDL;
$VERBOSE = (defined($opt_verbose) ? 1 : 0);
&DTDset_verbosity(1) if $VERBOSE;
$ENTSFILE = $opt_entsfile || "ENTS.html";
$DTDFILE = $ARGV[0] || "";
$MAPFILE = $opt_catalog || "catalog";
$MWIDTH = $opt_modelwidth || 65;
$DESCFILE = $opt_descfile || "";
$DOCURL = $opt_docurl ||
"http://www.oac.uci.edu/indiv/ehood/dtd2html.html";
$OUTDIR = $opt_outdir || ".";
$DTDNAME = $opt_dtdname || "";
$HOMEFILE = $opt_homefile || "DTD-HOME.html";
$TOPFILE = $opt_topfile || "TOP-ELEM.html";
$ALLFILE = $opt_allfile || "ALL-ELEM.html";
$TREEFILE = $opt_treefile || "DTD-TREE.html";
$UPDATEEL = $opt_updateel || "";
$LEVEL = $opt_level || 15;
$TREETOP = $opt_treetop || "";
$QHb = $opt_qrefhtag || "H2";
$QHb =~ s/[<>]//g;
$QHb =~ tr/a-z/A-Z/;
$QHe = "</$QHb>"; $QHb = "<$QHb>";
$QREF = 1 if $opt_qrefhtag;
if ($DTDFILE) {
open(DTD_FILE, "< $DTDFILE") || die "Unable to open $DTDFILE\n";
$DTD = "main'DTD_FILE";
} else {
$DTD = 'STDIN';
}
if (! $DTDNAME) {
if ($DTDFILE) {
$DTDNAME = $DTDFILE;
$DTDNAME =~ s/.*\///; $DTDNAME =~ s/^(.*)\..*$/\1/;
} else {
$DTDNAME = 'Unknown';
}
}
$DTDNAME .= ' DTD';
$DTDFILE = 'DTD' unless $DTDFILE;
}
##---------------------------------------------------------------------------##
sub read_descfile {
local($filename) = shift;
return unless $filename;
local($handle) = ('FILE' . $dfilecnt++);
if (!open($handle, "< $filename")) {
warn "Unable to open $filename\n";
return;
}
print STDERR "Reading $filename ...\n" if $VERBOSE;
local(@elem, $txt, $tmp, $id, $action, $arg);
$txt = "";
while(<$handle>) {
next if /^\s*<!--/ || /^\s*<!>/; # Skip comments
if (s/^\s*<\?\s*DTD2HTML\s+([^>\s]+)//) {
$id = $1;
$txt = "" if $txt =~ /^\s*(<P>)?\s*$/;
foreach (@elem) {
if ($_ && !$ElemDesc{$_}) { $ElemDesc{$_} = $txt; }
}
if ($UPDATEEL) {
if ($#elem > 0) {
$tmp = join(',', @elem);
$SharedDesc{$tmp} = $txt;
foreach (@elem) {
$SharedId{$_} = $tmp;
}
} else {
$SharedId{$elem[0]} = '' if $txt;
}
}
## Determine type of action
if ($id =~ s/^#//) { # Processing directive
($arg) = /^\s*(\S+)\s*>\s*$/;
if ($id =~ /include/i) {
&read_descfile($arg);
}
@elem = ();
} else { # Description entry
@elem = split(/,/, $id);
grep(/&/ || tr/A-Z/a-z/, @elem);
}
$txt = "";
} else { # Text for a description
$txt .= $_;
}
}
foreach (@elem) {
$ElemDesc{$_} = $txt
if $_ && $txt !~ /^\s*<P>\s*$/;
}
close($handle);
print STDERR "Finished $filename\n" if $VERBOSE;
}
##---------------------------------------------------------------------------##
sub write_home_page {
open(PGFILE, "> $OUTDIR/$HOMEFILE") ||
die "Unable to create $OUTDIR/$HOMEFILE\n";
print STDERR "Writing $HOMEFILE ...\n" if $VERBOSE;
&print_head(PGFILE, $DTDNAME);
if ($ElemDesc{$HomeDesc}) {
print PGFILE "<HR>\n";
&print_elem_desc(PGFILE, $HomeDesc);
}
&print_goto_topall(PGFILE);
if (!$NODOCURL) {
print PGFILE "<HR>\n";
&print_info(PGFILE);
}
&print_end(PGFILE);
close(PGFILE);
}
##---------------------------------------------------------------------------##
sub write_tree_page {
local(@array);
open(PGFILE, "> $OUTDIR/$TREEFILE") ||
die "Unable to create $OUTDIR/$TREEFILE\n";
print STDERR "Writing $TREEFILE ...\n" if $VERBOSE;
&print_head(PGFILE, "$DTDNAME: Top element tree(s)",
"$DTDNAME: <BR>Top element tree(s)");
if ($TREETOP) {
@array = split(/,/, $TREETOP);
} else {
@array = &DTDget_top_elements();
}
if ($#array > 0) {
print PGFILE "<HR>\n",
"<UL>\n";
foreach (@array) {
tr/a-z/A-Z/;
print PGFILE qq|<LI><A HREF="#$_">$_</A></LI>\n|;
}
print PGFILE "</UL>\n";
}
foreach (@array) {
tr/a-z/A-Z/;
print PGFILE "<HR>\n",
"<H2><A NAME=\"$_\">$_</A></H2>\n",
"<HR>\n",
"<PRE>\n";
&DTDprint_tree($_, $LEVEL, "main'PGFILE");
print PGFILE "</PRE>\n";
}
&print_goto_topall(PGFILE);
&print_end(PGFILE);
close(PGFILE);
}
##---------------------------------------------------------------------------##
sub write_topelem_page {
local(@array);
open(PGFILE, "> $OUTDIR/$TOPFILE") ||
die "Unable to create $OUTDIR/$TOPFILE\n";
print STDERR "Writing $TOPFILE ...\n" if $VERBOSE;
&print_head(PGFILE, "$DTDNAME: Top elements",
"Top elements in $DTDNAME");
@array = ($TREETOP ? split(/,/, $TREETOP) : &DTDget_top_elements());
&print_elem_list(PGFILE, *array);
&print_goto_topall(PGFILE);
&print_end(PGFILE);
close(PGFILE);
}
##---------------------------------------------------------------------------##
sub write_allelem_page {
local(@array);
open(PGFILE, "> $OUTDIR/$ALLFILE") ||
die "Unable to create $OUTDIR/$ALLFILE\n";
print STDERR "Writing $ALLFILE ...\n" if $VERBOSE;
&print_head(PGFILE, "$DTDNAME: All elements",
"All elements in $DTDNAME");
@array = &DTDget_elements();
&print_elem_list(PGFILE, *array);
&print_goto_topall(PGFILE);
&print_end(PGFILE);
close(PGFILE);
}
##---------------------------------------------------------------------------##
sub write_ents_page {
local($tmp) = ("$OUTDIR/$ENTSFILE");
open(PGFILE, "> $tmp") || die "Unable to create $tmp\n";
print STDERR "Writing $ENTSFILE ...\n" if $VERBOSE;
&print_head(PGFILE, "$DTDNAME: General Entities",
"General Entities in $DTDNAME");
if ($ElemDesc{$EntsDesc}) {
print PGFILE "<HR>\n";
&print_elem_desc(PGFILE, $EntsDesc);
}
@array = &DTDget_gen_data_ents();
&print_ent_list(PGFILE, *array);
&print_goto_topall(PGFILE);
&print_end(PGFILE);
close(PGFILE);
}
##---------------------------------------------------------------------------##
sub write_elem_page {
local($elem) = shift @_;
local($Elem) = $elem;
local(@array);
open(FILE, "> $OUTDIR/$elem.html") ||
die "Unable to create $OUTDIR/$elem.html\n";
print STDERR "Writing $elem.html ...\n" if $VERBOSE;
$Elem =~ tr/a-z/A-Z/;
&print_head(FILE, "$DTDNAME: $Elem element", $Elem);
&print_elem_desc(FILE, $elem);
print FILE "<HR>\n";
## Content ##
print FILE "<H2>Content</H2>\n";
if ($ANNOTATE) {
@array = &DTDget_base_children($elem, 1);
&print_elem_list(FILE, *array, 1);
} else {
@array = sort &DTDget_base_children($elem);
&remove_dups(*array);
&print_elem_list(FILE, *array);
}
## Inclusions ##
@array = sort &DTDget_inc_children($elem);
if ($#array >= 0) {
print FILE "<H3>Inclusions</H3>\n";
&remove_dups(*array);
&print_elem_list(FILE, *array);
}
## Exclusions ##
@array = sort &DTDget_exc_children($elem);
if ($#array >= 0) {
print FILE "<H3>Exclusions</H3>\n";
&remove_dups(*array);
&print_elem_list(FILE, *array);
}
print FILE "<HR>\n";
## Attribute and content model links ##
print FILE "<P>\n";
if (&write_elem_attr($elem)) {
print FILE "<A HREF=\"$elem.attr.html\">",
"<STRONG>ATTRIBUTES</STRONG></A><BR>\n";
} else {
print FILE "<STRONG>No</STRONG> ATTRIBUTES<BR>\n";
}
if (&write_elem_syntax($elem)) {
print FILE "<A HREF=\"$elem.cont.html\">",
"<STRONG>CONTENT DECLARATION</STRONG></A>\n";
} else {
print FILE "<STRONG>Empty</STRONG> CONTENT DECLARATION\n";
}
print FILE "</P>\n";
## Tag Minimization ##
@array = split(' ', $dtd'ElemTag{$elem});
if ($#array > 0) {
print FILE "<DL>\n";
print FILE "<DT><STRONG>Tag Minimization</STRONG><DD>\n";
print FILE "Open Tag: ";
if ($array[0] eq '-') {
print FILE "<EM>REQUIRED</EM><BR>\n";
} else {
print FILE "<EM>OPTIONAL</EM><BR>\n";
}
print FILE "Close Tag: ";
if ($array[1] eq '-') {
print FILE "<EM>REQUIRED</EM><BR>\n";
} else {
print FILE "<EM>OPTIONAL</EM><BR>\n";
}
print FILE "</DL>\n";
}
print FILE "<HR>\n";
&print_parent_list(FILE, $elem);
&print_goto_topall(FILE, $elem);
&print_end(FILE);
close(FILE);
}
##---------------------------------------------------------------------------##
sub write_elem_attr {
local($elem) = shift @_;
local($Elem) = $elem;
local(%attr, @array, @vals, $def, $tmp);
%attr = &DTDget_elem_attr($elem);
@array = sort keys %attr;
return 0 if ($#array < 0);
open(ATTRFILE, "> $OUTDIR/$elem.attr.html") ||
die "Unable to create $OUTDIR/$elem.attr.html\n";
print STDERR "Writing $elem.attr.html ...\n" if $VERBOSE;
$Elem =~ tr/a-z/A-Z/;
&print_head(ATTRFILE, "$Elem: Attributes", "$Elem: <BR>Attributes");
&print_attr_desc(ATTRFILE, $elem);
print ATTRFILE "\n";
foreach (@array) {
($tmp = $_) =~ tr/a-z/A-Z/;
print ATTRFILE qq|<HR><H2><A NAME="$_">$tmp</A></H2>\n|;
&print_attr_sp_desc(ATTRFILE, $elem, $_);
print ATTRFILE "<H3>Value(s)</H3>\n";
@vals = split(/$;/o, $attr{$_});
$def = shift @vals;
$def .= ' = ' . shift @vals if ($def =~ /^\s*$rni$FIXED\s*$/o);
if ($#vals > 0) {
if ($vals[0] eq $NOTATION) {
print ATTRFILE "<CODE>", shift(@vals), "</CODE><BR>", "\n"; }
&print_attr_list(ATTRFILE, *vals);
} else {
if (&DTDis_attr_keyword($vals[0])) {
$vals[0] =~ tr/a-z/A-Z/;
$vals[0] = "<CODE>".$vals[0]."</CODE>";
}
print ATTRFILE $vals[0], "\n";
}
print ATTRFILE "<H3>Default Value</H3>\n",
"<STRONG>", &htmlize($def), "</STRONG>\n";
}
print ATTRFILE "<HR>\n",
"Back to <A HREF=\"$elem.html\">",
"<STRONG>$Elem</STRONG></A><P>\n";
&print_end(ATTRFILE);
close(ATTRFILE);
1;
}
##---------------------------------------------------------------------------##
sub write_elem_syntax {
local($elem) = shift @_;
local($Elem) = $elem;
return 0 if $dtd'ElemCont{$elem} =~ /^\s*$EMPTY\s*$/oi;
open(SYNFILE, "> $OUTDIR/$elem.cont.html") ||
die "Unable to create $OUTDIR/$elem.cont.html\n";
print STDERR "Writing $elem.cont.html ...\n" if $VERBOSE;
$Elem =~ tr/a-z/A-Z/;
&print_head(SYNFILE, "$Elem: Content Model Declaration",
"$Elem: <BR>Content Model Declaration");
## Content Rule ##
print SYNFILE "<HR><H2>Content Rule</H2>\n";
@array = &DTDget_base_children($elem, 1);
&print_elem_content(SYNFILE, *array);
## Inclusions ##
if ($dtd'ElemInc{$elem}) {
print SYNFILE "<H3>Inclusions</H3>\n";
@array = &DTDget_inc_children($elem, 1);
&print_elem_content(SYNFILE, *array);
}
## Exclusions ##
if ($dtd'ElemExc{$elem}) {
print SYNFILE "<H3>Exclusions</H3>\n";
@array = &DTDget_exc_children($elem, 1);
&print_elem_content(SYNFILE, *array);
}
print SYNFILE "<HR>\n",
"Back to <A HREF=\"$elem.html\">",
"<STRONG>$Elem</STRONG></A><P>\n";
&print_end(SYNFILE);
close(SYNFILE);
1;
}
##---------------------------------------------------------------------------##
sub print_elem_content {
local($handle, *array) = @_;
local($prev, $open, $len, $tmp) = ('',0,0,0);
print $handle "<PRE>";
foreach (@array) {
next if $_ eq ""; # Ignore NULL strings
if ($_ eq $dtd'grpo_) { # '('
if ($prev eq $_) { # Print consecutive ('s together
print $handle &htmlize($_);
} else { # Else, start newline
print $handle "\n", ' ' x $open, $_;
}
$open++; # Increase group open counter
$len = $open+1; # Adjust length of line counter
next; # Goto next token
} elsif ($_ eq $dtd'grpc_) {
$open--; # ')', decrement group open counter
}
$tmp = $len + length($_);
if ($tmp > $MWIDTH) { # Check if line goes past $MWIDTH chars
if (&DTDis_occur_indicator($_) || &DTDis_group_connector($_)) {
print $handle &htmlize($_), "\n", ' ' x ($open);
$len = $open;
next;
} else {
print $handle "\n", ' ' x $open;
$len = $open + length($_);
}
} else {
$len = $tmp;
}
if ($_ eq $dtd'and_) { # Put spaces around '&'.
print $handle ' ', &htmlize($_), ' ';
$len += 2;
if ($len > 70) {
print $handle "\n", ' ' x $open;
$len = $open;
}
} elsif (!&DTDis_element($_)) { # Uppercase reserved words, OR
# bogus elements
tr/a-z/A-Z/;
print $handle &htmlize($_);
} elsif (&DTDis_tag_name($_)) { # Create anchors for element names
print $handle qq|<A HREF="$_.html">$_</A>|;
} else {
print $handle &htmlize($_);
}
} continue {
$prev = $_ unless /^\s*$/;
}
print $handle "</PRE>\n";
}
##---------------------------------------------------------------------------##
sub print_elem_desc {
local($handle, $elem) = @_;
$elem =~ tr/A-Z/a-z/;
if ($elem && $ElemDesc{$elem}) {
print $handle $ElemDesc{$elem};
}
}
##---------------------------------------------------------------------------##
sub print_attr_desc {
local($handle, $elem) = @_;
local($attr);
$elem =~ tr/A-Z/a-z/;
$attr = $elem . '*';
if ($elem && $ElemDesc{$attr}) {
print $handle $ElemDesc{$attr};
}
}
##---------------------------------------------------------------------------##
sub print_attr_sp_desc {
local($handle, $elem, $attr) = @_;
$elem =~ tr/A-Z/a-z/;
$attr =~ tr/A-Z/a-z/;
if ($elem) {
if ($ElemDesc{"$elem*$attr"}) { # Check for local description
print $handle $ElemDesc{"$elem*$attr"};
} elsif ($ElemDesc{"\*$attr"}) { # Check for global description
print $handle $ElemDesc{"\*$attr"};
}
}
}
##---------------------------------------------------------------------------##
sub print_goto_topall {
local($old) = select(shift);
local($elem) = shift;
local($tmp);
print <<End;
<HR>
<P>
<A HREF="$TOPFILE"><STRONG>Top Elements</STRONG></A>
<BR>
<A HREF="$ALLFILE"><STRONG>All Elements</STRONG></A>
<BR>
End
## Link to entities page
print qq|<A HREF="$ENTSFILE"><STRONG>General Entities</STRONG></A><BR>\n|
if $ENTS;
## Link to tree page
$tmp = $TREEFILE . ($elem ? "#$elem" : '');
print qq|<A HREF="$tmp"><STRONG>Tree</STRONG></A>\n|
if $TREE || $TREELINK;
print "</P>\n";
select($old);
}
##---------------------------------------------------------------------------##
sub print_attr_list {
local($handle, *array) = @_;
print $handle "<UL COMPACT>\n";
foreach (@array) {
if (&DTDis_attr_keyword($_)) { tr/a-z/A-Z/; }
print $handle "<LI>", &htmlize($_), "</LI>\n";
}
print $handle "</UL>\n";
}
##---------------------------------------------------------------------------##
sub print_ent_list {
local($handle, *array) = @_;
print $handle "<UL>\n";
foreach (@array) {
next if /^\s*$/;
print $handle qq|<LI><STRONG>$_</STRONG>|;
print $handle qq| -- $ElemDesc{"$_&"}| if $ElemDesc{"$_&"};
print $handle qq|</LI>\n|;
}
print $handle "</UL>\n";
}
##---------------------------------------------------------------------------##
sub print_elem_list {
local($handle, *array, $hascons) = @_;
if ($hascons) { # Connectors in list
local($ep, $iselem) = ('', 0);
print $handle "<UL>\n";
print $handle "<LI>";
foreach (@array) {
next if /^\s*$/;
if (/$dtd'grpo/o) {
if ($ep) {
print $handle qq| -- $ElemDesc{"$ep+"}|
if $iselem && $ElemDesc{"$ep+"};
print $handle "</LI>\n<LI>";
$ep = '';
}
print $handle &htmlize($_);
} elsif (&DTDis_occur_indicator($_) ||
&DTDis_group_connector($_) ||
/$dtd'grpc/o ) {
print $handle &htmlize($_);
} else {
if ($ep) {
print $handle qq| -- $ElemDesc{"$ep+"}|
if $iselem && $ElemDesc{"$ep+"};
print $handle "</LI>\n<LI>";
}
if (!&DTDis_element($_)) {
tr/a-z/A-Z/;
print $handle &htmlize($_);
$iselem = 0;
} else {
print $handle qq|<A HREF="$_.html">|,
qq|<STRONG>$_</STRONG></A>|;
$iselem = 1;
}
$ep = $_;
}
}
print $handle qq| -- $ElemDesc{"$ep+"}|
if $iselem && $ElemDesc{"$ep+"};
print $handle "</LI>\n</UL>\n"
} else { # Just the elements in list
print $handle "<UL>\n";
foreach (@array) {
next if /^\s*$/;
if (!&DTDis_element($_)) {
tr/a-z/A-Z/;
print $handle "<LI>", &htmlize($_), "</LI>\n";
} else {
print $handle qq|<LI><A HREF="$_.html">|,
qq|<STRONG>$_</STRONG></A>|;
print $handle qq| -- $ElemDesc{"$_+"}|
if $ElemDesc{"$_+"};
print $handle qq|</LI>\n|;
}
}
print $handle "</UL>\n";
}
}
##---------------------------------------------------------------------------##
sub print_head {
local($handle, $title, $head) = @_;
local($old) = select($handle);
$head = $title unless $head;
print <<End;
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<HTML>
<HEAD>
<TITLE>$title</TITLE>
</HEAD>
<BODY>
<H1>$head</H1>
End
select($old);
}
##---------------------------------------------------------------------------##
sub print_end {
local($old) = select(shift);
print <<End;
<HR>
<ADDRESS>
<A HREF="$HOMEFILE">$DTDNAME</A>
</ADDRESS>
</BODY>
</HTML>
End
select($old);
}
##---------------------------------------------------------------------------##
sub print_info {
local($old) = select(shift);
print <<End;
<ADDRESS>
Document generated by
<A HREF="$DOCURL"><CODE>dtd2html</CODE></A> $VERSION.
</ADDRESS>
End
select($old);
}
##---------------------------------------------------------------------------##
sub remove_dups {
local(*array) = shift;
local(%dup) = ();
@array = grep($dup{$_}++ < 1, @array);
}
##---------------------------------------------------------------------------##
sub print_entsdescfile {
local($str);
@ids = sort &DTDget_gen_data_ents();
select(STDOUT); $^ = Empty; $~ = CenterCom; $= = 1000000;
$str = "General Entity Descriptions"; write;
foreach (@ids) {
print STDOUT "<?DTD2HTML $_& >\n";
}
}
##---------------------------------------------------------------------------##
sub print_elemdescfile {
local($f, *others) = @_;
local(%attribute, @array, @ids, $elem, $attr, $str);
@ids = sort (&DTDget_elements(), keys %others);
## Output Home Page description ##
select(STDOUT); $^ = Empty; $~ = CenterCom; $= = 1000000;
$str = "Home Page Description"; write;
print STDOUT "<?DTD2HTML $HomeDesc >\n";
if ($f && $ElemDesc{$HomeDesc}) { print STDOUT $ElemDesc{$HomeDesc}; }
## Output any shared descriptions ##
@array = sort keys %SharedDesc;
if ($#array >= 0) {
$str = "Shared Descriptions"; write;
foreach $elem (sort keys %SharedDesc) {
print STDOUT "<?DTD2HTML $elem >\n";
if ($f && $SharedDesc{$elem}) { print STDOUT $SharedDesc{$elem}; }
}
}
## Output brief descriptions ##
$str = "Short Descriptions"; write;
foreach $elem (@ids) {
next if $elem =~ /\*/ || $elem =~ /\+/;
print STDOUT "<?DTD2HTML $elem+ >\n";
if ($f && $ElemDesc{"$elem+"}) { print STDOUT $ElemDesc{"$elem+"}; }
}
## Output descriptions ##
$str = "Descriptions"; write;
foreach $elem (@ids) {
next if $elem =~ /\+/;
print STDOUT "<?DTD2HTML $elem >\n";
if ($f && $ElemDesc{$elem} && !$SharedId{$elem}) {
print STDOUT $ElemDesc{$elem};
}
%attribute = &DTDget_elem_attr($elem);
@array = sort keys %attribute;
if ($#array >= 0) {
print STDOUT "<?DTD2HTML $elem* >\n";
if ($f && $ElemDesc{"$elem*"}) {
print STDOUT $ElemDesc{"$elem*"}; }
foreach $attr (@array) {
print STDOUT "<?DTD2HTML $elem*$attr >\n";
if ($f && $ElemDesc{"$elem*$attr"}) {
print STDOUT $ElemDesc{"$elem*$attr"}; }
}
}
%attribute = ();
}
}
##---------------------------------------------------------------------------##
sub update_elemdesc {
local(@array, $elem, $attr, %attribute, %new, $str);
local(%old);
## Read element description file ##
&read_descfile($UPDATEEL);
foreach (grep(/&/, keys %ElemDesc)) { delete $ElemDesc{$_}; }
%old = %ElemDesc;
## Check for Home Page description ##
if (!defined($ElemDesc{$HomeDesc})) { $new{$HomeDesc} = 1; }
else { delete $old{$HomeDesc}; }
## Check for new elements and old descriptions ##
foreach $elem (&DTDget_elements()) {
## Check elements
if (!defined($ElemDesc{$elem})) { $new{$elem} = 1; }
else { delete $old{$elem}; }
delete $old{"$elem+"};
## Check attributes
%attribute = &DTDget_elem_attr($elem);
@array = keys %attribute;
if ($#array >= 0) {
if (!defined($ElemDesc{"$elem*"})) { $new{"$elem*"} = 1; }
else { delete $old{"$elem*"}; }
foreach $attr (@array) {
if (!defined($ElemDesc{"$elem*$attr"})) {
$new{"$elem*$attr"} = 1; }
else { delete $old{"$elem*$attr"}; }
}
}
%attribute = ();
}
## Output status report of updating element description file ##
if (!$NOREPORT) {
local($delold, $date) = (($KEEPOLD ? "No" : "Yes"), `date`);
select(STDOUT); $^ = ReportTop; $= = 1000000;
@array = sort keys %new;
if ($#array >= 0) {
$~ = ReportLine;
$str = "New identifiers:"; write;
$~ = ReportIds;
$str = join(', ', @array); while ($str) { write; }
# foreach (@array) { $str = " $_"; write; }
}
@array = grep(!/^\*/, sort keys %old); # Ignore global attr ids
if ($#array >= 0) {
$~ = ReportLine;
$str = "Old identifiers:"; write;
$~ = ReportIds;
$str = join(', ', @array); while ($str) { write; }
# foreach (@array) { $str = " $_"; write; }
}
$~ = ReportLine;
$str = ""; write;
}
## Output descriptions ##
if (!$RPRTONLY) {
grep(!/^\*/ && delete $old{$_}, keys %old) unless $KEEPOLD;
&print_elemdescfile(1, *old);
}
}
##---------------------------------------------------------------------------##
sub print_parent_list {
local($handle, $elem) = @_;
local(@array);
print $handle "<H2>Parent Elements</H2>\n";
@array = &DTDget_parents($elem);
if ($#array >= 0) {
&remove_dups(*array);
print $handle "<UL COMPACT>\n";
foreach (@array) {
tr/A-Z/a-z/;
print $handle qq|<LI><A HREF="$_.html">|,
qq|<STRONG>$_</STRONG></A>|;
print $handle qq| -- $ElemDesc{"$_+"}|
if $ElemDesc{"$_+"};
print $handle qq|</LI>\n|;
}
print $handle "</UL>\n";
} else {
print $handle "<P>None</P>\n";
}
}
##---------------------------------------------------------------------------##
sub write_qref {
local($elem);
&read_descfile($DESCFILE);
&print_head(STDOUT, "$DTDNAME Quick Reference");
if ($ElemDesc{$HomeDesc}) { print STDOUT $ElemDesc{$HomeDesc}; }
print STDOUT "<HR>\n";
print STDOUT "<DL>\n" if $QREFDL;
foreach $elem (&DTDget_elements()) {
if ($QREFDL) { print STDOUT "<DT>"; }
else { print STDOUT $QHb; }
print STDOUT qq|<A NAME="$elem"><$elem></A>|;
if ($QREFDL) { print STDOUT "\n<DD>"; }
else { print STDOUT $QHe; }
print STDOUT "\n", $ElemDesc{$elem}, "\n";
}
print STDOUT "</DL>\n" if $QREFDL;
&print_end(STDOUT);
}
##---------------------------------------------------------------------------##
sub htmlize_tree_entry {
local($iselem, $str) = @_;
if ($iselem) {
if (($str =~ /\.\.\./) || ($str =~ /\{-\}/)) {
$str =~ s%([0-9a-zA-Z\.\-]+)%&anchor_tree_entry(1,$1)%oe;
} else {
$str =~ s%([0-9a-zA-Z\.\-]+)%&anchor_tree_entry(0,$1)%oe
}
}
$str;
}
##---------------------------------------------------------------------------##
sub anchor_tree_entry {
local($rel, $elem) = @_;
local($ret) = ($elem);
if (&'DTDis_element($elem)) {
if ($rel) {
$ret = qq%<A HREF="#$elem">$elem</A>%;
} else {
$ret = qq%<A NAME="$elem" HREF="${elem}.html">% .
qq%<STRONG>$elem</STRONG></A>%;
}
}
$ret;
}
##---------------------------------------------------------------------------##
sub htmlize {
local($string) = shift;
$string =~ s/\&/\&/g;
$string =~ s/</\</g;
$string =~ s/>/\>/g;
$string;
}
##---------------------------------------------------------------------------##
sub usage {
print STDOUT <<EndOfUsage;
Usage: $PROG [<options>] file
Options:
-allfile <filename> : Filename for All Elements page.
(def: ALL-ELEM.html)
-catalog <filename> : Catalog file for mapping public identifiers and
entities to system files.
(def: catalog)
-contnosort : Base content list is in order of model declaration.
-descfile <filename> : Element description file.
-docurl <URL> : URL to dtd2html HTML document.
(def: http://www.oac.uci.edu/indiv/ehood/dtd2html.html)
-dtdname <string> : String name of DTD for HTML output; " DTD" is
appended to <string>.
-elemlist : Generate empty element description file.
-ents : Create a general entities page.
-entsfile <filename> : Filename of general entities page.
-entslist : Generate empty entity list for use in a description
file.
-help : This usage message.
-homefile <filename> : Filename for Home page.
(def: DTD-HOME.html)
-keepold : Keep old descriptions if -updateel specified.
-level <#> : Cutoff level for tree.
(def: 15)
-modelwidth <#> : Maximum output width for content model declarations.
(def: 65)
-nodocurl : Do not put link to $PROG doc on home page.
-noreport : No report generated if -updateel specified.
-outdir <path> : Destination directory for HTML files.
(def: ./)
-qref : Output quick reference.
-qrefdl : Output quick reference in a <DL>, implies -qref.
-qrefhtag <string> : Header tag for element name in qref.
(def: H2)
-reportonly : Only output report if -updateel specified.
-topfile <filename> : Filename for Top Elements page.
(def: TOP-ELEM.html)
-tree : Create tree file.
-treelink : Create link to tree in HTML pages, regardless.
-treefile <filename> : Filename of Tree page.
(def: DTD-TREE.html)
-treeonly : Just output the Tree page; implies -tree.
-treetop <string> : Comma separated list of top elements for tree;
overrides computed top elements.
-updateel <filename> : Update an element description file; update
sent to stdout (NOTE: entities are not computed).
-verbose : Print out what's going on (generates much output);
mainly used for debugging purposes.
Version: $VERSION
dtd.pl Version: $dtd'VERSION
Copyright (C) 1994-1996 Earl Hood, ehood\@medusa.acs.uci.edu
dtd2html comes with ABSOLUTELY NO WARRANTY and dtd2html may be copied only
under the terms of the GNU General Public License (version 2, or later),
which may be found in the distribution.
EndOfUsage
exit 0;
}
##---------------------------------------------------------------------------##
## Formats
##
format ReportTop=
<!-- Element Description File Update -->
<!-- Source File: @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< -->
$UPDATEEL
<!-- Source DTD: @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< -->
$DTDFILE
<!-- Deleting Old? @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< -->
$delold
<!-- Date: @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< -->
$date
.
format ReportLine=
<!-- @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< -->
$str
.
format ReportIds=
<!-- ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< -->
$str
.
format CenterCom=
<!-- #################################################################### -->
<!-- ## @||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ## -->
$str
<!-- #################################################################### -->
.
format Empty=
.
|