=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/make/for.c,v retrieving revision 1.24 retrieving revision 1.25 diff -c -r1.24 -r1.25 *** src/usr.bin/make/for.c 2001/05/03 13:41:05 1.24 --- src/usr.bin/make/for.c 2001/05/23 12:34:42 1.25 *************** *** 1,5 **** /* $OpenPackages$ */ ! /* $OpenBSD: for.c,v 1.24 2001/05/03 13:41:05 espie Exp $ */ /* $NetBSD: for.c,v 1.4 1996/11/06 17:59:05 christos Exp $ */ /* --- 1,5 ---- /* $OpenPackages$ */ ! /* $OpenBSD: for.c,v 1.25 2001/05/23 12:34:42 espie Exp $ */ /* $NetBSD: for.c,v 1.4 1996/11/06 17:59:05 christos Exp $ */ /* *************** *** 62,93 **** * SUCH DAMAGE. */ ! /*- ! * for.c -- ! * Functions to handle loops in a makefile. ! * ! * Interface: ! * For_Eval Evaluate the .for in the passed line. ! * For_Accumulate Add lines to an accumulating loop ! * For_Run Run accumulated loop ! * ! */ - #include - #include - #include - #include "make.h" - #include "buf.h" - - #ifndef lint - #if 0 - static char sccsid[] = "@(#)for.c 8.1 (Berkeley) 6/6/93"; - #else - UNUSED - static char rcsid[] = "$OpenBSD: for.c,v 1.24 2001/05/03 13:41:05 espie Exp $"; - #endif - #endif /* not lint */ - /* * For statements are of the form: * --- 62,83 ---- * SUCH DAMAGE. */ ! #include ! #include ! #include ! #include ! #include ! #include "config.h" ! #include "defines.h" ! #include "buf.h" ! #include "for.h" ! #include "lst.h" ! #include "error.h" ! #include "var.h" ! #include "lowparse.h" ! #include "str.h" ! #include "memory.h" /* * For statements are of the form: * *************** *** 104,125 **** /* State of a for loop. */ struct For_ { ! char *text; /* unexpanded text */ ! LIST vars; /* list of variables */ ! LstNode var; /* current var */ ! int nvars; /* total number of vars */ LIST lst; /* List of items */ size_t guess; /* Estimated expansion size */ BUFFER buf; /* Accumulating text */ unsigned long lineno; /* Line number at start of loop */ unsigned long level; /* Nesting level */ ! Boolean freeold; }; static void ForExec(void *, void *); static unsigned long build_words_list(Lst, const char *); - /* Cut a string into words, stuff that into list. */ static unsigned long build_words_list(lst, s) Lst lst; --- 94,121 ---- /* State of a for loop. */ struct For_ { ! char *text; /* Unexpanded text */ ! LIST vars; /* List of variables */ ! LstNode var; /* Current var */ ! int nvars; /* Total number of vars */ LIST lst; /* List of items */ size_t guess; /* Estimated expansion size */ BUFFER buf; /* Accumulating text */ unsigned long lineno; /* Line number at start of loop */ unsigned long level; /* Nesting level */ ! bool freeold; }; + /* ForExec(value, handle); + * Expands next variable in loop sequence described by handle to value. */ static void ForExec(void *, void *); + + /* n = build_words_list(lst, s); + * Cuts string into words, pushes words into list, in reverse order, + * because Parse_FromString works as a stack. + * Returns the number of words. */ static unsigned long build_words_list(Lst, const char *); static unsigned long build_words_list(lst, s) Lst lst; *************** *** 132,156 **** end = s; while ((wrd = iterate_words(&end)) != NULL) { ! Lst_AtFront(lst, escape_dup(wrd, end, "\"'")); n++; } return n; } - /* - *----------------------------------------------------------------------- - * For_Eval -- - * Evaluate the for loop in the passed line. The line - * looks like this: - * .for in - * - * Results: - * Loop structure, to accumulate further lines. - * NULL if this was not a for loop after all. - *----------------------------------------------------------------------- - */ - For * For_Eval(line) const char *line; /* Line to parse */ --- 128,139 ---- end = s; while ((wrd = iterate_words(&end)) != NULL) { ! Lst_AtFront(lst, escape_dupi(wrd, end, "\"'")); n++; } return n; } For * For_Eval(line) const char *line; /* Line to parse */ *************** *** 189,198 **** endVar = ptr++; while (*ptr && isspace(*ptr)) ptr++; ! /* finished variable list */ if (endVar - wrd == 2 && wrd[0] == 'i' && wrd[1] == 'n') break; ! Lst_AtEnd(&arg->vars, interval_dup(wrd, endVar)); arg->nvars++; } if (arg->nvars == 0) { --- 172,181 ---- endVar = ptr++; while (*ptr && isspace(*ptr)) ptr++; ! /* End of variable list ? */ if (endVar - wrd == 2 && wrd[0] == 'i' && wrd[1] == 'n') break; ! Lst_AtEnd(&arg->vars, Str_dupi(wrd, endVar)); arg->nvars++; } if (arg->nvars == 0) { *************** *** 201,207 **** } /* Make a list with the remaining words. */ ! sub = Var_Subst(ptr, NULL, FALSE); if (DEBUG(FOR)) { LstNode ln; (void)fprintf(stderr, "For: Iterator "); --- 184,190 ---- } /* Make a list with the remaining words. */ ! sub = Var_Subst(ptr, NULL, false); if (DEBUG(FOR)) { LstNode ln; (void)fprintf(stderr, "For: Iterator "); *************** *** 225,244 **** } ! /*- ! *----------------------------------------------------------------------- ! * For_Accumulate -- ! * Accumulate lines in a for loop, until we find the matching endfor. ! * ! * Results: ! * TRUE: keep accumulating lines. ! * FALSE: We found the matching .endfor ! * ! * Side Effects: ! * Accumulate lines in arg. ! *----------------------------------------------------------------------- ! */ ! Boolean For_Accumulate(arg, line) For *arg; const char *line; /* Line to parse */ --- 208,214 ---- } ! bool For_Accumulate(arg, line) For *arg; const char *line; /* Line to parse */ *************** *** 258,264 **** (void)fprintf(stderr, "For: end for %lu\n", arg->level); /* If matching endfor, don't add line to buffer. */ if (--arg->level == 0) ! return FALSE; } else if (strncmp(ptr, "for", 3) == 0 && isspace(ptr[3])) { --- 228,234 ---- (void)fprintf(stderr, "For: end for %lu\n", arg->level); /* If matching endfor, don't add line to buffer. */ if (--arg->level == 0) ! return false; } else if (strncmp(ptr, "for", 3) == 0 && isspace(ptr[3])) { *************** *** 269,291 **** } Buf_AddString(&arg->buf, line); Buf_AddChar(&arg->buf, '\n'); ! return TRUE; } #define GUESS_EXPANSION 32 - /*- - *----------------------------------------------------------------------- - * ForExec -- - * Expand the for loop for this index and push it in the Makefile - *----------------------------------------------------------------------- - */ static void ! ForExec(namep, argp) ! void *namep; void *argp; { ! char *name = (char *)namep; For *arg = (For *)argp; BUFFER buf; --- 239,255 ---- } Buf_AddString(&arg->buf, line); Buf_AddChar(&arg->buf, '\n'); ! return true; } #define GUESS_EXPANSION 32 static void ! ForExec(valuep, argp) ! void *valuep; void *argp; { ! char *value = (char *)valuep; For *arg = (For *)argp; BUFFER buf; *************** *** 294,322 **** if (arg->var == NULL) { arg->var = Lst_Last(&arg->vars); arg->text = Buf_Retrieve(&arg->buf); ! arg->freeold = FALSE; } if (DEBUG(FOR)) ! (void)fprintf(stderr, "--- %s = %s\n", (char *)Lst_Datum(arg->var), name); Buf_Init(&buf, arg->guess); ! Var_SubstVar(&buf, arg->text, Lst_Datum(arg->var), name); if (arg->freeold) free(arg->text); arg->text = Buf_Retrieve(&buf); ! arg->freeold = TRUE; arg->var = Lst_Rev(arg->var); if (arg->var == NULL) Parse_FromString(arg->text, arg->lineno); } - - /*- - *----------------------------------------------------------------------- - * For_Run -- - * Run the for loop, pushing expanded lines for reparse - *----------------------------------------------------------------------- - */ void For_Run(arg) --- 258,280 ---- if (arg->var == NULL) { arg->var = Lst_Last(&arg->vars); arg->text = Buf_Retrieve(&arg->buf); ! arg->freeold = false; } if (DEBUG(FOR)) ! (void)fprintf(stderr, "--- %s = %s\n", (char *)Lst_Datum(arg->var), ! value); Buf_Init(&buf, arg->guess); ! Var_SubstVar(&buf, arg->text, Lst_Datum(arg->var), value); if (arg->freeold) free(arg->text); arg->text = Buf_Retrieve(&buf); ! arg->freeold = true; arg->var = Lst_Rev(arg->var); if (arg->var == NULL) Parse_FromString(arg->text, arg->lineno); } void For_Run(arg)