make(1): inline Lst_ForEachUntil in meta mode
This means no more unnecessary void pointers in function signatures and no more abstraction level at checking a single element of a list. In most cases it is more appropriate to define a function that operates on the list as a whole, thereby hiding implementation details like the ListNode from the caller.
This commit is contained in:
parent
6da5d62c3f
commit
a41e5257d9
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: lst.c,v 1.93 2020/11/24 19:46:29 rillig Exp $ */
|
||||
/* $NetBSD: lst.c,v 1.94 2020/11/27 08:07:26 rillig Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1988, 1989, 1990, 1993
|
||||
@ -34,7 +34,7 @@
|
||||
|
||||
#include "make.h"
|
||||
|
||||
MAKE_RCSID("$NetBSD: lst.c,v 1.93 2020/11/24 19:46:29 rillig Exp $");
|
||||
MAKE_RCSID("$NetBSD: lst.c,v 1.94 2020/11/27 08:07:26 rillig Exp $");
|
||||
|
||||
static ListNode *
|
||||
LstNodeNew(ListNode *prev, ListNode *next, void *datum)
|
||||
@ -198,20 +198,6 @@ Lst_FindDatum(List *list, const void *datum)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int
|
||||
Lst_ForEachUntil(List *list, LstActionUntilProc proc, void *procData)
|
||||
{
|
||||
ListNode *ln;
|
||||
int result = 0;
|
||||
|
||||
for (ln = list->first; ln != NULL; ln = ln->next) {
|
||||
result = proc(ln->datum, procData);
|
||||
if (result != 0)
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Move all nodes from src to the end of dst.
|
||||
* The source list is destroyed and freed. */
|
||||
void
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: lst.h,v 1.86 2020/11/24 19:46:29 rillig Exp $ */
|
||||
/* $NetBSD: lst.h,v 1.87 2020/11/27 08:07:26 rillig Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
|
||||
@ -104,8 +104,6 @@ struct List {
|
||||
|
||||
/* Free the datum of a node, called before freeing the node itself. */
|
||||
typedef void LstFreeProc(void *);
|
||||
/* An action for Lst_ForEachUntil and Lst_ForEachUntilConcurrent. */
|
||||
typedef int LstActionUntilProc(void *datum, void *args);
|
||||
|
||||
/* Create or destroy a list */
|
||||
|
||||
@ -146,14 +144,6 @@ void LstNode_Set(ListNode *, void *);
|
||||
/* Set the value of the node to NULL. Having NULL in a list is unusual. */
|
||||
void LstNode_SetNull(ListNode *);
|
||||
|
||||
/* Iterating over a list, using a callback function */
|
||||
|
||||
/* Run the action for each datum of the list, until the action returns
|
||||
* non-zero.
|
||||
*
|
||||
* During this iteration, the list must not be modified structurally. */
|
||||
int Lst_ForEachUntil(List *, LstActionUntilProc, void *);
|
||||
|
||||
/* Using the list as a queue */
|
||||
|
||||
/* Add a datum at the tail of the queue. */
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: make.c,v 1.217 2020/11/24 23:13:09 rillig Exp $ */
|
||||
/* $NetBSD: make.c,v 1.218 2020/11/27 08:07:26 rillig Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1988, 1989, 1990, 1993
|
||||
@ -102,7 +102,7 @@
|
||||
#include "job.h"
|
||||
|
||||
/* "@(#)make.c 8.1 (Berkeley) 6/6/93" */
|
||||
MAKE_RCSID("$NetBSD: make.c,v 1.217 2020/11/24 23:13:09 rillig Exp $");
|
||||
MAKE_RCSID("$NetBSD: make.c,v 1.218 2020/11/27 08:07:26 rillig Exp $");
|
||||
|
||||
/* Sequence # to detect recursion. */
|
||||
static unsigned int checked_seqno = 1;
|
||||
@ -1032,9 +1032,9 @@ MakePrintStatusOrder(GNode *gn)
|
||||
|
||||
static void MakePrintStatusList(GNodeList *, int *);
|
||||
|
||||
/* Print the status of a top-level node, viz. it being up-to-date already
|
||||
/*
|
||||
* Print the status of a top-level node, viz. it being up-to-date already
|
||||
* or not created due to an error in a lower level.
|
||||
* Callback function for Make_Run via Lst_ForEachUntil.
|
||||
*/
|
||||
static Boolean
|
||||
MakePrintStatus(GNode *gn, int *errors)
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: meta.c,v 1.148 2020/11/23 23:44:03 rillig Exp $ */
|
||||
/* $NetBSD: meta.c,v 1.149 2020/11/27 08:07:26 rillig Exp $ */
|
||||
|
||||
/*
|
||||
* Implement 'meta' mode.
|
||||
@ -312,17 +312,15 @@ meta_name(char *mname, size_t mnamelen,
|
||||
* Return true if running ${.MAKE}
|
||||
* Bypassed if target is flagged .MAKE
|
||||
*/
|
||||
static int
|
||||
is_submake(void *cmdp, void *gnp)
|
||||
static Boolean
|
||||
is_submake(const char *cmd, GNode *gn)
|
||||
{
|
||||
static const char *p_make = NULL;
|
||||
static size_t p_len;
|
||||
char *cmd = cmdp;
|
||||
GNode *gn = gnp;
|
||||
char *mp = NULL;
|
||||
char *cp;
|
||||
char *cp2;
|
||||
int rc = 0; /* keep looking */
|
||||
Boolean rc = FALSE;
|
||||
|
||||
if (p_make == NULL) {
|
||||
void *dontFreeIt;
|
||||
@ -342,17 +340,17 @@ is_submake(void *cmdp, void *gnp)
|
||||
case ' ':
|
||||
case '\t':
|
||||
case '\n':
|
||||
rc = 1;
|
||||
rc = TRUE;
|
||||
break;
|
||||
}
|
||||
if (cp2 > cmd && rc > 0) {
|
||||
if (cp2 > cmd && rc) {
|
||||
switch (cp2[-1]) {
|
||||
case ' ':
|
||||
case '\t':
|
||||
case '\n':
|
||||
break;
|
||||
default:
|
||||
rc = 0; /* no match */
|
||||
rc = FALSE; /* no match */
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -361,6 +359,17 @@ is_submake(void *cmdp, void *gnp)
|
||||
return rc;
|
||||
}
|
||||
|
||||
static Boolean
|
||||
any_is_submake(GNode *gn)
|
||||
{
|
||||
StringListNode *ln;
|
||||
|
||||
for (ln = gn->commands->first; ln != NULL; ln = ln->next)
|
||||
if (is_submake(ln->datum, gn))
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
typedef struct meta_file_s {
|
||||
FILE *fp;
|
||||
GNode *gn;
|
||||
@ -434,7 +443,7 @@ meta_needed(GNode *gn, const char *dname, const char *tname,
|
||||
}
|
||||
if ((gn->type & (OP_META|OP_SUBMAKE)) == OP_SUBMAKE) {
|
||||
/* OP_SUBMAKE is a bit too aggressive */
|
||||
if (Lst_ForEachUntil(gn->commands, is_submake, gn)) {
|
||||
if (any_is_submake(gn)) {
|
||||
DEBUG1(META, "Skipping meta for %s: .SUBMAKE\n", gn->name);
|
||||
return FALSE;
|
||||
}
|
||||
@ -945,17 +954,25 @@ fgetLine(char **bufp, size_t *szp, int o, FILE *fp)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Lst_ForEachUntil wants 1 to stop search */
|
||||
static int
|
||||
prefix_match(void *p, void *q)
|
||||
static Boolean
|
||||
prefix_match(const char *prefix, const char *path)
|
||||
{
|
||||
const char *prefix = p;
|
||||
const char *path = q;
|
||||
size_t n = strlen(prefix);
|
||||
|
||||
return strncmp(path, prefix, n) == 0;
|
||||
}
|
||||
|
||||
static Boolean
|
||||
has_any_prefix(const char *path, StringList *prefixes)
|
||||
{
|
||||
StringListNode *ln;
|
||||
|
||||
for (ln = prefixes->first; ln != NULL; ln = ln->next)
|
||||
if (prefix_match(ln->datum, path))
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* See if the path equals prefix or starts with "prefix/". */
|
||||
static Boolean
|
||||
path_starts_with(const char *path, const char *prefix)
|
||||
@ -977,7 +994,7 @@ meta_ignore(GNode *gn, const char *p)
|
||||
|
||||
if (*p == '/') {
|
||||
cached_realpath(p, fname); /* clean it up */
|
||||
if (Lst_ForEachUntil(metaIgnorePaths, prefix_match, fname)) {
|
||||
if (has_any_prefix(fname, metaIgnorePaths)) {
|
||||
#ifdef DEBUG_META_MODE
|
||||
DEBUG1(META, "meta_oodate: ignoring path: %s\n", p);
|
||||
#endif
|
||||
@ -1369,7 +1386,7 @@ meta_oodate(GNode *gn, Boolean oodate)
|
||||
if (strncmp(p, cwd, cwdlen) == 0)
|
||||
break;
|
||||
|
||||
if (!Lst_ForEachUntil(metaBailiwick, prefix_match, p))
|
||||
if (!has_any_prefix(p, metaBailiwick))
|
||||
break;
|
||||
|
||||
/* tmpdir might be within */
|
||||
|
Loading…
Reference in New Issue
Block a user