groff-commit
[Top][All Lists]
Advanced

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

[groff] 04/04: Implement new .soquiet and .msoquiet requests.


From: G. Branden Robinson
Subject: [groff] 04/04: Implement new .soquiet and .msoquiet requests.
Date: Thu, 8 Apr 2021 23:58:37 -0400 (EDT)

gbranden pushed a commit to branch master
in repository groff.

commit 955323df9ebfb8e0889f8eac77edd3477333fe66
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Fri Apr 9 13:09:31 2021 +1000

    Implement new .soquiet and .msoquiet requests.
    
    Needed for two planned developments: (1) the i18n patch in Savannah
    bug #59814 can use this to quietly attempt to open a localization file.
    groff only supports a few locales, so people with LANG=es_ES, for
    instance, would ordinarily see warning diagnostics on every groff
    startup if file warnings were enabled; and (2) system- or
    site-configurable support of per-user {.,}troffrc or man.local files,
    gracefully failing if they don't exist.
    
    * src/roff/troff/input.cpp:
      (do_source): Add new function, taking boolean "quietly" parameter and
      absorbing function of source(), with added conditional.
    
      (source): Convert into a wrapper to call do_source() unquietly.
    
      (source_quietly): Wrap do_source(), quietly.
    
      (do_macro_source, macro_source, macro_source_quietly): Analogous to
      the foregoing.
    
      (init_requests): Hook "msoquiet" to macro_source_quietly() and
      "soquiet" to "source_quietly().
    
    * doc/groff.texi (I/O):
    * man/groff.7.man (Requests/Request short reference):
    * man/groff_diff.7.man (Language/New requests): Document them.
    
    * src/roff/groff/tests/msoquiet_works.sh:
    * src/roff/groff/tests/soquiet_works.sh: Test them.
    
    * src/roff/groff/groff.am (groff_TESTS): Add tests.
    
    Fixes <https://savannah.gnu.org/bugs/?59973>.
---
 ChangeLog                              | 35 ++++++++++++++++++++++++
 NEWS                                   |  4 +++
 doc/groff.texi                         | 12 ++++++--
 man/groff.7.man                        | 18 ++++++++++++
 man/groff_diff.7.man                   | 19 +++++++++++++
 src/roff/groff/groff.am                |  2 ++
 src/roff/groff/tests/msoquiet_works.sh | 31 +++++++++++++++++++++
 src/roff/groff/tests/soquiet_works.sh  | 30 ++++++++++++++++++++
 src/roff/troff/input.cpp               | 50 +++++++++++++++++++++++++++++-----
 9 files changed, 191 insertions(+), 10 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index ddaed14..5b3f57b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,38 @@
+2021-04-09  G. Branden Robinson <g.branden.robinson@gmail.com>
+
+       Implement new .soquiet and .msoquiet requests.
+
+       Needed for two planned developments: {1} the i18n patch in
+       Savannah #59814 can use this to quietly attempt to open a
+       localization file.  groff only supports a few locales, so people
+       with LANG=es_ES, for instance, would ordinarily see warning
+       diagnostics on every groff startup if file warnings were
+       enabled; and {2} system- or site-configurable support of
+       per-user {.,}troffrc or man.local files, gracefully failing if
+       they don't exist.
+
+       * src/roff/troff/input.cpp:
+       (do_source): Add new function, taking boolean "quietly"
+       parameter and absorbing function of source(), with added
+       conditional.
+       (source): Convert into a wrapper to call do_source() unquietly.
+       (source_quietly): Wrap do_source(), quietly.
+       (do_macro_source, macro_source, macro_source_quietly): Analogous
+       to the foregoing.
+       (init_requests): Hook "msoquiet" to macro_source_quietly() and
+       "soquiet" to "source_quietly().
+
+       * doc/groff.texi (I/O):
+       * man/groff.7.man (Requests/Request short reference):
+       * man/groff_diff.7.man (Language/New requests): Document them.
+
+       * src/roff/groff/tests/msoquiet_works.sh:
+       * src/roff/groff/tests/soquiet_works.sh: Test them.
+
+       * src/roff/groff/groff.am (groff_TESTS): Add tests.
+
+       Fixes <https://savannah.gnu.org/bugs/?59973>.
+
 2021-04-08  G. Branden Robinson <g.branden.robinson@gmail.com>
 
        * doc/groff.texi (ms Document Control Settings) <FF>: Update
diff --git a/NEWS b/NEWS
index 22c4d88..4a726cf 100644
--- a/NEWS
+++ b/NEWS
@@ -54,6 +54,10 @@ o Point-size escapes of the form '\sNN', where NN is in the 
range 10-39,
   advanced usage) are expected to be able to cope; ask the development
   team for support if you need it.
 
