[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[groff] 13/19: [troff]: Trivially refactor.
From: |
G. Branden Robinson |
Subject: |
[groff] 13/19: [troff]: Trivially refactor. |
Date: |
Sun, 22 Sep 2024 00:33:06 -0400 (EDT) |
gbranden pushed a commit to branch master
in repository groff.
commit 6c752dea20a71097c3b854000262dacb17943131
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Sat Sep 21 21:32:23 2024 -0500
[troff]: Trivially refactor.
* src/roff/troff/input.cpp (interpolate_macro): Fix code style nits.
Reorder equality comparisons to avoid inadvertent lvalue assignment.
Rename local variable `warned` to `was_warned` and demote it from
`int` to `bool`. Assign to it using Boolean, not integer, literals.
Explicitly compare variable of pointer type to null pointer literal
instead of letting it pun down to a Boolean. Stop treating return
value of `warning()` as significant. If ever there was a function
that was called only for its side effects, that's it.
---
ChangeLog | 12 ++++++++++++
src/roff/troff/input.cpp | 21 +++++++++++----------
2 files changed, 23 insertions(+), 10 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 130f94c67..f4dad2c0f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2024-09-21 G. Branden Robinson <g.branden.robinson@gmail.com>
+
+ * src/roff/troff/input.cpp (interpolate_macro): Fix code style
+ nits. Reorder equality comparisons to avoid inadvertent lvalue
+ assignment. Rename local variable `warned` to `was_warned` and
+ demote it from `int` to `bool`. Assign to it using Boolean, not
+ integer, literals. Explicitly compare variable of pointer type
+ to null pointer literal instead of letting it pun down to a
+ Boolean. Stop treating return value of `warning()` as
+ significant. If ever there was a function that was called only
+ for its side effects, that's it.
+
2024-09-21 G. Branden Robinson <g.branden.robinson@gmail.com>
* src/roff/troff/input.cpp (device_request): Add extensive new
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 670fe2eea..f14a42336 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -4020,9 +4020,10 @@ bool operator==(const macro &m1, const macro &m2)
static void interpolate_macro(symbol nm, bool do_not_want_next_token)
{
- request_or_macro *p = (request_or_macro *)request_dictionary.lookup(nm);
- if (p == 0) {
- int warned = 0;
+ request_or_macro *p
+ = (request_or_macro *)request_dictionary.lookup(nm);
+ if (0 /* nullptr */ == p) {
+ bool was_warned = false;
const char *s = nm.contents();
if (strlen(s) > 2) {
request_or_macro *r;
@@ -4033,20 +4034,20 @@ static void interpolate_macro(symbol nm, bool
do_not_want_next_token)
r = (request_or_macro *)request_dictionary.lookup(symbol(buf));
if (r) {
macro *m = r->to_macro();
- if (!m || !m->is_empty())
- warned = warning(WARN_SPACE,
- "macro '%1' not defined "
- "(possibly missing space after '%2')",
- nm.contents(), buf);
+ if ((0 /* nullptr */ == m) || !m->is_empty()) {
+ warning(WARN_SPACE, "macro '%1' not defined (possibly missing"
+ " space after '%2')", nm.contents(), buf);
+ was_warned = true;
+ }
}
}
- if (!warned) {
+ if (!was_warned) {
warning(WARN_MAC, "macro '%1' not defined", nm.contents());
p = new macro;
request_dictionary.define(nm, p);
}
}
- if (p)
+ if (p != 0 /* nullptr */)
p->invoke(nm, do_not_want_next_token);
else {
skip_line();
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [groff] 13/19: [troff]: Trivially refactor.,
G. Branden Robinson <=