groff-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[groff] 07/07: [troff]: Trivially refactor (trap Booleans).


From: G. Branden Robinson
Subject: [groff] 07/07: [troff]: Trivially refactor (trap Booleans).
Date: Thu, 25 Jan 2024 15:49:56 -0500 (EST)

gbranden pushed a commit to branch master
in repository groff.

commit c4a97613b1865f006272e181467931254f245b95
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Thu Jan 25 10:25:12 2024 -0600

    [troff]: Trivially refactor (trap Booleans).
    
    * src/roff/troff/div.h:
    * src/roff/troff/input.cpp: Rename trap-related flags and boolify them.
      Assign to them using Boolean literals.
      - `trap_sprung_flag` -> `was_trap_sprung`
      - `postpone_traps_flag` -> `are_traps_postponed`
    
    * src/roff/troff/div.cpp (space_request):
    * src/roff/troff/env.cpp (pending_output_line::output)
      (environment::output)
      (environment::output_title)
    * src/roff/troff/input.cpp (process_input_stack, spring_trap)
      (postpone_traps, unpostpone_traps):
      Update variable access sites.
    
    * src/roff/troff/div.h:
    * src/roff/troff/input.cpp: Demote return type of `unpostpone_traps()`
      from `int` to `bool`.
      (unpostpone_traps): Return Boolean, not integer, literals.
    
    Also annotate null pointers with `nullptr` comment to ease any future
    transition to C++11, which defines it as a keyword.
---
 ChangeLog                | 23 +++++++++++++++++++++++
 src/roff/troff/div.cpp   |  2 +-
 src/roff/troff/div.h     |  4 ++--
 src/roff/troff/env.cpp   |  8 ++++----
 src/roff/troff/input.cpp | 22 +++++++++++-----------
 5 files changed, 41 insertions(+), 18 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index a7a69c61f..7c42add2e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,26 @@
+2024-01-25  G. Branden Robinson <g.branden.robinson@gmail.com>
+
+       [troff]: Trivially refactor (trap Booleans).
+
+       * src/roff/troff/div.h:
+       * src/roff/troff/input.cpp: Rename trap-related flags and
+       boolify them.  Assign to them using Boolean literals.
+       - `trap_sprung_flag` -> `was_trap_sprung`
+       - `postpone_traps_flag` -> `are_traps_postponed`
+
+       * src/roff/troff/div.cpp (space_request):
+       * src/roff/troff/env.cpp (pending_output_line::output)
+       (environment::output)
+       (environment::output_title)
+       * src/roff/troff/input.cpp (process_input_stack, spring_trap)
+       (postpone_traps, unpostpone_traps):
+       Update variable access sites.
+
+       * src/roff/troff/div.h:
+       * src/roff/troff/input.cpp: Demote return type of
+       `unpostpone_traps()` from `int` to `bool`.
+       (unpostpone_traps): Return Boolean, not integer, literals.
+
 2024-01-23  G. Branden Robinson <g.branden.robinson@gmail.com>
 
        * doc/groff.texi: Resolve warnings thrown by Texinfo 7.1.
