gbranden pushed a commit to branch master
in repository groff.

commit 95f7038002e78310cf8f0ce18105681a254ce1d3
Author: G. Branden Robinson <[email protected]>
AuthorDate: Sun Aug 25 18:27:12 2024 -0500

    [troff]: Trivially refactor `environment` class.
    
    * src/roff/troff/env.h: Rename (private) member variables.
      `dummy` -> `is_dummy_env`
      `fill` -> `is_filling`
      `spreading` -> `is_spreading`
      `discarding` -> `is_discarding`
    
    * src/roff/troff/env.cpp (environment::add_char)
      (environment::add_node, environment::space_newline)
      (environment::space, environment::environment)
      (environment::copy, environment::get_fill, fill, no_fill)
      (environment::interrupt, environment::newline)
      (environment::output_line, environment::start_line)
      (environment::possibly_break_line)
      (environment::dump_troff_state, environment::do_break)
      (title, environment::print_env): Migrate to new names.
---
 ChangeLog              | 18 +++++++++++
 src/roff/troff/env.cpp | 84 ++++++++++++++++++++++++++------------------------
 src/roff/troff/env.h   | 12 ++++----
 3 files changed, 68 insertions(+), 46 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index cddb7fa96..7e50d107a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2024-08-25  G. Branden Robinson <[email protected]>
+
+       * src/roff/troff/env.h: Trivially refactor `environment` class.
+       Rename (private) member variables.
+       `dummy` -> `is_dummy_env`
+       `fill` -> `is_filling`
+       `spreading` -> `is_spreading`
+       `discarding` -> `is_discarding`
+       * src/roff/troff/env.cpp (environment::add_char)
+       (environment::add_node, environment::space_newline)
+       (environment::space, environment::environment)
+       (environment::copy, environment::get_fill, fill, no_fill)
+       (environment::interrupt, environment::newline)
+       (environment::output_line, environment::start_line)
+       (environment::possibly_break_line)
+       (environment::dump_troff_state, environment::do_break)
+       (title, environment::print_env): Migrate to new names.
+
 2024-08-25  G. Branden Robinson <[email protected]>
 
        * src/roff/troff/input.cpp
diff --git a/src/roff/troff/env.cpp b/src/roff/troff/env.cpp
index cf580bc12..31df9db2c 100644
--- a/src/roff/troff/env.cpp
+++ b/src/roff/troff/env.cpp
@@ -300,7 +300,7 @@ void environment::add_char(charinfo *ci)
   if (line_interrupted)
     ;
   // don't allow fields in dummy environments
-  else if (ci == field_delimiter_char && !dummy) {
+  else if (ci == field_delimiter_char && !is_dummy_env) {
     if (has_current_field)
       wrap_up_field();
     else
@@ -378,7 +378,7 @@ void environment::add_node(node *nd)
   }
   else {
     if (line == 0 /* nullptr */) {
-      if (discarding && nd->discardable()) {
+      if (is_discarding && nd->discardable()) {
        // XXX possibly: input_line_start -= nd->width();
        delete nd;
        return;
@@ -486,8 +486,8 @@ void environment::space_newline()
     return;
   }
   add_node(new word_space_node(x, get_fill_color(), w));
-  possibly_break_line(false, spreading);
-  spreading = false;
+  possibly_break_line(false, is_spreading);
+  is_spreading = false;
 }
 
 void environment::space()
@@ -522,8 +522,8 @@ void environment::space(hunits space_width, hunits 
sentence_space_width)
                               get_fill_color(),
                               new width_list(space_width,
                                              sentence_space_width)));
-  possibly_break_line(false, spreading);
-  spreading = false;
+  possibly_break_line(false, is_spreading);
+  is_spreading = false;
 }
 
 static node *do_underline_special(bool do_underline_spaces)
@@ -688,7 +688,7 @@ void environment::set_fill_color(color *c)
 }
 
 environment::environment(symbol nm)
