Module Name:    src
Committed By:   rillig
Date:           Sat Oct 17 19:10:07 UTC 2020

Modified Files:
        src/usr.bin/make: parse.c

Log Message:
make(1): clean up ParseMessage

Since there is no code path that would lead to the "invalid syntax"
message, it has been removed.

The switch statement for choosing the log level was overly bloated.


To generate a diff of this commit:
cvs rdiff -u -r1.376 -r1.377 src/usr.bin/make/parse.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/parse.c
diff -u src/usr.bin/make/parse.c:1.376 src/usr.bin/make/parse.c:1.377
--- src/usr.bin/make/parse.c:1.376	Sat Oct 17 18:58:26 2020
+++ src/usr.bin/make/parse.c	Sat Oct 17 19:10:07 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.376 2020/10/17 18:58:26 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.377 2020/10/17 19:10:07 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -131,7 +131,7 @@
 #include "pathnames.h"
 
 /*	"@(#)parse.c	8.3 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: parse.c,v 1.376 2020/10/17 18:58:26 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.377 2020/10/17 19:10:07 rillig Exp $");
 
 /* types and constants */
 
@@ -726,38 +726,26 @@ Parse_Error(int type, const char *fmt, .
  * is malformed.
  */
 static Boolean
-ParseMessage(char *line)
+ParseMessage(const char *directive)
 {
-    int mtype;
+    const char *p = directive;
+    int mtype = *p == 'i' ? PARSE_INFO :
+		*p == 'w' ? PARSE_WARNING : PARSE_FATAL;
+    char *arg;
 
-    switch (*line) {
-    case 'i':
-	mtype = PARSE_INFO;
-	break;
-    case 'w':
-	mtype = PARSE_WARNING;
-	break;
-    case 'e':
-	mtype = PARSE_FATAL;
-	break;
-    default:
-	Parse_Error(PARSE_WARNING, "invalid syntax: \".%s\"", line);
-	return FALSE;
-    }
-
-    while (ch_isalpha(*line))
-	line++;
-    if (!ch_isspace(*line))
-	return FALSE;			/* not for us */
-    pp_skip_whitespace(&line);
+    while (ch_isalpha(*p))
+	p++;
+    if (!ch_isspace(*p))
+	return FALSE;		/* missing argument */
 
-    (void)Var_Subst(line, VAR_CMD, VARE_WANTRES, &line);
+    cpp_skip_whitespace(&p);
+    (void)Var_Subst(p, VAR_CMD, VARE_WANTRES, &arg);
     /* TODO: handle errors */
-    Parse_Error(mtype, "%s", line);
-    free(line);
+
+    Parse_Error(mtype, "%s", arg);
+    free(arg);
 
     if (mtype == PARSE_FATAL) {
-	/* Terminate almost immediately. */
 	PrintOnError(NULL, NULL);
 	exit(1);
     }

Reply via email to