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: extract common code for advancing a s...



details:   https://anonhg.NetBSD.org/src/rev/17be56d6b94e
branches:  trunk
changeset: 989002:17be56d6b94e
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Oct 09 11:00:27 2021 +0000

description:
indent: extract common code for advancing a single tab

No functional change.

diffstat:

 usr.bin/indent/indent.c     |  8 ++++----
 usr.bin/indent/indent.h     |  8 +++++++-
 usr.bin/indent/io.c         |  8 ++++----
 usr.bin/indent/pr_comment.c |  6 +++---
 4 files changed, 18 insertions(+), 12 deletions(-)

diffs (118 lines):

diff -r 45d8b7d6e023 -r 17be56d6b94e usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c   Sat Oct 09 10:56:13 2021 +0000
+++ b/usr.bin/indent/indent.c   Sat Oct 09 11:00:27 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.c,v 1.135 2021/10/08 23:47:40 rillig Exp $      */
+/*     $NetBSD: indent.c,v 1.136 2021/10/09 11:00:27 rillig Exp $      */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.135 2021/10/08 23:47:40 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.136 2021/10/09 11:00:27 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -579,7 +579,7 @@
        if (*p == ' ')
            ind++;
        else if (*p == '\t')
-           ind = opt.tabsize * (1 + ind / opt.tabsize);
+           ind = next_tab(ind);
        else
            break;
        p++;
@@ -606,7 +606,7 @@
     if (tabs_to_var) {
        int tpos;
 
-       while ((tpos = opt.tabsize * (1 + pos / opt.tabsize)) <= cur_decl_ind) {
+       while ((tpos = next_tab(pos)) <= cur_decl_ind) {
            buf_add_char(&code, '\t');
            pos = tpos;
        }
diff -r 45d8b7d6e023 -r 17be56d6b94e usr.bin/indent/indent.h
--- a/usr.bin/indent/indent.h   Sat Oct 09 10:56:13 2021 +0000
+++ b/usr.bin/indent/indent.h   Sat Oct 09 11:00:27 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.h,v 1.37 2021/10/08 23:43:33 rillig Exp $       */
+/*     $NetBSD: indent.h,v 1.38 2021/10/09 11:00:27 rillig Exp $       */
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -367,3 +367,9 @@
 {
     return ch == ' ' || ch == '\t';
 }
+
+static inline int
+next_tab(int ind)
+{
+    return ind - ind % opt.tabsize + opt.tabsize;
+}
diff -r 45d8b7d6e023 -r 17be56d6b94e usr.bin/indent/io.c
--- a/usr.bin/indent/io.c       Sat Oct 09 10:56:13 2021 +0000
+++ b/usr.bin/indent/io.c       Sat Oct 09 11:00:27 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: io.c,v 1.90 2021/10/08 21:16:23 rillig Exp $   */
+/*     $NetBSD: io.c,v 1.91 2021/10/09 11:00:27 rillig Exp $   */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: io.c,v 1.90 2021/10/08 21:16:23 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.91 2021/10/09 11:00:27 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -189,7 +189,7 @@
        if (*com_st == ' ')
            target_ind++, com_st++;
        else if (*com_st == '\t') {
-           target_ind = opt.tabsize * (1 + target_ind / opt.tabsize);
+           target_ind = next_tab(target_ind);
            com_st++;
        } else
            target_ind = 0;
@@ -473,7 +473,7 @@
        if (*p == '\n' || *p == '\f')
            ind = 0;
        else if (*p == '\t')
-           ind = opt.tabsize * (ind / opt.tabsize + 1);
+           ind = next_tab(ind);
        else if (*p == '\b')
            --ind;
        else
diff -r 45d8b7d6e023 -r 17be56d6b94e usr.bin/indent/pr_comment.c
--- a/usr.bin/indent/pr_comment.c       Sat Oct 09 10:56:13 2021 +0000
+++ b/usr.bin/indent/pr_comment.c       Sat Oct 09 11:00:27 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pr_comment.c,v 1.68 2021/10/08 22:37:33 rillig Exp $   */
+/*     $NetBSD: pr_comment.c,v 1.69 2021/10/09 11:00:27 rillig Exp $   */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: pr_comment.c,v 1.68 2021/10/08 22:37:33 rillig Exp $");
+__RCSID("$NetBSD: pr_comment.c,v 1.69 2021/10/09 11:00:27 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -131,7 +131,7 @@
            ps.com_ind = ps.decl_on_line || ps.ind_level == 0
                ? opt.decl_comment_column - 1 : opt.comment_column - 1;
            if (ps.com_ind <= target_ind)
-               ps.com_ind = opt.tabsize * (1 + target_ind / opt.tabsize);
+               ps.com_ind = next_tab(target_ind);
            /* XXX: the '+ 1' smells like an off-by-one error */
            if (ps.com_ind + 1 + 24 > adj_max_line_length)
                adj_max_line_length = ps.com_ind + 1 + 24;



Home | Main Index | Thread Index | Old Index