diff --git a/src/roff/troff/div.cpp b/src/roff/troff/div.cpp
index 6ac9ef017..29d6ebe20 100644
--- a/src/roff/troff/div.cpp
+++ b/src/roff/troff/div.cpp
@@ -821,7 +821,7 @@ void space_request()
 void blank_line()
 {
   curenv->do_break();
-  if (!trap_sprung_flag && !curdiv->no_space_mode)
+  if (!was_trap_sprung && !curdiv->no_space_mode)
     curdiv->space(curenv->get_vertical_spacing());
   else
     truncated_space += curenv->get_vertical_spacing();
diff --git a/src/roff/troff/div.h b/src/roff/troff/div.h
index 1ffc8cc23..d8d83a297 100644
--- a/src/roff/troff/div.h
+++ b/src/roff/troff/div.h
@@ -159,9 +159,9 @@ extern bool seen_last_page_ejector;
 extern int last_page_number;
 
 void spring_trap(symbol);      // implemented by input.c
-extern int trap_sprung_flag;
+extern bool was_trap_sprung;
 void postpone_traps();
-int unpostpone_traps();
+bool unpostpone_traps();
 
 void push_page_ejector();
 void continue_page_eject();
diff --git a/src/roff/troff/env.cpp b/src/roff/troff/env.cpp
index fdcb24b59..14295b08f 100644
--- a/src/roff/troff/env.cpp
+++ b/src/roff/troff/env.cpp
@@ -119,12 +119,12 @@ pending_output_line::~pending_output_line()
 
 int pending_output_line::output()
 {
-  if (trap_sprung_flag)
+  if (was_trap_sprung)
     return 0;
 #ifdef WIDOW_CONTROL
   if (next && next->last_line && !no_fill) {
     curdiv->need(vs + post_vs + vunits(vresolution));
-    if (trap_sprung_flag) {
+    if (was_trap_sprung) {
       next->last_line = 0;     // Try to avoid infinite loops.
       return 0;
     }
@@ -153,7 +153,7 @@ void environment::output(node *nd, int no_fill_flag,
 #else /* WIDOW_CONTROL */
   output_pending_lines();
 #endif /* WIDOW_CONTROL */
-  if (!trap_sprung_flag && !pending_lines
+  if (!was_trap_sprung && !pending_lines
 #ifdef WIDOW_CONTROL
       && (!widow_control || no_fill_flag)
 #endif /* WIDOW_CONTROL */
@@ -175,7 +175,7 @@ void environment::output_title(node *nd, int no_fill_flag,
                               vunits vs, vunits post_vs,
                               hunits width)
 {
-  if (!trap_sprung_flag)
+  if (!was_trap_sprung)
     curdiv->output(nd, no_fill_flag, vs, post_vs, width);
   else
     pending_lines = new pending_output_line(nd, no_fill_flag, vs, post_vs,
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 75d723d36..39a3c8012 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -3209,7 +3209,7 @@ void process_input_stack()
     }
     if (!suppress_next)
       tok.next();
-    trap_sprung_flag = 0;
+    was_trap_sprung = false;
   }
 }
 
@@ -4272,15 +4272,15 @@ static void report_composite_characters()
   skip_line();
 }
 
-int trap_sprung_flag = 0;
-int postpone_traps_flag = 0;
+bool was_trap_sprung = false;
+static bool are_traps_postponed = false;
 symbol postponed_trap;
 
 void spring_trap(symbol nm)
 {
   assert(!nm.is_null());
-  trap_sprung_flag = 1;
-  if (postpone_traps_flag) {
+  was_trap_sprung = true;
+  if (are_traps_postponed) {
     postponed_trap = nm;
     return;
   }
@@ -4301,19 +4301,19 @@ void spring_trap(symbol nm)
 
 void postpone_traps()
 {
-  postpone_traps_flag = 1;
+  are_traps_postponed = true;
 }
 
-int unpostpone_traps()
+bool unpostpone_traps()
 {
-  postpone_traps_flag = 0;
+  are_traps_postponed = false;
   if (!postponed_trap.is_null()) {
     spring_trap(postponed_trap);
     postponed_trap = NULL_SYMBOL;
-    return 1;
+    return true;
   }
   else
-    return 0;
+    return false;
 }
 
 void read_request()
@@ -4398,7 +4398,7 @@ void do_define_string(define_mode mode, comp_mode comp)
     c = get_copy(&n);
   macro mac;
   request_or_macro *rm = (request_or_macro *)request_dictionary.lookup(nm);
-  macro *mm = rm ? rm->to_macro() : 0;
+  macro *mm = rm ? rm->to_macro() : 0 /* nullptr */;
   if (mode == DEFINE_APPEND && mm)
     mac = *mm;
   if (comp == COMP_DISABLE)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]