Module Name: src Committed By: rillig Date: Fri Jan 7 20:37:25 UTC 2022
Modified Files: src/usr.bin/make: main.c parse.c targ.c var.c Log Message: make: clean up comments, variable names, function names The comment in ApplyDependencySourceOther repeated the code, its second half didn't match any current code. The comment above ParseDependencySourcesEmpty repeated the code. No binary change, except for assertion line numbers. To generate a diff of this commit: cvs rdiff -u -r1.565 -r1.566 src/usr.bin/make/main.c cvs rdiff -u -r1.629 -r1.630 src/usr.bin/make/parse.c cvs rdiff -u -r1.174 -r1.175 src/usr.bin/make/targ.c cvs rdiff -u -r1.995 -r1.996 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/main.c diff -u src/usr.bin/make/main.c:1.565 src/usr.bin/make/main.c:1.566 --- src/usr.bin/make/main.c:1.565 Sat Jan 1 21:41:50 2022 +++ src/usr.bin/make/main.c Fri Jan 7 20:37:25 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.565 2022/01/01 21:41:50 rillig Exp $ */ +/* $NetBSD: main.c,v 1.566 2022/01/07 20:37:25 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -111,7 +111,7 @@ #include "trace.h" /* "@(#)main.c 8.3 (Berkeley) 3/19/94" */ -MAKE_RCSID("$NetBSD: main.c,v 1.565 2022/01/01 21:41:50 rillig Exp $"); +MAKE_RCSID("$NetBSD: main.c,v 1.566 2022/01/07 20:37:25 rillig Exp $"); #if defined(MAKE_NATIVE) && !defined(lint) __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 " "The Regents of the University of California. " @@ -1799,22 +1799,22 @@ void Error(const char *fmt, ...) { va_list ap; - FILE *err_file; + FILE *f; - err_file = opts.debug_file; - if (err_file == stdout) - err_file = stderr; + f = opts.debug_file; + if (f == stdout) + f = stderr; (void)fflush(stdout); for (;;) { va_start(ap, fmt); - fprintf(err_file, "%s: ", progname); - (void)vfprintf(err_file, fmt, ap); + fprintf(f, "%s: ", progname); + (void)vfprintf(f, fmt, ap); va_end(ap); - (void)fprintf(err_file, "\n"); - (void)fflush(err_file); - if (err_file == stderr) + (void)fprintf(f, "\n"); + (void)fflush(f); + if (f == stderr) break; - err_file = stderr; + f = stderr; } main_errors++; } @@ -2093,21 +2093,21 @@ void Main_ExportMAKEFLAGS(bool first) { static bool once = true; - const char *expr; - char *s; + char *flags; if (once != first) return; once = false; - expr = "${.MAKEFLAGS} ${.MAKEOVERRIDES:O:u:@v@$v=${$v:Q}@}"; - (void)Var_Subst(expr, SCOPE_CMDLINE, VARE_WANTRES, &s); + (void)Var_Subst( + "${.MAKEFLAGS} ${.MAKEOVERRIDES:O:u:@v@$v=${$v:Q}@}", + SCOPE_CMDLINE, VARE_WANTRES, &flags); /* TODO: handle errors */ - if (s[0] != '\0') { + if (flags[0] != '\0') { #ifdef POSIX - setenv("MAKEFLAGS", s, 1); + setenv("MAKEFLAGS", flags, 1); #else - setenv("MAKE", s, 1); + setenv("MAKE", flags, 1); #endif } } @@ -2121,7 +2121,7 @@ getTmpdir(void) if (tmpdir != NULL) return tmpdir; - /* Honor $TMPDIR but only if it is valid. Ensure it ends with '/'. */ + /* Honor $TMPDIR if it is valid, strip a trailing '/'. */ (void)Var_Subst("${TMPDIR:tA:U" _PATH_TMP ":S,/$,,W}/", SCOPE_GLOBAL, VARE_WANTRES, &tmpdir); /* TODO: handle errors */ Index: src/usr.bin/make/parse.c diff -u src/usr.bin/make/parse.c:1.629 src/usr.bin/make/parse.c:1.630 --- src/usr.bin/make/parse.c:1.629 Fri Jan 7 20:09:58 2022 +++ src/usr.bin/make/parse.c Fri Jan 7 20:37:25 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: parse.c,v 1.629 2022/01/07 20:09:58 rillig Exp $ */ +/* $NetBSD: parse.c,v 1.630 2022/01/07 20:37:25 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -106,7 +106,7 @@ #include "pathnames.h" /* "@(#)parse.c 8.3 (Berkeley) 3/19/94" */ -MAKE_RCSID("$NetBSD: parse.c,v 1.629 2022/01/07 20:09:58 rillig Exp $"); +MAKE_RCSID("$NetBSD: parse.c,v 1.630 2022/01/07 20:37:25 rillig Exp $"); /* * A file being read. @@ -334,7 +334,7 @@ loadfile(const char *path, int fd) if (!Buf_EndsWith(&buf, '\n')) Buf_AddByte(&buf, '\n'); - return buf; + return buf; /* may not be null-terminated */ } static void @@ -568,11 +568,9 @@ HandleMessage(ParseErrorLevel level, con } /* - * Add the child to the parent's children. - * - * Additionally, add the parent to the child's parents, but only if the - * target is not special. An example for such a special target is .END, - * which does not need to be informed once the child target has been made. + * Add the child to the parent's children, and for non-special targets, vice + * versa. Special targets such as .END do not need to be informed once the + * child target has been made. */ static void LinkSource(GNode *pgn, GNode *cgn, bool isSpecial) @@ -728,17 +726,17 @@ ApplyDependencySourceKeyword(const char return false; } +/* + * In a line like ".MAIN: source1 source2", add all sources to the list of + * things to create, but only if the user didn't specify a target on the + * command line and .MAIN occurs for the first time. + * + * See HandleDependencyTargetSpecial, branch SP_MAIN. + * See unit-tests/cond-func-make-main.mk. + */ static void ApplyDependencySourceMain(const char *src) { - /* - * In a line like ".MAIN: source1 source2", add all sources to the - * list of things to create, but only if the user didn't specify a - * target on the command line and .MAIN occurs for the first time. - * - * See HandleDependencyTargetSpecial, branch SP_MAIN. - * See unit-tests/cond-func-make-main.mk. - */ Lst_Append(&opts.create, bmake_strdup(src)); /* * Add the name to the .TARGETS variable as well, so the user can @@ -775,24 +773,13 @@ ApplyDependencySourceOrder(const char *s order_pred = gn; } +/* The source is not an attribute, so find/create a node for it. */ static void ApplyDependencySourceOther(const char *src, GNodeType targetAttr, ParseSpecial special) { GNode *gn; - /* - * The source is not an attribute, so find/create a node for it. - * After that, apply any operator to it from a special target or - * link it to its parents, as appropriate. - * - * In the case of a source that was the object of a '::' operator, - * the attribute is applied to all of its instances (as kept in - * the 'cohorts' list of the node) or all the cohorts are linked - * to all the targets. - */ - - /* Find/create the 'src' node and attach to all targets */ gn = Targ_GetNode(src); if (doing_depend) RememberLocation(gn); @@ -830,7 +817,7 @@ ApplyDependencySource(GNodeType targetAt * actually a real target (i.e. isn't a .USE or .EXEC rule) to be made. */ static void -FindMainTarget(void) +MaybeUpdateMainTarget(void) { GNodeListNode *ln; @@ -849,15 +836,15 @@ FindMainTarget(void) } static void -InvalidLineType(const char *lstart) +InvalidLineType(const char *line) { - if ((strncmp(lstart, "<<<<<<", 6) == 0) || - (strncmp(lstart, "======", 6) == 0) || - (strncmp(lstart, ">>>>>>", 6) == 0)) + if (strncmp(line, "<<<<<<", 6) == 0 || + strncmp(line, "======", 6) == 0 || + strncmp(line, ">>>>>>", 6) == 0) Parse_Error(PARSE_FATAL, "Makefile appears to contain unresolved CVS/RCS/??? merge conflicts"); - else if (lstart[0] == '.') { - const char *dirstart = lstart + 1; + else if (line[0] == '.') { + const char *dirstart = line + 1; const char *dirend; cpp_skip_whitespace(&dirstart); dirend = dirstart; @@ -1106,7 +1093,7 @@ ParseDependencyOp(char **pp) if (**pp == '!') return (*pp)++, OP_FORCE; if ((*pp)[1] == ':') - return (*pp) += 2, OP_DOUBLEDEP; + return *pp += 2, OP_DOUBLEDEP; else return (*pp)++, OP_DEPENDS; } @@ -1123,17 +1110,9 @@ ClearPaths(SearchPathList *paths) Dir_SetPATH(); } -/* - * Several special targets take different actions if present with no - * sources: - * a .SUFFIXES line with no sources clears out all old suffixes - * a .PRECIOUS line makes all targets precious - * a .IGNORE line ignores errors for all targets - * a .SILENT line creates silence when making all targets - * a .PATH removes all directories from the search path(s). - */ +/* Handle a "dependency" line like '.SPECIAL:' without any sources. */ static void -ParseDependencySourcesEmpty(ParseSpecial special, SearchPathList *paths) +HandleDependencySourcesEmpty(ParseSpecial special, SearchPathList *paths) { switch (special) { case SP_SUFFIXES: @@ -1364,7 +1343,7 @@ ParseDependencySources(char *p, GNodeTyp ParseSpecial special, SearchPathList **inout_paths) { if (*p == '\0') { - ParseDependencySourcesEmpty(special, *inout_paths); + HandleDependencySourcesEmpty(special, *inout_paths); } else if (special == SP_MFLAGS) { Main_ParseArgLine(p); return; @@ -1397,7 +1376,7 @@ ParseDependencySources(char *p, GNodeTyp return; } - FindMainTarget(); + MaybeUpdateMainTarget(); } /* @@ -1621,6 +1600,7 @@ VarCheckSyntax(VarAssignOp type, const c } } +/* Perform a variable assignment that uses the operator ':='. */ static void VarAssign_EvalSubst(GNode *scope, const char *name, const char *uvalue, FStr *out_avalue) @@ -1633,6 +1613,7 @@ VarAssign_EvalSubst(GNode *scope, const * * TODO: Add a test that demonstrates why this code is needed, * apart from making the debug log longer. + * XXX: The variable name is expanded up to 3 times. */ if (!Var_ExistsExpand(scope, name)) Var_SetExpand(scope, name, ""); @@ -1645,6 +1626,7 @@ VarAssign_EvalSubst(GNode *scope, const *out_avalue = FStr_InitOwn(evalue); } +/* Perform a variable assignment that uses the operator '!='. */ static void VarAssign_EvalShell(const char *name, const char *uvalue, GNode *scope, FStr *out_avalue) @@ -1696,6 +1678,7 @@ VarAssign_Eval(const char *name, VarAssi else if (op == VAR_SHELL) VarAssign_EvalShell(name, uvalue, scope, &avalue); else { + /* XXX: The variable name is expanded up to 2 times. */ if (op == VAR_DEFAULT && Var_ExistsExpand(scope, name)) return false; @@ -2113,11 +2096,7 @@ TrackInput(const char *name) } -/* - * Start parsing from the given source. - * - * The given file is added to the includes stack. - */ +/* Parse from the given buffer, later return to the current file. */ void Parse_PushInput(const char *name, int lineno, Buffer buf, struct ForLoop *forLoop) @@ -2592,9 +2571,8 @@ ParseForLoop(const char *line) * leaving only variable assignments, other directives, dependency lines * and shell commands to the caller. * - * Results: - * A line without its newline and without any trailing whitespace, - * or NULL. + * Return a line without without trailing whitespace, or NULL for EOF. The + * caller must not free the returned line. */ static char * ReadHighLevelLine(void) Index: src/usr.bin/make/targ.c diff -u src/usr.bin/make/targ.c:1.174 src/usr.bin/make/targ.c:1.175 --- src/usr.bin/make/targ.c:1.174 Fri Jan 7 19:24:27 2022 +++ src/usr.bin/make/targ.c Fri Jan 7 20:37:25 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: targ.c,v 1.174 2022/01/07 19:24:27 rillig Exp $ */ +/* $NetBSD: targ.c,v 1.175 2022/01/07 20:37:25 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -78,10 +78,8 @@ * * Targ_List Return the list of all targets so far. * - * GNode_New Create a new GNode for the passed target - * (string). The node is *not* placed in the - * hash table, though all its fields are - * initialized. + * GNode_New Create a new GNode with the given name, don't add it + * to allNodes. * * Targ_FindNode Find the node, or return NULL. * @@ -100,8 +98,7 @@ * Debugging: * Targ_PrintGraph * Print out the entire graph, all variables and - * statistics for the directory cache. Should print - * something for suffixes, too, but... + * statistics for the directory cache. */ #include <time.h> @@ -110,7 +107,7 @@ #include "dir.h" /* "@(#)targ.c 8.2 (Berkeley) 3/19/94" */ -MAKE_RCSID("$NetBSD: targ.c,v 1.174 2022/01/07 19:24:27 rillig Exp $"); +MAKE_RCSID("$NetBSD: targ.c,v 1.175 2022/01/07 20:37:25 rillig Exp $"); /* * All target nodes that appeared on the left-hand side of one of the @@ -545,7 +542,6 @@ Targ_PrintNodes(GNodeList *gnodes, int p Targ_PrintNode(ln->datum, pass); } -/* Print only those targets that are just a source. */ static void PrintOnlySources(void) { Index: src/usr.bin/make/var.c diff -u src/usr.bin/make/var.c:1.995 src/usr.bin/make/var.c:1.996 --- src/usr.bin/make/var.c:1.995 Fri Jan 7 12:44:57 2022 +++ src/usr.bin/make/var.c Fri Jan 7 20:37:25 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: var.c,v 1.995 2022/01/07 12:44:57 rillig Exp $ */ +/* $NetBSD: var.c,v 1.996 2022/01/07 20:37:25 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -140,7 +140,7 @@ #include "metachar.h" /* "@(#)var.c 8.3 (Berkeley) 3/19/94" */ -MAKE_RCSID("$NetBSD: var.c,v 1.995 2022/01/07 12:44:57 rillig Exp $"); +MAKE_RCSID("$NetBSD: var.c,v 1.996 2022/01/07 20:37:25 rillig Exp $"); /* * Variables are defined using one of the VAR=value assignments. Their @@ -153,7 +153,8 @@ MAKE_RCSID("$NetBSD: var.c,v 1.995 2022/ * Scope variables are stored in a GNode.scope. The only way to undefine * a scope variable is using the .undef directive. In particular, it must * not be possible to undefine a variable during the evaluation of an - * expression, or Var.name might point nowhere. + * expression, or Var.name might point nowhere. (There is another, + * unintended way to undefine a scope variable, see varmod-loop-delete.mk.) * * Environment variables are short-lived. They are returned by VarFind, and * after using them, they must be freed using VarFreeShortLived. @@ -2838,7 +2839,7 @@ ParseModifier_Match(const char **pp, con static ApplyModifierResult ApplyModifier_Match(const char **pp, ModChain *ch) { - const char mod = **pp; + char mod = **pp; char *pattern; ParseModifier_Match(pp, ch, &pattern); @@ -3389,9 +3390,8 @@ ApplyModifier_Order(const char **pp, Mod else goto bad; *pp += 3; - } else { + } else goto bad; - } if (!ModChain_ShouldEval(ch)) return AMR_OK;