diff --git a/usr.bin/sgmlfmt/sgmlfmt.1 b/usr.bin/sgmlfmt/sgmlfmt.1 index c332ccfc3dd5..346fe331342e 100644 --- a/usr.bin/sgmlfmt/sgmlfmt.1 +++ b/usr.bin/sgmlfmt/sgmlfmt.1 @@ -23,13 +23,18 @@ declaration before any uncommented text: .Bd -literal -offset indent .Ed -.Pp Options for +.Pp +Options for .Nm include the following: .Bl -tag -width Ds .It Fl f Ar format Determines the output format which can be one of the following: .Bl -tag -width Ds +.It Ar ascii +Generates a single output file with the extension +.Pa .ascii +suitable for viewing on an ASCII terminal. .It Ar html Generates a set of linked HTML files suitable for use with an HTML browser. A top level file, @@ -42,27 +47,35 @@ contains a complete table of contents. A series of files named .Pa file2.html ... .Pa filen.html contain the actual text of the document. +.It Ar koi8-r +Generates a single output file with the extension +.Pa .koi8-r +suitable for viewing on an terminal supporting the KOI8-R +character encoding. .It Ar latex Generates a single output file with the extension -.Pa .tex +.Pa .latex suitable for processing with LaTeX. Note that the LaTeX style file -.Pa /usr/share/sgml/FreeBSD/lib/linuxdoc.sty +.Pa /usr/share/sgml/FreeBSD/linuxdoc.sty must be accessible to LaTeX for correct processing. -.It Ar ascii +.It Ar latin1 Generates a single output file with the extension -.Pa .ascii -suitable for viewing on an ASCII terminal. -.It Ar nroff +.Pa .latin1 +suitable for viewing on an terminal supporting the ISO8859-1 +character encoding. +.It Ar roff Generates a single output file with the extension -.Pa .nroff +.Pa .roff suitable processing with -.Xr nroff 1 -or .Xr groff 1 . This is actually an intermediate conversion used by the -.Fl f Ar ascii -format option. +.Fl f Ar ascii , +.Fl f Ar latin1 , +.Fl f Ar koi8-r , +and +.Fl f Ar ps +format options. .El .It Fl i Ar name Pretend that @@ -128,26 +141,26 @@ the extension may be omitted on the command line. In all cases, the output files are created in the current working directory. .Sh FILES -.Pa /usr/share/sgml/FreeBSD/dtd/linuxdoc +.Pa /usr/share/sgml/FreeBSD/linuxdoc.dtd - the linuxdoc DTD. .Pp -.Pa /usr/share/sgml/FreeBSD/rep/ -- directory containing replacement files for -.Xr sgmlsasp 1 . +.Pa /usr/share/sgml/transpec +- directory containing translation specification files for +.Xr instant 1 . .Pp -.Pa /usr/share/sgml/FreeBSD/lib/linuxdoc.sty +.Pa /usr/share/sgml/FreeBSD/linuxdoc.sty - the LaTeX style used in documents produced with the -.Fl latex +.Fl f Ar latex format option. .Sh SEE ALSO .Xr sgmls 1 , -.Xr sgmlsasp 1 , +.Xr instant 1 , +.Xr transpec 5 , .Xr groff 1 .Sh HISTORY The .Nm -command appeared in -.Fx 2.0.5 . +command appeared in Version 2.0.5 FreeBSD UNIX. .Sh AUTHORS The .Nm @@ -157,30 +170,3 @@ The linuxdoc DTD was written by Matt Welsh .Aq mdw@cs.cornell.edu and based on the Qwertz DTD written by Tom Gordon .Aq thomas.gordon@gmd.de . -.Sh BUGS -The ASCII output has many, many bugs including no meaningful -cross references, and numerous formatting problems. -.Pp -A line in the SGML source file beginning with a period (.) will -confuse -.Xr groff 1 -which is used to generate ASCII output. -.Pp -The division of the sources file into separate HTML files is -currently fixed. -.Pp -Although legal according to the DTD, it the ascii formatting gets botched if -the -.Li -.No ... -.Li -tags are omitted following a -sectioning tag such as -.Li . -.Pp -Beginning and ending tags for the -.Li -element must occur on the same line for correct formatting with -the -.Fl ascii -option. diff --git a/usr.bin/sgmlfmt/sgmlfmt.pl b/usr.bin/sgmlfmt/sgmlfmt.pl index 8f6fbacc2362..366a7f10ac77 100755 --- a/usr.bin/sgmlfmt/sgmlfmt.pl +++ b/usr.bin/sgmlfmt/sgmlfmt.pl @@ -1,68 +1,59 @@ #!/usr/bin/perl -# $Id: sgmlfmt.pl,v 1.9 1996/03/26 13:26:53 jfieber Exp $ + +# $Id: sgmlfmt.pl,v 1.10 1996/05/15 17:05:17 jfieber Exp $ + +# Copyright (C) 1996 +# John R. Fieber. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY JOHN R. FIEBER AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL JOHN R. FIEBER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. + # Format an sgml document tagged according to the linuxdoc DTD. # by John Fieber for the FreeBSD documentation # project. -# -# Bugs: -# -# Text lines that start with a period (.) confuse the conversions that -# use groff. The workaround is to make sure the SGML source doesn't -# have any periods at the beginning of a line. -# -# Although legal by the DTD, it the ascii formatting gets botched if -# the tags are omitted following a . -# -# Beginning and end tags for the element must occur on the same line. -# -# The whole approach of using sgmlsasp and passing a few things -# through for processing by this script is doomed. This whole thing -# needs to be re-thought and a better DTD should be used anyway. -# -####################################################################### -# Look in a couple places for the SGML DTD and replacement files -# require 'newgetopt.pl'; -if (-d "$ENV{'HOME'}/lib/sgml/FreeBSD") { - $sgmldir = "$ENV{'HOME'}/lib/sgml"; -} -elsif (-d "$ENV{'HOME'}/sgml/FreeBSD") { - $sgmldir = "$ENV{'HOME'}/sgml"; -} -elsif (-d "/usr/share/sgml/FreeBSD" ) { - $sgmldir = "/usr/share/sgml"; -} -else { - die "Cannot locate sgml files!\n"; -} +# +# The SGML parser, and translation engine. +# + +$sgmls = "sgmls"; +$instant = "instant"; # # Locate the DTD, an SGML declaration, and the replacement files # -$doctype = ""; -$dtdbase = "$sgmldir/FreeBSD"; -$dtd = "$dtdbase/dtd/linuxdoc"; -if (-f "$dtd.dec") { - $decl = "$dtd.dec"; -} -else { - $decl = ""; -} -$replbase = "$dtdbase/rep"; - -if (! $ENV{"SGML_PATH"}) { - $ENV{"SGML_PATH"} = "$sgmldir/%O/%C/%T"; -} +$doctype = ""; +$dtdbase = "/usr/share/sgml/FreeBSD"; +$dtd = "$dtdbase/linuxdoc.dtd"; +$decl = "$dtdbase/linuxdoc.dcl"; sub usage { print "Usage:\n"; print "sgmlfmt -f [-i ...] [-links] [-ssi] file\n"; - print "where is one of: html, latex, ascii, nroff\n"; + print "where is one of: html, latex, ascii, roff\n"; } # @@ -85,64 +76,37 @@ sub getfile { $fileroot =~ s/\.sgml$//; # drop the .sgml $filepath = $file; $filepath =~ s/\/*[^\/]*$//; - if ($filepath eq "") { - $ENV{"SGML_PATH"} .= ":."; - } - else { - $ENV{"SGML_PATH"} .= ":$filepath/%S:."; + if ($filepath ne "") { + $ENV{"SGML_PATH"} .= ":$filepath/%S:%S"; } return 1; } # -# A function to run sgmls and sgmlsasp on the input file. +# A function to run sgmls and instant on the input file. # # Arguments: # 1. A file handle for the output -# 2. A replacement file (directory actually) +# 2. A translation file # sub sgmlparse { - local($fhandle, $replacement) = @_; + local($ifhandle, $replacement) = @_; $defines = join(" -i ", @opt_i); if ($defines ne "") { $defines = "-i $defines"; } - $ENV{'SGML_PATH'} = "$replbase/$replacement.%N:$ENV{'SGML_PATH'}"; - open($fhandle, "sgmls $defines $decl $file | sgmlsasp $replbase/$replacement.mapping |"); + open($ifhandle, "$sgmls $defines $decl $file | " . + "$instant -Dfilename=$fileroot -t linuxdoc-${replacement}.ts |"); } # -# Generate nroff output +# Generate roff output # -sub gen_nroff { - open (outfile, ">$fileroot.nroff"); - &sgmlparse(infile, "nroff"); - $\ = "\n"; # automatically add newline on print - while () { - chop; - # This is supposed to ensure that no text line starts - # with a dot (.), thus confusing groff, but it doesn't - # appear to work. - unless (/^\.DS/.../^\.DE/) { - s/^[ \t]{1,}(.*)/$1/g; - } - s/^\.[ \t].*/\\\&$&/g; - print outfile; - } - $\ = ""; - close(infile); - close(outfile); -} - -# -# Generate ASCII output using groff -# - -sub gen_ascii { - &sgmlparse(infile, "nroff"); - open(outfile, "| groff -T ascii -t -ms | col -b > $fileroot.ascii"); +sub gen_roff { + open (outfile, ">$fileroot.roff"); + &sgmlparse(infile, "roff"); while () { print outfile; } @@ -151,18 +115,28 @@ sub gen_ascii { } # -# Generate Postscript output using groff (this is suboptimal -# for printed output!) +# Generate something from roff output # -sub gen_ps { - &sgmlparse(infile, "grops"); - open(outfile, "| groff -T ps -t -ms > $fileroot.ps"); +sub do_groff { + local($driver, $postproc) = @_; + open (outfile, ">$fileroot.trf"); + &sgmlparse(infile, "roff"); while () { print outfile; } close(infile); close(outfile); + system("groff -T ${driver} -t ${fileroot}.trf ${postproc} > ${fileroot}.${driver}"); + + # If foo.tmp has been created, then there are cross references + # in the file and we need a second pass to resolve them correctly. + + if (stat("${fileroot}.tmp")) { + system("groff -T ${driver} -t ${fileroot}.trf ${postproc} > ${fileroot}.${driver}"); + unlink("${fileroot}.qrf"); + } + unlink("${fileroot}.trf"); } # @@ -170,7 +144,7 @@ sub gen_ps { # sub gen_latex { - open(outfile, ">$fileroot.tex"); + open(outfile, ">$fileroot.latex"); &sgmlparse(infile, "latex"); while () { print outfile; @@ -544,29 +518,13 @@ sub html2html { last tagsw; } if (s/^<\@\@endref>//) { -# $text[$st_ol[$sc]] .= ""; + $text[$st_ol[$sc]] .= ""; last tagsw; } if (s/^<\@\@refnam>//) { - $text[$st_ol[$sc]] .= "$refname"; + $text[$st_ol[$sc]] .= "$refname"; last tagsw; } - # URLs - if (s/^<\@\@url>//) { - chop; - $urlname = $_; - $text[$st_ol[$sc]] .= ""; - last tagsw; - } - if (s/^<\@\@urlnam>//) { - $text[$st_ol[$sc]] .= "$urlname"; - last tagsw; - } - if (s/^<\@\@endurl>//) { -# $text[$st_ol[$sc]] .= ""; - last tagsw; - } - # If nothing else did anything with this line, just print it. $text[$st_ol[$sc]] .= "$_"; @@ -690,23 +648,25 @@ sub main { # Generate output if ($opt_f eq 'html') { - print "generating $fileroot.html"; - if ($opt_links == 1) { - print " with external links"; - } - print "...\n"; &gen_html(); + &gen_html(); } - elsif ($opt_f eq 'tex' || $opt_f eq 'latex') { - print "generating $fileroot.tex...\n"; &gen_latex(); + elsif ($opt_f eq 'latex' || $opt_f eq 'latex') { + &gen_latex(); } - elsif ($opt_f eq 'nroff') { - print "generating $fileroot.nroff...\n"; &gen_nroff(); + elsif ($opt_f eq 'roff') { + &gen_roff(); } elsif ($opt_f eq 'ascii') { - print "generating $fileroot.ascii...\n"; &gen_ascii(); + &do_groff("ascii", "| col"); } - elsif ($opt_f eq 'ps') { - print "generating $fileroot.ps...\n"; &gen_ps(); + elsif ($opt_f eq 'latin1') { + &do_groff("latin1", "| col"); + } + elsif ($opt_f eq 'koi8-r') { + &do_groff("koi8-r", "| col"); + } + elsif ($opt_f eq 'ps') { + &do_groff("ps", ""); } else { if ($opt_f eq "") {