gbranden pushed a commit to branch master
in repository groff.

commit b4b268443fe76f4f0db49a2bb7bcf47e730e8dee
Author: G. Branden Robinson <[email protected]>
AuthorDate: Mon Dec 29 05:59:12 2025 -0600

    [troff]: Trivially refactor.
    
    * src/roff/troff/div.h: Rename declaration `cleanup_and_exit()` to
      `write_any_trailer_and_exit()`.  Comment formal argument name as a
      compromise with the Stroustrup-style C++ used in most of groff.
    
    * src/roff/troff/div.cpp (cleanup_and_exit): Rename this...
      (write_any_trailer_and_exit): ...to this.
    
    * src/roff/troff/div.cpp (top_level_diversion::begin_page):
    * src/roff/troff/input.cpp (exit_troff, abort_request, do_error)
      (fatal_with_file_and_line): Migrate call sites.
---
 ChangeLog                | 14 ++++++++++++++
 src/roff/troff/div.cpp   | 10 +++++-----
 src/roff/troff/div.h     |  2 +-
 src/roff/troff/input.cpp |  8 ++++----
 src/roff/troff/node.cpp  |  3 ++-
 5 files changed, 26 insertions(+), 11 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index c77403e8f..43bfafb2f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2025-12-29  G. Branden Robinson <[email protected]>
+
+       [troff]: Trivially refactor.
+
+       * src/roff/troff/div.h: Rename declaration `cleanup_and_exit()`
+       to `write_any_trailer_and_exit()`.  Comment formal argument
+       name as a compromise with the Stroustrup-style C++ used in most
+       of groff.
+       * src/roff/troff/div.cpp (cleanup_and_exit): Rename this...
+       (write_any_trailer_and_exit): ...to this.
+       * src/roff/troff/div.cpp (top_level_diversion::begin_page):
+       * src/roff/troff/input.cpp (exit_troff, abort_request, do_error)
+       (fatal_with_file_and_line): Migrate call sites.
+
 2025-12-29  G. Branden Robinson <[email protected]>
 
        * src/roff/troff/input.cpp: Refactor.
diff --git a/src/roff/troff/div.cpp b/src/roff/troff/div.cpp
index 2b779b732..d237967b2 100644
--- a/src/roff/troff/div.cpp
+++ b/src/roff/troff/div.cpp
@@ -636,10 +636,10 @@ void end_diversions()
   }
 }
 
-// TODO: This might be better named `write_trailer_and_exit()`.  Most
-// formatter state is "cleaned up" in input.cpp:exit_troff().
-void cleanup_and_exit(int exit_code)
+// input.cpp:exit_troff() cleans up most formatter state.
+void write_any_trailer_and_exit(int exit_code)
 {
+  // If output was never initialized, there is no trailer to write.
   if (the_output != 0 /* nullptr */) {
     the_output->trailer(topdiv->get_page_length());
     // If we're already dying, don't call the_output's destructor.  See
@@ -660,12 +660,12 @@ bool top_level_diversion::begin_page(vunits n)
        ? curenv->is_empty()
        : (is_eoi_macro_finished && (seen_last_page_ejector
                                      || began_page_in_eoi_macro)))
-      cleanup_and_exit(EXIT_SUCCESS);
+      write_any_trailer_and_exit(EXIT_SUCCESS);
     if (!is_eoi_macro_finished)
       began_page_in_eoi_macro = true;
   }
   if (last_page_number > 0 && page_number == last_page_number)
-    cleanup_and_exit(EXIT_SUCCESS);
+    write_any_trailer_and_exit(EXIT_SUCCESS);
   if (0 /* nullptr */ == the_output)
     init_output();
   ++page_count;
diff --git a/src/roff/troff/div.h b/src/roff/troff/div.h
index 912b43d0c..04547146a 100644
--- a/src/roff/troff/div.h
+++ b/src/roff/troff/div.h
@@ -175,7 +175,7 @@ void continue_page_eject();
 void handle_first_page_transition();
 void blank_line();
 
-extern void cleanup_and_exit(int);
+extern void write_any_trailer_and_exit(int /* exit_code */);
 
 // Local Variables:
 // fill-column: 72
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 20fe1b165..18f7bfe26 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -3319,7 +3319,7 @@ void exit_troff()
     process_input_stack();
   }
   // TODO: delete pointers in file name set.
-  cleanup_and_exit(EXIT_SUCCESS);
+  write_any_trailer_and_exit(EXIT_SUCCESS);
 }
 
 // This implements .ex.  The input stack must be cleared before calling
@@ -9309,7 +9309,7 @@ void abort_request()
 {
   terminal_write(true /* do append newline */ ,
                 false /* interpret leading spaces */);
-  cleanup_and_exit(EXIT_FAILURE);
+  write_any_trailer_and_exit(EXIT_FAILURE);
 }
 
 // Consume the rest of the input line in copy mode and return it as a C
@@ -10695,7 +10695,7 @@ static void do_error(error_type type,
   fputc('\n', stderr);
   fflush(stderr);
   if (type == FATAL)
-    cleanup_and_exit(EXIT_FAILURE);
+    write_any_trailer_and_exit(EXIT_FAILURE);
 }
 
 // This function should have no callers in production builds.
@@ -10766,7 +10766,7 @@ void fatal_with_file_and_line(const char *filename, int 
lineno,
   errprint(format, arg1, arg2, arg3);
   fputc('\n', stderr);
   fflush(stderr);
-  cleanup_and_exit(EXIT_FAILURE);
+  write_any_trailer_and_exit(EXIT_FAILURE);
 }
 
 void error_with_file_and_line(const char *filename, int lineno,
diff --git a/src/roff/troff/node.cpp b/src/roff/troff/node.cpp
index 769ea17ea..acf7d86b1 100644
--- a/src/roff/troff/node.cpp
+++ b/src/roff/troff/node.cpp
@@ -1745,7 +1745,8 @@ real_output_file::~real_output_file()
 {
   if (!fp)
     return;
-  // Prevent destructor from recursing; see div.cpp:cleanup_and_exit().
+  // Prevent destructor from recursing; see
+  // div.cpp:write_any_trailer_and_exit().
   is_dying = true;
   // To avoid looping, set fp to 0 before calling fatal().
   if (ferror(fp)) {

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

Reply via email to