Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/indent indent: replace column calculations with inde...
details: https://anonhg.NetBSD.org/src/rev/5d196bca3920
branches: trunk
changeset: 988638:5d196bca3920
user: rillig <rillig%NetBSD.org@localhost>
date: Fri Oct 08 17:12:08 2021 +0000
description:
indent: replace column calculations with indent, part 3
No functional change.
diffstat:
usr.bin/indent/io.c | 17 +++++++----------
usr.bin/indent/pr_comment.c | 16 ++++++++--------
2 files changed, 15 insertions(+), 18 deletions(-)
diffs (89 lines):
diff -r e76d4ea6da90 -r 5d196bca3920 usr.bin/indent/io.c
--- a/usr.bin/indent/io.c Fri Oct 08 17:07:36 2021 +0000
+++ b/usr.bin/indent/io.c Fri Oct 08 17:12:08 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: io.c,v 1.83 2021/10/08 17:07:36 rillig Exp $ */
+/* $NetBSD: io.c,v 1.84 2021/10/08 17:12:08 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@
#include <sys/cdefs.h>
#if defined(__NetBSD__)
-__RCSID("$NetBSD: io.c,v 1.83 2021/10/08 17:07:36 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.84 2021/10/08 17:12:08 rillig Exp $");
#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $");
#endif
@@ -196,22 +196,19 @@
output_string(".*/\n");
}
- int target_col = 1 + compute_code_indent();
+ int target_ind = compute_code_indent();
for (int i = 0; i < ps.p_l_follow; i++) {
if (ps.paren_indents[i] >= 0) {
int ind = ps.paren_indents[i];
- /*
- * XXX: this mix of 'indent' and 'column' smells like
- * an off-by-one error.
- */
- ps.paren_indents[i] = (short)-(ind + target_col);
+ /* XXX: the '+ 1' smells like an off-by-one error. */
+ ps.paren_indents[i] = (short)-(ind + target_ind + 1);
debug_println(
"setting pi[%d] from %d to %d for column %d",
- i, ind, ps.paren_indents[i], target_col);
+ i, ind, ps.paren_indents[i], target_ind + 1);
}
}
- cur_ind = output_indent(cur_ind, target_col - 1);
+ cur_ind = output_indent(cur_ind, target_ind);
output_range(code.s, code.e);
cur_ind = indentation_after(cur_ind, code.s);
}
diff -r e76d4ea6da90 -r 5d196bca3920 usr.bin/indent/pr_comment.c
--- a/usr.bin/indent/pr_comment.c Fri Oct 08 17:07:36 2021 +0000
+++ b/usr.bin/indent/pr_comment.c Fri Oct 08 17:12:08 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pr_comment.c,v 1.58 2021/10/07 23:15:15 rillig Exp $ */
+/* $NetBSD: pr_comment.c,v 1.59 2021/10/08 17:12:08 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@
#include <sys/cdefs.h>
#if defined(__NetBSD__)
-__RCSID("$NetBSD: pr_comment.c,v 1.58 2021/10/07 23:15:15 rillig Exp $");
+__RCSID("$NetBSD: pr_comment.c,v 1.59 2021/10/08 17:12:08 rillig Exp $");
#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $");
#endif
@@ -126,18 +126,18 @@
} else {
break_delim = false;
- int target_col;
+ int target_ind;
if (code.s != code.e)
- target_col = 1 + indentation_after(compute_code_indent(), code.s);
+ target_ind = indentation_after(compute_code_indent(), code.s);
else if (lab.s != lab.e)
- target_col = 1 + indentation_after(compute_label_indent(), lab.s);
+ target_ind = indentation_after(compute_label_indent(), lab.s);
else
- target_col = 1;
+ target_ind = 0;
ps.com_col = ps.decl_on_line || ps.ind_level == 0
? opt.decl_comment_column : opt.comment_column;
- if (ps.com_col <= target_col)
- ps.com_col = opt.tabsize * (1 + (target_col - 1) / opt.tabsize) + 1;
+ if (ps.com_col <= target_ind + 1)
+ ps.com_col = opt.tabsize * (1 + target_ind / opt.tabsize) + 1;
if (ps.com_col + 24 > adj_max_line_length)
/* XXX: mismatch between column and length */
adj_max_line_length = ps.com_col + 24;
Home |
Main Index |
Thread Index |
Old Index