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): clean up ParseMessage
details: https://anonhg.NetBSD.org/src/rev/487540fa03ec
branches: trunk
changeset: 941041:487540fa03ec
user: rillig <rillig%NetBSD.org@localhost>
date: Sat Oct 17 19:10:07 2020 +0000
description:
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.
diffstat:
usr.bin/make/parse.c | 48 ++++++++++++++++++------------------------------
1 files changed, 18 insertions(+), 30 deletions(-)
diffs (73 lines):
diff -r 70fc8121117b -r 487540fa03ec usr.bin/make/parse.c
--- a/usr.bin/make/parse.c Sat Oct 17 18:58:26 2020 +0000
+++ b/usr.bin/make/parse.c Sat Oct 17 19:10:07 2020 +0000
@@ -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 @@
* is malformed.
*/
static Boolean
-ParseMessage(char *line)
+ParseMessage(const char *directive)
{
- int mtype;
-
- 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);
-
- (void)Var_Subst(line, VAR_CMD, VARE_WANTRES, &line);
+ const char *p = directive;
+ int mtype = *p == 'i' ? PARSE_INFO :
+ *p == 'w' ? PARSE_WARNING : PARSE_FATAL;
+ char *arg;
+
+ while (ch_isalpha(*p))
+ p++;
+ if (!ch_isspace(*p))
+ return FALSE; /* missing argument */
+
+ 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);
}
Home |
Main Index |
Thread Index |
Old Index