forked from ariadne/pkgconf
parse: replace strdup_parse with pkg_tuple_parse().
parent
4ea25d56f4
commit
30fe1fae39
2
main.c
2
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);
|
||||
|
||||
|
|
61
parse.c
61
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"))
|
||||
|
|
2
pkg.h
2
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
|
||||
|
|
Loading…
Reference in New Issue