+o New requests 'soquiet' and 'msoquiet' are available.  They operate as
+  'so' and 'mso', respectively, except that they do not emit a warning
+  diagnostic if the file name argument does not exist.
+
 o New requests 'stringdown' and 'stringup' are available.  These change
   the string named in their argument by replacing each of its bytes with
   its lowercase or uppercase version (if any), respectively.  groff
diff --git a/doc/groff.texi b/doc/groff.texi
index 0a1fbf0..911d6dd 100644
--- a/doc/groff.texi
+++ b/doc/groff.texi
@@ -14269,7 +14269,8 @@ The fill color is associated with the current 
environment
 
 @code{gtroff} has several requests for including files:
 
-@Defreq {so, file}
+@DefreqList {so, file}
+@DefreqListEndx {soquiet, file}
 @cindex including a file (@code{so})
 @cindex file, inclusion (@code{so})
 Read in the specified @var{file} and include it in place of the
@@ -14295,6 +14296,10 @@ yields @samp{This is foobar}.
 
 The search path for @var{file} can be controlled with the @option{-I}
 command-line option.
+
+@code{soquiet} works the same way, except that no warning diagnostic
+is issued if @var{file} does not exist, even if warnings of type
+@samp{file} are enabled.
 @endDefreq
 
 @Defreq {pso, command}
@@ -14313,8 +14318,9 @@ The comment regarding a final newline for the @code{so} 
request is valid
 for @code{pso} also.
 @endDefreq
 
-@Defreq {mso, file}
-Identical to the @code{so} request
+@DefreqList {mso, file}
+@DefreqListEndx {msoquiet, file}
+Identical to the @code{so} and @code{soquiet} requests, respectively,
 except that @code{gtroff} searches for the specified @var{file} in the
 same directories as macro files for the @option{-m} command-line option.
 If the file name to be included has the form @file{@var{name}.tmac} and
diff --git a/man/groff.7.man b/man/groff.7.man
index e799629..27a1c98 100644
--- a/man/groff.7.man
+++ b/man/groff.7.man
@@ -2213,6 +2213,15 @@ directories.
 .
 .
 .TPx
+.REQ .msoquiet "file"
+As
+.request .mso ,
+but no warning is emitted if
+.I file
+does not exist.
+.
+.
+.TPx
 .REQ .na
 Disable line adjustment.
 .
@@ -2551,6 +2560,15 @@ Interpolate (\[lq]source\[rq])
 .
 .
 .TPx
+.REQ .soquiet file
+As
+.request .so ,
+but no warning is emitted if
+.I file
+does not exist.
+.
+.
+.TPx
 .REQ .sp
 Skip one line vertically.
 .
diff --git a/man/groff_diff.7.man b/man/groff_diff.7.man
index 384897b..a5e263c 100644
--- a/man/groff_diff.7.man
+++ b/man/groff_diff.7.man
@@ -2580,6 +2580,15 @@ and the request has no other effect.
 .
 .
 .TP
+.BI .msoquiet\~ file
+As
+.BR .mso ,
+but no warning is emitted if
+.I file
+does not exist.
+.
+.
+.TP
 .BI .nop \~anything
 Execute
 .IR anything .
@@ -2856,6 +2865,16 @@ can also be a range of sizes
 Contrary to the font file command, the list can't extend over more
 than a single line.
 .
+.
+.TP
+.BI .soquiet\~ file
+As
+.BR .so ,
+but no warning is emitted if
+.I file
+does not exist.
+.
+.
 .TP
 .BI .special\~ "s1 s2\~"\c
 \&.\|.\|.
diff --git a/src/roff/groff/groff.am b/src/roff/groff/groff.am
index 7e50651..42fb983 100644
--- a/src/roff/groff/groff.am
+++ b/src/roff/groff/groff.am
@@ -45,6 +45,7 @@ groff_TESTS = \
   src/roff/groff/tests/do_not_loop_infinitely_when_breaking_cjk.sh \
   src/roff/groff/tests/dot-cp_register_works.sh \
   src/roff/groff/tests/dot-nm_register_works.sh \
+  src/roff/groff/tests/msoquiet_works.sh \
   src/roff/groff/tests/on_latin1_device_oq_is_0x27.sh \
   src/roff/groff/tests/recognize_end_of_sentence.sh \
   src/roff/groff/tests/regression_savannah_56555.sh \
@@ -53,6 +54,7 @@ groff_TESTS = \
   src/roff/groff/tests/regression_savannah_58337.sh \
   src/roff/groff/tests/regression_savannah_59202.sh \
   src/roff/groff/tests/smoke-test_html_device.sh \
+  src/roff/groff/tests/soquiet_works.sh \
   src/roff/groff/tests/string_case_xform_errors.sh \
   src/roff/groff/tests/string_case_xform_requests.sh \
   src/roff/groff/tests/string_case_xform_unicode_escape.sh \
