summaryrefslogtreecommitdiffstats
path: root/usr.bin/make/for.c
diff options
context:
space:
mode:
authorjkh <jkh@FreeBSD.org>1995-01-23 21:03:17 +0000
committerjkh <jkh@FreeBSD.org>1995-01-23 21:03:17 +0000
commit2dab142d474fb234edc194c7335fd5a627df77a6 (patch)
tree4fe60a8bd60f90f8461d826b8a6c0cd471c798d3 /usr.bin/make/for.c
parenta8745a0ec131df320b6a7be781964c129c33644f (diff)
downloadFreeBSD-src-2dab142d474fb234edc194c7335fd5a627df77a6.zip
FreeBSD-src-2dab142d474fb234edc194c7335fd5a627df77a6.tar.gz
Bring in a number of changes from NetBSD's make, fixing quite a few
problems in the process: 1. Quoting should work properly now. In particular, Chet's reported bash make problem has gone away. 2. A lot of memory that just wasn't being free'd after use is now freed. This should cause make to take up a LOT less memory when dealing with archive targets. 3. Give proper credit to Adam de Boor in a number of files. Obtained from: NetBSD (and Adam de Boor)
Diffstat (limited to 'usr.bin/make/for.c')
-rw-r--r--usr.bin/make/for.c55
1 files changed, 29 insertions, 26 deletions
diff --git a/usr.bin/make/for.c b/usr.bin/make/for.c
index e16d5ff..dbefad6 100644
--- a/usr.bin/make/for.c
+++ b/usr.bin/make/for.c
@@ -1,9 +1,6 @@
/*
- * Copyright (c) 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Christos Zoulas.
+ * Copyright (c) 1992, The Regents of the University of California.
+ * All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -76,13 +73,13 @@ static Lst forLst; /* List of items */
/*
* State of a for loop.
*/
-struct For {
+typedef struct _For {
Buffer buf; /* Unexpanded buffer */
char* var; /* Index name */
Lst lst; /* List of variables */
-};
+} For;
-static int ForExec __P((char *, struct For *));
+static int ForExec __P((ClientData, ClientData));
@@ -118,27 +115,28 @@ For_Eval (line)
Buffer buf;
int varlen;
- for (ptr++; *ptr && isspace(*ptr); ptr++)
+ for (ptr++; *ptr && isspace((unsigned char) *ptr); ptr++)
continue;
/*
* If we are not in a for loop quickly determine if the statement is
* a for.
*/
- if (ptr[0] != 'f' || ptr[1] != 'o' || ptr[2] != 'r' || !isspace(ptr[3]))
+ if (ptr[0] != 'f' || ptr[1] != 'o' || ptr[2] != 'r' ||
+ !isspace((unsigned char) ptr[3]))
return FALSE;
ptr += 3;
/*
* we found a for loop, and now we are going to parse it.
*/
- while (*ptr && isspace(*ptr))
+ while (*ptr && isspace((unsigned char) *ptr))
ptr++;
/*
* Grab the variable
*/
buf = Buf_Init(0);
- for (wrd = ptr; *ptr && !isspace(*ptr); ptr++)
+ for (wrd = ptr; *ptr && !isspace((unsigned char) *ptr); ptr++)
continue;
Buf_AddBytes(buf, ptr - wrd, (Byte *) wrd);
@@ -149,20 +147,21 @@ For_Eval (line)
}
Buf_Destroy(buf, FALSE);
- while (*ptr && isspace(*ptr))
+ while (*ptr && isspace((unsigned char) *ptr))
ptr++;
/*
* Grab the `in'
*/
- if (ptr[0] != 'i' || ptr[1] != 'n' || !isspace(ptr[2])) {
+ if (ptr[0] != 'i' || ptr[1] != 'n' ||
+ !isspace((unsigned char) ptr[2])) {
Parse_Error (level, "missing `in' in for");
printf("%s\n", ptr);
return 0;
}
ptr += 3;
- while (*ptr && isspace(*ptr))
+ while (*ptr && isspace((unsigned char) *ptr))
ptr++;
/*
@@ -178,14 +177,14 @@ For_Eval (line)
Lst_AtEnd(forLst, (ClientData) Buf_GetAll(buf, &varlen)), \
Buf_Destroy(buf, FALSE)
- for (ptr = sub; *ptr && isspace(*ptr); ptr++)
+ for (ptr = sub; *ptr && isspace((unsigned char) *ptr); ptr++)
continue;
for (wrd = ptr; *ptr; ptr++)
- if (isspace(*ptr)) {
+ if (isspace((unsigned char) *ptr)) {
ADDWORD();
buf = Buf_Init(0);
- while (*ptr && isspace(*ptr))
+ while (*ptr && isspace((unsigned char) *ptr))
ptr++;
wrd = ptr--;
}
@@ -203,10 +202,11 @@ For_Eval (line)
}
else if (*ptr == '.') {
- for (ptr++; *ptr && isspace(*ptr); ptr++)
+ for (ptr++; *ptr && isspace((unsigned char) *ptr); ptr++)
continue;
- if (strncmp(ptr, "endfor", 6) == 0 && (isspace(ptr[6]) || !ptr[6])) {
+ if (strncmp(ptr, "endfor", 6) == 0 &&
+ (isspace((unsigned char) ptr[6]) || !ptr[6])) {
if (DEBUG(FOR))
(void) fprintf(stderr, "For: end for %d\n", forLevel);
if (--forLevel < 0) {
@@ -214,7 +214,8 @@ For_Eval (line)
return 0;
}
}
- else if (strncmp(ptr, "for", 3) == 0 && isspace(ptr[3])) {
+ else if (strncmp(ptr, "for", 3) == 0 &&
+ isspace((unsigned char) ptr[3])) {
forLevel++;
if (DEBUG(FOR))
(void) fprintf(stderr, "For: new loop %d\n", forLevel);
@@ -245,10 +246,12 @@ For_Eval (line)
*-----------------------------------------------------------------------
*/
static int
-ForExec(name, arg)
- char *name;
- struct For *arg;
+ForExec(namep, argp)
+ ClientData namep;
+ ClientData argp;
{
+ char *name = (char *) namep;
+ For *arg = (For *) argp;
int len;
Var_Set(arg->var, name, VAR_GLOBAL);
if (DEBUG(FOR))
@@ -277,7 +280,7 @@ ForExec(name, arg)
void
For_Run()
{
- struct For arg;
+ For arg;
if (forVar == NULL || forBuf == NULL || forLst == NULL)
return;
@@ -291,6 +294,6 @@ For_Run()
Lst_ForEach(arg.lst, ForExec, (ClientData) &arg);
free((Address)arg.var);
- Lst_Destroy(arg.lst, free);
+ Lst_Destroy(arg.lst, (void (*) __P((ClientData))) free);
Buf_Destroy(arg.buf, TRUE);
}
OpenPOWER on IntegriCloud