2000-05-17 15:37:10 +00:00
|
|
|
#!/usr/bin/perl
|
|
|
|
#
|
2000-08-02 17:39:24 +00:00
|
|
|
# ldp_mk - create all various output forms needed for the LDP from SGML file
|
2000-05-17 15:37:10 +00:00
|
|
|
#
|
2000-08-02 17:39:24 +00:00
|
|
|
# gferg@sgi.com / Ferg
|
|
|
|
#
|
|
|
|
# LOG:
|
|
|
|
# 02Aug2000 - added cmd-line options and index creation (gferg)
|
2000-05-17 15:37:10 +00:00
|
|
|
#
|
|
|
|
|
|
|
|
if($ARGV[0] eq '') {
|
2000-08-02 17:39:24 +00:00
|
|
|
&usage();
|
|
|
|
exit(0);
|
2000-05-17 15:37:10 +00:00
|
|
|
}
|
|
|
|
|
2000-08-02 17:39:24 +00:00
|
|
|
my($_toolroot) = $ENV{'SGML_TOOLROOT'} ||
|
|
|
|
'/export/sunsite/users/gferg/toolroot';
|
|
|
|
my($_jade) = 'jade-1.2.1';
|
2000-10-09 15:12:25 +00:00
|
|
|
my($dtd) = 'SGML';
|
|
|
|
my($dcl) = '';
|
2000-08-02 17:39:24 +00:00
|
|
|
my($linuxdoc) = 1;
|
|
|
|
my($create_index) = 1;
|
2000-10-09 15:12:25 +00:00
|
|
|
my($cmd, $fname, $fname_wo_ext, $txt_filter, $style, $s, $db_v, $x) = '';
|
2001-01-03 17:38:25 +00:00
|
|
|
my(@flines) = ();
|
2000-08-02 17:39:24 +00:00
|
|
|
|
|
|
|
while(1) {
|
|
|
|
|
|
|
|
if ($ARGV[0] eq "-style") {
|
|
|
|
shift(@ARGV);
|
2000-10-09 15:12:25 +00:00
|
|
|
$style = $ARGV[0];
|
2000-08-02 17:39:24 +00:00
|
|
|
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];
|
2000-05-17 15:37:10 +00:00
|
|
|
$fname_wo_ext = $fname;
|
2000-10-09 15:12:25 +00:00
|
|
|
if( $fname =~ /\.[\w]+ml$/ ) {
|
2000-05-17 15:37:10 +00:00
|
|
|
$fname_wo_ext =~ s/\.[\w]+$//;
|
|
|
|
} else {
|
2000-10-09 15:12:25 +00:00
|
|
|
if( -e "$fname.sgml" ) {
|
|
|
|
$fname .= "\.sgml";
|
|
|
|
} else {
|
|
|
|
$fname .= "\.xml";
|
|
|
|
}
|
2000-05-17 15:37:10 +00:00
|
|
|
}
|
|
|
|
if( !(-e "$fname") ) {
|
2000-08-02 17:39:24 +00:00
|
|
|
print "\nldp_mk: ERROR - cannot find/read $fname\n";
|
|
|
|
&usage();
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2000-08-08 18:13:07 +00:00
|
|
|
if( $style eq '' ) {
|
|
|
|
$style = "$_toolroot/dsssl/docbook/html/ldp.dsl#html";
|
|
|
|
}
|
2000-05-17 15:37:10 +00:00
|
|
|
|
2000-11-13 20:51:53 +00:00
|
|
|
|
2000-05-17 15:37:10 +00:00
|
|
|
# determine DTD
|
|
|
|
#
|
2001-01-03 17:38:25 +00:00
|
|
|
open(FP_IN, "head -50 $fname | grep -i '\!doctype' |") ||
|
2000-08-02 17:39:24 +00:00
|
|
|
die "\nldp_mk: ERROR - cannot determine DTD for $fname\n";
|
|
|
|
$s = <FP_IN>;
|
2000-05-17 15:37:10 +00:00
|
|
|
close(FP_IN);
|
2000-08-02 17:39:24 +00:00
|
|
|
|
|
|
|
if( $s eq '' ) {
|
|
|
|
die "\nldp_mk: cannot determine DTD for $fname\n";
|
2000-05-17 15:37:10 +00:00
|
|
|
}
|
2000-10-09 15:12:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2000-08-02 17:39:24 +00:00
|
|
|
if( $s =~ /linuxdoc/i ) {
|
|
|
|
|
2000-05-17 15:37:10 +00:00
|
|
|
$linuxdoc = 1;
|
|
|
|
print "\nldp_mk: $fname is LinuxDoc SGML\n";
|
2000-08-02 17:39:24 +00:00
|
|
|
|
2000-11-13 20:51:53 +00:00
|
|
|
if( $txt_filter eq '' ) {
|
|
|
|
$txt_filter = 'lynx';
|
|
|
|
}
|
|
|
|
|
2000-05-17 15:37:10 +00:00
|
|
|
} else {
|
2000-08-02 17:39:24 +00:00
|
|
|
|
|
|
|
# determine docbook version
|
|
|
|
#
|
|
|
|
($db_v) = ($s =~ /\s+V(\d)\./i);
|
|
|
|
|
|
|
|
# do not override any various SGML catalog file settings
|
|
|
|
#
|
2000-10-09 15:12:25 +00:00
|
|
|
if( $s =~ /\ xml\ /i ) {
|
|
|
|
$dtd = 'XML';
|
|
|
|
$x = 'x';
|
|
|
|
$dcl = "${_toolroot}/${_jade}/pubtext/xml.dcl";
|
|
|
|
}
|
|
|
|
|
2000-08-02 17:39:24 +00:00
|
|
|
if( $ENV{'SGML_CATALOG_FILES'} eq '' ) {
|
2000-10-09 15:12:25 +00:00
|
|
|
$s = ($db_v =~ /3/ ? "${_toolroot}/dtd/docbook${x}_31/catalog:" :
|
|
|
|
"${_toolroot}/dtd/docbook${x}_41/catalog:") .
|
|
|
|
"${_toolroot}/dsssl/docbook/catalog:" .
|
|
|
|
"${_toolroot}/${_jade}/dsssl/catalog";
|
2000-08-02 17:39:24 +00:00
|
|
|
$ENV{'SGML_CATALOG_FILES'} = $s;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !(-d "$fname_wo_ext") ) {
|
|
|
|
mkdir("$fname_wo_ext", 0755);
|
|
|
|
}
|
|
|
|
|
2000-05-17 15:37:10 +00:00
|
|
|
$linuxdoc = 0;
|
2000-10-09 15:12:25 +00:00
|
|
|
print "\nldp_mk: $fname is DocBook (vers. $db_v) $dtd\n";
|
2000-11-13 20:51:53 +00:00
|
|
|
|
|
|
|
if( $txt_filter eq '' ) {
|
|
|
|
$txt_filter = 'w3m';
|
|
|
|
}
|
2000-08-02 17:39:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-10-09 15:12:25 +00:00
|
|
|
# create the index...
|
2000-08-02 17:39:24 +00:00
|
|
|
#
|
|
|
|
if( $linuxdoc == 0 && $create_index == 1 ) {
|
|
|
|
|
2000-10-09 15:12:25 +00:00
|
|
|
print "\nldp_mk: creating index from $fname...\n";
|
2000-08-02 17:39:24 +00:00
|
|
|
|
2000-10-09 15:12:25 +00:00
|
|
|
$cmd =
|
|
|
|
"$_toolroot/mkindex/collateindex.pl -N -o index.sgml; " .
|
|
|
|
"$_toolroot/$_jade/jade/jade -t sgml -V html-index -d $style $dcl $fname ; " .
|
2000-08-08 18:13:07 +00:00
|
|
|
"$_toolroot/mkindex/collateindex.pl -g -t Index -i doc-index " .
|
|
|
|
"-o index.sgml HTML.index;" .
|
|
|
|
"rm -f HTML.index";
|
2000-08-02 17:39:24 +00:00
|
|
|
system($cmd);
|
2000-05-17 15:37:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# create HTML version
|
|
|
|
#
|
|
|
|
print "\nldp_mk: creating HTML from $fname...\n";
|
|
|
|
|
|
|
|
if( $linuxdoc == 1 ) {
|
2000-08-02 17:39:24 +00:00
|
|
|
|
2000-05-17 15:37:10 +00:00
|
|
|
$cmd = "$_toolroot/sgml-tools/bin/sgml2html -c latin $fname";
|
2000-08-02 17:39:24 +00:00
|
|
|
|
2000-05-17 15:37:10 +00:00
|
|
|
} else {
|
2000-08-02 17:39:24 +00:00
|
|
|
|
2000-10-09 15:12:25 +00:00
|
|
|
$cmd =
|
|
|
|
"$_toolroot/$_jade/jade/jade -t sgml -i html -d $style $dcl $fname; " .
|
|
|
|
"mv -f \*.html $fname_wo_ext/;" .
|
|
|
|
"$_toolroot/$_jade/jade/jade -t sgml -i html -V nochunks " .
|
2001-01-03 17:38:25 +00:00
|
|
|
"-d $style $dcl $fname > 00_${fname_wo_ext}.html";
|
2000-05-17 15:37:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
system($cmd);
|
|
|
|
if( ($linuxdoc == 1 && !(-e "$fname_wo_ext.html"))
|
|
|
|
||
|
|
|
|
($linuxdoc == 0 && !(-e "$fname_wo_ext/index.html")) ) {
|
2000-08-02 17:39:24 +00:00
|
|
|
print "\nldp_mk: WARNING - could not create HTML: $fname_wo_ext\n";
|
2000-05-17 15:37:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# create PLAIN TEXT version
|
|
|
|
#
|
|
|
|
print "\nldp_mk: creating plain text from $fname...\n";
|
|
|
|
|
|
|
|
if( $linuxdoc == 1 ) {
|
2000-08-02 17:39:24 +00:00
|
|
|
|
2000-05-17 15:37:10 +00:00
|
|
|
$cmd = "$_toolroot/sgml-tools/bin/sgml2txt -c latin -f $fname";
|
2000-08-02 17:39:24 +00:00
|
|
|
|
2000-05-17 15:37:10 +00:00
|
|
|
} else {
|
2000-08-02 17:39:24 +00:00
|
|
|
|
2001-01-03 17:38:25 +00:00
|
|
|
open(F_IN, "00_${fname_wo_ext}.html");
|
|
|
|
$s = join('', <F_IN>);
|
|
|
|
close(F_IN);
|
|
|
|
|
|
|
|
# fix to place URLs in-line for text variant
|
|
|
|
#
|
|
|
|
open(F_OUT, "> TXT_${fname_wo_ext}.html");
|
|
|
|
$s =~ s/<A\s*HREF=\"(.*?)\"\s*TARGET=\"(.*?)\"\s*>(.*?)<\/A\s*>/<TT>[$1]<\/TT>\ $3/gm;
|
|
|
|
print F_OUT $s;
|
|
|
|
close(F_OUT);
|
|
|
|
|
2000-08-02 17:39:24 +00:00
|
|
|
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 ";
|
|
|
|
}
|
|
|
|
|
2001-01-03 17:38:25 +00:00
|
|
|
$cmd .= "TXT_${fname_wo_ext}.html > $fname_wo_ext.txt;" .
|
|
|
|
"rm -f TXT_${fname_wo_ext}.html";
|
2000-08-08 18:13:07 +00:00
|
|
|
}
|
2000-08-02 17:39:24 +00:00
|
|
|
|
2000-08-08 18:13:07 +00:00
|
|
|
system($cmd);
|
2000-08-02 17:39:24 +00:00
|
|
|
|
2000-08-08 18:13:07 +00:00
|
|
|
# patch the text file; especially needed w/lynx
|
|
|
|
#
|
|
|
|
if( -e "$fname_wo_ext.txt" ) {
|
|
|
|
|
|
|
|
my($def_blanks)= 3;
|
|
|
|
my($count) = 0;
|
2001-01-03 17:38:25 +00:00
|
|
|
@flines = ();
|
2000-08-08 18:13:07 +00:00
|
|
|
|
|
|
|
open(CPIPE, "pwd |");
|
|
|
|
$s = <CPIPE>; chop($s);
|
|
|
|
my($pat) = 'file://localhost' . $s . '/';
|
2000-10-09 15:12:25 +00:00
|
|
|
$pat =~ s/\+/\\+/g;
|
|
|
|
my($pat2) = $fname_wo_ext;
|
|
|
|
$pat2 =~ s/\+/\\+/g;
|
2000-08-08 18:13:07 +00:00
|
|
|
close(CPIPE);
|
|
|
|
|
|
|
|
open(HFILE, "+< $fname_wo_ext.txt") ||
|
|
|
|
die "\nldp_mk: cannot open: $fname_wo_ext.txt";
|
|
|
|
while(<HFILE>) {
|
|
|
|
if (length($_) == 1) {
|
|
|
|
$count++;
|
|
|
|
} else {
|
|
|
|
$count = 0;
|
|
|
|
}
|
|
|
|
if ($count <= $def_blanks) {
|
|
|
|
$_ =~ s/$pat//g;
|
2000-10-09 15:12:25 +00:00
|
|
|
$_ =~ s/00_$pat2/$pat2/g;
|
2000-08-08 18:13:07 +00:00
|
|
|
push(@flines, $_);
|
|
|
|
}
|
2000-08-02 17:39:24 +00:00
|
|
|
}
|
2000-05-17 15:37:10 +00:00
|
|
|
|
2000-08-08 18:13:07 +00:00
|
|
|
seek(HFILE,0,0);
|
|
|
|
print HFILE @flines;
|
|
|
|
truncate(HFILE, tell(HFILE));
|
|
|
|
close(HFILE);
|
2000-05-17 15:37:10 +00:00
|
|
|
|
2000-08-02 17:39:24 +00:00
|
|
|
} else {
|
|
|
|
|
2000-08-08 18:13:07 +00:00
|
|
|
print "\nldp_mk: WARNING - could not create TXT: $fname_wo_ext.txt\n";
|
2000-08-02 17:39:24 +00:00
|
|
|
}
|
2000-05-17 15:37:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
# create PDF/PS versions
|
|
|
|
#
|
2000-08-02 17:39:24 +00:00
|
|
|
# Note that we use the single-page HTML variant
|
2000-05-17 15:37:10 +00:00
|
|
|
#
|
|
|
|
print "\nldp_mk: creating PDF from $fname...\n";
|
|
|
|
|
2000-11-13 20:51:53 +00:00
|
|
|
my($print_str) = '';
|
|
|
|
|
2000-05-17 15:37:10 +00:00
|
|
|
if( $linuxdoc == 1 ) {
|
2000-11-13 20:51:53 +00:00
|
|
|
|
|
|
|
# patch the linuxdoc-source single HTML file
|
|
|
|
#
|
2000-05-17 15:37:10 +00:00
|
|
|
system("$_toolroot/sgml_ld_1html $fname");
|
2000-11-13 20:51:53 +00:00
|
|
|
$print_str = "00_${fname_wo_ext}.html";
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
# create new files from DocBook-source single HTML file to use for print
|
|
|
|
#
|
|
|
|
require "$_toolroot/lib/fix_print_html.lib";
|
|
|
|
&fix_print_html("00_${fname_wo_ext}.html", 'body.html', 'title.html');
|
|
|
|
|
|
|
|
$print_str = "--titlefile title.html body.html";
|
2000-05-17 15:37:10 +00:00
|
|
|
}
|
|
|
|
|
2000-11-13 20:51:53 +00:00
|
|
|
|
2000-08-02 17:39:24 +00:00
|
|
|
if( -e "00_$fname_wo_ext.html" ) {
|
2000-05-17 15:37:10 +00:00
|
|
|
|
2000-08-02 17:39:24 +00:00
|
|
|
$cmd = "$_toolroot/htmldoc/bin/htmldoc --size universal -t pdf -f " .
|
2000-11-13 20:51:53 +00:00
|
|
|
"$fname_wo_ext.pdf $print_str; " .
|
2000-08-02 17:39:24 +00:00
|
|
|
"$_toolroot/htmldoc/bin/htmldoc --size universal -t ps -f " .
|
2000-11-13 20:51:53 +00:00
|
|
|
"$fname_wo_ext.ps $print_str";
|
2000-08-02 17:39:24 +00:00
|
|
|
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";
|
2000-05-17 15:37:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-08-02 17:39:24 +00:00
|
|
|
#
|
2000-05-17 15:37:10 +00:00
|
|
|
# perform the packaging steps
|
|
|
|
#
|
2000-08-02 17:39:24 +00:00
|
|
|
|
2000-05-17 15:37:10 +00:00
|
|
|
print "\nldp_mk: creating HTML package...\n";
|
2000-08-02 17:39:24 +00:00
|
|
|
|
2000-05-17 15:37:10 +00:00
|
|
|
if( $linuxdoc == 1 ) {
|
|
|
|
$cmd = "tar -cvf $fname_wo_ext-html.tar $fname_wo_ext\*.html; " .
|
2000-08-02 17:39:24 +00:00
|
|
|
"gzip -f $fname_wo_ext-html.tar";
|
2000-05-17 15:37:10 +00:00
|
|
|
} else {
|
|
|
|
$cmd = "tar -cvf $fname_wo_ext-html.tar $fname_wo_ext/\*; " .
|
2000-08-02 17:39:24 +00:00
|
|
|
"gzip -f $fname_wo_ext-html.tar";
|
2000-05-17 15:37:10 +00:00
|
|
|
}
|
|
|
|
system($cmd);
|
2000-08-02 17:39:24 +00:00
|
|
|
|
2000-05-17 15:37:10 +00:00
|
|
|
if( !(-e "$fname_wo_ext-html.tar.gz") ) {
|
2000-08-02 17:39:24 +00:00
|
|
|
print "\nldp_mk: WARNING - could not create $fname_wo_ext-html.tar.gz\n";
|
2000-05-17 15:37:10 +00:00
|
|
|
}
|
|
|
|
|
2000-08-02 17:39:24 +00:00
|
|
|
|
2000-05-17 15:37:10 +00:00
|
|
|
print "\nldp_mk: creating SGML package...\n";
|
2000-08-02 17:39:24 +00:00
|
|
|
|
|
|
|
$cmd = "cp $fname ldp_mk_tmp; gzip -f ldp_mk_tmp; " .
|
2000-10-09 15:12:25 +00:00
|
|
|
"mv -f ldp_mk_tmp.gz $fname_wo_ext." . lc($dtd) . ".gz";
|
2000-05-17 15:37:10 +00:00
|
|
|
system($cmd);
|
|
|
|
|
|
|
|
|
|
|
|
# if LinuxDoc, create DocBook SGML...
|
|
|
|
#
|
|
|
|
if( $linuxdoc == 1 ) {
|
|
|
|
|
|
|
|
print "\nldp_mk: creating DocBook from LinuxDoc...\n";
|
|
|
|
|
|
|
|
$ENV{'SGML_CATALOG_FILES'} =
|
2000-10-09 15:12:25 +00:00
|
|
|
"$_toolroot/dtd/docbook.cat:$_toolroot/$_jade/dsssl/catalog";
|
2000-05-17 15:37:10 +00:00
|
|
|
|
|
|
|
$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") ) {
|
2000-08-02 17:39:24 +00:00
|
|
|
print "\nldp_mk: WARNING - could not create DocBook: DB_$fname\n";
|
2000-05-17 15:37:10 +00:00
|
|
|
} else {
|
2000-08-02 17:39:24 +00:00
|
|
|
$cmd = "gzip -f DB_$fname";
|
2000-05-17 15:37:10 +00:00
|
|
|
system($cmd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-01-03 17:38:25 +00:00
|
|
|
# cleanup
|
|
|
|
system("rm -f index.sgml body.html title.html");
|
|
|
|
|
2000-08-02 17:39:24 +00:00
|
|
|
print "\nldp_mk: completed...\n";
|
|
|
|
|
2000-05-17 15:37:10 +00:00
|
|
|
exit(0);
|
|
|
|
|
2000-08-02 17:39:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
sub usage {
|
|
|
|
|
|
|
|
print "\n\n",
|
|
|
|
"usage: ldp_mk ",
|
2000-11-13 20:51:53 +00:00
|
|
|
"-style <stylesheet> -txt <txt_filter> -no_index <file>.sgml\n\n",
|
2000-08-02 17:39:24 +00:00
|
|
|
" where:\n",
|
|
|
|
" <stylesheet> - fullpath to a DSSSL stylesheet\n",
|
|
|
|
" <txt_filter> - one of the following: lynx, w3m, html2text\n";
|
|
|
|
}
|
|
|
|
|