groff-commit
[Top][All Lists]
Advanced

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

[groff] 13/14: [nroff]: Fix Savannah #60943.


From: G. Branden Robinson
Subject: [groff] 13/14: [nroff]: Fix Savannah #60943.
Date: Mon, 19 Jul 2021 14:36:18 -0400 (EDT)

gbranden pushed a commit to branch master
in repository groff.

commit 2b955c571c6b62a16f710961094c68928d74a0c4
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Tue Jul 20 02:47:42 2021 +1000

    [nroff]: Fix Savannah #60943.
    
    * src/roff/nroff/nroff.sh: Add new `is_option_argument_pending` flag to
      add an additional state to the option parser.  Set it if an
      argument-requiring option is encountered with no abutting argument.
      If it is set when a new argument is encountered, absorb the argument
      into the groff option list and clear the flag.  Moderize script in a
      couple of other ways.
      - Exit with status 2 upon usage errors so that this is
        condition is easily distinguished form a groff abort (which
        exits with status 1).
      - Test shell variables for non-nullity with test(1) -n operator
        instead of a string comparison.
    
    * src/roff/nroff/tests/verbose_option_works.sh: Test correct
      construction of groff command using this input form.
    
    * src/roff/nroff/nroff.1.man (Options): Add spaces between option flags
      and option arguments.  Sync metasyntactic variable names with groff(1)
      while we're at it.
    
      (Description): Drop sentence warning of whitespace prohibition.
    
      (Exit status): Add new section.
    
    * NEWS: Add item since the interface changed.
    
    Fixes <https://savannah.gnu.org/bugs/?60943>.
---
 ChangeLog                                    | 25 ++++++++
 NEWS                                         |  3 +
 src/roff/nroff/nroff.1.man                   | 89 ++++++++++++++++------------
 src/roff/nroff/nroff.sh                      | 32 +++++++---
 src/roff/nroff/tests/verbose_option_works.sh |  4 ++
 5 files changed, 108 insertions(+), 45 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index a0f733d..ff091ef 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,28 @@
+2021-07-20  G. Branden Robinson <g.branden.robinson@gmail.com>
+
+       [nroff]: Support space between option flags and their arguments.
+
+       * src/roff/nroff/nroff.sh: Add new `is_option_argument_pending`
+       flag to add an additional state to the option parser.  Set it if
+       an argument-requiring option is encountered with no abutting
+       argument.  If it is set when a new argument is encountered,
+       absorb the argument into the groff option list and clear the
+       flag.  Moderize script in a couple of other ways.
+         - Exit with status 2 upon usage errors so that this is
+           condition is easily distinguished form a groff abort (which
+           exits with status 1).
+         - Test shell variables for non-nullity with test(1) -n
+           operator instead of a string comparison.
+       * src/roff/nroff/tests/verbose_option_works.sh: Test correct
+       construction of groff command using this input form.
+       * src/roff/nroff/nroff.1.man (Options): Add spaces between
+       option flags and option arguments.  Sync metasyntactic variable
+       names with groff(1) while we're at it.
+       (Description): Drop sentence warning of whitespace prohibition.
+       (Exit status): Add new section.
+
+       Fixes <https://savannah.gnu.org/bugs/?60943>.
+
 2021-07-19  G. Branden Robinson <g.branden.robinson@gmail.com>
 
        * src/roff/troff/input.cpp (main): Emit error diagnostic if `-d`
diff --git a/NEWS b/NEWS
index c262704..fa80cd3 100644
--- a/NEWS
+++ b/NEWS
@@ -105,6 +105,9 @@ o The new option -V emits the constructed groff command 
that nroff would
 o nroff now recognizes the -b, -E, -k, -K, and -z options and passes
   them through to troff.
 
+o nroff now supports whitespace between option flag letters and option
+  arguments, like groff and troff themselves.
+
 Macro Packages
 --------------
 
diff --git a/src/roff/nroff/nroff.1.man b/src/roff/nroff/nroff.1.man
index aeddc47..c8b140d 100644
--- a/src/roff/nroff/nroff.1.man
+++ b/src/roff/nroff/nroff.1.man
@@ -7,7 +7,7 @@
 .\" Legal Terms
 .\" ====================================================================
 .\"
-.\" Copyright (C) 1989-2020 Free Software Foundation, Inc.
+.\" Copyright (C) 1989-2021 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
@@ -36,39 +36,34 @@
 .
 .SY @g@nroff
 .RB [ \-bcCEhikpStUVz ]
