Module Name: othersrc Committed By: dholland Date: Tue Mar 5 04:27:27 UTC 2013
Modified Files: othersrc/usr.bin/dholland-make2: compat.c cond.c graph.h job.c job.h main.c make.c make.h nonints.h parse.c suff.c targ.c Log Message: Clean up the last non-file-local lists. To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 othersrc/usr.bin/dholland-make2/compat.c \ othersrc/usr.bin/dholland-make2/main.c \ othersrc/usr.bin/dholland-make2/parse.c cvs rdiff -u -r1.4 -r1.5 othersrc/usr.bin/dholland-make2/cond.c \ othersrc/usr.bin/dholland-make2/nonints.h cvs rdiff -u -r1.5 -r1.6 othersrc/usr.bin/dholland-make2/graph.h cvs rdiff -u -r1.3 -r1.4 othersrc/usr.bin/dholland-make2/job.c cvs rdiff -u -r1.1.1.1 -r1.2 othersrc/usr.bin/dholland-make2/job.h cvs rdiff -u -r1.7 -r1.8 othersrc/usr.bin/dholland-make2/make.c \ othersrc/usr.bin/dholland-make2/suff.c \ othersrc/usr.bin/dholland-make2/targ.c cvs rdiff -u -r1.9 -r1.10 othersrc/usr.bin/dholland-make2/make.h 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/compat.c diff -u othersrc/usr.bin/dholland-make2/compat.c:1.6 othersrc/usr.bin/dholland-make2/compat.c:1.7 --- othersrc/usr.bin/dholland-make2/compat.c:1.6 Tue Mar 5 03:32:08 2013 +++ othersrc/usr.bin/dholland-make2/compat.c Tue Mar 5 04:27:27 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: compat.c,v 1.6 2013/03/05 03:32:08 dholland Exp $ */ +/* $NetBSD: compat.c,v 1.7 2013/03/05 04:27:27 dholland Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -101,7 +101,7 @@ #include "job.h" #include "pathnames.h" -MAKE_RCSID("$NetBSD: compat.c,v 1.6 2013/03/05 03:32:08 dholland Exp $"); +MAKE_RCSID("$NetBSD: compat.c,v 1.7 2013/03/05 04:27:27 dholland Exp $"); /* * The following array is used to make a fast determination of which @@ -198,7 +198,7 @@ CompatInterrupt(int signo) *----------------------------------------------------------------------- */ int -CompatRunCommand(void *cmdp, void *gnp) +CompatRunCommand(char *cmdp, unsigned cmdindex, GNode *gn) { char *cmdStart; /* Start of expanded command */ char *cp, *bp; @@ -209,7 +209,6 @@ CompatRunCommand(void *cmdp, void *gnp) int status; /* Description of child's death */ pid_t cpid; /* Child actually found */ pid_t retstat; /* Result of wait */ - LstNode cmdNode; /* Node where current command is located */ const char ** volatile av; /* Argument vector for thing to exec */ char ** volatile mav;/* Copy of the argument vector for freeing */ int argc; /* Number of arguments in av or 0 if not @@ -218,14 +217,14 @@ CompatRunCommand(void *cmdp, void *gnp) * locally */ Boolean useShell; /* TRUE if command should be executed * using a shell */ - char * volatile cmd = (char *)cmdp; - GNode *gn = (GNode *)gnp; + char * volatile cmd = cmdp; silent = gn->type & OP_SILENT; errCheck = !(gn->type & OP_IGNORE); doIt = FALSE; + + assert(stringarray_get(&gn->commands, cmdindex) == cmd); - cmdNode = Lst_Member(gn->commands, cmd); cmdStart = Var_Subst(NULL, cmd, gn, FALSE); /* @@ -240,10 +239,9 @@ CompatRunCommand(void *cmdp, void *gnp) return(0); } cmd = cmdStart; - Lst_Replace(cmdNode, cmdStart); - + stringarray_set(&gn->commands, cmdindex, cmdStart); if ((gn->type & OP_SAVE_CMDS) && (gn != ENDNode)) { - (void)Lst_AtEnd(ENDNode->commands, cmdStart); + stringarray_add(&ENDNode->commands, cmdStart, NULL); return(0); } if (strcmp(cmdStart, "...") == 0) { @@ -384,7 +382,8 @@ again: free(mav); if (bp) free(bp); - Lst_Replace(cmdNode, NULL); + /* XXX is this really right? */ + stringarray_set(&gn->commands, cmdindex, NULL); #ifdef USE_META if (useMeta) { @@ -496,6 +495,8 @@ Compat_Make(void *gnp, void *pgnp) { GNode *gn = (GNode *)gnp; GNode *pgn = (GNode *)pgnp; + unsigned i; + char *cmd; if (!meta[0]) /* we came here from jobs */ Compat_Init(); @@ -589,7 +590,12 @@ Compat_Make(void *gnp, void *pgnp) meta_job_start(NULL, gn); } #endif - Lst_ForEach(gn->commands, CompatRunCommand, gn); + for (i=0; i<stringarray_num(&gn->commands); i++) { + cmd = stringarray_get(&gn->commands, i); + if (CompatRunCommand(cmd, i, gn)) { + break; + } + } curTarg = NULL; } else { Job_Touch(gn, gn->type & OP_SILENT); Index: othersrc/usr.bin/dholland-make2/main.c diff -u othersrc/usr.bin/dholland-make2/main.c:1.6 othersrc/usr.bin/dholland-make2/main.c:1.7 --- othersrc/usr.bin/dholland-make2/main.c:1.6 Tue Mar 5 03:32:08 2013 +++ othersrc/usr.bin/dholland-make2/main.c Tue Mar 5 04:27:27 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.6 2013/03/05 03:32:08 dholland Exp $ */ +/* $NetBSD: main.c,v 1.7 2013/03/05 04:27:27 dholland Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -128,7 +128,7 @@ MAKE_COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993\ The Regents of the University of California. All rights reserved."); -MAKE_RCSID("$NetBSD: main.c,v 1.6 2013/03/05 03:32:08 dholland Exp $"); +MAKE_RCSID("$NetBSD: main.c,v 1.7 2013/03/05 04:27:27 dholland Exp $"); #ifndef DEFMAXLOCAL @@ -141,7 +141,7 @@ GNode *DEFAULT; /* .DEFAULT node */ Boolean allPrecious; /* .PRECIOUS given on line by itself */ static Boolean noBuiltins; /* -r flag */ -static Lst makefiles; /* ordered list of makefiles to read */ +static struct stringarray makefiles; /* ordered list of makefiles to read */ static Boolean printVars; /* print value of one or more vars */ static Lst variables; /* list of variables to print */ int maxJobs; /* -j argument */ @@ -478,8 +478,10 @@ rearg: Var_Append(MAKEFLAGS, "-e", VAR_GLOBAL); break; case 'f': - if (argvalue == NULL) goto noarg; - (void)Lst_AtEnd(makefiles, argvalue); + if (argvalue == NULL) { + goto noarg; + } + stringarray_add(&makefiles, argvalue, NULL); break; case 'i': ignoreErrors = TRUE; @@ -679,7 +681,7 @@ ReadAllMakefiles(const void *p, const vo } int -str2Lst_Append(Lst lp, char *str, const char *sep) +str2Lst_Append(struct stringarray *lp, char *str, const char *sep) { char *cp; int n; @@ -688,7 +690,7 @@ str2Lst_Append(Lst lp, char *str, const sep = " \t"; for (n = 0, cp = strtok(str, sep); cp; cp = strtok(NULL, sep)) { - (void)Lst_AtEnd(lp, cp); + stringarray_add(lp, cp, NULL); n++; } return (n); @@ -865,7 +867,7 @@ main(int argc, char **argv) Var_Set(MAKE_DEPENDFILE, ".depend", VAR_GLOBAL, 0); stringarray_init(&create); - makefiles = Lst_Init(FALSE); + stringarray_init(&makefiles); printVars = FALSE; debugVflag = FALSE; variables = Lst_Init(FALSE); @@ -1125,19 +1127,30 @@ main(int argc, char **argv) } } - if (!Lst_IsEmpty(makefiles)) { - LstNode ln; - - ln = Lst_Find(makefiles, NULL, ReadAllMakefiles); - if (ln != NULL) - Fatal("%s: cannot open %s.", progname, - (char *)Lst_Datum(ln)); + if (stringarray_num(&makefiles) > 0) { + unsigned i; + char *mf; + + for (i=0; i<stringarray_num(&makefiles); i++) { + mf = stringarray_get(&makefiles, i); + if (ReadAllMakefiles(mf, NULL) == 0) { + Fatal("%s: cannot open %s.", progname, mf); + break; + } + } } else { - p1 = Var_Subst(NULL, "${" MAKEFILE_PREFERENCE "}", - VAR_CMD, 0); + p1 = Var_Subst(NULL, "${" MAKEFILE_PREFERENCE "}", VAR_CMD, 0); if (p1) { - (void)str2Lst_Append(makefiles, p1, NULL); - (void)Lst_Find(makefiles, NULL, ReadMakefile); + unsigned i; + char *mf; + + (void)str2Lst_Append(&makefiles, p1, NULL); + for (i=0; i<stringarray_num(&makefiles); i++) { + mf = stringarray_get(&makefiles, i); + if (ReadMakefile(mf, NULL) == 0) { + break; + } + } free(p1); } } @@ -1289,7 +1302,8 @@ main(int argc, char **argv) glist_destroy(targs); Lst_Destroy(variables, NULL); - Lst_Destroy(makefiles, NULL); + stringarray_setsize(&makefiles, 0); + stringarray_cleanup(&makefiles); num = stringarray_num(&create); for (i=0; i<num; i++) { free(stringarray_get(&create, i)); Index: othersrc/usr.bin/dholland-make2/parse.c diff -u othersrc/usr.bin/dholland-make2/parse.c:1.6 othersrc/usr.bin/dholland-make2/parse.c:1.7 --- othersrc/usr.bin/dholland-make2/parse.c:1.6 Tue Mar 5 03:32:08 2013 +++ othersrc/usr.bin/dholland-make2/parse.c Tue Mar 5 04:27:27 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: parse.c,v 1.6 2013/03/05 03:32:08 dholland Exp $ */ +/* $NetBSD: parse.c,v 1.7 2013/03/05 04:27:27 dholland Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -138,7 +138,7 @@ #include "buf.h" #include "pathnames.h" -MAKE_RCSID("$NetBSD: parse.c,v 1.6 2013/03/05 03:32:08 dholland Exp $"); +MAKE_RCSID("$NetBSD: parse.c,v 1.7 2013/03/05 04:27:27 dholland Exp $"); //////////////////////////////////////////////////////////// // types and constants @@ -343,7 +343,6 @@ static void ParseVErrorInternal(FILE *, static int ParseFindKeyword(const char *); static void ParseDoSrc(int, const char *); static void ParseDoDependency(char *); -static void ParseHasCommands(void *); static void ParseDoInclude(char *); static void ParseSetParseFile(const char *); #ifdef SYSVINCLUDE @@ -1919,7 +1918,7 @@ ParseAddCmd(GNode *gn, char *cmd) /* if target already supplied, ignore commands */ if (!(gn->type & OP_HAS_COMMANDS)) { - (void)Lst_AtEnd(gn->commands, cmd); + stringarray_add(&gn->commands, cmd, NULL); ParseMark(gn); } else { #ifdef notyet @@ -1961,10 +1960,9 @@ ParseAddCmd(GNode *gn, char *cmd) *----------------------------------------------------------------------- */ static void -ParseHasCommands(void *gnp) +ParseHasCommands(GNode *gn) { - GNode *gn = (GNode *)gnp; - if (!Lst_IsEmpty(gn->commands)) { + if (stringarray_num(&gn->commands) > 0) { gn->type |= OP_HAS_COMMANDS; } } Index: othersrc/usr.bin/dholland-make2/cond.c diff -u othersrc/usr.bin/dholland-make2/cond.c:1.4 othersrc/usr.bin/dholland-make2/cond.c:1.5 --- othersrc/usr.bin/dholland-make2/cond.c:1.4 Tue Mar 5 03:32:08 2013 +++ othersrc/usr.bin/dholland-make2/cond.c Tue Mar 5 04:27:27 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: cond.c,v 1.4 2013/03/05 03:32:08 dholland Exp $ */ +/* $NetBSD: cond.c,v 1.5 2013/03/05 04:27:27 dholland Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -90,7 +90,7 @@ #include "dir.h" #include "buf.h" -MAKE_RCSID("$NetBSD: cond.c,v 1.4 2013/03/05 03:32:08 dholland Exp $"); +MAKE_RCSID("$NetBSD: cond.c,v 1.5 2013/03/05 04:27:27 dholland Exp $"); /* * The parsing of conditional expressions is based on this grammar: @@ -437,7 +437,8 @@ CondDoCommands(int argLen MAKE_ATTR_UNUS GNode *gn; gn = Targ_FindNode(arg, TARG_NOCREATE); - return (gn != NULL) && !OP_NOP(gn->type) && !Lst_IsEmpty(gn->commands); + return (gn != NULL) && !OP_NOP(gn->type) && + stringarray_num(&gn->commands) > 0; } /*- Index: othersrc/usr.bin/dholland-make2/nonints.h diff -u othersrc/usr.bin/dholland-make2/nonints.h:1.4 othersrc/usr.bin/dholland-make2/nonints.h:1.5 --- othersrc/usr.bin/dholland-make2/nonints.h:1.4 Tue Mar 5 03:32:08 2013 +++ othersrc/usr.bin/dholland-make2/nonints.h Tue Mar 5 04:27:27 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: nonints.h,v 1.4 2013/03/05 03:32:08 dholland Exp $ */ +/* $NetBSD: nonints.h,v 1.5 2013/03/05 04:27:27 dholland Exp $ */ /*- * Copyright (c) 1988, 1989, 1990, 1993 @@ -85,7 +85,7 @@ void Arch_End(void); int Arch_IsLib(GNode *); /* compat.c */ -int CompatRunCommand(void *, void *); +int CompatRunCommand(char *, unsigned, GNode *); void Compat_Run(GList *); int Compat_Make(void *, void *); @@ -168,7 +168,7 @@ Boolean Targ_Ignore(GNode *); Boolean Targ_Silent(GNode *); Boolean Targ_Precious(GNode *); void Targ_SetMain(GNode *); -int Targ_PrintCmd(void *, void *); +void Targ_PrintCmd(const char *); void Targ_PrintNode(GNode *, int *); char *Targ_FmtTime(time_t); void Targ_PrintType(int); Index: othersrc/usr.bin/dholland-make2/graph.h diff -u othersrc/usr.bin/dholland-make2/graph.h:1.5 othersrc/usr.bin/dholland-make2/graph.h:1.6 --- othersrc/usr.bin/dholland-make2/graph.h:1.5 Tue Mar 5 03:32:08 2013 +++ othersrc/usr.bin/dholland-make2/graph.h Tue Mar 5 04:27:27 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: graph.h,v 1.5 2013/03/05 03:32:08 dholland Exp $ */ +/* $NetBSD: graph.h,v 1.6 2013/03/05 04:27:27 dholland Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -172,7 +172,7 @@ struct GNode { unsigned int checked; /* Last time we tried to makle this node */ Hash_Table context; /* The local variables */ - Lst commands; /* Creation commands */ + struct stringarray commands;/* Creation commands */ struct _Suff *suffix; /* Suffix for the node (determined by * Suff_FindDeps and opaque to everyone Index: othersrc/usr.bin/dholland-make2/job.c diff -u othersrc/usr.bin/dholland-make2/job.c:1.3 othersrc/usr.bin/dholland-make2/job.c:1.4 --- othersrc/usr.bin/dholland-make2/job.c:1.3 Mon Mar 4 23:03:42 2013 +++ othersrc/usr.bin/dholland-make2/job.c Tue Mar 5 04:27:27 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: job.c,v 1.3 2013/03/04 23:03:42 dholland Exp $ */ +/* $NetBSD: job.c,v 1.4 2013/03/05 04:27:27 dholland Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -149,7 +149,7 @@ #include "trace.h" # define STATIC static -MAKE_RCSID("$NetBSD: job.c,v 1.3 2013/03/04 23:03:42 dholland Exp $"); +MAKE_RCSID("$NetBSD: job.c,v 1.4 2013/03/05 04:27:27 dholland Exp $"); /* * error handling variables @@ -338,7 +338,6 @@ static void JobChildSig(int); static void JobContinueSig(int); static Job *JobFindPid(int, int, Boolean); static int JobPrintCommand(void *, void *); -static int JobSaveCommand(void *, void *); static void JobClose(Job *); static void JobExec(Job *, char **); static void JobMakeArgv(Job *, char **); @@ -679,8 +678,7 @@ JobPrintCommand(void *cmdp, void *jobp) if (strcmp(cmd, "...") == 0) { job->node->type |= OP_SAVE_CMDS; if ((job->flags & JOB_IGNDOTS) == 0) { - job->tailCmds = Lst_Succ(Lst_Member(job->node->commands, - cmd)); + job->tailCmdsIx = 1 + stringarray_find(&job->node->commands, cmd); return 1; } return 0; @@ -716,7 +714,10 @@ JobPrintCommand(void *cmdp, void *jobp) * We're not actually executing anything... * but this one needs to be - use compat mode just for it. */ - CompatRunCommand(cmdp, job->node); + unsigned cmdindex; + + cmdindex = stringarray_find(&job->node->commands, cmdp); + CompatRunCommand(cmdp, cmdindex, job->node); return 0; } break; @@ -879,12 +880,11 @@ JobPrintCommand(void *cmdp, void *jobp) * *----------------------------------------------------------------------- */ -static int -JobSaveCommand(void *cmd, void *gn) +static void +JobSaveCommand(char *cmd, GNode *gn) { - cmd = Var_Subst(NULL, (char *)cmd, (GNode *)gn, FALSE); - (void)Lst_AtEnd(postCommands->commands, cmd); - return(0); + cmd = Var_Subst(NULL, cmd, gn, FALSE); + stringarray_add(&postCommands->commands, cmd, NULL); } @@ -944,6 +944,7 @@ static void JobFinish(Job *job, int status) { Boolean done, return_job_token; + unsigned i; if (DEBUG(JOB)) { fprintf(debug_file, "Jobfinish: %d [%s], status %d\n", @@ -1058,10 +1059,13 @@ JobFinish(Job *job, int status) * the parents. In addition, any saved commands for the node are placed * on the .END target. */ - if (job->tailCmds != NULL) { - Lst_ForEachFrom(job->node->commands, job->tailCmds, - JobSaveCommand, - job->node); + if (job->tailCmdsIx != ARRAY_NOTFOUND) { + for (i=job->tailCmdsIx; + i<stringarray_num(&job->node->commands); + i++) { + JobSaveCommand(stringarray_get(&job->node->commands, i), + job->node); + } } job->node->made = MADE; if (!(job->flags & JOB_SPECIAL)) @@ -1192,13 +1196,13 @@ Job_Touch(GNode *gn, Boolean silent) Boolean Job_CheckCommands(GNode *gn, void (*abortProc)(const char *, ...)) { - if (OP_NOP(gn->type) && Lst_IsEmpty(gn->commands) && + if (OP_NOP(gn->type) && stringarray_num(&gn->commands) == 0 && ((gn->type & OP_LIB) == 0 || glist_num(&gn->children) == 0)) { /* * No commands. Look for .DEFAULT rule from which we might infer * commands */ - if ((DEFAULT != NULL) && !Lst_IsEmpty(DEFAULT->commands) && + if ((DEFAULT != NULL) && stringarray_num(&DEFAULT->commands) > 0 && (gn->type & OP_SPECIAL) == 0) { char *p1; /* @@ -1499,6 +1503,7 @@ JobStart(GNode *gn, int flags) Boolean cmdsOK; /* true if the nodes commands were all right */ Boolean noExec; /* Set true if we decide not to run the job */ int tfd; /* File descriptor to the temp file */ + unsigned i, num; for (job = job_table; job < job_table_end; job++) { if (job->job_state == JOB_ST_FREE) @@ -1513,7 +1518,7 @@ JobStart(GNode *gn, int flags) flags |= JOB_SPECIAL; job->node = gn; - job->tailCmds = NULL; + job->tailCmdsIx = ARRAY_NOTFOUND; /* * Set the initial value of the flags for this job based on the global @@ -1589,7 +1594,13 @@ JobStart(GNode *gn, int flags) * We can do all the commands at once. hooray for sanity */ numCommands = 0; - Lst_ForEach(gn->commands, JobPrintCommand, job); + + num = stringarray_num(&gn->commands); + for (i=0; i<num; i++) { + if (JobPrintCommand(stringarray_get(&gn->commands, i), job)) { + break; + } + } /* * If we didn't print out any commands to the shell script, @@ -1616,7 +1627,12 @@ JobStart(GNode *gn, int flags) * doesn't do any harm in this case and may do some good. */ if (cmdsOK) { - Lst_ForEach(gn->commands, JobPrintCommand, job); + num = stringarray_num(&gn->commands); + for (i=0; i<num; i++) { + if (JobPrintCommand(stringarray_get(&gn->commands, i), job)) { + break; + } + } } /* * Don't execute the shell, thank you. @@ -1657,10 +1673,13 @@ JobStart(GNode *gn, int flags) * the commands for the job were no good. */ if (cmdsOK && aborting == 0) { - if (job->tailCmds != NULL) { - Lst_ForEachFrom(job->node->commands, job->tailCmds, - JobSaveCommand, - job->node); + if (job->tailCmdsIx != ARRAY_NOTFOUND) { + for (i=job->tailCmdsIx; + i<stringarray_num(&job->node->commands); + i++) { + JobSaveCommand(stringarray_get(&job->node->commands, i), + job->node); + } } job->node->made = MADE; Make_Update(job->node); @@ -2584,7 +2603,7 @@ int Job_Finish(void) { if (postCommands != NULL && - (!Lst_IsEmpty(postCommands->commands) || + (stringarray_num(&postCommands->commands) > 0 || glist_num(&postCommands->children) > 0)) { if (errors) { Error("Errors reported so .END ignored"); Index: othersrc/usr.bin/dholland-make2/job.h diff -u othersrc/usr.bin/dholland-make2/job.h:1.1.1.1 othersrc/usr.bin/dholland-make2/job.h:1.2 --- othersrc/usr.bin/dholland-make2/job.h:1.1.1.1 Mon Feb 25 01:32:59 2013 +++ othersrc/usr.bin/dholland-make2/job.h Tue Mar 5 04:27:27 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: job.h,v 1.1.1.1 2013/02/25 01:32:59 dholland Exp $ */ +/* $NetBSD: job.h,v 1.2 2013/03/05 04:27:27 dholland Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -144,7 +144,7 @@ struct pollfd; typedef struct Job { int pid; /* The child's process ID */ GNode *node; /* The target the child is making */ - LstNode tailCmds; /* The node of the first command to be + unsigned tailCmdsIx; /* The index of the first command to be * saved when the job has been run */ FILE *cmdFILE; /* When creating the shell script, this is * where the commands go */ Index: othersrc/usr.bin/dholland-make2/make.c diff -u othersrc/usr.bin/dholland-make2/make.c:1.7 othersrc/usr.bin/dholland-make2/make.c:1.8 --- othersrc/usr.bin/dholland-make2/make.c:1.7 Tue Mar 5 03:32:08 2013 +++ othersrc/usr.bin/dholland-make2/make.c Tue Mar 5 04:27:27 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: make.c,v 1.7 2013/03/05 03:32:08 dholland Exp $ */ +/* $NetBSD: make.c,v 1.8 2013/03/05 04:27:27 dholland Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -111,7 +111,7 @@ #include "dir.h" #include "job.h" -MAKE_RCSID("$NetBSD: make.c,v 1.7 2013/03/05 03:32:08 dholland Exp $"); +MAKE_RCSID("$NetBSD: make.c,v 1.8 2013/03/05 04:27:27 dholland Exp $"); static unsigned int checked = 1;/* Sequence # to detect recursion */ static Lst toBeMade; /* The current fringe of the graph. These @@ -435,22 +435,36 @@ Make_HandleUse(GNode *cgn, GNode *pgn) } #endif - if ((cgn->type & (OP_USE|OP_USEBEFORE)) || Lst_IsEmpty(pgn->commands)) { + if ((cgn->type & (OP_USE|OP_USEBEFORE)) || + stringarray_num(&pgn->commands) == 0) { + struct stringarray *p, *c; + unsigned pn, cn, i; + + p = &pgn->commands; + c = &cgn->commands; + pn = stringarray_num(p); + cn = stringarray_num(c); + stringarray_setsize(p, pn + cn); + if (cgn->type & OP_USEBEFORE) { /* * .USEBEFORE -- * prepend the child's commands to the parent. */ - Lst cmds = pgn->commands; - pgn->commands = Lst_Duplicate(cgn->commands, NULL); - (void)Lst_Concat(pgn->commands, cmds, LST_CONCNEW); - Lst_Destroy(cmds, NULL); + for (i=pn; i-- > 0; ) { + stringarray_set(p, cn + i, stringarray_get(p, i)); + } + for (i=0; i<cn; i++) { + stringarray_set(p, i, stringarray_get(c, i)); + } } else { /* * .USE or target has no commands -- * append the child's commands to the parent. */ - (void)Lst_Concat(pgn->commands, cgn->commands, LST_CONCNEW); + for (i=0; i<cn; i++) { + stringarray_set(p, pn + i, stringarray_get(c, i)); + } } } Index: othersrc/usr.bin/dholland-make2/suff.c diff -u othersrc/usr.bin/dholland-make2/suff.c:1.7 othersrc/usr.bin/dholland-make2/suff.c:1.8 --- othersrc/usr.bin/dholland-make2/suff.c:1.7 Tue Mar 5 03:32:08 2013 +++ othersrc/usr.bin/dholland-make2/suff.c Tue Mar 5 04:27:27 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: suff.c,v 1.7 2013/03/05 03:32:08 dholland Exp $ */ +/* $NetBSD: suff.c,v 1.8 2013/03/05 04:27:27 dholland Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -131,7 +131,7 @@ #include "hash.h" #include "dir.h" -MAKE_RCSID("$NetBSD: suff.c,v 1.7 2013/03/05 03:32:08 dholland Exp $"); +MAKE_RCSID("$NetBSD: suff.c,v 1.8 2013/03/05 04:27:27 dholland Exp $"); static Lst sufflist; /* Lst of suffixes */ #ifdef CLEANUP @@ -701,8 +701,7 @@ Suff_AddTransform(char *line) * attached to several different transformations. */ gn = (GNode *)Lst_Datum(ln); - Lst_Destroy(gn->commands, NULL); - gn->commands = Lst_Init(FALSE); + stringarray_setsize(&gn->commands, 0); glist_setsize(&gn->children, 0); } @@ -752,7 +751,7 @@ Suff_EndTransform(void *gnp, void *dummy if ((gn->type & OP_DOUBLEDEP) && glist_num(&gn->cohorts) > 0) { gn = glist_get(&gn->cohorts, glist_num(&gn->cohorts) - 1); } - if ((gn->type & OP_TRANSFORM) && Lst_IsEmpty(gn->commands) && + if ((gn->type & OP_TRANSFORM) && stringarray_num(&gn->commands) == 0 && glist_num(&gn->children) == 0) { Suff *s, *t; @@ -1447,7 +1446,7 @@ SuffFindCmds(Src *targ, Lst slst) s = glist_get(&t->children, i); i++; - if (s->type & OP_OPTIONAL && Lst_IsEmpty(t->commands)) { + if (s->type & OP_OPTIONAL && stringarray_num(&t->commands) == 0) { /* * We haven't looked to see if .OPTIONAL files exist yet, so * don't use one as the implicit source. @@ -2202,7 +2201,7 @@ SuffFindNormalDeps(GNode *gn, Lst slst) * not define suffix rules if the gnode had children but we * don't do this anymore. */ - if (Lst_IsEmpty(gn->commands)) + if (stringarray_num(&gn->commands) == 0) SuffAddLevel(srcs, targ); else { if (DEBUG(SUFF)) @@ -2707,11 +2706,14 @@ static int SuffPrintTrans(void *tp, void *dummy) { GNode *t = (GNode *)tp; + unsigned i; fprintf(debug_file, "%-16s: ", t->name); Targ_PrintType(t->type); fputc('\n', debug_file); - Lst_ForEach(t->commands, Targ_PrintCmd, NULL); + for (i=0; i<stringarray_num(&t->commands); i++) { + Targ_PrintCmd(stringarray_get(&t->commands, i)); + } fputc('\n', debug_file); return(dummy ? 0 : 0); } Index: othersrc/usr.bin/dholland-make2/targ.c diff -u othersrc/usr.bin/dholland-make2/targ.c:1.7 othersrc/usr.bin/dholland-make2/targ.c:1.8 --- othersrc/usr.bin/dholland-make2/targ.c:1.7 Tue Mar 5 03:32:08 2013 +++ othersrc/usr.bin/dholland-make2/targ.c Tue Mar 5 04:27:27 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: targ.c,v 1.7 2013/03/05 03:32:08 dholland Exp $ */ +/* $NetBSD: targ.c,v 1.8 2013/03/05 04:27:27 dholland Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -127,7 +127,7 @@ #include "hash.h" #include "dir.h" -MAKE_RCSID("$NetBSD: targ.c,v 1.7 2013/03/05 03:32:08 dholland Exp $"); +MAKE_RCSID("$NetBSD: targ.c,v 1.8 2013/03/05 04:27:27 dholland Exp $"); static GList allTargets; /* the list of all targets found so far */ #ifdef CLEANUP @@ -259,7 +259,7 @@ Targ_NewGN(const char *name) glist_init(&gn->order_pred); glist_init(&gn->order_succ); Hash_InitTable(&gn->context, 0); - gn->commands = Lst_Init(FALSE); + stringarray_init(&gn->commands); gn->suffix = NULL; gn->lineno = 0; gn->fname = NULL; @@ -307,7 +307,8 @@ TargFreeGN(GNode *gn) glist_setsize(&gn->order_succ, 0); glist_cleanup(&gn->order_succ); Hash_DeleteTable(&gn->context); - Lst_Destroy(gn->commands, NULL); + stringarray_setsize(&gn->commands, 0); + stringarray_cleanup(&gn->commands); free(gn); } #endif @@ -512,11 +513,10 @@ TargPrintName(GNode *gn) } -int -Targ_PrintCmd(void *cmd, void *dummy) +void +Targ_PrintCmd(const char *cmd) { - fprintf(debug_file, "\t%s\n", (char *)cmd); - return (dummy ? 0 : 0); + fprintf(debug_file, "\t%s\n", cmd); } /*- @@ -617,6 +617,7 @@ void Targ_PrintNode(GNode *gn, int *passp) { int pass = passp ? *passp : 0; + unsigned i; fprintf(debug_file, "# %s%s, flags %x, type %x, made %d\n", gn->name, gn->cohort_num, gn->flags, gn->type, gn->made); @@ -647,8 +648,6 @@ Targ_PrintNode(GNode *gn, int *passp) } } if (glist_num(&gn->iParents) > 0) { - unsigned i; - fprintf(debug_file, "# implicit parents: "); for (i=0; i<glist_num(&gn->iParents); i++) { TargPrintName(glist_get(&gn->iParents, i)); @@ -660,8 +659,6 @@ Targ_PrintNode(GNode *gn, int *passp) fprintf(debug_file, "# %d unmade children\n", gn->unmade); } if (glist_num(&gn->parents) > 0) { - unsigned i; - fprintf(debug_file, "# parents: "); for (i=0; i<glist_num(&gn->parents); i++) { TargPrintName(glist_get(&gn->parents, i)); @@ -669,8 +666,6 @@ Targ_PrintNode(GNode *gn, int *passp) fprintf(debug_file, "\n"); } if (glist_num(&gn->order_pred) > 0) { - unsigned i; - fprintf(debug_file, "# order_pred: "); for (i=0; i<glist_num(&gn->order_pred); i++) { TargPrintName(glist_get(&gn->order_pred, i)); @@ -678,8 +673,6 @@ Targ_PrintNode(GNode *gn, int *passp) fprintf(debug_file, "\n"); } if (glist_num(&gn->order_succ) > 0) { - unsigned i; - fprintf(debug_file, "# order_succ: "); for (i=0; i<glist_num(&gn->order_succ); i++) { TargPrintName(glist_get(&gn->order_succ, i)); @@ -697,19 +690,15 @@ Targ_PrintNode(GNode *gn, int *passp) fprintf(debug_file, ":: "); break; } Targ_PrintType(gn->type); - { - unsigned i; - - for (i=0; i<glist_num(&gn->children); i++) { - TargPrintName(glist_get(&gn->children, i)); - } + for (i=0; i<glist_num(&gn->children); i++) { + TargPrintName(glist_get(&gn->children, i)); } fprintf(debug_file, "\n"); - Lst_ForEach(gn->commands, Targ_PrintCmd, NULL); + for (i=0; i<stringarray_num(&gn->commands); i++) { + Targ_PrintCmd(stringarray_get(&gn->commands, i)); + } fprintf(debug_file, "\n\n"); if (gn->type & OP_DOUBLEDEP) { - unsigned i; - for (i=0; i<glist_num(&gn->cohorts); i++) { Targ_PrintNode(glist_get(&gn->cohorts, i), &pass); } Index: othersrc/usr.bin/dholland-make2/make.h diff -u othersrc/usr.bin/dholland-make2/make.h:1.9 othersrc/usr.bin/dholland-make2/make.h:1.10 --- othersrc/usr.bin/dholland-make2/make.h:1.9 Tue Mar 5 03:32:08 2013 +++ othersrc/usr.bin/dholland-make2/make.h Tue Mar 5 04:27:27 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: make.h,v 1.9 2013/03/05 03:32:08 dholland Exp $ */ +/* $NetBSD: make.h,v 1.10 2013/03/05 04:27:27 dholland Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -284,6 +284,6 @@ void PrintOnError(GNode *, const char *) void Main_ExportMAKEFLAGS(Boolean); Boolean Main_SetObjdir(const char *); int mkTempFile(const char *, char **); -int str2Lst_Append(Lst, char *, const char *); +int str2Lst_Append(struct stringarray *, char *, const char *); #endif /* _MAKE_H_ */