Module Name: src
Committed By: rillig
Date: Sat Mar 13 10:32:25 UTC 2021
Modified Files:
src/usr.bin/indent: indent.c indent.h io.c pr_comment.c
Log Message:
indent: inline calls to count_spaces and count_spaces_until
These two functions operated on column numbers instead of indentation,
which required adjustments of '+ 1' and '- 1'. Their names were
completely wrong since these functions did not count anything, instead
they computed the column.
No functional change.
To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.50 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.12 -r1.13 src/usr.bin/indent/indent.h
cvs rdiff -u -r1.40 -r1.41 src/usr.bin/indent/io.c
cvs rdiff -u -r1.23 -r1.24 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.49 src/usr.bin/indent/indent.c:1.50
--- src/usr.bin/indent/indent.c:1.49 Sat Mar 13 10:06:47 2021
+++ src/usr.bin/indent/indent.c Sat Mar 13 10:32:25 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: indent.c,v 1.49 2021/03/13 10:06:47 rillig Exp $ */
+/* $NetBSD: indent.c,v 1.50 2021/03/13 10:32:25 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -46,7 +46,7 @@ static char sccsid[] = "@(#)indent.c 5.1
#include <sys/cdefs.h>
#ifndef lint
#if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.49 2021/03/13 10:06:47 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.50 2021/03/13 10:32:25 rillig Exp $");
#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
#endif
@@ -686,7 +686,8 @@ main(int argc, char **argv)
*e_code++ = ' ';
ps.want_blank = false;
*e_code++ = token[0];
- ps.paren_indents[ps.p_l_follow - 1] = count_spaces_until(1, s_code, e_code) - 1;
+ ps.paren_indents[ps.p_l_follow - 1] =
+ indentation_after_range(0, s_code, e_code);
if (sp_sw && ps.p_l_follow == 1 && opt.extra_expression_indent
&& ps.paren_indents[0] < 2 * opt.ind_size)
ps.paren_indents[0] = 2 * opt.ind_size;
@@ -1150,8 +1151,9 @@ main(int argc, char **argv)
if (ps.block_init_level <= 0)
ps.block_init = 0;
if (break_comma && (!opt.leave_comma ||
- count_spaces_until(1 + compute_code_indent(), s_code, e_code) >
- opt.max_col - opt.tabsize))
+ 1 + indentation_after_range(
+ compute_code_indent(), s_code, e_code)
+ > opt.max_col - opt.tabsize))
force_nl = true;
}
break;
Index: src/usr.bin/indent/indent.h
diff -u src/usr.bin/indent/indent.h:1.12 src/usr.bin/indent/indent.h:1.13
--- src/usr.bin/indent/indent.h:1.12 Sat Mar 13 10:20:54 2021
+++ src/usr.bin/indent/indent.h Sat Mar 13 10:32:25 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: indent.h,v 1.12 2021/03/13 10:20:54 rillig Exp $ */
+/* $NetBSD: indent.h,v 1.13 2021/03/13 10:32:25 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -30,7 +30,7 @@
#if 0
#if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.h,v 1.12 2021/03/13 10:20:54 rillig Exp $");
+__RCSID("$NetBSD: indent.h,v 1.13 2021/03/13 10:32:25 rillig Exp $");
#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/indent.h 336333 2018-07-16 05:46:50Z pstef $");
#endif
@@ -47,8 +47,6 @@ void add_typename(const char *);
void alloc_typenames(void);
int compute_code_indent(void);
int compute_label_indent(void);
-int count_spaces(int, const char *);
-int count_spaces_until(int, const char *, const char *);
int indentation_after_range(int, const char *, const char *);
int indentation_after(int, const char *);
void init_constant_tt(void);
Index: src/usr.bin/indent/io.c
diff -u src/usr.bin/indent/io.c:1.40 src/usr.bin/indent/io.c:1.41
--- src/usr.bin/indent/io.c:1.40 Sat Mar 13 10:20:54 2021
+++ src/usr.bin/indent/io.c Sat Mar 13 10:32:25 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: io.c,v 1.40 2021/03/13 10:20:54 rillig Exp $ */
+/* $NetBSD: io.c,v 1.41 2021/03/13 10:32:25 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.40 2021/03/13 10:20:54 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.41 2021/03/13 10:32:25 rillig Exp $");
#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $");
#endif
@@ -184,7 +184,7 @@ dump_line(void)
}
} else
output_range(s_lab, e_lab);
- cur_col = count_spaces(cur_col, s_lab);
+ cur_col = 1 + indentation_after(cur_col - 1, s_lab);
} else
cur_col = 1; /* there is no label section */
@@ -215,7 +215,7 @@ dump_line(void)
}
cur_col = 1 + output_indent(cur_col - 1, target_col - 1);
output_range(s_code, e_code);
- cur_col = count_spaces(cur_col, s_code);
+ cur_col = 1 + indentation_after(cur_col - 1, s_code);
}
if (s_com != e_com) { /* print comment, if any */
int target = ps.com_col;
@@ -306,8 +306,8 @@ compute_code_indent(void)
int w;
int t = paren_indent;
- if ((w = count_spaces(t, s_code) - opt.max_col) > 0
- && count_spaces(target_ind + 1, s_code) <= opt.max_col) {
+ if ((w = 1 + indentation_after(t - 1, s_code) - opt.max_col) > 0
+ && 1 + indentation_after(target_ind, s_code) <= opt.max_col) {
t -= w + 1;
if (t > target_ind + 1)
target_ind = t - 1;
@@ -447,18 +447,6 @@ indentation_after(int ind, const char *s
return indentation_after_range(ind, s, NULL);
}
-int
-count_spaces_until(int col, const char *s, const char *e)
-{
- return 1 + indentation_after_range(col - 1, s, e);
-}
-
-int
-count_spaces(int col, const char *s)
-{
- return 1 + indentation_after(col - 1, s);
-}
-
void
diag(int level, const char *msg, ...)
{
Index: src/usr.bin/indent/pr_comment.c
diff -u src/usr.bin/indent/pr_comment.c:1.23 src/usr.bin/indent/pr_comment.c:1.24
--- src/usr.bin/indent/pr_comment.c:1.23 Sat Mar 13 10:06:47 2021
+++ src/usr.bin/indent/pr_comment.c Sat Mar 13 10:32:25 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: pr_comment.c,v 1.23 2021/03/13 10:06:47 rillig Exp $ */
+/* $NetBSD: pr_comment.c,v 1.24 2021/03/13 10:32:25 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.23 2021/03/13 10:06:47 rillig Exp $");
+__RCSID("$NetBSD: pr_comment.c,v 1.24 2021/03/13 10:32:25 rillig Exp $");
#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $");
#endif
@@ -162,11 +162,11 @@ pr_comment(void)
int target_col;
break_delim = false;
if (s_code != e_code)
- target_col = count_spaces(1 + compute_code_indent(), s_code);
+ target_col = 1 + indentation_after(compute_code_indent(), s_code);
else {
target_col = 1;
if (s_lab != e_lab)
- target_col = count_spaces(1 + compute_label_indent(), s_lab);
+ target_col = 1 + indentation_after(compute_label_indent(), 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)
@@ -188,7 +188,7 @@ pr_comment(void)
start = buf_ptr >= save_com && buf_ptr < save_com + sc_size ?
sc_buf : in_buffer;
- ps.n_comment_delta = 1 - count_spaces_until(1, start, buf_ptr - 2);
+ ps.n_comment_delta = -indentation_after_range(0, start, buf_ptr - 2);
} else {
ps.n_comment_delta = 0;
while (*buf_ptr == ' ' || *buf_ptr == '\t')
@@ -208,7 +208,7 @@ pr_comment(void)
if (t_ptr >= buf_end)
fill_buffer();
if (t_ptr[0] == '*' && t_ptr[1] == '/') {
- if (adj_max_col >= count_spaces_until(ps.com_col, buf_ptr, t_ptr + 2))
+ if (adj_max_col >= 1 + indentation_after_range(ps.com_col - 1, buf_ptr, t_ptr + 2))
break_delim = false;
break;
}
@@ -332,7 +332,7 @@ pr_comment(void)
*e_com++ = '*';
break;
default: /* we have a random char */
- now_col = count_spaces_until(ps.com_col, s_com, e_com);
+ now_col = 1 + indentation_after_range(ps.com_col - 1, s_com, e_com);
do {
check_size_comment(1, &last_bl);
*e_com = *buf_ptr++;