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: calculate indentation instead of column
details: https://anonhg.NetBSD.org/src/rev/8a2cb74636a5
branches: trunk
changeset: 988636:8a2cb74636a5
user: rillig <rillig%NetBSD.org@localhost>
date: Fri Oct 08 17:04:13 2021 +0000
description:
indent: calculate indentation instead of column
This avoids constantly adding and subtracting 1.
No functional change.
diffstat:
usr.bin/indent/io.c | 22 +++++++++++-----------
1 files changed, 11 insertions(+), 11 deletions(-)
diffs (79 lines):
diff -r 116843c6c142 -r 8a2cb74636a5 usr.bin/indent/io.c
--- a/usr.bin/indent/io.c Fri Oct 08 17:00:21 2021 +0000
+++ b/usr.bin/indent/io.c Fri Oct 08 17:04:13 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: io.c,v 1.81 2021/10/08 17:00:21 rillig Exp $ */
+/* $NetBSD: io.c,v 1.82 2021/10/08 17:04:13 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.81 2021/10/08 17:00:21 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.82 2021/10/08 17:04:13 rillig Exp $");
#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $");
#endif
@@ -110,7 +110,7 @@
void
dump_line(void)
{
- int cur_col;
+ int cur_ind;
static bool not_first_line;
if (ps.procname[0] != '\0') {
@@ -158,7 +158,7 @@
lab.e--;
*lab.e = '\0';
- cur_col = 1 + output_indent(0, compute_label_indent());
+ cur_ind = output_indent(0, compute_label_indent());
if (lab.s[0] == '#' && (strncmp(lab.s, "#else", 5) == 0
|| strncmp(lab.s, "#endif", 6) == 0)) {
@@ -184,9 +184,9 @@
}
} else
output_range(lab.s, lab.e);
- cur_col = 1 + indentation_after(cur_col - 1, lab.s);
+ cur_ind = indentation_after(cur_ind, lab.s);
} else
- cur_col = 1; /* there is no label section */
+ cur_ind = 0; /* there is no label section */
ps.is_case_label = false;
@@ -211,9 +211,9 @@
}
}
- cur_col = 1 + output_indent(cur_col - 1, target_col - 1);
+ cur_ind = output_indent(cur_ind, target_col - 1);
output_range(code.s, code.e);
- cur_col = 1 + indentation_after(cur_col - 1, code.s);
+ cur_ind = indentation_after(cur_ind, code.s);
}
if (com.s != com.e) { /* print comment, if any */
@@ -233,15 +233,15 @@
} else
target_col = 1;
}
- if (cur_col > target_col) { /* if comment can't fit on this line,
+ if (cur_ind + 1 > target_col) { /* if comment can't fit on this line,
* put it on next line */
output_char('\n');
- cur_col = 1;
+ cur_ind = 0;
ps.stats.lines++;
}
while (com.e > com_st && isspace((unsigned char)com.e[-1]))
com.e--;
- (void)output_indent(cur_col - 1, target_col - 1);
+ (void)output_indent(cur_ind, target_col - 1);
output_range(com_st, com.e);
ps.comment_delta = ps.n_comment_delta;
ps.stats.comment_lines++;
Home |
Main Index |
Thread Index |
Old Index