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.
This commit is contained in:
parent
4f1ab5eff9
commit
5888ddac66
@ -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/indent.h 336333 2018-07-16 05:46:50Z pst
|
||||
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);
|
||||
|
@ -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 (Berkeley) 6/6/93";
|
||||
#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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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 8.1 (Berkeley) 6/6/93";
|
||||
#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)
|
||||
|
Loading…
Reference in New Issue
Block a user