2 # (if your perl5 lives in different path, plese edit the line above.)
4 # sgml21html - convert SGML into one HTML (using sgml2html)
6 # Copyright (C) 1999 Sadaaki Kato <skato@venus.dti.ne.jp>
7 # Taketoshi Sano <kgh12351@nifty.ne.jp>
10 # This is free software with ABSOLUTELY NO WARRANTY.
12 # You can redistribute it and/or modify it under the terms of
13 # the GNU General Public License version 2.
15 # $Date: 2000/05/07 15:22:35 $
17 # usage: sgml21html file[.sgml]
18 # Please read the Notes at the end of this script
24 # Definition for Commands - Please edit to match your system
25 my $S2H = "sgml2html"; # used to convert SGML -> HTML initially
27 my @optS2H = (); # for jLinuxdoc-SGML (linuxdoc-sgml-ja) 1.5.1
28 # my @optS2H = ("-l", "ja", "-c", "nippon"); # for sgml-tools-ja 1.0.9
30 my $NKF = "nkf -j"; # used to convert JP code to jis
31 # my $NKF = "kcc -j"; # if you don't have nkf but have kcc, use this line.
33 my $DATE = "date"; # used to get date output
36 my $TMPF ="./sgml21html$$.tmp.html"; # temporary file name
38 # $HED defines the header form.
39 # 'SGML_TITLE' will be replaced by the title strings.
41 my $DEFAULT_HEAD = <<END_OF_HEADER;
44 <META http-equiv="Content-Type" content="text/html; charset=ISO-2022-JP">
52 # $FOT defines the footer form.
53 # 'TODAY' will be replaced by the $DATE output.
55 my $DEFAULT_FOOT = <<END_OF_FOOTER;
57 sgml21html conversion date: TODAY
75 if (!defined $ARGV[0]) {
76 print "usage: sgml21html SGML_file[.sgml]\n";
80 if ($ARGV[0] eq "--JFindex") {
81 $DEFAULT_HEAD .= "<A HREF=\"INDEX-JF.html\">JF-INDEX (document list of JF Project)</A>";
85 # check sgml-tools or jLinuxdoc-SGML(linuxdoc-sgml-ja)
86 $s2hvers = chkvers($S2H);
88 # for sgml-tools-ja 1.0.9
89 @optS2H = ("-l", "ja", "-c", "nippon");
92 while (defined $ARGV[0]) {
94 # initialize / reset header & footer
95 my $HED=$DEFAULT_HEAD;
96 my $FOT=$DEFAULT_FOOT;
98 # get argument (SGML filename)
104 print "NAME: " . $name . "\n";
106 # use sgml2html on given filename
107 if(($ret = useS2H($sgml,$name)) != 0) {
108 print "Can not exec sgml2html\n";
112 # get list of html files
113 @htmls = gethtmls($name);
114 if ( !defined $htmls[0] ) {
115 print "Can not read html files\n";
120 if(($title = extitle($sgml)) eq "") {
121 print "Can not extract <title>\n";
125 # make and printout the header
126 my $fh = new IO::File "|$NKF > $TMPF";
127 $HED =~ s/SGML_TITLE/$title/;
131 print "Can not write temporary file\n";
136 foreach $html (@htmls) {
137 @stack = maketxt($html, $name);
138 if( defined $stack[0] ) {
139 foreach $line (@stack) {
143 print "Can not make text. aborted\n";
152 $date = getdate($DATE);
153 $FOT =~ s/TODAY/$date/;
156 # close temporary file
159 # remove htmlfiles from sgml2html
162 # mv temporary file to target html file
163 $html = $name . ".html";
176 my ($sgml,$name) = @_;
177 my $check = $sgml . ".sgml";
178 if( ( -r $name ) || ( -r $sgml ) || -r "$check" ) {
179 my @args = ("$S2H", @optS2H, "$sgml");
180 if(system(@args) != 0) {
181 print "system @args failed: $?\n";
185 print "Invalid File specified\n";
197 my $fh = new IO::File;
202 if ( /<title>(.*)$/ ) {
208 print "Can not read : " . $sgml . "\n";
215 # get the list of html files
222 my $html = $name . $type;
224 while( -r "$html" ) {
227 $html = $name . "-" . $i . $type;
233 # cutt headers and footers, and modify toc.
235 my ($html, $name) = @_;
240 my $fh = new IO::File;
245 if ( ! -r "$html" ) {
246 print "Can not read $html\n";
259 # push text into stack
267 for ($i=0;$i<6;$i++) {
275 foreach $line (@temp) {
277 s/<A HREF=\"$pname-(\d+)\.html\"/<A HREF=\"\#s$1\"/;
278 s/<A HREF=\"$pname-\d+\.html(\#.*)\"/<A HREF=\"$1\"/;
279 s/<A NAME=\"s(\d+)\">(\d+\.)\s(.*)<\/A/<A NAME=\"s$1\">$2<\/A> <A HREF=\"#toc$1\">$3<\/A/;
290 my $fh = new IO::File;
292 $fh->open("$datecmd |");
306 my $fh = new IO::File;
308 $fh->open("$s2hcmd |");
311 if(/^SGML-Tools version 1.0.9$/) {
322 # $Log: sgml21html,v $
323 # Revision 1.17 2000/05/07 15:22:35 takes
324 # guidance-sgml.m4: update some description
325 # archives/sgml21html: add "--JFindex" option.
327 # Revision 1.16 2000/02/23 01:27:33 morimoto
329 # Wed Feb 23 10:26:22 2000 Jun Morimoto <morimoto@xantia.citroen.org>
331 # * workshop/archives/sgml21html: À¸À®¤µ¤ì¤ë [Back] ¤Î¥ê¥ó¥¯Àè¤ò
332 # INDEX-JF.html ¤ËÊѹ¹
334 # Revision 1.15 2000/01/11 15:20:04 takes
335 # more modification to escape "+" in filename
337 # Revision 1.14 1999/12/05 03:28:02 sano
338 # modify "sub maketext($$)" to handle label/ref correctly
340 # Revision 1.13 1999/09/07 04:23:45 sano
341 # add "charset=ISO-2022-JP" as a META tag in default header
343 # Revision 1.12 1999/08/19 07:00:49 sano
344 # use "$name" variable to distinguish toc related & others
346 # Revision 1.11 1999/06/27 15:22:34 sano
347 # added one line to correct the <rabel> <ref id> tag handling
348 # (thanks to fukushima-san, and hayakawa-san)
350 # Revision 1.10 1999/05/24 04:31:38 sano
351 # update the bottomline Notation
353 # Revision 1.9 1999/05/24 04:27:49 sano
354 # add version check rutine "chkvers" to make enable using
355 # with ether jLinuxdoc-SGML (linuxdoc-sgml-ja) 1.5.1 or
356 # sgml-tools-ja 1.0.9
358 # Revision 1.8 1999/05/24 03:49:27 sano
359 # add comments for use with jLinuxdoc-SGML 1.5.1,
362 # Revision 1.7 1999/05/24 01:21:02 sano
363 # update to be usable with sgml-tools-ja 1.0.9, and
364 # fix bug in extitle (add return to avoid the repeating match)
366 # Revision 1.6 1999/04/30 12:54:02 sano
367 # change <toc> modify code to handle the name including "-"
369 # Revision 1.5 1999/03/20 18:43:06 sano
370 # add comments, and header and footer initialization
372 # v1.4 - remove absolute path for commands,
373 # v1.4 - and replace die to return -1 in useS2H
375 # v1.3 - add and modify error recovery in main loop
377 # v1.2 - Fix main loop bug.
379 # v1.1 - Initial Version. announce to JF ML
384 # - sgml-tools 1.0.9 or jLinuxdoc-SGML (linuxdoc-sgml-ja) 1.5.1
385 # if you get trouble with automatic version checking,
386 # use the fixed @optS2H line and comment out
387 # the call for chkvers($S2H).
389 # - perl 5.004 (or later) as "/usr/bin/perl",
390 # if you don't have it at that place,
391 # please change the first line to point the perl 5.004.
393 # - nkf (of kcc with the modification of this script)
394 # if you use kcc, use commented out $NKF line.
396 # - date (this is standard command, so you should have it)