gbranden pushed a commit to branch master
in repository groff.
commit b1d9fc5a30020483c718fbfe04039b3a59eb7882
Author: G. Branden Robinson <[email protected]>
AuthorDate: Fri May 30 20:25:15 2025 -0500
[troff]: Trivially refactor.
...continuing reform of functions that are troff request handlers such
that their names end with `_request`.
* src/roff/troff/env.cpp
(tab_character): Rename this...
(tab_character_request): ...to this.
(leader_character): Rename this...
(leader_character_request): ...to this.
(hyphen_char): Rename this...
(hyphenation_character_request): ...to this.
(field_characters): Rename this...
(field_characters_request): ...to this. Also mark it `static` because
the `environment` class has no need for `friend` access to it, unlike
the foregoing.
(init_env_requests): Wire up request names to new handler function
names.
* src/roff/troff/input.cpp
(set_page_character): Rename this...
(page_character_request): ...to this. Also mark it `static` because
the `environment` class has no need for `friend` access to it.
(init_input_requests): Wire up request name to new handler function
name.
* src/roff/troff/node.cpp
(set_soft_hyphen_character): Rename this...
(soft_hyphen_character_request): ...to this.
(init_node_requests): Wire up request name to new handler function
name.
Also annotate open questions and potential future directions.
---
ChangeLog | 32 ++++++++++++++++++++++++++++++++
src/roff/troff/env.cpp | 30 +++++++++++++++++++++---------
src/roff/troff/env.h | 4 ++--
src/roff/troff/input.cpp | 11 +++++++++--
src/roff/troff/node.cpp | 10 ++++++++--
5 files changed, 72 insertions(+), 15 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index a22a2e967..0084aeee2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,35 @@
+2025-05-30 G. Branden Robinson <[email protected]>
+
+ [troff]: Trivially refactor, continuing reform of functions that
+ are troff request handlers such that their names end with
+ `_request`.
+
+ * src/roff/troff/env.cpp
+ (tab_character): Rename this...
+ (tab_character_request): ...to this.
+ (leader_character): Rename this...
+ (leader_character_request): ...to this.
+ (hyphen_char): Rename this...
+ (hyphenation_character_request): ...to this.
+ (field_characters): Rename this...
+ (field_characters_request): ...to this. Also mark it `static`
+ because the `environment` class has no need for `friend` access
+ to it, unlike the foregoing.
+ (init_env_requests): Wire up request names to new handler
+ function names.
+ * src/roff/troff/input.cpp
+ (set_page_character): Rename this...
+ (page_character_request): ...to this. Also mark it `static`
+ because the `environment` class has no need for `friend` access
+ to it.
+ (init_input_requests): Wire up request name to new handler
+ function name.
+ * src/roff/troff/node.cpp
+ (set_soft_hyphen_character): Rename this...
+ (soft_hyphen_character_request): ...to this.
+ (init_node_requests): Wire up request name to new handler
+ function name.
+
2025-05-30 G. Branden Robinson <[email protected]>
* src/roff/troff/input.cpp (read_title_parts): Fix code style
diff --git a/src/roff/troff/env.cpp b/src/roff/troff/env.cpp
index 90bb92a08..529f79968 100644
--- a/src/roff/troff/env.cpp
+++ b/src/roff/troff/env.cpp
@@ -309,7 +309,6 @@ int font_size::to_units()
// we can't do this in a static constructor because various dictionaries
// have to get initialized first
-
static symbol default_environment_name("0");
void init_environments()
@@ -318,13 +317,21 @@ void init_environments()
(void) env_dictionary.lookup(default_environment_name, curenv);
}
-void tab_character()
+// Set tab character, used to fill out the remainder of a tab stop where
+// a tab (TAB, U+0009) occurs in the input. If a null pointer,
+// horizontal motion "fills" the tab stop.
+void tab_character_request()
{
curenv->tab_char = read_character();
skip_line();
}
-void leader_character()
+// Set leader character, used to fill out the remainder of a tab stop
+// where a leader (SOH, U+0001) occurs in the input. If a null pointer,
+// horizontal motion "fills" the tab stop. Used when the behavior of a
+// null pointer tab character is also desired on the same output line
+// (or more generally).
+void leader_character_request()
{
curenv->leader_char = read_character();
skip_line();
@@ -1793,9 +1800,13 @@ void set_hyphenation_mode_default()
skip_line();
}
-void hyphen_char()
+// Set hyphenation character, which the input uses to mark the position
+// of a discretionary break ("dbreak") in a word.
+void hyphenation_character_request()
{
curenv->hyphen_indicator_char = read_character();
+ // TODO?: If null pointer, set to ESCAPE_PERCENT, eliminating test(s)
+ // while processing output line?
skip_line();
}
@@ -3017,7 +3028,8 @@ tab_type environment::distance_to_next_tab(hunits
*distance, hunits *leftpos)
leftpos);
}
-void field_characters()
+// XXX: Field characters are global; shouldn't they be environmental?
+static void field_characters_request()
{
field_delimiter_char = read_character();
if (field_delimiter_char)
@@ -4270,12 +4282,12 @@ void init_env_requests()
init_request("ev", environment_switch);
init_request("evc", environment_copy);
init_request("fam", family_change);
- init_request("fc", field_characters);
+ init_request("fc", field_characters_request);
init_request("fi", fill);
init_request("fcolor", fill_color_change);
init_request("ft", select_font);
init_request("gcolor", stroke_color_change);
- init_request("hc", hyphen_char);
+ init_request("hc", hyphenation_character_request);
init_request("hla", select_hyphenation_language);
init_request("hlm", hyphen_line_max_request);
init_request("hy", hyphenate_request);
@@ -4285,7 +4297,7 @@ void init_env_requests()
init_request("in", indent);
init_request("it", input_trap);
init_request("itc", input_trap_continued);
- init_request("lc", leader_character);
+ init_request("lc", leader_character_request);
init_request("linetabs", line_tabs_request);
init_request("ll", line_length);
init_request("ls", line_spacing);
@@ -4305,7 +4317,7 @@ void init_env_requests()
init_request("ss", space_size);
init_request("ta", set_tabs);
init_request("ti", temporary_indent);
- init_request("tc", tab_character);
+ init_request("tc", tab_character_request);
init_request("tl", title);
init_request("ul", underline);
init_request("vs", vertical_spacing);
diff --git a/src/roff/troff/env.h b/src/roff/troff/env.h
index 95a2c2739..aea185561 100644
--- a/src/roff/troff/env.h
+++ b/src/roff/troff/env.h
@@ -398,8 +398,8 @@ public:
friend void margin_character();
friend void no_number();
friend void number_lines();
- friend void leader_character();
- friend void tab_character();
+ friend void leader_character_request();
+ friend void tab_character_request();
friend void hyphenate_request();
friend void set_hyphenation_mode_default();
friend void no_hyphenate();
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 57e573416..1c56c40a3 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -5964,9 +5964,16 @@ static void do_width() // \w
charinfo *page_character;
-void set_page_character()
+// XXX: The page character is global; shouldn't it be environmental?
+// Its idiomatic use is in `tl` requests when formatting titles (headers
+// or footers), which full-service macro packages typically put in their
+// own environment anyway to ensure that a consistent typeface is used
+// there regardless of how body text is styled.
+static void page_character_request()
{
page_character = read_character();
+ // TODO?: If null pointer, set to `percent_symbol` (see below),
+ // eliminating test in `read_title_parts()` (also below)?
skip_line();
}
@@ -9589,7 +9596,7 @@ void init_input_requests()
init_request("open", open_request);
init_request("opena", opena_request);
init_request("output", output_request);
- init_request("pc", set_page_character);
+ init_request("pc", page_character_request);
init_request("pchar", report_character_request);
init_request("pcolor", report_color);
init_request("pcomposite", report_composite_characters);
diff --git a/src/roff/troff/node.cpp b/src/roff/troff/node.cpp
index 7c0f8af40..5681829a7 100644
--- a/src/roff/troff/node.cpp
+++ b/src/roff/troff/node.cpp
@@ -7314,7 +7314,13 @@ static void set_kerning_mode()
skip_line();
}
-static void set_soft_hyphen_character()
+// Set (soft) hyphenation character, used to mark where a discretionary
+// break ("dbreak") has occurred in formatted output, conventionally
+// within a word at a syllable boundary.
+//
+// XXX: The soft hyphen character is global; shouldn't it be
+// environmental?
+static void soft_hyphen_character_request()
{
soft_hyphen_char = read_character();
if (0 /* nullptr */ == soft_hyphen_char)
@@ -7368,7 +7374,7 @@ void init_node_requests()
init_request("lg", set_ligature_mode);
init_request("pftr", dump_font_translations);
init_request("rfschar", remove_font_specific_character);
- init_request("shc", set_soft_hyphen_character);
+ init_request("shc", soft_hyphen_character_request);
init_request("special", set_special_fonts);
init_request("sty", associate_style_with_font_position);
init_request("tkf", configure_track_kerning);
_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit