gbranden pushed a commit to branch master
in repository groff.

commit f0bb39a6962f7b7882b1eb74d9973a3adf9b55f8
Author: G. Branden Robinson <[email protected]>
AuthorDate: Fri Nov 28 19:24:21 2025 -0600

    [troff]: Modestly refactor (4/8).
    
    * src/roff/troff/number.cpp (get_incr_number)
      (is_valid_expression, is_valid_term):
      Construct integer from character literal.
    
      (is_valid_term): Store return value of `tok.ch()` in temporary local
      variable of `int`, not `char`, type.
---
 ChangeLog                 |  3 +++
 src/roff/troff/number.cpp | 30 +++++++++++++++---------------
 2 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index d5cd1bf85..2bdd6cf61 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -11,9 +11,12 @@
        * src/roff/troff/div.cpp (return_request):
        * src/roff/troff/reg.cpp (assign_register_format_request):
        * src/roff/troff/env.cpp (configure_tab_stops_request):
+       * src/roff/troff/number.cpp (get_incr_number)
+       (is_valid_expression, is_valid_term):
        Construct integer from character literal.
        * src/roff/troff/env.cpp (adjust):
        * src/roff/troff/reg.cpp (assign_register_format_request):
+       * src/roff/troff/number.cpp (is_valid_term):
        Store return value of `tok.ch()` in local variable of `int`, not
        `char`, type.
        * src/roff/troff/env.cpp: Retype global `TAB_REPEAT_CHAR` from
diff --git a/src/roff/troff/number.cpp b/src/roff/troff/number.cpp
index a55c24eef..16a685f75 100644
--- a/src/roff/troff/number.cpp
+++ b/src/roff/troff/number.cpp
@@ -223,11 +223,11 @@ static incr_number_result get_incr_number(units *res, 
unsigned char si)
   if (!is_valid_expression_start())
     return INVALID;
   incr_number_result result = ASSIGN;
-  if (tok.ch() == '+') {
+  if (tok.ch() == int('+')) { // TODO: grochar
     tok.next();
     result = INCREMENT;
   }
-  else if (tok.ch() == '-') {
+  else if (tok.ch() == int('-')) { // TODO: grochar
     tok.next();
     result = DECREMENT;
   }
@@ -264,7 +264,7 @@ static bool is_valid_expression(units *u, int scaling_unit,
   while (result) {
     if (is_parenthesized)
       tok.skip_spaces();
-    int op = tok.ch();
+    int op = tok.ch();// safely compares to char literals; TODO: grochar
     switch (op) {
     case '+':
     case '-':
@@ -277,29 +277,29 @@ static bool is_valid_expression(units *u, int 
scaling_unit,
       break;
     case '>':
       tok.next();
-      if (tok.ch() == '=') {
+      if (tok.ch() == int('=')) { // TODO: grochar
        tok.next();
        op = OP_GEQ;
       }
-      else if (tok.ch() == '?') {
+      else if (tok.ch() == int('?')) { // TODO: grochar
        tok.next();
        op = OP_MAX;
       }
       break;
     case '<':
       tok.next();
-      if (tok.ch() == '=') {
+      if (tok.ch() == int('=')) { // TODO: grochar
        tok.next();
        op = OP_LEQ;
       }
-      else if (tok.ch() == '?') {
+      else if (tok.ch() == int('?')) { // TODO: grochar
        tok.next();
        op = OP_MIN;
       }
       break;
     case '=':
       tok.next();
-      if (tok.ch() == '=')
+      if (tok.ch() == int('=')) // TODO: grochar
        tok.next();
       break;
     default:
@@ -387,15 +387,15 @@ static bool is_valid_term(units *u, int scaling_unit,
   for (;;)
     if (is_parenthesized && tok.is_space())
       tok.next();
-    else if (tok.ch() == '+')
+    else if (tok.ch() == int('+')) // TODO: grochar
       tok.next();
-    else if (tok.ch() == '-') {
+    else if (tok.ch() == int('-')) { // TODO: grochar
       tok.next();
       is_negative = !is_negative;
     }
     else
       break;
-  unsigned char c = tok.ch();
+  int c = tok.ch(); // safely compares to char literals; TODO: grochar
   switch (c) {
   case '|':
     // | is not restricted to the outermost level
@@ -418,7 +418,7 @@ static bool is_valid_term(units *u, int scaling_unit,
   case '(':
     tok.next();
     c = tok.ch();
-    if (c == ')') {
+    if (c == ')') { // TODO: grochar
       if (is_mandatory)
        return false;
       warning(WARN_SYNTAX, "empty parentheses");
@@ -428,7 +428,7 @@ static bool is_valid_term(units *u, int scaling_unit,
     }
     else if (c != 0 && strchr(SCALING_UNITS, c) != 0) {
       tok.next();
-      if (tok.ch() == ';') {
+      if (tok.ch() == ';') { // TODO: grochar
        tok.next();
        scaling_unit = c;
       }
@@ -446,7 +446,7 @@ static bool is_valid_term(units *u, int scaling_unit,
                             true /* is_parenthesized */, is_mandatory))
       return false;
     tok.skip_spaces();
-    if (tok.ch() != ')') {
+    if (tok.ch() != ')') { // TODO: grochar
       if (is_mandatory)
        return false;
       warning(WARN_SYNTAX, "expected ')', got %1", tok.description());
@@ -507,7 +507,7 @@ static bool is_valid_term(units *u, int scaling_unit,
     return false;
   }
   int divisor = 1;
-  if (tok.ch() == '.') {
+  if (tok.ch() == int('.')) { // TODO: grochar
     tok.next();
     for (;;) {
       c = tok.ch();

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

Reply via email to