-[\c
-.BI \-d cs\c
-]
-[\c
-.BI \-K arg\c
-]
-[\c
-.BI \-m name\c
-]
-[\c
-.BI \-M dir\c
-]
-[\c
-.BI \-n num\c
-]
-[\c
-.BI \-o list\c
-]
-[\c
-.BI \-P post-proc-option\c
-]
-[\c
-.BI \-r cn\c
-]
-[\c
-.BI \-T dev\c
-]
-[\c
-.BI \-w warning\c
-]
-[\c
-.BI \-W warning\c
-]
+.RB [ \-d\~\c
+.IR cs ]
+.RB [ \-d\~\c
+.IB name =\c
+.IR string ]
+.RB [ \-K\~\c
+.IR enc ]
+.RB [ \-m\~\c
+.IR name ]
+.RB [ \-M\~\c
+.IR dir ]
+.RB [ \-n\~\c
+.IR num ]
+.RB [ \-o\~\c
+.IR list ]
+.RB [ \-P\~\c
+.IR arg ]
+.RB [ \-r\~\c
+.IR cn ]
+.RB [ \-r\~\c
+.IB reg =\c
+.IR expr ]
+.RB [ \-T\~\c
+.IR dev ]
+.RB [ \-w\~\c
+.IR name ]
+.RB [ \-W\~\c
+.IR name ]
 .RI [ file\~\c
 \&.\|.\|.\&]
 .YS
@@ -143,10 +138,6 @@ is implied.
 .
 .
 .P
-Whitespace is
-.I not
-permitted between an option and its argument.
-.
 The
 .BR \-b ,
 .BR \-C ,
@@ -221,6 +212,28 @@ all exit afterward.
 .
 .
 .\" ====================================================================
+.SH "Exit status"
+.\" ====================================================================
+.
+.I \%@g@nroff
+exits with error
+.RB status\~ 2
+if there was a problem parsing its arguments,
+with
+.RB status\~ 0
+if any of the options
+.BR \-V ,
+.BR \-v ,
+.BR \-\-version ,
+or
+.B \-\-help
+were specified,
+and with the status of
+.I groff
+otherwise.
+.
+.
+.\" ====================================================================
 .SH Environment
 .\" ====================================================================
 .
diff --git a/src/roff/nroff/nroff.sh b/src/roff/nroff/nroff.sh
index ece9431..3e8837d 100644
--- a/src/roff/nroff/nroff.sh
+++ b/src/roff/nroff/nroff.sh
@@ -1,7 +1,7 @@
 #! /bin/sh
 # Emulate nroff with groff.
 #
-# Copyright (C) 1992-2020 Free Software Foundation, Inc.
+# Copyright (C) 1992-2021 Free Software Foundation, Inc.
 #
 # Written by James Clark.
 
@@ -62,8 +62,19 @@ esac
 Topt=
 opts=
 dry_run=
+is_option_argument_pending=
 for i
 do
+  # Remember last argument seen for a usage diagnostic after loop exits.
+  arg=$1
+
+  if [ -n "$is_option_argument_pending" ]
+  then
+    is_option_argument_pending=
+    opts="$opts $1"
+    shift
+  fi
+
   case $1 in
     -c)
       opts="$opts -P-c" ;;
@@ -73,8 +84,8 @@ do
       # ignore these options
       ;;
     -[dKmMnoPrTwW])
-      echo "$prog: option '$1' requires an argument" >&2
-      exit 1 ;;
+      is_option_argument_pending=yes
+      opts="$opts $1" ;;
     -[bCEikpStUz] | -[dKMmrnoPwW]*)
       opts="$opts $1" ;;
     -T*)
@@ -106,19 +117,26 @@ EOF
     -)
       break ;;
     -*)
-      echo "$prog: invalid option '$1'; see '$prog --help'" >&2
-      exit 1 ;;
+      echo "$prog: usage error: invalid option '$1';" \
+           " see '$prog --help'" >&2
+      exit 2 ;;
     *)
       break ;;
   esac
   shift
 done
 
-if test "x$Topt" != x
+if [ -n "$is_option_argument_pending" ]
+then
+    echo "$prog: usage error: option '$arg' requires an argument" >&2
+    exit 2
+fi
+
+if [ -n "$Topt" ]
 then
   T=$Topt
 else
-  if test "x$Tenv" != x
+  if [ -n "$Tenv" ]
   then
     T=-T$Tenv
   fi
diff --git a/src/roff/nroff/tests/verbose_option_works.sh 
b/src/roff/nroff/tests/verbose_option_works.sh
index 3d5237e..bdee8a1 100755
--- a/src/roff/nroff/tests/verbose_option_works.sh
+++ b/src/roff/nroff/tests/verbose_option_works.sh
@@ -60,3 +60,7 @@ nroff -V \"1a 1b\" 2 | sed "$sedexpr" \
 echo "testing 'nroff -V 1a\\\"1b 2'" >&2
 nroff -V 1a\"1b 2 | sed "$sedexpr" \
     | grep -x "test-groff -Tascii -mtty-char 1a\"1b 2"
+
+echo "testing 'nroff -V -d FOO=BAR 1'" >&2
+nroff -V -d FOO=BAR 1 | sed "$sedexpr" \
+    | grep -x "test-groff -Tascii -mtty-char -d FOO=BAR 1"



reply via email to

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