gbranden pushed a commit to branch master
in repository groff.

commit 9896ef9f5f966f81b69d53d9485f7cd13c064a95
Author: G. Branden Robinson <[email protected]>
AuthorDate: Thu Mar 27 05:48:23 2025 -0500

    [troff]: Trivially refactor.
    
    Rename `read_string()` to `read_rest_of_line_as_argument()`.  What it
    reads does not necessarily become a *roff language string.
    
    * src/roff/troff/input.cpp: Do it.
    
    * src/roff/troff/token.h: Update declaration.
    
    * src/roff/troff/env.cpp (override_sizes)
      (read_hyphenation_patterns_from_file)
      (load_hyphenation_patterns_from_file)
      (append_hyphenation_patterns_from_file):
    * src/roff/troff/input.cpp (next_file, line_file)
      (do_source, pipe_source_request, open_file, open_request)
      (opena_request, abort_request, pipe_output, system_request)
      (copy_file, transparent_file, do_macro_source): Update call sites.
---
 ChangeLog                | 20 ++++++++++++++++++++
 src/roff/troff/env.cpp   | 12 ++++++------
 src/roff/troff/input.cpp | 28 +++++++++++++++-------------
 src/roff/troff/token.h   |  2 +-
 4 files changed, 42 insertions(+), 20 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index a539c6b2e..017c40334 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,23 @@
+2025-03-27  G. Branden Robinson <[email protected]>
+
+       [troff]: Trivially refactor.
+
+       Rename `read_string()` to `read_rest_of_line_as_argument()`.
+       What it reads does not necessarily become a *roff language
+       string.
+
+       * src/roff/troff/input.cpp: Do it.
+       * src/roff/troff/token.h: Update declaration.
+       * src/roff/troff/env.cpp (override_sizes)
+       (read_hyphenation_patterns_from_file)
+       (load_hyphenation_patterns_from_file)
+       (append_hyphenation_patterns_from_file):
+       * src/roff/troff/input.cpp (next_file, line_file)
+       (do_source, pipe_source_request, open_file, open_request)
+       (opena_request, abort_request, pipe_output, system_request)
+       (copy_file, transparent_file, do_macro_source): Update call
+       sites.
+
 2025-03-26  G. Branden Robinson <[email protected]>
 
        * src/include/json-encode.h (struct json_char): Use explicitly
diff --git a/src/roff/troff/env.cpp b/src/roff/troff/env.cpp
index 90eea11f2..bcee757d0 100644
--- a/src/roff/troff/env.cpp
+++ b/src/roff/troff/env.cpp
@@ -1334,7 +1334,7 @@ void override_sizes()
   int *sizes = new int[n]; // C++03: new int[n]();
   (void) memset(sizes, 0, (n * sizeof(int)));
   int i = 0;
-  char *buf = read_string();
+  char *buf = read_rest_of_line_as_argument();
   if (!buf)
     return;
   char *p = strtok(buf, " \t");
@@ -4493,7 +4493,7 @@ void hyphenate(hyphen_list *h, unsigned flags)
 
 static void read_hyphenation_patterns_from_file(bool append)
 {
-  char *filename = read_string();
+  char *filename = read_rest_of_line_as_argument();
   if (filename != 0 /* nullptr */) {
     if (0 /* nullptr */ == current_language)
       error("no current hyphenation language");
@@ -4513,8 +4513,8 @@ static void load_hyphenation_patterns_from_file()
     return;
   }
   read_hyphenation_patterns_from_file(false /* append */);
-  // No `skip_line()` here; the above function calls `read_string()` and
-  // `tok.next()`.
+  // No `skip_line()` here; the above function calls
+  // `read_rest_of_line_as_argument()` and `tok.next()`.
 }
 
 static void append_hyphenation_patterns_from_file()
@@ -4526,8 +4526,8 @@ static void append_hyphenation_patterns_from_file()
     return;
   }
   read_hyphenation_patterns_from_file(true /* append */);
