Module Name: src
Committed By: rillig
Date: Sat Oct 9 11:00:27 UTC 2021
Modified Files:
src/usr.bin/indent: indent.c indent.h io.c pr_comment.c
Log Message:
indent: extract common code for advancing a single tab
No functional change.
To generate a diff of this commit:
cvs rdiff -u -r1.135 -r1.136 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.37 -r1.38 src/usr.bin/indent/indent.h
cvs rdiff -u -r1.90 -r1.91 src/usr.bin/indent/io.c
cvs rdiff -u -r1.68 -r1.69 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.c
diff -u src/usr.bin/indent/indent.c:1.135 src/usr.bin/indent/indent.c:1.136
--- src/usr.bin/indent/indent.c:1.135 Fri Oct 8 23:47:40 2021
+++ src/usr.bin/indent/indent.c Sat Oct 9 11:00:27 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: indent.c,v 1.135 2021/10/08 23:47:40 rillig Exp $ */
+/* $NetBSD: indent.c,v 1.136 2021/10/09 11:00:27 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)indent.c 5.1
#include <sys/cdefs.h>
#if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.135 2021/10/08 23:47:40 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.136 2021/10/09 11:00:27 rillig Exp $");
#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
#endif
@@ -579,7 +579,7 @@ main_prepare_parsing(void)
if (*p == ' ')
ind++;
else if (*p == '\t')
- ind = opt.tabsize * (1 + ind / opt.tabsize);
+ ind = next_tab(ind);
else
break;
p++;
@@ -606,7 +606,7 @@ indent_declaration(int cur_decl_ind, boo
if (tabs_to_var) {
int tpos;
- while ((tpos = opt.tabsize * (1 + pos / opt.tabsize)) <= cur_decl_ind) {
+ while ((tpos = next_tab(pos)) <= cur_decl_ind) {
buf_add_char(&code, '\t');
pos = tpos;
}
Index: src/usr.bin/indent/indent.h
diff -u src/usr.bin/indent/indent.h:1.37 src/usr.bin/indent/indent.h:1.38
--- src/usr.bin/indent/indent.h:1.37 Fri Oct 8 23:43:33 2021
+++ src/usr.bin/indent/indent.h Sat Oct 9 11:00:27 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: indent.h,v 1.37 2021/10/08 23:43:33 rillig Exp $ */
+/* $NetBSD: indent.h,v 1.38 2021/10/09 11:00:27 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -367,3 +367,9 @@ is_hspace(char ch)
{
return ch == ' ' || ch == '\t';
}
+
+static inline int
+next_tab(int ind)
+{
+ return ind - ind % opt.tabsize + opt.tabsize;
+}
Index: src/usr.bin/indent/io.c
diff -u src/usr.bin/indent/io.c:1.90 src/usr.bin/indent/io.c:1.91
--- src/usr.bin/indent/io.c:1.90 Fri Oct 8 21:16:23 2021
+++ src/usr.bin/indent/io.c Sat Oct 9 11:00:27 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: io.c,v 1.90 2021/10/08 21:16:23 rillig Exp $ */
+/* $NetBSD: io.c,v 1.91 2021/10/09 11:00:27 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)io.c 8.1 (Be
#include <sys/cdefs.h>
#if defined(__NetBSD__)
-__RCSID("$NetBSD: io.c,v 1.90 2021/10/08 21:16:23 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.91 2021/10/09 11:00:27 rillig Exp $");
#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $");
#endif
@@ -189,7 +189,7 @@ dump_line_comment(int ind)
if (*com_st == ' ')
target_ind++, com_st++;
else if (*com_st == '\t') {
- target_ind = opt.tabsize * (1 + target_ind / opt.tabsize);
+ target_ind = next_tab(target_ind);
com_st++;
} else
target_ind = 0;
@@ -473,7 +473,7 @@ indentation_after_range(int ind, const c
if (*p == '\n' || *p == '\f')
ind = 0;
else if (*p == '\t')
- ind = opt.tabsize * (ind / opt.tabsize + 1);
+ ind = next_tab(ind);
else if (*p == '\b')
--ind;
else
Index: src/usr.bin/indent/pr_comment.c
diff -u src/usr.bin/indent/pr_comment.c:1.68 src/usr.bin/indent/pr_comment.c:1.69
--- src/usr.bin/indent/pr_comment.c:1.68 Fri Oct 8 22:37:33 2021
+++ src/usr.bin/indent/pr_comment.c Sat Oct 9 11:00:27 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: pr_comment.c,v 1.68 2021/10/08 22:37:33 rillig Exp $ */
+/* $NetBSD: pr_comment.c,v 1.69 2021/10/09 11:00:27 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)pr_comment.c
#include <sys/cdefs.h>
#if defined(__NetBSD__)
-__RCSID("$NetBSD: pr_comment.c,v 1.68 2021/10/08 22:37:33 rillig Exp $");
+__RCSID("$NetBSD: pr_comment.c,v 1.69 2021/10/09 11:00:27 rillig Exp $");
#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $");
#endif
@@ -131,7 +131,7 @@ process_comment(void)
ps.com_ind = ps.decl_on_line || ps.ind_level == 0
? opt.decl_comment_column - 1 : opt.comment_column - 1;
if (ps.com_ind <= target_ind)
- ps.com_ind = opt.tabsize * (1 + target_ind / opt.tabsize);
+ ps.com_ind = next_tab(target_ind);
/* XXX: the '+ 1' smells like an off-by-one error */
if (ps.com_ind + 1 + 24 > adj_max_line_length)
adj_max_line_length = ps.com_ind + 1 + 24;