groff-commit
[Top][All Lists]
Advanced

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

[groff] 13/35: [troff]: `open{,a}` now accept spacey file names.


From: G. Branden Robinson
Subject: [groff] 13/35: [troff]: `open{,a}` now accept spacey file names.
Date: Tue, 10 Dec 2024 16:35:33 -0500 (EST)

gbranden pushed a commit to branch master
in repository groff.

commit f11b1c8da04a209d22ea2bd49e02a0eb725becd0
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Sat Dec 7 12:03:06 2024 -0600

    [troff]: `open{,a}` now accept spacey file names.
    
    The `open` and `opena` requests now accept leading and embedded spaces
    in their "file" arguments, just like `so`.
    
    * src/roff/troff/input.cpp (open_file): Gather the second argument with
      `read_string()` (which reads a potentially spaceful argument including
      a discardable leading double quote), not `get_long_name()` (which
      reads a GNU troff identifier).  Call `tok.next()` at the end of the
      function as required by `read_string()`.
    
      (open_request, opena_request): Drop `skip_line()` call from end of
      function and annotate why.
    
    * doc/groff.texi.in (I/O):
    * man/groff.7.man (Request short reference):
    * man/groff_diff.7.man (New requests): Document it.
    
    * NEWS: Update existing items.
    
    A more general revision to groff(7) will follow.
---
 ChangeLog                | 20 ++++++++++++++++++++
 NEWS                     | 10 ++++++----
 doc/groff.texi.in        |  4 ++--
 man/groff_diff.7.man     |  8 ++++++--
 src/roff/troff/input.cpp | 21 +++++++++------------
 5 files changed, 43 insertions(+), 20 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 60f42135b..9842e60e2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,23 @@
+2024-12-07  G. Branden Robinson <g.branden.robinson@gmail.com>
+
+       [troff]: The `open` and `opena` requests now accept leading and
+       embedded spaces in their "file" arguments, just like `so`.
+
+       * src/roff/troff/input.cpp (open_file): Gather the second
+       argument with `read_string()` (which reads a potentially
+       spaceful argument including a discardable leading double quote),
+       not `get_long_name()` (which reads a GNU troff identifier).
+       Call `tok.next()` at the end of the function as required by
+       `read_string()`.
+       (open_request, opena_request): Drop `skip_line()` call from end
+       of function and annotate why.
+
+       * doc/groff.texi.in (I/O):
+       * man/groff.7.man (Request short reference):
+       * man/groff_diff.7.man (New requests): Document it.
+
+       * NEWS: Update existing items.
+
 2024-12-07  G. Branden Robinson <g.branden.robinson@gmail.com>
 
        [troff]: The `nx` request now accepts leading and embedded
diff --git a/NEWS b/NEWS
index 1eee9288e..518fe9206 100644
--- a/NEWS
+++ b/NEWS
@@ -58,12 +58,14 @@ troff
 
 *  GNU troff now strips a leading neutral double quote from the argument
    to the `cf`, `hpf`, `hpfa`, `mso`, `msoquiet`, `nx`, `pi`, `pso`,
-   `so`, `soquiet`, `sy`, and `trf` requests, allowing it to contain
-   embedded leading spaces.
+   `so`, `soquiet`, and `sy` requests, and the second argument to the
+   `open` and `opena` requests, allowing it to contain embedded leading
+   spaces.
 
 *  GNU troff now accepts space characters in the argument to the `cf`,
-   `hpf`, `hpfa`, `mso`, `msoquiet`, `nx`, `so`, and `soquiet`
-   requests.  See "soelim" below.
+   `hpf`, `hpfa`, `mso`, `msoquiet`, `nx`, `so`, and `soquiet` requests,
+   and the second argument to the `open` and `opena` requests.  See
+   "soelim" below.
 
 *  The "el" warning category has been withdrawn.  If enabled (which it
    was not by default), the formatter would emit a diagnostic if it
diff --git a/doc/groff.texi.in b/doc/groff.texi.in
index a64cdf8a2..228d52d8b 100644
--- a/doc/groff.texi.in
+++ b/doc/groff.texi.in
@@ -16558,8 +16558,8 @@ output.
 @endExample
 @endDefreq
 
-@DefreqList {open, stream file}
-@DefreqListEndx {opena, stream file}
+@DefreqList {open, stream [@code{"}]file}
+@DefreqListEndx {opena, stream [@code{"}]file}
 @cindex opening file (@code{open})
 @cindex file, opening (@code{open})
 @cindex appending to a file (@code{opena})
diff --git a/man/groff_diff.7.man b/man/groff_diff.7.man
index 57e1a6696..e75dc0a2c 100644
--- a/man/groff_diff.7.man
+++ b/man/groff_diff.7.man
@@ -3225,7 +3225,9 @@ See
 .
 .
 .TP
-.BI .open\~ "stream file"
+.BI .open\~ "stream\~\c
+.RB [ \[dq] ]\c
+.I file
 Open
 .I file
 for writing and associate
@@ -3239,7 +3241,9 @@ and
 .
 .
 .TP
-.BI .opena\~ "stream file"
+.BI .opena\~ "stream\~\c
+.RB [ \[dq] ]\c
+.I file
 As
 .BR open ,
 but if
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index f763f5047..91425bc98 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -7409,15 +7409,13 @@ static void open_file(bool appending)
 {
   symbol stream = get_name(true /* required */);
   if (!stream.is_null()) {
-    symbol fnarg = get_long_name(true /* required */);
-    if (!fnarg.is_null()) {
+    char *filename = read_string();
+    if (filename != 0 /* nullptr */) {
       const string mode = appending ? "appending" : "writing";
-      string filename = fnarg.contents();
       errno = 0;
-      FILE *fp = fopen(filename.contents(), appending ? "a" : "w");
+      FILE *fp = fopen(filename, appending ? "a" : "w");
       if (0 /* nullptr */ == fp) {
-       error("cannot open file '%1' for %2: %3",
-             filename.contents(),
+       error("cannot open file '%1' for %2: %3", filename,
              appending ? "appending" : "writing",
              strerror(errno));
        // If we already had a key of this name in the dictionary, it's
@@ -7432,16 +7430,15 @@ static void open_file(bool appending)
          assert(oldfp != 0 /* nullptr */);
          if (oldfp != 0 /* nullptr */ && (fclose(oldfp) != 0)) {
            error("cannot close file '%1' already associated with"
-                 " stream '%2': %3", filename.contents(),
-                 strerror(errno));
+                 " stream '%2': %3", filename, strerror(errno));
            return;
          }
        }
-       grostream *grost = new grostream(filename.contents(), mode,
-                                        &*fp);
+       grostream *grost = new grostream(filename, mode, &*fp);
        stream_dictionary.define(stream, (object *)grost);
       }
     }
+    tok.next();
   }
 }
 
@@ -7458,7 +7455,7 @@ static void open_request() // .open
   }
   else
     open_file(false /* appending */);
-  skip_line();
+  // No skip_line() here; open_file() calls read_string(), tok.next().
 }
 
 static void opena_request() // .opena
@@ -7474,7 +7471,7 @@ static void opena_request() // .opena
   }
   else
     open_file(true /* appending */);
-  skip_line();
+  // No skip_line() here; open_file() calls read_string(), tok.next().
 }
 
 static void close_stream(symbol &stream)



reply via email to

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