diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2007-01-04 17:55:36 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2007-01-04 17:55:36 +0000 |
commit | 45fb3a386813e8f12d372141747d24ba09a32657 (patch) | |
tree | e45a65ac5bf4e05c7cfd9892873722ef59e9636a /usr.bin | |
parent | deb608b55212d1d748b2fc1e22ebb1207cf73810 (diff) |
having a function that iterates through node's datum so that we retrieve
the list item with lst_member is non-sensical, create a new function
(Lst_ForEachNodeWhile) that iterates through lstnodes directly and use
it.
Less obfuscated, slightly more efficient...
okay otto@
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/make/compat.c | 18 | ||||
-rw-r--r-- | usr.bin/make/job.c | 18 | ||||
-rw-r--r-- | usr.bin/make/lst.h | 5 | ||||
-rw-r--r-- | usr.bin/make/lst.lib/lstForEachFrom.c | 11 |
4 files changed, 30 insertions, 22 deletions
diff --git a/usr.bin/make/compat.c b/usr.bin/make/compat.c index 02ec6a20990..5040991614f 100644 --- a/usr.bin/make/compat.c +++ b/usr.bin/make/compat.c @@ -1,5 +1,5 @@ /* $OpenPackages$ */ -/* $OpenBSD: compat.c,v 1.50 2004/04/07 13:11:35 espie Exp $ */ +/* $OpenBSD: compat.c,v 1.51 2007/01/04 17:55:35 espie Exp $ */ /* $NetBSD: compat.c,v 1.14 1996/11/06 17:59:01 christos Exp $ */ /* @@ -75,7 +75,7 @@ static char meta[256]; static GNode *ENDNode; static void CompatInterrupt(int); -static int CompatRunCommand(void *, void *); +static int CompatRunCommand(LstNode, void *); static void CompatMake(void *, void *); static int shellneed(char **); @@ -154,7 +154,7 @@ shellneed(char **av) *----------------------------------------------------------------------- */ static int -CompatRunCommand(void *cmdp, /* Command to execute */ +CompatRunCommand(LstNode cmdNode,/* Command to execute */ void *gnp) /* Node from which the command came */ { char *cmdStart; /* Start of expanded command */ @@ -166,13 +166,12 @@ CompatRunCommand(void *cmdp, /* Command to execute */ int status; /* Description of child's death */ pid_t cpid; /* Child actually found */ pid_t stat; /* Status of fork */ - LstNode cmdNode; /* Node where current command is located */ char ** volatile av; /* Argument vector for thing to exec */ int argc; /* Number of arguments in av or 0 if not * dynamically allocated */ bool local; /* true if command should be executed * locally */ - char *cmd = (char *)cmdp; + char *cmd = (char *)Lst_Datum(cmdNode); GNode *gn = (GNode *)gnp; static char *shargv[4] = { _PATH_BSHELL }; @@ -180,7 +179,6 @@ CompatRunCommand(void *cmdp, /* Command to execute */ errCheck = !(gn->type & OP_IGNORE); doExecute = !noExecute; - cmdNode = Lst_Member(&gn->commands, cmd); cmdStart = Var_Subst(cmd, &gn->context, false); /* brk_string will return an argv with a NULL in av[0], thus causing @@ -356,7 +354,7 @@ CompatRunCommand(void *cmdp, /* Command to execute */ signal(SIGQUIT, SIG_IGN); interrupted = 0; if (i != NULL) - Lst_Find(&i->commands, CompatRunCommand, i); + Lst_ForEachNodeWhile(&i->commands, CompatRunCommand, i); exit(SIGINT); } exit(interrupted); @@ -441,7 +439,7 @@ CompatMake(void *gnp, /* The node to make */ /* Our commands are ok, but we still have to worry about the -t * flag... */ if (!touchFlag) - Lst_Find(&gn->commands, CompatRunCommand, gn); + Lst_ForEachNodeWhile(&gn->commands, CompatRunCommand, gn); else Job_Touch(gn, gn->type & OP_SILENT); } else @@ -575,7 +573,7 @@ Compat_Run(Lst targs) /* List of target nodes to re-create */ if (!queryFlag) { gn = Targ_FindNode(".BEGIN", TARG_NOCREATE); if (gn != NULL) { - Lst_Find(&gn->commands, CompatRunCommand, gn); + Lst_ForEachNodeWhile(&gn->commands, CompatRunCommand, gn); if (gn->made == ERROR) { printf("\n\nStop.\n"); exit(1); @@ -605,5 +603,5 @@ Compat_Run(Lst targs) /* List of target nodes to re-create */ /* If the user has defined a .END target, run its commands. */ if (errors == 0) - Lst_Find(&ENDNode->commands, CompatRunCommand, ENDNode); + Lst_ForEachNodeWhile(&ENDNode->commands, CompatRunCommand, ENDNode); } diff --git a/usr.bin/make/job.c b/usr.bin/make/job.c index 0697b3466e4..590e3d7a093 100644 --- a/usr.bin/make/job.c +++ b/usr.bin/make/job.c @@ -1,5 +1,5 @@ /* $OpenPackages$ */ -/* $OpenBSD: job.c,v 1.59 2005/04/13 02:33:08 deraadt Exp $ */ +/* $OpenBSD: job.c,v 1.60 2007/01/04 17:55:35 espie Exp $ */ /* $NetBSD: job.c,v 1.16 1996/11/06 17:59:08 christos Exp $ */ /* @@ -434,7 +434,7 @@ static void SigHandler(int); static void HandleSigs(void); static void JobPassSig(int); static int JobCmpPid(void *, void *); -static int JobPrintCommand(void *, void *); +static int JobPrintCommand(LstNode, void *); static void JobSaveCommand(void *, void *); static void JobClose(Job *); static void JobFinish(Job *, int *); @@ -672,7 +672,7 @@ JobCmpPid(void *job, /* job to examine */ *----------------------------------------------------------------------- */ static int -JobPrintCommand(void *cmdp, /* command string to print */ +JobPrintCommand(LstNode cmdNode, /* command string to print */ void *jobp) /* job for which to print it */ { bool noSpecials; /* true if we shouldn't worry about @@ -686,8 +686,7 @@ JobPrintCommand(void *cmdp, /* command string to print */ char *cmdTemplate; /* Template to use when printing the * command */ char *cmdStart; /* Start of expanded command */ - LstNode cmdNode; /* Node for replacing the command */ - char *cmd = (char *)cmdp; + char *cmd = (char *)Lst_Datum(cmdNode); Job *job = (Job *)jobp; noSpecials = (noExecute && !(job->node->type & OP_MAKE)); @@ -695,7 +694,7 @@ JobPrintCommand(void *cmdp, /* command string to print */ 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->tailCmds = Lst_Succ(cmdNode); return 0; } return 1; @@ -712,7 +711,6 @@ JobPrintCommand(void *cmdp, /* command string to print */ /* For debugging, we replace each command with the result of expanding * the variables in the command. */ - cmdNode = Lst_Member(&job->node->commands, cmd); cmdStart = cmd = Var_Subst(cmd, &job->node->context, false); Lst_Replace(cmdNode, cmdStart); @@ -1664,7 +1662,7 @@ JobStart(GNode *gn, /* target to create */ gn->current = Lst_Succ(gn->current); if (gn->current == NULL || - !JobPrintCommand(Lst_Datum(gn->current), job)) { + !JobPrintCommand(gn->current, job)) { noExec = true; gn->current = NULL; } @@ -1687,7 +1685,7 @@ JobStart(GNode *gn, /* target to create */ * We can do all the commands at once. hooray for sanity */ numCommands = 0; - Lst_Find(&gn->commands, JobPrintCommand, job); + Lst_ForEachNodeWhile(&gn->commands, JobPrintCommand, job); /* * If we didn't print out any commands to the shell script, @@ -1713,7 +1711,7 @@ JobStart(GNode *gn, /* target to create */ * doesn't do any harm in this case and may do some good. */ if (cmdsOK) { - Lst_Find(&gn->commands, JobPrintCommand, job); + Lst_ForEachNodeWhile(&gn->commands, JobPrintCommand, job); } /* * Don't execute the shell, thank you. diff --git a/usr.bin/make/lst.h b/usr.bin/make/lst.h index 6e1af60b989..53d8d098310 100644 --- a/usr.bin/make/lst.h +++ b/usr.bin/make/lst.h @@ -2,7 +2,7 @@ #define _LST_H_ /* $OpenPackages$ */ -/* $OpenBSD: lst.h,v 1.25 2003/06/03 02:56:11 millert Exp $ */ +/* $OpenBSD: lst.h,v 1.26 2007/01/04 17:55:35 espie Exp $ */ /* $NetBSD: lst.h,v 1.7 1996/11/06 17:59:12 christos Exp $ */ /* @@ -61,6 +61,7 @@ struct ListNode_ { typedef void (*SimpleProc)(void *); typedef int (*FindProc)(void *, void *); +typedef int (*ForEachNodeWhileProc)(LstNode, void *); typedef int (*FindProcConst)(void *, const void *); typedef void (*ForEachProc)(void *, void *); typedef void *(*DuplicateProc)(void *); @@ -128,6 +129,8 @@ extern LstNode Lst_Member(Lst, void *); extern void Lst_ForEachFrom(LstNode, ForEachProc, void *); extern void Lst_Every(Lst, SimpleProc); +extern void Lst_ForEachNodeWhile(Lst, ForEachNodeWhileProc, void *); + extern bool Lst_AddNew(Lst, void *); /* * for using the list as a queue diff --git a/usr.bin/make/lst.lib/lstForEachFrom.c b/usr.bin/make/lst.lib/lstForEachFrom.c index 7ef94f4ad62..1329d3ec9a6 100644 --- a/usr.bin/make/lst.lib/lstForEachFrom.c +++ b/usr.bin/make/lst.lib/lstForEachFrom.c @@ -1,5 +1,5 @@ /* $OpenPackages$ */ -/* $OpenBSD: lstForEachFrom.c,v 1.14 2004/04/07 13:11:36 espie Exp $ */ +/* $OpenBSD: lstForEachFrom.c,v 1.15 2007/01/04 17:55:35 espie Exp $ */ /* $NetBSD: lstForEachFrom.c,v 1.5 1996/11/06 17:59:42 christos Exp $ */ /* @@ -72,3 +72,12 @@ Lst_Every(Lst l, SimpleProc proc) (*proc)(tln->datum); } +void +Lst_ForEachNodeWhile(Lst l, ForEachNodeWhileProc proc, void *d) +{ + LstNode it; + + for (it = l->firstPtr; it != NULL; it = it->nextPtr) + if ((*proc)(it, d) == 0) + return; +} |