#!/usr/bin/perl # # ldp_mk - create all various output forms needed for the LDP from SGML file # # gferg@sgi.com / Ferg # # LOG: # 02Aug2000 - added cmd-line options and index creation (gferg) # if($ARGV[0] eq '') { &usage(); exit(0); } my($_toolroot) = $ENV{'SGML_TOOLROOT'} || '/export/sunsite/users/gferg/toolroot'; my($_jade) = 'jade-1.2.1'; my($linuxdoc) = 1; my($create_index) = 1; my($cmd, $fname, $fname_wo_ext, $txt_filter, $style, $s, $db_v) = ''; while(1) { if ($ARGV[0] eq "-style") { shift(@ARGV); $style = ($ARGV[0] + 0); shift(@ARGV); } elsif ($ARGV[0] eq "-txt") { shift(@ARGV); $txt_filter = $ARGV[0]; shift(@ARGV); } elsif ($ARGV[0] eq "-no_index") { shift(@ARGV); $create_index = 0; } else { last; } } $fname = $ARGV[(@ARGV + 0) - 1]; $fname_wo_ext = $fname; if( $fname =~ /\.sgml$/ ) { $fname_wo_ext =~ s/\.[\w]+$//; } else { $fname .= "\.sgml"; } if( !(-e "$fname") ) { print "\nldp_mk: ERROR - cannot find/read $fname\n"; &usage(); exit(0); } if( $txt_filter eq '' ) { $txt_filter = 'lynx'; } # determine DTD # open(FP_IN, "head $fname | grep -i '\!doctype' |") || die "\nldp_mk: ERROR - cannot determine DTD for $fname\n"; $s = ; close(FP_IN); if( $s eq '' ) { die "\nldp_mk: cannot determine DTD for $fname\n"; } if( $s =~ /linuxdoc/i ) { $linuxdoc = 1; print "\nldp_mk: $fname is LinuxDoc SGML\n"; } else { # determine docbook version # ($db_v) = ($s =~ /\s+V(\d)\./i); # do not override any various SGML catalog file settings # if( $ENV{'SGML_CATALOG_FILES'} eq '' ) { $s = ($db_v =~ /3/ ? "$_toolroot/dtd/docbook_31/catalog:" : "$_toolroot/dtd/docbook_41/catalog:") . "$_toolroot/dsssl/docbook/catalog:" . "$_toolroot/jade-1.2.1/dsssl/catalog"; $ENV{'SGML_CATALOG_FILES'} = $s; } if( !(-d "$fname_wo_ext") ) { mkdir("$fname_wo_ext", 0755); } $linuxdoc = 0; print "\nldp_mk: $fname is DocBook (vers. $db_v) SGML\n"; } # create the SGML index... # if( $linuxdoc == 0 && $create_index == 1 ) { print "\nldp_mk: creating SGML index from $fname...\n"; $cmd = "$_toolroot/mkindex/collateindex.pl -N -o index.sgml; " . "$_toolroot/$_jade/jade/jade -t sgml -V html-index " . "-d $_toolroot/dsssl/docbook/html/ldp.dsl#html " . ($style ne '' ? "-d $style " : '') . "$fname ; " . "$_toolroot/mkindex/collateindex.pl -g -t Index " . "-i doc-index -o index.sgml HTML.index;" . "rm -f HTML.index"; system($cmd); } # create HTML version # print "\nldp_mk: creating HTML from $fname...\n"; if( $linuxdoc == 1 ) { $cmd = "$_toolroot/sgml-tools/bin/sgml2html -c latin $fname"; } else { $cmd = "$_toolroot/$_jade/jade/jade -t sgml -i html " . "-d $_toolroot/dsssl/docbook/html/ldp.dsl#html " . ($style ne '' ? "-d $style " : '') . "$fname; " . "mv -f \*.html $fname_wo_ext/;" . "$_toolroot/$_jade/jade/jade -t sgml -i html -V nochunks " . "-d $_toolroot/dsssl/docbook/html/ldp.dsl#html " . ($style ne '' ? "-d $style " : '') . " $fname > 00_" . "$fname_wo_ext.html"; } system($cmd); if( ($linuxdoc == 1 && !(-e "$fname_wo_ext.html")) || ($linuxdoc == 0 && !(-e "$fname_wo_ext/index.html")) ) { print "\nldp_mk: WARNING - could not create HTML: $fname_wo_ext\n"; } # create PLAIN TEXT version # print "\nldp_mk: creating plain text from $fname...\n"; if( $linuxdoc == 1 ) { $cmd = "$_toolroot/sgml-tools/bin/sgml2txt -c latin -f $fname"; system($cmd); } else { if( $txt_filter =~ /lynx/i ) { $cmd = "lynx -dump "; } elsif( $txt_filter =~ /w3m/i ) { $cmd = "$_toolroot/w3m/bin/w3m -S -cols 78 -dump "; } elsif( $txt_filter =~ /html2text/ ) { $cmd = "$_toolroot/html2text/bin/html2text -style pretty -nobs "; } else { print "\nldp_mk: txt_filter($txt_filter) unrecognized, using lynx\n"; $cmd = "lynx -dump "; } $cmd .= " 00_" . "$fname_wo_ext" . ".html > $fname_wo_ext.txt"; system($cmd); # patch the text file; especially needed w/lynx # if( -e "$fname_wo_ext.txt" ) { my($pat) = 'file://localhost/export/sunsite/users/gferg/howto/'; open(HFILE, "+< $fname_wo_ext.txt") || die "\nldp_mk: cannot open: $fname_wo_ext.txt"; my(@flines) = ; for($i=0; $i < (@flines + 0); $i++) { $flines[$i] =~ s/$pat//g; $flines[$i] =~ s/00_$fname_wo_ext/$fname_wo_ext/g; } seek(HFILE,0,0); print HFILE @flines; truncate(HFILE, tell(HFILE)); close(HFILE); } } if( !(-e "$fname_wo_ext.txt") ) { print "\nldp_mk: WARNING - could not create TXT: $fname_wo_ext.txt\n"; } else { # clean-up PLAIN TEXT version # $cmd = "cat $fname_wo_ext.txt|$_toolroot/sgml-tools/bin/cutblank >" . "ldp_mk_tmp; mv -f ldp_mk_tmp $fname_wo_ext.txt"; system($cmd); } # create PDF/PS versions # # Note that we use the single-page HTML variant # print "\nldp_mk: creating PDF from $fname...\n"; if( $linuxdoc == 1 ) { system("$_toolroot/sgml_ld_1html $fname"); } if( -e "00_$fname_wo_ext.html" ) { $cmd = "$_toolroot/htmldoc/bin/htmldoc --size universal -t pdf -f " . "$fname_wo_ext.pdf 00_" . "$fname_wo_ext.html; " . "$_toolroot/htmldoc/bin/htmldoc --size universal -t ps -f " . "$fname_wo_ext.ps 00_" . "$fname_wo_ext.html"; system($cmd); if( !(-e "$fname_wo_ext.pdf") ) { print "\nldp_mk: WARNING - could not create $fname_wo_ext.pdf\n"; } if( !(-e "$fname_wo_ext.ps") ) { print "\nldp_mk: WARNING - could not create $fname_wo_ext.ps\n"; } else { $cmd = "gzip -f $fname_wo_ext.ps"; system($cmd); } } else { print "\nldp_mk: WARNING - HTML file 00_$fname_wo_ext.html not found; ", "skipping PDF/PS creation\n"; } # # perform the packaging steps # print "\nldp_mk: creating HTML package...\n"; if( $linuxdoc == 1 ) { $cmd = "tar -cvf $fname_wo_ext-html.tar $fname_wo_ext\*.html; " . "gzip -f $fname_wo_ext-html.tar"; } else { $cmd = "tar -cvf $fname_wo_ext-html.tar $fname_wo_ext/\*; " . "gzip -f $fname_wo_ext-html.tar"; } system($cmd); if( !(-e "$fname_wo_ext-html.tar.gz") ) { print "\nldp_mk: WARNING - could not create $fname_wo_ext-html.tar.gz\n"; } print "\nldp_mk: creating SGML package...\n"; $cmd = "cp $fname ldp_mk_tmp; gzip -f ldp_mk_tmp; " . "mv -f ldp_mk_tmp.gz $fname_wo_ext.sgml.gz"; system($cmd); if( !(-e "$fname_wo_ext.sgml.gz") ) { print "\nldp_mk: WARNING - could not create $fname_wo_ext.sgml.gz\n"; } # if LinuxDoc, create DocBook SGML... # if( $linuxdoc == 1 ) { print "\nldp_mk: creating DocBook from LinuxDoc...\n"; $ENV{'SGML_CATALOG_FILES'} = "$_toolroot/dtd/docbook.cat:$_toolroot/$_jade/dsssl/catalog"; $cmd = "$_toolroot/$_jade/sgmlnorm/sgmlnorm " . "$_toolroot/ld2db/docbook.dcl $fname > EX_$fname ;" . "$_toolroot/$_jade/jade/jade -t sgml " . "-c $_toolroot/ld2db/catalog " . "-d $_toolroot/ld2db/ld2db.dsl#db EX_$fname > DB_$fname ;" . "rm -f EX_$fname"; system($cmd); if( !(-e "DB_$fname") ) { print "\nldp_mk: WARNING - could not create DocBook: DB_$fname\n"; } else { $cmd = "gzip -f DB_$fname"; system($cmd); } } print "\nldp_mk: completed...\n"; exit(0); sub usage { print "\n\n", "usage: ldp_mk ", "-style -txt -no_index .sgml\n\n"; " where:\n", " - fullpath to a DSSSL stylesheet\n", " - one of the following: lynx, w3m, html2text\n"; }