gbranden pushed a commit to branch master
in repository groff.

commit 5edb38a93fd6345cac66ca7a0f068b69936df17b
Author: G. Branden Robinson <[email protected]>
AuthorDate: Tue Nov 18 01:16:00 2025 -0600

    [troff]: Trivially refactor.
    
    Rename `get_name()` to `read_identifier()`.  Part of the idea here is to
    use the verb "read" to suggest that the function advances the token
    pointer through the input stream (and it does).  Another part is to
    reduce confusion, since the `font_info` and `tfont` classes have an
    unrelated accessor member function `get_name()`.
    
    * src/roff/troff/token.h (get_name): Rename declaration from this...
      (read_identifier): ...to this.
    
    * src/roff/troff/input.cpp  (get_name): Rename definition from this...
      (read_identifier): ...to this.
    
    * src/roff/troff/div.cpp (do_divert, when_request)
      (diversion_trap, change_trap, mark):
    * src/roff/troff/env.cpp (select_fill_color_request)
      (select_stroke_color_request, select_font_request)
      (family_change, do_input_trap, select_hyphenation_language):
    * src/roff/troff/input.cpp (print_color_request)
      (diagnose_invalid_identifier, eoi_macro, blank_line_macro)
      (leading_spaces_macro, do_request, process_input_stack)
      (print_macro_request, map_composite_character)
      (do_define_string, do_define_macro, remove_macro, rename_macro)
      (alias_macro, chop_macro, do_string_case_transform)
      (substring_request, length_request, asciify_request)
      (unformat_macro, device_macro_request)
      (is_conditional_expression_true, open_file, close_request)
      (write_macro_request, define_class_request):
    * src/roff/troff/node.cpp (translate_font)
      (mount_font_at_position, associate_style_with_font_position)
      (read_font_identifier, zoom_font):
    * src/roff/troff/reg.cpp (define_register_request)
      (inline_define_register [0], assign_register_format_request)
      (remove_register_request, alias_register_request)
      (rename_register_request, print_register_request): Update call sites.
---
 ChangeLog                | 39 ++++++++++++++++++++++++++
 src/roff/troff/div.cpp   | 10 +++----
 src/roff/troff/env.cpp   | 12 ++++----
 src/roff/troff/input.cpp | 71 +++++++++++++++++++++++-------------------------
 src/roff/troff/node.cpp  | 17 ++++++------
 src/roff/troff/reg.cpp   | 26 ++++++------------
 src/roff/troff/token.h   |  2 +-
 7 files changed, 103 insertions(+), 74 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 508c9950b..13c398d8e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,42 @@
+2025-11-18  G. Branden Robinson <[email protected]>
+
+       [troff]: Trivially refactor.  Rename `get_name()` to
+       `read_identifier()`.  Part of the idea here is to use the verb
+       "read" to suggest that the function advances the token pointer
+       through the input stream (and it does).  Another part is to
+       reduce confusion, since the `font_info` and `tfont` classes have
+       an unrelated accessor member function `get_name()`.
+
+       * src/roff/troff/token.h (get_name): Rename declaration from
+       this...
+       (read_identifier): ...to this.
+       * src/roff/troff/input.cpp  (get_name): Rename definition from
+       this...
+       (read_identifier): ...to this.
+       * src/roff/troff/div.cpp (do_divert, when_request)
+       (diversion_trap, change_trap, mark):
+       * src/roff/troff/env.cpp (select_fill_color_request)
+       (select_stroke_color_request, select_font_request)
+       (family_change, do_input_trap, select_hyphenation_language):
+       * src/roff/troff/input.cpp (print_color_request)
+       (diagnose_invalid_identifier, eoi_macro, blank_line_macro)
+       (leading_spaces_macro, do_request, process_input_stack)
+       (print_macro_request, map_composite_character)
+       (do_define_string, do_define_macro, remove_macro, rename_macro)
+       (alias_macro, chop_macro, do_string_case_transform)
+       (substring_request, length_request, asciify_request)
+       (unformat_macro, device_macro_request)
+       (is_conditional_expression_true, open_file, close_request)
+       (write_macro_request, define_class_request):
+       * src/roff/troff/node.cpp (translate_font)
+       (mount_font_at_position, associate_style_with_font_position)
+       (read_font_identifier, zoom_font):
+       * src/roff/troff/reg.cpp (define_register_request)
+       (inline_define_register [0], assign_register_format_request)
+       (remove_register_request, alias_register_request)
+       (rename_register_request, print_register_request): Update call
+       sites.
+
 2025-11-17  G. Branden Robinson <[email protected]>
 
        * src/roff/troff/input.cpp (length_request): Drop erroneous
