groff-commit
[Top][All Lists]
Advanced

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

[groff] 05/07: [grog]: Refactor device (`-T` option) handling.


From: G. Branden Robinson
Subject: [groff] 05/07: [grog]: Refactor device (`-T` option) handling.
Date: Tue, 29 Jun 2021 00:19:22 -0400 (EDT)

gbranden pushed a commit to branch master
in repository groff.

commit 182942f0453fc138147780b237492b8c50e514c8
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Mon Jun 28 21:08:09 2021 +1000

    [grog]: Refactor device (`-T` option) handling.
    
    * src/utils/grog/grog.pl: Redeclare `device` as a scalar instead of a
      list.
    
      (process_arguments): Generalize handling of `-T` and `-m` options to
      permit optional whitespace.  Rename scalar `was_T` to
      `delayed_option`.
    
      (infer_device): Stop unconditionally adding a `-T ps` argument to the
      generated groff command.  Remove logic that validates any given `-T`
      option argument; instead, let groff fail if a bad one is supplied (its
      own diagnostics in this scenario were improved in commit 5a721a30, 27
      May).  This makes grog agnostic about any differently configured
      default device in groff itself, and about the GROFF_TYPESETTER
      environment variable.
    
      Fixes <https://savannah.gnu.org/bugs/?55301> by getting out of the
      way.
    
    * src/utils/grog/tests/PF-does-not-start-pic-region.sh:
    * src/utils/grog/tests/smoke-test.sh: Update expected output.
---
 ChangeLog                                          | 23 ++++++++
 src/utils/grog/grog.pl                             | 66 ++++++++--------------
 .../grog/tests/PF-does-not-start-pic-region.sh     |  2 +-
 src/utils/grog/tests/smoke-test.sh                 | 46 +++++++--------
 4 files changed, 69 insertions(+), 68 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index ef01064..2951e9c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,28 @@
 2021-06-28  G. Branden Robinson <g.branden.robinson@gmail.com>
 
+       [grog]: Refactor device (`-T` option) handling.
+
+       * src/utils/grog/grog.pl: Redeclare `device` as a scalar instead
+       of a list.
+       (process_arguments): Generalize handling of `-T` and `-m`
+       options to permit optional whitespace.  Rename scalar `was_T` to
+       `delayed_option`.
+       (infer_device): Stop unconditionally adding a `-T ps` argument
+       to the generated groff command.  Remove logic that validates any
+       given `-T` option argument; instead, let groff fail if a bad one
+       is supplied (its own diagnostics in this scenario were improved
+       in commit 5a721a30, 27 May).  This makes grog agnostic about any
+       differently configured default device in groff itself, and about
+       the GROFF_TYPESETTER environment variable.
+
+       Fixes <https://savannah.gnu.org/bugs/?55301> by getting out of
+       the way.
+
+       * src/utils/grog/tests/PF-does-not-start-pic-region.sh:
+       * src/utils/grog/tests/smoke-test.sh: Update expected output.
+
+2021-06-28  G. Branden Robinson <g.branden.robinson@gmail.com>
+
        * src/utils/grog/grog.am (grog): Drop sed replacement of unused
        configuration variables @g@, @BINDIR@, @libdir@, and @EGREP@.
        * src/utils/grog/grog.pl (process_arguments, construct_command):
diff --git a/src/utils/grog/grog.pl b/src/utils/grog/grog.pl
index 5f66412..944f14c 100644
--- a/src/utils/grog/grog.pl
+++ b/src/utils/grog/grog.pl
@@ -45,7 +45,7 @@ my $groff_opts =
   'abcCd:D:eEf:F:gGhiI:jJkK:lL:m:M:n:No:pP:r:RsStT:UvVw:W:XzZ';
 
 my @command = ();              # the constructed groff command
-my @device = ();               # stores -T
+my $device = '';               # argument to '-T' grog option
 my @requested_package = ();    # arguments to '-m' grog options
 
 my $do_run = 0;                        # run generated 'groff' command
