Module Name: src
Committed By: rillig
Date: Mon Aug 3 20:26:09 UTC 2020
Modified Files:
src/usr.bin/make: Makefile arch.c buf.c cond.c dir.c for.c main.c
meta.c parse.c str.c trace.c var.c
Log Message:
make(1): no declaration-after-statement anymore
NetBSD make is intended to be maximally portable, therefore it uses only
C89. This was not declared in the Makefile before.
There are still a few places in parse.c and metachar.c that use
end-of-line comments. These will be fixed in a follow-up commit.
To generate a diff of this commit:
cvs rdiff -u -r1.78 -r1.79 src/usr.bin/make/Makefile
cvs rdiff -u -r1.80 -r1.81 src/usr.bin/make/arch.c
cvs rdiff -u -r1.30 -r1.31 src/usr.bin/make/buf.c
cvs rdiff -u -r1.87 -r1.88 src/usr.bin/make/cond.c
cvs rdiff -u -r1.83 -r1.84 src/usr.bin/make/dir.c
cvs rdiff -u -r1.60 -r1.61 src/usr.bin/make/for.c
cvs rdiff -u -r1.295 -r1.296 src/usr.bin/make/main.c
cvs rdiff -u -r1.91 -r1.92 src/usr.bin/make/meta.c
cvs rdiff -u -r1.246 -r1.247 src/usr.bin/make/parse.c
cvs rdiff -u -r1.54 -r1.55 src/usr.bin/make/str.c
cvs rdiff -u -r1.14 -r1.15 src/usr.bin/make/trace.c
cvs rdiff -u -r1.411 -r1.412 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/Makefile
diff -u src/usr.bin/make/Makefile:1.78 src/usr.bin/make/Makefile:1.79
--- src/usr.bin/make/Makefile:1.78 Sat Aug 1 21:48:17 2020
+++ src/usr.bin/make/Makefile Mon Aug 3 20:26:09 2020
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.78 2020/08/01 21:48:17 rillig Exp $
+# $NetBSD: Makefile,v 1.79 2020/08/03 20:26:09 rillig Exp $
# @(#)Makefile 5.2 (Berkeley) 12/28/90
PROG= make
@@ -73,6 +73,8 @@ COPTS.main.c+= ${GCC_NO_FORMAT_TRUNCATIO
COPTS.meta.c+= ${GCC_NO_FORMAT_TRUNCATION}
COPTS.parse.c+= ${GCC_NO_FORMAT_TRUNCATION}
+COPTS+= -Wdeclaration-after-statement
+
# A simple unit-test driver to help catch regressions
test: .MAKE
cd ${.CURDIR}/unit-tests \
Index: src/usr.bin/make/arch.c
diff -u src/usr.bin/make/arch.c:1.80 src/usr.bin/make/arch.c:1.81
--- src/usr.bin/make/arch.c:1.80 Sat Aug 1 14:47:49 2020
+++ src/usr.bin/make/arch.c Mon Aug 3 20:26:09 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: arch.c,v 1.80 2020/08/01 14:47:49 rillig Exp $ */
+/* $NetBSD: arch.c,v 1.81 2020/08/03 20:26:09 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
*/
#ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: arch.c,v 1.80 2020/08/01 14:47:49 rillig Exp $";
+static char rcsid[] = "$NetBSD: arch.c,v 1.81 2020/08/03 20:26:09 rillig Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)arch.c 8.2 (Berkeley) 1/2/94";
#else
-__RCSID("$NetBSD: arch.c,v 1.80 2020/08/01 14:47:49 rillig Exp $");
+__RCSID("$NetBSD: arch.c,v 1.81 2020/08/03 20:26:09 rillig Exp $");
#endif
#endif /* not lint */
#endif
@@ -624,6 +624,8 @@ ArchStatMember(const char *archive, cons
*/
goto badarch;
} else {
+ char *nameend;
+
/*
* We need to advance the stream's pointer to the start of the
* next header. Files are padded with newlines to an even-byte
@@ -634,7 +636,7 @@ ArchStatMember(const char *archive, cons
size = (int)strtol(arh.ar_size, NULL, 10);
memcpy(memName, arh.ar_name, sizeof(arh.ar_name));
- char *nameend = memName + AR_MAX_NAME_LEN;
+ nameend = memName + AR_MAX_NAME_LEN;
while (*nameend == ' ') {
nameend--;
}
@@ -851,6 +853,7 @@ ArchFindMember(const char *archive, cons
int size; /* Size of archive member */
char magic[SARMAG];
size_t len, tlen;
+ const char * base;
arch = fopen(archive, mode);
if (arch == NULL) {
@@ -873,7 +876,7 @@ ArchFindMember(const char *archive, cons
* to point 'member' to the final component, if there is one, to make
* the comparisons easier...
*/
- const char *base = strrchr(member, '/');
+ base = strrchr(member, '/');
if (base != NULL) {
member = base + 1;
}
Index: src/usr.bin/make/buf.c
diff -u src/usr.bin/make/buf.c:1.30 src/usr.bin/make/buf.c:1.31
--- src/usr.bin/make/buf.c:1.30 Sat Aug 1 21:51:22 2020
+++ src/usr.bin/make/buf.c Mon Aug 3 20:26:09 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: buf.c,v 1.30 2020/08/01 21:51:22 rillig Exp $ */
+/* $NetBSD: buf.c,v 1.31 2020/08/03 20:26:09 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: buf.c,v 1.30 2020/08/01 21:51:22 rillig Exp $";
+static char rcsid[] = "$NetBSD: buf.c,v 1.31 2020/08/03 20:26:09 rillig Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)buf.c 8.1 (Berkeley) 6/6/93";
#else
-__RCSID("$NetBSD: buf.c,v 1.30 2020/08/01 21:51:22 rillig Exp $");
+__RCSID("$NetBSD: buf.c,v 1.31 2020/08/03 20:26:09 rillig Exp $");
#endif
#endif /* not lint */
#endif
@@ -107,13 +107,14 @@ void
Buf_AddBytesZ(Buffer *bp, const Byte *bytesPtr, size_t numBytes)
{
size_t count = bp->count;
+ Byte *ptr;
if (__predict_false(count + numBytes >= bp->size)) {
bp->size += max(bp->size, numBytes + 16);
bp->buffer = bmake_realloc(bp->buffer, bp->size);
}
- Byte *ptr = bp->buffer + count;
+ ptr = bp->buffer + count;
bp->count = count + numBytes;
memcpy(ptr, bytesPtr, numBytes);
ptr[numBytes] = '\0';
Index: src/usr.bin/make/cond.c
diff -u src/usr.bin/make/cond.c:1.87 src/usr.bin/make/cond.c:1.88
--- src/usr.bin/make/cond.c:1.87 Sat Aug 1 21:40:49 2020
+++ src/usr.bin/make/cond.c Mon Aug 3 20:26:09 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: cond.c,v 1.87 2020/08/01 21:40:49 rillig Exp $ */
+/* $NetBSD: cond.c,v 1.88 2020/08/03 20:26:09 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.87 2020/08/01 21:40:49 rillig Exp $";
+static char rcsid[] = "$NetBSD: cond.c,v 1.88 2020/08/03 20:26:09 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.87 2020/08/01 21:40:49 rillig Exp $");
+__RCSID("$NetBSD: cond.c,v 1.88 2020/08/03 20:26:09 rillig Exp $");
#endif
#endif /* not lint */
#endif
@@ -241,6 +241,7 @@ CondGetArg(Boolean doEval, char **linePt
Buffer buf;
int paren_depth;
char ch;
+ size_t argLen;
cp = *linePtr;
if (func != NULL)
@@ -300,7 +301,6 @@ CondGetArg(Boolean doEval, char **linePt
cp++;
}
- size_t argLen;
*argPtr = Buf_GetAllZ(&buf, &argLen);
Buf_Destroy(&buf, FALSE);
Index: src/usr.bin/make/dir.c
diff -u src/usr.bin/make/dir.c:1.83 src/usr.bin/make/dir.c:1.84
--- src/usr.bin/make/dir.c:1.83 Sat Aug 1 14:47:49 2020
+++ src/usr.bin/make/dir.c Mon Aug 3 20:26:09 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: dir.c,v 1.83 2020/08/01 14:47:49 rillig Exp $ */
+/* $NetBSD: dir.c,v 1.84 2020/08/03 20:26:09 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: dir.c,v 1.83 2020/08/01 14:47:49 rillig Exp $";
+static char rcsid[] = "$NetBSD: dir.c,v 1.84 2020/08/03 20:26:09 rillig Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)dir.c 8.2 (Berkeley) 1/2/94";
#else
-__RCSID("$NetBSD: dir.c,v 1.83 2020/08/01 14:47:49 rillig Exp $");
+__RCSID("$NetBSD: dir.c,v 1.84 2020/08/03 20:26:09 rillig Exp $");
#endif
#endif /* not lint */
#endif
@@ -733,6 +733,11 @@ DirExpandCurly(const char *word, const c
const char *middle = brace + 1;
const char *middle_end = closing_brace(middle);
size_t middle_len = (size_t)(middle_end - middle);
+ const char *prefix;
+ size_t prefix_len;
+ const char *suffix;
+ size_t suffix_len;
+ const char *piece;
if (DEBUG(DIR)) {
fprintf(debug_file, "%s: word=\"%s\" middle=\"%.*s\"\n",
@@ -744,14 +749,14 @@ DirExpandCurly(const char *word, const c
return;
}
- const char *prefix = word;
- size_t prefix_len = (size_t)(brace - prefix);
- const char *suffix = middle_end + 1;
- size_t suffix_len = strlen(suffix);
+ prefix = word;
+ prefix_len = (size_t)(brace - prefix);
+ suffix = middle_end + 1;
+ suffix_len = strlen(suffix);
/* Split the middle into pieces, separated by commas. */
- const char *piece = middle;
+ piece = middle;
while (piece < middle_end + 1) {
const char *piece_end = separator_comma(piece);
size_t piece_len = (size_t)(piece_end - piece);
Index: src/usr.bin/make/for.c
diff -u src/usr.bin/make/for.c:1.60 src/usr.bin/make/for.c:1.61
--- src/usr.bin/make/for.c:1.60 Sun Aug 2 08:10:36 2020
+++ src/usr.bin/make/for.c Mon Aug 3 20:26:09 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: for.c,v 1.60 2020/08/02 08:10:36 rillig Exp $ */
+/* $NetBSD: for.c,v 1.61 2020/08/03 20:26:09 rillig Exp $ */
/*
* Copyright (c) 1992, The Regents of the University of California.
@@ -30,14 +30,14 @@
*/
#ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: for.c,v 1.60 2020/08/02 08:10:36 rillig Exp $";
+static char rcsid[] = "$NetBSD: for.c,v 1.61 2020/08/03 20:26:09 rillig Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)for.c 8.1 (Berkeley) 6/6/93";
#else
-__RCSID("$NetBSD: for.c,v 1.60 2020/08/02 08:10:36 rillig Exp $");
+__RCSID("$NetBSD: for.c,v 1.61 2020/08/03 20:26:09 rillig Exp $");
#endif
#endif /* not lint */
#endif
@@ -316,6 +316,8 @@ static size_t
for_var_len(const char *var)
{
char ch, var_start, var_end;
+ int depth;
+ size_t len;
var_start = *var;
if (var_start == 0)
@@ -330,8 +332,7 @@ for_var_len(const char *var)
/* Single char variable */
return 1;
- int depth = 1;
- size_t len;
+ depth = 1;
for (len = 1; (ch = var[len++]) != 0;) {
if (ch == var_start)
depth++;
@@ -346,6 +347,8 @@ for_var_len(const char *var)
static void
for_substitute(Buffer *cmds, strlist_t *items, unsigned int item_no, char ech)
{
+ char ch;
+
const char *item = strlist_str(items, item_no);
/* If there were no escapes, or the only escape is the other variable
@@ -357,7 +360,6 @@ for_substitute(Buffer *cmds, strlist_t *
}
/* Escape ':', '$', '\\' and 'ech' - removed by :U processing */
- char ch;
while ((ch = *item++) != 0) {
if (ch == '$') {
size_t len = for_var_len(item);
@@ -384,6 +386,7 @@ For_Iterate(void *v_arg, size_t *ret_len
char *body_end;
char ch;
Buffer cmds;
+ size_t cmd_len;
if (arg->sub_next + strlist_num(&arg->vars) > strlist_num(&arg->items)) {
/* No more iterations */
@@ -406,7 +409,6 @@ For_Iterate(void *v_arg, size_t *ret_len
* to contrive a makefile where an unwanted substitution happens.
*/
- size_t cmd_len;
cmd_cp = Buf_GetAllZ(&arg->buf, &cmd_len);
body_end = cmd_cp + cmd_len;
Buf_InitZ(&cmds, cmd_len + 256);
Index: src/usr.bin/make/main.c
diff -u src/usr.bin/make/main.c:1.295 src/usr.bin/make/main.c:1.296
--- src/usr.bin/make/main.c:1.295 Sun Aug 2 08:06:35 2020
+++ src/usr.bin/make/main.c Mon Aug 3 20:26:09 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.295 2020/08/02 08:06:35 rillig Exp $ */
+/* $NetBSD: main.c,v 1.296 2020/08/03 20:26:09 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -69,7 +69,7 @@
*/
#ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: main.c,v 1.295 2020/08/02 08:06:35 rillig Exp $";
+static char rcsid[] = "$NetBSD: main.c,v 1.296 2020/08/03 20:26:09 rillig Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
@@ -81,7 +81,7 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 19
#if 0
static char sccsid[] = "@(#)main.c 8.3 (Berkeley) 3/19/94";
#else
-__RCSID("$NetBSD: main.c,v 1.295 2020/08/02 08:06:35 rillig Exp $");
+__RCSID("$NetBSD: main.c,v 1.296 2020/08/03 20:26:09 rillig Exp $");
#endif
#endif /* not lint */
#endif
@@ -696,6 +696,7 @@ Main_ParseArgLine(const char *line)
char *args; /* Space used by the args */
char *p1;
const char *argv0 = Var_Value(".MAKE", VAR_GLOBAL, &p1);
+ char *buf;
if (line == NULL)
return;
@@ -704,7 +705,7 @@ Main_ParseArgLine(const char *line)
if (!*line)
return;
- char *buf = str_concat(argv0, line, STR_ADDSPACE);
+ buf = str_concat(argv0, line, STR_ADDSPACE);
free(p1);
argv = brk_string(buf, &argc, TRUE, &args);
@@ -764,14 +765,17 @@ Main_SetVarObjdir(const char *var, const
{
char *path_freeIt;
const char *path = Var_Value(var, VAR_CMD, &path_freeIt);
+ const char *xpath;
+ char *xpath_freeIt;
+
if (path == NULL || path[0] == '\0') {
bmake_free(path_freeIt);
return FALSE;
}
/* expand variable substitutions */
- const char *xpath = path;
- char *xpath_freeIt = NULL;
+ xpath = path;
+ xpath_freeIt = NULL;
if (strchr(path, '$') != 0)
xpath = xpath_freeIt = Var_Subst(path, VAR_GLOBAL,
VARE_WANTRES);
@@ -1600,7 +1604,7 @@ Cmd_Exec(const char *cmd, const char **e
Buffer buf; /* buffer to store the result */
char *cp;
int savederr; /* saved errno */
-
+ ssize_t cc; /* bytes read, or -1 */
*errfmt = NULL;
@@ -1660,7 +1664,6 @@ Cmd_Exec(const char *cmd, const char **e
Buf_InitZ(&buf, 0);
/* XXX: split variable cc into 2 */
- ssize_t cc; /* bytes read, or -1 */
do {
char result[BUFSIZ];
cc = read(fds[0], result, sizeof(result));
@@ -2037,6 +2040,8 @@ void
PrintOnError(GNode *gn, const char *s)
{
static GNode *en = NULL;
+ const char *expr;
+ char *cp;
if (DEBUG(HASH)) {
Targ_Stats();
@@ -2062,8 +2067,8 @@ PrintOnError(GNode *gn, const char *s)
Var_Delete(".ERROR_CMD", VAR_GLOBAL);
Lst_ForEach(gn->commands, addErrorCMD, gn);
}
- const char *expr = "${MAKE_PRINT_VAR_ON_ERROR:@v@$v='${$v}'\n@}";
- char *cp = Var_Subst(expr, VAR_GLOBAL, VARE_WANTRES);
+ expr = "${MAKE_PRINT_VAR_ON_ERROR:@v@$v='${$v}'\n@}";
+ cp = Var_Subst(expr, VAR_GLOBAL, VARE_WANTRES);
if (cp) {
if (*cp)
printf("%s", cp);
@@ -2085,13 +2090,15 @@ void
Main_ExportMAKEFLAGS(Boolean first)
{
static int once = 1;
+ const char *expr;
+ char *s;
if (once != first)
return;
once = 0;
- const char *expr = "${.MAKEFLAGS} ${.MAKEOVERRIDES:O:u:@v@$v=${$v:Q}@}";
- char *s = Var_Subst(expr, VAR_CMD, VARE_WANTRES);
+ expr = "${.MAKEFLAGS} ${.MAKEOVERRIDES:O:u:@v@$v=${$v:Q}@}";
+ s = Var_Subst(expr, VAR_CMD, VARE_WANTRES);
if (s != NULL && s[0] != '\0') {
#ifdef POSIX
setenv("MAKEFLAGS", s, 1);
Index: src/usr.bin/make/meta.c
diff -u src/usr.bin/make/meta.c:1.91 src/usr.bin/make/meta.c:1.92
--- src/usr.bin/make/meta.c:1.91 Sat Aug 1 09:55:00 2020
+++ src/usr.bin/make/meta.c Mon Aug 3 20:26:09 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: meta.c,v 1.91 2020/08/01 09:55:00 rillig Exp $ */
+/* $NetBSD: meta.c,v 1.92 2020/08/03 20:26:09 rillig Exp $ */
/*
* Implement 'meta' mode.
@@ -1010,9 +1010,12 @@ meta_ignore(GNode *gn, const char *p)
}
if (metaIgnorePatterns) {
+ const char *expr;
+ char *pm;
+
Var_Set(".p.", p, gn);
- const char *expr = "${" MAKE_META_IGNORE_PATTERNS ":@m@${.p.:M$m}@}";
- char *pm = Var_Subst(expr, gn, VARE_WANTRES);
+ expr = "${" MAKE_META_IGNORE_PATTERNS ":@m@${.p.:M$m}@}";
+ pm = Var_Subst(expr, gn, VARE_WANTRES);
if (*pm) {
#ifdef DEBUG_META_MODE
if (DEBUG(META))
Index: src/usr.bin/make/parse.c
diff -u src/usr.bin/make/parse.c:1.246 src/usr.bin/make/parse.c:1.247
--- src/usr.bin/make/parse.c:1.246 Sat Aug 1 14:47:49 2020
+++ src/usr.bin/make/parse.c Mon Aug 3 20:26:09 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: parse.c,v 1.246 2020/08/01 14:47:49 rillig Exp $ */
+/* $NetBSD: parse.c,v 1.247 2020/08/03 20:26:09 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
*/
#ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: parse.c,v 1.246 2020/08/01 14:47:49 rillig Exp $";
+static char rcsid[] = "$NetBSD: parse.c,v 1.247 2020/08/03 20:26:09 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.246 2020/08/01 14:47:49 rillig Exp $");
+__RCSID("$NetBSD: parse.c,v 1.247 2020/08/03 20:26:09 rillig Exp $");
#endif
#endif /* not lint */
#endif
@@ -1291,9 +1291,10 @@ ParseDoDependency(char *line)
"Makefile appears to contain unresolved cvs/rcs/??? merge conflicts");
else if (lstart[0] == '.') {
const char *dirstart = lstart + 1;
+ const char *dirend;
while (isspace((unsigned char)*dirstart))
dirstart++;
- const char *dirend = dirstart;
+ dirend = dirstart;
while (isalnum((unsigned char)*dirend) || *dirend == '-')
dirend++;
Parse_Error(PARSE_FATAL, "Unknown directive \"%.*s\"",
@@ -2364,12 +2365,12 @@ ParseDoInclude(char *line)
static void
ParseSetIncludedFile(void)
{
- char *pf_freeIt;
- char *pd_freeIt;
+ const char *pf, *pd;
+ char *pf_freeIt, *pd_freeIt;
- const char *pf = Var_Value(".PARSEFILE", VAR_GLOBAL, &pf_freeIt);
+ pf = Var_Value(".PARSEFILE", VAR_GLOBAL, &pf_freeIt);
Var_Set(".INCLUDEDFROMFILE", pf, VAR_GLOBAL);
- const char *pd = Var_Value(".PARSEDIR", VAR_GLOBAL, &pd_freeIt);
+ pd = Var_Value(".PARSEDIR", VAR_GLOBAL, &pd_freeIt);
Var_Set(".INCLUDEDFROMDIR", pd, VAR_GLOBAL);
if (DEBUG(PARSE))
Index: src/usr.bin/make/str.c
diff -u src/usr.bin/make/str.c:1.54 src/usr.bin/make/str.c:1.55
--- src/usr.bin/make/str.c:1.54 Sat Aug 1 10:44:23 2020
+++ src/usr.bin/make/str.c Mon Aug 3 20:26:09 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: str.c,v 1.54 2020/08/01 10:44:23 rillig Exp $ */
+/* $NetBSD: str.c,v 1.55 2020/08/03 20:26:09 rillig Exp $ */
/*-
* Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
*/
#ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: str.c,v 1.54 2020/08/01 10:44:23 rillig Exp $";
+static char rcsid[] = "$NetBSD: str.c,v 1.55 2020/08/03 20:26:09 rillig Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)str.c 5.8 (Berkeley) 6/1/90";
#else
-__RCSID("$NetBSD: str.c,v 1.54 2020/08/01 10:44:23 rillig Exp $");
+__RCSID("$NetBSD: str.c,v 1.55 2020/08/03 20:26:09 rillig Exp $");
#endif
#endif /* not lint */
#endif
@@ -142,26 +142,35 @@ char **
brk_string(const char *str, int *out_words_len, Boolean expand,
char **out_words_buf)
{
+ size_t str_len;
+ char *words_buf;
+ int words_cap;
+ char **words;
+ int words_len;
+ char inquote;
+ char *word_start;
+ char *word_end;
+ const char *str_p;
+
/* skip leading space chars. */
for (; *str == ' ' || *str == '\t'; ++str)
continue;
/* words_buf holds the words, separated by '\0'. */
- size_t str_len = strlen(str);
- char *words_buf = bmake_malloc(strlen(str) + 1);
+ str_len = strlen(str);
+ words_buf = bmake_malloc(strlen(str) + 1);
- int words_cap = MAX((str_len / 5), 50);
- char **words = bmake_malloc((words_cap + 1) * sizeof(char *));
+ words_cap = MAX((str_len / 5), 50);
+ words = bmake_malloc((words_cap + 1) * sizeof(char *));
/*
* copy the string; at the same time, parse backslashes,
* quotes and build the word list.
*/
- int words_len = 0;
- char inquote = '\0';
- char *word_start = words_buf;
- char *word_end = words_buf;
- const char *str_p;
+ words_len = 0;
+ inquote = '\0';
+ word_start = words_buf;
+ word_end = words_buf;
for (str_p = str;; ++str_p) {
char ch = *str_p;
switch(ch) {
Index: src/usr.bin/make/trace.c
diff -u src/usr.bin/make/trace.c:1.14 src/usr.bin/make/trace.c:1.15
--- src/usr.bin/make/trace.c:1.14 Sat Aug 1 09:55:00 2020
+++ src/usr.bin/make/trace.c Mon Aug 3 20:26:09 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: trace.c,v 1.14 2020/08/01 09:55:00 rillig Exp $ */
+/* $NetBSD: trace.c,v 1.15 2020/08/03 20:26:09 rillig Exp $ */
/*-
* Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -31,11 +31,11 @@
#ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: trace.c,v 1.14 2020/08/01 09:55:00 rillig Exp $";
+static char rcsid[] = "$NetBSD: trace.c,v 1.15 2020/08/03 20:26:09 rillig Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: trace.c,v 1.14 2020/08/01 09:55:00 rillig Exp $");
+__RCSID("$NetBSD: trace.c,v 1.15 2020/08/03 20:26:09 rillig Exp $");
#endif /* not lint */
#endif
@@ -78,8 +78,8 @@ void
Trace_Init(const char *pathname)
{
if (pathname != NULL) {
- trpid = getpid();
char *dontFreeIt;
+ trpid = getpid();
trwd = Var_Value(".CURDIR", VAR_GLOBAL, &dontFreeIt);
trfile = fopen(pathname, "a");
Index: src/usr.bin/make/var.c
diff -u src/usr.bin/make/var.c:1.411 src/usr.bin/make/var.c:1.412
--- src/usr.bin/make/var.c:1.411 Mon Aug 3 16:45:23 2020
+++ src/usr.bin/make/var.c Mon Aug 3 20:26:09 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: var.c,v 1.411 2020/08/03 16:45:23 rillig Exp $ */
+/* $NetBSD: var.c,v 1.412 2020/08/03 20:26:09 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -69,14 +69,14 @@
*/
#ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: var.c,v 1.411 2020/08/03 16:45:23 rillig Exp $";
+static char rcsid[] = "$NetBSD: var.c,v 1.412 2020/08/03 20:26:09 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.411 2020/08/03 16:45:23 rillig Exp $");
+__RCSID("$NetBSD: var.c,v 1.412 2020/08/03 20:26:09 rillig Exp $");
#endif
#endif /* not lint */
#endif
@@ -288,6 +288,8 @@ typedef enum {
static Var *
VarFind(const char *name, GNode *ctxt, VarFindFlags flags)
{
+ Hash_Entry *var;
+
/*
* If the variable name begins with a '.', it could very well be one of
* the local ones. We check the name against all the local variables
@@ -336,7 +338,7 @@ VarFind(const char *name, GNode *ctxt, V
* look for it in VAR_CMD, VAR_GLOBAL and the environment, in that order,
* depending on the FIND_* flags in 'flags'
*/
- Hash_Entry *var = Hash_FindEntry(&ctxt->context, name);
+ var = Hash_FindEntry(&ctxt->context, name);
if (var == NULL && (flags & FIND_CMD) && ctxt != VAR_CMD)
var = Hash_FindEntry(&VAR_CMD->context, name);
@@ -356,9 +358,10 @@ VarFind(const char *name, GNode *ctxt, V
if ((env = getenv(name)) != NULL) {
Var *v = bmake_malloc(sizeof(Var));
+ size_t len;
v->name = bmake_strdup(name);
- size_t len = strlen(env);
+ len = strlen(env);
Buf_InitZ(&v->val, len + 1);
Buf_AddBytesZ(&v->val, env, len);
@@ -417,12 +420,14 @@ VarAdd(const char *name, const char *val
Var *v = bmake_malloc(sizeof(Var));
size_t len = val != NULL ? strlen(val) : 0;
+ Hash_Entry *h;
+
Buf_InitZ(&v->val, len + 1);
Buf_AddBytesZ(&v->val, val, len);
v->flags = 0;
- Hash_Entry *h = Hash_CreateEntry(&ctxt->context, name, NULL);
+ h = Hash_CreateEntry(&ctxt->context, name, NULL);
Hash_SetValue(h, v);
v->name = h->name;
VAR_DEBUG_IF(!(ctxt->flags & INTERNAL),
@@ -434,9 +439,11 @@ void
Var_Delete(const char *name, GNode *ctxt)
{
char *name_freeIt = NULL;
+ Hash_Entry *ln;
+
if (strchr(name, '$') != NULL)
name = name_freeIt = Var_Subst(name, VAR_GLOBAL, VARE_WANTRES);
- Hash_Entry *ln = Hash_FindEntry(&ctxt->context, name);
+ ln = Hash_FindEntry(&ctxt->context, name);
VAR_DEBUG("%s:delete %s%s\n",
ctxt->name, name, ln != NULL ? "" : " (not found)");
free(name_freeIt);
@@ -468,6 +475,8 @@ Var_Export1(const char *name, VarExportF
{
char tmp[BUFSIZ];
VarExportFlags parent = flags & VAR_EXPORT_PARENT;
+ Var *v;
+ char *val;
if (*name == '.')
return 0; /* skip internals */
@@ -487,15 +496,17 @@ Var_Export1(const char *name, VarExportF
}
}
- Var *v = VarFind(name, VAR_GLOBAL, 0);
+ v = VarFind(name, VAR_GLOBAL, 0);
if (v == NULL)
return 0;
if (!parent && (v->flags & VAR_EXPORTED) && !(v->flags & VAR_REEXPORT))
return 0; /* nothing to do */
- char *val = Buf_GetAllZ(&v->val, NULL);
+ val = Buf_GetAllZ(&v->val, NULL);
if (!(flags & VAR_EXPORT_LITERAL) && strchr(val, '$')) {
+ int n;
+
if (parent) {
/*
* Flag this as something we need to re-export.
@@ -512,7 +523,7 @@ Var_Export1(const char *name, VarExportF
*/
return 0;
}
- int n = snprintf(tmp, sizeof(tmp), "${%s}", name);
+ n = snprintf(tmp, sizeof(tmp), "${%s}", name);
if (n < (int)sizeof(tmp)) {
val = Var_Subst(tmp, VAR_GLOBAL, VARE_WANTRES);
setenv(name, val, 1);
@@ -546,6 +557,8 @@ Var_ExportVars_callback(void *entry, voi
void
Var_ExportVars(void)
{
+ char *val;
+
/*
* Several make's support this sort of mechanism for tracking
* recursion - but each uses a different name.
@@ -565,7 +578,7 @@ Var_ExportVars(void)
return;
}
- char *val = Var_Subst("${" MAKE_EXPORTED ":O:u}", VAR_GLOBAL, VARE_WANTRES);
+ val = Var_Subst("${" MAKE_EXPORTED ":O:u}", VAR_GLOBAL, VARE_WANTRES);
if (*val) {
char **av;
char *as;
@@ -588,12 +601,15 @@ Var_ExportVars(void)
void
Var_Export(char *str, int isExport)
{
+ VarExportFlags flags;
+ char *val;
+
if (isExport && (!str || !str[0])) {
var_exportedVars = VAR_EXPORTED_ALL; /* use with caution! */
return;
}
- VarExportFlags flags = 0;
+ flags = 0;
if (strncmp(str, "-env", 4) == 0) {
str += 4;
} else if (strncmp(str, "-literal", 8) == 0) {
@@ -603,7 +619,7 @@ Var_Export(char *str, int isExport)
flags |= VAR_EXPORT_PARENT;
}
- char *val = Var_Subst(str, VAR_GLOBAL, VARE_WANTRES);
+ val = Var_Subst(str, VAR_GLOBAL, VARE_WANTRES);
if (*val) {
char *as;
int ac;
@@ -656,11 +672,12 @@ Var_UnExport(char *str)
char *vlist;
char *cp;
int n;
+ Boolean unexport_env;
vlist = NULL;
str += strlen("unexport");
- Boolean unexport_env = strncmp(str, "-env", 4) == 0;
+ unexport_env = strncmp(str, "-env", 4) == 0;
if (unexport_env) {
char **newenv;
@@ -743,6 +760,7 @@ Var_Set_with_flags(const char *name, con
VarSet_Flags flags)
{
char *name_freeIt = NULL;
+ Var *v;
/*
* We only look for a variable in the given context since anything set
@@ -761,7 +779,6 @@ Var_Set_with_flags(const char *name, con
}
}
- Var *v;
if (ctxt == VAR_GLOBAL) {
v = VarFind(name, VAR_CMD, 0);
if (v != NULL) {
@@ -884,6 +901,7 @@ void
Var_Append(const char *name, const char *val, GNode *ctxt)
{
char *expanded_name = NULL;
+ Var *v;
if (strchr(name, '$') != NULL) {
expanded_name = Var_Subst(name, ctxt, VARE_WANTRES);
@@ -897,7 +915,7 @@ Var_Append(const char *name, const char
name = expanded_name;
}
- Var *v = VarFind(name, ctxt, ctxt == VAR_GLOBAL ? (FIND_CMD | FIND_ENV) : 0);
+ v = VarFind(name, ctxt, ctxt == VAR_GLOBAL ? (FIND_CMD | FIND_ENV) : 0);
if (v == NULL) {
Var_Set(name, val, ctxt);
@@ -909,6 +927,8 @@ Var_Append(const char *name, const char
Buf_GetAllZ(&v->val, NULL));
if (v->flags & VAR_FROM_ENV) {
+ Hash_Entry *h;
+
/*
* If the original variable came from the environment, we
* have to install it in the global context (we could place
@@ -916,7 +936,7 @@ Var_Append(const char *name, const char
* export other variables...)
*/
v->flags &= ~VAR_FROM_ENV;
- Hash_Entry *h = Hash_CreateEntry(&ctxt->context, name, NULL);
+ h = Hash_CreateEntry(&ctxt->context, name, NULL);
Hash_SetValue(h, v);
}
}
@@ -944,10 +964,12 @@ Boolean
Var_Exists(const char *name, GNode *ctxt)
{
char *name_freeIt = NULL;
+ Var *v;
+
if (strchr(name, '$') != NULL)
name = name_freeIt = Var_Subst(name, ctxt, VARE_WANTRES);
- Var *v = VarFind(name, ctxt, FIND_CMD | FIND_GLOBAL | FIND_ENV);
+ v = VarFind(name, ctxt, FIND_CMD | FIND_GLOBAL | FIND_ENV);
free(name_freeIt);
if (v == NULL)
return FALSE;
@@ -976,11 +998,13 @@ const char *
Var_Value(const char *name, GNode *ctxt, char **freeIt)
{
Var *v = VarFind(name, ctxt, FIND_ENV | FIND_GLOBAL | FIND_CMD);
+ char *p;
+
*freeIt = NULL;
if (v == NULL)
return NULL;
- char *p = Buf_GetAllZ(&v->val, NULL);
+ p = Buf_GetAllZ(&v->val, NULL);
if (VarFreeEnv(v, FALSE))
*freeIt = p;
return p;
@@ -1130,6 +1154,10 @@ Str_SYSVMatch(const char *word, const ch
{
const char *p = pattern;
const char *w = word;
+ const char *percent;
+ size_t w_len;
+ size_t p_len;
+ const char *w_tail;
*hasPercent = FALSE;
if (*p == '\0') { /* ${VAR:=suffix} */
@@ -1137,7 +1165,7 @@ Str_SYSVMatch(const char *word, const ch
return w;
}
- const char *percent = strchr(p, '%');
+ percent = strchr(p, '%');
if (percent != NULL) { /* ${VAR:...%...=...} */
*hasPercent = TRUE;
if (*w == '\0')
@@ -1158,12 +1186,12 @@ Str_SYSVMatch(const char *word, const ch
}
/* Test whether the tail matches */
- size_t w_len = strlen(w);
- size_t p_len = strlen(p);
+ w_len = strlen(w);
+ p_len = strlen(p);
if (w_len < p_len)
return NULL;
- const char *w_tail = w + w_len - p_len;
+ w_tail = w + w_len - p_len;
if (memcmp(p, w_tail, p_len) != 0)
return NULL;
@@ -1182,6 +1210,9 @@ static void
ModifyWord_SYSVSubst(const char *word, SepBuf *buf, void *data)
{
const ModifyWord_SYSVSubstArgs *args = data;
+ char *rhs_expanded;
+ const char *rhs;
+ const char *percent;
size_t match_len;
Boolean lhsPercent;
@@ -1194,10 +1225,10 @@ ModifyWord_SYSVSubst(const char *word, S
/* Append rhs to the buffer, substituting the first '%' with the
* match, but only if the lhs had a '%' as well. */
- char *rhs_expanded = Var_Subst(args->rhs, args->ctx, VARE_WANTRES);
+ rhs_expanded = Var_Subst(args->rhs, args->ctx, VARE_WANTRES);
- const char *rhs = rhs_expanded;
- const char *percent = strchr(rhs, '%');
+ rhs = rhs_expanded;
+ percent = strchr(rhs, '%');
if (percent != NULL && lhsPercent) {
/* Copy the prefix of the replacement pattern */
@@ -1231,6 +1262,7 @@ ModifyWord_Subst(const char *word, SepBu
size_t wordLen = strlen(word);
ModifyWord_SubstArgs *args = data;
const VarPatternFlags pflags = args->pflags;
+ const char *match;
if ((pflags & VARP_SUB_ONE) && (pflags & VARP_SUB_MATCHED))
goto nosub;
@@ -1255,10 +1287,12 @@ ModifyWord_Subst(const char *word, SepBu
}
if (args->pflags & VARP_ANCHOR_END) {
+ const char *start;
+
if (wordLen < args->lhsLen)
goto nosub;
- const char *start = word + (wordLen - args->lhsLen);
+ start = word + (wordLen - args->lhsLen);
if (memcmp(start, args->lhs, args->lhsLen) != 0)
goto nosub;
@@ -1269,7 +1303,6 @@ ModifyWord_Subst(const char *word, SepBu
}
/* unanchored */
- const char *match;
while ((match = Str_FindSubstring(word, args->lhs)) != NULL) {
SepBuf_AddBytesBetween(buf, word, match);
SepBuf_AddBytes(buf, args->rhs, args->rhsLen);
@@ -1396,12 +1429,15 @@ typedef struct {
static void
ModifyWord_Loop(const char *word, SepBuf *buf, void *data)
{
+ const ModifyWord_LoopArgs *args;
+ char *s;
+
if (word[0] == '\0')
return;
- const ModifyWord_LoopArgs *args = data;
+ args = data;
Var_Set_with_flags(args->tvar, word, args->ctx, VAR_NO_EXPORT);
- char *s = Var_Subst(args->str, args->ctx, args->eflags);
+ s = Var_Subst(args->str, args->ctx, args->eflags);
VAR_DEBUG("ModifyWord_Loop: in \"%s\", replace \"%s\" with \"%s\" "
"to \"%s\"\n",
@@ -1426,12 +1462,15 @@ static char *
VarSelectWords(Byte sep, Boolean oneBigWord, const char *str, int first,
int last)
{
- SepBuf buf;
- SepBuf_Init(&buf, sep);
-
char **av; /* word list */
char *as; /* word list memory */
int ac;
+ int start, end, step;
+ int i;
+
+ SepBuf buf;
+ SepBuf_Init(&buf, sep);
+
if (oneBigWord) {
/* fake what brk_string() would do if there were only one word */
ac = 1;
@@ -1456,7 +1495,6 @@ VarSelectWords(Byte sep, Boolean oneBigW
/*
* We avoid scanning more of the list than we need to.
*/
- int start, end, step;
if (first > last) {
start = MIN(ac, first) - 1;
end = MAX(0, last - 1);
@@ -1467,7 +1505,6 @@ VarSelectWords(Byte sep, Boolean oneBigW
step = 1;
}
- int i;
for (i = start; (step < 0) == (i >= end); i += step) {
SepBuf_AddStr(&buf, av[i]);
SepBuf_Sep(&buf);
@@ -1512,24 +1549,24 @@ static char *
ModifyWords(GNode *ctx, Byte sep, Boolean oneBigWord,
const char *str, ModifyWordsCallback modifyWord, void *data)
{
+ SepBuf result;
+ char **av; /* word list */
+ char *as; /* word list memory */
+ int ac;
+ int i;
+
if (oneBigWord) {
- SepBuf result;
SepBuf_Init(&result, sep);
modifyWord(str, &result, data);
return SepBuf_Destroy(&result, FALSE);
}
- SepBuf result;
SepBuf_Init(&result, sep);
- char **av; /* word list */
- char *as; /* word list memory */
- int ac;
av = brk_string(str, &ac, FALSE, &as);
VAR_DEBUG("ModifyWords: split \"%s\" into %d words\n", str, ac);
- int i;
for (i = 0; i < ac; i++) {
modifyWord(av[i], &result, data);
if (result.buf.count > 0)
@@ -1547,9 +1584,10 @@ static char *
WordList_JoinFree(char **av, int ac, char *as)
{
Buffer buf;
+ int i;
+
Buf_InitZ(&buf, 0);
- int i;
for (i = 0; i < ac; i++) {
if (i != 0)
Buf_AddByte(&buf, ' ');
@@ -1610,6 +1648,9 @@ ParseModifierPart(
* unescaped ampersands with subst->lhs. */
) {
Buffer buf;
+ const char *p;
+ char *rstr;
+
Buf_InitZ(&buf, 0);
/*
@@ -1618,8 +1659,10 @@ ParseModifierPart(
* backslashes to quote the delimiter, $, and \, but don't
* touch other backslashes.
*/
- const char *p = *pp;
+ p = *pp;
while (*p != '\0' && *p != delim) {
+ const char *varstart;
+
Boolean is_escaped = p[0] == '\\' && (
p[1] == delim || p[1] == '\\' || p[1] == '$' ||
(p[1] == '&' && subst != NULL));
@@ -1668,7 +1711,7 @@ ParseModifierPart(
* neither is the difference between parsing :D and :M documented.
* No code should ever depend on these details, but who knows. */
- const char *varstart = p; /* Nested variable, only parsed */
+ varstart = p; /* Nested variable, only parsed */
if (p[1] == PROPEN || p[1] == BROPEN) {
/*
* Find the end of this variable reference
@@ -1703,7 +1746,7 @@ ParseModifierPart(
if (out_length != NULL)
*out_length = Buf_Size(&buf);
- char *rstr = Buf_Destroy(&buf, FALSE);
+ rstr = Buf_Destroy(&buf, FALSE);
VAR_DEBUG("Modifier part: \"%s\"\n", rstr);
return rstr;
}
@@ -1761,6 +1804,9 @@ VarHash(const char *str)
uint32_t c2 = 0x2ad7eb25U;
size_t len2 = strlen(str);
+ char *buf;
+ size_t i;
+
size_t len;
for (len = len2; len; ) {
uint32_t k = 0;
@@ -1798,8 +1844,7 @@ VarHash(const char *str)
h *= 0xc2b2ae35;
h ^= h >> 16;
- char *buf = bmake_malloc(9);
- size_t i;
+ buf = bmake_malloc(9);
for (i = 0; i < 8; i++) {
buf[i] = hexdigits[h & 0x0f];
h >>= 4;
@@ -1904,11 +1949,13 @@ ModMatchEq(const char *mod, const char *
static ApplyModifierResult
ApplyModifier_Loop(const char **pp, ApplyModifiersState *st) {
ModifyWord_LoopArgs args;
+ char delim;
+ int prev_sep;
args.ctx = st->ctxt;
(*pp)++; /* Skip the first '@' */
- char delim = '@';
+ delim = '@';
args.tvar = ParseModifierPart(pp, delim, st->eflags & ~VARE_WANTRES,
st->ctxt, NULL, NULL, NULL);
if (args.tvar == NULL) {
@@ -1931,7 +1978,7 @@ ApplyModifier_Loop(const char **pp, Appl
}
args.eflags = st->eflags & (VARE_UNDEFERR | VARE_WANTRES);
- int prev_sep = st->sep;
+ prev_sep = st->sep;
st->sep = ' '; /* XXX: should be st->sep for consistency */
st->newVal = ModifyWords(st->ctxt, st->sep, st->oneBigWord, st->val,
ModifyWord_Loop, &args);
@@ -1946,6 +1993,9 @@ ApplyModifier_Loop(const char **pp, Appl
static ApplyModifierResult
ApplyModifier_Defined(const char **pp, ApplyModifiersState *st)
{
+ Buffer buf; /* Buffer for patterns */
+ const char *p;
+
VarEvalFlags neflags;
if (st->eflags & VARE_WANTRES) {
Boolean wantres;
@@ -1966,9 +2016,8 @@ ApplyModifier_Defined(const char **pp, A
* the delimiter (expand the variable substitution).
* The result is left in the Buffer buf.
*/
- Buffer buf; /* Buffer for patterns */
Buf_InitZ(&buf, 0);
- const char *p = *pp + 1;
+ p = *pp + 1;
while (*p != st->endc && *p != ':' && *p != '\0') {
if (*p == '\\' &&
(p[1] == ':' || p[1] == '$' || p[1] == st->endc || p[1] == '\\')) {
@@ -2009,11 +2058,12 @@ ApplyModifier_Defined(const char **pp, A
static ApplyModifierResult
ApplyModifier_Gmtime(const char **pp, ApplyModifiersState *st)
{
+ time_t utc;
+
const char *mod = *pp;
if (!ModMatchEq(mod, "gmtime", st->endc))
return AMR_UNKNOWN;
- time_t utc;
if (mod[6] == '=') {
char *ep;
utc = strtoul(mod + 7, &ep, 10);
@@ -2030,11 +2080,12 @@ ApplyModifier_Gmtime(const char **pp, Ap
static Boolean
ApplyModifier_Localtime(const char **pp, ApplyModifiersState *st)
{
+ time_t utc;
+
const char *mod = *pp;
if (!ModMatchEq(mod, "localtime", st->endc))
return AMR_UNKNOWN;
- time_t utc;
if (mod[9] == '=') {
char *ep;
utc = strtoul(mod + 10, &ep, 10);
@@ -2063,10 +2114,12 @@ ApplyModifier_Hash(const char **pp, Appl
static ApplyModifierResult
ApplyModifier_Path(const char **pp, ApplyModifiersState *st)
{
+ GNode *gn;
+
if (st->v->flags & VAR_JUNK)
st->v->flags |= VAR_KEEP;
- GNode *gn = Targ_FindNode(st->v->name, TARG_NOCREATE);
+ gn = Targ_FindNode(st->v->name, TARG_NOCREATE);
if (gn == NULL || gn->type & OP_NOPATH) {
st->newVal = NULL;
} else if (gn->path) {
@@ -2085,16 +2138,20 @@ ApplyModifier_Path(const char **pp, Appl
static ApplyModifierResult
ApplyModifier_Exclam(const char **pp, ApplyModifiersState *st)
{
+ char delim;
+ char *cmd;
+ const char *emsg;
+
(*pp)++;
- char delim = '!';
- char *cmd = ParseModifierPart(pp, delim, st->eflags, st->ctxt,
- NULL, NULL, NULL);
+ delim = '!';
+ cmd = ParseModifierPart(pp, delim, st->eflags, st->ctxt,
+ NULL, NULL, NULL);
if (cmd == NULL) {
st->missing_delim = delim;
return AMR_CLEANUP;
}
- const char *emsg = NULL;
+ emsg = NULL;
if (st->eflags & VARE_WANTRES)
st->newVal = Cmd_Exec(cmd, &emsg);
else
@@ -2114,11 +2171,14 @@ ApplyModifier_Exclam(const char **pp, Ap
static ApplyModifierResult
ApplyModifier_Range(const char **pp, ApplyModifiersState *st)
{
+ int n;
+ Buffer buf;
+ int i;
+
const char *mod = *pp;
if (!ModMatchEq(mod, "range", st->endc))
return AMR_UNKNOWN;
- int n;
if (mod[5] == '=') {
char *ep;
n = strtoul(mod + 6, &ep, 10);
@@ -2135,10 +2195,8 @@ ApplyModifier_Range(const char **pp, App
free(av);
}
- Buffer buf;
Buf_InitZ(&buf, 0);
- int i;
for (i = 0; i < n; i++) {
if (i != 0)
Buf_AddByte(&buf, ' ');
@@ -2156,6 +2214,10 @@ ApplyModifier_Match(const char **pp, App
const char *mod = *pp;
Boolean copy = FALSE; /* pattern should be, or has been, copied */
Boolean needSubst = FALSE;
+ const char *endpat;
+ char *pattern;
+ ModifyWordsCallback callback;
+
/*
* In the loop below, ignore ':' unless we are at (or back to) the
* original brace level.
@@ -2182,14 +2244,16 @@ ApplyModifier_Match(const char **pp, App
}
}
*pp = p;
- const char *endpat = p;
+ endpat = p;
- char *pattern;
if (copy) {
+ char *dst;
+ const char *src;
+
/* Compress the \:'s out of the pattern. */
pattern = bmake_malloc(endpat - (mod + 1) + 1);
- char *dst = pattern;
- const char *src = mod + 1;
+ dst = pattern;
+ src = mod + 1;
for (; src < endpat; src++, dst++) {
if (src[0] == '\\' && src + 1 < endpat &&
/* XXX: st->startc is missing here; see above */
@@ -2216,8 +2280,7 @@ ApplyModifier_Match(const char **pp, App
VAR_DEBUG("Pattern[%s] for [%s] is [%s]\n", st->v->name, st->val, pattern);
- ModifyWordsCallback callback = mod[0] == 'M'
- ? ModifyWord_Match : ModifyWord_NoMatch;
+ callback = mod[0] == 'M' ? ModifyWord_Match : ModifyWord_NoMatch;
st->newVal = ModifyWords(st->ctxt, st->sep, st->oneBigWord, st->val,
callback, pattern);
free(pattern);
@@ -2228,6 +2291,10 @@ ApplyModifier_Match(const char **pp, App
static ApplyModifierResult
ApplyModifier_Subst(const char **pp, ApplyModifiersState *st)
{
+ ModifyWord_SubstArgs args;
+ char *lhs, *rhs;
+ Boolean oneBigWord;
+
char delim = (*pp)[1];
if (delim == '\0') {
Error("Missing delimiter for :S modifier");
@@ -2237,7 +2304,6 @@ ApplyModifier_Subst(const char **pp, App
*pp += 2;
- ModifyWord_SubstArgs args;
args.pflags = 0;
/*
@@ -2249,23 +2315,23 @@ ApplyModifier_Subst(const char **pp, App
(*pp)++;
}
- char *lhs = ParseModifierPart(pp, delim, st->eflags, st->ctxt,
- &args.lhsLen, &args.pflags, NULL);
+ lhs = ParseModifierPart(pp, delim, st->eflags, st->ctxt,
+ &args.lhsLen, &args.pflags, NULL);
if (lhs == NULL) {
st->missing_delim = delim;
return AMR_CLEANUP;
}
args.lhs = lhs;
- char *rhs = ParseModifierPart(pp, delim, st->eflags, st->ctxt,
- &args.rhsLen, NULL, &args);
+ rhs = ParseModifierPart(pp, delim, st->eflags, st->ctxt,
+ &args.rhsLen, NULL, &args);
if (rhs == NULL) {
st->missing_delim = delim;
return AMR_CLEANUP;
}
args.rhs = rhs;
- Boolean oneBigWord = st->oneBigWord;
+ oneBigWord = st->oneBigWord;
for (;; (*pp)++) {
switch (**pp) {
case 'g':
@@ -2295,6 +2361,11 @@ ApplyModifier_Subst(const char **pp, App
static ApplyModifierResult
ApplyModifier_Regex(const char **pp, ApplyModifiersState *st)
{
+ char *re;
+ ModifyWord_SubstRegexArgs args;
+ Boolean oneBigWord;
+ int error;
+
char delim = (*pp)[1];
if (delim == '\0') {
Error("Missing delimiter for :C modifier");
@@ -2304,14 +2375,12 @@ ApplyModifier_Regex(const char **pp, App
*pp += 2;
- char *re = ParseModifierPart(pp, delim, st->eflags, st->ctxt,
- NULL, NULL, NULL);
+ re = ParseModifierPart(pp, delim, st->eflags, st->ctxt, NULL, NULL, NULL);
if (re == NULL) {
st->missing_delim = delim;
return AMR_CLEANUP;
}
- ModifyWord_SubstRegexArgs args;
args.replace = ParseModifierPart(pp, delim, st->eflags, st->ctxt,
NULL, NULL, NULL);
if (args.replace == NULL) {
@@ -2321,7 +2390,7 @@ ApplyModifier_Regex(const char **pp, App
}
args.pflags = 0;
- Boolean oneBigWord = st->oneBigWord;
+ oneBigWord = st->oneBigWord;
for (;; (*pp)++) {
switch (**pp) {
case 'g':
@@ -2337,7 +2406,7 @@ ApplyModifier_Regex(const char **pp, App
break;
}
- int error = regcomp(&args.re, re, REG_EXTENDED);
+ error = regcomp(&args.re, re, REG_EXTENDED);
free(re);
if (error) {
VarREError(error, &args.re, "Regex compilation error");
@@ -2403,12 +2472,14 @@ ApplyModifier_ToSep(const char **pp, App
if (!isdigit((unsigned char)sep[1]))
return AMR_BAD; /* ":ts<backslash><unrecognised>". */
- char *end;
get_numeric:
- st->sep = strtoul(xp, &end, base);
- if (*end != ':' && *end != st->endc)
- return AMR_BAD;
- *pp = end;
+ {
+ char *end;
+ st->sep = strtoul(xp, &end, base);
+ if (*end != ':' && *end != st->endc)
+ return AMR_BAD;
+ *pp = end;
+ }
break;
}
} else {
@@ -2443,16 +2514,16 @@ ApplyModifier_To(const char **pp, ApplyM
ModifyWord_Realpath, NULL);
*pp = mod + 2;
} else if (mod[1] == 'u') {
+ size_t i;
size_t len = strlen(st->val);
st->newVal = bmake_malloc(len + 1);
- size_t i;
for (i = 0; i < len + 1; i++)
st->newVal[i] = toupper((unsigned char)st->val[i]);
*pp = mod + 2;
} else if (mod[1] == 'l') {
+ size_t i;
size_t len = strlen(st->val);
st->newVal = bmake_malloc(len + 1);
- size_t i;
for (i = 0; i < len + 1; i++)
st->newVal[i] = tolower((unsigned char)st->val[i]);
*pp = mod + 2;
@@ -2471,10 +2542,15 @@ ApplyModifier_To(const char **pp, ApplyM
static ApplyModifierResult
ApplyModifier_Words(const char **pp, ApplyModifiersState *st)
{
+ char delim;
+ char *estr;
+ char *ep;
+ int first, last;
+
(*pp)++; /* skip the '[' */
- char delim = ']'; /* look for closing ']' */
- char *estr = ParseModifierPart(pp, delim, st->eflags, st->ctxt,
- NULL, NULL, NULL);
+ delim = ']'; /* look for closing ']' */
+ estr = ParseModifierPart(pp, delim, st->eflags, st->ctxt,
+ NULL, NULL, NULL);
if (estr == NULL) {
st->missing_delim = delim;
return AMR_CLEANUP;
@@ -2491,6 +2567,8 @@ ApplyModifier_Words(const char **pp, App
if (st->oneBigWord) {
st->newVal = bmake_strdup("1");
} else {
+ Buffer buf;
+
/* XXX: brk_string() is a rather expensive
* way of counting words. */
char *as;
@@ -2499,7 +2577,6 @@ ApplyModifier_Words(const char **pp, App
free(as);
free(av);
- Buffer buf;
Buf_InitZ(&buf, 4); /* 3 digits + '\0' */
Buf_AddInt(&buf, ac);
st->newVal = Buf_Destroy(&buf, FALSE);
@@ -2525,12 +2602,10 @@ ApplyModifier_Words(const char **pp, App
* We expect estr to contain a single integer for :[N], or two integers
* separated by ".." for :[start..end].
*/
- char *ep;
- int first = strtol(estr, &ep, 0);
+ first = strtol(estr, &ep, 0);
if (ep == estr) /* Found junk instead of a number */
goto bad_modifier;
- int last;
if (ep[0] == '\0') { /* Found only one integer in :[N] */
last = first;
} else if (ep[0] == '.' && ep[1] == '.' && ep[2] != '\0') {
@@ -2633,6 +2708,9 @@ ApplyModifier_Order(const char **pp, App
static ApplyModifierResult
ApplyModifier_IfElse(const char **pp, ApplyModifiersState *st)
{
+ char delim;
+ char *then_expr, *else_expr;
+
Boolean value = FALSE;
VarEvalFlags then_eflags = st->eflags & ~VARE_WANTRES;
VarEvalFlags else_eflags = st->eflags & ~VARE_WANTRES;
@@ -2647,17 +2725,17 @@ ApplyModifier_IfElse(const char **pp, Ap
}
(*pp)++; /* skip past the '?' */
- char delim = ':';
- char *then_expr = ParseModifierPart(pp, delim, then_eflags, st->ctxt,
- NULL, NULL, NULL);
+ delim = ':';
+ then_expr = ParseModifierPart(pp, delim, then_eflags, st->ctxt,
+ NULL, NULL, NULL);
if (then_expr == NULL) {
st->missing_delim = delim;
return AMR_CLEANUP;
}
delim = st->endc; /* BRCLOSE or PRCLOSE */
- char *else_expr = ParseModifierPart(pp, delim, else_eflags, st->ctxt,
- NULL, NULL, NULL);
+ else_expr = ParseModifierPart(pp, delim, else_eflags, st->ctxt,
+ NULL, NULL, NULL);
if (else_expr == NULL) {
st->missing_delim = delim;
return AMR_CLEANUP;
@@ -2706,6 +2784,11 @@ ApplyModifier_IfElse(const char **pp, Ap
static ApplyModifierResult
ApplyModifier_Assign(const char **pp, ApplyModifiersState *st)
{
+ GNode *v_ctxt;
+ char *sv_name;
+ char delim;
+ char *val;
+
const char *mod = *pp;
const char *op = mod + 1;
if (!(op[0] == '=' ||
@@ -2719,8 +2802,8 @@ ApplyModifier_Assign(const char **pp, Ap
return AMR_BAD;
}
- GNode *v_ctxt = st->ctxt; /* context where v belongs */
- char *sv_name = NULL;
+ v_ctxt = st->ctxt; /* context where v belongs */
+ sv_name = NULL;
if (st->v->flags & VAR_JUNK) {
/*
* We need to bmake_strdup() it in case ParseModifierPart() recurses.
@@ -2746,9 +2829,8 @@ ApplyModifier_Assign(const char **pp, Ap
break;
}
- char delim = st->startc == PROPEN ? PRCLOSE : BRCLOSE;
- char *val = ParseModifierPart(pp, delim, st->eflags, st->ctxt,
- NULL, NULL, NULL);
+ delim = st->startc == PROPEN ? PRCLOSE : BRCLOSE;
+ val = ParseModifierPart(pp, delim, st->eflags, st->ctxt, NULL, NULL, NULL);
if (st->v->flags & VAR_JUNK) {
/* restore original name */
free(st->v->name);
@@ -2817,6 +2899,9 @@ ApplyModifier_Remember(const char **pp,
static ApplyModifierResult
ApplyModifier_SysV(const char **pp, ApplyModifiersState *st)
{
+ char delim;
+ char *lhs, *rhs;
+
const char *mod = *pp;
Boolean eqFound = FALSE;
@@ -2841,18 +2926,16 @@ ApplyModifier_SysV(const char **pp, Appl
if (*next != st->endc || !eqFound)
return AMR_UNKNOWN;
- char delim = '=';
+ delim = '=';
*pp = mod;
- char *lhs = ParseModifierPart(pp, delim, st->eflags, st->ctxt,
- NULL, NULL, NULL);
+ lhs = ParseModifierPart(pp, delim, st->eflags, st->ctxt, NULL, NULL, NULL);
if (lhs == NULL) {
st->missing_delim = delim;
return AMR_CLEANUP;
}
delim = st->endc;
- char *rhs = ParseModifierPart(pp, delim, st->eflags, st->ctxt,
- NULL, NULL, NULL);
+ rhs = ParseModifierPart(pp, delim, st->eflags, st->ctxt, NULL, NULL, NULL);
if (rhs == NULL) {
st->missing_delim = delim;
return AMR_CLEANUP;
@@ -2953,16 +3036,18 @@ ApplyModifiers(
VarEvalFlags const eflags,
void ** const freePtr /* free this after using the return value */
) {
- assert(startc == '(' || startc == '{' || startc == '\0');
- assert(endc == ')' || endc == '}' || startc == '\0');
-
ApplyModifiersState st = {
startc, endc, v, ctxt, eflags,
val, NULL, '\0', ' ', FALSE
};
-
- const char *p = *pp;
+ const char *p;
const char *mod;
+ ApplyModifierResult res;
+
+ assert(startc == '(' || startc == '{' || startc == '\0');
+ assert(endc == ')' || endc == '}' || startc == '\0');
+
+ p = *pp;
while (*p != '\0' && *p != endc) {
if (*p == '$') {
@@ -3013,7 +3098,7 @@ ApplyModifiers(
apply_mods:
VAR_DEBUG( "Applying[%s] :%c to \"%s\"\n", st.v->name, *p, st.val);
st.newVal = var_Error; /* default value, in case of errors */
- ApplyModifierResult res = AMR_BAD; /* just a safe fallback */
+ res = AMR_BAD; /* just a safe fallback */
mod = p;
switch (*mod) {
case ':':
@@ -3292,14 +3377,18 @@ Var_Parse(const char * const str, GNode
* expanding it in a non-local context. This
* is done to support dynamic sources. The
* result is just the invocation, unaltered */
+ const char *extramodifiers;
+ Var *v;
+ char *nstr;
*freePtr = NULL;
- const char *extramodifiers = NULL; /* extra modifiers to apply first */
+ extramodifiers = NULL; /* extra modifiers to apply first */
dynamic = FALSE;
- Var *v; /* Variable in invocation */
startc = str[1];
if (startc != PROPEN && startc != BROPEN) {
+ char name[2];
+
/*
* If it's not bounded by braces of some sort, life is much simpler.
* We just need to check for the first character and return the
@@ -3311,8 +3400,9 @@ Var_Parse(const char * const str, GNode
*lengthPtr = 1;
return var_Error;
}
- char name[] = { startc, '\0' };
+ name[0] = startc;
+ name[1] = '\0';
v = VarFind(name, ctxt, FIND_ENV | FIND_GLOBAL | FIND_CMD);
if (v == NULL) {
*lengthPtr = 2;
@@ -3344,15 +3434,19 @@ Var_Parse(const char * const str, GNode
tstr = str + 1;
}
} else {
+ Buffer namebuf; /* Holds the variable name */
+ int depth;
+ size_t namelen;
+ char *varname;
+
endc = startc == PROPEN ? PRCLOSE : BRCLOSE;
- Buffer namebuf; /* Holds the variable name */
Buf_InitZ(&namebuf, 0);
/*
* Skip to the end character or a colon, whichever comes first.
*/
- int depth = 1;
+ depth = 1;
for (tstr = str + 2; *tstr != '\0'; tstr++) {
/* Track depth so we can spot parse errors. */
if (*tstr == startc)
@@ -3392,8 +3486,7 @@ Var_Parse(const char * const str, GNode
return var_Error;
}
- size_t namelen;
- char *varname = Buf_GetAllZ(&namebuf, &namelen);
+ varname = Buf_GetAllZ(&namebuf, &namelen);
/*
* At this point, varname points into newly allocated memory from
@@ -3478,7 +3571,7 @@ Var_Parse(const char * const str, GNode
* been dynamically-allocated, so it will need freeing when we
* return.
*/
- char *nstr = Buf_GetAllZ(&v->val, NULL);
+ nstr = Buf_GetAllZ(&v->val, NULL);
if (strchr(nstr, '$') != NULL && (eflags & VARE_WANTRES) != 0) {
nstr = Var_Subst(nstr, ctxt, eflags);
*freePtr = nstr;
@@ -3572,14 +3665,15 @@ char *
Var_Subst(const char *str, GNode *ctxt, VarEvalFlags eflags)
{
Buffer buf; /* Buffer for forming things */
- Buf_InitZ(&buf, 0);
+ Boolean trailingBslash;
/* Set true if an error has already been reported,
* to prevent a plethora of messages when recursing */
static Boolean errorReported;
- errorReported = FALSE;
- Boolean trailingBslash = FALSE; /* variable ends in \ */
+ Buf_InitZ(&buf, 0);
+ errorReported = FALSE;
+ trailingBslash = FALSE; /* variable ends in \ */
while (*str) {
if (*str == '\n' && trailingBslash)
@@ -3641,9 +3735,11 @@ Var_Subst(const char *str, GNode *ctxt,
str += 1;
}
} else {
+ size_t val_len;
+
str += length;
- size_t val_len = strlen(val);
+ val_len = strlen(val);
Buf_AddBytesZ(&buf, val, val_len);
trailingBslash = val_len > 0 && val[val_len - 1] == '\\';
}