-: dummy(false),
+: is_dummy_env(false),
   prev_line_length((units_per_inch*13)/2),
   line_length((units_per_inch*13)/2),
   prev_title_length((units_per_inch*13)/2),
@@ -702,7 +702,7 @@ environment::environment(symbol nm)
   space_size(12),
   sentence_space_size(12),
   adjust_mode(ADJUST_BOTH),
-  fill(true),
+  is_filling(true),
   line_interrupted(false),
   prev_line_interrupted(0),
   centered_line_count(0),
@@ -732,8 +732,8 @@ environment::environment(symbol nm)
   tab_char(0),
   leader_char(charset_table['.']),
   has_current_field(false),
-  discarding(false),
-  spreading(false),
+  is_discarding(false),
+  is_spreading(false),
   margin_character_flags(0),
   margin_character_node(0),
   margin_character_distance(points_to_units(10)),
@@ -778,7 +778,7 @@ environment::environment(symbol nm)
 }
 
 environment::environment(const environment *e)
-: dummy(true),
+: is_dummy_env(true),
   prev_line_length(e->prev_line_length),
   line_length(e->line_length),
   prev_title_length(e->prev_title_length),
@@ -796,7 +796,7 @@ environment::environment(const environment *e)
   space_size(e->space_size),
   sentence_space_size(e->sentence_space_size),
   adjust_mode(e->adjust_mode),
-  fill(e->fill),
+  is_filling(e->is_filling),
   line_interrupted(false),
   prev_line_interrupted(0),
   centered_line_count(0),
@@ -826,8 +826,8 @@ environment::environment(const environment *e)
   tab_char(e->tab_char),
   leader_char(e->leader_char),
   has_current_field(false),
-  discarding(false),
-  spreading(false),
+  is_discarding(false),
+  is_spreading(false),
   margin_character_flags(e->margin_character_flags),
   margin_character_node(e->margin_character_node),
   margin_character_distance(e->margin_character_distance),
@@ -878,7 +878,7 @@ void environment::copy(const environment *e)
   space_size = e->space_size;
   sentence_space_size = e->sentence_space_size;
   adjust_mode = e->adjust_mode;
-  fill = e->fill;
+  is_filling = e->is_filling;
   line_interrupted = false;
   prev_line_interrupted = 0;
   centered_line_count = 0;
@@ -904,10 +904,10 @@ void environment::copy(const environment *e)
   control_character = e->control_character;
   no_break_control_character = e->no_break_control_character;
   hyphen_indicator_char = e->hyphen_indicator_char;
-  spreading = false;
+  is_spreading = false;
   line = 0 /* nullptr */;
   pending_lines = 0 /* nullptr */;
-  discarding = false;
+  is_discarding = false;
   tabs = e->tabs;
   using_line_tabs = e->using_line_tabs;
   current_tab = TAB_NONE;
@@ -927,7 +927,7 @@ void environment::copy(const environment *e)
   hyphenation_mode_default = e->hyphenation_mode_default;
   fontno = e->fontno;
   prev_fontno = e->prev_fontno;
-  dummy = e->dummy;
+  is_dummy_env = e->is_dummy_env;
   family = e->family;
   prev_family = e->prev_family;
   leader_node = 0 /* nullptr */;
@@ -1050,7 +1050,7 @@ unsigned environment::get_adjust_mode()
 
 int environment::get_fill()
 {
-  return fill;
+  return is_filling;
 }
 
 hunits environment::get_indent()
@@ -1390,7 +1390,7 @@ void fill()
     tok.next();
   if (want_break)
     curenv->do_break();
-  curenv->fill = true;
+  curenv->is_filling = true;
   tok.next();
 }
 
@@ -1400,7 +1400,7 @@ void no_fill()
     tok.next();
   if (want_break)
     curenv->do_break();
-  curenv->fill = false;
+  curenv->is_filling = false;
   curenv->suppress_next_eol = true;
   tok.next();
 }
