* src/roff/troff/input.cpp: Slightly refactor. Boolify. Demote and rename global `while_break_flag` to `want_loop_break`.
(do_if_request): Demote return type from `int` to `bool`. Demote and rename local `invert` to `want_test_sense_inverted`. (while_request): Demote and rename local `escaped` to `is_char_escaped`. Annotate null pointers with `nullptr` comment to ease any future transition to C++11, which defines it as a keyword. --- ChangeLog | 9 ++++++ src/roff/troff/input.cpp | 60 ++++++++++++++++++++-------------------- 2 files changed, 39 insertions(+), 30 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3f29eecea..6dee3c19d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2024-04-04 G. Branden Robinson <g.branden.robin...@gmail.com> + + * src/roff/troff/input.cpp: Slightly refactor. Boolify. Demote + and rename global `while_break_flag` to `want_loop_break`. + (do_if_request): Demote return type from `int` to `bool`. + Demote and rename local `invert` to `want_test_sense_inverted`. + (while_request): Demote and rename local `escaped` to + `is_char_escaped`. + 2024-03-26 G. Branden Robinson <g.branden.robin...@gmail.com> * src/utils/grog/grog.pl (do_line): Recognize new requests in diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp index d355eed7d..3ee318088 100644 --- a/src/roff/troff/input.cpp +++ b/src/roff/troff/input.cpp @@ -2874,50 +2874,50 @@ static int transparent_translate(int cc) return cc; } -class int_stack { - struct int_stack_element { +class bool_stack { + struct bool_stack_element { int n; - int_stack_element *next; + bool_stack_element *next; } *top; public: - int_stack(); - ~int_stack(); + bool_stack(); + ~bool_stack(); void push(int); int is_empty(); int pop(); }; -int_stack::int_stack() +bool_stack::bool_stack() { top = 0; } -int_stack::~int_stack() +bool_stack::~bool_stack() { while (top != 0) { - int_stack_element *temp = top; + bool_stack_element *temp = top; top = top->next; delete temp; } } -int int_stack::is_empty() +int bool_stack::is_empty() { return top == 0; } -void int_stack::push(int n) +void bool_stack::push(int n) { - int_stack_element *p = new int_stack_element; + bool_stack_element *p = new bool_stack_element; p->next = top; p->n = n; top = p; } -int int_stack::pop() +int bool_stack::pop() { assert(top != 0); - int_stack_element *p = top; + bool_stack_element *p = top; top = top->next; int n = p->n; delete p; @@ -2981,7 +2981,7 @@ static int leading_spaces_space = 0; void process_input_stack() { - int_stack trap_bol_stack; + bool_stack trap_bol_stack; int bol = 1; for (;;) { int suppress_next = 0; @@ -5978,16 +5978,16 @@ static void nop_request() tok.next(); } -static int_stack if_else_stack; +static bool_stack if_else_stack; -static int do_if_request() +static bool do_if_request() { - int invert = 0; + bool want_test_sense_inverted = false; while (tok.is_space()) tok.next(); while (tok.ch() == '!') { tok.next(); - invert = !invert; + want_test_sense_inverted = !want_test_sense_inverted; } int result; unsigned char c = tok.ch(); @@ -6122,7 +6122,7 @@ static int do_if_request() else result = n > 0; } - if (invert) + if (want_test_sense_inverted) result = !result; if (result) begin_alternative(); @@ -6166,13 +6166,13 @@ static void else_request() } static int while_depth = 0; -static int while_break_flag = 0; +static bool want_loop_break = false; static void while_request() { // We can't use `has_arg()` here. XXX: Figure out why. macro mac; - int escaped = 0; + bool is_char_escaped = false; int level = 0; mac.append(new token_node(tok)); for (;;) { @@ -6181,15 +6181,15 @@ static void while_request() if (c == EOF) break; if (c == 0) { - escaped = 0; + is_char_escaped = false; mac.append(n); } - else if (escaped) { + else if (is_char_escaped) { if (c == '{') level += 1; else if (c == '}') level -= 1; - escaped = 0; + is_char_escaped = false; mac.append(c); } else { @@ -6198,7 +6198,7 @@ static void while_request() else if (c == ESCAPE_RIGHT_BRACE) level -= 1; else if (c == escape_char) - escaped = 1; + is_char_escaped = true; mac.append(c); if (c == '\n' && level <= 0) break; @@ -6218,8 +6218,8 @@ static void while_request() break; } process_input_stack(); - if (while_break_flag || input_stack::is_return_boundary()) { - while_break_flag = 0; + if (want_loop_break || input_stack::is_return_boundary()) { + want_loop_break = false; break; } } @@ -6236,7 +6236,7 @@ static void while_break_request() skip_line(); } else { - while_break_flag = 1; + want_loop_break = true; while (input_stack::get(0) != EOF) ; tok.next(); @@ -7525,7 +7525,7 @@ charinfo *token::get_char(bool required) // character is null. If not, this should be an assert(). Also // see escape_off(). error("escaped 'e' used while escape sequences disabled"); - return 0; + return 0 /* nullptr */; } } if (required) { @@ -7535,7 +7535,7 @@ charinfo *token::get_char(bool required) error("expected ordinary or special character, got %1", description()); } - return 0; + return 0 /* nullptr */; } charinfo *get_optional_char() -- 2.30.2
signature.asc
Description: PGP signature