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: add 'const', rename variables, reorde...



details:   https://anonhg.NetBSD.org/src/rev/025fbe2053b9
branches:  trunk
changeset: 953559:025fbe2053b9
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Mar 12 23:27:41 2021 +0000

description:
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.

diffstat:

 usr.bin/indent/indent.h |   8 ++++----
 usr.bin/indent/io.c     |  26 ++++++++++++--------------
 2 files changed, 16 insertions(+), 18 deletions(-)

diffs (100 lines):

diff -r 74ea459fb90d -r 025fbe2053b9 usr.bin/indent/indent.h
--- a/usr.bin/indent/indent.h   Fri Mar 12 23:16:00 2021 +0000
+++ b/usr.bin/indent/indent.h   Fri Mar 12 23:27:41 2021 +0000
@@ -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   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);
diff -r 74ea459fb90d -r 025fbe2053b9 usr.bin/indent/io.c
--- a/usr.bin/indent/io.c       Fri Mar 12 23:16:00 2021 +0000
+++ b/usr.bin/indent/io.c       Fri Mar 12 23:27:41 2021 +0000
@@ -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 @@
 #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 @@
  *
  */
 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



Home | Main Index | Thread Index | Old Index