gbranden pushed a commit to branch master
in repository groff.

commit 293222cffd76244a20c98d54e0ff68d6bd3ecbef
Author: G. Branden Robinson <[email protected]>
AuthorDate: Fri Jul 11 05:32:34 2025 -0500

    src/libs/libgroff/font.cpp: Fix code style nits.
    
    * src/libs/libgroff/font.cpp: Give the anonymous `struct` type used for
      `table` a name, so that it can be passed to a template function
      C++98-conformantly.  Give `table` a better name:
      `numeric_directive_table`.  Now that their enclosures have better
      names, give the `numeric_directive` `struct` element
      `numeric_directive` the better name `name`.
    
      (font::load_desc): Track renames.  Use a `size_t` as the loop index.
      Parenthesize (formally) complex pexpressions.  Use `array_length()` on
      `numeric_directive_table` instead of `sizeof` and division.
---
 ChangeLog                  | 13 +++++++++++++
 src/libs/libgroff/font.cpp | 20 +++++++++++---------
 2 files changed, 24 insertions(+), 9 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 5df97d06d..935b8e07d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2025-07-11  G. Branden Robinson <[email protected]>
+
+       * src/libs/libgroff/font.cpp: Fix code style nits.  Give the
+       anonymous `struct` type used for `table` a name, so that it
+       can be passed to a template function C++98-conformantly.  Give
+       `table` a better name: `numeric_directive_table`.  Now that
+       their enclosures have better names, give the `numeric_directive`
+       `struct` element `numeric_directive` the better name `name`.
+       (font::load_desc): Track renames.  Use a `size_t` as the loop
+       index.  Parenthesize (formally) complex pexpressions.  Use
+       `array_length()` on `numeric_directive_table` instead of
+       `sizeof` and division.
+
 2025-07-14  G. Branden Robinson <[email protected]>
 
        * src/devices/grolj4/lj4.cpp (lookup_paper_size): Sanity-check
diff --git a/src/libs/libgroff/font.cpp b/src/libs/libgroff/font.cpp
index 35564338a..faef870fe 100644
--- a/src/libs/libgroff/font.cpp
+++ b/src/libs/libgroff/font.cpp
@@ -29,7 +29,7 @@ along with this program.  If not, see 
<http://www.gnu.org/licenses/>. */
 #include <string.h> // strerror()
 #include <wchar.h>
 
-#include "lib.h"
+#include "lib.h" // array_length()
 
 #include "errarg.h"
 #include "error.h"
@@ -1256,10 +1256,10 @@ bool font::load(bool load_header_only)
   return true;
 }
 
-static struct {
-  const char *numeric_directive;
+static struct numeric_directive {
+  const char *name;
   int *ptr;
-} table[] = {
+} numeric_directive_table[] = {
   { "res", &font::res },
   { "hor", &font::hor },
   { "vert", &font::vert },
@@ -1286,10 +1286,12 @@ const char *font::load_desc()
     char *p = strtok(t.buf, WS);
     assert(p != 0 /* nullptr */);
     bool numeric_directive_found = false;
-    unsigned int idx;
-    for (idx = 0; !numeric_directive_found
-                 && idx < sizeof(table) / sizeof(table[0]); idx++)
-      if (strcmp(table[idx].numeric_directive, p) == 0)
+    size_t idx;
+    for (idx = 0;
+        (!numeric_directive_found
+         && (idx < array_length(numeric_directive_table)));
+        idx++)
+      if (strcmp(numeric_directive_table[idx].name, p) == 0)
        numeric_directive_found = true;
     if (numeric_directive_found) {
       char *q = strtok(0 /* nullptr */, WS);
@@ -1314,7 +1316,7 @@ const char *font::load_desc()
                " positive number, got '%2'", p, val);
        return 0 /* nullptr */;
       }
-      *(table[idx-1].ptr) = val;
+      *(numeric_directive_table[idx - 1].ptr) = val;
     }
     else if (strcmp("family", p) == 0) {
       p = strtok(0 /* nullptr */, WS);

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

Reply via email to