From 30fe1fae39e541a7c6c65f4e6d64d11632110de2 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sun, 6 May 2012 20:12:11 -0500 Subject: [PATCH] parse: replace strdup_parse with pkg_tuple_parse(). --- main.c | 2 +- parse.c | 61 +++++---------------------------------------------------- pkg.h | 2 +- 3 files changed, 7 insertions(+), 58 deletions(-) diff --git a/main.c b/main.c index bd52b6c..88a55fb 100644 --- a/main.c +++ b/main.c @@ -172,7 +172,7 @@ print_variable(pkg_t *pkg, void *unused) variable_tmpl = pkg_tuple_find(pkg->vars, want_variable); if (variable_tmpl != NULL) { - char *var = strdup_parse(pkg, variable_tmpl); + char *var = pkg_tuple_parse(pkg->vars, variable_tmpl); printf("%s", var); diff --git a/parse.c b/parse.c index a0b0014..4c70461 100644 --- a/parse.c +++ b/parse.c @@ -24,63 +24,12 @@ #include "pkg.h" #include "bsdstubs.h" -char * -strdup_parse(pkg_t *pkg, const char *value) -{ - char buf[BUFSIZ]; - const char *ptr; - char *bptr = buf; - - for (ptr = value; *ptr != '\0' && bptr - buf < BUFSIZ; ptr++) - { - if (*ptr != '$') - *bptr++ = *ptr; - else if (*(ptr + 1) == '{') - { - static char varname[BUFSIZ]; - char *vptr = varname; - const char *pptr; - char *kv, *parsekv; - - *vptr = '\0'; - - for (pptr = ptr + 2; *pptr != '\0'; pptr++) - { - if (*pptr != '}') - *vptr++ = *pptr; - else - { - *vptr = '\0'; - break; - } - } - - ptr += (pptr - ptr); - kv = pkg_tuple_find(pkg->vars, varname); - - if (kv != NULL) - { - parsekv = strdup_parse(pkg, kv); - - strncpy(bptr, parsekv, BUFSIZ - (bptr - buf)); - bptr += strlen(parsekv); - - free(parsekv); - } - } - } - - *bptr = '\0'; - - return strdup(buf); -} - static pkg_fragment_t * parse_fragment_list(pkg_t *pkg, const char *string) { int i, argc; char **argv; - char *repstr = strdup_parse(pkg, string); + char *repstr = pkg_tuple_parse(pkg->vars, string); pkg_fragment_t *head = NULL; argv_split(repstr, &argc, &argv); @@ -166,7 +115,7 @@ parse_deplist(pkg_t *pkg, const char *depends) pkg_dependency_t *deplist_head = NULL; pkg_comparator_t compare = PKG_ANY; char buf[BUFSIZ]; - char *kvdepends = strdup_parse(pkg, depends); + char *kvdepends = pkg_tuple_parse(pkg->vars, depends); char *start = buf; char *ptr = buf; char *vstart = NULL; @@ -389,11 +338,11 @@ parse_file(const char *filename, FILE *f) { case ':': if (!strcasecmp(key, "Name")) - pkg->realname = strdup_parse(pkg, value); + pkg->realname = pkg_tuple_parse(pkg->vars, value); else if (!strcasecmp(key, "Description")) - pkg->description = strdup_parse(pkg, value); + pkg->description = pkg_tuple_parse(pkg->vars, value); else if (!strcasecmp(key, "Version")) - pkg->version = strdup_parse(pkg, value); + pkg->version = pkg_tuple_parse(pkg->vars, value); else if (!strcasecmp(key, "CFLAGS")) pkg->cflags = parse_fragment_list(pkg, value); else if (!strcasecmp(key, "LIBS")) diff --git a/pkg.h b/pkg.h index 8f43a91..af46543 100644 --- a/pkg.h +++ b/pkg.h @@ -137,7 +137,6 @@ const char *pkg_get_comparator(pkg_dependency_t *pkgdep); pkg_t *parse_file(const char *path, FILE *f); pkg_dependency_t *parse_deplist(pkg_t *pkg, const char *depends); pkg_dependency_t *pkg_dependency_append(pkg_dependency_t *head, pkg_dependency_t *tail); -char *strdup_parse(pkg_t *pkg, const char *value); /* argvsplit.c */ int argv_split(const char *src, int *argc, char ***argv); @@ -155,5 +154,6 @@ char *pkg_fgetline(char *line, size_t size, FILE *stream); /* tuple.c */ pkg_tuple_t *pkg_tuple_add(pkg_tuple_t *parent, const char *key, const char *value); char *pkg_tuple_find(pkg_tuple_t *head, const char *key); +char *pkg_tuple_parse(pkg_tuple_t *vars, const char *value); #endif