gbranden pushed a commit to branch master
in repository groff.
commit 4160c6125f2ba56d9285bbf700912e9cb37e1538
Author: G. Branden Robinson <[email protected]>
AuthorDate: Wed Apr 2 08:53:46 2025 -0500
[troff]: Slightly refactor and fix code style nits.
* src/roff/troff/input.cpp (file_iterator::backtrace)
(string_iterator::backtrace): Favor `errprint()` over `fprintf()`.
(string_iterator::backtrace): Explicitly compare values of pointer
type to null pointer literals instead of letting them pun down to
Booleans. Parenthesize (formally) complex expressions. Always
terminate backtrace message with newline if anything at all was
written.
(lookup_color): Reorder equality comparison to avoid inadvertent
lvalue assignment.
Also annotate null pointers with `nullptr` comment to ease any future
transition to C++11, which defines it as a keyword. Also fix
inconsistent spacing around C++ `!` operator.
---
ChangeLog | 15 +++++++++++++++
src/roff/troff/input.cpp | 23 +++++++++++------------
2 files changed, 26 insertions(+), 12 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 4e504d96c..35f104304 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2025-04-02 G. Branden Robinson <[email protected]>
+
+ [troff]: Slightly refactor and fix code style nits.
+
+ * src/roff/troff/input.cpp (file_iterator::backtrace)
+ (string_iterator::backtrace): Favor `errprint()` over
+ `fprintf()`.
+ (string_iterator::backtrace): Explicitly compare values of
+ pointer type to null pointer literals instead of letting them
+ pun down to Booleans. Parenthesize (formally) complex
+ expressions. Always terminate backtrace message with newline if
+ anything at all was written.
+ (lookup_color): Reorder equality comparison to avoid inadvertent
+ lvalue assignment.
+
2025-04-02 G. Branden Robinson <[email protected]>
* src/roff/troff/input.cpp (macro::json_dump): Add more
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 41e1b8e1c..2455946ee 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -525,7 +525,7 @@ void file_iterator::backtrace()
// Get side effect of filename rewrite if stdin.
(void) get_location(false /* allow macro */, &f, &n);
if (program_name)
- fprintf(stderr, "%s: ", program_name);
+ errprint("%1: ", program_name);
errprint("backtrace: %3 '%1':%2\n", f, n,
was_popened ? "pipe" : "file");
}
@@ -1349,7 +1349,7 @@ static color *lookup_color(symbol nm)
if (nm == default_symbol)
return &default_color;
color *c = (color *)color_dictionary.lookup(nm);
- if (c == 0)
+ if (0 == c /* nullptr */)
warning(WARN_COLOR, "color '%1' not defined", nm.contents());
return c;
}
@@ -3127,7 +3127,7 @@ void process_input_stack()
symbol nm = get_name();
#if defined(DEBUGGING)
if (want_html_debugging) {
- if (! nm.is_null()) {
+ if (!nm.is_null()) {
if (strcmp(nm.contents(), "test") == 0) {
fprintf(stderr, "found it!\n");
fflush(stderr);
@@ -3953,19 +3953,18 @@ bool string_iterator::get_location(bool allow_macro,
void string_iterator::backtrace()
{
- if (mac.filename) {
- if (program_name)
- fprintf(stderr, "%s: ", program_name);
+ if (mac.filename != 0 /* nullptr */) {
+ if (program_name != 0 /* nullptr */)
+ errprint("%1: ", program_name);
errprint("backtrace: '%1':%2", mac.filename,
- mac.lineno + lineno - 1);
- if (how_invoked) {
+ (mac.lineno + lineno - 1));
+ if (how_invoked != 0 /* nullptr */) {
if (!nm.is_null())
- errprint(": %1 '%2'\n", how_invoked, nm.contents());
+ errprint(": %1 '%2'", how_invoked, nm.contents());
else
- errprint(": %1\n", how_invoked);
+ errprint(": %1", how_invoked);
}
- else
- errprint("\n");
+ errprint("\n");
}
}
_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit