Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/make make(1): make structure of the code in Cond_Eva...



details:   https://anonhg.NetBSD.org/src/rev/db005d20f17d
branches:  trunk
changeset: 979129:db005d20f17d
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Dec 14 21:35:21 2020 +0000

description:
make(1): make structure of the code in Cond_EvalLine clearer

diffstat:

 usr.bin/make/cond.c |  52 +++++++++++++++++++++++++++++-----------------------
 1 files changed, 29 insertions(+), 23 deletions(-)

diffs (83 lines):

diff -r f554eebfbf1b -r db005d20f17d usr.bin/make/cond.c
--- a/usr.bin/make/cond.c       Mon Dec 14 21:02:25 2020 +0000
+++ b/usr.bin/make/cond.c       Mon Dec 14 21:35:21 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cond.c,v 1.223 2020/12/14 20:39:35 rillig Exp $        */
+/*     $NetBSD: cond.c,v 1.224 2020/12/14 21:35:21 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -94,7 +94,7 @@
 #include "dir.h"
 
 /*     "@(#)cond.c     8.2 (Berkeley) 1/2/94"  */
-MAKE_RCSID("$NetBSD: cond.c,v 1.223 2020/12/14 20:39:35 rillig Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.224 2020/12/14 21:35:21 rillig Exp $");
 
 /*
  * The parsing of conditional expressions is based on this grammar:
@@ -1087,6 +1087,13 @@
        return CondEvalExpression(NULL, cond, out_value, FALSE, FALSE);
 }
 
+static Boolean
+IsEndif(const char *p)
+{
+       return p[0] == 'e' && p[1] == 'n' && p[2] == 'd' &&
+              p[3] == 'i' && p[4] == 'f' && !ch_isalpha(p[5]);
+}
+
 /* Evaluate the conditional directive in the line, which is one of:
  *
  *     .if <cond>
@@ -1154,30 +1161,29 @@
        p++;                    /* skip the leading '.' */
        cpp_skip_hspace(&p);
 
+       if (IsEndif(p)) {       /* It is an '.endif'. */
+               /* TODO: check for extraneous <cond> */
+
+               if (cond_depth == cond_min_depth) {
+                       Parse_Error(PARSE_FATAL, "if-less endif");
+                       return COND_PARSE;
+               }
+
+               /* Return state for previous conditional */
+               cond_depth--;
+               return cond_states[cond_depth] & IFS_ACTIVE
+                   ? COND_PARSE : COND_SKIP;
+       }
+
        /* Parse the name of the directive, such as 'if', 'elif', 'endif'. */
        if (p[0] == 'e') {
                if (p[1] != 'l') {
-                       if (!is_token(p + 1, "ndif", 4)) {
-                               /*
-                                * Unknown directive.  It might still be a
-                                * transformation rule like '.elisp.scm',
-                                * therefore no error message here.
-                                */
-                               return COND_INVALID;
-                       }
-
-                       /* It is an '.endif'. */
-                       /* TODO: check for extraneous <cond> */
-
-                       if (cond_depth == cond_min_depth) {
-                               Parse_Error(PARSE_FATAL, "if-less endif");
-                               return COND_PARSE;
-                       }
-
-                       /* Return state for previous conditional */
-                       cond_depth--;
-                       return cond_states[cond_depth] & IFS_ACTIVE
-                              ? COND_PARSE : COND_SKIP;
+                       /*
+                        * Unknown directive.  It might still be a
+                        * transformation rule like '.elisp.scm',
+                        * therefore no error message here.
+                        */
+                       return COND_INVALID;
                }
 
                /* Quite likely this is 'else' or 'elif' */



Home | Main Index | Thread Index | Old Index