groff-commit
[Top][All Lists]
Advanced

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

[groff] 15/33: [troff]: Slightly refactor (boolify).


From: G. Branden Robinson
Subject: [groff] 15/33: [troff]: Slightly refactor (boolify).
Date: Thu, 30 Dec 2021 00:46:47 -0500 (EST)

gbranden pushed a commit to branch temp-mail-fail
in repository groff.

commit 09d3fb82072c054b6e623fd6e0ab0c784e7935b4
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Fri Dec 24 21:11:45 2021 +1100

    [troff]: Slightly refactor (boolify).
    
    * src/roff/troff/div.cpp:
    * src/roff/troff/env.cpp:
    * src/roff/troff/input.cpp: Rename variables and demote from `int` to
      `bool`.  Initialize and assign them using Boolean literals.  The new
      names try harder to express a logical predicate, and start with verbs
      to resist interpretation as noun phrases.
      - exit_started -> is_exit_underway
      - done_end_macro -> is_end_macro_finished
      - seen_last_page_ejector (demoted but not renamed)
      - began_page_in_end_macro (demoted but not renamed)
---
 ChangeLog                | 16 ++++++++++++++++
 src/roff/troff/div.cpp   | 17 +++++++++--------
 src/roff/troff/div.h     |  6 +++---
 src/roff/troff/env.cpp   |  2 +-
 src/roff/troff/input.cpp |  6 +++---
 5 files changed, 32 insertions(+), 15 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 581e8aa1..9d81e5a5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2021-12-24  G. Branden Robinson <g.branden.robinson@gmail.com>
+
+       [troff]: Slightly refactor (boolify).
+
+       * src/roff/troff/div.cpp:
+       * src/roff/troff/env.cpp:
+       * src/roff/troff/input.cpp: Rename variables and demote from
+         `int` to `bool`.  Initialize and assign them using Boolean
+         literals.  The new names try harder to express a logical
+         predicate, and start with verbs to resist interpretation as
+         noun phrases.
+         - exit_started -> is_exit_underway
+         - done_end_macro -> is_end_macro_finished
+         - seen_last_page_ejector (demoted but not renamed)
+         - began_page_in_end_macro (demoted but not renamed)
+
 2021-12-20  G. Branden Robinson <g.branden.robinson@gmail.com>
 
        * tmac/e.tmac: Explain presence of undocumented `$r` and `$R`
diff --git a/src/roff/troff/div.cpp b/src/roff/troff/div.cpp
index 7eda8e2a..002d2e11 100644
--- a/src/roff/troff/div.cpp
+++ b/src/roff/troff/div.cpp
@@ -33,12 +33,12 @@ along with this program.  If not, see 
<http://www.gnu.org/licenses/>. */
 
 #include "nonposix.h"
 
-int exit_started = 0;          // the exit process has started
-int done_end_macro = 0;                // the end macro (if any) has finished
-int seen_last_page_ejector = 0;        // seen the LAST_PAGE_EJECTOR cookie
+bool is_exit_underway = false;
+bool is_end_macro_finished = false;
+bool seen_last_page_ejector = false;
+static bool began_page_in_end_macro = false;
 int last_page_number = 0;      // if > 0, the number of the last page
                                // specified with -o
-static int began_page_in_end_macro = 0;        // a new page was begun during 
the end macro
 
 static int last_post_line_extra_space = 0; // needed for \n(.a
 static int nl_reg_contents = -1;
@@ -573,13 +573,14 @@ void cleanup_and_exit(int exit_code)
 // The optional parameter is for the .trunc register.
 int top_level_diversion::begin_page(vunits n)
 {
-  if (exit_started) {
+  if (is_exit_underway) {
     if (page_count == last_page_count
        ? curenv->is_empty()
-       : (done_end_macro && (seen_last_page_ejector || 
began_page_in_end_macro)))
+       : (is_end_macro_finished && (seen_last_page_ejector
+                                     || began_page_in_end_macro)))
       cleanup_and_exit(EXIT_SUCCESS);
-    if (!done_end_macro)
-      began_page_in_end_macro = 1;
+    if (!is_end_macro_finished)
+      began_page_in_end_macro = true;
   }
   if (last_page_number > 0 && page_number == last_page_number)
     cleanup_and_exit(EXIT_SUCCESS);
diff --git a/src/roff/troff/div.h b/src/roff/troff/div.h
index 4e035716..10e75d07 100644
--- a/src/roff/troff/div.h
+++ b/src/roff/troff/div.h
@@ -150,10 +150,10 @@ public:
 extern top_level_diversion *topdiv;
 extern diversion *curdiv;
 
-extern int exit_started;
-extern int done_end_macro;
+extern bool is_exit_underway;
+extern bool is_end_macro_finished;
+extern bool seen_last_page_ejector;
 extern int last_page_number;
-extern int seen_last_page_ejector;
 
 void spring_trap(symbol);      // implemented by input.c
 extern int trap_sprung_flag;
diff --git a/src/roff/troff/env.cpp b/src/roff/troff/env.cpp
index 31ad774d..0469ec66 100644
--- a/src/roff/troff/env.cpp
+++ b/src/roff/troff/env.cpp
@@ -1718,7 +1718,7 @@ void environment::newline()
   else if (interrupted) {
     interrupted = 0;
     // see environment::final_break
-    prev_line_interrupted = exit_started ? 2 : 1;
+    prev_line_interrupted = is_exit_underway ? 2 : 1;
   }
   else if (center_lines > 0) {
     --center_lines;
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 2c97b2f0..618a2854 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -2568,7 +2568,7 @@ static symbol do_get_long_name(bool required, char end)
 
 void exit_troff()
 {
-  exit_started = 1;
+  is_exit_underway = true;
   topdiv->set_last_page();
   if (!end_macro_name.is_null()) {
     spring_trap(end_macro_name);
@@ -2580,7 +2580,7 @@ void exit_troff()
   process_input_stack();
   end_diversions();
   if (topdiv->get_page_length() > 0) {
-    done_end_macro = 1;
+    is_end_macro_finished = true;
     topdiv->set_ejecting();
     static unsigned char buf[2] = { LAST_PAGE_EJECTOR, '\0' };
     input_stack::push(make_temp_iterator((char *)buf));
@@ -2605,7 +2605,7 @@ void exit_troff()
 void exit_request()
 {
   input_stack::clear();
-  if (exit_started)
+  if (is_exit_underway)
     tok.next();
   else
     exit_troff();



reply via email to

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