=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/make/parse.c,v retrieving revision 1.62 retrieving revision 1.63 diff -c -r1.62 -r1.63 *** src/usr.bin/make/parse.c 2001/05/29 12:53:42 1.62 --- src/usr.bin/make/parse.c 2001/06/12 22:44:21 1.63 *************** *** 1,5 **** /* $OpenPackages$ */ ! /* $OpenBSD: parse.c,v 1.62 2001/05/29 12:53:42 espie Exp $ */ /* $NetBSD: parse.c,v 1.29 1997/03/10 21:20:04 christos Exp $ */ /* --- 1,5 ---- /* $OpenPackages$ */ ! /* $OpenBSD: parse.c,v 1.63 2001/06/12 22:44:21 espie Exp $ */ /* $NetBSD: parse.c,v 1.29 1997/03/10 21:20:04 christos Exp $ */ /* *************** *** 92,104 **** #include "extern.h" #include "lst.h" #include "parsevar.h" static LIST theParseIncPath;/* list of directories for "..." includes */ static LIST theSysIncPath; /* list of directories for <...> includes */ Lst sysIncPath = &theSysIncPath; Lst parseIncPath = &theParseIncPath; - static LIST targets; /* targets we're working on */ #ifdef CLEANUP static LIST targCmds; /* command lines for targets */ #endif --- 92,110 ---- #include "extern.h" #include "lst.h" #include "parsevar.h" + #include "stats.h" + #include "garray.h" + + static struct growableArray gsources, gtargets; + #define SOURCES_SIZE 128 + #define TARGETS_SIZE 32 + static LIST theParseIncPath;/* list of directories for "..." includes */ static LIST theSysIncPath; /* list of directories for <...> includes */ Lst sysIncPath = &theSysIncPath; Lst parseIncPath = &theParseIncPath; #ifdef CLEANUP static LIST targCmds; /* command lines for targets */ #endif *************** *** 201,209 **** static int ParseFindKeyword(const char *); static void ParseLinkSrc(GNode *, GNode *); ! static int ParseDoOp(void *, void *); ! static int ParseAddDep(void *, void *); ! static void ParseDoSrc(int, const char *, Lst); static int ParseFindMain(void *, void *); static void ParseAddDir(void *, void *); static void ParseClearPath(void *); --- 207,215 ---- static int ParseFindKeyword(const char *); static void ParseLinkSrc(GNode *, GNode *); ! static int ParseDoOp(GNode *, int); ! static int ParseAddDep(GNode *, GNode *); ! static void ParseDoSrc(int, const char *); static int ParseFindMain(void *, void *); static void ParseAddDir(void *, void *); static void ParseClearPath(void *); *************** *** 295,307 **** *--------------------------------------------------------------------- */ static int ! ParseDoOp(gnp, opp) ! void *gnp; /* The node to which the operator is to be * applied */ ! void *opp; /* The operator to apply */ { - GNode *gn = (GNode *)gnp; - int op = *(int *)opp; /* * If the dependency mask of the operator and the node don't match and * the node has actually had an operator applied to it before, and --- 301,311 ---- *--------------------------------------------------------------------- */ static int ! ParseDoOp(gn, op) ! GNode *gn; /* The node to which the operator is to be * applied */ ! int op; /* The operator to apply */ { /* * If the dependency mask of the operator and the node don't match and * the node has actually had an operator applied to it before, and *************** *** 322,327 **** --- 326,332 ---- * instance. */ GNode *cohort; LstNode ln; + unsigned int i; cohort = Targ_NewGN(gn->name); /* Duplicate links to parents so graph traversal is simple. Perhaps *************** *** 337,344 **** Lst_AtEnd(&gn->cohorts, cohort); /* Replace the node in the targets list with the new copy */ ! ln = Lst_Member(&targets, gn); ! Lst_Replace(ln, cohort); gn = cohort; } /* We don't want to nuke any previous flags (whatever they were) so we --- 342,351 ---- Lst_AtEnd(&gn->cohorts, cohort); /* Replace the node in the targets list with the new copy */ ! for (i = 0; i < gtargets.n; i++) ! if (gtargets.a[i] == gn) ! break; ! gtargets.a[i] = cohort; gn = cohort; } /* We don't want to nuke any previous flags (whatever they were) so we *************** *** 364,376 **** *--------------------------------------------------------------------- */ static int ! ParseAddDep(pp, sp) ! void *pp; ! void *sp; { - GNode *p = (GNode *)pp; - GNode *s = (GNode *)sp; - if (p->order < s->order) { /* XXX: This can cause loops, and loops can cause unmade targets, * but checking is tedious, and the debugging output can show the --- 371,380 ---- *--------------------------------------------------------------------- */ static int ! ParseAddDep(p, s) ! GNode *p; ! GNode *s; { if (p->order < s->order) { /* XXX: This can cause loops, and loops can cause unmade targets, * but checking is tedious, and the debugging output can show the *************** *** 399,408 **** *--------------------------------------------------------------------- */ static void ! ParseDoSrc(tOp, src, allsrc) int tOp; /* operator (if any) from special targets */ const char *src; /* name of the source to handle */ - Lst allsrc; /* List of all sources to wait for */ { GNode *gn = NULL; --- 403,411 ---- *--------------------------------------------------------------------- */ static void ! ParseDoSrc(tOp, src) int tOp; /* operator (if any) from special targets */ const char *src; /* name of the source to handle */ { GNode *gn = NULL; *************** *** 412,418 **** if (keywd != -1) { int op = parseKeywords[keywd].op; if (op != 0) { ! Lst_Find(&targets, ParseDoOp, &op); return; } if (parseKeywords[keywd].spec == Wait) { --- 415,421 ---- if (keywd != -1) { int op = parseKeywords[keywd].op; if (op != 0) { ! Array_Find(>argets, ParseDoOp, op); return; } if (parseKeywords[keywd].spec == Wait) { *************** *** 472,481 **** if (tOp) { gn->type |= tOp; } else { ! LstNode ln; ! ! for (ln = Lst_First(&targets); ln != NULL; ln = Lst_Adv(ln)) ! ParseLinkSrc((GNode *)Lst_Datum(ln), gn); } if ((gn->type & OP_OPMASK) == OP_DOUBLEDEP) { GNode *cohort; --- 475,481 ---- if (tOp) { gn->type |= tOp; } else { ! Array_ForEach(>argets, ParseLinkSrc, gn); } if ((gn->type & OP_OPMASK) == OP_DOUBLEDEP) { GNode *cohort; *************** *** 486,495 **** if (tOp) { cohort->type |= tOp; } else { ! LstNode ln; ! ! for (ln = Lst_First(&targets); ln != NULL; ln = Lst_Adv(ln)) ! ParseLinkSrc((GNode *)Lst_Datum(ln), cohort); } } } --- 486,492 ---- if (tOp) { cohort->type |= tOp; } else { ! Array_ForEach(>argets, ParseLinkSrc, cohort); } } } *************** *** 497,505 **** } gn->order = waiting; ! Lst_AtEnd(allsrc, gn); if (waiting) { ! Lst_Find(allsrc, ParseAddDep, gn); } } --- 494,502 ---- } gn->order = waiting; ! Array_AtEnd(&gsources, gn); if (waiting) { ! Array_Find(&gsources, ParseAddDep, gn); } } *************** *** 607,624 **** LIST paths; /* List of search paths to alter when parsing * a list of .PATH targets */ int tOp; /* operator from special target */ - LIST curTargs; /* list of target names to be found and added - * to the targets list */ - LIST curSrcs; /* list of sources in order */ - tOp = 0; specType = Not; waiting = 0; Lst_Init(&paths); ! Lst_Init(&curTargs); ! Lst_Init(&curSrcs); do { for (cp = line; *cp && !isspace(*cp) && *cp != '(';) --- 604,616 ---- LIST paths; /* List of search paths to alter when parsing * a list of .PATH targets */ int tOp; /* operator from special target */ tOp = 0; specType = Not; waiting = 0; Lst_Init(&paths); ! Array_Reset(&gsources); do { for (cp = line; *cp && !isspace(*cp) && *cp != '(';) *************** *** 664,669 **** --- 656,663 ---- cp++; } if (*cp == '(') { + LIST temp; + Lst_Init(&temp); /* Archives must be handled specially to make sure the OP_ARCHV * flag is set in their 'type' field, for one thing, and because * things like "archive(file1.o file2.o file3.o)" are permissible. *************** *** 672,682 **** * and places them on the given list, returning true if all * went well and false if there was an error in the * specification. On error, line should remain untouched. */ ! if (!Arch_ParseArchive(&line, &targets, NULL)) { Parse_Error(PARSE_FATAL, "Error in archive specification: \"%s\"", line); return; } else { continue; } } --- 666,678 ---- * and places them on the given list, returning true if all * went well and false if there was an error in the * specification. On error, line should remain untouched. */ ! if (!Arch_ParseArchive(&line, &temp, NULL)) { Parse_Error(PARSE_FATAL, "Error in archive specification: \"%s\"", line); return; } else { + AppendList2Array(&temp, >argets); + Lst_Destroy(&temp, NOFREE); continue; } } *************** *** 746,757 **** case Interrupt: gn = Targ_FindNode(line, TARG_CREATE); gn->type |= OP_NOTMAIN; ! Lst_AtEnd(&targets, gn); break; case Default: gn = Targ_NewGN(".DEFAULT"); gn->type |= OP_NOTMAIN|OP_TRANSFORM; ! Lst_AtEnd(&targets, gn); DEFAULT = gn; break; case NotParallel: --- 742,753 ---- case Interrupt: gn = Targ_FindNode(line, TARG_CREATE); gn->type |= OP_NOTMAIN; ! Array_AtEnd(>argets, gn); break; case Default: gn = Targ_NewGN(".DEFAULT"); gn->type |= OP_NOTMAIN|OP_TRANSFORM; ! Array_AtEnd(>argets, gn); DEFAULT = gn; break; case NotParallel: *************** *** 806,836 **** * Dir module could have added a directory to the path... */ LIST emptyPath; Lst_Init(&emptyPath); Dir_Expand(line, &emptyPath, &curTargs); Lst_Destroy(&emptyPath, Dir_Destroy); - } else { - /* - * No wildcards, but we want to avoid code duplication, - * so create a list with the word on it. - */ - Lst_AtEnd(&curTargs, line); - } - while ((targName = (char *)Lst_DeQueue(&curTargs)) != NULL) { ! if (!Suff_IsTransform(targName)) { gn = Targ_FindNode(targName, TARG_CREATE); ! } else { gn = Suff_AddTransform(targName); } if (gn != NULL) ! Lst_AtEnd(&targets, gn); } ! } else if (specType == ExPath && *line != '.' && *line != '\0') { Parse_Error(PARSE_WARNING, "Extra target (%s) ignored", line); - } *cp = savec; /* --- 802,836 ---- * Dir module could have added a directory to the path... */ LIST emptyPath; + LIST curTargs; /* list of target names to be found + * and added to the targets list */ Lst_Init(&emptyPath); + Lst_Init(&curTargs); Dir_Expand(line, &emptyPath, &curTargs); Lst_Destroy(&emptyPath, Dir_Destroy); while ((targName = (char *)Lst_DeQueue(&curTargs)) != NULL) { ! if (!Suff_IsTransform(targName)) gn = Targ_FindNode(targName, TARG_CREATE); ! else gn = Suff_AddTransform(targName); + + if (gn != NULL) + Array_AtEnd(>argets, gn); } + Lst_Destroy(&curTargs, NOFREE); + } else { + if (!Suff_IsTransform(line)) + gn = Targ_FindNode(line, TARG_CREATE); + else + gn = Suff_AddTransform(line); if (gn != NULL) ! Array_AtEnd(>argets, gn); ! /* Don't need the list of target names anymore... */ } ! } else if (specType == ExPath && *line != '.' && *line != '\0') Parse_Error(PARSE_WARNING, "Extra target (%s) ignored", line); *cp = savec; /* *************** *** 857,868 **** line = cp; } while (*line != '!' && *line != ':' && *line); ! /* ! * Don't need the list of target names anymore... ! */ ! Lst_Destroy(&curTargs, NOFREE); ! ! if (!Lst_IsEmpty(&targets)) { switch (specType) { default: Parse_Error(PARSE_WARNING, "Special and mundane targets don't mix. Mundane ones ignored"); --- 857,863 ---- line = cp; } while (*line != '!' && *line != ':' && *line); ! if (!Array_IsEmpty(>argets)) { switch (specType) { default: Parse_Error(PARSE_WARNING, "Special and mundane targets don't mix. Mundane ones ignored"); *************** *** 897,903 **** cp++; /* Advance beyond operator */ ! Lst_Find(&targets, ParseDoOp, &op); /* * Get to the first source --- 892,898 ---- cp++; /* Advance beyond operator */ ! Array_Find(>argets, ParseDoOp, op); /* * Get to the first source *************** *** 1054,1060 **** } while ((gn = (GNode *)Lst_DeQueue(&sources)) != NULL) ! ParseDoSrc(tOp, gn->name, &curSrcs); cp = line; } else { if (*cp) { --- 1049,1055 ---- } while ((gn = (GNode *)Lst_DeQueue(&sources)) != NULL) ! ParseDoSrc(tOp, gn->name); cp = line; } else { if (*cp) { *************** *** 1062,1068 **** cp += 1; } ! ParseDoSrc(tOp, line, &curSrcs); } while (*cp && isspace(*cp)) { cp++; --- 1057,1063 ---- cp += 1; } ! ParseDoSrc(tOp, line); } while (*cp && isspace(*cp)) { cp++; *************** *** 1076,1086 **** * absence of any user input, we want the first target on * the first dependency line that is actually a real target * (i.e. isn't a .USE or .EXEC rule) to be made. */ ! Lst_Find(&targets, ParseFindMain, NULL); } /* Finally, destroy the list of sources. */ - Lst_Destroy(&curSrcs, NOFREE); } /*- --- 1071,1080 ---- * absence of any user input, we want the first target on * the first dependency line that is actually a real target * (i.e. isn't a .USE or .EXEC rule) to be made. */ ! Array_Find(>argets, ParseFindMain, NULL); } /* Finally, destroy the list of sources. */ } /*- *************** *** 1468,1475 **** static void ParseFinishDependency() { ! Lst_Every(&targets, Suff_EndTransform); ! Lst_Destroy(&targets, ParseHasCommands); } static void --- 1462,1470 ---- static void ParseFinishDependency() { ! Array_Every(>argets, Suff_EndTransform); ! Array_Every(>argets, ParseHasCommands); ! Array_Reset(>argets); } static void *************** *** 1480,1486 **** * commands of all targets in the dependency spec */ char *cmd = estrdup(line); ! Lst_ForEach(&targets, ParseAddCmd, cmd); #ifdef CLEANUP Lst_AtEnd(&targCmds, cmd); #endif --- 1475,1481 ---- * commands of all targets in the dependency spec */ char *cmd = estrdup(line); ! Array_ForEach(>argets, ParseAddCmd, cmd); #ifdef CLEANUP Lst_AtEnd(&targCmds, cmd); #endif *************** *** 1542,1548 **** char *end; /* Need a new list for the target nodes. */ ! Lst_Init(&targets); inDependency = true; dep = NULL; --- 1537,1543 ---- char *end; /* Need a new list for the target nodes. */ ! Array_Reset(>argets); inDependency = true; dep = NULL; *************** *** 1598,1604 **** mainNode = NULL; Lst_Init(parseIncPath); Lst_Init(sysIncPath); ! Lst_Init(&targets); LowParse_Init(); #ifdef CLEANUP Lst_Init(&targCmds); --- 1593,1601 ---- mainNode = NULL; Lst_Init(parseIncPath); Lst_Init(sysIncPath); ! Array_Init(&gsources, SOURCES_SIZE); ! Array_Init(>argets, TARGETS_SIZE); ! LowParse_Init(); #ifdef CLEANUP Lst_Init(&targCmds); *************** *** 1610,1616 **** Parse_End() { Lst_Destroy(&targCmds, (SimpleProc)free); - Lst_Destroy(&targets, NOFREE); Lst_Destroy(sysIncPath, Dir_Destroy); Lst_Destroy(parseIncPath, Dir_Destroy); LowParse_End(); --- 1607,1612 ----