gbranden pushed a commit to branch master
in repository groff.
commit 270af000826befe7053387ee4ad95ca41e7aa539
Author: G. Branden Robinson <[email protected]>
AuthorDate: Mon Dec 29 05:23:06 2025 -0600
[troff]: Trivially refactor for clarity.
"asciify" is one of the code base's more overloaded terms. Rename one
application of it.
* src/roff/troff/token.h: Rename `asciify()` and relocate its
declaration from here...
* src/roff/troff/input.h: ...to here, as `encode_for_stream_output()`.
* src/roff/troff/input.cpp (asciify): Rename this definition...
(encode_for_stream_output): ...to this.
* src/roff/troff/div.cpp
(top_level_diversion::transparent_output):
* src/roff/troff/input.cpp:
(device_extension_node::tprint)
(input_char_description)
(do_terminal)
(do_write_request)
(stream_write_macro_request)
(abort_request): Update call sites.
---
ChangeLog | 24 ++++++++++++++++++++++++
src/roff/troff/div.cpp | 2 +-
src/roff/troff/input.cpp | 18 +++++++++++-------
src/roff/troff/input.h | 1 +
src/roff/troff/token.h | 2 --
5 files changed, 37 insertions(+), 10 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index e60b6737c..f5233e740 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,27 @@
+2025-12-29 G. Branden Robinson <[email protected]>
+
+ [troff]: Trivially refactor for clarity. "asciify" is one of
+ the code base's more overloaded terms. Rename one application
+ of it.
+
+ * src/roff/troff/token.h: Rename `asciify()` and relocate its
+ declaration from here...
+ * src/roff/troff/input.h: ...to here, as
+ `encode_for_stream_output()`.
+
+ * src/roff/troff/input.cpp (asciify): Rename this definition...
+ (encode_for_stream_output): ...to this.
+
+ * src/roff/troff/div.cpp
+ (top_level_diversion::transparent_output):
+ * src/roff/troff/input.cpp:
+ (device_extension_node::tprint)
+ (input_char_description)
+ (do_terminal)
+ (do_write_request)
+ (stream_write_macro_request)
+ (abort_request): Update call sites.
+
2025-12-29 G. Branden Robinson <[email protected]>
* src/roff/troff/input.cpp: Trivially refactor.
diff --git a/src/roff/troff/div.cpp b/src/roff/troff/div.cpp
index 983f39cfe..2b779b732 100644
--- a/src/roff/troff/div.cpp
+++ b/src/roff/troff/div.cpp
@@ -497,7 +497,7 @@ void top_level_diversion::transparent_output(unsigned char
c)
fatal("attempting transparent output from top-level diversion"
" before first page has started, when a top-of-page trap is"
" defined; invoke break or flush request beforehand");
- const char *s = asciify(c);
+ const char *s = encode_for_stream_output(c);
while (*s)
the_output->transparent_char(*s++);
}
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 81c24e6fe..0d0413a2b 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -7006,7 +7006,9 @@ void device_extension_node::tprint(troff_output_file *out)
for (;;) {
int c = iter.get(0 /* nullptr */);
if (c != EOF)
- for (const char *s = ::asciify(c); *s != 0 /* nullptr */; s++)
+ for (const char *s = encode_for_stream_output(c);
+ *s != 0 /* nullptr */;
+ s++)
tprint_char(out, *s);
else
break;
@@ -7969,7 +7971,9 @@ void ps_bbox_request() // .psbb
}
}
-const char *asciify(int c)
+// Encode a token for output to an operating system file stream.
+// Express unencodable tokens as null characters.
+const char *encode_for_stream_output(int c)
{
static char buf[3];
buf[0] = (0U == escape_char) ? '\\' : escape_char;
@@ -8067,7 +8071,7 @@ const char *input_char_description(int c)
static char buf[bufsz];
(void) memset(buf, 0, bufsz);
if (is_invalid_input_char(c)) {
- const char *s = asciify(c);
+ const char *s = encode_for_stream_output(c);
if (*s) {
buf[0] = '\'';
strcpy(buf + 1, s);
@@ -8173,7 +8177,7 @@ static void do_terminal(bool do_append_newline,
for (;
(c != '\n') && (c != EOF);
(c = read_char_in_copy_mode(0 /* nullptr */)))
- fputs(asciify(c), stderr);
+ fputs(encode_for_stream_output(c), stderr);
}
if (do_append_newline)
fputc('\n', stderr);
@@ -8410,7 +8414,7 @@ static void do_write_request(bool do_append_newline)
if ('"' == c)
c = read_char_in_copy_mode(0 /* nullptr */);
while (c != '\n' && c != EOF) {
- fputs(asciify(c), fp);
+ fputs(encode_for_stream_output(c), fp);
c = read_char_in_copy_mode(0 /* nullptr */);
}
}
@@ -8460,7 +8464,7 @@ static void stream_write_macro_request() // .writem
int c = iter.get(0 /* nullptr */);
if (c == EOF)
break;
- fputs(asciify(c), fp);
+ fputs(encode_for_stream_output(c), fp);
}
fflush(fp);
}
@@ -9314,7 +9318,7 @@ void abort_request()
for (;
(c != '\n') && (c != EOF);
(c = read_char_in_copy_mode(0 /* nullptr */)))
- fputs(asciify(c), stderr);
+ fputs(encode_for_stream_output(c), stderr);
fputc('\n', stderr);
}
fflush(stderr);
diff --git a/src/roff/troff/input.h b/src/roff/troff/input.h
index 37a10cd0c..25fc20fc2 100644
--- a/src/roff/troff/input.h
+++ b/src/roff/troff/input.h
@@ -68,6 +68,7 @@ const int INPUT_SOFT_HYPHEN = 0255; // \u00ad
extern void do_stroke_color(symbol);
extern void do_fill_color(symbol);
+extern const char *encode_for_stream_output(int c);
extern bool was_invoked_with_regular_control_character;
extern bool suppress_push;
extern bool want_nodes_dumped;
diff --git a/src/roff/troff/token.h b/src/roff/troff/token.h
index b3a7c39fb..0e48197b6 100644
--- a/src/roff/troff/token.h
+++ b/src/roff/troff/token.h
@@ -159,8 +159,6 @@ extern bool read_integer(int *result, int prev_value);
extern void interpolate_register(symbol, int);
-const char *asciify(int c);
-
inline bool token::is_newline()
{
return (TOKEN_NEWLINE == type);
_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit