Module Name: othersrc
Committed By: dholland
Date: Sat Mar 23 22:00:51 UTC 2013
Modified Files:
othersrc/usr.bin/dholland-make2: meta.c
Log Message:
Rip the linked lists out of here and make it build again.
To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 othersrc/usr.bin/dholland-make2/meta.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: othersrc/usr.bin/dholland-make2/meta.c
diff -u othersrc/usr.bin/dholland-make2/meta.c:1.2 othersrc/usr.bin/dholland-make2/meta.c:1.3
--- othersrc/usr.bin/dholland-make2/meta.c:1.2 Mon Feb 25 03:39:28 2013
+++ othersrc/usr.bin/dholland-make2/meta.c Sat Mar 23 22:00:51 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: meta.c,v 1.2 2013/02/25 03:39:28 dholland Exp $ */
+/* $NetBSD: meta.c,v 1.3 2013/03/23 22:00:51 dholland Exp $ */
/*
* Implement 'meta' mode.
@@ -54,10 +54,10 @@
# define USE_FILEMON
#endif
-MAKE_RCSID("$NetBSD: meta.c,v 1.2 2013/02/25 03:39:28 dholland Exp $");
+MAKE_RCSID("$NetBSD: meta.c,v 1.3 2013/03/23 22:00:51 dholland Exp $");
static BuildMon Mybm; /* for compat */
-static Lst metaBailiwick; /* our scope of control */
+static struct stringarray metaBailiwick; /* our scope of control */
Boolean useMeta = FALSE;
static Boolean useFilemon = FALSE;
@@ -307,12 +307,10 @@ meta_name(struct GNode *gn, char *mname,
* Bypassed if target is flagged .MAKE
*/
static int
-is_submake(void *cmdp, void *gnp)
+is_submake(const char *cmd, GNode *gn)
{
static char *p_make = NULL;
static int p_len;
- char *cmd = cmdp;
- GNode *gn = gnp;
char *mp = NULL;
char *cp;
char *cp2;
@@ -360,10 +358,8 @@ typedef struct meta_file_s {
} meta_file_t;
static int
-printCMD(void *cmdp, void *mfpp)
+printCMD(const char *cmd, meta_file_t *mfp)
{
- meta_file_t *mfp = mfpp;
- char *cmd = cmdp;
char *cp = NULL;
if (strchr(cmd, '$')) {
@@ -400,8 +396,9 @@ meta_create(BuildMon *pbm, GNode *gn)
char *fname;
const char *cp;
char *p[4]; /* >= possible uses */
- int i;
+ int ii;
struct stat fs;
+ unsigned j, num;
/* This may be a phony node which we don't want meta data for... */
@@ -417,10 +414,10 @@ meta_create(BuildMon *pbm, GNode *gn)
mf.fp = NULL;
- i = 0;
+ ii = 0;
- dname = Var_Value(".OBJDIR", gn, &p[i++]);
- tname = Var_Value(TARGET, gn, &p[i++]);
+ dname = Var_Value(".OBJDIR", gn, &p[ii++]);
+ tname = Var_Value(TARGET, gn, &p[ii++]);
/* The object directory may not exist. Check it.. */
if (stat(dname, &fs) != 0) {
@@ -430,7 +427,7 @@ meta_create(BuildMon *pbm, GNode *gn)
goto out;
}
/* Check if there are no commands to execute. */
- if (Lst_IsEmpty(gn->commands)) {
+ if (stringarray_num(&gn->commands) == 0) {
if (DEBUG(META))
fprintf(debug_file, "Skipping meta for %s: no commands\n",
gn->name);
@@ -450,11 +447,14 @@ meta_create(BuildMon *pbm, GNode *gn)
}
if (!(gn->type & OP_META)) {
/* We do not generate .meta files for sub-makes */
- if (Lst_ForEach(gn->commands, is_submake, gn)) {
- if (DEBUG(META))
- fprintf(debug_file, "Skipping meta for %s: .MAKE\n",
+ num = stringarray_num(&gn->commands);
+ for (j=0; j<num; j++) {
+ if (is_submake(stringarray_get(&gn->commands, j), gn)) {
+ if (DEBUG(META))
+ fprintf(debug_file, "Skipping meta for %s: .MAKE\n",
gn->name);
- goto out;
+ goto out;
+ }
}
}
@@ -498,7 +498,10 @@ meta_create(BuildMon *pbm, GNode *gn)
mf.gn = gn;
- Lst_ForEach(gn->commands, printCMD, &mf);
+ num = stringarray_num(&gn->commands);
+ for (j=0; j<num; j++) {
+ printCMD(stringarray_get(&gn->commands, j), &mf);
+ }
fprintf(mf.fp, "CWD %s\n", getcwd(buf, sizeof(buf)));
fprintf(mf.fp, "TARGET %s\n", tname);
@@ -519,9 +522,9 @@ meta_create(BuildMon *pbm, GNode *gn)
gn->type |= OP_SILENT;
}
out:
- for (i--; i >= 0; i--) {
- if (p[i])
- free(p[i]);
+ for (ii--; ii >= 0; ii--) {
+ if (p[ii])
+ free(p[ii]);
}
return (mf.fp);
@@ -588,10 +591,10 @@ meta_init(const char *make_mode)
/*
* We consider ourselves master of all within ${.MAKE.META.BAILIWICK}
*/
- metaBailiwick = Lst_Init(FALSE);
+ stringarray_init(&metaBailiwick);
cp = Var_Subst(NULL, "${.MAKE.META.BAILIWICK:O:u:tA}", VAR_GLOBAL, 0);
if (cp) {
- str2Lst_Append(metaBailiwick, cp, NULL);
+ str2Lst_Append(&metaBailiwick, cp, NULL);
}
}
@@ -793,15 +796,28 @@ fgetLine(char **bufp, size_t *szp, int o
}
static int
-prefix_match(void *p, void *q)
+prefix_match(const char *prefix, const char *path)
{
- const char *prefix = p;
- const char *path = q;
size_t n = strlen(prefix);
return (0 == strncmp(path, prefix, n));
}
+static Boolean
+path_in_bailiwick(const char *path)
+{
+ unsigned i, num;
+
+ num = stringarray_num(&metaBailiwick);
+ for (i=0; i<num; i++) {
+ if (prefix_match(stringarray_get(&metaBailiwick, i), path)) {
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+#if 0 /* not used */
static int
string_match(const void *p, const void *q)
{
@@ -810,7 +826,7 @@ string_match(const void *p, const void *
return strcmp(p1, p2);
}
-
+#endif
/*
* When running with 'meta' functionality, a target can be out-of-date
@@ -846,12 +862,12 @@ meta_oodate(GNode *gn, Boolean oodate)
static size_t tmplen = 0;
FILE *fp;
Boolean needOODATE = FALSE;
- Lst missingFiles;
+ struct stringarray missingFiles;
if (oodate)
return oodate; /* we're done */
- missingFiles = Lst_Init(FALSE);
+ stringarray_init(&missingFiles);
/*
* We need to check if the target is out-of-date. This includes
@@ -876,8 +892,8 @@ meta_oodate(GNode *gn, Boolean oodate)
int pid;
int f = 0;
int x;
- LstNode ln;
struct stat fs;
+ unsigned num, pos;
if (!buf) {
bufsz = 8 * BUFSIZ;
@@ -898,7 +914,9 @@ meta_oodate(GNode *gn, Boolean oodate)
/* we want to track all the .meta we read */
Var_Append(".MAKE.META.FILES", fname, VAR_GLOBAL);
- ln = Lst_First(gn->commands);
+ num = stringarray_num(&gn->commands);
+ pos = 0;
+
while (!oodate && (x = fgetLine(&buf, &bufsz, 0, fp)) > 0) {
lineno++;
if (buf[x - 1] == '\n')
@@ -1021,7 +1039,7 @@ meta_oodate(GNode *gn, Boolean oodate)
break;
case 'M': /* renaMe */
- if (Lst_IsEmpty(missingFiles))
+ if (stringarray_num(&missingFiles) == 0)
break;
/* 'L' and 'M' put single quotes around the args */
if (*p == '\'') {
@@ -1033,11 +1051,14 @@ meta_oodate(GNode *gn, Boolean oodate)
}
/* FALLTHROUGH */
case 'D': /* unlink */
- if (*p == '/' && !Lst_IsEmpty(missingFiles)) {
+ if (*p == '/' && stringarray_num(&missingFiles) > 0) {
/* remove p from the missingFiles list if present */
- if ((ln = Lst_Find(missingFiles, p, string_match)) != NULL) {
- char *tp = Lst_Datum(ln);
- Lst_Remove(missingFiles, ln);
+ unsigned pos2;
+
+ pos2 = stringarray_find(&missingFiles, p);
+ if (pos2 != ARRAY_NOTFOUND) {
+ char *tp = stringarray_get(&missingFiles, pos2);
+ stringarray_remove(&missingFiles, pos2);
free(tp);
}
}
@@ -1066,14 +1087,14 @@ meta_oodate(GNode *gn, Boolean oodate)
if (*p != '/')
break;
- if (Lst_IsEmpty(metaBailiwick))
+ if (stringarray_num(&metaBailiwick) == 0)
break;
/* ignore cwd - normal dependencies handle those */
if (strncmp(p, cwd, cwdlen) == 0)
break;
- if (!Lst_ForEach(metaBailiwick, prefix_match, p))
+ if (!path_in_bailiwick(p))
break;
/* tmpdir might be within */
@@ -1085,7 +1106,7 @@ meta_oodate(GNode *gn, Boolean oodate)
break;
if (stat(p, &fs) < 0) {
- Lst_AtEnd(missingFiles, bmake_strdup(p));
+ stringarray_add(&missingFiles, bmake_strdup(p), NULL);
}
break;
case 'R': /* Read */
@@ -1192,12 +1213,12 @@ meta_oodate(GNode *gn, Boolean oodate)
* Compare the current command with the one in the
* meta data file.
*/
- if (ln == NULL) {
+ if (pos == ARRAY_NOTFOUND) {
if (DEBUG(META))
fprintf(debug_file, "%s: %d: there were more build commands in the meta data file than there are now...\n", fname, lineno);
oodate = TRUE;
} else {
- char *cmd = (char *)Lst_Datum(ln);
+ char *cmd = stringarray_get(&gn->commands, pos);
if (!needOODATE) {
if (strstr(cmd, "$?"))
@@ -1246,14 +1267,17 @@ meta_oodate(GNode *gn, Boolean oodate)
oodate = TRUE;
}
free(cmd);
- ln = Lst_Succ(ln);
+ pos++;
+ if (pos == stringarray_num(&gn->commands)) {
+ pos = ARRAY_NOTFOUND;
+ }
}
} else if (strcmp(buf, "CWD") == 0) {
/*
* Check if there are extra commands now
* that weren't in the meta data file.
*/
- if (!oodate && ln != NULL) {
+ if (!oodate && pos != ARRAY_NOTFOUND) {
if (DEBUG(META))
fprintf(debug_file, "%s: %d: there are extra build commands now that weren't in the meta data file\n", fname, lineno);
oodate = TRUE;
@@ -1267,12 +1291,17 @@ meta_oodate(GNode *gn, Boolean oodate)
}
fclose(fp);
- if (!Lst_IsEmpty(missingFiles)) {
+ if (stringarray_num(&missingFiles) > 0) {
+ unsigned i;
+
if (DEBUG(META))
fprintf(debug_file, "%s: missing files: %s...\n",
- fname, (char *)Lst_Datum(Lst_First(missingFiles)));
+ fname, stringarray_get(&missingFiles, 0));
oodate = TRUE;
- Lst_Destroy(missingFiles, (FreeProc *)free);
+ for (i=0; i<stringarray_num(&missingFiles); i++) {
+ free(stringarray_get(&missingFiles, i));
+ }
+ stringarray_setsize(&missingFiles, 0);
}
} else {
if ((gn->type & OP_META)) {
@@ -1292,6 +1321,7 @@ meta_oodate(GNode *gn, Boolean oodate)
if (cp)
free(cp);
}
+ stringarray_cleanup(&missingFiles);
return oodate;
}