@@ -182,12 +182,11 @@ sub warn {
 
 sub process_arguments {
   my $no_more_options = 0;
+  my $delayed_option = '';
   my $was_minus = 0;
-  my $was_T = 0;
   my $optarg = 0;
 
   foreach my $arg (@ARGV) {
-
     if ( $optarg ) {
       push @command, $arg;
       $optarg = 0;
@@ -199,9 +198,10 @@ sub process_arguments {
       next;
     }
 
-    if ( $was_T ) {
-      push @device, $arg;
-      $was_T = 0;
+    if ($delayed_option) {
+      push @requested_package, $arg if ($delayed_option eq 'm');
+      $device = $arg if ($delayed_option eq 'T');
+      $delayed_option = '';
       next;
     }
 
@@ -245,6 +245,15 @@ sub process_arguments {
       next;
     }
 
+    # Handle '-m' or '-T' followed by whitespace.
+    if ($arg =~ /^-[mT]$/) {
+      $delayed_option = $arg;
+      $delayed_option =~ s/-//;
+      next;
+    }
+
+    # Handle '-m' and '-T' without whitespace.
+
     if ($arg =~ /^-m/) {
       my $package = $arg;
       $package =~ s/-m//;
@@ -252,13 +261,10 @@ sub process_arguments {
       next;
     }
 
-    if ($arg =~ /^-T$/) {
-      $was_T = 1;
-      next;
-    }
-
-    if ($arg =~ s/^-T(\w+)$/$1/) {
-      push @device, $1;
+    if ($arg =~ /^-T/) {
+      my $dev = $arg;
+      $dev =~ s/-T//;
+      $device = $dev;
       next;
     }
 
@@ -691,37 +697,9 @@ my @supplemental_package = ();
 my @preprocessor = ();
 
 sub infer_device {
-  # default device is 'ps' when without '-T'
-  # XXX: No, that depends on how the 'configure' script was called (but
-  # most people don't seem to change it).  Also we should check
-  # GROFF_TYPESETTER.  --GBR
-  my $device;
-  push @device, 'ps' unless ( @device );
-
-  for my $d (@device) {
-    if ( $d =~ /^(             # suitable devices
-                 dvi|
-                 html|
-                 xhtml|
-                 lbp|
-                 lj4|
-                 ps|
-                 pdf|
-                 ascii|
-                 cp1047|
-                 latin1|
-                 utf8
-               )$/x ) {
-      $device = $d;
-    } else {
-      next;
-    }
-
-
-    if ( $device ) {
-      push @command, '-T';
-      push @command, $device;
-    }
+  if ($device) {
+    push @command, '-T';
+    push @command, $device;
   }
 
   if ( $device eq 'pdf' ) {
diff --git a/src/utils/grog/tests/PF-does-not-start-pic-region.sh 
b/src/utils/grog/tests/PF-does-not-start-pic-region.sh
index 4081873..d3b871f 100755
--- a/src/utils/grog/tests/PF-does-not-start-pic-region.sh
+++ b/src/utils/grog/tests/PF-does-not-start-pic-region.sh
@@ -28,6 +28,6 @@ DOC='.PF
 .PE'
 
 echo "$DOC" | "$grog" \
-    | grep -q 'groff -T ps -$'
+    | grep -Fqx 'groff -'
 
 # vim:set ai et sw=4 ts=4 tw=72:
diff --git a/src/utils/grog/tests/smoke-test.sh 
b/src/utils/grog/tests/smoke-test.sh
index 724edb9..adb2c19 100755
--- a/src/utils/grog/tests/smoke-test.sh
+++ b/src/utils/grog/tests/smoke-test.sh
@@ -26,119 +26,119 @@ src="${abs_top_srcdir:-..}"
 doc=src/preproc/eqn/neqn.1
 echo "testing simple man(7) page $doc" >&2
 "$grog" "$doc" | \
-    grep -Fqx 'groff -T ps -man '"$doc"
+           grep -Fqx 'groff -man '"$doc"
 
 doc=src/preproc/tbl/tbl.1
 echo "testing tbl(1)-using man(7) page $doc" >&2
 "$grog" "$doc" | \
-    grep -Fqx 'groff -T ps -t -man '"$doc"
+    grep -Fqx 'groff -t -man '"$doc"
 
 doc=man/groff_diff.7
 echo "testing eqn(1)-using man(7) page $doc" >&2
 "$grog" "$doc" | \
-    grep -Fqx 'groff -T ps -e -man '"$doc"
+    grep -Fqx 'groff -e -man '"$doc"
 
 doc=src/preproc/soelim/soelim.1
 echo "testing pic(1)-using man(7) page $doc" >&2
 # BUG: grog spuriously detects a need for soelim(1).
 "$grog" "$doc" | \
-    grep -Fqx 'groff -T ps -s -p -man '"$doc"
+    grep -Fqx 'groff -s -p -man '"$doc"
 
 doc=tmac/groff_mdoc.7
 echo "testing tbl(1)-using mdoc(7) page $doc" >&2
 "$grog" "$doc" | \
-    grep -Fqx 'groff -T ps -t -mdoc '"$doc"
+    grep -Fqx 'groff -t -mdoc '"$doc"
 
 doc=$src/doc/meintro.me
 echo "testing me(7) document $doc" >&2
 "$grog" "$doc" | \
-    grep -Fqx 'groff -T ps -me '"$doc"
+    grep -Fqx 'groff -me '"$doc"
 
 doc=$src/doc/meintro_fr.me
 echo "testing tbl(1)-using me(7) document $doc" >&2
 "$grog" "$doc" | \
-    grep -Fqx 'groff -T ps -t -me '"$doc"
+    grep -Fqx 'groff -t -me '"$doc"
 
 doc=$src/doc/meref.me
 echo "testing me(7) document $doc" >&2
 "$grog" "$doc" | \
-    grep -Fqx 'groff -T ps -me '"$doc"
+    grep -Fqx 'groff -me '"$doc"
 
 doc=$src/doc/grnexmpl.me
 echo "testing grn(1)- and eqn(1)-using me(7) document $doc" >&2
 "$grog" "$doc" | \
-    grep -Fqx 'groff -T ps -e -g -me '"$doc"
+    grep -Fqx 'groff -e -g -me '"$doc"
 
 doc=$src/contrib/mm/examples/letter.mm
 echo "testing mm(7) document $doc" >&2
 "$grog" "$doc" | \
-    grep -Fqx 'groff -T ps -mm '"$doc"
+    grep -Fqx 'groff -mm '"$doc"
 
 doc=$src/contrib/mom/examples/copyright-chapter.mom
 echo "testing mom(7) document $doc" >&2
 "$grog" "$doc" | \
-    grep -Fqx 'groff -T ps -mom '"$doc"
+    grep -Fqx 'groff -mom '"$doc"
 
 doc=$src/contrib/mom/examples/copyright-default.mom
 echo "testing mom(7) document $doc" >&2
 "$grog" "$doc" | \
-    grep -Fqx 'groff -T ps -mom '"$doc"
+    grep -Fqx 'groff -mom '"$doc"
 
 doc=$src/contrib/mom/examples/letter.mom
 echo "testing mom(7) document $doc" >&2
 "$grog" "$doc" | \
-    grep -Fqx 'groff -T ps -mom '"$doc"
+    grep -Fqx 'groff -mom '"$doc"
 
 doc=$src/contrib/mom/examples/mom-pdf.mom
 echo "testing mom(7) document $doc" >&2
 "$grog" "$doc" | \
-    grep -Fqx 'groff -T ps -mom '"$doc"
+    grep -Fqx 'groff -mom '"$doc"
 
 doc=$src/contrib/mom/examples/mon_premier_doc.mom
 echo "testing mom(7) document $doc" >&2
 "$grog" "$doc" | \
-    grep -Fqx 'groff -T ps -mom '"$doc"
+    grep -Fqx 'groff -mom '"$doc"
 
 doc=$src/contrib/mom/examples/sample_docs.mom
 echo "testing mom(7) document $doc" >&2
 "$grog" "$doc" | \
-    grep -Fqx 'groff -T ps -mom '"$doc"
+    grep -Fqx 'groff -mom '"$doc"
 
 doc=$src/contrib/mom/examples/slide-demo.mom
 echo "testing mom(7) document $doc" >&2
 "$grog" "$doc" | \
-    grep -Fqx 'groff -T ps -t -e -p -mom '"$doc"
+    grep -Fqx 'groff -t -e -p -mom '"$doc"
 
 doc=$src/contrib/mom/examples/typesetting.mom
 echo "testing mom(7) document $doc" >&2
 "$grog" "$doc" | \
-    grep -Fqx 'groff -T ps -mom '"$doc"
+    grep -Fqx 'groff -mom '"$doc"
 
 doc=$src/contrib/pdfmark/cover.ms
 echo "testing ms(7) document $doc" >&2
 "$grog" "$doc" | \
-    grep -Fqx 'groff -T ps -ms '"$doc"
+    grep -Fqx 'groff -ms '"$doc"
 
 doc=$src/contrib/pdfmark/pdfmark.ms
 echo "testing ms(7) document $doc" >&2
 "$grog" "$doc" | \
-    grep -Fqx 'groff -T ps -ms '"$doc"
+    grep -Fqx 'groff -ms '"$doc"
 
 doc=$src/doc/ms.ms
 echo "testing tbl(1)-using ms(7) document $doc" >&2
 "$grog" "$doc" | \
-    grep -Fqx 'groff -T ps -t -ms '"$doc"
+    grep -Fqx 'groff -t -ms '"$doc"
 
 doc=$src/doc/pic.ms
 echo "testing tbl(1)-, eqn(1)-, and pic(1)-using ms(7) document $doc" \
     >&2
 "$grog" "$doc" | \
-    grep -Fqx 'groff -T ps -t -e -p -ms '"$doc"
+    grep -Fqx 'groff -t -e -p -ms '"$doc"
 
 doc=$src/doc/webpage.ms
 echo "testing ms(7) document $doc" >&2
 # BUG: Should detect -mwww (and -mpspic?) too.
 "$grog" "$doc" | \
-    grep -Fqx 'groff -T ps -ms '"$doc"
+    grep -Fqx 'groff -ms '"$doc"
 
 # vim:set ai et sw=4 ts=4 tw=72:



reply via email to

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