diff --git a/src/roff/troff/div.cpp b/src/roff/troff/div.cpp
index c82dcb820..aa1df9858 100644
--- a/src/roff/troff/div.cpp
+++ b/src/roff/troff/div.cpp
@@ -101,7 +101,7 @@ diversion *curdiv;
 void do_divert(bool appending, bool boxing)
 {
   tok.skip();
-  symbol nm = get_name();
+  symbol nm = read_identifier();
   if (nm.is_null()) {
     // Why the asymmetric diagnostic severity?  See Savannah #67139.
     if (!(curdiv->is_box) && boxing)
@@ -768,7 +768,7 @@ void when_request()
 {
   vunits n;
   if (get_vunits(&n, 'v')) {
-    symbol s = get_name();
+    symbol s = read_identifier();
     if (s.is_null())
       topdiv->remove_trap_at(n);
     else
@@ -976,7 +976,7 @@ void diversion_trap()
 {
   vunits n;
   if (has_arg() && get_vunits(&n, 'v')) {
-    symbol s = get_name();
+    symbol s = read_identifier();
     if (!s.is_null())
       curdiv->set_diversion_trap(s, n);
     else
@@ -989,7 +989,7 @@ void diversion_trap()
 
 void change_trap()
 {
-  symbol s = get_name(true /* required */);
+  symbol s = read_identifier(true /* required */);
   if (!s.is_null()) {
     vunits x;
     if (has_arg() && get_vunits(&x, 'v'))
@@ -1008,7 +1008,7 @@ void print_traps()
 
 void mark()
 {
-  symbol s = get_name();
+  symbol s = read_identifier();
   if (s.is_null())
     curdiv->marked_place = curdiv->get_vertical_position();
   else if (curdiv == topdiv)
diff --git a/src/roff/troff/env.cpp b/src/roff/troff/env.cpp
index d1f7fde3f..7a58fbf8d 100644
--- a/src/roff/troff/env.cpp
+++ b/src/roff/troff/env.cpp
@@ -1262,7 +1262,7 @@ node *environment::extract_output_line()
 
 static void select_fill_color_request()
 {
-  symbol s = get_name();
+  symbol s = read_identifier();
   if (s.is_null())
     curenv->set_fill_color(curenv->get_prev_fill_color());
   else
@@ -1272,7 +1272,7 @@ static void select_fill_color_request()
 
 static void select_stroke_color_request()
 {
-  symbol s = get_name();
+  symbol s = read_identifier();
   if (s.is_null())
     curenv->set_stroke_color(curenv->get_prev_stroke_color());
   else
@@ -1322,7 +1322,7 @@ void select_font(symbol s)
 
 static void select_font_request()
 {
-  select_font(get_name());
+  select_font(read_identifier());
   skip_line();
 }
 
@@ -1332,7 +1332,7 @@ void family_change()
     skip_line();
     return;
   }
-  symbol s = get_name();
+  symbol s = read_identifier();
   curenv->set_family(s);
   skip_line();
 }
@@ -2783,7 +2783,7 @@ void do_input_trap(bool respect_continuation)
       warning(WARN_RANGE,
              "input trap line count must be greater than zero");
     else {
-      symbol s = get_name(true /* required */);
+      symbol s = read_identifier(true /* required */);
       if (!s.is_null()) {
        curenv->input_trap_count = n;
        curenv->input_trap = s;
@@ -3751,7 +3751,7 @@ static void select_hyphenation_language()
     skip_line();
     return;
   }
-  symbol nm = get_name();
+  symbol nm = read_identifier();
   if (!nm.is_null()) {
     current_language = static_cast<hyphenation_language *>
       (language_dictionary.lookup(nm));
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index c829edba3..54861dc39 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -1595,7 +1595,7 @@ static void print_color_request()
   color *value;
   if (has_arg()) {
     do {
-      key = get_name();
+      key = read_identifier();
       value = static_cast<color *>(color_dictionary.lookup(key));
       if (value != 0 /* nullptr */)
        errprint("%1\t%2\n", key.contents(), value->print_color());
@@ -3009,7 +3009,7 @@ static void diagnose_invalid_identifier()
     error("%1 is not allowed in an identifier", tok.description());
 }
 
-symbol get_name(bool required)
+symbol read_identifier(bool required)
 {
   if (want_att_compat) {
     char buf[3];
@@ -3160,19 +3160,19 @@ void return_macro_request()
 
 void eoi_macro()
 {
-  end_of_input_macro_name = get_name();
+  end_of_input_macro_name = read_identifier();
   skip_line();
 }
 
 void blank_line_macro()
 {
-  blank_line_macro_name = get_name();
+  blank_line_macro_name = read_identifier();
   skip_line();
 }
 
 void leading_spaces_macro()
 {
-  leading_spaces_macro_name = get_name();
+  leading_spaces_macro_name = read_identifier();
   skip_line();
 }
 
@@ -3196,7 +3196,7 @@ void do_request()
   }
   want_att_compat_stack.push(want_att_compat);
   want_att_compat = false;
-  symbol nm = get_name();
+  symbol nm = read_identifier();
   if (nm.is_null())
     skip_line();
   else
@@ -3322,7 +3322,7 @@ void process_input_stack()
          do {
            tok.next();
          } while (tok.is_white_space());
-         symbol nm = get_name();
+         symbol nm = read_identifier();
 #if defined(DEBUGGING)
          if (want_html_debugging) {
            if (!nm.is_null()) {
@@ -4015,9 +4015,8 @@ void print_macro_request()
   symbol s;
   if (has_arg()) {
     do {
-      s = get_name();
+      s = read_identifier();
       if (s.is_null())
-       // get_name() already threw an error.
        break;
       rm = static_cast<request_or_macro *>(request_dictionary.lookup(s));
       if (rm != 0 /* nullptr */)
@@ -4584,7 +4583,7 @@ dictionary composite_dictionary(17);
 
 static void map_composite_character()
 {
-  symbol from = get_name();
+  symbol from = read_identifier();
   if (from.is_null()) {
     warning(WARN_MISSING, "composite character mapping request expects"
            " arguments");
@@ -4605,7 +4604,7 @@ static void map_composite_character()
   const char *from_decomposed = decompose_unicode(from_gn);
   if (from_decomposed != 0 /* nullptr */)
     from_gn = &from_decomposed[1];
-  symbol to = get_name();
+  symbol to = read_identifier();
   if (to.is_null()) {
     composite_dictionary.remove(symbol(from_gn));
     skip_line();
@@ -4806,7 +4805,7 @@ void do_define_string(define_mode mode, comp_mode comp)
   symbol nm;
   node *n = 0 /* nullptr */;
   int c;
-  nm = get_name(true /* required */);
+  nm = read_identifier(true /* required */);
   if (nm.is_null()) {
     skip_line();
     return;
@@ -4816,7 +4815,6 @@ void do_define_string(define_mode mode, comp_mode comp)
   else if (tok.is_tab())
     c = '\t';
   else if (!tok.is_space()) {
-    // get_name() should have thrown a particularized diagnostic
     skip_line();
     return;
   }
@@ -5230,12 +5228,12 @@ void do_define_macro(define_mode mode, calling_mode 
calling, comp_mode comp)
 {
   symbol nm, term, dot_symbol(".");
   if (calling == CALLING_INDIRECT) {
-    symbol temp1 = get_name(true /* required */);
+    symbol temp1 = read_identifier(true /* required */);
     if (temp1.is_null()) {
       skip_line();
       return;
     }
-    symbol temp2 = get_name();
+    symbol temp2 = read_identifier();
     input_stack::push(make_temp_iterator("\n"));
     if (!temp2.is_null()) {
       interpolate_string(temp2);
@@ -5246,13 +5244,13 @@ void do_define_macro(define_mode mode, calling_mode 
calling, comp_mode comp)
     tok.next();
   }
   if (mode == DEFINE_NORMAL || mode == DEFINE_APPEND) {
-    nm = get_name(true /* required */);
+    nm = read_identifier(true /* required */);
     if (nm.is_null()) {
       skip_line();
       return;
     }
   }
-  term = get_name();   // the request that terminates the definition
+  term = read_identifier(); // terminating name
   if (term.is_null())
     term = dot_symbol;
   while (!tok.is_newline() && !tok.is_eof())
@@ -5426,7 +5424,7 @@ void remove_macro()
     return;
   }
   for (;;) {
-    symbol s = get_name();
+    symbol s = read_identifier();
     if (s.is_null())
       break;
     request_dictionary.remove(s);
@@ -5441,10 +5439,10 @@ void rename_macro()
     skip_line();
     return;
   }
-  symbol s1 = get_name();
+  symbol s1 = read_identifier();
   assert(s1 != 0 /* nullptr */);
   if (!s1.is_null()) {
-    symbol s2 = get_name();
+    symbol s2 = read_identifier();
     if (s2.is_null())
       warning(WARN_MISSING, "renaming request expects identifier of"
              " existing request, macro, string, or diversion as"
@@ -5462,10 +5460,10 @@ void alias_macro()
     skip_line();
     return;
   }
-  symbol s1 = get_name();
+  symbol s1 = read_identifier();
   assert(s1 != 0 /* nullptr */);
   if (!s1.is_null()) {
-    symbol s2 = get_name();
+    symbol s2 = read_identifier();
     if (s2.is_null())
       warning(WARN_MISSING, "name aliasing request expects identifier"
              " of existing request, macro, string, or diversion as"
@@ -5485,7 +5483,7 @@ void chop_macro()
     skip_line();
     return;
   }
-  symbol s = get_name();
+  symbol s = read_identifier();
   assert(s != 0 /* nullptr */);
   if (!s.is_null()) {
     request_or_macro *p = lookup_request(s);
@@ -5532,7 +5530,7 @@ enum case_xform_mode { STRING_UPCASE, STRING_DOWNCASE };
 void do_string_case_transform(case_xform_mode mode)
 {
   assert((mode == STRING_DOWNCASE) || (mode == STRING_UPCASE));
-  symbol s = get_name();
+  symbol s = read_identifier();
   assert(s != 0 /* nullptr */);
   if (s.is_null()) {
     skip_line();
@@ -5598,7 +5596,7 @@ void substring_request()
     return;
   }
   int start;                   // 0, 1, ..., n-1  or  -1, -2, ...
-  symbol s = get_name();
+  symbol s = read_identifier();
   assert(s != 0 /* nullptr */);
   if (!s.is_null() && get_integer(&start)) {
     request_or_macro *p = lookup_request(s);
@@ -5694,7 +5692,7 @@ void length_request()
     return;
   }
   symbol ret;
-  ret = get_name();
+  ret = read_identifier();
   if (ret.is_null()) {
     // The identifier was garbage, like `a\&b`.
     skip_line();
@@ -5707,7 +5705,6 @@ void length_request()
   else if (tok.is_tab())
     c = '\t';
   else if (!tok.is_space()) {
-    // get_name() should have thrown a particularized diagnostic
     skip_line();
     return;
   }
@@ -5738,7 +5735,7 @@ static void asciify_request()
     skip_line();
     return;
   }
-  symbol s = get_name();
+  symbol s = read_identifier();
   if (!s.is_null()) {
     request_or_macro *p = lookup_request(s);
     macro *m = p->to_macro();
@@ -5774,7 +5771,7 @@ void unformat_macro()
     skip_line();
     return;
   }
-  symbol s = get_name();
+  symbol s = read_identifier();
   if (!s.is_null()) {
     request_or_macro *p = lookup_request(s);
     macro *m = p->to_macro();
@@ -6657,7 +6654,7 @@ static void device_request()
 
 static void device_macro_request()
 {
-  symbol s = get_name(true /* required */);
+  symbol s = read_identifier(true /* required */);
   if (!(s.is_null() || s.is_empty())) {
     request_or_macro *p = lookup_request(s);
     macro *m = p->to_macro();
@@ -6970,7 +6967,7 @@ static bool is_conditional_expression_true()
   // Check for GNU troff extended conditional expression operators.
   else if ((c == 'd') || (c == 'r')) {
     tok.next();
-    symbol nm = get_name(true /* required */);
+    symbol nm = read_identifier(true /* required */);
     if (nm.is_null()) {
       skip_branch();
       return false;
@@ -7989,7 +7986,7 @@ static void print_stream_request()
 
 static void open_file(bool appending)
 {
-  symbol stream = get_name(true /* required */);
+  symbol stream = read_identifier(true /* required */);
   if (!stream.is_null()) {
     char *filename = read_rest_of_line_as_argument();
     if (filename != 0 /* nullptr */) {
@@ -8108,7 +8105,7 @@ static void close_request() // .close
     skip_line();
     return;
   }
-  symbol stream = get_name();
+  symbol stream = read_identifier();
   // Testing has_arg() should have ensured this.
   assert(stream != 0 /* nullptr */);
   if (!stream.is_null())
@@ -8120,7 +8117,7 @@ static void close_request() // .close
 
 void do_write_request(int newline)
 {
-  symbol stream = get_name(true /* required */);
+  symbol stream = read_identifier(true /* required */);
   if (stream.is_null()) {
     skip_line();
     return;
@@ -8169,7 +8166,7 @@ void write_request_continue()
 
 void write_macro_request()
 {
-  symbol stream = get_name(true /* required */);
+  symbol stream = read_identifier(true /* required */);
   if (stream.is_null()) {
     skip_line();
     return;
@@ -8182,7 +8179,7 @@ void write_macro_request()
     skip_line();
     return;
   }
-  symbol s = get_name(true /* required */);
+  symbol s = read_identifier(true /* required */);
   if (s.is_null()) {
     skip_line();
     return;
@@ -8529,7 +8526,7 @@ dictionary char_class_dictionary(501);
 static void define_class_request()
 {
   tok.skip();
-  symbol nm = get_name(true /* required */);
+  symbol nm = read_identifier(true /* required */);
   if (nm.is_null()) {
     skip_line();
     return;
diff --git a/src/roff/troff/node.cpp b/src/roff/troff/node.cpp
index a46da10d2..92553bb1d 100644
--- a/src/roff/troff/node.cpp
+++ b/src/roff/troff/node.cpp
@@ -6759,14 +6759,15 @@ static void translate_font()
     skip_line();
     return;
   }
-  symbol from = get_name(true /* required */);
-  assert(!from.is_null()); // has_arg()+get_name() should ensure this
+  symbol from = read_identifier(true /* required */);
+  // has_arg()+read_identifier() should ensure the assertion succeeds.
+  assert(!from.is_null());
   if (is_nonnegative_integer(from.contents())) {
     error("cannot translate a font mounting position");
     skip_line();
     return;
   }
-  symbol to = get_name();
+  symbol to = read_identifier();
   if ((!to.is_null()) && is_nonnegative_integer(to.contents())) {
     error("cannot translate to a font mounting position");
     skip_line();
@@ -6805,7 +6806,7 @@ static void mount_font_at_position()
     if (n < 0)
       error("font mounting position %1 is negative", n);
     else {
-      symbol internal_name = get_name(true /* required */);
+      symbol internal_name = read_identifier(true /* required */);
       if (!internal_name.is_null()) {
        symbol filename = get_long_name();
        if (!mount_font(n, internal_name, filename)) {
@@ -6930,7 +6931,7 @@ static void associate_style_with_font_position()
        warning(WARN_MISSING, "abstract style configuration request"
                " expects a style name as second argument");
       else {
-       symbol internal_name = get_name(true /* required */);
+       symbol internal_name = read_identifier(true /* required */);
        if (!internal_name.is_null())
          (void) mount_style(n, internal_name);
       }
@@ -6966,7 +6967,7 @@ static bool read_font_identifier(font_lookup_info *finfo)
   int n;
   tok.skip();
   if (tok.is_usable_as_delimiter()) {
-    symbol s = get_name(true /* required */);
+    symbol s = read_identifier(true /* required */);
     finfo->requested_name = const_cast<char *>(s.contents());
     if (!s.is_null()) {
       n = symbol_fontno(s);
@@ -7120,8 +7121,8 @@ static void zoom_font()
     skip_line();
     return;
   }
-  symbol font_name = get_name();
-  // has_arg()+get_name() should ensure the following
+  symbol font_name = read_identifier();
+  // has_arg()+read_identifier() should ensure the assertion succeeds.
   assert(font_name != 0 /* nullptr */);
   if (is_nonnegative_integer(font_name.contents())) {
     warning(WARN_FONT, "cannot set zoom factor of a font mounting"
diff --git a/src/roff/troff/reg.cpp b/src/roff/troff/reg.cpp
index bf6e6b348..b4565cdf9 100644
--- a/src/roff/troff/reg.cpp
+++ b/src/roff/troff/reg.cpp
@@ -334,9 +334,8 @@ void define_register_request()
     skip_line();
     return;
   }
-  symbol nm = get_name();
+  symbol nm = read_identifier();
   if (nm.is_null()) {
-    // get_name() has already thrown an error diagnostic on bogus input.
     skip_line();
     return;
   }
@@ -377,7 +376,7 @@ void inline_define_register()
   if (!start_token.is_usable_as_delimiter(true /* report error */))
     return;
   tok.next();
-  symbol nm = get_name(true /* required */);
+  symbol nm = read_identifier(true /* required */);
   if (nm.is_null())
     return;
   reg *r = static_cast<reg *>(register_dictionary.lookup(nm));
@@ -438,9 +437,8 @@ void assign_register_format_request()
     skip_line();
     return;
   }
-  symbol nm = get_name();
+  symbol nm = read_identifier();
   if (nm.is_null()) {
-    // get_name() has already thrown an error diagnostic on bogus input.
     skip_line();
     return;
   }
@@ -479,8 +477,7 @@ void remove_register_request()
     return;
   }
   for (;;) {
-    symbol s = get_name();
-    // get_name() has already thrown an error diagnostic on bogus input.
+    symbol s = read_identifier();
     if (s.is_null())
       break;
     register_dictionary.remove(s);
@@ -498,16 +495,13 @@ void alias_register_request()
     skip_line();
     return;
   }
-  symbol s1 = get_name();
-  // get_name() has already thrown an error diagnostic on bogus input.
+  symbol s1 = read_identifier();
   if (!s1.is_null()) {
     if (!has_arg())
       warning(WARN_MISSING, "register aliasing request expects"
              " identifier of existing register as second argument");
     else {
-      symbol s2 = get_name();
-      // get_name() has already thrown an error diagnostic on bogus
-      // input.
+      symbol s2 = read_identifier();
       if (!s2.is_null()) {
        if (!register_dictionary.alias(s1, s2))
          error("cannot alias undefined register '%1'", s2.contents());
@@ -525,14 +519,12 @@ void rename_register_request()
     skip_line();
     return;
   }
-  symbol s1 = get_name();
-  // get_name() has already thrown an error diagnostic on bogus input.
+  symbol s1 = read_identifier();
   if (!has_arg())
     warning(WARN_MISSING, "register renaming request exepects new"
            " identifier as second argument");
   else if (!s1.is_null()) {
-    symbol s2 = get_name();
-    // get_name() has already thrown an error diagnostic on bogus input.
+    symbol s2 = read_identifier();
     if (!s2.is_null())
       register_dictionary.rename(s1, s2);
   }
@@ -569,7 +561,7 @@ void print_register_request()
   symbol identifier;
   if (has_arg()) {
     do {
-      identifier = get_name();
+      identifier = read_identifier();
       r = look_up_register(identifier, true /* suppress creation */);
       if (r != 0 /* nullptr */)
        dump_register(&identifier, r);
diff --git a/src/roff/troff/token.h b/src/roff/troff/token.h
index ab7059b60..697cb5142 100644
--- a/src/roff/troff/token.h
+++ b/src/roff/troff/token.h
@@ -122,7 +122,7 @@ public:
 
 extern token tok;              // the current token
 
-extern symbol get_name(bool /* required */ = false);
+extern symbol read_identifier(bool /* required */ = false);
 extern symbol get_long_name(bool /* required */ = false);
 extern charinfo *read_character(); // TODO?: bool /* required */ = false
 extern char *read_rest_of_line_as_argument();

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

Reply via email to