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 inp_from_file from inp_read_line



details:   https://anonhg.NetBSD.org/src/rev/caad9af6a638
branches:  trunk
changeset: 1026487:caad9af6a638
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Nov 26 14:33:12 2021 +0000

description:
indent: extract inp_from_file from inp_read_line

No functional change.

diffstat:

 usr.bin/indent/io.c |  32 +++++++++++++++++++++-----------
 1 files changed, 21 insertions(+), 11 deletions(-)

diffs (60 lines):

diff -r 4b5fc6857533 -r caad9af6a638 usr.bin/indent/io.c
--- a/usr.bin/indent/io.c       Fri Nov 26 14:27:19 2021 +0000
+++ b/usr.bin/indent/io.c       Fri Nov 26 14:33:12 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: io.c,v 1.135 2021/11/26 14:27:19 rillig Exp $  */
+/*     $NetBSD: io.c,v 1.136 2021/11/26 14:33:12 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.135 2021/11/26 14:27:19 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.136 2021/11/26 14:33:12 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -282,6 +282,23 @@
     debug_inp(__func__);
 }
 
+/*
+ * After having read from save_com, continue with the rest of the input line
+ * before reading the next line from the input file.
+ */
+static bool
+inp_from_file(void)
+{
+    if (inbuf.saved_inp_s == NULL)
+       return false;
+
+    inbuf.inp.s = inbuf.saved_inp_s;
+    inbuf.inp.e = inbuf.saved_inp_e;
+    inbuf.saved_inp_s = inbuf.saved_inp_e = NULL;
+    debug_println("switched inp.s back to saved_inp_s");
+    return inbuf.inp.s < inbuf.inp.e;
+}
+
 void
 inp_comment_insert_lbrace(void)
 {
@@ -617,15 +634,8 @@
     int ch;
     FILE *f = input;
 
-    if (inbuf.saved_inp_s != NULL) {   /* there is a partly filled input buffer left */
-       inbuf.inp.s = inbuf.saved_inp_s;        /* do not read anything, just switch buffers */
-       inbuf.inp.e = inbuf.saved_inp_e;
-       inbuf.saved_inp_s = inbuf.saved_inp_e = NULL;
-       debug_println("switched inp.s back to saved_inp_s");
-       if (inbuf.inp.s < inbuf.inp.e)
-           return;             /* only return if there is really something in
-                                * this buffer */
-    }
+    if (inp_from_file())
+       return;
 
     for (p = inbuf.inp.buf;;) {
        if (p >= inbuf.inp.l) {



Home | Main Index | Thread Index | Old Index