Module Name: src
Committed By: rillig
Date: Sat Mar 13 09:54:12 UTC 2021
Modified Files:
src/usr.bin/indent: indent.h io.c pr_comment.c
Log Message:
indent: replace compute_label_column with compute_label_indent
Using the invariant 'column == 1 + indent'. This removes several overly
complicated '+ 1' from the code that are not needed conceptually.
No functional change.
To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/usr.bin/indent/indent.h
cvs rdiff -u -r1.37 -r1.38 src/usr.bin/indent/io.c
cvs rdiff -u -r1.21 -r1.22 src/usr.bin/indent/pr_comment.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.bin/indent/indent.h
diff -u src/usr.bin/indent/indent.h:1.9 src/usr.bin/indent/indent.h:1.10
--- src/usr.bin/indent/indent.h:1.9 Sat Mar 13 09:21:57 2021
+++ src/usr.bin/indent/indent.h Sat Mar 13 09:54:11 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: indent.h,v 1.9 2021/03/13 09:21:57 rillig Exp $ */
+/* $NetBSD: indent.h,v 1.10 2021/03/13 09:54:11 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -30,7 +30,7 @@
#if 0
#if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.h,v 1.9 2021/03/13 09:21:57 rillig Exp $");
+__RCSID("$NetBSD: indent.h,v 1.10 2021/03/13 09:54:11 rillig Exp $");
#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/indent.h 336333 2018-07-16 05:46:50Z pstef $");
#endif
@@ -46,7 +46,7 @@ __FBSDID("$FreeBSD: head/usr.bin/indent/
void add_typename(const char *);
void alloc_typenames(void);
int compute_code_column(void);
-int compute_label_column(void);
+int compute_label_indent(void);
int count_spaces(int, const char *);
int count_spaces_until(int, const char *, const char *);
void init_constant_tt(void);
Index: src/usr.bin/indent/io.c
diff -u src/usr.bin/indent/io.c:1.37 src/usr.bin/indent/io.c:1.38
--- src/usr.bin/indent/io.c:1.37 Sat Mar 13 09:48:04 2021
+++ src/usr.bin/indent/io.c Sat Mar 13 09:54:11 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: io.c,v 1.37 2021/03/13 09:48:04 rillig Exp $ */
+/* $NetBSD: io.c,v 1.38 2021/03/13 09:54:11 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -46,7 +46,7 @@ static char sccsid[] = "@(#)io.c 8.1 (Be
#include <sys/cdefs.h>
#ifndef lint
#if defined(__NetBSD__)
-__RCSID("$NetBSD: io.c,v 1.37 2021/03/13 09:48:04 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.38 2021/03/13 09:54:11 rillig Exp $");
#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $");
#endif
@@ -162,7 +162,7 @@ dump_line(void)
while (e_lab > s_lab && (e_lab[-1] == ' ' || e_lab[-1] == '\t'))
e_lab--;
*e_lab = '\0';
- cur_col = 1 + output_indent(0, compute_label_column() - 1);
+ cur_col = 1 + output_indent(0, compute_label_indent());
if (s_lab[0] == '#' && (strncmp(s_lab, "#else", 5) == 0
|| strncmp(s_lab, "#endif", 6) == 0)) {
char *s = s_lab;
@@ -315,12 +315,13 @@ compute_code_column(void)
}
int
-compute_label_column(void)
+compute_label_indent(void)
{
- return
- ps.pcase ? (int) (case_ind * opt.ind_size) + 1
- : *s_lab == '#' ? 1
- : opt.ind_size * (ps.ind_level - label_offset) + 1;
+ if (ps.pcase)
+ return (int) (case_ind * opt.ind_size);
+ if (s_lab[0] == '#')
+ return 0;
+ return opt.ind_size * (ps.ind_level - label_offset);
}
Index: src/usr.bin/indent/pr_comment.c
diff -u src/usr.bin/indent/pr_comment.c:1.21 src/usr.bin/indent/pr_comment.c:1.22
--- src/usr.bin/indent/pr_comment.c:1.21 Sat Mar 13 00:26:56 2021
+++ src/usr.bin/indent/pr_comment.c Sat Mar 13 09:54:11 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: pr_comment.c,v 1.21 2021/03/13 00:26:56 rillig Exp $ */
+/* $NetBSD: pr_comment.c,v 1.22 2021/03/13 09:54:11 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -46,7 +46,7 @@ static char sccsid[] = "@(#)pr_comment.c
#include <sys/cdefs.h>
#ifndef lint
#if defined(__NetBSD__)
-__RCSID("$NetBSD: pr_comment.c,v 1.21 2021/03/13 00:26:56 rillig Exp $");
+__RCSID("$NetBSD: pr_comment.c,v 1.22 2021/03/13 09:54:11 rillig Exp $");
#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $");
#endif
@@ -166,7 +166,7 @@ pr_comment(void)
else {
target_col = 1;
if (s_lab != e_lab)
- target_col = count_spaces(compute_label_column(), s_lab);
+ target_col = count_spaces(compute_label_indent() + 1, s_lab);
}
ps.com_col = ps.decl_on_line || ps.ind_level == 0 ? opt.decl_com_ind : opt.com_ind;
if (ps.com_col <= target_col)