Module Name: src
Committed By: rillig
Date: Fri Mar 12 23:27:41 UTC 2021
Modified Files:
src/usr.bin/indent: indent.h io.c
Log Message:
indent: add 'const', rename variables, reorder formula for tab width
Column counting starts at 1. This 1 should rather be at the beginning
of the formula since it is thought of being added at the very beginning
of the line, not at the end.
When adding a tab, the newly added tab is added at the end of the
string, therefore that '+ 1' should be at the end of the formula as
well.
No functional change.
To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/usr.bin/indent/indent.h
cvs rdiff -u -r1.31 -r1.32 src/usr.bin/indent/io.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.6 src/usr.bin/indent/indent.h:1.7
--- src/usr.bin/indent/indent.h:1.6 Fri Mar 12 23:16:00 2021
+++ src/usr.bin/indent/indent.h Fri Mar 12 23:27:41 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: indent.h,v 1.6 2021/03/12 23:16:00 rillig Exp $ */
+/* $NetBSD: indent.h,v 1.7 2021/03/12 23:27:41 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -30,7 +30,7 @@
#if 0
#if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.h,v 1.6 2021/03/12 23:16:00 rillig Exp $");
+__RCSID("$NetBSD: indent.h,v 1.7 2021/03/12 23:27:41 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,8 @@ void add_typename(const char *);
void alloc_typenames(void);
int compute_code_indent(void);
int compute_label_indent(void);
-int count_spaces(int, char *);
-int count_spaces_until(int, char *, char *);
+int count_spaces(int, const char *);
+int count_spaces_until(int, const char *, const char *);
void init_constant_tt(void);
#ifdef debug
const char *token_type_name(token_type);
Index: src/usr.bin/indent/io.c
diff -u src/usr.bin/indent/io.c:1.31 src/usr.bin/indent/io.c:1.32
--- src/usr.bin/indent/io.c:1.31 Fri Mar 12 23:16:00 2021
+++ src/usr.bin/indent/io.c Fri Mar 12 23:27:41 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: io.c,v 1.31 2021/03/12 23:16:00 rillig Exp $ */
+/* $NetBSD: io.c,v 1.32 2021/03/12 23:27:41 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.31 2021/03/12 23:16:00 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.32 2021/03/12 23:27:41 rillig Exp $");
#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $");
#endif
@@ -478,42 +478,40 @@ pad_output(int current, int target)
*
*/
int
-count_spaces_until(int cur, char *buffer, char *end)
+count_spaces_until(int col, const char *buffer, const char *end)
/*
* this routine figures out where the character position will be after
* printing the text in buffer starting at column "current"
*/
{
- char *buf; /* used to look thru buffer */
-
- for (buf = buffer; *buf != '\0' && buf != end; ++buf) {
- switch (*buf) {
+ for (const char *p = buffer; *p != '\0' && p != end; ++p) {
+ switch (*p) {
case '\n':
case 014: /* form feed */
- cur = 1;
+ col = 1;
break;
case '\t':
- cur = opt.tabsize * (1 + (cur - 1) / opt.tabsize) + 1;
+ col = 1 + opt.tabsize * ((col - 1) / opt.tabsize + 1);
break;
case 010: /* backspace */
- --cur;
+ --col;
break;
default:
- ++cur;
+ ++col;
break;
} /* end of switch */
} /* end of for loop */
- return cur;
+ return col;
}
int
-count_spaces(int cur, char *buffer)
+count_spaces(int col, const char *buffer)
{
- return count_spaces_until(cur, buffer, NULL);
+ return count_spaces_until(col, buffer, NULL);
}
void