-  // No `skip_line()` here; the above function calls `read_string()` and
-  // `tok.next()`.
+  // No `skip_line()` here; the above function calls
+  // `read_rest_of_line_as_argument()` and `tok.next()`.
 }
 
 // Most hyphenation functionality is environment-specific; see
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 51364fd96..0530e4df2 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -920,7 +920,7 @@ void next_file()
 {
   char *filename = 0 /* nullptr */;
   if (has_arg(true /* peek */)) {
-    filename = read_string();
+    filename = read_rest_of_line_as_argument();
     tok.next();
   }
   if (0 /* nullptr */ == filename)
@@ -6463,7 +6463,7 @@ void line_file()
   int n;
   if (get_integer(&n)) {
     if (has_arg(true /* peek */)) {
-      const char *reported_file_name = read_string();
+      const char *reported_file_name = read_rest_of_line_as_argument();
       (void) input_stack::set_location(reported_file_name, (n - 1));
       delete[] reported_file_name;
       tok.next();
@@ -6837,7 +6837,7 @@ static void while_continue_request()
 
 void do_source(bool quietly)
 {
-  char *filename = read_string();
+  char *filename = read_rest_of_line_as_argument();
   errno = 0;
   FILE *fp = include_search_path.open_file_cautious(filename);
   if (fp != 0 /* nullptr */)
@@ -6887,7 +6887,7 @@ void pipe_source_request() // .pso
     skip_line();
     return;
   }
-  char *pcmd = read_string();
+  char *pcmd = read_rest_of_line_as_argument();
   // `has_arg()` should have ensured that this pointer is non-null.
   assert(pcmd != 0 /* nullptr */);
   if (0 /* nullptr */ == pcmd)
@@ -7636,7 +7636,7 @@ static void open_file(bool appending)
 {
   symbol stream = get_name(true /* required */);
   if (!stream.is_null()) {
-    char *filename = read_string();
+    char *filename = read_rest_of_line_as_argument();
     if (filename != 0 /* nullptr */) {
       const string mode = appending ? "appending" : "writing";
       errno = 0;
@@ -7683,7 +7683,8 @@ static void open_request() // .open
   }
   else
     open_file(false /* appending */);
-  // No skip_line() here; open_file() calls read_string(), tok.next().
+  // No skip_line() here; open_file() calls
+  // read_rest_of_line_as_argument(), tok.next().
 }
 
 static void opena_request() // .opena
@@ -7699,7 +7700,8 @@ static void opena_request() // .opena
   }
   else
     open_file(true /* appending */);
-  // No skip_line() here; open_file() calls read_string(), tok.next().
+  // No skip_line() here; open_file() calls
+  // read_rest_of_line_as_argument(), tok.next().
 }
 
 static void close_stream(symbol &stream)
@@ -8625,7 +8627,7 @@ void abort_request()
 // stream pointer.
 //
 // The caller has responsibility for `delete`ing the returned array.
-char *read_string()
+char *read_rest_of_line_as_argument()
 {
   int len = 256;
   char *s = new char[len]; // C++03: new char[len]();
@@ -8676,7 +8678,7 @@ void pipe_output()
     skip_line();
     return;
   }
-  char *pc = read_string();
+  char *pc = read_rest_of_line_as_argument();
   // `has_arg()` should have ensured that this pointer is non-null.
   assert(pc != 0 /* nullptr */);
   if (0 /* nullptr */ == pc)
@@ -8716,7 +8718,7 @@ void system_request()
     skip_line();
     return;
   }
-  char *command = read_string();
+  char *command = read_rest_of_line_as_argument();
   // `has_arg()` should have ensured that this pointer is non-null.
   assert(command != 0 /* nullptr */);
   if (0 /* nullptr */ == command)
@@ -8744,7 +8746,7 @@ void copy_file()
     handle_initial_request(COPY_FILE_REQUEST);
     return;
   }
-  char *filename = read_string();
+  char *filename = read_rest_of_line_as_argument();
   if (want_break)
     curenv->do_break();
   if (filename != 0 /* nullptr */)
@@ -8787,7 +8789,7 @@ void transparent_file()
     handle_initial_request(TRANSPARENT_FILE_REQUEST);
     return;
   }
-  char *filename = read_string();
+  char *filename = read_rest_of_line_as_argument();
   if (want_break)
     curenv->do_break();
   if (filename != 0 /* nullptr */) {
@@ -8952,7 +8954,7 @@ static void process_startup_file(const char *filename)
 
 void do_macro_source(bool quietly)
 {
-  char *macro_filename = read_string();
+  char *macro_filename = read_rest_of_line_as_argument();
   char *path;
   FILE *fp = mac_path->open_file(macro_filename, &path);
   if (fp != 0 /* nullptr */) {
diff --git a/src/roff/troff/token.h b/src/roff/troff/token.h
index 59ffecc97..37a6d3b9c 100644
--- a/src/roff/troff/token.h
+++ b/src/roff/troff/token.h
@@ -115,7 +115,7 @@ extern token tok;           // the current token
 extern symbol get_name(bool /* required */ = false);
 extern symbol get_long_name(bool /* required */ = false);
 extern charinfo *get_optional_char();
-extern char *read_string();
+extern char *read_rest_of_line_as_argument();
 extern void check_missing_character();
 extern void skip_line();
 extern void handle_initial_title();

_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit

Reply via email to