gbranden pushed a commit to branch master
in repository groff.
commit 24de795fb4c0582c8e133d0dffb5f883b4bbc5a2
Author: G. Branden Robinson <[email protected]>
AuthorDate: Thu May 15 08:20:31 2025 -0500
src/roff/troff/node.cpp: Fix code style nits.
* src/roff/troff/node.cpp: Fix code style nits.
(font_info::get_tfont)
(tfont::get_lig)
(troff_output_file::flush_tbuf)
(troff_output_file::put_char_width)
(troff_output_file::put_char)
(troff_output_file::set_font)
(troff_output_file::really_copy_file)
(node::add_discretionary_hyphen)
(break_char_node::add_self)
(space_node::split)
(node_list_split)
(composite_node::asciify)
(hline_node::tprint)
(vline_node::tprint)
(overstrike_node::tprint)
(node::add_char)
(same_node): Reorder equality comparisons to avoid inadvertent lvalue
assignment.
Also break up 7-link chain of short circuit operations such that each
logical predicate appears on its own source line.
Also annotate null pointers with `nullptr` comment to ease any future
transition to C++11, which defines it as a keyword.
---
ChangeLog | 22 ++++++++++++++++++++++
src/roff/troff/node.cpp | 44 +++++++++++++++++++++++---------------------
2 files changed, 45 insertions(+), 21 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 0de470d23..56039cbae 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,25 @@
+2025-05-15 G. Branden Robinson <[email protected]>
+
+ * src/roff/troff/node.cpp: Fix code style nits.
+ (font_info::get_tfont)
+ (tfont::get_lig)
+ (troff_output_file::flush_tbuf)
+ (troff_output_file::put_char_width)
+ (troff_output_file::put_char)
+ (troff_output_file::set_font)
+ (troff_output_file::really_copy_file)
+ (node::add_discretionary_hyphen)
+ (break_char_node::add_self)
+ (space_node::split)
+ (node_list_split)
+ (composite_node::asciify)
+ (hline_node::tprint)
+ (vline_node::tprint)
+ (overstrike_node::tprint)
+ (node::add_char)
+ (same_node): Reorder equality comparisons to avoid inadvertent
+ lvalue assignment.
+
2025-05-13 G. Branden Robinson <[email protected]>
* src/roff/troff/node.cpp (container_node::dump_node): Give
diff --git a/src/roff/troff/node.cpp b/src/roff/troff/node.cpp
index 130af98fe..20d879432 100644
--- a/src/roff/troff/node.cpp
+++ b/src/roff/troff/node.cpp
@@ -299,8 +299,10 @@ int env_get_zoom(environment *env)
tfont *font_info::get_tfont(font_size fs, int height, int slant,
int fontno)
{
- if (last_tfont == 0 || fs != last_size
- || height != last_height || slant != last_slant
+ if (0 /* nullptr */ == last_tfont
+ || fs != last_size
+ || height != last_height
+ || slant != last_slant
|| global_ligature_mode != last_ligature_mode
|| global_kern_mode != last_kern_mode
|| fontno != number) {
@@ -668,7 +670,7 @@ symbol SYMBOL_Fl("Fl");
charinfo *tfont::get_lig(charinfo *c1, charinfo *c2)
{
- if (ligature_mode == 0)
+ if (0 == ligature_mode)
return 0 /* nullptr */;
charinfo *ci = 0 /* nullptr */;
if (c1->get_ascii_code() == 'f') {
@@ -1060,9 +1062,9 @@ void troff_output_file::flush_tbuf()
return;
}
- if (tbuf_len == 0)
+ if (0 == tbuf_len)
return;
- if (tbuf_kern == 0)
+ if (0 == tbuf_kern)
put('t');
else {
put('u');
@@ -1117,7 +1119,7 @@ void troff_output_file::put_char_width(charinfo *ci,
tfont *tf,
else {
put('C');
const char *s = ci->nm.contents();
- if (s[1] == 0) {
+ if (0 == s[1]) {
put('\\');
put(s[0]);
}
@@ -1194,7 +1196,7 @@ void troff_output_file::put_char(charinfo *ci, tfont *tf,
else {
put('C');
const char *s = ci->nm.contents();
- if (s[1] == 0) {
+ if (0 == s[1]) {
put('\\');
put(s[0]);
}
@@ -1283,7 +1285,7 @@ void troff_output_file::set_font(tfont *tf)
int height = tf->get_height();
if (current_height != height) {
put("x Height ");
- put(height == 0 ? current_size : height);
+ put((0 == height) ? current_size : height);
put('\n');
current_height = height;
}
@@ -1619,7 +1621,7 @@ void troff_output_file::really_copy_file(hunits x, vunits
y,
do_motion();
errno = 0;
FILE *ifp = include_search_path.open_file_cautious(filename);
- if (ifp == 0)
+ if (0 /* nullptr */ == ifp)
error("cannot open '%1': %2", filename, strerror(errno));
else {
int c;
@@ -2644,7 +2646,7 @@ node *node::add_discretionary_hyphen()
glyph_node *gn = new glyph_node(soft_hyphen_char, tf, gcol, fcol,
state, div_nest_level);
node *n1 = n->merge_glyph_node(gn);
- if (n1 == 0 /* nullptr */) {
+ if (0 /* nullptr */ == n1) {
gn->next = n;
n1 = gn;
}
@@ -3101,7 +3103,7 @@ enum break_char_type {
node *break_char_node::add_self(node *n, hyphen_list **p)
{
bool have_space_node = false;
- assert((*p)->hyphenation_code == 0);
+ assert(0 == (*p)->hyphenation_code);
if (break_code & ALLOWS_BREAK_BEFORE) {
if (((*p)->is_breakable)
|| (break_code & IGNORES_SURROUNDING_HYPHENATION_CODES)) {
@@ -4098,7 +4100,7 @@ void node::split(int /*where*/, node ** /*prep*/, node **
/*postp*/)
void space_node::split(int where, node **pre, node **post)
{
- assert(where == 0);
+ assert(0 == where);
*pre = next;
*post = 0 /* nullptr */;
delete this;
@@ -4107,7 +4109,7 @@ void space_node::split(int where, node **pre, node **post)
static void node_list_split(node *p, int *wherep,
node **prep, node **postp)
{
- if (p == 0)
+ if (0 /* nullptr */ == p)
return;
int nb = p->nbreaks();
node_list_split(p->next, wherep, prep, postp);
@@ -4129,7 +4131,7 @@ static void node_list_split(node *p, int *wherep,
void dbreak_node::split(int where, node **prep, node **postp)
{
assert(where >= 0);
- if (where == 0) {
+ if (0 == where) {
*postp = post;
post = 0 /* nullptr */;
if (0 /* nullptr */ == pre)
@@ -4731,7 +4733,7 @@ hyphenation_type composite_node::get_hyphenation_type()
void composite_node::asciify(macro *m)
{
unsigned char c = ci->get_asciify_code();
- if (c == 0)
+ if (0 == c)
c = ci->get_ascii_code();
if (c != 0) {
m->append(c);
@@ -5127,7 +5129,7 @@ void hline_node::tprint(troff_output_file *out)
return;
}
int i = int(x / w);
- if (i == 0) {
+ if (0 == i) {
hunits xx = x - w;
hunits xx2 = (xx / 2);
out->right(xx2);
@@ -5165,7 +5167,7 @@ void vline_node::tprint(troff_output_file *out)
y = -y;
int i = y / h;
vunits rem = y - i*h;
- if (i == 0) {
+ if (0 == i) {
out->right(nodes->width());
out->down(-rem);
}
@@ -5191,7 +5193,7 @@ void vline_node::tprint(troff_output_file *out)
else {
int i = y / h;
vunits rem = y - i*h;
- if (i == 0) {
+ if (0 == i) {
out->down(rem);
out->right(nodes->width());
}
@@ -5242,7 +5244,7 @@ void overstrike_node::tprint(troff_output_file *out)
void bracket_node::tprint(troff_output_file *out)
{
- if (nodes == 0)
+ if (0 /* nullptr */ == nodes)
return;
int npieces = 0;
node *tem;
@@ -5598,7 +5600,7 @@ node *node::add_char(charinfo *ci, environment *env,
else {
hunits old_width = width();
node *p = gn->merge_self(this);
- if (p == 0) {
+ if (0 /* nullptr */ == p) {
*widthp += gn->width();
gn->next = this;
res = gn;
@@ -5642,7 +5644,7 @@ static inline int same_node(node *n1, node *n2)
return false;
}
else
- return n2 == 0;
+ return 0 /* nullptr */ == n2;
}
int same_node_list(node *n1, node *n2)
_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit