groff-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Groff-commit] groff ChangeLog NEWS src/roff/grog/Makefile.sub...


From: Bernd Warken
Subject: [Groff-commit] groff ChangeLog NEWS src/roff/grog/Makefile.sub...
Date: Mon, 06 Nov 2006 12:33:32 +0000

CVSROOT:        /cvsroot/groff
Module name:    groff
Changes by:     Bernd Warken <bwarken>  06/11/06 12:33:32

Modified files:
        .              : ChangeLog NEWS 
        src/roff/grog  : Makefile.sub grog.man grog.pl grog.sh 

Log message:
        Rewrite of grog.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/groff/ChangeLog?cvsroot=groff&r1=1.1000&r2=1.1001
http://cvs.savannah.gnu.org/viewcvs/groff/NEWS?cvsroot=groff&r1=1.225&r2=1.226
http://cvs.savannah.gnu.org/viewcvs/groff/src/roff/grog/Makefile.sub?cvsroot=groff&r1=1.10&r2=1.11
http://cvs.savannah.gnu.org/viewcvs/groff/src/roff/grog/grog.man?cvsroot=groff&r1=1.10&r2=1.11
http://cvs.savannah.gnu.org/viewcvs/groff/src/roff/grog/grog.pl?cvsroot=groff&r1=1.15&r2=1.16
http://cvs.savannah.gnu.org/viewcvs/groff/src/roff/grog/grog.sh?cvsroot=groff&r1=1.15&r2=1.16

Patches:
Index: ChangeLog
===================================================================
RCS file: /cvsroot/groff/groff/ChangeLog,v
retrieving revision 1.1000
retrieving revision 1.1001
diff -u -b -r1.1000 -r1.1001
--- ChangeLog   28 Oct 2006 16:59:32 -0000      1.1000
+++ ChangeLog   6 Nov 2006 12:33:31 -0000       1.1001
@@ -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  <address@hidden>
 
        * tmac/trace.tmac: Improve tracing of `.nr'.

Index: NEWS
===================================================================
RCS file: /cvsroot/groff/groff/NEWS,v
retrieving revision 1.225
retrieving revision 1.226
diff -u -b -r1.225 -r1.226
--- NEWS        28 Oct 2006 16:59:32 -0000      1.225
+++ NEWS        6 Nov 2006 12:33:32 -0000       1.226
@@ -63,6 +63,8 @@
 
 o `groffer' version 1.* exists now in a shell and a Perl version.
 
