make(1): format the source code consistently, at least per file

Some files use 4 spaces per indentation level, others use 8.  At least
for the few files from this commit, they use a consistent style
throughout each file now.

In Cond_Eval, the #define has changed into an enum since the identifiers
need not be visible to the C preprocessor.
This commit is contained in:
rillig 2020-08-09 19:51:02 +00:00
parent d02a9c330e
commit 173c978875
5 changed files with 400 additions and 399 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: buf.c,v 1.33 2020/08/09 18:52:03 rillig Exp $ */
/* $NetBSD: buf.c,v 1.34 2020/08/09 19:51:02 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.33 2020/08/09 18:52:03 rillig Exp $";
static char rcsid[] = "$NetBSD: buf.c,v 1.34 2020/08/09 19:51:02 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.33 2020/08/09 18:52:03 rillig Exp $");
__RCSID("$NetBSD: buf.c,v 1.34 2020/08/09 19:51:02 rillig Exp $");
#endif
#endif /* not lint */
#endif
@ -144,8 +144,8 @@ Buf_AddInt(Buffer *bp, int n)
* add enough slop to cope with a '-' sign and a trailing '\0'.
*/
enum {
bits = sizeof(int) * CHAR_BIT,
buf_size = 1 + (bits + 2) / 3 + 1
bits = sizeof(int) * CHAR_BIT,
buf_size = 1 + (bits + 2) / 3 + 1
};
char buf[buf_size];
@ -209,7 +209,7 @@ Buf_Destroy(Buffer *buf, Boolean freeData)
}
#ifndef BUF_COMPACT_LIMIT
# define BUF_COMPACT_LIMIT 128 /* worthwhile saving */
# define BUF_COMPACT_LIMIT 128 /* worthwhile saving */
#endif
/* Reset the buffer and return its data.

View File

@ -1,4 +1,4 @@
/* $NetBSD: cond.c,v 1.92 2020/08/08 18:54:04 rillig Exp $ */
/* $NetBSD: cond.c,v 1.93 2020/08/09 19:51:02 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.92 2020/08/08 18:54:04 rillig Exp $";
static char rcsid[] = "$NetBSD: cond.c,v 1.93 2020/08/09 19:51:02 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.92 2020/08/08 18:54:04 rillig Exp $");
__RCSID("$NetBSD: cond.c,v 1.93 2020/08/09 19:51:02 rillig Exp $");
#endif
#endif /* not lint */
#endif
@ -93,7 +93,7 @@ __RCSID("$NetBSD: cond.c,v 1.92 2020/08/08 18:54:04 rillig Exp $");
#include <assert.h>
#include <ctype.h>
#include <errno.h> /* For strtoul() error checking */
#include <errno.h>
#include "make.h"
#include "hash.h"
@ -148,13 +148,13 @@ typedef enum {
static Token CondE(Boolean);
static CondEvalResult do_Cond_EvalExpression(Boolean *);
static const struct If *if_info; /* Info for current statement */
static const char *condExpr; /* The expression to parse */
static Token condPushBack=TOK_NONE; /* Single push-back token used in
static const struct If *if_info; /* Info for current statement */
static const char *condExpr; /* The expression to parse */
static Token condPushBack = TOK_NONE; /* Single push-back token used in
* parsing */
static unsigned int cond_depth = 0; /* current .if nesting level */
static unsigned int cond_min_depth = 0; /* depth at makefile open */
static unsigned int cond_depth = 0; /* current .if nesting level */
static unsigned int cond_min_depth = 0; /* depth at makefile open */
/*
* Indicate when we should be strict about lhs of comparisons.
@ -168,7 +168,7 @@ static Boolean lhsStrict;
static int
istoken(const char *str, const char *tok, size_t len)
{
return strncmp(str, tok, len) == 0 && !isalpha((unsigned char)str[len]);
return strncmp(str, tok, len) == 0 && !isalpha((unsigned char)str[len]);
}
/* Push back the most recent token read. We only need one level of
@ -191,11 +191,11 @@ static int
CondGetArg(Boolean doEval, const char **linePtr, char **argPtr,
const char *func)
{
const char *cp;
Buffer buf;
int paren_depth;
char ch;
size_t argLen;
const char *cp;
Buffer buf;
int paren_depth;
char ch;
size_t argLen;
cp = *linePtr;
if (func != NULL)
@ -237,8 +237,8 @@ CondGetArg(Boolean doEval, const char **linePtr, char **argPtr,
* variable, so we don't do it too. Nor do we return an error,
* though perhaps we should...
*/
int len;
void *freeIt;
int len;
void *freeIt;
VarEvalFlags eflags = VARE_UNDEFERR | (doEval ? VARE_WANTRES : 0);
const char *cp2 = Var_Parse(cp, VAR_CMD, eflags, &len, &freeIt);
Buf_AddStr(&buf, cp2);
@ -248,9 +248,8 @@ CondGetArg(Boolean doEval, const char **linePtr, char **argPtr,
}
if (ch == '(')
paren_depth++;
else
if (ch == ')' && --paren_depth < 0)
break;
else if (ch == ')' && --paren_depth < 0)
break;
Buf_AddByte(&buf, *cp);
cp++;
}
@ -264,7 +263,7 @@ CondGetArg(Boolean doEval, const char **linePtr, char **argPtr,
if (func != NULL && *cp++ != ')') {
Parse_Error(PARSE_WARNING, "Missing closing parenthesis for %s()",
func);
func);
return 0;
}
@ -302,12 +301,12 @@ static Boolean
CondDoExists(int argLen MAKE_ATTR_UNUSED, const char *arg)
{
Boolean result;
char *path;
char *path;
path = Dir_FindFile(arg, dirSearchPath);
if (DEBUG(COND)) {
fprintf(debug_file, "exists(%s) result is \"%s\"\n",
arg, path ? path : "");
arg, path ? path : "");
}
if (path != NULL) {
result = TRUE;
@ -322,7 +321,7 @@ CondDoExists(int argLen MAKE_ATTR_UNUSED, const char *arg)
static Boolean
CondDoTarget(int argLen MAKE_ATTR_UNUSED, const char *arg)
{
GNode *gn;
GNode *gn;
gn = Targ_FindNode(arg, TARG_NOCREATE);
return gn != NULL && !OP_NOP(gn->type);
@ -333,7 +332,7 @@ CondDoTarget(int argLen MAKE_ATTR_UNUSED, const char *arg)
static Boolean
CondDoCommands(int argLen MAKE_ATTR_UNUSED, const char *arg)
{
GNode *gn;
GNode *gn;
gn = Targ_FindNode(arg, TARG_NOCREATE);
return gn != NULL && !OP_NOP(gn->type) && !Lst_IsEmpty(gn->commands);
@ -395,7 +394,7 @@ CondGetString(Boolean doEval, Boolean *quoted, void **freeIt, Boolean strictLHS)
Buffer buf;
const char *cp;
const char *str;
int len;
int len;
int qt;
const char *start;
@ -457,7 +456,7 @@ CondGetString(Boolean doEval, Boolean *quoted, void **freeIt, Boolean strictLHS)
*/
if ((condExpr == start + len) &&
(*condExpr == '\0' ||
isspace((unsigned char) *condExpr) ||
isspace((unsigned char)*condExpr) ||
strchr("!=><)", *condExpr))) {
goto cleanup;
}
@ -471,12 +470,12 @@ CondGetString(Boolean doEval, Boolean *quoted, void **freeIt, Boolean strictLHS)
free(*freeIt);
*freeIt = NULL;
}
str = NULL; /* not finished yet */
condExpr--; /* don't skip over next char */
str = NULL; /* not finished yet */
condExpr--; /* don't skip over next char */
break;
default:
if (strictLHS && !qt && *start != '$' &&
!isdigit((unsigned char) *start)) {
!isdigit((unsigned char)*start)) {
/* lhs must be quoted, a variable reference or number */
if (*freeIt) {
free(*freeIt);
@ -489,26 +488,26 @@ CondGetString(Boolean doEval, Boolean *quoted, void **freeIt, Boolean strictLHS)
break;
}
}
got_str:
got_str:
*freeIt = Buf_GetAll(&buf, NULL);
str = *freeIt;
cleanup:
cleanup:
Buf_Destroy(&buf, FALSE);
return str;
}
static const struct If {
const char *form; /* Form of if */
int formlen; /* Length of form */
Boolean doNot; /* TRUE if default function should be negated */
Boolean (*defProc)(int, const char *); /* Default function to apply */
const char *form; /* Form of if */
int formlen; /* Length of form */
Boolean doNot; /* TRUE if default function should be negated */
Boolean (*defProc)(int, const char *); /* Default function to apply */
} ifs[] = {
{ "def", 3, FALSE, CondDoDefined },
{ "ndef", 4, TRUE, CondDoDefined },
{ "make", 4, FALSE, CondDoMake },
{ "nmake", 5, TRUE, CondDoMake },
{ "", 0, FALSE, CondDoDefined },
{ NULL, 0, FALSE, NULL }
{ "def", 3, FALSE, CondDoDefined },
{ "ndef", 4, TRUE, CondDoDefined },
{ "make", 4, FALSE, CondDoMake },
{ "nmake", 5, TRUE, CondDoMake },
{ "", 0, FALSE, CondDoDefined },
{ NULL, 0, FALSE, NULL }
};
/*-
@ -520,15 +519,15 @@ static const struct If {
static Token
compare_expression(Boolean doEval)
{
Token t;
const char *lhs;
const char *rhs;
const char *op;
void *lhsFree;
void *rhsFree;
Token t;
const char *lhs;
const char *rhs;
const char *op;
void *lhsFree;
void *rhsFree;
Boolean lhsQuoted;
Boolean rhsQuoted;
double left, right;
double left, right;
t = TOK_ERROR;
rhs = NULL;
@ -546,7 +545,7 @@ compare_expression(Boolean doEval)
/*
* Skip whitespace to get to the operator
*/
while (isspace((unsigned char) *condExpr))
while (isspace((unsigned char)*condExpr))
condExpr++;
/*
@ -556,39 +555,39 @@ compare_expression(Boolean doEval)
*/
op = condExpr;
switch (*condExpr) {
case '!':
case '=':
case '<':
case '>':
if (condExpr[1] == '=') {
condExpr += 2;
} else {
condExpr += 1;
}
break;
default:
if (!doEval) {
t = TOK_FALSE;
goto done;
}
/* For .ifxxx "..." check for non-empty string. */
if (lhsQuoted) {
t = lhs[0] != 0;
goto done;
}
/* For .ifxxx <number> compare against zero */
if (CondCvtArg(lhs, &left)) {
t = left != 0.0;
goto done;
}
/* For .if ${...} check for non-empty string (defProc is ifdef). */
if (if_info->form[0] == 0) {
t = lhs[0] != 0;
goto done;
}
/* Otherwise action default test ... */
t = if_info->defProc(strlen(lhs), lhs) != if_info->doNot;
case '!':
case '=':
case '<':
case '>':
if (condExpr[1] == '=') {
condExpr += 2;
} else {
condExpr += 1;
}
break;
default:
if (!doEval) {
t = TOK_FALSE;
goto done;
}
/* For .ifxxx "..." check for non-empty string. */
if (lhsQuoted) {
t = lhs[0] != 0;
goto done;
}
/* For .ifxxx <number> compare against zero */
if (CondCvtArg(lhs, &left)) {
t = left != 0.0;
goto done;
}
/* For .if ${...} check for non-empty string (defProc is ifdef). */
if (if_info->form[0] == 0) {
t = lhs[0] != 0;
goto done;
}
/* Otherwise action default test ... */
t = if_info->defProc(strlen(lhs), lhs) != if_info->doNot;
goto done;
}
while (isspace((unsigned char)*condExpr))
@ -610,16 +609,16 @@ compare_expression(Boolean doEval)
}
if (rhsQuoted || lhsQuoted) {
do_string_compare:
do_string_compare:
if (((*op != '!') && (*op != '=')) || (op[1] != '=')) {
Parse_Error(PARSE_WARNING,
"String comparison operator should be either == or !=");
"String comparison operator should be either == or !=");
goto done;
}
if (DEBUG(COND)) {
fprintf(debug_file, "lhs = \"%s\", rhs = \"%s\", op = %.2s\n",
lhs, rhs, op);
lhs, rhs, op);
}
/*
* Null-terminate rhs and perform the comparison.
@ -641,9 +640,9 @@ do_string_compare:
if (DEBUG(COND)) {
fprintf(debug_file, "left = %f, right = %f, op = %.2s\n", left,
right, op);
right, op);
}
switch(op[0]) {
switch (op[0]) {
case '!':
if (op[1] != '=') {
Parse_Error(PARSE_WARNING,
@ -691,15 +690,16 @@ get_mpt_arg(Boolean doEval, const char **linePtr, char **argPtr,
* Use Var_Parse to parse the spec in parens and return
* TOK_TRUE if the resulting string is empty.
*/
int length;
void *freeIt;
int length;
void *freeIt;
const char *val;
const char *cp = *linePtr;
/* We do all the work here and return the result as the length */
*argPtr = NULL;
val = Var_Parse(cp - 1, VAR_CMD, doEval ? VARE_WANTRES : 0, &length, &freeIt);
val = Var_Parse(cp - 1, VAR_CMD, doEval ? VARE_WANTRES : 0, &length,
&freeIt);
/*
* Advance *linePtr to beyond the closing ). Note that
* we subtract one because 'length' is calculated from 'cp - 1'.
@ -734,23 +734,23 @@ static Token
compare_function(Boolean doEval)
{
static const struct fn_def {
const char *fn_name;
int fn_name_len;
int (*fn_getarg)(Boolean, const char **, char **, const char *);
Boolean (*fn_proc)(int, const char *);
const char *fn_name;
int fn_name_len;
int (*fn_getarg)(Boolean, const char **, char **, const char *);
Boolean (*fn_proc)(int, const char *);
} fn_defs[] = {
{ "defined", 7, CondGetArg, CondDoDefined },
{ "make", 4, CondGetArg, CondDoMake },
{ "exists", 6, CondGetArg, CondDoExists },
{ "empty", 5, get_mpt_arg, CondDoEmpty },
{ "target", 6, CondGetArg, CondDoTarget },
{ "commands", 8, CondGetArg, CondDoCommands },
{ NULL, 0, NULL, NULL },
{ "defined", 7, CondGetArg, CondDoDefined },
{ "make", 4, CondGetArg, CondDoMake },
{ "exists", 6, CondGetArg, CondDoExists },
{ "empty", 5, get_mpt_arg, CondDoEmpty },
{ "target", 6, CondGetArg, CondDoTarget },
{ "commands", 8, CondGetArg, CondDoCommands },
{ NULL, 0, NULL, NULL },
};
const struct fn_def *fn_def;
Token t;
char *arg = NULL;
int arglen;
Token t;
char *arg = NULL;
int arglen;
const char *cp = condExpr;
const char *cp1;
@ -884,7 +884,7 @@ CondToken(Boolean doEval)
static Token
CondT(Boolean doEval)
{
Token t;
Token t;
t = CondToken(doEval);
@ -932,7 +932,7 @@ CondT(Boolean doEval)
static Token
CondF(Boolean doEval)
{
Token l, o;
Token l, o;
l = CondT(doEval);
if (l != TOK_ERROR) {
@ -978,7 +978,7 @@ CondF(Boolean doEval)
static Token
CondE(Boolean doEval)
{
Token l, o;
Token l, o;
l = CondF(doEval);
if (l != TOK_ERROR) {
@ -1051,7 +1051,8 @@ do_Cond_EvalExpression(Boolean *value)
*-----------------------------------------------------------------------
*/
CondEvalResult
Cond_EvalExpression(const struct If *info, char *line, Boolean *value, int eprint, Boolean strictLHS)
Cond_EvalExpression(const struct If *info, char *line, Boolean *value,
int eprint, Boolean strictLHS)
{
static const struct If *dflt_info;
const struct If *sv_if_info = if_info;
@ -1066,7 +1067,7 @@ Cond_EvalExpression(const struct If *info, char *line, Boolean *value, int eprin
if (info == NULL && (info = dflt_info) == NULL) {
/* Scan for the entry for .if - it can't be first */
for (info = ifs; ; info++)
for (info = ifs;; info++)
if (info->form[0] == 0)
break;
dflt_info = info;
@ -1117,23 +1118,23 @@ Cond_EvalExpression(const struct If *info, char *line, Boolean *value, int eprin
CondEvalResult
Cond_Eval(char *line)
{
#define MAXIF 128 /* maximum depth of .if'ing */
#define MAXIF_BUMP 32 /* how much to grow by */
enum { MAXIF = 128 }; /* maximum depth of .if'ing */
enum { MAXIF_BUMP = 32 }; /* how much to grow by */
enum if_states {
IF_ACTIVE, /* .if or .elif part active */
ELSE_ACTIVE, /* .else part active */
SEARCH_FOR_ELIF, /* searching for .elif/else to execute */
SKIP_TO_ELSE, /* has been true, but not seen '.else' */
SKIP_TO_ELSE, /* has been true, but not seen '.else' */
SKIP_TO_ENDIF /* nothing else to execute */
};
static enum if_states *cond_state = NULL;
static unsigned int max_if_depth = MAXIF;
const struct If *ifp;
Boolean isElif;
Boolean value;
int level; /* Level at which to report errors. */
enum if_states state;
Boolean isElif;
Boolean value;
int level; /* Level at which to report errors. */
enum if_states state;
level = PARSE_FATAL;
if (!cond_state) {
@ -1156,7 +1157,8 @@ Cond_Eval(char *line)
}
/* Return state for previous conditional */
cond_depth--;
return cond_state[cond_depth] <= ELSE_ACTIVE ? COND_PARSE : COND_SKIP;
return cond_state[cond_depth] <= ELSE_ACTIVE
? COND_PARSE : COND_SKIP;
}
/* Quite likely this is 'else' or 'elif' */
@ -1200,7 +1202,7 @@ Cond_Eval(char *line)
* function is, etc. -- by looking in the table of valid "ifs"
*/
line += 2;
for (ifp = ifs; ; ifp++) {
for (ifp = ifs;; ifp++) {
if (ifp->form == NULL)
return COND_INVALID;
if (istoken(ifp->form, line, ifp->formlen)) {
@ -1236,8 +1238,8 @@ Cond_Eval(char *line)
* can need more than the default.
*/
max_if_depth += MAXIF_BUMP;
cond_state = bmake_realloc(cond_state, max_if_depth *
sizeof(*cond_state));
cond_state = bmake_realloc(cond_state,
max_if_depth * sizeof(*cond_state));
}
state = cond_state[cond_depth];
cond_depth++;

View File

@ -1,4 +1,4 @@
/* $NetBSD: dir.c,v 1.84 2020/08/03 20:26:09 rillig Exp $ */
/* $NetBSD: dir.c,v 1.85 2020/08/09 19:51:02 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.84 2020/08/03 20:26:09 rillig Exp $";
static char rcsid[] = "$NetBSD: dir.c,v 1.85 2020/08/09 19:51:02 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.84 2020/08/03 20:26:09 rillig Exp $");
__RCSID("$NetBSD: dir.c,v 1.85 2020/08/09 19:51:02 rillig Exp $");
#endif
#endif /* not lint */
#endif
@ -217,34 +217,34 @@ __RCSID("$NetBSD: dir.c,v 1.84 2020/08/03 20:26:09 rillig Exp $");
* in a cache for when Dir_MTime was actually called.
*/
Lst dirSearchPath; /* main search path */
Lst dirSearchPath; /* main search path */
static Lst openDirectories; /* the list of all open directories */
static Lst openDirectories; /* the list of all open directories */
/*
* Variables for gathering statistics on the efficiency of the hashing
* mechanism.
*/
static int hits, /* Found in directory cache */
misses, /* Sad, but not evil misses */
nearmisses, /* Found under search path */
bigmisses; /* Sought by itself */
static int hits; /* Found in directory cache */
static int misses; /* Sad, but not evil misses */
static int nearmisses; /* Found under search path */
static int bigmisses; /* Sought by itself */
static Path *dot; /* contents of current directory */
static Path *cur; /* contents of current directory, if not dot */
static Path *dotLast; /* a fake path entry indicating we need to
* look for . last */
static Hash_Table mtimes; /* Results of doing a last-resort stat in
* Dir_FindFile -- if we have to go to the
* system to find the file, we might as well
* have its mtime on record. XXX: If this is done
* way early, there's a chance other rules will
* have already updated the file, in which case
* we'll update it again. Generally, there won't
* be two rules to update a single file, so this
* should be ok, but... */
static Path *dot; /* contents of current directory */
static Path *cur; /* contents of current directory, if not dot */
static Path *dotLast; /* a fake path entry indicating we need to
* look for . last */
static Hash_Table lmtimes; /* same as mtimes but for lstat */
/* Results of doing a last-resort stat in Dir_FindFile -- if we have to go to
* the system to find the file, we might as well have its mtime on record.
*
* XXX: If this is done way early, there's a chance other rules will have
* already updated the file, in which case we'll update it again. Generally,
* there won't be two rules to update a single file, so this should be ok,
* but... */
static Hash_Table mtimes;
static Hash_Table lmtimes; /* same as mtimes but for lstat */
static int DirFindName(const void *, const void *);
static int DirMatchFiles(const char *, Path *, Lst);
@ -263,9 +263,9 @@ static char *DirLookupAbs(Path *, const char *, const char *);
* mtime and mode are all we care about.
*/
struct cache_st {
time_t lmtime; /* lstat */
time_t mtime; /* stat */
mode_t mode;
time_t lmtime; /* lstat */
time_t mtime; /* stat */
mode_t mode;
};
/* minimize changes below */
@ -304,7 +304,7 @@ cached_stats(Hash_Table *htp, const char *pathname, struct stat *st, int flags)
return -1;
if (st->st_mtime == 0)
st->st_mtime = 1; /* avoid confusion with missing file */
st->st_mtime = 1; /* avoid confusion with missing file */
if (!entry)
entry = Hash_CreateEntry(htp, pathname, NULL);
@ -321,7 +321,7 @@ cached_stats(Hash_Table *htp, const char *pathname, struct stat *st, int flags)
cst->mode = st->st_mode;
if (DEBUG(DIR)) {
fprintf(debug_file, " Caching %s for %s\n",
Targ_FmtTime(st->st_mtime), pathname);
Targ_FmtTime(st->st_mtime), pathname);
}
return 0;
@ -432,7 +432,7 @@ Dir_InitDot(void)
* to make sure it's not destroyed.
*/
dot->refCount += 1;
Dir_SetPATH(); /* initialize */
Dir_SetPATH(); /* initialize */
}
/*-
@ -475,9 +475,9 @@ Dir_End(void)
void
Dir_SetPATH(void)
{
LstNode ln; /* a list element */
LstNode ln; /* a list element */
Path *p;
Boolean hasLastDot = FALSE; /* true we should search dot last */
Boolean hasLastDot = FALSE; /* true we should search dot last */
Var_Delete(".PATH", VAR_GLOBAL);
@ -567,27 +567,27 @@ Dir_HasWildcards(char *name)
int wild = 0, brace = 0, bracket = 0;
for (cp = name; *cp; cp++) {
switch(*cp) {
switch (*cp) {
case '{':
brace++;
wild = 1;
break;
brace++;
wild = 1;
break;
case '}':
brace--;
break;
brace--;
break;
case '[':
bracket++;
wild = 1;
break;
bracket++;
wild = 1;
break;
case ']':
bracket--;
break;
bracket--;
break;
case '?':
case '*':
wild = 1;
break;
wild = 1;
break;
default:
break;
break;
}
}
return wild && bracket == 0 && brace == 0;
@ -618,9 +618,9 @@ Dir_HasWildcards(char *name)
static int
DirMatchFiles(const char *pattern, Path *p, Lst expansions)
{
Hash_Search search; /* Index into the directory's table */
Hash_Entry *entry; /* Current entry in the table */
Boolean isDot; /* TRUE if the directory being searched is . */
Hash_Search search; /* Index into the directory's table */
Hash_Entry *entry; /* Current entry in the table */
Boolean isDot; /* TRUE if the directory being searched is . */
isDot = (*p->name == '.' && p->name[1] == '\0');
@ -679,7 +679,7 @@ static Boolean
contains_wildcard(const char *p)
{
for (; *p != '\0'; p++) {
switch(*p) {
switch (*p) {
case '*':
case '?':
case '{':
@ -805,8 +805,8 @@ DirExpandCurly(const char *word, const char *brace, Lst path, Lst expansions)
static void
DirExpandInt(const char *word, Lst path, Lst expansions)
{
LstNode ln; /* Current node */
Path *p; /* Directory in the node */
LstNode ln; /* Current node */
Path *p; /* Directory in the node */
if (Lst_Open(path) == SUCCESS) {
while ((ln = Lst_Next(path)) != NULL) {
@ -863,7 +863,7 @@ DirPrintWord(void *word, void *dummy MAKE_ATTR_UNUSED)
void
Dir_Expand(const char *word, Lst path, Lst expansions)
{
const char *cp;
const char *cp;
if (DEBUG(DIR)) {
fprintf(debug_file, "Expanding \"%s\"... ", word);
@ -894,7 +894,7 @@ Dir_Expand(const char *word, Lst path, Lst expansions)
/*
* Back up to the start of the component
*/
char *dirpath;
char *dirpath;
while (cp > word && *cp != '/') {
cp--;
@ -922,7 +922,7 @@ Dir_Expand(const char *word, Lst path, Lst expansions)
*dp = '\0';
path = Lst_Init(FALSE);
(void)Dir_AddDir(path, dirpath);
DirExpandInt(cp+1, path, expansions);
DirExpandInt(cp + 1, path, expansions);
Lst_Destroy(path, NULL);
}
} else {
@ -972,7 +972,7 @@ static char *
DirLookup(Path *p, const char *name MAKE_ATTR_UNUSED, const char *cp,
Boolean hasSlash MAKE_ATTR_UNUSED)
{
char *file; /* the current filename to check */
char *file; /* the current filename to check */
if (DEBUG(DIR)) {
fprintf(debug_file, " %s ...\n", p->name);
@ -1008,8 +1008,8 @@ DirLookup(Path *p, const char *name MAKE_ATTR_UNUSED, const char *cp,
static char *
DirLookupSubdir(Path *p, const char *name)
{
struct stat stb; /* Buffer for stat, if necessary */
char *file; /* the current filename to check */
struct stat stb; /* Buffer for stat, if necessary */
char *file; /* the current filename to check */
if (p != dot) {
file = str_concat(p->name, name, STR_ADDSLASH);
@ -1050,40 +1050,40 @@ DirLookupSubdir(Path *p, const char *name)
static char *
DirLookupAbs(Path *p, const char *name, const char *cp)
{
char *p1; /* pointer into p->name */
const char *p2; /* pointer into name */
char *p1; /* pointer into p->name */
const char *p2; /* pointer into name */
if (DEBUG(DIR)) {
fprintf(debug_file, " %s ...\n", p->name);
}
/*
* If the file has a leading path component and that component
* exactly matches the entire name of the current search
* directory, we can attempt another cache lookup. And if we don't
* have a hit, we can safely assume the file does not exist at all.
*/
for (p1 = p->name, p2 = name; *p1 && *p1 == *p2; p1++, p2++) {
continue;
}
if (*p1 != '\0' || p2 != cp - 1) {
return NULL;
}
if (Hash_FindEntry(&p->files, cp) == NULL) {
if (DEBUG(DIR)) {
fprintf(debug_file, " %s ...\n", p->name);
fprintf(debug_file, " must be here but isn't -- returning\n");
}
/* Return empty string: terminates search */
return bmake_strdup("");
}
/*
* If the file has a leading path component and that component
* exactly matches the entire name of the current search
* directory, we can attempt another cache lookup. And if we don't
* have a hit, we can safely assume the file does not exist at all.
*/
for (p1 = p->name, p2 = name; *p1 && *p1 == *p2; p1++, p2++) {
continue;
}
if (*p1 != '\0' || p2 != cp - 1) {
return NULL;
}
if (Hash_FindEntry(&p->files, cp) == NULL) {
if (DEBUG(DIR)) {
fprintf(debug_file, " must be here but isn't -- returning\n");
}
/* Return empty string: terminates search */
return bmake_strdup("");
}
p->hits += 1;
hits += 1;
if (DEBUG(DIR)) {
fprintf(debug_file, " returning %s\n", name);
}
return bmake_strdup(name);
p->hits += 1;
hits += 1;
if (DEBUG(DIR)) {
fprintf(debug_file, " returning %s\n", name);
}
return bmake_strdup(name);
}
/*-
@ -1103,25 +1103,24 @@ static char *
DirFindDot(Boolean hasSlash MAKE_ATTR_UNUSED, const char *name, const char *cp)
{
if (Hash_FindEntry(&dot->files, cp) != NULL) {
if (DEBUG(DIR)) {
fprintf(debug_file, " in '.'\n");
}
hits += 1;
dot->hits += 1;
return bmake_strdup(name);
if (Hash_FindEntry(&dot->files, cp) != NULL) {
if (DEBUG(DIR)) {
fprintf(debug_file, " in '.'\n");
}
if (cur &&
Hash_FindEntry(&cur->files, cp) != NULL) {
if (DEBUG(DIR)) {
fprintf(debug_file, " in ${.CURDIR} = %s\n", cur->name);
}
hits += 1;
cur->hits += 1;
return str_concat(cur->name, cp, STR_ADDSLASH);
hits += 1;
dot->hits += 1;
return bmake_strdup(name);
}
if (cur && Hash_FindEntry(&cur->files, cp) != NULL) {
if (DEBUG(DIR)) {
fprintf(debug_file, " in ${.CURDIR} = %s\n", cur->name);
}
hits += 1;
cur->hits += 1;
return str_concat(cur->name, cp, STR_ADDSLASH);
}
return NULL;
return NULL;
}
/*-
@ -1149,14 +1148,14 @@ DirFindDot(Boolean hasSlash MAKE_ATTR_UNUSED, const char *name, const char *cp)
char *
Dir_FindFile(const char *name, Lst path)
{
LstNode ln; /* a list element */
char *file; /* the current filename to check */
Path *p; /* current path member */
const char *cp; /* Terminal name of file */
Boolean hasLastDot = FALSE; /* true we should search dot last */
Boolean hasSlash; /* true if 'name' contains a / */
struct stat stb; /* Buffer for stat, if necessary */
const char *trailing_dot = ".";
LstNode ln; /* a list element */
char *file; /* the current filename to check */
Path *p; /* current path member */
const char *cp; /* Terminal name of file */
Boolean hasLastDot = FALSE; /* true we should search dot last */
Boolean hasSlash; /* true if 'name' contains a / */
struct stat stb; /* Buffer for stat, if necessary */
const char *trailing_dot = ".";
/*
* Find the final component of the name and note whether it has a
@ -1201,41 +1200,39 @@ Dir_FindFile(const char *name, Lst path)
* of each of the directories on the search path.
*/
if (!hasSlash || (cp - name == 2 && *name == '.')) {
/*
* We look through all the directories on the path seeking one which
* contains the final component of the given name. If such a beast
* is found, we concatenate the directory name and the final
* component and return the resulting string. If we don't find any
* such thing, we go on to phase two...
*
* No matter what, we always look for the file in the current
* directory before anywhere else (unless we found the magic
* DOTLAST path, in which case we search it last) and we *do not*
* add the ./ to it if it exists.
* This is so there are no conflicts between what the user
* specifies (fish.c) and what pmake finds (./fish.c).
*/
if (!hasLastDot &&
(file = DirFindDot(hasSlash, name, cp)) != NULL) {
Lst_Close(path);
return file;
}
/*
* We look through all the directories on the path seeking one which
* contains the final component of the given name. If such a beast
* is found, we concatenate the directory name and the final
* component and return the resulting string. If we don't find any
* such thing, we go on to phase two...
*
* No matter what, we always look for the file in the current
* directory before anywhere else (unless we found the magic
* DOTLAST path, in which case we search it last) and we *do not*
* add the ./ to it if it exists.
* This is so there are no conflicts between what the user
* specifies (fish.c) and what pmake finds (./fish.c).
*/
if (!hasLastDot && (file = DirFindDot(hasSlash, name, cp)) != NULL) {
Lst_Close(path);
return file;
}
while ((ln = Lst_Next(path)) != NULL) {
p = (Path *)Lst_Datum(ln);
if (p == dotLast)
continue;
if ((file = DirLookup(p, name, cp, hasSlash)) != NULL) {
Lst_Close(path);
return file;
}
while ((ln = Lst_Next(path)) != NULL) {
p = (Path *)Lst_Datum(ln);
if (p == dotLast)
continue;
if ((file = DirLookup(p, name, cp, hasSlash)) != NULL) {
Lst_Close(path);
return file;
}
}
if (hasLastDot &&
(file = DirFindDot(hasSlash, name, cp)) != NULL) {
Lst_Close(path);
return file;
}
if (hasLastDot && (file = DirFindDot(hasSlash, name, cp)) != NULL) {
Lst_Close(path);
return file;
}
}
Lst_Close(path);
@ -1267,20 +1264,20 @@ Dir_FindFile(const char *name, Lst path)
}
if (name[0] != '/') {
Boolean checkedDot = FALSE;
Boolean checkedDot = FALSE;
if (DEBUG(DIR)) {
fprintf(debug_file, " Trying subdirectories...\n");
}
if (!hasLastDot) {
if (dot) {
checkedDot = TRUE;
if ((file = DirLookupSubdir(dot, name)) != NULL)
return file;
}
if (cur && (file = DirLookupSubdir(cur, name)) != NULL)
return file;
if (dot) {
checkedDot = TRUE;
if ((file = DirLookupSubdir(dot, name)) != NULL)
return file;
}
if (cur && (file = DirLookupSubdir(cur, name)) != NULL)
return file;
}
(void)Lst_Open(path);
@ -1289,8 +1286,8 @@ Dir_FindFile(const char *name, Lst path)
if (p == dotLast)
continue;
if (p == dot) {
if (checkedDot)
continue;
if (checkedDot)
continue;
checkedDot = TRUE;
}
if ((file = DirLookupSubdir(p, name)) != NULL) {
@ -1301,13 +1298,13 @@ Dir_FindFile(const char *name, Lst path)
Lst_Close(path);
if (hasLastDot) {
if (dot && !checkedDot) {
checkedDot = TRUE;
if ((file = DirLookupSubdir(dot, name)) != NULL)
return file;
}
if (cur && (file = DirLookupSubdir(cur, name)) != NULL)
return file;
if (dot && !checkedDot) {
checkedDot = TRUE;
if ((file = DirLookupSubdir(dot, name)) != NULL)
return file;
}
if (cur && (file = DirLookupSubdir(cur, name)) != NULL)
return file;
}
if (checkedDot) {
@ -1336,8 +1333,8 @@ Dir_FindFile(const char *name, Lst path)
fprintf(debug_file, " Trying exact path matches...\n");
}
if (!hasLastDot && cur && ((file = DirLookupAbs(cur, name, cp))
!= NULL)) {
if (!hasLastDot && cur &&
((file = DirLookupAbs(cur, name, cp)) != NULL)) {
if (file[0] == '\0') {
free(file);
return NULL;
@ -1361,8 +1358,8 @@ Dir_FindFile(const char *name, Lst path)
}
Lst_Close(path);
if (hasLastDot && cur && ((file = DirLookupAbs(cur, name, cp))
!= NULL)) {
if (hasLastDot && cur &&
((file = DirLookupAbs(cur, name, cp)) != NULL)) {
if (file[0] == '\0') {
free(file);
return NULL;
@ -1449,61 +1446,61 @@ Dir_FindFile(const char *name, Lst path)
*-----------------------------------------------------------------------
*/
int
Dir_FindHereOrAbove(char *here, char *search_path, char *result, int rlen) {
Dir_FindHereOrAbove(char *here, char *search_path, char *result, int rlen)
{
struct stat st;
char dirbase[MAXPATHLEN + 1], *db_end;
char try[MAXPATHLEN + 1], *try_end;
struct stat st;
char dirbase[MAXPATHLEN + 1], *db_end;
char try[MAXPATHLEN + 1], *try_end;
/* copy out our starting point */
snprintf(dirbase, sizeof(dirbase), "%s", here);
db_end = dirbase + strlen(dirbase);
/* copy out our starting point */
snprintf(dirbase, sizeof(dirbase), "%s", here);
db_end = dirbase + strlen(dirbase);
/* loop until we determine a result */
while (1) {
/* loop until we determine a result */
while (1) {
/* try and stat(2) it ... */
snprintf(try, sizeof(try), "%s/%s", dirbase, search_path);
if (cached_stat(try, &st) != -1) {
/*
* success! if we found a file, chop off
* the filename so we return a directory.
*/
if ((st.st_mode & S_IFMT) != S_IFDIR) {
try_end = try + strlen(try);
while (try_end > try && *try_end != '/')
try_end--;
if (try_end > try)
*try_end = 0; /* chop! */
}
/* try and stat(2) it ... */
snprintf(try, sizeof(try), "%s/%s", dirbase, search_path);
if (cached_stat(try, &st) != -1) {
/*
* success! if we found a file, chop off
* the filename so we return a directory.
*/
if ((st.st_mode & S_IFMT) != S_IFDIR) {
try_end = try + strlen(try);
while (try_end > try && *try_end != '/')
try_end--;
if (try_end > try)
*try_end = 0; /* chop! */
}
/*
* done!
*/
snprintf(result, rlen, "%s", try);
return 1;
}
/*
* nope, we didn't find it. if we used up dirbase we've
* reached the root and failed.
*/
if (db_end == dirbase)
break; /* failed! */
/*
* truncate dirbase from the end to move up a dir
*/
while (db_end > dirbase && *db_end != '/')
db_end--;
*db_end = 0; /* chop! */
} /* while (1) */
/*
* done!
*/
snprintf(result, rlen, "%s", try);
return 1;
}
/*
* we failed...
* nope, we didn't find it. if we used up dirbase we've
* reached the root and failed.
*/
return 0;
if (db_end == dirbase)
break; /* failed! */
/*
* truncate dirbase from the end to move up a dir
*/
while (db_end > dirbase && *db_end != '/')
db_end--;
*db_end = 0; /* chop! */
} /* while (1) */
/*
* we failed...
*/
return 0;
}
/*-
@ -1527,8 +1524,8 @@ Dir_FindHereOrAbove(char *here, char *search_path, char *result, int rlen) {
int
Dir_MTime(GNode *gn, Boolean recheck)
{
char *fullName; /* the full pathname of name */
struct stat stb; /* buffer for finding the mod time */
char *fullName; /* the full pathname of name */
struct stat stb; /* buffer for finding the mod time */
if (gn->type & OP_ARCHV) {
return Arch_MTime(gn);
@ -1561,15 +1558,16 @@ Dir_MTime(GNode *gn, Boolean recheck)
gn->path = bmake_strdup(fullName);
if (!Job_RunTarget(".STALE", gn->fname))
fprintf(stdout,
"%s: %s, %d: ignoring stale %s for %s, "
"found %s\n", progname, gn->fname, gn->lineno,
makeDependfile, gn->name, fullName);
"%s: %s, %d: ignoring stale %s for %s, "
"found %s\n", progname, gn->fname,
gn->lineno,
makeDependfile, gn->name, fullName);
}
}
}
if (DEBUG(DIR))
fprintf(debug_file, "Found '%s' as '%s'\n",
gn->name, fullName ? fullName : "(not found)" );
gn->name, fullName ? fullName : "(not found)");
}
} else {
fullName = gn->path;
@ -1620,10 +1618,10 @@ Dir_MTime(GNode *gn, Boolean recheck)
Path *
Dir_AddDir(Lst path, const char *name)
{
LstNode ln = NULL; /* node in case Path structure is found */
Path *p = NULL; /* pointer to new Path structure */
DIR *d; /* for reading directory */
struct dirent *dp; /* entry in directory */
LstNode ln = NULL; /* node in case Path structure is found */
Path *p = NULL; /* pointer to new Path structure */
DIR *d; /* for reading directory */
struct dirent *dp; /* entry in directory */
if (strcmp(name, ".DOTLAST") == 0) {
ln = Lst_Find(path, name, DirFindName);
@ -1726,10 +1724,11 @@ Dir_CopyDir(void *p)
char *
Dir_MakeFlags(const char *flag, Lst path)
{
char *str; /* the string which will be returned */
char *s1, *s2;/* the current directory preceded by 'flag' */
LstNode ln; /* the node of the current directory */
Path *p; /* the structure describing the current directory */
char *str; /* the string which will be returned */
char *s1, *s2; /* the current directory preceded by 'flag' */
LstNode ln; /* the node of the current directory */
Path *p; /* the structure describing the current
* directory */
str = bmake_strdup("");
@ -1768,11 +1767,11 @@ Dir_MakeFlags(const char *flag, Lst path)
void
Dir_Destroy(void *pp)
{
Path *p = (Path *)pp;
Path *p = (Path *)pp;
p->refCount -= 1;
if (p->refCount == 0) {
LstNode ln;
LstNode ln;
ln = Lst_Member(openDirectories, p);
(void)Lst_Remove(openDirectories, ln);
@ -1803,7 +1802,7 @@ Dir_Destroy(void *pp)
void
Dir_ClearPath(Lst path)
{
Path *p;
Path *p;
while (!Lst_IsEmpty(path)) {
p = (Path *)Lst_DeQueue(path);
Dir_Destroy(p);
@ -1833,7 +1832,7 @@ void
Dir_Concat(Lst path1, Lst path2)
{
LstNode ln;
Path *p;
Path *p;
for (ln = Lst_First(path2); ln != NULL; ln = Lst_Succ(ln)) {
p = (Path *)Lst_Datum(ln);
@ -1848,19 +1847,21 @@ Dir_Concat(Lst path1, Lst path2)
void
Dir_PrintDirectories(void)
{
LstNode ln;
Path *p;
LstNode ln;
Path *p;
fprintf(debug_file, "#*** Directory Cache:\n");
fprintf(debug_file, "# Stats: %d hits %d misses %d near misses %d losers (%d%%)\n",
hits, misses, nearmisses, bigmisses,
(hits+bigmisses+nearmisses ?
hits * 100 / (hits + bigmisses + nearmisses) : 0));
fprintf(debug_file,
"# Stats: %d hits %d misses %d near misses %d losers (%d%%)\n",
hits, misses, nearmisses, bigmisses,
(hits + bigmisses + nearmisses ?
hits * 100 / (hits + bigmisses + nearmisses) : 0));
fprintf(debug_file, "# %-20s referenced\thits\n", "directory");
if (Lst_Open(openDirectories) == SUCCESS) {
while ((ln = Lst_Next(openDirectories)) != NULL) {
p = (Path *)Lst_Datum(ln);
fprintf(debug_file, "# %-20s %10d\t%4d\n", p->name, p->refCount, p->hits);
fprintf(debug_file, "# %-20s %10d\t%4d\n", p->name, p->refCount,
p->hits);
}
Lst_Close(openDirectories);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: for.c,v 1.62 2020/08/08 18:54:04 rillig Exp $ */
/* $NetBSD: for.c,v 1.63 2020/08/09 19:51:02 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.62 2020/08/08 18:54:04 rillig Exp $";
static char rcsid[] = "$NetBSD: for.c,v 1.63 2020/08/09 19:51:02 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.62 2020/08/08 18:54:04 rillig Exp $");
__RCSID("$NetBSD: for.c,v 1.63 2020/08/09 19:51:02 rillig Exp $");
#endif
#endif /* not lint */
#endif
@ -83,33 +83,32 @@ __RCSID("$NetBSD: for.c,v 1.62 2020/08/08 18:54:04 rillig Exp $");
* For_Run.
*/
static int forLevel = 0; /* Nesting level */
static int forLevel = 0; /* Nesting level */
/*
* State of a for loop.
*/
typedef struct {
Buffer buf; /* Body of loop */
strlist_t vars; /* Iteration variables */
strlist_t items; /* Substitution items */
char *parse_buf;
int short_var;
int sub_next;
Buffer buf; /* Body of loop */
strlist_t vars; /* Iteration variables */
strlist_t items; /* Substitution items */
char *parse_buf;
int short_var;
int sub_next;
} For;
static For *accumFor; /* Loop being accumulated */
static For *accumFor; /* Loop being accumulated */
static char *
make_str(const char *ptr, int len)
{
char *new_ptr;
char *new_ptr;
new_ptr = bmake_malloc(len + 1);
memcpy(new_ptr, ptr, len);
new_ptr[len] = 0;
return new_ptr;
new_ptr = bmake_malloc(len + 1);
memcpy(new_ptr, ptr, len);
new_ptr[len] = 0;
return new_ptr;
}
static void
@ -155,7 +154,7 @@ For_Eval(char *line)
int n, nwords;
/* Skip the '.' and any following whitespace */
for (ptr++; *ptr && isspace((unsigned char) *ptr); ptr++)
for (ptr++; *ptr && isspace((unsigned char)*ptr); ptr++)
continue;
/*
@ -163,8 +162,8 @@ For_Eval(char *line)
* a for.
*/
if (ptr[0] != 'f' || ptr[1] != 'o' || ptr[2] != 'r' ||
!isspace((unsigned char) ptr[3])) {
if (ptr[0] == 'e' && strncmp(ptr+1, "ndfor", 5) == 0) {
!isspace((unsigned char)ptr[3])) {
if (ptr[0] == 'e' && strncmp(ptr + 1, "ndfor", 5) == 0) {
Parse_Error(PARSE_FATAL, "for-less endfor");
return -1;
}
@ -181,7 +180,7 @@ For_Eval(char *line)
/* Grab the variables. Terminate on "in". */
for (;; ptr += len) {
while (*ptr && isspace((unsigned char) *ptr))
while (*ptr && isspace((unsigned char)*ptr))
ptr++;
if (*ptr == '\0') {
Parse_Error(PARSE_FATAL, "missing `in' in for");
@ -205,7 +204,7 @@ For_Eval(char *line)
return -1;
}
while (*ptr && isspace((unsigned char) *ptr))
while (*ptr && isspace((unsigned char)*ptr))
ptr++;
/*
@ -232,7 +231,7 @@ For_Eval(char *line)
continue;
escapes = 0;
while ((ch = *ptr++)) {
switch(ch) {
switch (ch) {
case ':':
case '$':
case '\\':
@ -288,17 +287,17 @@ For_Accum(char *line)
if (*ptr == '.') {
for (ptr++; *ptr && isspace((unsigned char) *ptr); ptr++)
for (ptr++; *ptr && isspace((unsigned char)*ptr); ptr++)
continue;
if (strncmp(ptr, "endfor", 6) == 0 &&
(isspace((unsigned char) ptr[6]) || !ptr[6])) {
(isspace((unsigned char)ptr[6]) || !ptr[6])) {
if (DEBUG(FOR))
(void)fprintf(debug_file, "For: end for %d\n", forLevel);
if (--forLevel <= 0)
return 0;
} else if (strncmp(ptr, "for", 3) == 0 &&
isspace((unsigned char) ptr[3])) {
isspace((unsigned char)ptr[3])) {
forLevel++;
if (DEBUG(FOR))
(void)fprintf(debug_file, "For: new loop %d\n", forLevel);
@ -310,7 +309,6 @@ For_Accum(char *line)
return 1;
}
static size_t
for_var_len(const char *var)
@ -354,7 +352,7 @@ for_substitute(Buffer *cmds, strlist_t *items, unsigned int item_no, char ech)
/* If there were no escapes, or the only escape is the other variable
* terminator, then just substitute the full string */
if (!(strlist_info(items, item_no) &
(ech == ')' ? ~FOR_SUB_ESCAPE_BRACE : ~FOR_SUB_ESCAPE_PAREN))) {
(ech == ')' ? ~FOR_SUB_ESCAPE_BRACE : ~FOR_SUB_ESCAPE_PAREN))) {
Buf_AddStr(cmds, item);
return;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: strlist.c,v 1.4 2009/01/24 11:59:39 dsl Exp $ */
/* $NetBSD: strlist.c,v 1.5 2020/08/09 19:51:02 rillig Exp $ */
/*-
* Copyright (c) 2008 - 2009 The NetBSD Foundation, Inc.
@ -33,11 +33,11 @@
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: strlist.c,v 1.4 2009/01/24 11:59:39 dsl Exp $";
static char rcsid[] = "$NetBSD: strlist.c,v 1.5 2020/08/09 19:51:02 rillig Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: strlist.c,v 1.4 2009/01/24 11:59:39 dsl Exp $");
__RCSID("$NetBSD: strlist.c,v 1.5 2020/08/09 19:51:02 rillig Exp $");
#endif /* not lint */
#endif
@ -76,18 +76,18 @@ strlist_add_str(strlist_t *sl, char *str, unsigned int info)
strlist_item_t *items;
if (str == NULL)
return;
return;
n = sl->sl_num + 1;
sl->sl_num = n;
items = sl->sl_items;
if (n >= sl->sl_max) {
items = bmake_realloc(items, (n + 7) * sizeof *sl->sl_items);
sl->sl_items = items;
sl->sl_max = n + 6;
items = bmake_realloc(items, (n + 7) * sizeof *sl->sl_items);
sl->sl_items = items;
sl->sl_max = n + 6;
}
items += n - 1;
items->si_str = str;
items->si_info = info;
items[1].si_str = NULL; /* STRLIST_FOREACH() terminator */
items[1].si_str = NULL; /* STRLIST_FOREACH() terminator */
}