gbranden pushed a commit to branch master
in repository groff.

commit 413611e7187112fed68ab04f30158c716b7425c5
Author: G. Branden Robinson <g.branden.robin...@gmail.com>
AuthorDate: Fri Jul 11 05:41:01 2025 -0500

    [eqn]: Fix code style nits.
    
    * src/preproc/eqn/lex.cpp: Sort libgroff header files before
      program-specific ones.  Give the anonymous `struct` type used for
      `token_table` a name, so that it can be passed to a template function
      C++98-conformantly.
    
      (init_table): Use `array_length()` on `token_table`, `common_defs`,
      `troff_defs`, and `mathml_defs` instead of `sizeof` and division.
---
 ChangeLog               | 10 ++++++++++
 src/preproc/eqn/lex.cpp | 18 ++++++++++--------
 2 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 935b8e07d..5391a53fc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2025-07-11  G. Branden Robinson <g.branden.robin...@gmail.com>
+
+       * src/preproc/eqn/lex.cpp: Fix code style nits.  Sort libgroff
+       header files before program-specific ones.  Give the anonymous
+       `struct` type used for `token_table` a name, so that it can be
+       passed to a template function C++98-conformantly.
+       (init_table): Use `array_length()` on `token_table`,
+       `common_defs`, `troff_defs`, and `mathml_defs` instead of
+       `sizeof` and division.
+
 2025-07-11  G. Branden Robinson <g.branden.robin...@gmail.com>
 
        * src/libs/libgroff/font.cpp: Fix code style nits.  Give the
diff --git a/src/preproc/eqn/lex.cpp b/src/preproc/eqn/lex.cpp
index d8304f34c..44aa576cd 100644
--- a/src/preproc/eqn/lex.cpp
+++ b/src/preproc/eqn/lex.cpp
@@ -1,4 +1,4 @@
-/* Copyright (C) 1989-2024 Free Software Foundation, Inc.
+/* Copyright (C) 1989-2025 Free Software Foundation, Inc.
      Written by James Clark (j...@jclark.com)
 
 This file is part of groff.
@@ -20,10 +20,12 @@ along with this program.  If not, see 
<http://www.gnu.org/licenses/>. */
 #include <config.h>
 #endif
 
+#include "lib.h" // array_length()
+#include "ptable.h"
+#include "stringclass.h"
+
 #include "eqn.h"
 #include "eqn.hpp"
-#include "stringclass.h"
-#include "ptable.h"
 
 // declarations to avoid friend name injection problems
 int get_char();
@@ -57,7 +59,7 @@ implement_ptable(definition)
 
 PTABLE(definition) macro_table;
 
-static struct {
+static struct eqn_primitive {
   const char *name;
   int token;
 } token_table[] = {
@@ -283,13 +285,13 @@ static struct builtin_def mathml_defs[] = {
 void init_table(const char *device)
 {
   unsigned int i;
-  for (i = 0; i < sizeof(token_table)/sizeof(token_table[0]); i++) {
+  for (i = 0; i < array_length(token_table); i++) {
     definition *def = new definition[1];
     def->is_macro = 0;
     def->tok = token_table[i].token;
     macro_table.define(token_table[i].name, def);
   }
-  for (i = 0; i < sizeof(common_defs)/sizeof(common_defs[0]); i++) {
+  for (i = 0; i < array_length(common_defs); i++) {
     definition *def = new definition[1];
     def->is_macro = 1;
     def->contents = strsave(common_defs[i].def);
@@ -297,7 +299,7 @@ void init_table(const char *device)
     macro_table.define(common_defs[i].name, def);
   }
   if (output_format == troff) {
-    for (i = 0; i < sizeof(troff_defs)/sizeof(troff_defs[0]); i++) {
+    for (i = 0; i < array_length(troff_defs); i++) {
       definition *def = new definition[1];
       def->is_macro = 1;
       def->contents = strsave(troff_defs[i].def);
@@ -306,7 +308,7 @@ void init_table(const char *device)
     }
   }
   else if (output_format == mathml) {
-    for (i = 0; i < sizeof(mathml_defs)/sizeof(mathml_defs[0]); i++) {
+    for (i = 0; i < array_length(mathml_defs); i++) {
       definition *def = new definition[1];
       def->is_macro = 1;
       def->contents = strsave(mathml_defs[i].def);

_______________________________________________
groff-commit mailing list
groff-commit@gnu.org
https://lists.gnu.org/mailman/listinfo/groff-commit

Reply via email to