summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbwarken <bwarken>2006-11-06 12:33:31 +0000
committerbwarken <bwarken>2006-11-06 12:33:31 +0000
commit7d573302b6b0865484180f6549187cfd106365b0 (patch)
tree55b89603e81641ee50be57a22564f862a618b3a6
parentd81498bed4e0d799cf753d9becf20040118dafa0 (diff)
downloadgroff-7d573302b6b0865484180f6549187cfd106365b0.tar.gz
Rewrite of grog.
-rw-r--r--ChangeLog49
-rw-r--r--NEWS2
-rw-r--r--src/roff/grog/Makefile.sub63
-rw-r--r--src/roff/grog/grog.man755
-rw-r--r--src/roff/grog/grog.pl537
-rw-r--r--src/roff/grog/grog.sh317
6 files changed, 1381 insertions, 342 deletions
diff --git a/ChangeLog b/ChangeLog
index 2a1897e6..45fe15a7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,52 @@
+2006-11-06 Bernd Warken
+
+ * src/roff/grog/grog.pl: Rewrite
+ - Call by `#! /usr/bin/env perl'. That isn't replaced.
+ - Rename usage() to version().
+ - Use warnings.
+ - For `use strict', start all global variables with an upper case
+ character. Use `my' for all variables. Use several new
+ variables.
+ - Add option `-h'.
+ - Add copyright to GPL and Emacs comment.
+ - Handle several `-m*' options.
+ - Fix handling of `-ms' and `-mm'. Add .TL and .NH.
+ - Allow options after file names.
+ - Allow only one `-' parameter (standard input).
+ - Add option abbreviations.
+ - Expand the usage information.
+ - Add `chem'.
+ - Add single quote "'" as additional first character and allow
+ arbitrary space after the first character.
+
+ * src/roff/grog/grog.sh: Rewrite
+ - Remove option `-e' of `sed'.
+ - Allow file names with space characters.
+ - Add option `-h'.
+ - Add copyright to GPL.
+ - Handle several `-m*' options.
+ - Fix handling of `-ms' and `-mm'. Add .TL and .NH.
+ - Allow options after file names.
+ - Allow only one `-' parameter (standard input).
+ - Add option abbreviations.
+ - Expand the usage information.
+ - Add `chem'.
+ - Add single quote "'" as additional first character and allow
+ arbitrary space after the first character.
+
+ * src/roff/grog/Makefile.sub:
+ - Add copyright to GPL.
+ - Remove `grog:'. Move `grog.old:' to `grog:' in order to have a
+ fair chance to choose between the shell version and the Perl
+ version of `grog'. This is now again comparable to grog in groff
+ version 1.10.
+
+ * src/roff/grog/grog.man: Rewrite
+ - Move the license to GPL.
+ - New sections: OPTIONS, DETAILS, EXAMPLES, COPYING.
+ - Take over some setup and macros from `groffer'.
+ - Add information on options.
+
2006-10-28 Werner LEMBERG <wl@gnu.org>
* tmac/trace.tmac: Improve tracing of `.nr'.
diff --git a/NEWS b/NEWS
index 6e92c45b..da7f58cf 100644
--- a/NEWS
+++ b/NEWS
@@ -63,6 +63,8 @@ o A new escape `\$^' has been added. It represents the parameters of a
o `groffer' version 1.* exists now in a shell and a Perl version.
+o Rewrite of `grog'.
+
Pic
---
diff --git a/src/roff/grog/Makefile.sub b/src/roff/grog/Makefile.sub
index 765d9285..94275609 100644
--- a/src/roff/grog/Makefile.sub
+++ b/src/roff/grog/Makefile.sub
@@ -1,33 +1,58 @@
+# Makefile.sub for `grog' (integration into the `groff' source tree)
+
+# File position: <groff-source>/src/roff/grog/Makefile.sub
+
+# Copyright (C) 1993, 2006 Free Software Foundation, Inc.
+
+# Last update: 4 Nov 2006
+
+# This file is part of `grog' which is part of `groff'.
+
+# `groff' is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+
+# `groff' is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with `groff'; see the files COPYING and LICENSE in the top
+# directory of the `groff' source. If not, write to the Free Software
+# Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA.
+
+########################################################################
+
MAN1=grog.n
CLEANADD=grog
-all: grog
-
-grog: grog.sh
- rm -f $@
- sed -e "s|@g@|$(g)|g" \
- -e "s|@EGREP@|$(EGREP)|g" \
- -e "s|@VERSION@|$(version)$(revision)|" \
- -e $(SH_SCRIPT_SED_CMD) $(srcdir)/grog.sh >$@
- chmod +x $@
+all: grog $(MAN1)
-grog.old: grog.pl grog.sh
- if test -n "$(PERLPATH)" && test -f "$(PERLPATH)"; then \
- rm -f $@; \
- sed -e "s|/usr/bin/perl|$(PERLPATH)|" \
- -e "s|@VERSION@|$(version)$(revision)|" $(srcdir)/grog.pl >$@; \
+grog: grog.pl grog.sh $(SH_DEPS_SED_SCRIPT)
+ -@rm -f $@;
+ if test -n "$(PERLPATH)" && test -f "$(PERLPATH)" && \
+ "$(PERLPATH)" -e 'require v5.6'; then \
+ echo 'Using the Perl version for grog.'; \
+ sed -f "$(SH_DEPS_SED_SCRIPT)" \
+ -e "s|@VERSION@|$(version)$(revision)|" \
+ -e "$(SH_SCRIPT_SED_CMD)" \
+ $(srcdir)/grog.pl >$@; \
else \
- rm -f $@; \
- sed -e "s|@g@|$(g)|g" \
+ echo 'Using the shell version for grog.'; \
+ sed -f "$(SH_DEPS_SED_SCRIPT)" \
+ -e "s|@g@|$(g)|g" \
-e "s|@EGREP@|$(EGREP)|g" \
-e "s|@VERSION@|$(version)$(revision)|" \
- -e $(SH_SCRIPT_SED_CMD) $(srcdir)/grog.sh >$@; \
+ -e "$(SH_SCRIPT_SED_CMD)" \
+ $(srcdir)/grog.sh >$@; \
fi
chmod +x $@
install_data: grog
- -test -d $(DESTDIR)$(bindir) || $(mkinstalldirs) $(DESTDIR)$(bindir)
- -rm -f $(DESTDIR)$(bindir)/grog
+ -@test -d $(DESTDIR)$(bindir) || $(mkinstalldirs) $(DESTDIR)$(bindir)
+ -@rm -f $(DESTDIR)$(bindir)/grog
$(INSTALL_SCRIPT) grog $(DESTDIR)$(bindir)/grog
uninstall_sub:
diff --git a/src/roff/grog/grog.man b/src/roff/grog/grog.man
index 44282337..198f8160 100644
--- a/src/roff/grog/grog.man
+++ b/src/roff/grog/grog.man
@@ -1,40 +1,453 @@
-.ig
-Copyright (C) 1989-2000, 2001, 2002, 2003 Free Software Foundation, Inc.
-
-Permission is granted to make and distribute verbatim copies of
-this manual provided the copyright notice and this permission notice
-are preserved on all copies.
-
-Permission is granted to copy and distribute modified versions of this
-manual under the conditions for verbatim copying, provided that the
-entire resulting derived work is distributed under the terms of a
-permission notice identical to this one.
-
-Permission is granted to copy and distribute translations of this
-manual into another language, under the above conditions for modified
-versions, except that this permission notice may be included in
-translations approved by the Free Software Foundation instead of in
-the original English.
-..
.TH GROG @MAN1EXT@ "@MDATE@" "Groff Version @VERSION@"
.SH NAME
grog \- guess options for groff command
.SH SYNOPSIS
-.B grog
-[
-.BI \- option
-\|.\|.\|.\&
-]
-[
-.IR files\ \|.\|.\|.\&
-]
+.\" The .SH was moved to this place in order to appease `apropos'.
+.
+.\" --------------------------------------------------------------------
+.\" Legalize
+.\" --------------------------------------------------------------------
+.
+.ig
+grog.1 - man page for grog (section 1)
+
+Source file position: <groff_source_top>/src/roff/grog/grog.man
+Installed position: $prefix/share/man/man1/grog.1
+
+Last Update: 6 Nov 2006
+..
+.de copyleft
+Copyright (C) 1989-2000,2001,2002,2003,2006
+Free Software Foundation, Inc.
+.
+Written by
+.MTO "" "James Clark" .
+Maintained by
+.MTO "wl@gnu.org" "Werner Lemberg" .
+Rewritten and put under GPL by
+.MTO "" "Bernd Warken" .
+.
+.
+.P
+This file is part of
+.IR \%grog ,
+which is part of
+.IR \%groff ,
+a free software project.
+.
+You can redistribute it and/or modify it under the terms of the
+.nh
+.B GNU General Public License
+.hy
+(\f[CR]GPL\f[]) as published by the
+.nh
+.BR "Free Software Foundation" ,
+.hy
+either version 2, or (at your option) any later version.
+.
+.P
+You should have received a copy of the \f[CR]GNU General Public
+License\f[] along with
+.IR groff ,
+see the files \%\f[CB]COPYING\f[] and \%\f[CB]LICENSE\f[] in the top
+directory of the
+.I groff
+source package.
+.
+Or read the
+.I man\~page
+.BR gpl (1).
+You can also write to the
+.nh
+.B Free Software Foundation, 51 Franklin St - Fifth Floor, Boston,
+.BR "MA 02110-1301, USA" .
+.hy
+..
+.
+.\" --------------------------------------------------------------------
+.\" Setup
+.\" --------------------------------------------------------------------
+.
+.mso www.tmac
+.
+.if n \{\
+. mso tty-char.tmac
+. ftr CR R
+. ftr CI I
+. ftr CB B
+.\}
+.
+.if '\*[.T]'dvi' \{\
+. ftr CB CW
+.\}
+.
+.ds Ellipsis "\&.\|.\|.\""
+.
+.\" --------------------------------------------------------------------
+.\" configuration of prompt for `.Shell_cmd'* macros
+.ds grog:Shell_cmd.prompt_text sh#\" prompt for shell commands
+.ds grog:Shell_cmd_base.prompt_font I\" font for prompts
+.
+.\" automatically determine setup from the configuration above
+.als @f grog:Shell_cmd_base.prompt_font\"
+.als @t grog:Shell_cmd.prompt_text\"
+.ds grog:Shell_cmd.prompt \f[\*[@f]]\*[@t]\f[]\" needed
+.nr @w \w'\*[grog:Shell_cmd.prompt]'\"
+.ft \*[@f]
+.\" Full prompt width is maximum of texts plus 1m
+.nr grog:Shell_cmd_base.prompt_width (\n[@w]>?\n[@w+]+1m)\" needed
+.ft
+.rm @f
+.rm @t
+.rr @w
+.
+.
+.\" --------------------------------------------------------------------
+.\" static register for inter-macro communication in `.Synopsis'*
+.nr grog:Synopsis.level 0
+.
+.\" --------------------------------------------------------------------
+.\" Macro definitions
+.
+.\" Ignore all arguments like a comment, even after a .eo call.
+.de c
+..
+.c --------------------------------------------------------------------
+.c .Synopsis ()
+.c
+.c Begin a synopsis section, to be ended by a ./Synopsis macro.
+.c
+.de Synopsis
+. if (\\n[grog:Synopsis.level] > 0) \
+. Error .\\$0: previous .Synopsis was not closed by ./Synopsis.
+. nh
+. ds @1 \\$1\"
+. nr @old_indent \\n(.i
+. ad l
+. in +\w'\fB\\*[@1]\0'u
+. ti \\n[@old_indent]u
+. B \\*[@1]\0\c
+. rr @old_indent
+. rm @1
+. nr grog:Synopsis.level +1\" marker for ./Synopsis
+..
+.c --------------------------------------------------------------------
+.c ./Synopsis ()
+.c
+.c Close a synopsis section opened by the previous .Synopsis macro.
+.c
+.de /Synopsis
+. if (\\n[grog:Synopsis.level] <= 0) \
+. Error .\\$0: no previous call of .Synopsis
+. br
+. ad
+. in
+. hy
+. nr grog:Synopsis.level -1
+..
+.c --------------------------------------------------------------------
+.c .Opt_alt ([<minus> <opt>]... [<arg> [<punct>]])
+.c
+.c Alternate options separated by a vertical bar.
+.c
+.c Arguments:
+.c minus: either `-' or `--' (font CB).
+.c opt: a name for an option, empty allowed (font CB).
+.c arg: optionally, the argument to the option (font I).
+.c punct: optional punctuation (in the starting font).
+.c Result:
+.c The minus/opt argument pairs, each
+.c separated by a vertical bar `|', optionally add 'arg', separated
+.c a space character ` '.
+.c
+.c Example:
+.c .Opt_alt - T -- device -- device-troff device .
+.c results in
+.c -T|--device|--device-troff device.
+.c
+.de Opt_alt
+. Opt_alt_base "" | "" \\$@
+..
+.c --------------------------------------------------------------------
+.c .Opt_alt_base (<pre> <sep> <post> [<minus> <opt>]... [arg [punct]])
+.c
+.c Alternating options; base macro for many others; do not use directly.
+.c
+.c Arguments:
+.c <pre>: prefix, result is preceded by this.
+.c <sep>: separator between minus/opt pairs.
+.c <post>: postfix, is appended to the result.
+.c <minus>: either `-' or `--' (font CB).
+.c <opt>: a name for an option, empty allowed (font CB).
+.c <arg>: optionally, the argument to the option (font I).
+.c <punct>: optional punctuation (in the starting font).
+.c Result:
+.c String `<pre>' followed by the <minus>/<opt> argument pairs, each
+.c separated by string `<sep>', optionally add '<arg>', separated by
+.c a single space ` ', followed by the string `<post>'. Terminated
+.c by the optional punctuation <punct>.
+.c
+.de Opt_alt_base
+. nr @font \\n[.f]\"
+. if (\\n[.$] < 3) \
+. Error .\\0: not enough arguments.
+. ds @pre \)\\$1\)\" prefix
+. ds @sep \)\\$2\)\" separator
+. ds @post \)\\$3\)\" postfix
+. shift 3
+. nr @count 0
+. ds @res \f[CR]\\*[@pre]\"
+. while (\\n[.$] >= 2) \{\
+. c do the pairs, break on no `-'
+. if !'\\$1'-' \{\
+. if !'\\$1'--' \
+. break
+. \}
+. c separator
+. if (\\n[@count] > 0) \
+. as @res \f[CR]\\*[@sep]\:\"
+. nr @count +1
+. c combine minus with option name
+. as @res \f[CB]\\-\"
+. if '\\$1'--' \
+. as @res \\-\"
+. as @res \\$2\"
+. shift 2
+. \}
+. if (\\n[.$] >= 3) \
+. Error .\\0: wrong arguments: \\$@
+. c all pairs are done
+. ie (\\n[.$] == 0) \
+. as @res \f[CR]\\*[@post]\"
+. el \{\
+. c optional option argument
+. if !'\\$1'' \
+. as @res \f[CR] \,\f[I]\\$1\"
+. shift
+. c postfix
+. as @res \\f[CR]\\*[@post]\"
+. if (\\n[.$] >= 1) \{\
+. c add punctuation
+. as @res \f[\\n[@font]]\\$1\"
+. \}
+. \}
+. nh
+. Text \\*[@res]
+. hy
+. ft \\n[@font]
+. rr @count
+. rr @font
+. rm @pre
+. rm @post
+. rm @sep
+. rm @res
+..
+.c --------------------------------------------------------------------
+.c .Text (<text>...)
+.c
+.c Treat the arguments as text, no matter how they look.
+.c
+.de Text
+. if (\\n[.$] == 0) \
+. return
+. nh
+. nop \)\\$*\)
+. hy
+..
+.c --------------------------------------------------------------------
+.c .File_name (<path_name>)
+.c
+.c Display a file or directory name in CB font.
+.c
+.de File_name
+. Header_CB \\$@
+..
+.c --------------------------------------------------------------------
+.c .Header_CB (<path_name>)
+.c
+.c Display a line in CB font, for example after .TP
+.c
+.de Header_CB
+. nh
+. Text \f[CB]\\$1\f[]\\$2
+. hy
+..
+.c --------------------------------------------------------------------
+.c .Topic ([<indent>])
+.c
+.c A bulleted paragraph
+.c
+.de Topic
+. ie (\\n[.$] = 0) \
+. ds @indent 2m\"
+. el \
+. ds @indent \\$1\"
+. TP \\*[@indent]
+. Text \[bu]
+. rm @indent
+..
+.c --------------------------------------------------------------------
+.c .Shell_cmd (<CR> [<CI>] ...)
+.c
+.c A shell command line; display args alternating in fonts CR and CI.
+.c
+.de Shell_cmd
+. grog:Shell_cmd_base "\*[grog:Shell_cmd.prompt]" \\$@
+..
+.c --------------------------------------------------------------------
+.c .Shell_cmd_base (<prompt> [<CR> [<CI>] ...])
+.c
+.c A shell command line; display args alternating in fonts CR and CI.
+.c Internal, do not use directly.
+.c
+.c Globals: read-only register @.Shell_cmd_width
+.c
+.de grog:Shell_cmd_base
+. if (\\n[.$] <= 0) \
+. return
+. nr @+font \\n[.f]\"
+. ds @prompt \\$1\"
+. ft CR
+. c gap between prompt and command
+. nr @+gap \\n[grog:Shell_cmd_base.prompt_width]-\\w'\\*[@prompt]'\"
+. ds @res \\*[@prompt]\h'\\n[@+gap]u'\"
+. shift
+. ds @cf CR\"
+. while (\\n[.$] > 0) \{\
+. as @res \\f[\\*[@cf]]\\$1\"
+. shift
+. ie '\\*[@cf]'CR' \
+. ds @cf I\"
+. el \
+. ds @cf CR\"
+. \}
+. br
+. ad l
+. nh
+. nf
+. Text \\*[@res]\"
+. fi
+. hy
+. ad
+. br
+. ft \\n[@+font]
+. rr @+font
+. rr @+gap
+. rm @cf
+. rm @res
+..
+.
+.\" End of macro definitions
+.
+.
+.\" --------------------------------------------------------------------
+.\" SH "SYNOPSIS"
+.\" --------------------------------------------------------------------
+.
+.ad l
+.Synopsis grog
+.RB [ \-C ]
+.RI [ groff\-option \*[Ellipsis]]
+.RB [ \-\- ]
+.RI [ \%filespec \*[Ellipsis]]
+./Synopsis
+.
+.Synopsis grog
+.Opt_alt - h -- help
+./Synopsis
+.
+.Synopsis grog
+.Opt_alt - v -- version
+./Synopsis
+.
+.
+.\" --------------------------------------------------------------------
.SH DESCRIPTION
+.\" --------------------------------------------------------------------
+.
.B grog
-reads
-.I files
-and guesses which of the
+reads the input (file names or standard input) and guesses which of
+the
.BR groff (@MAN1EXT@)
-options
+options are needed to perform the input with the
+.B groff
+program.
+.
+The corresponding
+.B groff
+command is output.
+.
+.
+.\" --------------------------------------------------------------------
+.SH "OPTIONS"
+.\" --------------------------------------------------------------------
+.
+The only
+.B grog
+options recognized are
+.B \-C
+(which is also passed on) to enable compatibility mode;
+.B \-v
+and
+.B \-\-version
+print information on the version number; and
+.B \-h
+and
+.B \-\-help
+print usage information.
+.
+.BR \-v ,
+.BR \-\-version ,
+.BR \-h ,
+and
+.B \-\-help
+stop the program directly without printing a
+.B groff
+command to standard output.
+.
+.
+.P
+All other specified short options (words starting with one minus
+character
+.BR \- )
+are interpreted as
+.B groff
+options or option clusters with or without argument.
+.
+No space is allowed between options and their argument.
+.
+Except from the
+.BI \-m arg
+options, all options will be passed on, i.e. they are included
+unchanged in the command for the output without effecting the work of
+.BR grog .
+.
+.
+.P
+A
+.I filespec
+argument can either be the name of an existing file or a single minus
+.B \-
+to mean standard input.
+.
+If no
+.I filespec
+is specified standard input is read automatically.
+.
+.
+.\" --------------------------------------------------------------------
+.SH "DETAILS"
+.\" --------------------------------------------------------------------
+.
+.B grog
+reads all
+.I filespec
+parameters as a whole.
+.
+It tries to guess which of the following
+.B groff
+options are required for running the input under
+.BR groff :
.BR \-e ,
.BR \-man ,
.BR \-me ,
@@ -49,33 +462,246 @@ options
.BR \-G ,
.BR \-s ,
and
-.BR \-t
-are required for printing
-.IR files ,
-and prints the groff command including those options on the standard output.
-A filename of
-.B \-
-is taken to refer to the standard input.
-If no files are specified the standard input will be read.
-Any specified options will be included in the printed command.
-No space is allowed between options and their arguments.
-The only options recognized are
-.B \-C
-(which is also passed on) to enable compatibility mode, and
-.B \-v
-to print the version number.
-.LP
-For example,
-.IP
-.B \`grog \-Tdvi paper.ms\`
-.LP
-will guess the appropriate command to print
-.B paper.ms
-and then run it after adding the
-.B \-Tdvi
+.BR \-t .
+The guessed
+.B groff
+command including those options and the found
+.I filespec
+parameters is put on the standard output.
+.
+.
+.P
+It is possible to specify arbitrary
+.B groff
+options on the command line.
+.
+These are passed on the output without change, except for the
+.BI \-m arg
+options.
+.
+.
+.P
+The
+.B groff
+program has trouble when the wrong
+.BI \-m arg
+option or several of these options are specified.
+.
+In these cases,
+.B grog
+will print an error message and exit with an error code.
+.
+It is better to specify no
+.BI \-m arg
option.
+.
+Because such an option is only accepted and passed when
+.B grog
+does not find any of these options or the same option is found.
+.
+.
+.P
+If several different
+.BI \-m arg
+options are found by
+.B grog
+an error message is produced and the program is terminated with an
+error code.
+.
+But the output is written with the wrong options nevertheless.
+.
+.
+.P
+Remember that it is not necessary to determine a macro package.
+.
+A
+.I roff
+file can also be written in the
+.I groff
+language without any macro package.
+.
+.B grog
+will produce an output without an
+.BI \-m arg
+option.
+.
+.
+.P
+As
+.B groff
+also works with pure text files without any
+.I roff
+requests,
+.B grog
+cannot be used to identify a file to be a
+.I roff
+file.
+.
+.
+.P
+The
+.BR groffer (@MAN1EXT@)
+program heavily depends on a working
+.BR grog .
+.
+.
+.P
+The
+.B grog
+source contains two files written in different programming languages:
+.
+.ft CB
+grog.pl
+.ft R
+is the
+.I Perl
+version, while
+.ft CB
+grog.sh
+.ft R
+is a shell script using
+BR awk (1).
+During the run of
+.BR make (1),
+it is determined whether the system contains a suitable version of
+.BR perl (1).
+If so,
+.ft CB
+grog.pl
+.ft R
+is transformed into
+.BR grog ;
+otherwise
+.ft CB
+grog.sh
+.ft R
+is used instead.
+.
+.
+.\" --------------------------------------------------------------------
+.SH "EXAMPLES"
+.\" --------------------------------------------------------------------
+.
+.Topic
+Calling
+.RS
+.IP
+.Shell_cmd "grog meintro.me"
+.P
+results in
+.IP
+.ft CR
+groff \-me meintro.me
+.ft
+.P
+So
+.B grog
+recognized that the file
+.File_name meintro.me
+is written with the
+.B \-me
+macro package.
+.RE
+.
+.
+.Topic
+On the other hand,
+.RS
+.IP
+.Shell_cmd "grog pic.ms"
+.P
+outputs
+.IP
+.ft CR
+groff \-pte \-ms pic.ms
+.ft
+.P
+Besides determining the macro package
+.BR \-ms ,
+.B grog
+recognized that the file
+.File_name pic.ms
+additionally needs
+.BR \-pte ,
+the combination of
+.B \-p
+for
+.IR pic ,
+.B \-t
+for
+.IR tbl ,
+and
+.B \-e
+for
+.IR eqn .
+.RE
+.
+.
+.Topic
+If both files are combined by the command
+.RS
+.IP
+.Shell_cmd "grog meintro.me pic.ms"
+.P
+an error message is sent to standard error because
+.B groff
+cannot work with two different macro packages:
+.IP
+.ft CR
+grog: error: there are several macro packages: -me -ms
+.ft
+.P
+Additionally the corresponding output with the wrong options is printed
+to standard output:
+.IP
+.ft CR
+groff -pte -me -ms meintro.me pic.ms
+.ft
+.P
+But the program is terminated with an error code.
+.RE
+.
+.
+.Topic
+The call of
+.RS
+.IP
+.Shell_cmd "grog \-ksS \-Tdvi grnexmpl.g"
+.P
+contains several
+.B groff
+options that are just passed on the output without any interface to
+.BR grog .
+These are the option cluster
+.B \-ksS
+consisting of
+.BR \-k ,
+.BR \-s ,
+and
+.BR \-S ;
+and the option
+.B \-T
+with argument
+.BR dvi .
+The output is
+.IP
+.ft CR
+groff \-ksS \-Tdvi grnexmpl.g
+.ft
+.P
+so no additional option was added by
+.BR grog .
+As no option
+.BI \-m arg
+was found by
+.B grog
+this file does not use a macro package.
+.RE
+.
+.
+.\" --------------------------------------------------------------------
.SH "SEE ALSO"
-.BR doctype (1),
+.\" --------------------------------------------------------------------
.BR groff (@MAN1EXT@),
.BR @g@troff (@MAN1EXT@),
.BR @g@tbl (@MAN1EXT@),
@@ -84,7 +710,24 @@ option.
.BR @g@refer (@MAN1EXT@),
.BR @g@grn (@MAN1EXT@),
.BR grap (1),
-.BR @g@soelim (@MAN1EXT@)
+.BR @g@soelim (@MAN1EXT@),
+.BR groff_me (@MAN7EXT@),
+.BR groff_ms (@MAN7EXT@),
+.BR groff_mm (@MAN7EXT@),
+.BR groff_mom (@MAN7EXT@),
+.BR groff_man (@MAN7EXT@),
+.BR groffer (@MAN1EXT@)
+.
+.
+.\" --------------------------------------------------------------------
+.SH "COPYING"
+.\" --------------------------------------------------------------------
+.copyleft
+.
+.
+.\" --------------------------------------------------------------------
+.\" Emacs settings
+.\" --------------------------------------------------------------------
.
.\" Local Variables:
.\" mode: nroff
diff --git a/src/roff/grog/grog.pl b/src/roff/grog/grog.pl
index b802fd56..60f0dfec 100644
--- a/src/roff/grog/grog.pl
+++ b/src/roff/grog/grog.pl
@@ -1,222 +1,373 @@
-#! /usr/bin/perl
-# grog -- guess options for groff command
+#! /usr/bin/env perl
+# grog - guess options for groff command
# Inspired by doctype script in Kernighan & Pike, Unix Programming
# Environment, pp 306-8.
-$prog = $0;
-$prog =~ s@.*/@@;
+# Source file position: <groff-source>/src/roff/grog/grog.pl
+# Installed position: <prefix>/bin/grog
-$sp = "[\\s\\n]";
+# Copyright (C) 1993, 2006 Free Software Foundation, Inc.
+# Written by James Clark, maintained by Werner Lemberg.
+# Rewritten and put under GPL by Bernd Warken.
-push(@command, "groff");
+# This file is part of `grog', which is part of `groff'.
-while ($ARGV[0] =~ /^-./) {
- $arg = shift(@ARGV);
- $sp = "" if $arg eq "-C";
- &usage(0) if $arg eq "-v" || $arg eq "--version";
- &help() if $arg eq "--help";
- last if $arg eq "--";
- push(@command, $arg);
-}
+# `groff' is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License (GPL) as published
+# by the Free Software Foundation; either version 2, or (at your
+# option) any later version.
+
+# `groff' is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with `groff'; see the files COPYING and LICENSE in the top
+# directory of the `groff' source. If not, write to the Free Software
+# Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301,
+# USA.
+
+########################################################################
+my $Last_Update = '6 Nov 2006';
+########################################################################
+
+require v5.6;
-@ARGV = ('-') unless @ARGV;
-foreach $arg (@ARGV) {
- &process($arg, 0);
+use warnings;
+use strict;
+use File::Spec;
+
+my $Prog = $0;
+{
+ my ($v, $d, $f) = File::Spec->splitpath($Prog);
+ $Prog = $f;
}
-sub process {
- local($filename, $level) = @_;
- local(*FILE);
+my $Sp = "[\\s\\n]";
+
+my @Command; # stores the final output
+my @Mparams; # stores the options -m*
+my %Groff;
+
+{
+ my @filespec = ();
+ my $double_minus = 0;
+ my $was_minus = 0;
+ my $had_filespec = 0;
- if (!open(FILE, $filename eq "-" ? $filename : "< $filename")) {
- print STDERR "$prog: can't open \`$filename': $!\n";
- exit 1 unless $level;
- return;
+ foreach my $arg (@ARGV) {
+ next unless $arg;
+ if ($double_minus) {
+ $had_filespec = 1;
+ if (-f $arg && -r $arg) {
+ push @filespec, $arg;
+ } else {
+ print STDERR "grog: $arg is not a readable file.\n";
+ }
+ next;
}
- while (<FILE>) {
- if (/^\.TS$sp/) {
- $_ = <FILE>;
- if (!/^\./) {
- $tbl++;
- $soelim++ if $level;
- }
- }
- elsif (/^\.EQ$sp/) {
- $_ = <FILE>;
- if (!/^\./ || /^\.[0-9]/) {
- $eqn++;
- $soelim++ if $level;
- }
- }
- elsif (/^\.GS$sp/) {
- $_ = <FILE>;
- if (!/^\./) {
- $grn++;
- $soelim++ if $level;
- }
- }
- elsif (/^\.G1$sp/) {
- $_ = <FILE>;
- if (!/^\./) {
- $grap++;
- $pic++;
- $soelim++ if $level;
- }
- }
- elsif (/^\.PS$sp([ 0-9.<].*)?$/) {
- if (/^\.PS\s*<\s*(\S+)/) {
- $pic++;
- $soelim++ if $level;
- &process($1, $level);
- }
- else {
- $_ = <FILE>;
- if (!/^\./ || /^\.ps/) {
- $pic++;
- $soelim++ if $level;
- }
- }
- }
- elsif (/^\.R1$sp/) {
- $refer++;
- $soelim++ if $level;
- }
- elsif (/^\.\[/) {
- $refer_open++;
- $soelim++ if $level;
- }
- elsif (/^\.\]/) {
- $refer_close++;
- $soelim++ if $level;
- }
- elsif (/^\.[PLI]P$sp/) {
- $PP++;
- }
- elsif (/^\.P$/) {
- $P++;
- }
- elsif (/^\.(PH|SA)$sp/) {
- $mm++;
- }
- elsif (/^\.TH$sp/) {
- $TH++;
- }
- elsif (/^\.SH$sp/) {
- $SH++;
- }
- elsif (/^\.([pnil]p|sh)$sp/) {
- $me++;
- }
- elsif (/^\.Dd$sp/) {
- $mdoc++;
- }
- elsif (/^\.(Tp|Dp|De|Cx|Cl)$sp/) {
- $mdoc_old = 1;
- }
- # In the old version of -mdoc `Oo' is a toggle, in the new it's
- # closed by `Oc'.
- elsif (/^\.Oo$sp/) {
- $Oo++;
- s/^\.Oo/\. /;
- redo;
- }
- # The test for `Oo' and `Oc' not starting a line (as allowed by the
- # new implementation of -mdoc) is not complete; it assumes that
- # macro arguments are well behaved, i.e., "" is used within "..." to
- # indicate a doublequote as a string element, and weird features
- # like `.foo a"b' are not used.
- elsif (/^\..* Oo( |$)/) {
- s/\\\".*//;
- s/\"[^\"]*\"//g;
- s/\".*//;
- if (s/ Oo( |$)/ /) {
- $Oo++;
- }
- redo;
- }
- elsif (/^\.Oc$sp/) {
- $Oo--;
- s/^\.Oc/\. /;
- redo;
- }
- elsif (/^\..* Oc( |$)/) {
- s/\\\".*//;
- s/\"[^\"]*\"//g;
- s/\".*//;
- if (s/ Oc( |$)/ /) {
- $Oo--;
- }
- redo;
- }
- elsif (/^\.(PRINTSTYLE|START)$sp/) {
- $mom++;
- }
- if (/^\.so$sp/) {
- chop;
- s/^.so *//;
- s/\\\".*//;
- s/ .*$//;
- &process($_, $level + 1) unless /\\/ || $_ eq "";
- }
+
+ if ($arg eq '--') {
+ $double_minus = 1;
+ push(@Command, $arg);
+ next;
+ }
+ if ($arg eq '-') {
+ unless ($was_minus) {
+ push @filespec, $arg;
+ $was_minus = 1;
+ }
+ next;
}
- close(FILE);
-}
-sub usage {
- local($exit_status) = $_;
- print "GNU grog (groff) version @VERSION@\n";
- exit $exit_status;
+ &version(0) if $arg eq '-v' || '--version' =~ /^$arg/;
+ &help() if $arg eq '-h' || '--help' =~ /^$arg/;
+ print STDERR "grog: wrong option $arg.\n" if $arg =~ /^--/;
+
+ if ($arg =~ /^-m/) {
+ push @Mparams, $arg;
+ next;
+ }
+ $Sp = '' if $arg eq '-C';
+
+ if ($arg =~ /^-/) {
+ push(@Command, $arg);
+ next;
+ } else {
+ $had_filespec = 1;
+ if (-f $arg && -r $arg) {
+ push @filespec, $arg;
+ } else {
+ print STDERR "grog: $arg is not a readable file.\n";
+ }
+ next;
+ }
+ }
+ @filespec = ('-') if ! @filespec && ! $had_filespec;
+ exit 1 unless @filespec;
+ @ARGV = @filespec;
}
-sub help {
- print "usage: grog [ option ...] [files...]\n";
- exit 0;
+foreach my $arg (@ARGV) {
+ &process($arg, 0);
}
-$refer ||= $refer_open && $refer_close;
+sub process {
+ my ($filename, $level) = @_;
+ local(*FILE);
-if ($pic || $tbl || $eqn || $grn || $grap || $refer) {
- $s = "-";
- $s .= "s" if $soelim;
- $s .= "R" if $refer;
- # grap must be run before pic
- $s .= "G" if $grap;
- $s .= "p" if $pic;
- $s .= "g" if $grn;
- $s .= "t" if $tbl;
- $s .= "e" if $eqn;
- push(@command, $s);
-}
+ if (!open(FILE, $filename eq "-" ? $filename : "< $filename")) {
+ print STDERR "$Prog: can't open \`$filename': $!\n";
+ exit 1 unless $level;
+ return;
+ }
+ while (<FILE>) {
+ s/^[.']\s*/./;
+ s/^\s+|\s+$//g;
-if ($me > 0) {
- push(@command, "-me");
-}
-elsif ($SH > 0 && $TH > 0) {
- push(@command, "-man");
-}
-else ($mom > 0) {
- push(@command, "-mom");
-}
-elsif ($PP > 0) {
- push(@command, "-ms");
+ if (/^(.cstart)|(begin\s+chem)$/) {
+ $Groff{'chem'}++;
+ $Groff{'pic'}++;
+ } elsif (/^\.TS$Sp/) {
+ $_ = <FILE>;
+ if (!/^\./) {
+ $Groff{'tbl'}++;
+ $Groff{'soelim'}++ if $level;
+ }
+ } elsif (/^\.EQ$Sp/) {
+ $_ = <FILE>;
+ if (!/^\./ || /^\.[0-9]/) {
+ $Groff{'eqn'}++;
+ $Groff{'soelim'}++ if $level;
+ }
+ } elsif (/^\.GS$Sp/) {
+ $_ = <FILE>;
+ if (!/^\./) {
+ $Groff{'grn'}++;
+ $Groff{'soelim'}++ if $level;
+ }
+ } elsif (/^\.G1$Sp/) {
+ $_ = <FILE>;
+ if (!/^\./) {
+ $Groff{'grap'}++;
+ $Groff{'pic'}++;
+ $Groff{'soelim'}++ if $level;
+ }
+ } elsif (/^\.PS$Sp([ 0-9.<].*)?$/) {
+ if (/^\.PS\s*<\s*(\S+)/) {
+ $Groff{'pic'}++;
+ $Groff{'soelim'}++ if $level;
+ &process($1, $level);
+ } else {
+ $_ = <FILE>;
+ if (!/^\./ || /^\.ps/) {
+ $Groff{'pic'}++;
+ $Groff{'soelim'}++ if $level;
+ }
+ }
+ } elsif (/^\.R1$Sp/) {
+ $Groff{'refer'}++;
+ $Groff{'soelim'}++ if $level;
+ } elsif (/^\.\[/) {
+ $Groff{'refer_open'}++;
+ $Groff{'soelim'}++ if $level;
+ } elsif (/^\.\]/) {
+ $Groff{'refer_close'}++;
+ $Groff{'soelim'}++ if $level;
+ } elsif (/^\.NH$Sp/) {
+ $Groff{'NH'}++; # for ms
+ } elsif (/^\.TL$Sp/) {
+ $Groff{'TL'}++; # for mm and ms
+ } elsif (/^\.PP$Sp/) {
+ $Groff{'PP'}++; # for mom and ms
+ } elsif (/^\.[IL]P$Sp/) {
+ $Groff{'ILP'}++; # for man and ms
+ } elsif (/^\.P$/) {
+ $Groff{'P'}++;
+ } elsif (/^\.(PH|SA)$Sp/) {
+ $Groff{'mm'}++;
+ } elsif (/^\.TH$Sp/) {
+ $Groff{'TH'}++;
+ } elsif (/^\.SH$Sp/) {
+ $Groff{'SH'}++;
+ } elsif (/^\.([pnil]p|sh)$Sp/) {
+ $Groff{'me'}++;
+ } elsif (/^\.Dd$Sp/) {
+ $Groff{'mdoc'}++;
+ } elsif (/^\.(Tp|Dp|De|Cx|Cl)$Sp/) {
+ $Groff{'mdoc_old'} = 1;
+ }
+ # In the old version of -mdoc `Oo' is a toggle, in the new it's
+ # closed by `Oc'.
+ elsif (/^\.Oo$Sp/) {
+ $Groff{'Oo'}++;
+ s/^\.Oo/\. /;
+ redo;
+ }
+ # The test for `Oo' and `Oc' not starting a line (as allowed by the
+ # new implementation of -mdoc) is not complete; it assumes that
+ # macro arguments are well behaved, i.e., "" is used within "..." to
+ # indicate a doublequote as a string element, and weird features
+ # like `.foo a"b' are not used.
+ elsif (/^\..* Oo( |$)/) {
+ s/\\\".*//;
+ s/\"[^\"]*\"//g;
+ s/\".*//;
+ if (s/ Oo( |$)/ /) {
+ $Groff{'Oo'}++;
+ }
+ redo;
+ } elsif (/^\.Oc$Sp/) {
+ $Groff{'Oo'}--;
+ s/^\.Oc/\. /;
+ redo;
+ } elsif (/^\..* Oc( |$)/) {
+ s/\\\".*//;
+ s/\"[^\"]*\"//g;
+ s/\".*//;
+ if (s/ Oc( |$)/ /) {
+ $Groff{'Oo'}--;
+ }
+ redo;
+ } elsif (/^\.(PRINTSTYLE|START)$Sp/) {
+ $Groff{'mom'}++;
+ }
+ if (/^\.so$Sp/) {
+ chop;
+ s/^.so *//;
+ s/\\\".*//;
+ s/ .*$//;
+ &process($_, $level + 1) unless /\\/ || $_ eq "";
+ }
+ }
+ close(FILE);
}
-elsif ($P > 0 || $mm > 0) {
- push(@command, "-mm");
+
+sub help {
+ print <<EOF;
+usage: grog [option]... [--] [filespec]...
+
+"filespec" is either the name of an existing, readable file or "-" for
+standard input. If no "filespec" is specified, standard input is
+assumed automatically.
+
+"option" is either a "groff" option or one of these:
+
+-C compatibility mode
+-h --help print this uasge message
+-v --version print version information
+
+"groff" options are appended to the output, "-m" options are checked.
+
+EOF
+ exit 0;
}
-elsif ($mdoc > 0) {
- push(@command, ($mdoc_old || $Oo > 0) ? "-mdoc-old" : "-mdoc");
+
+sub version {
+ my ($exit_status) = @_;
+ print "Perl version of GNU $Prog of $Last_Update " .
+ "in groff version @VERSION@\n";
+ exit $exit_status;
}
-push(@command, "--") if @ARGV && $ARGV[0] =~ /^-./;
+{
+ my @m = ();
+ my $is_man = 0;
+ my $is_mm = 0;
+ my $is_mom = 0;
+
+ $Groff{'refer'} ||= $Groff{'refer_open'} && $Groff{'refer_close'};
-push(@command, @ARGV);
+ if ( $Groff{'pic'} || $Groff{'tbl'} || $Groff{'eqn'} ||
+ $Groff{'grn'} || $Groff{'grap'} || $Groff{'refer'} ) {
+ my $s = "-";
+ $s .= "s" if $Groff{'soelim'};
+ $s .= "R" if $Groff{'refer'};
+ # grap must be run before pic
+ $s .= "G" if $Groff{'grap'};
+ $s .= "p" if $Groff{'pic'};
+ $s .= "g" if $Groff{'grn'};
+ $s .= "t" if $Groff{'tbl'};
+ $s .= "e" if $Groff{'eqn'};
+ push(@Command, $s);
+ }
+
+ if ( $Groff{'me'} ) {
+ push(@m, '-me');
+ push(@Command, '-me');
+ }
+ if ( $Groff{'SH'} && $Groff{'TH'} ) {
+ push(@m, '-man');
+ push(@Command, '-man');
+ $is_man = 1;
+ }
+ if ( $Groff{'mom'} ) {
+ push(@m, '-mom');
+ push(@Command, '-mom');
+ $is_mom = 1;
+ }
+ if ( $Groff{'mm'} || ($Groff{'P'} && ! $is_man) ) {
+ push(@m, '-mm');
+ push(@Command, '-mm');
+ $is_mm = 1;
+ }
+ if ( $Groff{'NH'} || ($Groff{'TL'} && ! $is_mm) ||
+ ($Groff{'ILP'} && ! $is_man) ||
+ ($Groff{'PP'} && ! $is_mom && ! $is_man) ) {
+ # .PP occurs in -mom, -man and -ms, .IP and .LP occur in -man and -ms
+ push(@m, '-ms');
+ push(@Command, '-ms');
+ }
+ if ( $Groff{'mdoc'} ) {
+ my $s = ( $Groff{'mdoc_old'} || $Groff{'Oo'} ) ? '-mdoc-old' : '-mdoc';
+ push(@m, $s);
+ push(@Command, $s);
+ }
-# We could implement an option to execute the command here.
+ if ($Groff{'chem'}) {
+ my @chem = ('chem', @ARGV, '|', 'groff');
+ unshift(@Command, @chem);
+ } else {
+ unshift @Command, 'groff';
+ push(@Command, @ARGV);
+ }
-foreach (@command) {
- next unless /[\$\\\"\';&()|<> \t\n]/;
- s/\'/\'\\\'\'/;
+ foreach (@Command) {
+ next unless /\s/;
$_ = "'" . $_ . "'";
+ }
+
+ # We could implement an option to execute the command here.
+
+# foreach (@Command) {
+# next unless /[\$\\\"\';&()|<> \t\n]/;
+# s/\'/\'\\\'\'/;
+# $_ = "'" . $_ . "'";
+# }
+
+ my $n = scalar @m;
+ my $np = scalar @Mparams;
+ print STDERR "$Prog: more than 1 `-m' argument: @Mparams" if $np > 1;
+ if ($n == 0) {
+ unshift @Command, $Mparams[0] if $np == 1;
+ } elsif ($n == 1) {
+ if ($np == 1) {
+ print STDERR "$Prog: wrong `-m' argument: $Mparams[0]\n"
+ if $m[0] ne $Mparams[0];
+ }
+ } else {
+ print STDERR "$Prog: error: there are several macro packages: @m\n";
+ }
+
+ print "@Command\n";
+
+ exit $n if $n > 1;
+ exit 0;
}
-print join(' ', @command), "\n";
+########################################################################
+### Emacs settings
+# Local Variables:
+# mode: CPerl
+# End:
diff --git a/src/roff/grog/grog.sh b/src/roff/grog/grog.sh
index 3323763f..428ef976 100644
--- a/src/roff/grog/grog.sh
+++ b/src/roff/grog/grog.sh
@@ -2,44 +2,169 @@
# grog -- guess options for groff command
# Like doctype in Kernighan & Pike, Unix Programming Environment, pp 306-8.
+# Source file position: <groff-source>/src/roff/grog/grog.sh
+# Installed position: <prefix>/bin/grog
+
+# Copyright (C) 1993, 2006 Free Software Foundation, Inc.
+# Written by James Clark, maintained by Werner Lemberg.
+# Rewritten by and put under GPL Bernd Warken.
+
+# This file is part of `grog', which is part of `groff'.
+
+# `groff' is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License (GPL) as published
+# by the Free Software Foundation; either version 2, or (at your
+# option) any later version.
+
+# `groff' is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with `groff'; see the files COPYING and LICENSE in the top
+# directory of the `groff' source. If not, write to the Free Software
+# Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301,
+# USA.
+
+########################################################################
+Last_Update='6 Nov 2006'
+########################################################################
+
soelim=@g@soelim
opts=
+mopt=
+nr=0
sp="([ ]|$)"
+double_minus=0
+was_minus=0
+filespec=
+had_filespec=0
for arg
do
- case "$arg" in
- --)
- shift; break;;
- -)
- break;;
- -C)
- sp=; opts="$opts -C"; shift; break;;
- -v | --version)
- echo "GNU grog (groff) version @VERSION@"
- exit 0;;
- --help)
- echo "usage: grog [ option ...] [files...]"
- exit 0;;
- -*)
- opts="$opts $arg"; shift;;
- *)
- break;;
- esac
+ if test _"${double_minus}"_ = _1_
+ then
+ had_filespec=1
+ if test -f "${arg}" && test -r "${arg}"
+ then
+ case "$arg" in
+ *" "*)
+ eval filespec="'${filespec} '"'\"'"'${arg}'"'\"'
+ ;;
+ *)
+ eval filespec="'${filespec} ${arg}'"
+ ;;
+ esac
+ else
+ echo "grog: ${arg} is not a readable file.">&2
+ fi
+ continue
+ fi
+ case "$arg" in
+ --)
+ double_minus=1
+ ;;
+ -)
+ # omit several -
+ if test _"${was_minus}"_ = _0_
+ then
+ was_minus=1
+ filespec="${filespec} -"
+ fi
+ ;;
+ -C)
+ sp=; opts="$opts -C";
+ ;;
+ -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
+ echo \
+"Shell version of GNU grog of $Last_Update in groff version @VERSION@";
+ exit 0
+ ;;
+ -h|--h|--he|--hel|--help)
+ cat <<EOF
+
+usage: grog [option]... [--] [filespec]...
+
+"filespec" is either the name of an existing, readable file or "-" for
+standard input. If no "filespec" is specified, standard input is
+assumed automatically.
+
+"option" is either a "groff" option or one of these:
+
+-C compatibility mode
+-h --help print this uasge message and exit
+-v --version print version information and exit
+
+"groff" options are appended to the output, "-m" options are checked.
+
+EOF
+ exit 0
+ ;;
+ -m*)
+ if test _"$nr"_ = _0_
+ then
+ nr=1
+ mopt="$arg"
+ else
+ echo "grog: several -m* options are not allowed." >&2
+ mopt=
+ fi
+ ;;
+ -*)
+ opts="$opts $arg"
+ ;;
+ *)
+ had_filespec=1
+ if test -f "${arg}" && test -r "${arg}"
+ then
+ case "$arg" in
+ *" "*)
+ eval filespec="'${filespec} '"'\"'"'${arg}'"'\"'
+ ;;
+ *)
+ eval filespec="'${filespec} ${arg}'"
+ ;;
+ esac
+ else
+ echo "grog: ${arg} is not a readable file.">&2
+ fi
+ ;;
+ esac
done
+if test _"${filespec}"_ = __ && test _"${had_filespec}"_ = _0_
+then
+ filespec='-'
+fi
+if test _"${filespec}"_ = __
+then
+ exit 1
+fi
+if test "${double_minus}" = 1
+then
+ eval files="'-- ${filespec}'"
+else
+ eval files="'${filespec}'"
+fi
+files=`echo $files|sed s/\"/\'/g`
-@EGREP@ -h \
- "^\.(\[|\])|((P|PS|[PLI]P|[pnil]p|sh|Dd|Tp|Dp|De|Cx|Cl|Oo|.* Oo|Oc|.* Oc|TS|TE|EQ|TH|SH|so|\[|R1|GS|G1|PH|SA)$sp)" $* \
-| sed -e '/^\.so/s/^.*$/.SO_START\
+
+eval sed "'s/[ ]*$//'" '--' "${filespec}" \
+| sed 's/^[ ]*begin[ ][ ]*chem$/.cstart/' \
+| sed 's/^[.'"'"'][ ]*/./' \
+| @EGREP@ -h \
+ "^\.(\[|\])|cstart|((P|PS|[PLI]P|[pnil]p|sh|Dd|Tp|Dp|De|Cx|Cl|Oo|.* Oo|Oc|.* Oc|NH|TL|TS|TE|EQ|TH|SH|so|\[|R1|GS|G1|PH|SA)$sp)" \
+| sed '/^\.so/s/^.*$/.SO_START\
&\
.SO_END/' \
| $soelim \
| @EGREP@ \
- '^\.(P|PS|[PLI]P|[pnil]p|sh|Dd|Tp|Dp|De|Cx|Cl|Oo|.* Oo|Oc|.* Oc|TS|TE|EQ|TH|SH|\[|\]|R1|GS|G1|PH|SA|SO_START|SO_END)' \
+ '^\.(cstart|P|PS|[PLI]P|[pnil]p|sh|Dd|Tp|Dp|De|Cx|Cl|Oo|.* Oo|Oc|.* Oc|NH|TL|TS|TE|EQ|TH|TL|NH|SH|\[|\]|R1|GS|G1|PH|SA|SO_START|SO_END)' \
| awk '
/^\.SO_START$/ { so = 1 }
/^\.SO_END$/ { so = 0 }
+/^\.cstart$/ { chem++ }
/^\.TS/ { tbl++; in_tbl = 1; if (so > 0) soelim++; }
/^\.TE/ { in_tbl = 0 }
/^\.PS([ 0-9.<].*)?$/ { pic++; if (so > 0) soelim++ }
@@ -50,7 +175,10 @@ done
/^\.GS/ { grn++; if (so > 0) soelim++ }
/^\.G1/ { grap++; pic++; if (so > 0) soelim++ }
/^\.TH/ { if (in_tbl != 1) TH++ }
-/^\.[PLI]P/ { PP++ }
+/^\.PP/ { PP++ }
+/^\.TL/ { TL++ }
+/^\.NH/ { NH++ }
+/^\.[IL]P/ { ILP++ }
/^\.P$/ { P++ }
/^\.SH/ { SH++ }
/^\.(PH|SA)/ { mm++ }
@@ -58,58 +186,99 @@ done
/^\.Dd/ { mdoc++ }
/^\.(Tp|Dp|De|Cx|Cl)/ { mdoc_old++ }
/^\.(O[oc]|.* O[oc]( |$))/ {
- sub(/\\\".*/, "")
- gsub(/\"[^\"]*\"/, "")
- sub(/\".*/, "")
- sub(/^\.Oo/, " Oo ")
- sub(/^\.Oc/, " Oc ")
- sub(/ Oo$/, " Oo ")
- sub(/ Oc$/, " Oc ")
- while (/ Oo /) {
- sub(/ Oo /, " ")
- Oo++
- }
- while (/ Oc /) {
- sub(/ Oc /, " ")
- Oo--
- }
+ sub(/\\\".*/, "")
+ gsub(/\"[^\"]*\"/, "")
+ sub(/\".*/, "")
+ sub(/^\.Oo/, " Oo ")
+ sub(/^\.Oc/, " Oc ")
+ sub(/ Oo$/, " Oo ")
+ sub(/ Oc$/, " Oc ")
+ while (/ Oo /) {
+ sub(/ Oo /, " ")
+ Oo++
+ }
+ while (/ Oc /) {
+ sub(/ Oc /, " ")
+ Oo--
+ }
}
/^\.(PRINTSTYLE|START)/ { mom++ }
END {
- if (files ~ /^-/)
- files = "-- " files
- printf "groff"
- refer = refer || (refer_start && refer_end)
- if (pic > 0 || tbl > 0 || grn > 0 || grap > 0 || eqn > 0 || refer > 0) {
- printf " -"
- if (soelim > 0) printf "s"
- if (refer > 0) printf "R"
- if (grn > 0) printf "g"
- if (grap > 0) printf "G"
- if (pic > 0) printf "p"
- if (tbl > 0) printf "t"
- if (eqn > 0) printf "e"
- }
- if (me > 0)
- printf " -me"
- else if (SH > 0 && TH > 0)
- printf " -man"
- else if (mom > 0)
- printf " -mom"
- else if (PP > 0)
- printf " -ms"
- else if (P > 0 || mm > 0)
- printf " -mm"
- else if (mdoc > 0) {
- if (mdoc_old > 0 || Oo > 0)
- printf " -mdoc-old"
- else
- printf " -mdoc"
- }
- if (opts != "")
- printf "%s", opts
- if (files != "")
- printf " %s", files
- print ""
-}' "opts=$opts" "files=$*" -
+ if (chem > 0) {
+ printf "chem %s | ", files
+ pic++
+ files = ""
+ }
+ printf "groff"
+ refer = refer || (refer_start && refer_end)
+ if (pic > 0 || tbl > 0 || grn > 0 || grap > 0 || eqn > 0 || refer > 0) {
+ printf " -"
+ if (soelim > 0) printf "s"
+ if (refer > 0) printf "R"
+ if (grn > 0) printf "g"
+ if (grap > 0) printf "G"
+ if (pic > 0) printf "p"
+ if (tbl > 0) printf "t"
+ if (eqn > 0) printf "e"
+ }
+ mnr = 0
+ m = ""
+ is_man = 0
+ is_mm = 0
+ is_mom = 0
+ # me
+ if (me > 0) {
+ mnr++; m = "-me"; printf " -me"
+ }
+ # man
+ if (SH > 0 && TH > 0) {
+ mnr++; m = "-man"; printf " -man"; is_man = 1
+ }
+ # mom
+ if (mom > 0) {
+ mnr++; m = "-mom"; printf " -mom"; is_mom = 1
+ }
+ # mm
+ if ( mm > 0 || (P > 0 && is_man == 0) ) {
+ mnr++; m = "-mm"; printf " -mm"; is_mm = 1
+ }
+ # ms
+ if ( NH > 0 || (TL > 0 && is_mm == 0) || (ILP > 0 && is_man == 0) ||
+ (PP > 0 && is_mom == 0 && is_man == 0) ) {
+ # .TL also occurs in -mm, .IP and .LP also occur in -man
+ # .PP also occurs in -mom and -man
+ mnr++; m = "-ms"; printf " -ms"
+ }
+ # mdoc
+ if (mdoc > 0) {
+ mnr++
+ if (mdoc_old > 0 || Oo > 0) {
+ m = "-mdoc-old"; printf " -mdoc-old"
+ }
+ else {
+ m = "-mdoc"; printf " -mdoc"
+ }
+ }
+
+ if (mnr == 0) {
+ if (mopt != "")
+ printf "%s", mopt
+ }
+
+ if (opts != "")
+ printf "%s", opts
+ if (files != "")
+ printf " %s", files
+ print ""
+
+ if (mnr == 1) {
+ if (mopt != "" && m != mopt)
+ printf "grog: wrong option %s\n", mopt | "cat 1>&2"
+ }
+ if (mnr >= 2) {
+ err = "grog: error: there are several -m* arguments"
+ printf "%s\n", err | "cat 1>&2"
+ exit mnr
+ }
+}' "opts=$opts" "mopt=$mopt" "files=$files" -