Module Name:    src
Committed By:   rillig
Date:           Fri Nov 26 14:17:01 UTC 2021

Modified Files:
        src/usr.bin/indent: indent.c io.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.232 -r1.233 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.133 -r1.134 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.c
diff -u src/usr.bin/indent/indent.c:1.232 src/usr.bin/indent/indent.c:1.233
--- src/usr.bin/indent/indent.c:1.232	Thu Nov 25 18:48:37 2021
+++ src/usr.bin/indent/indent.c	Fri Nov 26 14:17:01 2021
@@ -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 @@ static char sccsid[] = "@(#)indent.c	5.1
 
 #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 @@ diag(int level, const char *msg, ...)
     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)
 {

Index: src/usr.bin/indent/io.c
diff -u src/usr.bin/indent/io.c:1.133 src/usr.bin/indent/io.c:1.134
--- src/usr.bin/indent/io.c:1.133	Thu Nov 25 21:59:40 2021
+++ src/usr.bin/indent/io.c	Fri Nov 26 14:17:01 2021
@@ -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 @@ static char sccsid[] = "@(#)io.c	8.1 (Be
 
 #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 @@ inp_read_line(void)
     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;
-}

Reply via email to