@@ -1778,7 +1778,7 @@ void hyphen_line_max_request()
 
 void environment::interrupt()
 {
-  if (!dummy) {
+  if (!is_dummy_env) {
     add_node(new transparent_dummy_node);
     line_interrupted = true;
   }
@@ -1812,7 +1812,7 @@ void environment::newline()
   node *to_be_output = 0 /* nullptr */;
   hunits to_be_output_width;
   prev_line_interrupted = 0;
-  if (dummy)
+  if (is_dummy_env)
     space_newline();
   else if (line_interrupted) {
     line_interrupted = false;
@@ -1838,7 +1838,7 @@ void environment::newline()
     to_be_output_width = width_total;
     line = 0 /* nullptr */;
   }
-  else if (fill)
+  else if (is_filling)
     space_newline();
   else {
     to_be_output = line;
@@ -1847,7 +1847,7 @@ void environment::newline()
   }
   input_line_start = line == 0 /* nullptr */ ? H0 : width_total;
   if (to_be_output) {
-    if (is_writing_html && !fill) {
+    if (is_writing_html && !is_filling) {
       curdiv->modified_tag.incl(MTSM_EOL);
       if (suppress_next_eol)
        suppress_next_eol = false;
@@ -1924,14 +1924,14 @@ void environment::output_line(node *nd, hunits width, 
bool was_centered)
     width += w;
     ++next_line_number;
   }
-  output(nn, !fill, vertical_spacing, total_post_vertical_spacing(), width,
-        was_centered);
+  output(nn, !is_filling, vertical_spacing,
+        total_post_vertical_spacing(), width, was_centered);
 }
 
 void environment::start_line()
 {
   assert(line == 0 /* nullptr */);
-  discarding = false;
+  is_discarding = false;
   line = new line_start_node;
   if (have_temporary_indent) {
     saved_indent = temporary_indent;
@@ -2196,7 +2196,8 @@ void environment::possibly_break_line(bool 
must_break_here,
                                      bool must_adjust)
 {
   bool was_centered = centered_line_count > 0;
-  if (!fill || (current_tab != TAB_NONE) || has_current_field || dummy)
+  if (!is_filling || (current_tab != TAB_NONE) || has_current_field
+      || is_dummy_env)
     return;
   while (line != 0 /* nullptr */
         && (must_adjust
@@ -2271,10 +2272,10 @@ void environment::possibly_break_line(bool 
must_break_here,
        width_total += tem->width();
        space_total += tem->nspaces();
       }
-      discarding = false;
+      is_discarding = false;
     }
     else {
-      discarding = true;
+      is_discarding = true;
       to_be_discarded = line;
       line = 0 /* nullptr */;
     }
@@ -2377,12 +2378,13 @@ void environment::dump_troff_state()
          curenv->centered_line_count);
   fprintf(stderr, SPACES "register 'll' = %d\n",
          curenv->line_length.to_units());
-  fprintf(stderr, SPACES "%sfilling\n", curenv->fill ? "" : "not ");
+  fprintf(stderr, SPACES "%sfilling\n",
+         curenv->is_filling ? "" : "not ");
   fprintf(stderr, SPACES "page offset 'po' = %d\n",
          topdiv->get_page_offset().to_units());
   fprintf(stderr, SPACES "seen_break = %d\n", curenv->seen_break);
   fprintf(stderr, SPACES "seen_space = %d\n", curenv->seen_space);
-  fprintf(stderr, SPACES "discarding = %d\n", curenv->discarding);
+  fprintf(stderr, SPACES "is_discarding = %d\n", curenv->is_discarding);
   fflush(stderr);
 #undef SPACES
 }
@@ -2497,13 +2499,13 @@ void environment::do_break(bool want_adjustment)
     line = line->next;
     delete tem;
   }
-  discarding = false;
+  is_discarding = false;
   input_line_start = H0;
   if (line != 0 /* nullptr */) {
-    if (fill) {
+    if (is_filling) {
       switch (adjust_mode) {
       case ADJUST_CENTER:
-       saved_indent += (target_text_length - width_total)/2;
+       saved_indent += (target_text_length - width_total) / 2;
        was_centered = true;
        break;
       case ADJUST_RIGHT:
@@ -2607,8 +2609,10 @@ void title()
     tem->next = nd;
     nd = tem;
   }
-  curenv->output_title(nd, !curenv->fill, curenv->vertical_spacing,
-                      curenv->total_post_vertical_spacing(), length_title);
+  curenv->output_title(nd, !curenv->is_filling,
+                      curenv->vertical_spacing,
+                      curenv->total_post_vertical_spacing(),
+                      length_title);
   curenv->hyphen_line_count = 0;
   tok.next();
 }
@@ -3430,7 +3434,7 @@ void environment::print_env()
           sentence_space_size);
   errprint("  previous line interrupted/continued: %1\n",
           prev_line_interrupted ? "yes" : "no");
-  errprint("  filling: %1\n", fill ? "on" : "off");
+  errprint("  filling: %1\n", is_filling ? "on" : "off");
   errprint("  alignment/adjustment: %1\n",
           adjust_mode == ADJUST_LEFT
             ? "left"
@@ -3485,7 +3489,7 @@ void environment::print_env()
   errprint("  computing tab stops from: %1\n",
           using_line_tabs ? "output line start (\"line tabs\")"
             : "input line start");
-  errprint("  forcing adjustment: %1\n", spreading ? "yes" : "no");
+  errprint("  forcing adjustment: %1\n", is_spreading ? "yes" : "no");
   if (margin_character_node != 0 /* nullptr */) {
     errprint("  margin character flags: %1\n",
             margin_character_flags == MARGIN_CHARACTER_ON
diff --git a/src/roff/troff/env.h b/src/roff/troff/env.h
index 68b6a5e7b..6e0600ae7 100644
--- a/src/roff/troff/env.h
+++ b/src/roff/troff/env.h
@@ -140,7 +140,7 @@ void widow_control_request();
 #endif /* WIDOW_CONTROL */
 
 class environment {
-  bool dummy;                  // dummy environment used for \w
+  bool is_dummy_env;                   // dummy environment used for \w
   hunits prev_line_length;
   hunits line_length;
   hunits prev_title_length;
@@ -158,7 +158,7 @@ class environment {
   int space_size;              // in 36ths of an em
   int sentence_space_size;     // same but for spaces at the end of sentences
   int adjust_mode;
-  bool fill;
+  bool is_filling;
   bool line_interrupted;
   int prev_line_interrupted;   // three-valued Boolean :-|
   int centered_line_count;
@@ -200,8 +200,8 @@ class environment {
   int field_spaces;
   int tab_field_spaces;
   bool tab_precedes_field;
-  bool discarding;
-  bool spreading;              // set by \p
+  bool is_discarding;
+  bool is_spreading;           // set by \p
   unsigned margin_character_flags;
   node *margin_character_node;
   hunits margin_character_distance;
@@ -268,7 +268,7 @@ public:
   statem *construct_state(bool has_only_eol);
   void print_env();
   void copy(const environment *);
-  bool is_dummy() { return dummy; }
+  bool is_dummy() { return is_dummy_env; }
   bool is_empty();
   bool is_composite() { return composite; }
   void set_composite() { composite = true; }
@@ -342,7 +342,7 @@ public:
   void set_char_slant(int);
   void set_input_line_position(hunits);        // used by \n(hp
   void interrupt();
-  void spread() { spreading = true; }
+  void spread() { is_spreading = true; }
   void possibly_break_line(bool /* must_break_here */ = false,
                           bool /* must_adjust */ = false);
   void do_break(bool /* want_adjustment */ = false);   // .br, .brp

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

Reply via email to