Module Name:    src
Committed By:   rillig
Date:           Sat Aug  1 18:02:37 UTC 2020

Modified Files:
        src/usr.bin/make: cond.c make.h nonints.h var.c

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


To generate a diff of this commit:
cvs rdiff -u -r1.85 -r1.86 src/usr.bin/make/cond.c
cvs rdiff -u -r1.112 -r1.113 src/usr.bin/make/make.h
cvs rdiff -u -r1.88 -r1.89 src/usr.bin/make/nonints.h
cvs rdiff -u -r1.383 -r1.384 src/usr.bin/make/var.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/make/cond.c
diff -u src/usr.bin/make/cond.c:1.85 src/usr.bin/make/cond.c:1.86
--- src/usr.bin/make/cond.c:1.85	Sat Aug  1 14:47:49 2020
+++ src/usr.bin/make/cond.c	Sat Aug  1 18:02:37 2020
@@ -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 CondToken(Boolean);
 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 @@ CondE(Boolean doEval)
  *
  *-----------------------------------------------------------------------
  */
-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 @@ Cond_EvalExpression(const struct If *inf
     return rval;
 }
 
-static int
+static CondEvalResult
 do_Cond_EvalExpression(Boolean *value)
 {
 
@@ -1231,16 +1231,12 @@ do_Cond_EvalExpression(Boolean *value)
  *	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 */

Index: src/usr.bin/make/make.h
diff -u src/usr.bin/make/make.h:1.112 src/usr.bin/make/make.h:1.113
--- src/usr.bin/make/make.h:1.112	Fri Jul 31 20:22:10 2020
+++ src/usr.bin/make/make.h	Sat Aug  1 18:02:37 2020
@@ -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 @@ typedef struct GNode {
 /*
  * 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.

Index: src/usr.bin/make/nonints.h
diff -u src/usr.bin/make/nonints.h:1.88 src/usr.bin/make/nonints.h:1.89
--- src/usr.bin/make/nonints.h:1.88	Sat Aug  1 09:25:36 2020
+++ src/usr.bin/make/nonints.h	Sat Aug  1 18:02:37 2020
@@ -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 @@ int Compat_Make(void *, void *);
 
 /* 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);
 

Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.383 src/usr.bin/make/var.c:1.384
--- src/usr.bin/make/var.c:1.383	Sat Aug  1 17:29:00 2020
+++ src/usr.bin/make/var.c	Sat Aug  1 18:02:37 2020
@@ -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 @@ bad_modifier:
     return AMR_BAD;
 }
 
-/* :O or :Ox */
+/* :O or :Or or :Ox */
 static ApplyModifierResult
 ApplyModifier_Order(const char *mod, ApplyModifiersState *st)
 {
@@ -2726,10 +2726,10 @@ static ApplyModifierResult
 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 @@ ApplyModifier_Assign(const char *mod, Ap
     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);

Reply via email to