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): use enum for return values of Cond_Eva...



details:   https://anonhg.NetBSD.org/src/rev/cc5515682835
branches:  trunk
changeset: 936687:cc5515682835
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Aug 01 18:02:37 2020 +0000

description:
make(1): use enum for return values of Cond_Eval and friends

diffstat:

 usr.bin/make/cond.c    |  20 ++++++++------------
 usr.bin/make/make.h    |  10 ++++++----
 usr.bin/make/nonints.h |   6 +++---
 usr.bin/make/var.c     |  12 ++++++------
 4 files changed, 23 insertions(+), 25 deletions(-)

diffs (172 lines):

diff -r 041a5c050bed -r cc5515682835 usr.bin/make/cond.c
--- a/usr.bin/make/cond.c       Sat Aug 01 17:56:56 2020 +0000
+++ b/usr.bin/make/cond.c       Sat Aug 01 18:02:37 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cond.c,v 1.85 2020/08/01 14:47:49 rillig Exp $ */
+/*     $NetBSD: cond.c,v 1.86 2020/08/01 18:02:37 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -70,14 +70,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: cond.c,v 1.85 2020/08/01 14:47:49 rillig Exp $";
+static char rcsid[] = "$NetBSD: cond.c,v 1.86 2020/08/01 18:02:37 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)cond.c     8.2 (Berkeley) 1/2/94";
 #else
-__RCSID("$NetBSD: cond.c,v 1.85 2020/08/01 14:47:49 rillig Exp $");
+__RCSID("$NetBSD: cond.c,v 1.86 2020/08/01 18:02:37 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -158,7 +158,7 @@
 static Token CondT(Boolean);
 static Token CondF(Boolean);
 static Token CondE(Boolean);
-static int do_Cond_EvalExpression(Boolean *);
+static CondEvalResult do_Cond_EvalExpression(Boolean *);
 
 static const struct If {
     const char *form;        /* Form of if */
@@ -1147,7 +1147,7 @@
  *
  *-----------------------------------------------------------------------
  */
-int
+CondEvalResult
 Cond_EvalExpression(const struct If *info, char *line, Boolean *value, int eprint, Boolean strictLHS)
 {
     static const struct If *dflt_info;
@@ -1186,7 +1186,7 @@
     return rval;
 }
 
-static int
+static CondEvalResult
 do_Cond_EvalExpression(Boolean *value)
 {
 
@@ -1231,16 +1231,12 @@
  *     COND_SKIP       if should skip lines after the conditional
  *     COND_INVALID    if not a valid conditional.
  *
- * Side Effects:
- *     None.
- *
  * Note that the states IF_ACTIVE and ELSE_ACTIVE are only different in order
- * to detect splurious .else lines (as are SKIP_TO_ELSE and SKIP_TO_ENDIF)
+ * to detect spurious .else lines (as are SKIP_TO_ELSE and SKIP_TO_ENDIF),
  * otherwise .else could be treated as '.elif 1'.
- *
  *-----------------------------------------------------------------------
  */
-int
+CondEvalResult
 Cond_Eval(char *line)
 {
 #define            MAXIF      128      /* maximum depth of .if'ing */
diff -r 041a5c050bed -r cc5515682835 usr.bin/make/make.h
--- a/usr.bin/make/make.h       Sat Aug 01 17:56:56 2020 +0000
+++ b/usr.bin/make/make.h       Sat Aug 01 18:02:37 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: make.h,v 1.112 2020/07/31 20:22:10 sjg Exp $   */
+/*     $NetBSD: make.h,v 1.113 2020/08/01 18:02:37 rillig Exp $        */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -337,9 +337,11 @@
 /*
  * Values returned by Cond_Eval.
  */
-#define COND_PARSE     0       /* Parse the next lines */
-#define COND_SKIP      1       /* Skip the next lines */
-#define COND_INVALID   2       /* Not a conditional statement */
+typedef enum {
+    COND_PARSE,                        /* Parse the next lines */
+    COND_SKIP,                 /* Skip the next lines */
+    COND_INVALID               /* Not a conditional statement */
+} CondEvalResult;
 
 /*
  * Definitions for the "local" variables. Used only for clarity.
diff -r 041a5c050bed -r cc5515682835 usr.bin/make/nonints.h
--- a/usr.bin/make/nonints.h    Sat Aug 01 17:56:56 2020 +0000
+++ b/usr.bin/make/nonints.h    Sat Aug 01 18:02:37 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nonints.h,v 1.88 2020/08/01 09:25:36 rillig Exp $      */
+/*     $NetBSD: nonints.h,v 1.89 2020/08/01 18:02:37 rillig Exp $      */
 
 /*-
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -91,8 +91,8 @@
 
 /* cond.c */
 struct If;
-int Cond_EvalExpression(const struct If *, char *, Boolean *, int, Boolean);
-int Cond_Eval(char *);
+CondEvalResult Cond_EvalExpression(const struct If *, char *, Boolean *, int, Boolean);
+CondEvalResult Cond_Eval(char *);
 void Cond_restore_depth(unsigned int);
 unsigned int Cond_save_depth(void);
 
diff -r 041a5c050bed -r cc5515682835 usr.bin/make/var.c
--- a/usr.bin/make/var.c        Sat Aug 01 17:56:56 2020 +0000
+++ b/usr.bin/make/var.c        Sat Aug 01 18:02:37 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: var.c,v 1.383 2020/08/01 17:29:00 rillig Exp $ */
+/*     $NetBSD: var.c,v 1.384 2020/08/01 18:02:37 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.383 2020/08/01 17:29:00 rillig Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.384 2020/08/01 18:02:37 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)var.c      8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: var.c,v 1.383 2020/08/01 17:29:00 rillig Exp $");
+__RCSID("$NetBSD: var.c,v 1.384 2020/08/01 18:02:37 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -2701,7 +2701,7 @@
     return AMR_BAD;
 }
 
-/* :O or :Ox */
+/* :O or :Or or :Ox */
 static ApplyModifierResult
 ApplyModifier_Order(const char *mod, ApplyModifiersState *st)
 {
@@ -2726,10 +2726,10 @@
 ApplyModifier_IfElse(const char *mod, ApplyModifiersState *st)
 {
     Boolean value = FALSE;
-    int cond_rc = 0;
     VarEvalFlags then_eflags = st->eflags & ~VARE_WANTRES;
     VarEvalFlags else_eflags = st->eflags & ~VARE_WANTRES;
 
+    int cond_rc = COND_PARSE;  /* anything other than COND_INVALID */
     if (st->eflags & VARE_WANTRES) {
        cond_rc = Cond_EvalExpression(NULL, st->v->name, &value, 0, FALSE);
        if (cond_rc != COND_INVALID && value)
@@ -2815,7 +2815,7 @@
     char *sv_name = NULL;
     if (st->v->flags & VAR_JUNK) {
        /*
-        * We need to bmake_strdup() it incase ParseModifierPart() recurses.
+        * We need to bmake_strdup() it in case ParseModifierPart() recurses.
         */
        sv_name = st->v->name;
        st->v->name = bmake_strdup(st->v->name);



Home | Main Index | Thread Index | Old Index