diff options
author | Dan Nicholson <dbn.lists@gmail.com> | 2008-04-02 17:47:37 -0700 |
---|---|---|
committer | Dan Nicholson <dbn.lists@gmail.com> | 2008-04-02 17:47:37 -0700 |
commit | 59701f36342cc1a2467caa2641e60b085db4512d (patch) | |
tree | e8736a4b0c1663747cf57d7530d660a8bf958359 /test | |
parent | 7e096f805d8ae6f2d813859b693e3fe0d3e19f48 (diff) |
Convert dep_t and prov_t to strarg types
Rather than duplicating a bunch of code in deps.c and prov.c to handle
arrays of strings, dep_t and prov_t have been converted to strarg_t.
Additionally, the functions to handle these types are now just macros
pointing to the associated strarg functions.
To handle these changes, the strarg functions have been converted to
actually work on strarg_t's instead of char** directly.
The deps and prov functionality, as well as the other types in struct
initd, have been moved into the types.h header.
Diffstat (limited to 'test')
-rw-r--r-- | test/tdep.c | 2 | ||||
-rw-r--r-- | test/tstrarg.c | 26 |
2 files changed, 11 insertions, 17 deletions
diff --git a/test/tdep.c b/test/tdep.c index 8836f47..02192dc 100644 --- a/test/tdep.c +++ b/test/tdep.c @@ -3,7 +3,7 @@ #endif #include <stdio.h> #include <string.h> -#include "dep.h" +#include "types.h" static void print_dep(dep_t *sa); diff --git a/test/tstrarg.c b/test/tstrarg.c index aa7c9a8..3e03e7b 100644 --- a/test/tstrarg.c +++ b/test/tstrarg.c @@ -10,42 +10,36 @@ int main(int argc, char *argv[]) { int n; - strarg_t *test = malloc(sizeof(strarg_t)); - if (!test) - error(2, errno, "malloc"); + strarg_t *test = strarg_new(); - test->str = strarg_new(&test->nstr); - - test->str = strarg_add(test->str, &test->nstr, "hello"); - test->str = strarg_add(test->str, &test->nstr, "world"); - test->str = strarg_add(test->str, &test->nstr, "it's"); - test->str = strarg_add(test->str, &test->nstr, "me"); + strarg_add(test, "hello"); + strarg_add(test, "world"); + strarg_add(test, "it's"); + strarg_add(test, "me"); printf("Contents of test strarg\n"); for (n = 0; n < strarg_get_num(test); n++) printf("Arg %d: %s\n", n, strarg_get_str(test, n)); - if (strarg_exists(test->str, test->nstr, "world")) + if (strarg_exists(test, "world")) printf("Found \"world\" in test\n"); else printf("Didn't find \"world\" in test\n"); - if (strarg_exists(test->str, test->nstr, "barf")) + if (strarg_exists(test, "barf")) printf("Found \"barf\" in test\n"); else printf("Didn't find \"barf\" in test\n"); printf("Removing last two elements\n"); - test->str = strarg_pop(test->str, &test->nstr); - test->str = strarg_pop(test->str, &test->nstr); + strarg_pop(test); + strarg_pop(test); printf("Contents of test strarg\n"); for (n = 0; n < strarg_get_num(test); n++) printf("Arg %d: %s\n", n, strarg_get_str(test, n)); - strarg_free(test->str, test->nstr); - free(test); - test = NULL; + strarg_free(test); return 0; } |