Module Name:    src
Committed By:   rillig
Date:           Sat Sep 12 11:21:16 UTC 2020

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

Log Message:
make(1): split ParseVErrorInternal into 2 functions


To generate a diff of this commit:
cvs rdiff -u -r1.290 -r1.291 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.290 src/usr.bin/make/parse.c:1.291
--- src/usr.bin/make/parse.c:1.290	Fri Sep 11 17:32:36 2020
+++ src/usr.bin/make/parse.c	Sat Sep 12 11:21:15 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.290 2020/09/11 17:32:36 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.291 2020/09/12 11:21:15 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: parse.c,v 1.290 2020/09/11 17:32:36 rillig Exp $";
+static char rcsid[] = "$NetBSD: parse.c,v 1.291 2020/09/12 11:21:15 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)parse.c	8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: parse.c,v 1.290 2020/09/11 17:32:36 rillig Exp $");
+__RCSID("$NetBSD: parse.c,v 1.291 2020/09/12 11:21:15 rillig Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -610,6 +610,43 @@ ParseFindKeyword(const char *str)
     return -1;
 }
 
+static void
+PrintLocation(FILE *f, const char *cfname, size_t clineno)
+{
+	char dirbuf[MAXPATHLEN+1];
+
+	(void)fprintf(f, "\"");
+	if (*cfname != '/' && strcmp(cfname, "(stdin)") != 0) {
+		char *cp, *cp2;
+		const char *dir, *fname;
+
+		/*
+		 * Nothing is more annoying than not knowing
+		 * which Makefile is the culprit; we try ${.PARSEDIR}
+		 * and apply realpath(3) if not absolute.
+		 */
+		dir = Var_Value(".PARSEDIR", VAR_GLOBAL, &cp);
+		if (dir == NULL)
+			dir = ".";
+		if (*dir != '/') {
+			dir = realpath(dir, dirbuf);
+		}
+		fname = Var_Value(".PARSEFILE", VAR_GLOBAL, &cp2);
+		if (fname == NULL) {
+			if ((fname = strrchr(cfname, '/')))
+				fname++;
+			else
+				fname = cfname;
+		}
+		(void)fprintf(f, "%s/%s", dir, fname);
+		bmake_free(cp2);
+		bmake_free(cp);
+	} else
+		(void)fprintf(f, "%s", cfname);
+
+	(void)fprintf(f, "\" line %d: ", (int)clineno);
+}
+
 /*-
  * ParseVErrorInternal  --
  *	Error message abort function for parsing. Prints out the context
@@ -628,42 +665,11 @@ ParseVErrorInternal(FILE *f, const char 
     const char *fmt, va_list ap)
 {
 	static Boolean fatal_warning_error_printed = FALSE;
-	char dirbuf[MAXPATHLEN+1];
 
 	(void)fprintf(f, "%s: ", progname);
 
-	if (cfname != NULL) {
-		(void)fprintf(f, "\"");
-		if (*cfname != '/' && strcmp(cfname, "(stdin)") != 0) {
-			char *cp, *cp2;
-			const char *dir, *fname;
-
-			/*
-			 * Nothing is more annoying than not knowing
-			 * which Makefile is the culprit; we try ${.PARSEDIR}
-			 * and apply realpath(3) if not absolute.
-			 */
-			dir = Var_Value(".PARSEDIR", VAR_GLOBAL, &cp);
-			if (dir == NULL)
-				dir = ".";
-			if (*dir != '/') {
-				dir = realpath(dir, dirbuf);
-			}
-			fname = Var_Value(".PARSEFILE", VAR_GLOBAL, &cp2);
-			if (fname == NULL) {
-				if ((fname = strrchr(cfname, '/')))
-					fname++;
-				else
-					fname = cfname;
-			}
-			(void)fprintf(f, "%s/%s", dir, fname);
-			bmake_free(cp2);
-			bmake_free(cp);
-		} else
-			(void)fprintf(f, "%s", cfname);
-
-		(void)fprintf(f, "\" line %d: ", (int)clineno);
-	}
+	if (cfname != NULL)
+		PrintLocation(f, cfname, clineno);
 	if (type == PARSE_WARNING)
 		(void)fprintf(f, "warning: ");
 	(void)vfprintf(f, fmt, ap);

Reply via email to