gbranden pushed a commit to branch master
in repository groff.
commit 3b94b1f296bd9a7b6d7f20f888058ccaff5aec46
Author: G. Branden Robinson <[email protected]>
AuthorDate: Mon Mar 17 02:44:59 2025 -0500
[troff]: Slightly refactor.
Boolify and rename global and local variables, class member functions,
and member function arguments relating to diversion re-reading and
interpreter state tracking whether the input stream is being read at the
beginning of an input line (or the predicate of a certain
control-structure requests, where ordinary and no-break control
characters are recognized).
* src/roff/troff/column.cpp (class vjustify_node) [0]:
* src/roff/troff/node.h (struct node, class word_space_node)
(class unbreakable_space_node, class diverted_space_node) (class
diverted_copy_file_node, hmotion_node): Rename `reread()` member
function to `need_reread()` and demote its argument and return value
to `bool` and pointer to `bool`, respectively.
* src/roff/troff/column.cpp (vjustify_node::reread) [0]: Rename this...
(vjustify_node::need_reread) [0]: ...to this, and update return and
argument types.
* src/roff/troff/input.cpp (bool::reread)
(diverted_space_node::reread, diverted_copy_file_node::reread)
(word_space_node::reread, unbreakable_space_node::reread)
(hmotion_node::reread): Rename this...
(bool::need_reread, diverted_space_node::need_reread)
(diverted_copy_file_node::need_reread)
(word_space_node::need_reread)
(unbreakable_space_node::need_reread)
(hmotion_node::need_reread): ...to this, and update return and
argument types.
(process_input_stack, do_define_macro, transparent_file): Rename
`bol` to `reading_beginning_of_input_line` and demote it from
`int` to `bool`.
Drop old-style Emacs file-local variable. Add editor aid comments.
---
ChangeLog | 36 ++++++++++++++++++++++
src/roff/troff/column.cpp | 15 ++++++---
src/roff/troff/input.cpp | 78 ++++++++++++++++++++++++-----------------------
src/roff/troff/node.h | 12 ++++----
4 files changed, 92 insertions(+), 49 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index c2b515fab..eaa9eacad 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,39 @@
+2025-03-17 G. Branden Robinson <[email protected]>
+
+ [troff]: Slightly refactor. Boolify and rename global and
+ local variables, class member functions, and member function
+ arguments relating to diversion re-reading and interpreter state
+ tracking whether the input stream is being read at the beginning
+ of an input line (or the predicate of a certain
+ control-structure requests, where ordinary and no-break control
+ characters are recognized).
+
+ * src/roff/troff/column.cpp (class vjustify_node) [0]:
+ * src/roff/troff/node.h (struct node, class word_space_node)
+ (class unbreakable_space_node, class diverted_space_node)
+ (class diverted_copy_file_node, hmotion_node): Rename `reread()`
+ member function to `need_reread()` and demote its argument and
+ return value to `bool` and pointer to `bool`, respectively.
+
+ * src/roff/troff/column.cpp (vjustify_node::reread) [0]: Rename
+ this...
+ (vjustify_node::need_reread) [0]: ...to this, and update return
+ and argument types.
+
+ * src/roff/troff/input.cpp (bool::reread)
+ (diverted_space_node::reread, diverted_copy_file_node::reread)
+ (word_space_node::reread, unbreakable_space_node::reread)
+ (hmotion_node::reread): Rename this...
+ (bool::need_reread, diverted_space_node::need_reread)
+ (diverted_copy_file_node::need_reread)
+ (word_space_node::need_reread)
+ (unbreakable_space_node::need_reread)
+ (hmotion_node::need_reread): ...to this, and update return and
+ argument types.
+ (process_input_stack, do_define_macro, transparent_file): Rename
+ `bol` to `reading_beginning_of_input_line` and demote it from
+ `int` to `bool`.
+
2025-03-17 G. Branden Robinson <[email protected]>
[troff]: Make bracket and overstrike nodes (created with `\b`
diff --git a/src/roff/troff/column.cpp b/src/roff/troff/column.cpp
index 55563ba46..1ae2e1c71 100644
--- a/src/roff/troff/column.cpp
+++ b/src/roff/troff/column.cpp
@@ -1,4 +1,3 @@
-// -*- C++ -*-
/* Copyright (C) 1989-2020 Free Software Foundation, Inc.
Written by James Clark ([email protected])
@@ -652,7 +651,7 @@ class vjustify_node : public node {
symbol typ;
public:
vjustify_node(symbol);
- int reread(int *);
+ bool need_reread(bool *);
const char *type();
int same(node *);
node *copy();
@@ -678,11 +677,11 @@ int vjustify_node::same(node *nd)
return typ == ((vjustify_node *)nd)->typ;
}
-int vjustify_node::reread(int *bolp)
+bool vjustify_node::need_reread(bool *bolp)
{
curdiv->vjustify(typ);
- *bolp = 1;
- return 1;
+ *bolp = true;
+ return true;
}
void macro_diversion::vjustify(symbol type)
@@ -729,3 +728,9 @@ void init_column_requests()
}
#endif /* COLUMN */
+
+// Local Variables:
+// fill-column: 72
+// mode: C++
+// End:
+// vim: set cindent noexpandtab shiftwidth=2 textwidth=72:
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 6ad60425a..1235c4d08 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -3059,14 +3059,14 @@ static int transparent_translate(int cc)
return cc;
}
-int node::reread(int *)
+bool node::need_reread(bool *)
{
- return 0 /* nullptr */;
+ return false;
}
int global_diverted_space = 0;
-int diverted_space_node::reread(int *bolp)
+bool diverted_space_node::need_reread(bool *bolp)
{
global_diverted_space = 1;
if (curenv->get_fill())
@@ -3074,41 +3074,41 @@ int diverted_space_node::reread(int *bolp)
else
curdiv->space(n);
global_diverted_space = 0;
- *bolp = 1;
- return 1;
+ *bolp = true;
+ return true;
}
-int diverted_copy_file_node::reread(int *bolp)
+bool diverted_copy_file_node::need_reread(bool *bolp)
{
curdiv->copy_file(filename.contents());
- *bolp = 1;
- return 1;
+ *bolp = true;
+ return true;
}
-int word_space_node::reread(int *)
+bool word_space_node::need_reread(bool *)
{
if (unformat) {
for (width_list *w = orig_width; w; w = w->next)
curenv->space(w->width, w->sentence_width);
unformat = 0;
- return 1;
+ return true;
}
- return 0;
+ return false;
}
-int unbreakable_space_node::reread(int *)
+bool unbreakable_space_node::need_reread(bool *)
{
- return 0;
+ return false;
}
-int hmotion_node::reread(int *)
+bool hmotion_node::need_reread(bool *)
{
if (unformat && was_tab) {
curenv->handle_tab(0);
unformat = 0;
- return 1;
+ return true;
}
- return 0;
+ return false;
}
static int leading_spaces_number = 0;
@@ -3117,14 +3117,14 @@ static int leading_spaces_space = 0;
void process_input_stack()
{
std::stack<int> trap_bol_stack;
- int bol = 1;
+ bool reading_beginning_of_input_line = true;
for (;;) {
int suppress_next = 0;
switch (tok.type) {
case token::TOKEN_CHAR:
{
unsigned char ch = tok.c;
- if (bol && !have_formattable_input
+ if (reading_beginning_of_input_line && !have_formattable_input
&& (curenv->get_control_character() == ch
|| curenv->get_no_break_control_character() == ch)) {
want_break = (curenv->get_control_character() == ch);
@@ -3179,14 +3179,14 @@ void process_input_stack()
ch = tok.c;
}
suppress_next = 1;
- bol = 0;
+ reading_beginning_of_input_line = false;
}
}
break;
}
case token::TOKEN_TRANSPARENT:
{
- if (bol) {
+ if (reading_beginning_of_input_line) {
if (possibly_handle_first_page_transition())
;
else {
@@ -3209,12 +3209,13 @@ void process_input_stack()
}
case token::TOKEN_NEWLINE:
{
- if (bol && !have_formattable_input_on_interrupted_line
+ if (reading_beginning_of_input_line
+ && !have_formattable_input_on_interrupted_line
&& !curenv->get_prev_line_interrupted())
trapping_blank_line();
else {
curenv->newline();
- bol = 1;
+ reading_beginning_of_input_line = true;
}
break;
}
@@ -3248,7 +3249,8 @@ void process_input_stack()
{
if (possibly_handle_first_page_transition())
;
- else if (bol && !curenv->get_prev_line_interrupted()) {
+ else if (reading_beginning_of_input_line
+ && !curenv->get_prev_line_interrupted()) {
int nspaces = 0;
// save space_width now so that it isn't changed by \f or \s
// which we wouldn't notice here
@@ -3270,12 +3272,12 @@ void process_input_stack()
curenv->add_node(new hmotion_node(space_width * nspaces,
curenv->get_fill_color()));
}
- bol = 0;
+ reading_beginning_of_input_line = false;
}
}
else {
curenv->space();
- bol = 0;
+ reading_beginning_of_input_line = false;
}
break;
}
@@ -3286,14 +3288,14 @@ void process_input_stack()
{
if (possibly_handle_first_page_transition())
;
- else if (tok.nd->reread(&bol)) {
+ else if (tok.nd->need_reread(&reading_beginning_of_input_line)) {
delete tok.nd;
tok.nd = 0;
}
else {
curenv->add_node(tok.nd);
tok.nd = 0;
- bol = 0;
+ reading_beginning_of_input_line = false;
curenv->possibly_break_line(true /* must break here */);
}
break;
@@ -3302,13 +3304,13 @@ void process_input_stack()
{
continue_page_eject();
// I think we just want to preserve bol.
- // bol = 1;
+ // reading_beginning_of_input_line = true;
break;
}
case token::TOKEN_BEGIN_TRAP:
{
- trap_bol_stack.push(bol);
- bol = 1;
+ trap_bol_stack.push(reading_beginning_of_input_line);
+ reading_beginning_of_input_line = true;
have_formattable_input = false;
break;
}
@@ -3317,7 +3319,7 @@ void process_input_stack()
if (trap_bol_stack.empty())
error("spurious end trap token detected!");
else {
- bol = trap_bol_stack.top();
+ reading_beginning_of_input_line = trap_bol_stack.top();
trap_bol_stack.pop();
}
have_formattable_input = false;
@@ -3348,7 +3350,7 @@ void process_input_stack()
}
default:
{
- bol = 0;
+ reading_beginning_of_input_line = false;
tok.process();
break;
}
@@ -5001,7 +5003,7 @@ void do_define_macro(define_mode mode, calling_mode
calling, comp_mode comp)
if (mm && mode == DEFINE_APPEND)
mac = *mm;
}
- int bol = 1;
+ bool reading_beginning_of_input_line = true;
if (comp == COMP_DISABLE)
mac.append(PUSH_GROFF_MODE);
else if (comp == COMP_ENABLE)
@@ -5014,7 +5016,7 @@ void do_define_macro(define_mode mode, calling_mode
calling, comp_mode comp)
mac.append(c);
c = get_copy(&n, true /* is defining */);
}
- if (bol && c == '.') {
+ if (reading_beginning_of_input_line && c == '.') {
const char *s = term.contents();
int d = 0;
// see if it matches term
@@ -5087,7 +5089,7 @@ void do_define_macro(define_mode mode, calling_mode
calling, comp_mode comp)
else
mac.append(c);
}
- bol = (c == '\n');
+ reading_beginning_of_input_line = (c == '\n');
c = get_copy(&n, true /* is defining */);
}
}
@@ -8766,7 +8768,7 @@ void transparent_file()
if (0 /* nullptr */ == fp)
error("cannot open '%1': %2", filename, strerror(errno));
else {
- int bol = 1;
+ bool reading_beginning_of_input_line = true;
for (;;) {
int c = getc(fp);
if (c == EOF)
@@ -8775,10 +8777,10 @@ void transparent_file()
warning(WARN_INPUT, "invalid input character code %1", int(c));
else {
curdiv->transparent_output(c);
- bol = c == '\n';
+ reading_beginning_of_input_line = c == '\n';
}
}
- if (!bol)
+ if (!reading_beginning_of_input_line)
curdiv->transparent_output('\n');
fclose(fp);
}
diff --git a/src/roff/troff/node.h b/src/roff/troff/node.h
index 0ac87d481..cbd04c464 100644
--- a/src/roff/troff/node.h
+++ b/src/roff/troff/node.h
@@ -98,7 +98,7 @@ struct node {
virtual int nbreaks();
virtual void split(int, node **, node **);
virtual hyphenation_type get_hyphenation_type();
- virtual int reread(int *);
+ virtual bool need_reread(bool *);
virtual token_node *get_token_node();
virtual int overlaps_vertically();
virtual int overlaps_horizontally();
@@ -245,7 +245,7 @@ public:
node * /* x */ = 0 /* nullptr */);
~word_space_node();
node *copy();
- int reread(int *);
+ bool need_reread(bool *);
bool set_unformat_flag();
void tprint(troff_output_file *);
bool is_same_as(node *);
@@ -264,7 +264,7 @@ public:
unbreakable_space_node(hunits, color *,
node * /* x */ = 0 /* nullptr */);
node *copy();
- int reread(int *);
+ bool need_reread(bool *);
void tprint(troff_output_file *);
bool is_same_as(node *);
void asciify(macro *);
@@ -289,7 +289,7 @@ public:
diverted_space_node(vunits, statem *, int,
node * /* p */ = 0 /* nullptr */);
node *copy();
- int reread(int *);
+ bool need_reread(bool *);
bool is_same_as(node *);
const char *type();
bool causes_tprint();
@@ -305,7 +305,7 @@ public:
diverted_copy_file_node(symbol, statem *, int,
node * /* p */ = 0 /* nullptr */);
node *copy();
- int reread(int *);
+ bool need_reread(bool *);
bool is_same_as(node *);
const char *type();
bool causes_tprint();
@@ -364,7 +364,7 @@ public:
node *nxt = 0 /* nullptr */)
: node(nxt), n(i), was_tab(flag1), unformat(flag2), col(c) {}
node *copy();
- int reread(int *);
+ bool need_reread(bool *);
bool set_unformat_flag();
void asciify(macro *);
void tprint(troff_output_file *);
_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit