gbranden pushed a commit to branch master
in repository groff.

commit 7fc42a60ba320147749bacf136d472ff781a61f0
Author: G. Branden Robinson <[email protected]>
AuthorDate: Fri Aug 23 00:36:42 2024 -0500

    [troff]: Trivially refactor (boolify macro class).
    
    ...renaming member functions and variables and demoting their (return)
    types from `int` to `bool`.
    
    * src/roff/troff/request.h:
    * src/roff/troff/input.cpp: Do it.
        `empty_macro` -> `is_empty_macro`
        `is_a_diversion`
        `is_a_string`
        `empty()` -> `is_empty()`
        `is_diversion()`
        `is_string()`
    
    * src/roff/troff/input.cpp (macro::macro, macro::clear_string_flag)
      (macro::append, macro::is_empty): Use Boolean, not integer, literals
      in initializers and assignments.
---
 ChangeLog                | 19 +++++++++++++++++++
 src/roff/troff/input.cpp | 31 ++++++++++++++++---------------
 src/roff/troff/request.h | 14 +++++++-------
 3 files changed, 42 insertions(+), 22 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index a0deec013..fba9e35d2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+2024-08-23  G. Branden Robinson <[email protected]>
+
+       [troff]: Trivially refactor.  Boolify `macro` class, renaming
+       member functions and variables and demoting their (return) types
+       from `int` to `bool`.
+
+       * src/roff/troff/request.h:
+       * src/roff/troff/input.cpp: Do it.
+       `empty_macro` -> `is_empty_macro`
+       `is_a_diversion`
+       `is_a_string`
+       `empty()` -> `is_empty()`
+       `is_diversion()`
+       `is_string()`
+
+       * src/roff/troff/input.cpp (macro::macro)
+       (macro::clear_string_flag, macro::append, macro::is_empty): Use
+       Boolean, not integer, literals in initializers and assignments.
+
 2024-08-23  G. Branden Robinson <[email protected]>
 
        * src/roff/troff/input.cpp (device_request): Don't write null
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 732185645..c5096e05a 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -3449,20 +3449,20 @@ macro::~macro()
 }
 
 macro::macro()
-: is_a_diversion(0), is_a_string(1)
+: is_a_diversion(false), is_a_string(true)
 {
   if (!input_stack::get_location(1, &filename, &lineno)) {
     filename = 0 /* nullptr */;
     lineno = 0 /* nullptr */;
   }
   len = 0;
-  empty_macro = 1;
+  is_empty_macro = true;
   p = 0; /* nullptr */
 }
 
 macro::macro(const macro &m)
 : filename(m.filename), lineno(m.lineno), len(m.len),
-  empty_macro(m.empty_macro), is_a_diversion(m.is_a_diversion),
+  is_empty_macro(m.is_empty_macro), is_a_diversion(m.is_a_diversion),
   is_a_string(m.is_a_string), p(m.p)
 {
   if (p != 0 /* nullptr */)
@@ -3477,24 +3477,25 @@ macro::macro(int is_div)
     lineno = 0 /* nullptr */;
   }
   len = 0;
-  empty_macro = 1;
-  is_a_string = 1;
+  is_empty_macro = true;
+  // A macro is a string until it contains a newline.
+  is_a_string = true;
   p = 0 /* nullptr */;
 }
 
-int macro::is_diversion()
+bool macro::is_diversion()
 {
   return is_a_diversion;
 }
 
-int macro::is_string()
+bool macro::is_string()
 {
   return is_a_string;
 }
 
 void macro::clear_string_flag()
 {
-  is_a_string = 0;
+  is_a_string = false;
 }
 
 macro &macro::operator=(const macro &m)
@@ -3508,7 +3509,7 @@ macro &macro::operator=(const macro &m)
   filename = m.filename;
   lineno = m.lineno;
   len = m.len;
-  empty_macro = m.empty_macro;
+  is_empty_macro = m.is_empty_macro;
   is_a_diversion = m.is_a_diversion;
   is_a_string = m.is_a_string;
   return *this;
@@ -3528,7 +3529,7 @@ void macro::append(unsigned char c)
   p->cl.append(c);
   ++len;
   if (c != PUSH_GROFF_MODE && c != PUSH_COMP_MODE && c != POP_GROFFCOMP_MODE)
-    empty_macro = 0;
+    is_empty_macro = false;
 }
 
 void macro::set(unsigned char c, int offset)
@@ -3575,7 +3576,7 @@ void macro::append(node *n)
   p->cl.append(0);
   p->nl.append(n);
   ++len;
-  empty_macro = 0;
+  is_empty_macro = false;
 }
 
 void macro::append_unsigned(unsigned int i)
@@ -3991,7 +3992,7 @@ static void interpolate_macro(symbol nm, bool 
do_not_want_next_token)
       r = (request_or_macro *)request_dictionary.lookup(symbol(buf));
       if (r) {
        macro *m = r->to_macro();
-       if (!m || !m->empty())
+       if (!m || !m->is_empty())
          warned = warning(WARN_SPACE,
                           "macro '%1' not defined "
                           "(possibly missing space after '%2')",
@@ -4130,9 +4131,9 @@ macro *macro::to_macro()
   return this;
 }
 
-int macro::empty()
+bool macro::is_empty()
 {
-  return empty_macro == 1;
+  return (is_empty_macro == true);
 }
 
 macro_iterator::macro_iterator(symbol s, macro &m, const char *how_called,
@@ -4923,7 +4924,7 @@ void chop_macro()
     macro *m = p->to_macro();
     if (!m)
       error("cannot chop request '%1'", s.contents());
-    else if (m->empty())
+    else if (m->is_empty())
       error("cannot chop empty object '%1'", s.contents());
     else {
       int have_restore = 0;
diff --git a/src/roff/troff/request.h b/src/roff/troff/request.h
index f60b670f6..85de56809 100644
--- a/src/roff/troff/request.h
+++ b/src/roff/troff/request.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 1989-2020 Free Software Foundation, Inc.
+/* Copyright (C) 1989-2024 Free Software Foundation, Inc.
      Written by James Clark ([email protected])
 
 This file is part of groff.
@@ -45,9 +45,9 @@ class macro : public request_or_macro {
   const char *filename;                // where was it defined?
   int lineno;
   int len;
-  int empty_macro;
-  int is_a_diversion;
-  int is_a_string;             // if it contains no newline
+  bool is_empty_macro;
+  bool is_a_diversion;
+  bool is_a_string;            // if it contains no newline
 public:
   macro_header *p;
   macro();
@@ -66,9 +66,9 @@ public:
   void invoke(symbol, bool);
   macro *to_macro();
   void print_size();
-  int empty();
-  int is_diversion();
-  int is_string();
+  bool is_empty();
+  bool is_diversion();
+  bool is_string();
   void clear_string_flag();
   friend class string_iterator;
   friend void chop_macro();

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

Reply via email to