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: split process_keyword_do_else into se...



details:   https://anonhg.NetBSD.org/src/rev/637e208a37d5
branches:  trunk
changeset: 1024034:637e208a37d5
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Oct 08 16:47:42 2021 +0000

description:
indent: split process_keyword_do_else into separate functions

No functional change.

diffstat:

 usr.bin/indent/indent.c |  54 +++++++++++++++++++++++++++---------------------
 1 files changed, 30 insertions(+), 24 deletions(-)

diffs (89 lines):

diff -r 72c21ea3ec51 -r 637e208a37d5 usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c   Fri Oct 08 16:20:33 2021 +0000
+++ b/usr.bin/indent/indent.c   Fri Oct 08 16:47:42 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.c,v 1.126 2021/10/08 16:20:33 rillig Exp $      */
+/*     $NetBSD: indent.c,v 1.127 2021/10/08 16:47:42 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.126 2021/10/08 16:20:33 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.127 2021/10/08 16:47:42 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -965,34 +965,37 @@
 }
 
 static void
-process_keyword_do_else(bool *force_nl, bool *last_else)
+process_keyword_do(bool *force_nl, bool *last_else)
 {
     ps.in_stmt = false;
 
-    if (*token.s == 'e') {
-       if (code.e != code.s && (!opt.cuddle_else || code.e[-1] != '}')) {
-           if (opt.verbose)
-               diag(0, "Line broken");
-           dump_line();        /* make sure this starts a line */
-           ps.want_blank = false;
-       }
+    if (code.e != code.s) {    /* make sure this starts a line */
+       if (opt.verbose)
+           diag(0, "Line broken");
+       dump_line();
+       ps.want_blank = false;
+    }
 
-       *force_nl = true;       /* following stuff must go onto new line */
-       *last_else = true;
-       parse(keyword_else);
+    *force_nl = true;          /* following stuff must go onto new line */
+    *last_else = false;
+    parse(keyword_do);
+}
 
-    } else {
-       if (code.e != code.s) { /* make sure this starts a line */
-           if (opt.verbose)
-               diag(0, "Line broken");
-           dump_line();
-           ps.want_blank = false;
-       }
+static void
+process_keyword_else(bool *force_nl, bool *last_else)
+{
+    ps.in_stmt = false;
 
-       *force_nl = true;       /* following stuff must go onto new line */
-       *last_else = false;
-       parse(keyword_do);
+    if (code.e != code.s && (!opt.cuddle_else || code.e[-1] != '}')) {
+       if (opt.verbose)
+           diag(0, "Line broken");
+       dump_line();            /* make sure this starts a line */
+       ps.want_blank = false;
     }
+
+    *force_nl = true;          /* following stuff must go onto new line */
+    *last_else = true;
+    parse(keyword_else);
 }
 
 static void
@@ -1378,7 +1381,10 @@
            goto copy_token;
 
        case keyword_do_else:
-           process_keyword_do_else(&force_nl, &last_else);
+           if (*token.s == 'd')
+               process_keyword_do(&force_nl, &last_else);
+           else
+               process_keyword_else(&force_nl, &last_else);
            goto copy_token;
 
        case type_def:



Home | Main Index | Thread Index | Old Index