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: move ind_add from io.c to indent.c



details:   https://anonhg.NetBSD.org/src/rev/fba595142d03
branches:  trunk
changeset: 1026485:fba595142d03
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Nov 26 14:17:01 2021 +0000

description:
indent: move ind_add from io.c to indent.c

It's a general-purpose function that is not directly related to input or
output.

diffstat:

 usr.bin/indent/indent.c |  24 ++++++++++++++++++++++--
 usr.bin/indent/io.c     |  20 ++------------------
 2 files changed, 24 insertions(+), 20 deletions(-)

diffs (83 lines):

diff -r 44f6862390ac -r fba595142d03 usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c   Fri Nov 26 13:32:38 2021 +0000
+++ b/usr.bin/indent/indent.c   Fri Nov 26 14:17:01 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.c,v 1.232 2021/11/25 18:48:37 rillig Exp $      */
+/*     $NetBSD: indent.c,v 1.233 2021/11/26 14:17:01 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.232 2021/11/25 18:48:37 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.233 2021/11/26 14:17:01 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -215,6 +215,26 @@
     va_end(ap);
 }
 
+/*
+ * Compute the indentation from starting at 'ind' and adding the text from
+ * 'start' to 'end'.
+ */
+int
+ind_add(int ind, const char *start, const char *end)
+{
+    for (const char *p = start; p != end; ++p) {
+       if (*p == '\n' || *p == '\f')
+           ind = 0;
+       else if (*p == '\t')
+           ind = next_tab(ind);
+       else if (*p == '\b')
+           --ind;
+       else
+           ++ind;
+    }
+    return ind;
+}
+
 static void
 search_stmt_newline(bool *force_nl)
 {
diff -r 44f6862390ac -r fba595142d03 usr.bin/indent/io.c
--- a/usr.bin/indent/io.c       Fri Nov 26 13:32:38 2021 +0000
+++ b/usr.bin/indent/io.c       Fri Nov 26 14:17:01 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: io.c,v 1.133 2021/11/25 21:59:40 rillig Exp $  */
+/*     $NetBSD: io.c,v 1.134 2021/11/26 14:17:01 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.133 2021/11/25 21:59:40 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.134 2021/11/26 14:17:01 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -684,19 +684,3 @@
     if (inhibit_formatting)
        output_range(inbuf.inp.s, inbuf.inp.e);
 }
-
-int
-ind_add(int ind, const char *start, const char *end)
-{
-    for (const char *p = start; p != end; ++p) {
-       if (*p == '\n' || *p == '\f')
-           ind = 0;
-       else if (*p == '\t')
-           ind = next_tab(ind);
-       else if (*p == '\b')
-           --ind;
-       else
-           ++ind;
-    }
-    return ind;
-}



Home | Main Index | Thread Index | Old Index