diff --git a/src/roff/groff/tests/msoquiet_works.sh 
b/src/roff/groff/tests/msoquiet_works.sh
new file mode 100755
index 0000000..c232a1b
--- /dev/null
+++ b/src/roff/groff/tests/msoquiet_works.sh
@@ -0,0 +1,31 @@
+#!/bin/sh
+#
+# Copyright (C) 2021 Free Software Foundation, Inc.
+#
+# This file 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 3 of the License, 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 this program. If not, see <http://www.gnu.org/licenses/>.
+#
+
+groff="${abs_top_builddir:-.}/test-groff"
+
+set -e
+
+DOC='.msoquiet nonexistent'
+
+OUTPUT=$(echo "$DOC" | "$groff" -Tascii 2>&1)
+
+echo "testing that .msoquiet of nonexistent file produces no warning" \
+  >&2
+test -z "$OUTPUT"
diff --git a/src/roff/groff/tests/soquiet_works.sh 
b/src/roff/groff/tests/soquiet_works.sh
new file mode 100755
index 0000000..8e8d71e
--- /dev/null
+++ b/src/roff/groff/tests/soquiet_works.sh
@@ -0,0 +1,30 @@
+#!/bin/sh
+#
+# Copyright (C) 2021 Free Software Foundation, Inc.
+#
+# This file 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 3 of the License, 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 this program. If not, see <http://www.gnu.org/licenses/>.
+#
+
+groff="${abs_top_builddir:-.}/test-groff"
+
+set -e
+
+DOC='.soquiet nonexistent'
+
+OUTPUT=$(echo "$DOC" | "$groff" -Tascii 2>&1)
+
+echo "testing that .soquiet of nonexistent file produces no error" >&2
+test -z "$OUTPUT"
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 02fa02e..80733d1 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -5956,9 +5956,7 @@ void while_continue_request()
   }
 }
 
-// .so
-
-void source()
+void do_source(bool quietly)
 {
   symbol nm = get_long_name(1);
   if (nm.is_null())
@@ -5971,11 +5969,29 @@ void source()
     if (fp)
       input_stack::push(new file_iterator(fp, nm.contents()));
     else
-      error("can't open '%1': %2", nm.contents(), strerror(errno));
+      // Suppress diagnostic only if we're operating quietly and it's an
+      // expected problem.
+      if (!(quietly && (ENOENT == errno)))
+       error("can't open '%1': %2", nm.contents(), strerror(errno));
     tok.next();
   }
 }
 
+// .so
+
+void source()
+{
+  do_source(0 /* not quietly*/ );
+}
+
+// .soquiet: like .so, but silently ignore files that can't be opened
+// due to their nonexistence
+
+void source_quietly()
+{
+  do_source(1 /* quietly */ );
+}
+
 // like .so but use popen()
 
 void pipe_source()
@@ -7775,7 +7791,7 @@ static void process_startup_file(const char *filename)
   mac_path = orig_mac_path;
 }
 
-void macro_source()
+void do_macro_source(bool quietly)
 {
   symbol nm = get_long_name(1);
   if (nm.is_null())
@@ -7815,12 +7831,30 @@ void macro_source()
       free(path);
     }
     else
-      warning(WARN_FILE, "can't open macro file '%1': %2",
-             nm.contents(), strerror(errno));
+      // Suppress diagnostic only if we're operating quietly and it's an
+      // expected problem.
+      if (!quietly && (ENOENT == errno))
+       warning(WARN_FILE, "can't open macro file '%1': %2",
+               nm.contents(), strerror(errno));
     tok.next();
   }
 }
 
+// .mso
+
+void macro_source()
+{
+  do_macro_source(0 /* not quietly (if WARN_FILE enabled) */ );
+}
+
+// .msoquiet: like .mso, but silently ignore files that can't be opened
+// due to their nonexistence
+
+void macro_source_quietly()
+{
+  do_macro_source(1 /* quietly */ );
+}
+
 static void process_input_file(const char *name)
 {
   FILE *fp;
@@ -8281,6 +8315,7 @@ void init_input_requests()
   init_request("lf", line_file);
   init_request("lsm", leading_spaces_macro);
   init_request("mso", macro_source);
+  init_request("msoquiet", macro_source_quietly);
   init_request("nop", nop_request);
   init_request("nroff", nroff_request);
   init_request("nx", next_file);
@@ -8302,6 +8337,7 @@ void init_input_requests()
   init_request("schar", define_special_character);
   init_request("shift", shift);
   init_request("so", source);
+  init_request("soquiet", source_quietly);
   init_request("spreadwarn", spreadwarn_request);
   init_request("stringdown", stringdown_request);
   init_request("stringup", stringup_request);



reply via email to

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