mirror of https://github.com/tLDP/LDP
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:
parent
7d8ff0059e
commit
f283e2bb70
|
@ -1,20 +1,43 @@
|
||||||
#!/usr/bin/perl
|
#!/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 '') {
|
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($_toolroot) = $ENV{'SGML_TOOLROOT'} ||
|
||||||
my($_jade) = 'jade-1.2.1';
|
'/export/sunsite/users/gferg/toolroot';
|
||||||
my($linuxdoc) = 1;
|
my($_jade) = 'jade-1.2.1';
|
||||||
my($cmd, $fname, $fname_wo_ext) = '';
|
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;
|
$fname_wo_ext = $fname;
|
||||||
if( $fname =~ /\.sgml$/ ) {
|
if( $fname =~ /\.sgml$/ ) {
|
||||||
$fname_wo_ext =~ s/\.[\w]+$//;
|
$fname_wo_ext =~ s/\.[\w]+$//;
|
||||||
|
@ -22,27 +45,71 @@ if( $fname =~ /\.sgml$/ ) {
|
||||||
$fname .= "\.sgml";
|
$fname .= "\.sgml";
|
||||||
}
|
}
|
||||||
if( !(-e "$fname") ) {
|
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
|
# determine DTD
|
||||||
#
|
#
|
||||||
open(FP_IN, "grep -i '\!doctype' $fname |") ||
|
open(FP_IN, "head $fname | grep -i '\!doctype' |") ||
|
||||||
die "ldp_mk: cannot determine DTD for $fname\n";
|
die "\nldp_mk: ERROR - cannot determine DTD for $fname\n";
|
||||||
$cmd = <FP_IN>;
|
$s = <FP_IN>;
|
||||||
close(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;
|
$linuxdoc = 1;
|
||||||
print "\nldp_mk: $fname is LinuxDoc SGML\n";
|
print "\nldp_mk: $fname is LinuxDoc SGML\n";
|
||||||
|
|
||||||
} else {
|
} 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;
|
$linuxdoc = 0;
|
||||||
$ENV{'SGML_CATALOG_FILES'} =
|
print "\nldp_mk: $fname is DocBook (vers. $db_v) SGML\n";
|
||||||
"$_toolroot/dtd/catalog:$_toolroot/dsssl/docbook/catalog:$_toolroot/jade-1.2.1/dsssl/catalog";
|
}
|
||||||
print "\nldp_mk: $fname is DocBook 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";
|
print "\nldp_mk: creating HTML from $fname...\n";
|
||||||
|
|
||||||
if( $linuxdoc == 1 ) {
|
if( $linuxdoc == 1 ) {
|
||||||
|
|
||||||
$cmd = "$_toolroot/sgml-tools/bin/sgml2html -c latin $fname";
|
$cmd = "$_toolroot/sgml-tools/bin/sgml2html -c latin $fname";
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$cmd = "mkdir $fname_wo_ext; cd $fname_wo_ext; " .
|
|
||||||
"$_toolroot/$_jade/jade/jade -t sgml -i html " .
|
$cmd = "$_toolroot/$_jade/jade/jade -t sgml -i html " .
|
||||||
"-d $_toolroot/dsssl/docbook/html/ldp.dsl#html ../$fname; " .
|
"-d $_toolroot/dsssl/docbook/html/ldp.dsl#html " .
|
||||||
"cd ..;" .
|
($style ne '' ? "-d $style " : '') .
|
||||||
|
"$fname; " .
|
||||||
|
"mv -f \*.html $fname_wo_ext/;" .
|
||||||
"$_toolroot/$_jade/jade/jade -t sgml -i html -V nochunks " .
|
"$_toolroot/$_jade/jade/jade -t sgml -i html -V nochunks " .
|
||||||
"-d $_toolroot/dsssl/docbook/html/ldp.dsl#html $fname >" .
|
"-d $_toolroot/dsssl/docbook/html/ldp.dsl#html " .
|
||||||
"00_" . "$fname_wo_ext.html";
|
($style ne '' ? "-d $style " : '') .
|
||||||
|
" $fname > 00_" . "$fname_wo_ext.html";
|
||||||
}
|
}
|
||||||
|
|
||||||
system($cmd);
|
system($cmd);
|
||||||
if( ($linuxdoc == 1 && !(-e "$fname_wo_ext.html"))
|
if( ($linuxdoc == 1 && !(-e "$fname_wo_ext.html"))
|
||||||
||
|
||
|
||||||
($linuxdoc == 0 && !(-e "$fname_wo_ext/index.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";
|
print "\nldp_mk: creating plain text from $fname...\n";
|
||||||
|
|
||||||
if( $linuxdoc == 1 ) {
|
if( $linuxdoc == 1 ) {
|
||||||
|
|
||||||
$cmd = "$_toolroot/sgml-tools/bin/sgml2txt -c latin -f $fname";
|
$cmd = "$_toolroot/sgml-tools/bin/sgml2txt -c latin -f $fname";
|
||||||
|
system($cmd);
|
||||||
|
|
||||||
} else {
|
} 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") ) {
|
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
|
# 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";
|
print "\nldp_mk: creating PDF from $fname...\n";
|
||||||
|
|
||||||
|
@ -102,51 +216,58 @@ if( $linuxdoc == 1 ) {
|
||||||
system("$_toolroot/sgml_ld_1html $fname");
|
system("$_toolroot/sgml_ld_1html $fname");
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !(-e "00_$fname_wo_ext.html") ) {
|
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 "$fname_wo_ext.pdf") ) {
|
$cmd = "$_toolroot/htmldoc/bin/htmldoc --size universal -t pdf -f " .
|
||||||
die "ldp_mk: Error - htmldoc could not create $fname_wo_ext.pdf\n";
|
"$fname_wo_ext.pdf 00_" . "$fname_wo_ext.html; " .
|
||||||
}
|
"$_toolroot/htmldoc/bin/htmldoc --size universal -t ps -f " .
|
||||||
if( !(-e "$fname_wo_ext.ps") ) {
|
"$fname_wo_ext.ps 00_" . "$fname_wo_ext.html";
|
||||||
die "ldp_mk: Error - htmldoc could not create $fname_wo_ext.ps\n";
|
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
|
# perform the packaging steps
|
||||||
#
|
#
|
||||||
|
|
||||||
print "\nldp_mk: creating HTML package...\n";
|
print "\nldp_mk: creating HTML package...\n";
|
||||||
|
|
||||||
if( $linuxdoc == 1 ) {
|
if( $linuxdoc == 1 ) {
|
||||||
$cmd = "tar -cvf $fname_wo_ext-html.tar $fname_wo_ext\*.html; " .
|
$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 {
|
} else {
|
||||||
$cmd = "tar -cvf $fname_wo_ext-html.tar $fname_wo_ext/\*; " .
|
$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);
|
system($cmd);
|
||||||
|
|
||||||
if( !(-e "$fname_wo_ext-html.tar.gz") ) {
|
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";
|
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";
|
"mv -f ldp_mk_tmp.gz $fname_wo_ext.sgml.gz";
|
||||||
system($cmd);
|
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";
|
if( !(-e "$fname_wo_ext.sgml.gz") ) {
|
||||||
$cmd = "gzip $fname_wo_ext.ps";
|
print "\nldp_mk: WARNING - could not create $fname_wo_ext.sgml.gz\n";
|
||||||
system($cmd);
|
|
||||||
if( !(-e "$fname_wo_ext.ps.gz") ) {
|
|
||||||
die "ldp_mk: Error - could not create package $fname_wo_ext.sgml.gz\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -168,13 +289,27 @@ if( $linuxdoc == 1 ) {
|
||||||
system($cmd);
|
system($cmd);
|
||||||
|
|
||||||
if( !(-e "DB_$fname") ) {
|
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 {
|
} else {
|
||||||
$cmd = "gzip DB_$fname";
|
$cmd = "gzip -f DB_$fname";
|
||||||
system($cmd);
|
system($cmd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
print "\nldp_mk: completed...\n";
|
||||||
|
|
||||||
exit(0);
|
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";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue