Module Name: src Committed By: rillig Date: Sat Nov 7 10:16:19 UTC 2020
Modified Files: src/usr.bin/make: arch.c buf.c compat.c cond.c dir.c for.c job.c main.c make.c meta.c nonints.h parse.c str.c var.c Log Message: make(1): clean up code stylistically * Replace character literal 0 with '\0'. * Replace pointer literal 0 with NULL. * Remove redundant parentheses. * Parentheses in multi-line conditions are not redundant at the beginning of a line. * Replace a few !ptr with ptr == NULL. * Replace a few ptr with ptr != NULL. * Replace (expr & mask) == 0 with !(expr & mask). * Remove redundant braces for blocks in cases where the generated code stays the same. (Assertions further down in the code would get different line numbers.) * Rename parameters in CondParser_String to reflect the data flow. * Replace #ifdef notdef with #if 0. The generated code stays exactly the same, at least with GCC 5.5.0 on NetBSD 8.0 amd64 using the default configuration. To generate a diff of this commit: cvs rdiff -u -r1.155 -r1.156 src/usr.bin/make/arch.c cvs rdiff -u -r1.42 -r1.43 src/usr.bin/make/buf.c cvs rdiff -u -r1.174 -r1.175 src/usr.bin/make/compat.c cvs rdiff -u -r1.177 -r1.178 src/usr.bin/make/cond.c cvs rdiff -u -r1.195 -r1.196 src/usr.bin/make/dir.c cvs rdiff -u -r1.112 -r1.113 src/usr.bin/make/for.c cvs rdiff -u -r1.305 -r1.306 src/usr.bin/make/job.c cvs rdiff -u -r1.432 -r1.433 src/usr.bin/make/main.c cvs rdiff -u -r1.186 -r1.187 src/usr.bin/make/make.c cvs rdiff -u -r1.138 -r1.139 src/usr.bin/make/meta.c cvs rdiff -u -r1.153 -r1.154 src/usr.bin/make/nonints.h cvs rdiff -u -r1.427 -r1.428 src/usr.bin/make/parse.c cvs rdiff -u -r1.70 -r1.71 src/usr.bin/make/str.c cvs rdiff -u -r1.671 -r1.672 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/arch.c diff -u src/usr.bin/make/arch.c:1.155 src/usr.bin/make/arch.c:1.156 --- src/usr.bin/make/arch.c:1.155 Fri Nov 6 23:59:21 2020 +++ src/usr.bin/make/arch.c Sat Nov 7 10:16:18 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: arch.c,v 1.155 2020/11/06 23:59:21 rillig Exp $ */ +/* $NetBSD: arch.c,v 1.156 2020/11/07 10:16:18 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -130,7 +130,7 @@ #include "config.h" /* "@(#)arch.c 8.2 (Berkeley) 1/2/94" */ -MAKE_RCSID("$NetBSD: arch.c,v 1.155 2020/11/06 23:59:21 rillig Exp $"); +MAKE_RCSID("$NetBSD: arch.c,v 1.156 2020/11/07 10:16:18 rillig Exp $"); #ifdef TARGET_MACHINE #undef MAKE_MACHINE @@ -335,7 +335,8 @@ Arch_ParseArchive(char **pp, GNodeList * */ buf = sacrifice = str_concat4(libName, "(", memName, ")"); - if (strchr(memName, '$') && strcmp(memName, oldMemName) == 0) { + if (strchr(memName, '$') != NULL && + strcmp(memName, oldMemName) == 0) { /* * Must contain dynamic sources, so we can't deal with it now. * Just create an ARCHV node for the thing and let @@ -490,8 +491,8 @@ ArchStatMember(const char *archive, cons * We use the ARMAG string to make sure this is an archive we * can handle... */ - if ((fread(magic, SARMAG, 1, arch) != 1) || - (strncmp(magic, ARMAG, SARMAG) != 0)) { + if (fread(magic, SARMAG, 1, arch) != 1 || + strncmp(magic, ARMAG, SARMAG) != 0) { fclose(arch); return NULL; } @@ -721,8 +722,8 @@ ArchFindMember(const char *archive, cons * We use the ARMAG string to make sure this is an archive we * can handle... */ - if ((fread(magic, SARMAG, 1, arch) != 1) || - (strncmp(magic, ARMAG, SARMAG) != 0)) { + if (fread(magic, SARMAG, 1, arch) != 1 || + strncmp(magic, ARMAG, SARMAG) != 0) { fclose(arch); return NULL; } Index: src/usr.bin/make/buf.c diff -u src/usr.bin/make/buf.c:1.42 src/usr.bin/make/buf.c:1.43 --- src/usr.bin/make/buf.c:1.42 Sat Oct 24 20:51:49 2020 +++ src/usr.bin/make/buf.c Sat Nov 7 10:16:18 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: buf.c,v 1.42 2020/10/24 20:51:49 rillig Exp $ */ +/* $NetBSD: buf.c,v 1.43 2020/11/07 10:16:18 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -75,7 +75,7 @@ #include "make.h" /* "@(#)buf.c 8.1 (Berkeley) 6/6/93" */ -MAKE_RCSID("$NetBSD: buf.c,v 1.42 2020/10/24 20:51:49 rillig Exp $"); +MAKE_RCSID("$NetBSD: buf.c,v 1.43 2020/11/07 10:16:18 rillig Exp $"); /* Make space in the buffer for adding a single byte. */ void @@ -160,7 +160,7 @@ Buf_Empty(Buffer *buf) void Buf_Init(Buffer *buf, size_t cap) { - if (cap <= 0) + if (cap == 0) cap = 256; buf->cap = cap; buf->len = 0; Index: src/usr.bin/make/compat.c diff -u src/usr.bin/make/compat.c:1.174 src/usr.bin/make/compat.c:1.175 --- src/usr.bin/make/compat.c:1.174 Mon Nov 2 20:50:24 2020 +++ src/usr.bin/make/compat.c Sat Nov 7 10:16:18 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: compat.c,v 1.174 2020/11/02 20:50:24 rillig Exp $ */ +/* $NetBSD: compat.c,v 1.175 2020/11/07 10:16:18 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -96,7 +96,7 @@ #include "pathnames.h" /* "@(#)compat.c 8.2 (Berkeley) 3/19/94" */ -MAKE_RCSID("$NetBSD: compat.c,v 1.174 2020/11/02 20:50:24 rillig Exp $"); +MAKE_RCSID("$NetBSD: compat.c,v 1.175 2020/11/07 10:16:18 rillig Exp $"); static GNode *curTarg = NULL; static pid_t compatChild; @@ -201,7 +201,7 @@ Compat_RunCommand(const char *cmdp, GNod (void)Var_Subst(cmd, gn, VARE_WANTRES, &cmdStart); /* TODO: handle errors */ - if (*cmdStart == '\0') { + if (cmdStart[0] == '\0') { free(cmdStart); return 0; } @@ -243,7 +243,7 @@ Compat_RunCommand(const char *cmdp, GNod /* * If we did not end up with a command, just skip it. */ - if (!*cmd) + if (cmd[0] == '\0') return 0; #if !defined(MAKE_NATIVE) @@ -599,15 +599,14 @@ Compat_Make(GNode *gn, GNode *pgn) pgn->flags &= ~(unsigned)REMAKE; break; case MADE: - if ((gn->type & OP_EXEC) == 0) { + if (!(gn->type & OP_EXEC)) { pgn->flags |= CHILDMADE; Make_TimeStamp(pgn, gn); } break; case UPTODATE: - if ((gn->type & OP_EXEC) == 0) { + if (!(gn->type & OP_EXEC)) Make_TimeStamp(pgn, gn); - } break; default: break; Index: src/usr.bin/make/cond.c diff -u src/usr.bin/make/cond.c:1.177 src/usr.bin/make/cond.c:1.178 --- src/usr.bin/make/cond.c:1.177 Fri Nov 6 22:39:10 2020 +++ src/usr.bin/make/cond.c Sat Nov 7 10:16:18 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: cond.c,v 1.177 2020/11/06 22:39:10 rillig Exp $ */ +/* $NetBSD: cond.c,v 1.178 2020/11/07 10:16:18 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -93,7 +93,7 @@ #include "dir.h" /* "@(#)cond.c 8.2 (Berkeley) 1/2/94" */ -MAKE_RCSID("$NetBSD: cond.c,v 1.177 2020/11/06 22:39:10 rillig Exp $"); +MAKE_RCSID("$NetBSD: cond.c,v 1.178 2020/11/07 10:16:18 rillig Exp $"); /* * The parsing of conditional expressions is based on this grammar: @@ -230,7 +230,7 @@ ParseFuncArg(const char **pp, Boolean do paren_depth = 0; for (;;) { char ch = *p; - if (ch == 0 || ch == ' ' || ch == '\t') + if (ch == '\0' || ch == ' ' || ch == '\t') break; if ((ch == '&' || ch == '|') && paren_depth == 0) break; @@ -381,13 +381,13 @@ is_separator(char ch) * * Results: * Returns the string, absent any quotes, or NULL on error. - * Sets quoted if the string was quoted. - * Sets freeIt if needed. + * Sets out_quoted if the string was quoted. + * Sets out_freeIt. */ /* coverity:[+alloc : arg-*4] */ static const char * CondParser_String(CondParser *par, Boolean doEval, Boolean strictLHS, - Boolean *quoted, void **freeIt) + Boolean *out_quoted, void **out_freeIt) { Buffer buf; const char *str; @@ -400,12 +400,12 @@ CondParser_String(CondParser *par, Boole Buf_Init(&buf, 0); str = NULL; - *freeIt = NULL; - *quoted = qt = par->p[0] == '"' ? 1 : 0; + *out_freeIt = NULL; + *out_quoted = qt = par->p[0] == '"'; start = par->p; if (qt) par->p++; - while (par->p[0] && str == NULL) { + while (par->p[0] != '\0' && str == NULL) { switch (par->p[0]) { case '\\': par->p++; @@ -441,14 +441,14 @@ CondParser_String(CondParser *par, Boole nested_p = par->p; atStart = nested_p == start; parseResult = Var_Parse(&nested_p, VAR_CMDLINE, eflags, &str, - freeIt); + out_freeIt); /* TODO: handle errors */ if (str == var_Error) { if (parseResult & VPR_ANY_MSG) par->printedError = TRUE; - if (*freeIt) { - free(*freeIt); - *freeIt = NULL; + if (*out_freeIt) { + free(*out_freeIt); + *out_freeIt = NULL; } /* * Even if !doEval, we still report syntax errors, which @@ -469,18 +469,18 @@ CondParser_String(CondParser *par, Boole goto cleanup; Buf_AddStr(&buf, str); - if (*freeIt) { - free(*freeIt); - *freeIt = NULL; + if (*out_freeIt) { + free(*out_freeIt); + *out_freeIt = NULL; } str = NULL; /* not finished yet */ continue; default: if (strictLHS && !qt && *start != '$' && !ch_isdigit(*start)) { /* lhs must be quoted, a variable reference or number */ - if (*freeIt) { - free(*freeIt); - *freeIt = NULL; + if (*out_freeIt) { + free(*out_freeIt); + *out_freeIt = NULL; } str = NULL; goto cleanup; @@ -491,8 +491,8 @@ CondParser_String(CondParser *par, Boole } } got_str: - *freeIt = Buf_GetAll(&buf, NULL); - str = *freeIt; + *out_freeIt = Buf_GetAll(&buf, NULL); + str = *out_freeIt; cleanup: Buf_Destroy(&buf, FALSE); return str; @@ -539,7 +539,7 @@ EvalNotEmpty(CondParser *par, const char /* For .if ${...} check for non-empty string (defProc is ifdef). */ if (par->if_info->form[0] == '\0') - return lhs[0] != 0; + return lhs[0] != '\0'; /* Otherwise action default test ... */ return If_Eval(par->if_info, lhs, strlen(lhs)); @@ -766,7 +766,7 @@ CondParser_Func(CondParser *par, Boolean /* Push anything numeric through the compare expression */ cp = par->p; - if (ch_isdigit(cp[0]) || strchr("+-", cp[0])) + if (ch_isdigit(cp[0]) || strchr("+-", cp[0]) != NULL) return CondParser_Comparison(par, doEval); /* @@ -1017,7 +1017,7 @@ CondEvalExpression(const struct If *info if (info == NULL && (info = dflt_info) == NULL) { /* Scan for the entry for .if - it can't be first */ for (info = ifs;; info++) - if (info->form[0] == 0) + if (info->form[0] == '\0') break; dflt_info = info; } @@ -1083,7 +1083,7 @@ Cond_EvalLine(const char *line) Boolean value; enum if_states state; - if (!cond_state) { + if (cond_state == NULL) { cond_state = bmake_malloc(max_if_depth * sizeof *cond_state); cond_state[0] = IF_ACTIVE; } @@ -1139,8 +1139,7 @@ Cond_EvalLine(const char *line) isElif = FALSE; if (line[0] != 'i' || line[1] != 'f') - /* Not an ifxxx or elifxxx line */ - return COND_INVALID; + return COND_INVALID; /* Not an ifxxx or elifxxx line */ /* * Figure out what sort of conditional it is -- what its default Index: src/usr.bin/make/dir.c diff -u src/usr.bin/make/dir.c:1.195 src/usr.bin/make/dir.c:1.196 --- src/usr.bin/make/dir.c:1.195 Fri Nov 6 23:59:21 2020 +++ src/usr.bin/make/dir.c Sat Nov 7 10:16:18 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: dir.c,v 1.195 2020/11/06 23:59:21 rillig Exp $ */ +/* $NetBSD: dir.c,v 1.196 2020/11/07 10:16:18 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -134,7 +134,7 @@ #include "job.h" /* "@(#)dir.c 8.2 (Berkeley) 1/2/94" */ -MAKE_RCSID("$NetBSD: dir.c,v 1.195 2020/11/06 23:59:21 rillig Exp $"); +MAKE_RCSID("$NetBSD: dir.c,v 1.196 2020/11/07 10:16:18 rillig Exp $"); #define DIR_DEBUG0(text) DEBUG0(DIR, text) #define DIR_DEBUG1(fmt, arg1) DEBUG1(DIR, fmt, arg1) @@ -326,7 +326,7 @@ cached_stats(HashTable *htp, const char struct cache_st *cst; int rc; - if (!pathname || !pathname[0]) + if (pathname == NULL || pathname[0] == '\0') return -1; entry = HashTable_FindEntry(htp, pathname); @@ -1176,7 +1176,7 @@ Dir_FindFile(const char *name, SearchPat * When searching for $(FILE), we will find it in $(INSTALLDIR) * b/c we added it here. This is not good... */ -#ifdef notdef +#if 0 if (base == trailing_dot) { base = strrchr(name, '/'); base++; @@ -1198,7 +1198,7 @@ Dir_FindFile(const char *name, SearchPat } else { return NULL; } -#else /* !notdef */ +#else DIR_DEBUG1(" Looking for \"%s\" ...\n", name); bigmisses++; @@ -1208,7 +1208,7 @@ Dir_FindFile(const char *name, SearchPat DIR_DEBUG0(" failed. Returning NULL\n"); return NULL; -#endif /* notdef */ +#endif } Index: src/usr.bin/make/for.c diff -u src/usr.bin/make/for.c:1.112 src/usr.bin/make/for.c:1.113 --- src/usr.bin/make/for.c:1.112 Sat Oct 31 18:41:07 2020 +++ src/usr.bin/make/for.c Sat Nov 7 10:16:18 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: for.c,v 1.112 2020/10/31 18:41:07 rillig Exp $ */ +/* $NetBSD: for.c,v 1.113 2020/11/07 10:16:18 rillig Exp $ */ /* * Copyright (c) 1992, The Regents of the University of California. @@ -60,7 +60,7 @@ #include "make.h" /* "@(#)for.c 8.1 (Berkeley) 6/6/93" */ -MAKE_RCSID("$NetBSD: for.c,v 1.112 2020/10/31 18:41:07 rillig Exp $"); +MAKE_RCSID("$NetBSD: for.c,v 1.113 2020/11/07 10:16:18 rillig Exp $"); /* The .for loop substitutes the items as ${:U<value>...}, which means * that characters that break this syntax must be backslash-escaped. */ @@ -302,7 +302,7 @@ for_var_len(const char *var) size_t len; var_start = *var; - if (var_start == 0) + if (var_start == '\0') /* just escape the $ */ return 0; @@ -315,7 +315,7 @@ for_var_len(const char *var) return 1; depth = 1; - for (len = 1; (ch = var[len++]) != 0;) { + for (len = 1; (ch = var[len++]) != '\0';) { if (ch == var_start) depth++; else if (ch == var_end && --depth == 0) Index: src/usr.bin/make/job.c diff -u src/usr.bin/make/job.c:1.305 src/usr.bin/make/job.c:1.306 --- src/usr.bin/make/job.c:1.305 Sat Nov 7 00:06:13 2020 +++ src/usr.bin/make/job.c Sat Nov 7 10:16:18 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: job.c,v 1.305 2020/11/07 00:06:13 rillig Exp $ */ +/* $NetBSD: job.c,v 1.306 2020/11/07 10:16:18 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -143,7 +143,7 @@ #include "trace.h" /* "@(#)job.c 8.2 (Berkeley) 3/19/94" */ -MAKE_RCSID("$NetBSD: job.c,v 1.305 2020/11/07 00:06:13 rillig Exp $"); +MAKE_RCSID("$NetBSD: job.c,v 1.306 2020/11/07 10:16:18 rillig Exp $"); /* A shell defines how the commands are run. All commands for a target are * written into a single file, which is then given to the shell to execute @@ -852,8 +852,8 @@ JobPrintCommand(Job *job, char *cmd) shutUp = TRUE; } /* If it's a comment line or blank, treat as an ignored error */ - if ((escCmd[0] == commandShell->commentChar) || - (escCmd[0] == 0)) + if (escCmd[0] == commandShell->commentChar || + (escCmd[0] == '\0')) cmdTemplate = commandShell->errOffOrExecIgnore; else cmdTemplate = commandShell->errExit; @@ -862,7 +862,7 @@ JobPrintCommand(Job *job, char *cmd) } if (DEBUG(SHELL) && strcmp(shellName, "sh") == 0 && - (job->flags & JOB_TRACED) == 0) { + !(job->flags & JOB_TRACED)) { DBPRINTF("set -%s\n", "x"); job->flags |= JOB_TRACED; } @@ -901,7 +901,7 @@ JobPrintCommands(Job *job) if (strcmp(cmd, "...") == 0) { job->node->type |= OP_SAVE_CMDS; - if ((job->flags & JOB_IGNDOTS) == 0) { + if (!(job->flags & JOB_IGNDOTS)) { job->tailCmds = ln->next; break; } @@ -974,7 +974,7 @@ JobFinish(Job *job, int status) job->pid, job->node->name, status); if ((WIFEXITED(status) && - (((WEXITSTATUS(status) != 0) && !(job->flags & JOB_IGNERR)))) || + ((WEXITSTATUS(status) != 0 && !(job->flags & JOB_IGNERR)))) || WIFSIGNALED(status)) { /* @@ -1077,13 +1077,13 @@ JobFinish(Job *job, int status) Trace_Log(JOBEND, job); if (!(job->flags & JOB_SPECIAL)) { - if ((status != 0) || - (aborting == ABORT_ERROR) || - (aborting == ABORT_INTERRUPT)) + if (status != 0 || + (aborting == ABORT_ERROR) || aborting == ABORT_INTERRUPT) return_job_token = TRUE; } - if ((aborting != ABORT_ERROR) && (aborting != ABORT_INTERRUPT) && (status == 0)) { + if (aborting != ABORT_ERROR && aborting != ABORT_INTERRUPT && + (status == 0)) { /* * As long as we aren't aborting and the job didn't return a non-zero * status that we shouldn't ignore, we call Make_Update to update @@ -1159,7 +1159,7 @@ Job_Touch(GNode *gn, Boolean silent) const char *file = GNode_Path(gn); times.actime = times.modtime = now; - if (utime(file, ×) < 0){ + if (utime(file, ×) < 0) { streamID = open(file, O_RDWR | O_CREAT, 0666); if (streamID >= 0) { @@ -1170,7 +1170,7 @@ Job_Touch(GNode *gn, Boolean silent) * modification time, then close the file. */ if (read(streamID, &c, 1) == 1) { - (void)lseek(streamID, (off_t)0, SEEK_SET); + (void)lseek(streamID, 0, SEEK_SET); while (write(streamID, &c, 1) == -1 && errno == EAGAIN) continue; } @@ -1211,8 +1211,8 @@ Job_CheckCommands(GNode *gn, void (*abor * No commands. Look for .DEFAULT rule from which we might infer * commands */ - if ((DEFAULT != NULL) && !Lst_IsEmpty(DEFAULT->commands) && - (gn->type & OP_SPECIAL) == 0) { + if (DEFAULT != NULL && !Lst_IsEmpty(DEFAULT->commands) && + !(gn->type & OP_SPECIAL)) { /* * Make only looks for a .DEFAULT if the node was never the * target of an operator, so that's what we do too. If @@ -1337,7 +1337,7 @@ JobExec(Job *job, char **argv) execDie("dup2", "job->cmdFILE"); if (fcntl(0, F_SETFD, 0) == -1) execDie("fcntl clear close-on-exec", "stdin"); - if (lseek(0, (off_t)0, SEEK_SET) == -1) + if (lseek(0, 0, SEEK_SET) == -1) execDie("lseek to 0", "stdin"); if (job->node->type & (OP_MAKE | OP_SUBMAKE)) { @@ -1682,7 +1682,7 @@ JobOutput(Job *job, char *cp, char *endp { char *ecp; - if (commandShell->noPrint && commandShell->noPrint[0] != '\0') { + if (commandShell->noPrint != NULL && commandShell->noPrint[0] != '\0') { while ((ecp = strstr(cp, commandShell->noPrint)) != NULL) { if (cp != ecp) { *ecp = '\0'; @@ -1779,7 +1779,7 @@ end_loop: * output remaining in the buffer. * Also clear the 'finish' flag so we stop looping. */ - if ((nr == 0) && (job->curPos != 0)) { + if (nr == 0 && job->curPos != 0) { job->outBuf[job->curPos] = '\n'; nr = 1; finish = FALSE; @@ -2496,7 +2496,7 @@ JobInterrupt(int runINTERRUPT, int signo JobRun(interrupt); } } - Trace_Log(MAKEINTR, 0); + Trace_Log(MAKEINTR, NULL); exit(signo); } @@ -2843,7 +2843,7 @@ emul_poll(struct pollfd *fd, int nfd, in tvp = &tv; } - nselect = select(maxfd + 1, &rfds, &wfds, 0, tvp); + nselect = select(maxfd + 1, &rfds, &wfds, NULL, tvp); if (nselect <= 0) return nselect; Index: src/usr.bin/make/main.c diff -u src/usr.bin/make/main.c:1.432 src/usr.bin/make/main.c:1.433 --- src/usr.bin/make/main.c:1.432 Fri Nov 6 23:11:11 2020 +++ src/usr.bin/make/main.c Sat Nov 7 10:16:18 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.432 2020/11/06 23:11:11 rillig Exp $ */ +/* $NetBSD: main.c,v 1.433 2020/11/07 10:16:18 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -118,7 +118,7 @@ #include "trace.h" /* "@(#)main.c 8.3 (Berkeley) 3/19/94" */ -MAKE_RCSID("$NetBSD: main.c,v 1.432 2020/11/06 23:11:11 rillig Exp $"); +MAKE_RCSID("$NetBSD: main.c,v 1.433 2020/11/07 10:16:18 rillig Exp $"); #if defined(MAKE_NATIVE) && !defined(lint) __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 " "The Regents of the University of California. " @@ -720,7 +720,7 @@ Main_SetObjdir(const char *fmt, ...) if (stat(path, &sb) == 0 && S_ISDIR(sb.st_mode)) { /* if not .CURDIR it must be writable */ if ((strcmp(path, curdir) != 0 && access(path, W_OK) != 0) || - chdir(path)) { + (chdir(path) != 0)) { (void)fprintf(stderr, "make warning: %s: %s.\n", path, strerror(errno)); } else { @@ -1181,9 +1181,9 @@ InitDefSysIncPath(char *syspath) for (start = syspath; *start != '\0'; start = cp) { for (cp = start; *cp != '\0' && *cp != ':'; cp++) continue; - if (*cp == ':') { + if (*cp == ':') *cp++ = '\0'; - } + /* look for magic parent directory search string */ if (strncmp(".../", start, 4) != 0) { (void)Dir_AddDir(defSysIncPath, start); @@ -1315,7 +1315,7 @@ CleanUp(void) if (DEBUG(GRAPH2)) Targ_PrintGraph(2); - Trace_Log(MAKEEND, 0); + Trace_Log(MAKEEND, NULL); if (enterFlagObj) printf("%s: Leaving directory `%s'\n", progname, objdir); @@ -1452,9 +1452,9 @@ main(int argc, char **argv) * Set some other useful macros */ { - char tmp[64], *ep; + char tmp[64], *ep = getenv(MAKE_LEVEL_ENV); - makelevel = ((ep = getenv(MAKE_LEVEL_ENV)) && *ep) ? atoi(ep) : 0; + makelevel = ep != NULL && ep[0] != '\0' ? atoi(ep) : 0; if (makelevel < 0) makelevel = 0; snprintf(tmp, sizeof tmp, "%d", makelevel); @@ -1858,7 +1858,7 @@ Fatal(const char *fmt, ...) if (DEBUG(GRAPH2) || DEBUG(GRAPH3)) Targ_PrintGraph(2); - Trace_Log(MAKEERROR, 0); + Trace_Log(MAKEERROR, NULL); exit(2); /* Not 1 so -q can distinguish error */ } @@ -1890,7 +1890,7 @@ DieHorribly(void) Job_AbortAll(); if (DEBUG(GRAPH2)) Targ_PrintGraph(2); - Trace_Log(MAKEERROR, 0); + Trace_Log(MAKEERROR, NULL); exit(2); /* Not 1, so -q can distinguish error */ } @@ -2032,7 +2032,7 @@ cached_realpath(const char *pathname, ch const char *rp; void *freeIt; - if (!pathname || !pathname[0]) + if (pathname == NULL || pathname[0] == '\0') return NULL; cache = get_cached_realpaths(); Index: src/usr.bin/make/make.c diff -u src/usr.bin/make/make.c:1.186 src/usr.bin/make/make.c:1.187 --- src/usr.bin/make/make.c:1.186 Sun Nov 1 17:47:26 2020 +++ src/usr.bin/make/make.c Sat Nov 7 10:16:18 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: make.c,v 1.186 2020/11/01 17:47:26 rillig Exp $ */ +/* $NetBSD: make.c,v 1.187 2020/11/07 10:16:18 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -107,7 +107,7 @@ #include "job.h" /* "@(#)make.c 8.1 (Berkeley) 6/6/93" */ -MAKE_RCSID("$NetBSD: make.c,v 1.186 2020/11/01 17:47:26 rillig Exp $"); +MAKE_RCSID("$NetBSD: make.c,v 1.187 2020/11/07 10:16:18 rillig Exp $"); /* Sequence # to detect recursion. */ static unsigned int checked = 1; @@ -212,7 +212,7 @@ Make_OODate(GNode *gn) * Certain types of targets needn't even be sought as their datedness * doesn't depend on their modification time... */ - if ((gn->type & (OP_JOIN|OP_USE|OP_USEBEFORE|OP_EXEC)) == 0) { + if (!(gn->type & (OP_JOIN|OP_USE|OP_USEBEFORE|OP_EXEC))) { (void)Dir_MTime(gn, 1); if (DEBUG(MAKE)) { if (gn->mtime != 0) { @@ -346,7 +346,7 @@ MakeAddChild(void *gnp, void *lp) GNode *gn = gnp; GNodeList *l = lp; - if ((gn->flags & REMAKE) == 0 && !(gn->type & (OP_USE|OP_USEBEFORE))) { + if (!(gn->flags & REMAKE) && !(gn->type & (OP_USE|OP_USEBEFORE))) { DEBUG2(MAKE, "MakeAddChild: need to examine %s%s\n", gn->name, gn->cohort_num); Lst_Enqueue(l, gn); @@ -394,9 +394,9 @@ Make_HandleUse(GNode *cgn, GNode *pgn) GNodeListNode *ln; /* An element in the children list */ #ifdef DEBUG_SRC - if ((cgn->type & (OP_USE|OP_USEBEFORE|OP_TRANSFORM)) == 0) { + if (!(cgn->type & (OP_USE|OP_USEBEFORE|OP_TRANSFORM))) { debug_printf("Make_HandleUse: called for plain node %s\n", cgn->name); - return; + return; /* XXX: debug mode should not affect control flow */ } #endif @@ -457,10 +457,10 @@ MakeHandleUse(GNode *cgn, GNode *pgn, GN { Boolean unmarked; - unmarked = ((cgn->type & OP_MARK) == 0); + unmarked = !(cgn->type & OP_MARK); cgn->type |= OP_MARK; - if ((cgn->type & (OP_USE|OP_USEBEFORE)) == 0) + if (!(cgn->type & (OP_USE|OP_USEBEFORE))) return; if (unmarked) @@ -717,7 +717,7 @@ Make_Update(GNode *cgn) continue; } assert(pgn->order_pred != NULL); - if (Lst_ForEachUntil(pgn->order_pred, MakeCheckOrder, 0)) { + if (Lst_ForEachUntil(pgn->order_pred, MakeCheckOrder, NULL)) { /* A .ORDER rule stops us building this */ continue; } @@ -771,7 +771,7 @@ MakeAddAllSrc(GNode *cgn, GNode *pgn) return; cgn->type |= OP_MARK; - if ((cgn->type & (OP_EXEC|OP_USE|OP_USEBEFORE|OP_INVISIBLE)) == 0) { + if (!(cgn->type & (OP_EXEC|OP_USE|OP_USEBEFORE|OP_INVISIBLE))) { const char *child, *allsrc; if (cgn->type & OP_ARCHV) @@ -875,7 +875,7 @@ MakeBuildChild(void *v_cn, void *toBeMad /* If this node is on the RHS of a .ORDER, check LHSs. */ assert(cn->order_pred); - if (Lst_ForEachUntil(cn->order_pred, MakeCheckOrder, 0)) { + if (Lst_ForEachUntil(cn->order_pred, MakeCheckOrder, NULL)) { /* Can't build this (or anything else in this child list) yet */ cn->made = DEFERRED; return 0; /* but keep looking */ @@ -1169,7 +1169,7 @@ Make_ExpandUse(GNodeList *targs) UnmarkChildren(gn); HandleUseNodes(gn); - if ((gn->type & OP_MADE) == 0) + if (!(gn->type & OP_MADE)) Suff_FindDeps(gn); else { /* Pretend we made all this node's children */ @@ -1353,7 +1353,7 @@ Make_Run(GNodeList *targs) MakePrintStatusList(targs, &errors); if (DEBUG(MAKE)) { debug_printf("done: errors %d\n", errors); - if (errors) + if (errors != 0) Targ_PrintGraph(4); } } Index: src/usr.bin/make/meta.c diff -u src/usr.bin/make/meta.c:1.138 src/usr.bin/make/meta.c:1.139 --- src/usr.bin/make/meta.c:1.138 Thu Nov 5 17:27:16 2020 +++ src/usr.bin/make/meta.c Sat Nov 7 10:16:19 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: meta.c,v 1.138 2020/11/05 17:27:16 rillig Exp $ */ +/* $NetBSD: meta.c,v 1.139 2020/11/07 10:16:19 rillig Exp $ */ /* * Implement 'meta' mode. @@ -92,7 +92,7 @@ extern char **environ; #endif #if !defined(HAVE_STRSEP) -# define strsep(s, d) stresep((s), (d), 0) +# define strsep(s, d) stresep((s), (d), '\0') #endif /* @@ -336,7 +336,7 @@ is_submake(void *cmdp, void *gnp) cmd = mp; } cp2 = strstr(cmd, p_make); - if ((cp2)) { + if (cp2 != NULL) { switch (cp2[p_len]) { case '\0': case ' ': @@ -795,7 +795,7 @@ meta_job_error(Job *job, GNode *gn, int } getcwd(cwd, sizeof cwd); Var_Set(".ERROR_CWD", cwd, VAR_GLOBAL); - if (pbm->meta_fname[0]) { + if (pbm->meta_fname[0] != '\0') { Var_Set(".ERROR_META_FILE", pbm->meta_fname, VAR_GLOBAL); } meta_job_finish(job); @@ -846,7 +846,7 @@ meta_cmd_finish(void *pbmp) int x; #endif - if (!pbm) + if (pbm == NULL) pbm = &Mybm; #ifdef USE_FILEMON @@ -1532,10 +1532,10 @@ meta_oodate(GNode *gn, Boolean oodate) if (buf[x - 1] == '\n') buf[x - 1] = '\0'; } - if (p && + if (p != NULL && !hasOODATE && !(gn->type & OP_NOMETA_CMP) && - strcmp(p, cmd) != 0) { + (strcmp(p, cmd) != 0)) { DEBUG4(META, "%s: %d: a build command has changed\n%s\nvs\n%s\n", fname, lineno, p, cmd); if (!metaIgnoreCMDs) Index: src/usr.bin/make/nonints.h diff -u src/usr.bin/make/nonints.h:1.153 src/usr.bin/make/nonints.h:1.154 --- src/usr.bin/make/nonints.h:1.153 Sat Nov 7 00:06:13 2020 +++ src/usr.bin/make/nonints.h Sat Nov 7 10:16:19 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: nonints.h,v 1.153 2020/11/07 00:06:13 rillig Exp $ */ +/* $NetBSD: nonints.h,v 1.154 2020/11/07 10:16:19 rillig Exp $ */ /*- * Copyright (c) 1988, 1989, 1990, 1993 @@ -216,19 +216,21 @@ void Var_End(void); typedef enum VarEvalFlags { VARE_NONE = 0, /* Treat undefined variables as errors. */ - VARE_UNDEFERR = 0x01, + VARE_UNDEFERR = 1 << 0, /* Expand and evaluate variables during parsing. */ - VARE_WANTRES = 0x02, + VARE_WANTRES = 1 << 1, /* In an assignment using the ':=' operator, keep '$$' as '$$' instead * of reducing it to a single '$'. */ - VARE_ASSIGN = 0x04 + VARE_ASSIGN = 1 << 2 } VarEvalFlags; typedef enum VarSet_Flags { - VAR_NO_EXPORT = 0x01, /* do not export */ + /* do not export */ + VAR_NO_EXPORT = 1 << 0, + /* Make the variable read-only. No further modification is possible, * except for another call to Var_Set with the same flag. */ - VAR_SET_READONLY = 0x02 + VAR_SET_READONLY = 1 << 1 } VarSetFlags; /* The state of error handling returned by Var_Parse. Index: src/usr.bin/make/parse.c diff -u src/usr.bin/make/parse.c:1.427 src/usr.bin/make/parse.c:1.428 --- src/usr.bin/make/parse.c:1.427 Thu Nov 5 17:27:16 2020 +++ src/usr.bin/make/parse.c Sat Nov 7 10:16:19 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: parse.c,v 1.427 2020/11/05 17:27:16 rillig Exp $ */ +/* $NetBSD: parse.c,v 1.428 2020/11/07 10:16:19 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -117,7 +117,7 @@ #include "pathnames.h" /* "@(#)parse.c 8.3 (Berkeley) 3/19/94" */ -MAKE_RCSID("$NetBSD: parse.c,v 1.427 2020/11/05 17:27:16 rillig Exp $"); +MAKE_RCSID("$NetBSD: parse.c,v 1.428 2020/11/07 10:16:19 rillig Exp $"); /* types and constants */ @@ -522,7 +522,7 @@ loadfile(const char *path, int fd) lf->buf = bmake_malloc(lf->len); bufpos = 0; - while (1) { + for (;;) { assert(bufpos <= lf->len); if (bufpos == lf->len) { if (lf->len > SIZE_MAX/2) { @@ -2502,7 +2502,7 @@ static void ParseTraditionalInclude(char *line) { char *cp; /* current position in file spec */ - int done = 0; + Boolean done = FALSE; int silent = line[0] != 'i'; char *file = line + (silent ? 8 : 7); char *all_files; @@ -2528,10 +2528,10 @@ ParseTraditionalInclude(char *line) for (cp = file; *cp && !ch_isspace(*cp); cp++) continue; - if (*cp) + if (*cp != '\0') *cp = '\0'; else - done = 1; + done = TRUE; Parse_include_file(file, FALSE, FALSE, silent); } @@ -2659,11 +2659,11 @@ ParseGetLine(int flags) /* XXX: can buf_end ever be null? */ if (cf->buf_end != NULL && ptr == cf->buf_end) { /* end of buffer */ - ch = 0; + ch = '\0'; break; } ch = *ptr; - if (ch == 0 || (ch == '\\' && ptr[1] == 0)) { + if (ch == '\0' || (ch == '\\' && ptr[1] == '\0')) { /* XXX: can buf_end ever be null? */ if (cf->buf_end == NULL) /* End of string (aka for loop) data */ @@ -2719,7 +2719,7 @@ ParseGetLine(int flags) /* Check we have a non-comment, non-blank line */ if (line_end == line || comment == line) { - if (ch == 0) + if (ch == '\0') /* At end of file */ return NULL; /* Parse another line */ @@ -2727,7 +2727,7 @@ ParseGetLine(int flags) } /* We now have a line of data */ - *line_end = 0; + *line_end = '\0'; if (flags & PARSE_RAW) { /* Leave '\' (etc) in line buffer (eg 'for' lines) */ @@ -2746,7 +2746,7 @@ ParseGetLine(int flags) /* Brutally ignore anything after a non-escaped '#' in non-commands */ if (comment != NULL && line[0] != '\t') { line_end = comment; - *line_end = 0; + *line_end = '\0'; } /* If we didn't see a '\\' then the in-situ data is fine */ @@ -2759,13 +2759,13 @@ ParseGetLine(int flags) for (; ; *tp++ = ch) { ch = *ptr++; if (ch != '\\') { - if (ch == 0) + if (ch == '\0') break; continue; } ch = *ptr++; - if (ch == 0) { + if (ch == '\0') { /* Delete '\\' at end of buffer */ tp--; break; @@ -2793,7 +2793,7 @@ ParseGetLine(int flags) while (tp > escaped && ch_isspace(tp[-1])) tp--; - *tp = 0; + *tp = '\0'; return line; } Index: src/usr.bin/make/str.c diff -u src/usr.bin/make/str.c:1.70 src/usr.bin/make/str.c:1.71 --- src/usr.bin/make/str.c:1.70 Sat Oct 24 20:51:49 2020 +++ src/usr.bin/make/str.c Sat Nov 7 10:16:19 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: str.c,v 1.70 2020/10/24 20:51:49 rillig Exp $ */ +/* $NetBSD: str.c,v 1.71 2020/11/07 10:16:19 rillig Exp $ */ /*- * Copyright (c) 1988, 1989, 1990, 1993 @@ -71,7 +71,7 @@ #include "make.h" /* "@(#)str.c 5.8 (Berkeley) 6/1/90" */ -MAKE_RCSID("$NetBSD: str.c,v 1.70 2020/10/24 20:51:49 rillig Exp $"); +MAKE_RCSID("$NetBSD: str.c,v 1.71 2020/11/07 10:16:19 rillig Exp $"); /* Return the concatenation of s1 and s2, freshly allocated. */ char * @@ -289,9 +289,9 @@ Str_Match(const char *str, const char *p * string. If, we succeeded. If we're at the end of the * pattern but not at the end of the string, we failed. */ - if (*pat == 0) - return *str == 0; - if (*str == 0 && *pat != '*') + if (*pat == '\0') + return *str == '\0'; + if (*str == '\0' && *pat != '*') return FALSE; /* @@ -302,9 +302,9 @@ Str_Match(const char *str, const char *p pat++; while (*pat == '*') pat++; - if (*pat == 0) + if (*pat == '\0') return TRUE; - while (*str != 0) { + while (*str != '\0') { if (Str_Match(str, pat)) return TRUE; str++; @@ -327,7 +327,7 @@ Str_Match(const char *str, const char *p pat += neg ? 2 : 1; for (;;) { - if (*pat == ']' || *pat == 0) { + if (*pat == ']' || *pat == '\0') { if (neg) break; return FALSE; @@ -335,7 +335,7 @@ Str_Match(const char *str, const char *p if (*pat == *str) break; if (pat[1] == '-') { - if (pat[2] == 0) + if (pat[2] == '\0') return neg; if (*pat <= *str && pat[2] >= *str) break; @@ -345,11 +345,11 @@ Str_Match(const char *str, const char *p } pat++; } - if (neg && *pat != ']' && *pat != 0) + if (neg && *pat != ']' && *pat != '\0') return FALSE; - while (*pat != ']' && *pat != 0) + while (*pat != ']' && *pat != '\0') pat++; - if (*pat == 0) + if (*pat == '\0') pat--; goto thisCharOK; } @@ -360,7 +360,7 @@ Str_Match(const char *str, const char *p */ if (*pat == '\\') { pat++; - if (*pat == 0) + if (*pat == '\0') return FALSE; } Index: src/usr.bin/make/var.c diff -u src/usr.bin/make/var.c:1.671 src/usr.bin/make/var.c:1.672 --- src/usr.bin/make/var.c:1.671 Sat Nov 7 00:06:13 2020 +++ src/usr.bin/make/var.c Sat Nov 7 10:16:19 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: var.c,v 1.671 2020/11/07 00:06:13 rillig Exp $ */ +/* $NetBSD: var.c,v 1.672 2020/11/07 10:16:19 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -130,7 +130,7 @@ #include "metachar.h" /* "@(#)var.c 8.3 (Berkeley) 3/19/94" */ -MAKE_RCSID("$NetBSD: var.c,v 1.671 2020/11/07 00:06:13 rillig Exp $"); +MAKE_RCSID("$NetBSD: var.c,v 1.672 2020/11/07 10:16:19 rillig Exp $"); #define VAR_DEBUG1(fmt, arg1) DEBUG1(VAR, fmt, arg1) #define VAR_DEBUG2(fmt, arg1, arg2) DEBUG2(VAR, fmt, arg1, arg2) @@ -518,7 +518,7 @@ Var_Export1(const char *name, VarExportF if (!MayExport(name)) return FALSE; - v = VarFind(name, VAR_GLOBAL, 0); + v = VarFind(name, VAR_GLOBAL, FALSE); if (v == NULL) return FALSE; @@ -728,7 +728,7 @@ Var_UnExport(const char *str) Words words = Str_Words(varnames, FALSE); for (i = 0; i < words.len; i++) { const char *varname = words.words[i]; - v = VarFind(varname, VAR_GLOBAL, 0); + v = VarFind(varname, VAR_GLOBAL, FALSE); if (v == NULL) { VAR_DEBUG1("Not unexporting \"%s\" (not found)\n", varname); continue; @@ -791,7 +791,7 @@ Var_SetWithFlags(const char *name, const } if (ctxt == VAR_GLOBAL) { - v = VarFind(name, VAR_CMDLINE, 0); + v = VarFind(name, VAR_CMDLINE, FALSE); if (v != NULL) { if (v->flags & VAR_FROM_CMD) { VAR_DEBUG3("%s:%s = %s ignored!\n", ctxt->name, name, val); @@ -806,7 +806,7 @@ Var_SetWithFlags(const char *name, const * here will override anything in a lower context, so there's not much * point in searching them all just to save a bit of memory... */ - v = VarFind(name, ctxt, 0); + v = VarFind(name, ctxt, FALSE); if (v == NULL) { if (ctxt == VAR_CMDLINE && !(flags & VAR_NO_EXPORT)) { /* @@ -839,7 +839,7 @@ Var_SetWithFlags(const char *name, const */ if (ctxt == VAR_CMDLINE && !(flags & VAR_NO_EXPORT) && name[0] != '.') { if (v == NULL) - v = VarFind(name, ctxt, 0); /* we just added it */ + v = VarFind(name, ctxt, FALSE); /* we just added it */ v->flags |= VAR_FROM_CMD; /* @@ -1341,9 +1341,9 @@ nosub: #ifndef NO_REGEX /* Print the error caused by a regcomp or regexec call. */ static void -VarREError(int reerr, regex_t *pat, const char *str) +VarREError(int reerr, const regex_t *pat, const char *str) { - size_t errlen = regerror(reerr, pat, 0, 0); + size_t errlen = regerror(reerr, pat, NULL, 0); char *errbuf = bmake_malloc(errlen); regerror(reerr, pat, errbuf, errlen); Error("%s: %s", str, errbuf); @@ -2959,7 +2959,7 @@ ok: v_ctxt = st->ctxt; /* context where v belongs */ if (!(st->exprFlags & VEF_UNDEF) && st->ctxt != VAR_GLOBAL) { - Var *gv = VarFind(st->v->name, st->ctxt, 0); + Var *gv = VarFind(st->v->name, st->ctxt, FALSE); if (gv == NULL) v_ctxt = VAR_GLOBAL; else @@ -3631,7 +3631,7 @@ FindLocalLegacyVar(const char *varname, { char name[] = { varname[0], '\0' }; - Var *v = VarFind(name, ctxt, 0); + Var *v = VarFind(name, ctxt, FALSE); if (v != NULL) { if (varname[1] == 'D') {