+o Rewrite of `grog'.
+
 Pic
 ---
 

Index: src/roff/grog/Makefile.sub
===================================================================
RCS file: /cvsroot/groff/groff/src/roff/grog/Makefile.sub,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -b -r1.10 -r1.11
--- src/roff/grog/Makefile.sub  28 Mar 2006 17:54:16 -0000      1.10
+++ src/roff/grog/Makefile.sub  6 Nov 2006 12:33:32 -0000       1.11
@@ -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
+all: grog $(MAN1)
 
-grog: grog.sh
-       rm -f $@
-       sed -e "s|@g@|$(g)|g" \
-         -e "s|@EGREP@|$(EGREP)|g" \
+grog: grog.pl grog.sh $(SH_DEPS_SED_SCRIPT)
+       address@hidden -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.sh >$@
-       chmod +x $@
-
-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 >$@; \
+             -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
+       address@hidden -d $(DESTDIR)$(bindir) || $(mkinstalldirs) 
$(DESTDIR)$(bindir)
+       address@hidden -f $(DESTDIR)$(bindir)/grog
        $(INSTALL_SCRIPT) grog $(DESTDIR)$(bindir)/grog
 
 uninstall_sub:

Index: src/roff/grog/grog.man
===================================================================
RCS file: /cvsroot/groff/groff/src/roff/grog/grog.man,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -b -r1.10 -r1.11
--- src/roff/grog/grog.man      18 Mar 2003 09:37:50 -0000      1.10
+++ src/roff/grog/grog.man      6 Nov 2006 12:33:32 -0000       1.11
@@ -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 "address@hidden" "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 address@hidden@t]\f[]\"            needed
+.nr @w \w'\*[grog:Shell_cmd.prompt]'\"
+.ft address@hidden
+.\" Full prompt width is maximum of texts plus 1m
+.nr grog:Shell_cmd_base.prompt_width (address@hidden>address@hidden)\" 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'address@hidden'u
+.  ti address@hidden
+.  B address@hidden
+.  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 address@hidden"
+.  while (\\n[.$] >= 2) \{\
+.    c                                  do the pairs, break on no `-'
+.    if !'\\$1'-' \{\
+.      if !'\\$1'--' \
+.        break
+.    \}
+.    c                                  separator
+.    if (address@hidden > 0) \
+.      as @res address@hidden:\"
+.    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 address@hidden"
+.  el \{\
+.    c                                  optional option argument
+.    if !'\\$1'' \
+.      as @res \f[CR] \,\f[I]\\$1\"
+.    shift
+.    c                                  postfix
+.    as @res address@hidden"
+.    if (\\n[.$] >= 1) \{\
+.      c                                add punctuation
+.      as @res address@hidden"
+.    \}
+.  \}
+.  nh
+.  Text address@hidden
+.  hy
+.  ft address@hidden
+.  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 address@hidden
+.  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'address@hidden'\"
+.  ds @res address@hidden'address@hidden'\"
+.  shift
+.  ds @cf CR\"
+.  while (\\n[.$] > 0) \{\
+.    as @res address@hidden"
+.    shift
+.    ie 'address@hidden'CR' \
+.      ds @cf I\"
+.    el \
+.      ds @cf CR\"
+.  \}
+.  br
+.  ad l
+.  nh
+.  nf
+.  Text address@hidden"
+.  fi
+.  hy
+.  ad
+.  br
+.  ft address@hidden
+.  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 @@
 .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 @address@hidden (@MAN1EXT@),
 .BR @address@hidden (@MAN1EXT@),
@@ -84,7 +710,24 @@
 .BR @address@hidden (@MAN1EXT@),
 .BR @address@hidden (@MAN1EXT@),
 .BR grap (1),
-.BR @address@hidden (@MAN1EXT@)
+.BR @address@hidden (@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

Index: src/roff/grog/grog.pl
===================================================================
RCS file: /cvsroot/groff/groff/src/roff/grog/grog.pl,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -b -r1.15 -r1.16
--- src/roff/grog/grog.pl       18 May 2005 07:03:07 -0000      1.15
+++ src/roff/grog/grog.pl       6 Nov 2006 12:33:32 -0000       1.16
@@ -1,122 +1,207 @@
-#! /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 =~ address@hidden/@@;
+# 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;
+
+use warnings;
+use strict;
+use File::Spec;
+
+my $Prog = $0;
+{
+  my ($v, $d, $f) = File::Spec->splitpath($Prog);
+  $Prog = $f;
+}
+
+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;
+
+  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;
+    }
+
+    if ($arg eq '--') {
+      $double_minus = 1;
+      push(@Command, $arg);
+      next;
+    }
+    if ($arg eq '-') {
+      unless ($was_minus) {
+       push @filespec, $arg;
+       $was_minus = 1;
+      }
+      next;
+    }
+
+    &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;
 }
 
