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

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"
@ -150,7 +150,7 @@ 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 Token condPushBack = TOK_NONE; /* Single push-back token used in
* parsing */
static unsigned int cond_depth = 0; /* current .if nesting level */
@ -248,8 +248,7 @@ CondGetArg(Boolean doEval, const char **linePtr, char **argPtr,
}
if (ch == '(')
paren_depth++;
else
if (ch == ')' && --paren_depth < 0)
else if (ch == ')' && --paren_depth < 0)
break;
Buf_AddByte(&buf, *cp);
cp++;
@ -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;
}
@ -476,7 +475,7 @@ CondGetString(Boolean doEval, Boolean *quoted, void **freeIt, Boolean strictLHS)
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,10 +488,10 @@ 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;
}
@ -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++;
/*
@ -610,7 +609,7 @@ 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 !=");
@ -643,7 +642,7 @@ do_string_compare:
fprintf(debug_file, "left = %f, right = %f, op = %.2s\n", left,
right, op);
}
switch(op[0]) {
switch (op[0]) {
case '!':
if (op[1] != '=') {
Parse_Error(PARSE_WARNING,
@ -699,7 +698,8 @@ get_mpt_arg(Boolean doEval, const char **linePtr, char **argPtr,
/* 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'.
@ -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,8 +1118,8 @@ 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 */
@ -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
@ -225,24 +225,24 @@ 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... */
/* 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 */
@ -567,7 +567,7 @@ Dir_HasWildcards(char *name)
int wild = 0, brace = 0, bracket = 0;
for (cp = name; *cp; cp++) {
switch(*cp) {
switch (*cp) {
case '{':
brace++;
wild = 1;
@ -679,7 +679,7 @@ static Boolean
contains_wildcard(const char *p)
{
for (; *p != '\0'; p++) {
switch(*p) {
switch (*p) {
case '*':
case '?':
case '{':
@ -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 {
@ -1111,8 +1111,7 @@ DirFindDot(Boolean hasSlash MAKE_ATTR_UNUSED, const char *name, const char *cp)
dot->hits += 1;
return bmake_strdup(name);
}
if (cur &&
Hash_FindEntry(&cur->files, cp) != NULL) {
if (cur && Hash_FindEntry(&cur->files, cp) != NULL) {
if (DEBUG(DIR)) {
fprintf(debug_file, " in ${.CURDIR} = %s\n", cur->name);
}
@ -1215,8 +1214,7 @@ Dir_FindFile(const char *name, Lst path)
* 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) {
if (!hasLastDot && (file = DirFindDot(hasSlash, name, cp)) != NULL) {
Lst_Close(path);
return file;
}
@ -1231,8 +1229,7 @@ Dir_FindFile(const char *name, Lst path)
}
}
if (hasLastDot &&
(file = DirFindDot(hasSlash, name, cp)) != NULL) {
if (hasLastDot && (file = DirFindDot(hasSlash, name, cp)) != NULL) {
Lst_Close(path);
return file;
}
@ -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,8 +1446,8 @@ 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;
@ -1562,14 +1559,15 @@ Dir_MTime(GNode *gn, Boolean recheck)
if (!Job_RunTarget(".STALE", gn->fname))
fprintf(stdout,
"%s: %s, %d: ignoring stale %s for %s, "
"found %s\n", progname, gn->fname, gn->lineno,
"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;
@ -1727,9 +1725,10 @@ 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' */
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 */
Path *p; /* the structure describing the current
* directory */
str = bmake_strdup("");
@ -1852,15 +1851,17 @@ Dir_PrintDirectories(void)
Path *p;
fprintf(debug_file, "#*** Directory Cache:\n");
fprintf(debug_file, "# Stats: %d hits %d misses %d near misses %d losers (%d%%)\n",
fprintf(debug_file,
"# Stats: %d hits %d misses %d near misses %d losers (%d%%)\n",
hits, misses, nearmisses, bigmisses,
(hits+bigmisses+nearmisses ?
(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
@ -99,7 +99,6 @@ typedef struct {
static For *accumFor; /* Loop being accumulated */
static char *
make_str(const char *ptr, int len)
@ -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)

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