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: inline calls to count_spaces and coun...
details: https://anonhg.NetBSD.org/src/rev/8fff9c787f19
branches: trunk
changeset: 1019516:8fff9c787f19
user: rillig <rillig%NetBSD.org@localhost>
date: Sat Mar 13 10:32:25 2021 +0000
description:
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.
diffstat:
usr.bin/indent/indent.c | 12 +++++++-----
usr.bin/indent/indent.h | 6 ++----
usr.bin/indent/io.c | 24 ++++++------------------
usr.bin/indent/pr_comment.c | 14 +++++++-------
4 files changed, 22 insertions(+), 34 deletions(-)
diffs (192 lines):
diff -r 0752fb361e53 -r 8fff9c787f19 usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c Sat Mar 13 10:20:54 2021 +0000
+++ b/usr.bin/indent/indent.c Sat Mar 13 10:32:25 2021 +0000
@@ -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 @@
#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 @@
*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 @@
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;
diff -r 0752fb361e53 -r 8fff9c787f19 usr.bin/indent/indent.h
--- a/usr.bin/indent/indent.h Sat Mar 13 10:20:54 2021 +0000
+++ b/usr.bin/indent/indent.h Sat Mar 13 10:32:25 2021 +0000
@@ -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 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);
diff -r 0752fb361e53 -r 8fff9c787f19 usr.bin/indent/io.c
--- a/usr.bin/indent/io.c Sat Mar 13 10:20:54 2021 +0000
+++ b/usr.bin/indent/io.c Sat Mar 13 10:32:25 2021 +0000
@@ -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 @@
#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 @@
}
} 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 @@
}
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 @@
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 @@
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, ...)
{
diff -r 0752fb361e53 -r 8fff9c787f19 usr.bin/indent/pr_comment.c
--- a/usr.bin/indent/pr_comment.c Sat Mar 13 10:20:54 2021 +0000
+++ b/usr.bin/indent/pr_comment.c Sat Mar 13 10:32:25 2021 +0000
@@ -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 @@
#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 @@
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 @@
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 @@
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 @@
*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++;
Home |
Main Index |
Thread Index |
Old Index