address@hidden = ('-') unless @ARGV;
-foreach $arg (@ARGV) {
+foreach my $arg (@ARGV) {
     &process($arg, 0);
 }
 
 sub process {
-    local($filename, $level) = @_;
+  my ($filename, $level) = @_;
     local(*FILE);
 
     if (!open(FILE, $filename eq "-" ? $filename : "< $filename")) {
-       print STDERR "$prog: can't open \`$filename': $!\n";
+    print STDERR "$Prog: can't open \`$filename': $!\n";
        exit 1 unless $level;
        return;
     }
     while (<FILE>) {
-       if (/^\.TS$sp/) {
+    s/^[.']\s*/./;
+    s/^\s+|\s+$//g;
+
+    if (/^(.cstart)|(begin\s+chem)$/) {
+      $Groff{'chem'}++;
+      $Groff{'pic'}++;
+    } elsif (/^\.TS$Sp/) {
            $_ = <FILE>;
            if (!/^\./) {
-               $tbl++;
-               $soelim++ if $level;
-           }
+       $Groff{'tbl'}++;
+       $Groff{'soelim'}++ if $level;
        }
-       elsif (/^\.EQ$sp/) {
+    } elsif (/^\.EQ$Sp/) {
            $_ = <FILE>;
            if (!/^\./ || /^\.[0-9]/) {
-               $eqn++;
-               $soelim++ if $level;
+       $Groff{'eqn'}++;
+       $Groff{'soelim'}++ if $level;
            }
-       }
-       elsif (/^\.GS$sp/) {
+    } elsif (/^\.GS$Sp/) {
            $_ = <FILE>;
            if (!/^\./) {
-               $grn++;
-               $soelim++ if $level;
-           }
+       $Groff{'grn'}++;
+       $Groff{'soelim'}++ if $level;
        }
-       elsif (/^\.G1$sp/) {
+    } elsif (/^\.G1$Sp/) {
            $_ = <FILE>;
            if (!/^\./) {
-               $grap++;
-               $pic++;
-               $soelim++ if $level;
+       $Groff{'grap'}++;
+       $Groff{'pic'}++;
+       $Groff{'soelim'}++ if $level;
            }
-       }
-       elsif (/^\.PS$sp([ 0-9.<].*)?$/) {
+    } elsif (/^\.PS$Sp([ 0-9.<].*)?$/) {
            if (/^\.PS\s*<\s*(\S+)/) {
-               $pic++;
-               $soelim++ if $level;
+       $Groff{'pic'}++;
+       $Groff{'soelim'}++ if $level;
                &process($1, $level);
-           }
-           else {
+      } else {
                $_ = <FILE>;
                if (!/^\./ || /^\.ps/) {
-                   $pic++;
-                   $soelim++ if $level;
-               }
-           }
-       }
-       elsif (/^\.R1$sp/) {
-           $refer++;
-           $soelim++ if $level;
-       }
-       elsif (/^\.\[/) {
-           $refer_open++;
-           $soelim++ if $level;
+         $Groff{'pic'}++;
+         $Groff{'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;
+    } 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/) {
-           $Oo++;
+    elsif (/^\.Oo$Sp/) {
+      $Groff{'Oo'}++;
            s/^\.Oo/\. /;
            redo;
        }
@@ -130,28 +215,25 @@
            s/\"[^\"]*\"//g;
            s/\".*//;
            if (s/ Oo( |$)/ /) {
-               $Oo++;
+       $Groff{'Oo'}++;
            }
            redo;
-       }
-       elsif (/^\.Oc$sp/) {
-           $Oo--;
+    } elsif (/^\.Oc$Sp/) {
+      $Groff{'Oo'}--;
            s/^\.Oc/\. /;
            redo;
-       }
-       elsif (/^\..* Oc( |$)/) {
+    } elsif (/^\..* Oc( |$)/) {
            s/\\\".*//;
            s/\"[^\"]*\"//g;
            s/\".*//;
            if (s/ Oc( |$)/ /) {
-               $Oo--;
+       $Groff{'Oo'}--;
            }
            redo;
+    } elsif (/^\.(PRINTSTYLE|START)$Sp/) {
+      $Groff{'mom'}++;
        }
-       elsif (/^\.(PRINTSTYLE|START)$sp/) {
-           $mom++;
-       }
-       if (/^\.so$sp/) {
+    if (/^\.so$Sp/) {
            chop;
            s/^.so *//;
            s/\\\".*//;
@@ -162,61 +244,130 @@
     close(FILE);
 }
 
-sub usage {
-    local($exit_status) = $_;
-    print "GNU grog (groff) version @address@hidden";
-    exit $exit_status;
-}
-
 sub help {
-    print "usage: grog [ option ...] [files...]\n";
+  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;
 }
 
-$refer ||= $refer_open && $refer_close;
+sub version {
+  my ($exit_status) = @_;
+  print "Perl version of GNU $Prog of $Last_Update " .
+    "in groff version @address@hidden";
+  exit $exit_status;
+}
 
-if ($pic || $tbl || $eqn || $grn || $grap || $refer) {
-    $s = "-";
-    $s .= "s" if $soelim;
-    $s .= "R" if $refer;
+{
+  my @m = ();
+  my $is_man = 0;
+  my $is_mm = 0;
+  my $is_mom = 0;
+
+  $Groff{'refer'} ||= $Groff{'refer_open'} && $Groff{'refer_close'};
+
+  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 $grap;
-    $s .= "p" if $pic;
-    $s .= "g" if $grn;
-    $s .= "t" if $tbl;
-    $s .= "e" if $eqn;
-    push(@command, $s);
-}
+    $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);
+  }
+
+  if ($Groff{'chem'}) {
+    my @chem = ('chem', @ARGV, '|', 'groff');
+    unshift(@Command, @chem);
+  } else {
+    unshift @Command, 'groff';
+    push(@Command, @ARGV);
+  }
 
-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");
-}
-elsif ($P > 0 || $mm > 0) {
-    push(@command, "-mm");
-}
-elsif ($mdoc > 0) {
-    push(@command, ($mdoc_old || $Oo > 0) ? "-mdoc-old" : "-mdoc");
-}
+  foreach (@Command) {
+    next unless /\s/;
+    $_ = "'" . $_ . "'";
+  }
 
-push(@command, "--") if @ARGV && $ARGV[0] =~ /^-./;
+  # We could implement an option to execute the command here.
 
-push(@command, @ARGV);
+#  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";
+  }
 
-# We could implement an option to execute the command here.
+  print "@Command\n";
 
-foreach (@command) {
-    next unless /[\$\\\"\';&()|<> \t\n]/;
-    s/\'/\'\\\'\'/;
-    $_ = "'" . $_ . "'";
+  exit $n if $n > 1;
+  exit 0;
 }
 
-print join(' ', @command), "\n";
+########################################################################
+### Emacs settings
+# Local Variables:
+# mode: CPerl
+# End:

Index: src/roff/grog/grog.sh
===================================================================
RCS file: /cvsroot/groff/groff/src/roff/grog/grog.sh,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -b -r1.15 -r1.16
--- src/roff/grog/grog.sh       28 Mar 2006 17:54:16 -0000      1.15
+++ src/roff/grog/grog.sh       6 Nov 2006 12:33:32 -0000       1.16
@@ -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'
+########################################################################
+
 address@hidden@soelim
 
 opts=
+mopt=
+nr=0
 sp="([  ]|$)"
+double_minus=0
+was_minus=0
+filespec=
+had_filespec=0
 
 for arg
 do
+  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
        --)
-               shift; break;;
+    double_minus=1
+    ;;
        -)
-               break;;
+    # omit several -
+    if test _"${was_minus}"_ = _0_
+    then
+      was_minus=1
+      filespec="${filespec} -"
+    fi
+    ;;
        -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;;
+    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"; shift;;
+    opts="$opts $arg"
+    ;;
+  *)
+    had_filespec=1
+    if test -f "${arg}" && test -r "${arg}"
+    then
+      case "$arg" in
+      *" "*)
+        eval filespec="'${filespec} '"'\"'"'${arg}'"'\"'
+        ;;
        *)
-               break;;
+        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`
 
address@hidden@ -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 @@
 /^\.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++ }
@@ -77,8 +205,11 @@
 /^\.(PRINTSTYLE|START)/ { mom++ }
 
 END {
-       if (files ~ /^-/)
-               files = "-- " 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) {
@@ -91,25 +222,63 @@
                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"
+  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 ""
-}' "opts=$opts" "files=$*" -
+
+  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" -




reply via email to

[Prev in Thread] Current Thread [Next in Thread]