gbranden pushed a commit to branch master
in repository groff.
commit 36f29d1bf5269f1829d4d388518543f426b693bb
Author: G. Branden Robinson <[email protected]>
AuthorDate: Tue Aug 13 04:45:16 2024 -0500
[troff]: Slightly refactor (global Booleans).
* src/roff/troff/troff.h: Slightly refactor; boolify and rename some
global `int`s.
- `suppress_output_flag` -> `want_output_suppressed`
- `color_flag` -> `want_color_output`
- `is_html` -> `is_writing_html`
* src/roff/troff/env.cpp (environment::newline, environment::make_tag)
(environment::construct_state, environment::construct_format_state)
(environment::construct_new_line_state):
* src/roff/troff/input.cpp ([top level], main):
* src/roff/troff/mtsm.cpp (statem:add_tag_ta, mtsm::push_state)
(mtsm::pop_state, mtsm::flush, mtsm:changed):
* src/roff/troff/node.cpp (suppress_node::tprint)
(space_char_hmotion_node::tprint, unbreakable_space_node::tprint):
Migrate `is_html`.
* src/roff/troff/input.cpp ([top level], activate_color, main):
(init_input_requests):
* src/roff/troff/node.cpp (troff_output_file::fill_color)
(troff_output_file::glyph_color): Migrate `color_flag`.
* src/roff/troff/input.cpp (init_input_requests): Use
`readonly_boolean_register` class to expose `want_color_output` to
documents, not `readonly_register`.
* src/roff/troff/input.cpp ([top level], main):
* src/roff/troff/node.cpp (init_output): Migrate `suppress_output_flag`.
---
ChangeLog | 28 ++++++++++++++++++++++++++++
src/roff/troff/env.cpp | 10 +++++-----
src/roff/troff/input.cpp | 18 +++++++++---------
src/roff/troff/mtsm.cpp | 10 +++++-----
src/roff/troff/node.cpp | 12 ++++++------
src/roff/troff/troff.h | 6 +++---
6 files changed, 56 insertions(+), 28 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 9b6045f3e..3480ebe16 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,31 @@
+2024-08-13 G. Branden Robinson <[email protected]>
+
+ * src/roff/troff/troff.h: Slightly refactor; boolify and rename
+ some global `int`s.
+ - `suppress_output_flag` -> `want_output_suppressed`
+ - `color_flag` -> `want_color_output`
+ - `is_html` -> `is_writing_html`
+ * src/roff/troff/env.cpp (environment::newline)
+ (environment::make_tag, environment::construct_state)
+ (environment::construct_format_state)
+ (environment::construct_new_line_state):
+ * src/roff/troff/input.cpp ([top level], main):
+ * src/roff/troff/mtsm.cpp (statem:add_tag_ta, mtsm::push_state)
+ (mtsm::pop_state, mtsm::flush, mtsm:changed):
+ * src/roff/troff/node.cpp (suppress_node::tprint)
+ (space_char_hmotion_node::tprint)
+ (unbreakable_space_node::tprint): Migrate `is_html`.
+ * src/roff/troff/input.cpp ([top level], activate_color, main):
+ (init_input_requests):
+ * src/roff/troff/node.cpp (troff_output_file::fill_color)
+ (troff_output_file::glyph_color): Migrate `color_flag`.
+ * src/roff/troff/input.cpp (init_input_requests): Use
+ `readonly_boolean_register` class to expose `want_color_output`
+ to documents, not `readonly_register`.
+ * src/roff/troff/input.cpp ([top level], main):
+ * src/roff/troff/node.cpp (init_output): Migrate
+ `suppress_output_flag`.
+
2024-08-11 G. Branden Robinson <[email protected]>
* src/roff/troff/input.cpp (hyphenation_patterns_file_code):
diff --git a/src/roff/troff/env.cpp b/src/roff/troff/env.cpp
index df948e1f7..d3aae3a5a 100644
--- a/src/roff/troff/env.cpp
+++ b/src/roff/troff/env.cpp
@@ -1838,7 +1838,7 @@ void environment::newline()
}
input_line_start = line == 0 /* nullptr */ ? H0 : width_total;
if (to_be_output) {
- if (is_html && !fill) {
+ if (is_writing_html && !fill) {
curdiv->modified_tag.incl(MTSM_EOL);
if (suppress_next_eol)
suppress_next_eol = false;
@@ -2336,7 +2336,7 @@ void environment::final_break()
node *environment::make_tag(const char *nm, int i)
{
- if (is_html) {
+ if (is_writing_html) {
/*
* need to emit tag for post-grohtml
* but we check to see whether we can emit specials
@@ -2386,7 +2386,7 @@ void environment::dump_node_list()
statem *environment::construct_state(bool has_only_eol)
{
- if (is_html) {
+ if (is_writing_html) {
statem *s = new statem();
if (!has_only_eol) {
s->add_tag(MTSM_IN, indent);
@@ -2417,7 +2417,7 @@ statem *environment::construct_state(bool has_only_eol)
void environment::construct_format_state(node *nd, bool was_centered,
int filling)
{
- if (is_html) {
+ if (is_writing_html) {
// find first glyph node which has a state.
while (nd != 0 /* nullptr */ && nd->state == 0 /* nullptr */)
nd = nd->next;
@@ -2447,7 +2447,7 @@ void environment::construct_format_state(node *nd, bool
was_centered,
void environment::construct_new_line_state(node *nd)
{
- if (is_html) {
+ if (is_writing_html) {
// find first glyph node which has a state.
while (nd != 0 /* nullptr */ && nd->state == 0 /* nullptr */)
nd = nd->next;
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 86c1d5997..c3611d8f2 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -82,7 +82,7 @@ void transparent_file();
token tok;
bool want_break = false;
int class_flag = 0;
-int color_flag = 1; // colors are on by default
+bool want_color_output = true;
static int backtrace_flag = 0;
char *pipe_command = 0 /* nullptr */;
charinfo *charset_table[256];
@@ -102,8 +102,8 @@ static symbol leading_spaces_macro_name;
static int compatible_flag = 0;
static int do_old_compatible_flag = -1; // for .do request
bool want_abstract_output = false;
-int suppress_output_flag = 0;
-int is_html = 0;
+bool want_output_suppressed = false;
+bool is_writing_html = false;
static int suppression_level = 0; // depth of nested \O escapes
bool in_nroff_mode = false;
@@ -1486,9 +1486,9 @@ static void activate_color()
{
int n;
if (has_arg() && get_integer(&n))
- color_flag = (n > 0);
+ want_color_output = (n > 0);
else
- color_flag = 1;
+ want_color_output = true;
skip_line();
}
@@ -8356,13 +8356,13 @@ int main(int argc, char **argv)
case 'T':
device = optarg;
tflag = 1;
- is_html = (strcmp(device, "html") == 0);
+ is_writing_html = (strcmp(device, "html") == 0);
break;
case 'C':
compatible_flag = 1;
// fall through
case 'c':
- color_flag = 0;
+ want_color_output = false;
break;
case 'M':
macro_path.command_line_dir(optarg);
@@ -8397,7 +8397,7 @@ int main(int argc, char **argv)
want_abstract_output = true;
break;
case 'z':
- suppress_output_flag = 1;
+ want_output_suppressed = true;
break;
case 'n':
if (sscanf(optarg, "%d", &next_page_number) == 1)
@@ -8715,7 +8715,7 @@ void init_input_requests()
register_dictionary.define(".cp", new
readonly_register(&do_old_compatible_flag));
register_dictionary.define(".O", new variable_reg(&suppression_level));
register_dictionary.define(".c", new lineno_reg);
- register_dictionary.define(".color", new readonly_register(&color_flag));
+ register_dictionary.define(".color", new
readonly_boolean_register(&want_color_output));
register_dictionary.define(".F", new filename_reg);
register_dictionary.define(".g", new readonly_text_register("1"));
register_dictionary.define(".H", new readonly_register(&hresolution));
diff --git a/src/roff/troff/mtsm.cpp b/src/roff/troff/mtsm.cpp
index dfa41a47a..d1418b22d 100644
--- a/src/roff/troff/mtsm.cpp
+++ b/src/roff/troff/mtsm.cpp
@@ -268,7 +268,7 @@ void statem::sub_tag_ce()
void statem::add_tag_ta()
{
- if (is_html) {
+ if (is_writing_html) {
string s = string("");
hunits d, l;
enum tab_type t;
@@ -358,7 +358,7 @@ mtsm::~mtsm()
void mtsm::push_state(statem *n)
{
- if (is_html) {
+ if (is_writing_html) {
#if defined(DEBUGGING)
if (want_html_debugging) {
fprintf(stderr, "--> state %d pushed\n", n->issue_no);
@@ -371,7 +371,7 @@ void mtsm::push_state(statem *n)
void mtsm::pop_state()
{
- if (is_html) {
+ if (is_writing_html) {
#if defined(DEBUGGING)
if (want_html_debugging) {
fprintf(stderr, "--> state popped\n");
@@ -426,7 +426,7 @@ void mtsm::inherit(statem *s, int reset_bool)
void mtsm::flush(FILE *fp, statem *s, string tag_list)
{
- if (is_html && s) {
+ if (is_writing_html && s) {
inherit(s, 1);
driver->flush(fp, s);
// Set rj, ce, ti to unknown if they were known and
@@ -510,7 +510,7 @@ int mtsm::has_changed(string_value_state t, statem *s)
int mtsm::changed(statem *s)
{
- if (s == 0 || !is_html)
+ if (s == 0 || !is_writing_html)
return 0;
s = new statem(s);
inherit(s, 0);
diff --git a/src/roff/troff/node.cpp b/src/roff/troff/node.cpp
index f99689a32..81c032c43 100644
--- a/src/roff/troff/node.cpp
+++ b/src/roff/troff/node.cpp
@@ -1263,7 +1263,7 @@ void troff_output_file::fill_color(color *col)
if (!col || current_fill_color == col)
return;
current_fill_color = col;
- if (!color_flag)
+ if (!want_color_output)
return;
flush_tbuf();
do_motion();
@@ -1316,7 +1316,7 @@ void troff_output_file::glyph_color(color *col)
if (!col || current_glyph_color == col)
return;
current_glyph_color = col;
- if (!color_flag)
+ if (!want_color_output)
return;
flush_tbuf();
// grotty doesn't like a color command if the vertical position is zero.
@@ -4178,7 +4178,7 @@ void suppress_node::tprint(troff_output_file *out)
else
strcpy(name, image_filename);
}
- if (is_html) {
+ if (is_writing_html) {
switch (last_position) {
case 'c':
out->start_special();
@@ -4852,7 +4852,7 @@ void hmotion_node::tprint(troff_output_file *out)
void space_char_hmotion_node::tprint(troff_output_file *out)
{
out->fill_color(col);
- if (is_html) {
+ if (is_writing_html) {
// we emit the space width as a negative glyph index
out->flush_tbuf();
out->do_motion();
@@ -5917,7 +5917,7 @@ void unbreakable_space_node::tprint(troff_output_file
*out)
{
out->fill_color(col);
out->word_marker();
- if (is_html) {
+ if (is_writing_html) {
// we emit the space width as a negative glyph index
out->flush_tbuf();
out->do_motion();
@@ -6786,7 +6786,7 @@ static void set_soft_hyphen_character()
void init_output()
{
- if (suppress_output_flag)
+ if (want_output_suppressed)
the_output = new suppress_output_file;
else if (want_abstract_output)
the_output = new ascii_output_file;
diff --git a/src/roff/troff/troff.h b/src/roff/troff/troff.h
index c2f37a034..66e9148ea 100644
--- a/src/roff/troff/troff.h
+++ b/src/roff/troff/troff.h
@@ -40,9 +40,9 @@ extern units scale(units n, units x, units y); // scale n by
x/y
extern units units_per_inch;
extern bool want_abstract_output;
-extern int suppress_output_flag;
-extern int color_flag;
-extern int is_html;
+extern bool want_output_suppressed;
+extern bool want_color_output;
+extern bool is_writing_html;
extern bool in_nroff_mode;
extern bool device_has_tcommand;
_______________________________________________
Groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit