MAJOR update. Cleaned up script, added support for DB 4.1, added command-line args, streamlined some of the processing, added ability to create index.sgml (collateindex, ect)

This commit is contained in:
gferg 2000-08-02 17:39:24 +00:00
parent 7d8ff0059e
commit f283e2bb70
1 changed files with 198 additions and 63 deletions

View File

@ -1,20 +1,43 @@
#!/usr/bin/perl
#
# ldp_mk <file>.sgml
# ldp_mk - create all various output forms needed for the LDP from SGML file
#
# 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 '') {
die "\nusage: ldp_mk <file>.sgml\n";
&usage();
exit(0);
}
my($_toolroot) = $ENV{'SGML_TOOLROOT'} || '/export/sunsite/users/gferg/toolroot';
my($_jade) = 'jade-1.2.1';
my($linuxdoc) = 1;
my($cmd, $fname, $fname_wo_ext) = '';
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) = '';
$fname = $ARGV[0];
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]+$//;
@ -22,27 +45,71 @@ if( $fname =~ /\.sgml$/ ) {
$fname .= "\.sgml";
}
if( !(-e "$fname") ) {
die "ldp_mk: Error - cannot find/read $fname\nusage: ldp_mk <file>.sgml\n";
print "\nldp_mk: ERROR - cannot find/read $fname\n";
&usage();
exit(0);
}
if( $txt_filter eq '' ) {
$txt_filter = 'lynx';
}
# determine DTD
#
open(FP_IN, "grep -i '\!doctype' $fname |") ||
die "ldp_mk: cannot determine DTD for $fname\n";
$cmd = <FP_IN>;
open(FP_IN, "head $fname | grep -i '\!doctype' |") ||
die "\nldp_mk: ERROR - cannot determine DTD for $fname\n";
$s = <FP_IN>;
close(FP_IN);
if( $cmd eq '' ) {
die "ldp_mk: cannot determine DTD for $fname\n";
if( $s eq '' ) {
die "\nldp_mk: cannot determine DTD for $fname\n";
}
if( $cmd =~ /linuxdoc/i ) {
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;
$ENV{'SGML_CATALOG_FILES'} =
"$_toolroot/dtd/catalog:$_toolroot/dsssl/docbook/catalog:$_toolroot/jade-1.2.1/dsssl/catalog";
print "\nldp_mk: $fname is DocBook SGML\n";
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);
}
@ -51,22 +118,27 @@ if( $cmd =~ /linuxdoc/i ) {
print "\nldp_mk: creating HTML from $fname...\n";
if( $linuxdoc == 1 ) {
$cmd = "$_toolroot/sgml-tools/bin/sgml2html -c latin $fname";
} else {
$cmd = "mkdir $fname_wo_ext; cd $fname_wo_ext; " .
"$_toolroot/$_jade/jade/jade -t sgml -i html " .
"-d $_toolroot/dsssl/docbook/html/ldp.dsl#html ../$fname; " .
"cd ..;" .
$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 $fname >" .
"00_" . "$fname_wo_ext.html";
"-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")) ) {
die "ldp_mk: Error - could not create HTML: $fname_wo_ext\n";
print "\nldp_mk: WARNING - could not create HTML: $fname_wo_ext\n";
}
@ -75,26 +147,68 @@ if( ($linuxdoc == 1 && !(-e "$fname_wo_ext.html"))
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 {
$cmd = "lynx -dump 00_" . "$fname_wo_ext" . ".html > $fname_wo_ext.txt";
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) = <HFILE>;
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);
}
}
system($cmd);
if( !(-e "$fname_wo_ext.txt") ) {
die "ldp_mk: Error - could not create TXT: $fname_wo_ext.txt\n";
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);
}
# 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 HTML in one big file for better PDF/PS quality
# Note that we use the single-page HTML variant
#
print "\nldp_mk: creating PDF from $fname...\n";
@ -102,51 +216,58 @@ if( $linuxdoc == 1 ) {
system("$_toolroot/sgml_ld_1html $fname");
}
if( !(-e "00_$fname_wo_ext.html") ) {
die "ldp_mk: Error - HTML file 00_$fname_wo_ext.html not found\n";
}
$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 "00_$fname_wo_ext.html" ) {
if( !(-e "$fname_wo_ext.pdf") ) {
die "ldp_mk: Error - htmldoc could not create $fname_wo_ext.pdf\n";
}
if( !(-e "$fname_wo_ext.ps") ) {
die "ldp_mk: Error - htmldoc could not create $fname_wo_ext.ps\n";
$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 $fname_wo_ext-html.tar";
"gzip -f $fname_wo_ext-html.tar";
} else {
$cmd = "tar -cvf $fname_wo_ext-html.tar $fname_wo_ext/\*; " .
"gzip $fname_wo_ext-html.tar";
"gzip -f $fname_wo_ext-html.tar";
}
system($cmd);
if( !(-e "$fname_wo_ext-html.tar.gz") ) {
die "ldp_mk: Error - could not create package $fname_wo_ext-html.tar.gz\n";
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 ldp_mk_tmp; " .
$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") ) {
die "ldp_mk: Error - could not create package $fname_wo_ext.sgml.gz\n";
}
print "\nldp_mk: creating PS package...\n";
$cmd = "gzip $fname_wo_ext.ps";
system($cmd);
if( !(-e "$fname_wo_ext.ps.gz") ) {
die "ldp_mk: Error - could not create package $fname_wo_ext.sgml.gz\n";
if( !(-e "$fname_wo_ext.sgml.gz") ) {
print "\nldp_mk: WARNING - could not create $fname_wo_ext.sgml.gz\n";
}
@ -168,13 +289,27 @@ if( $linuxdoc == 1 ) {
system($cmd);
if( !(-e "DB_$fname") ) {
print "\nnldp_mk: Warning: could not create DocBook file: DB_$fname\n";
print "\nldp_mk: WARNING - could not create DocBook: DB_$fname\n";
} else {
$cmd = "gzip DB_$fname";
$cmd = "gzip -f DB_$fname";
system($cmd);
}
}
print "\nldp_mk: completed...\n";
exit(0);
sub usage {
print "\n\n",
"usage: ldp_mk ",
"-style <stylesheet> -txt <txt_filter> -no_index <file>.sgml\n\n";
" where:\n",
" <stylesheet> - fullpath to a DSSSL stylesheet\n",
" <txt_filter> - one of the following: lynx, w3m, html2text\n";
}