summaryrefslogtreecommitdiffstats
path: root/usr.bin/make/var.c
diff options
context:
space:
mode:
authorharti <harti@FreeBSD.org>2005-05-18 14:50:35 +0000
committerharti <harti@FreeBSD.org>2005-05-18 14:50:35 +0000
commite6b2d317a96aecaf351b34c86989a87480496591 (patch)
tree3e8049c3572286310644109c58b11ff0e0ea83b4 /usr.bin/make/var.c
parentc355fa8659de0fe742763123445875b6ae9bbd32 (diff)
downloadFreeBSD-src-e6b2d317a96aecaf351b34c86989a87480496591.zip
FreeBSD-src-e6b2d317a96aecaf351b34c86989a87480496591.tar.gz
Get rid of global variables for argument vectors produced by brk_string()
introduce a struct that holds all the information about an argument vector and pass that around. Author: Max Okumoto <okumoto@ucsd.edu> Obtained from: DragonFlyBSD
Diffstat (limited to 'usr.bin/make/var.c')
-rw-r--r--usr.bin/make/var.c46
1 files changed, 22 insertions, 24 deletions
diff --git a/usr.bin/make/var.c b/usr.bin/make/var.c
index 077ddbf..cb40a49 100644
--- a/usr.bin/make/var.c
+++ b/usr.bin/make/var.c
@@ -1178,21 +1178,23 @@ Var_Value(const char *name, GNode *ctxt, char **frp)
static char *
VarModify(const char *str, VarModifyProc *modProc, void *datum)
{
- char **av; /* word list [first word does not count] */
- int ac;
- Buffer *buf; /* Buffer for the new string */
- Boolean addSpace; /* TRUE if need to add a space to the buffer
- * before adding the trimmed word */
- int i;
-
- av = brk_string(str, &ac, FALSE);
+ ArgArray aa;
+ Buffer *buf; /* Buffer for the new string */
+ int i;
+ Boolean addSpace; /*
+ * TRUE if need to add a space to
+ * the buffer before adding the
+ * trimmed word
+ */
- buf = Buf_Init(0);
+ brk_string(&aa, str, FALSE);
addSpace = FALSE;
- for (i = 1; i < ac; i++)
- addSpace = (*modProc)(av[i], addSpace, buf, datum);
+ buf = Buf_Init(0);
+ for (i = 1; i < aa.argc; i++)
+ addSpace = (*modProc)(aa.argv[i], addSpace, buf, datum);
+ ArgArray_Done(&aa);
return (Buf_Peel(buf));
}
@@ -1205,28 +1207,24 @@ VarModify(const char *str, VarModifyProc *modProc, void *datum)
*
* Results:
* A string containing the words sorted
- *
- * Side Effects:
- * Uses brk_string() so it invalidates any previous call to
- * brk_string().
*/
static char *
VarSortWords(const char *str, int (*cmp)(const void *, const void *))
{
- char **av;
- int ac;
- Buffer *buf;
- int i;
+ ArgArray aa;
+ Buffer *buf;
+ int i;
- av = brk_string(str, &ac, FALSE);
- qsort(av + 1, ac - 1, sizeof(char *), cmp);
+ brk_string(&aa, str, FALSE);
+ qsort(aa.argv + 1, aa.argc - 1, sizeof(char *), cmp);
buf = Buf_Init(0);
- for (i = 1; i < ac; i++) {
- Buf_Append(buf, av[i]);
- Buf_AddByte(buf, (Byte)((i < ac - 1) ? ' ' : '\0'));
+ for (i = 1; i < aa.argc; i++) {
+ Buf_Append(buf, aa.argv[i]);
+ Buf_AddByte(buf, (Byte)((i < aa.argc - 1) ? ' ' : '\0'));
}
+ ArgArray_Done(&aa);
return (Buf_Peel(buf));
}
OpenPOWER on IntegriCloud