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: if a file ends with indent off, don't...



details:   https://anonhg.NetBSD.org/src/rev/12d6666e95f4
branches:  trunk
changeset: 989901:12d6666e95f4
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue Oct 19 18:29:59 2021 +0000

description:
indent: if a file ends with indent off, don't add space-newline

diffstat:

 tests/usr.bin/indent/token_comment.c |   4 +---
 usr.bin/indent/indent.c              |   6 +++---
 usr.bin/indent/io.c                  |  14 +++++++-------
 3 files changed, 11 insertions(+), 13 deletions(-)

diffs (88 lines):

diff -r c51dd7ae245d -r 12d6666e95f4 tests/usr.bin/indent/token_comment.c
--- a/tests/usr.bin/indent/token_comment.c      Tue Oct 19 18:18:23 2021 +0000
+++ b/tests/usr.bin/indent/token_comment.c      Tue Oct 19 18:29:59 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: token_comment.c,v 1.3 2021/10/19 18:18:23 rillig Exp $ */
+/* $NetBSD: token_comment.c,v 1.4 2021/10/19 18:29:59 rillig Exp $ */
 /* $FreeBSD$ */
 
 /*
@@ -526,8 +526,6 @@
 }
 /* $ FIXME: Missing empty line. */
 /*INDENT OFF*/
- 
-/* $ FIXME: The line above has a trailing space. */
 #indent end
 
 /*
diff -r c51dd7ae245d -r 12d6666e95f4 usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c   Tue Oct 19 18:18:23 2021 +0000
+++ b/usr.bin/indent/indent.c   Tue Oct 19 18:29:59 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.c,v 1.138 2021/10/17 18:13:00 rillig Exp $      */
+/*     $NetBSD: indent.c,v 1.139 2021/10/19 18:29:59 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.138 2021/10/17 18:13:00 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.139 2021/10/19 18:29:59 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -274,7 +274,7 @@
 switch_buffer(void)
 {
     ps.search_brace = false;   /* stop looking for start of stmt */
-    saved_inp_s = inp.s;               /* save current input buffer */
+    saved_inp_s = inp.s;       /* save current input buffer */
     saved_inp_e = inp.e;
     inp.s = save_com;          /* fix so that subsequent calls to lexi will
                                 * take tokens out of save_com */
diff -r c51dd7ae245d -r 12d6666e95f4 usr.bin/indent/io.c
--- a/usr.bin/indent/io.c       Tue Oct 19 18:18:23 2021 +0000
+++ b/usr.bin/indent/io.c       Tue Oct 19 18:29:59 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: io.c,v 1.94 2021/10/11 19:04:47 rillig Exp $   */
+/*     $NetBSD: io.c,v 1.95 2021/10/19 18:29:59 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.94 2021/10/11 19:04:47 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.95 2021/10/19 18:29:59 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -427,8 +427,10 @@
        }
 
        if ((ch = getc(f)) == EOF) {
-           *p++ = ' ';
-           *p++ = '\n';
+           if (!inhibit_formatting) {
+               *p++ = ' ';
+               *p++ = '\n';
+           }
            had_eof = true;
            break;
        }
@@ -450,10 +452,8 @@
     }
 
     if (inhibit_formatting) {
-       p = inp.buf;
-       do {
+       for (p = inp.s; p < inp.e; p++)
            output_char(*p);
-       } while (*p++ != '\n');
     }
 }
 



Home | Main Index | Thread Index | Old Index