Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
rename pkg_config_list to pkg_config_kvlist and create a pkg_config_list (string list)
Baptiste Daroussin committed 13 years ago
commit c9c16e97e66b99ad4826eb1f362ec86e1aeadde1
parent fd6e54b
6 files changed +92 -20
modified libpkg/pkg.c
@@ -256,7 +256,7 @@ pkg_set_repourl(struct pkg *pkg, const char *str)
{
	struct pkg_config_kv *rkv = NULL;

-
	while (pkg_config_list(PKG_CONFIG_REPOS, &rkv) == EPKG_OK) {
+
	while (pkg_config_kvlist(PKG_CONFIG_REPOS, &rkv) == EPKG_OK) {
		const char *key = pkg_config_kv_get(rkv, PKG_CONFIG_KV_KEY);
		const char *val = pkg_config_kv_get(rkv, PKG_CONFIG_KV_VALUE);
		if (strcmp(str, key) == 0)
modified libpkg/pkg.h
@@ -64,6 +64,7 @@ struct pkg_repos;
struct pkg_repos_entry;

struct pkg_config_kv;
+
struct pkg_config_value;

struct pkg_plugins;

@@ -264,6 +265,7 @@ typedef enum _pkg_config_key {
	PKG_CONFIG_FETCH_RETRY,
	PKG_CONFIG_PLUGINS_DIR,
	PKG_CONFIG_ENABLE_PLUGINS,
+
	PKG_CONFIG_PLUGINS,
	PKG_CONFIG_PLUGINS_SUMMARY,
	PKG_CONFIG_DEBUG_SCRIPTS,
} pkg_config_key;
@@ -936,8 +938,10 @@ bool pkg_plugins_provides_cmd(struct pkg_plugins *p);
 */
int pkg_config_string(pkg_config_key key, const char **value);
int pkg_config_bool(pkg_config_key key, bool *value);
-
int pkg_config_list(pkg_config_key key, struct pkg_config_kv **kv);
+
int pkg_config_kvlist(pkg_config_key key, struct pkg_config_kv **kv);
+
int pkg_config_list(pkg_config_key key, struct pkg_config_value **v);
const char *pkg_config_kv_get(struct pkg_config_kv *kv, pkg_config_kv_t type);
+
const char *pkg_config_value(struct pkg_config_value *v);
int pkg_config_int64(pkg_config_key key, int64_t *value);

/**
modified libpkg/pkg_config.c
@@ -41,8 +41,9 @@

#define STRING 0
#define BOOL 1
-
#define LIST 2
+
#define KVLIST 2
#define INTEGER 3
+
#define LIST 4

#define ABI_VAR_STRING "${ABI}"

@@ -52,13 +53,19 @@ struct pkg_config_kv {
	STAILQ_ENTRY(pkg_config_kv) next;
};

+
struct pkg_config_value {
+
	char *value;
+
	STAILQ_ENTRY(pkg_config_value) next;
+
};
+

struct config_entry {
	uint8_t type;
	const char *key;
	const char *def;
	union {
		char *val;
-
		STAILQ_HEAD(, pkg_config_kv) list;
+
		STAILQ_HEAD(, pkg_config_kv) kvlist;
+
		STAILQ_HEAD(, pkg_config_value) list;
	};
};

@@ -114,7 +121,7 @@ static struct config_entry c[] = {
		{ NULL }
	},
	[PKG_CONFIG_REPOS] = {
-
		LIST,
+
		KVLIST,
		"REPOS",
		"NULL",
		{ NULL }
@@ -176,13 +183,19 @@ static struct config_entry c[] = {
	[PKG_CONFIG_PLUGINS_DIR] = {
		STRING,
		"PKG_PLUGINS_DIR",
-
		"/usr/local/etc/pkg/plugins",
+
		PREFIX"lib/pkg/",
		{ NULL }
	},
	[PKG_CONFIG_ENABLE_PLUGINS] = {
		BOOL,
		"PKG_ENABLE_PLUGINS",
-
		"NO",
+
		"YES",
+
		{ NULL }
+
	},
+
	[PKG_CONFIG_PLUGINS] = {
+
		LIST,
+
		"PLUGINS",
+
		"NULL",
		{ NULL }
	},
	[PKG_CONFIG_PLUGINS_SUMMARY] = {
@@ -203,13 +216,34 @@ static bool parsed = false;
static size_t c_size = sizeof(c) / sizeof(struct config_entry);

static void
+
parse_config_sequence(yaml_document_t *doc, yaml_node_t *seq, size_t ent)
+
{
+
	yaml_node_item_t *item = seq->data.sequence.items.top;
+
	yaml_node_t *val;
+
	struct pkg_config_value *v;
+

+
	STAILQ_INIT(&c[ent].list);
+
	while (item < seq->data.sequence.items.top) {
+
		val = yaml_document_get_node(doc, *item);
+
		if (val->type != YAML_SCALAR_NODE) {
+
			++item;
+
			continue;
+
		}
+
		v = malloc(sizeof(struct pkg_config_value));
+
		v->value = strdup(val->data.scalar.value);
+
		STAILQ_INSERT_TAIL(&(c[ent].list), v, next);
+
		++item;
+
	}
+
}
+

+
static void
parse_config_mapping(yaml_document_t *doc, yaml_node_t *map, size_t ent)
{
	yaml_node_pair_t *subpair = map->data.mapping.pairs.start;
	yaml_node_t *subkey, *subval;
	struct pkg_config_kv *kv;

-
	STAILQ_INIT(&c[ent].list);
+
	STAILQ_INIT(&c[ent].kvlist);
	while (subpair < map->data.mapping.pairs.top) {
		subkey = yaml_document_get_node(doc, subpair->key);
		subval = yaml_document_get_node(doc, subpair->value);
@@ -221,7 +255,7 @@ parse_config_mapping(yaml_document_t *doc, yaml_node_t *map, size_t ent)
		kv = malloc(sizeof(struct pkg_config_kv));
		kv->key = strdup(subkey->data.scalar.value);
		kv->value = strdup(subval->data.scalar.value);
-
		STAILQ_INSERT_TAIL(&(c[ent].list), kv, next);
+
		STAILQ_INSERT_TAIL(&(c[ent].kvlist), kv, next);
		++subpair;
	}
}
@@ -270,6 +304,8 @@ parse_configuration(yaml_document_t *doc, yaml_node_t *node)
				c[ent].val = strdup(val->data.scalar.value);
			else if (val->type == YAML_MAPPING_NODE)
				parse_config_mapping(doc, val, ent);
+
			else if (val->type == YAML_SEQUENCE_NODE)
+
				parse_config_sequence(doc, val, ent);
		}
		/*
		 * unknown values are just silently ignored, because we don't
@@ -405,23 +441,22 @@ pkg_config_bool(pkg_config_key key, bool *val)
}

int
-
pkg_config_list(pkg_config_key key, struct pkg_config_kv **kv)
+
pkg_config_kvlist(pkg_config_key key, struct pkg_config_kv **kv)
{
	if (parsed != true) {
-
		pkg_emit_error("pkg_init() must be called before pkg_config_list()");
+
		pkg_emit_error("pkg_init() must be called before pkg_config_kvlist()");
		return (EPKG_FATAL);
	}

-
	if (c[key].type != LIST) {
-
		pkg_emit_error("this config entry is not a list");
+
	if (c[key].type != KVLIST) {
+
		pkg_emit_error("this config entry is not a \"key: value\" list");
		return (EPKG_FATAL);
	}

-
	if (*kv == NULL) {
-
		*kv = STAILQ_FIRST(&(c[key].list));
-
	} else {
+
	if (*kv == NULL)
+
		*kv = STAILQ_FIRST(&(c[key].kvlist));
+
	else
		*kv = STAILQ_NEXT(*kv, next);
-
	}

	if (*kv == NULL)
		return (EPKG_END);
@@ -429,6 +464,38 @@ pkg_config_list(pkg_config_key key, struct pkg_config_kv **kv)
		return (EPKG_OK);
}

+
int
+
pkg_config_list(pkg_config_key key, struct pkg_config_value **v)
+
{
+
	if (parsed != true) {
+
		pkg_emit_error("pkg_init() must be called before pkg_config_list()");
+
		return (EPKG_FATAL);
+
	}
+

+
	if (c[key].type != LIST) {
+
		pkg_emit_error("this config entry is not a list");
+
		return (EPKG_FATAL);
+
	}
+

+
	if (*v == NULL)
+
		*v = STAILQ_FIRST(&(c[key].list));
+
	else
+
		*v = STAILQ_NEXT(*v, next);
+
	if (*v == NULL)
+
		return (EPKG_END);
+
	else
+
		return (EPKG_OK);
+
};
+

+
const char *
+
pkg_config_value(struct pkg_config_value *v)
+
{
+
	assert(v != NULL);
+

+
	return (v->value);
+
}
+

+

const char *
pkg_config_kv_get(struct pkg_config_kv *kv, pkg_config_kv_t type)
{
@@ -518,6 +585,7 @@ pkg_shutdown(void)
				free(c[i].val);
				break;
			case LIST:
+
			case KVLIST:
				break;
			case INTEGER:
				break;
modified libpkg/pkgdb.c
@@ -643,7 +643,7 @@ pkgdb_open_multirepos(const char *dbdir, struct pkgdb *db)

	fprintf(stderr, "%s", multirepo_warning);

-
	while (pkg_config_list(PKG_CONFIG_REPOS, &repokv) == EPKG_OK) {
+
	while (pkg_config_kvlist(PKG_CONFIG_REPOS, &repokv) == EPKG_OK) {
		const char *repo_name = pkg_config_kv_get(repokv,
		    PKG_CONFIG_KV_KEY);

modified pkg/main.c
@@ -322,7 +322,7 @@ main(int argc, char **argv)
		pkg_config_bool(PKG_CONFIG_MULTIREPOS, &b);
		if (b) {
			printf("Repositories:\n");
-
			while (pkg_config_list(PKG_CONFIG_REPOS, &kv) == EPKG_OK) {
+
			while (pkg_config_kvlist(PKG_CONFIG_REPOS, &kv) == EPKG_OK) {
				printf("             - %s: %s\n", pkg_config_kv_get(kv, PKG_CONFIG_KV_KEY),
				    pkg_config_kv_get(kv, PKG_CONFIG_KV_VALUE));
			}
modified pkg/update.c
@@ -78,7 +78,7 @@ pkgcli_update(bool force) {
		}
	} else {
		/* multiple repositories */
-
		while (pkg_config_list(PKG_CONFIG_REPOS, &repokv) == EPKG_OK) {
+
		while (pkg_config_kvlist(PKG_CONFIG_REPOS, &repokv) == EPKG_OK) {
			repo_name = pkg_config_kv_get(repokv, PKG_CONFIG_KV_KEY);
			packagesite = pkg_config_kv_get(repokv, PKG_CONFIG_KV_VALUE);