Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
s/plugin/plugins in the plugins interface
Marin Atanasov Nikolov committed 13 years ago
commit 682ebe5473e341be2a74b83609b9d5061d249f7b
parent 7e34c7c
3 files changed +46 -46
modified libpkg/pkg.h
@@ -65,7 +65,7 @@ struct pkg_repos_entry;

struct pkg_config_kv;

-
struct pkg_plugin;
+
struct pkg_plugins;

typedef enum {
	/**
@@ -282,13 +282,13 @@ typedef enum _pkg_stats_t {
/**
 * Keys for accessing pkg plugins data
 */
-
typedef enum _pkg_plugin_key {
-
	PKG_PLUGIN_NAME = 0,
-
	PKG_PLUGIN_DESC,
-
	PKG_PLUGIN_VERSION,
-
	PKG_PLUGIN_PLUGINFILE,
-
	PKG_PLUGIN_ENABLED,
-
} pkg_plugin_key;
+
typedef enum _pkg_plugins_key {
+
	PKG_PLUGINS_NAME = 0,
+
	PKG_PLUGINS_DESC,
+
	PKG_PLUGINS_VERSION,
+
	PKG_PLUGINS_PLUGINFILE,
+
	PKG_PLUGINS_ENABLED,
+
} pkg_plugins_key;

/**
 * Error type used everywhere by libpkg.
@@ -890,9 +890,9 @@ int64_t pkgdb_stats(struct pkgdb *db, pkg_stats_t type);
 * pkg plugins functions
 * @todo Document
 */
-
int pkg_plugin_init(void);
-
int pkg_plugin_shutdown(void);
-
int pkg_plugin_list(struct pkg_plugin **plugin);
+
int pkg_plugins_init(void);
+
int pkg_plugins_shutdown(void);
+
int pkg_plugins_list(struct pkg_plugins **plugin);

/**
 * Get the value of a configuration key
modified libpkg/plugins.c
@@ -40,31 +40,31 @@

#define N(a) (sizeof(a) / sizeof(a[0]))

-
struct _pkg_plugin_kv {
+
struct _pkg_plugins_kv {
	 char *key;
	 char *val;
-
} pkg_plugin_kv[] = {
-
	[PKG_PLUGIN_NAME] 	= { __DECONST(char *, "name"), NULL },
-
	[PKG_PLUGIN_DESC] 	= { __DECONST(char *, "description"), NULL },
-
	[PKG_PLUGIN_VERSION] 	= { __DECONST(char *, "version"), NULL },
-
	[PKG_PLUGIN_PLUGINFILE]	= { __DECONST(char *, "plugin"), NULL },
-
	[PKG_PLUGIN_ENABLED]	= { __DECONST(char *, "enabled"), NULL },
+
} pkg_plugins_kv[] = {
+
	[PKG_PLUGINS_NAME] 		= { __DECONST(char *, "name"), NULL },
+
	[PKG_PLUGINS_DESC] 		= { __DECONST(char *, "description"), NULL },
+
	[PKG_PLUGINS_VERSION] 		= { __DECONST(char *, "version"), NULL },
+
	[PKG_PLUGINS_PLUGINFILE]	= { __DECONST(char *, "plugin"), NULL },
+
	[PKG_PLUGINS_ENABLED]		= { __DECONST(char *, "enabled"), NULL },
};

-
struct pkg_plugin {
-
	struct _pkg_plugin_kv fields[N(pkg_plugin_kv)];
-
	STAILQ_ENTRY(pkg_plugin) next;
+
struct pkg_plugins {
+
	struct _pkg_plugins_kv fields[N(pkg_plugins_kv)];
+
	STAILQ_ENTRY(pkg_plugins) next;
};

-
STAILQ_HEAD(plugin_head, pkg_plugin);
-
static struct plugin_head ph = STAILQ_HEAD_INITIALIZER(ph);
+
STAILQ_HEAD(plugins_head, pkg_plugins);
+
static struct plugins_head ph = STAILQ_HEAD_INITIALIZER(ph);

-
static int pkg_plugin_discover(void);
-
static int pkg_plugin_parse_conf(const char *file);
-
static int pkg_plugin_free(void);
+
static int pkg_plugins_discover(void);
+
static int pkg_plugins_parse_conf(const char *file);
+
static int pkg_plugins_free(void);

static int
-
pkg_plugin_discover(void)
+
pkg_plugins_discover(void)
{
	FTS  	*fts = NULL;
	FTSENT	*ftsent = NULL;
@@ -92,7 +92,7 @@ pkg_plugin_discover(void)

		/* parse only .conf files */
		if (strstr(ftsent->fts_name, ".conf") != NULL)
-
			pkg_plugin_parse_conf(ftsent->fts_path);
+
			pkg_plugins_parse_conf(ftsent->fts_path);
	}

	fts_close(fts);
@@ -101,9 +101,9 @@ pkg_plugin_discover(void)
}

static int
-
pkg_plugin_parse_conf(const char *file)
+
pkg_plugins_parse_conf(const char *file)
{
-
	struct pkg_plugin *new = NULL;
+
	struct pkg_plugins *new = NULL;
	properties p = NULL;
	unsigned int i = 0;
	char *temp;
@@ -115,15 +115,15 @@ pkg_plugin_parse_conf(const char *file)
		return (EPKG_FATAL);
	}

-
	if ((new = calloc(1, sizeof(struct pkg_plugin))) == NULL) {
+
	if ((new = calloc(1, sizeof(struct pkg_plugins))) == NULL) {
		pkg_emit_error("Cannot allocate memory");
		return (EPKG_FATAL);
	}

	p = properties_read(fd);

-
	for (i = 0; i < N(pkg_plugin_kv); i++) {
-
		new->fields[i].key = strdup(pkg_plugin_kv[i].key);
+
	for (i = 0; i < N(pkg_plugins_kv); i++) {
+
		new->fields[i].key = strdup(pkg_plugins_kv[i].key);
		if ((temp = property_find(p, new->fields[i].key)) == NULL) {
			pkg_emit_error("required option '%s' is not specified in '%s'",
				       new->fields[i].key, file);
@@ -137,7 +137,7 @@ pkg_plugin_parse_conf(const char *file)

	if (wrong_conf == true) {
		pkg_emit_error("required options were missing in '%s', plugin will not be loaded", file);
-
		for (i = 0; i < N(pkg_plugin_kv); i++) {
+
		for (i = 0; i < N(pkg_plugins_kv); i++) {
			if (new->fields[i].key != NULL)
				free(new->fields[i].key);
			if (new->fields[i].val != NULL)
@@ -153,16 +153,16 @@ pkg_plugin_parse_conf(const char *file)
}

static int
-
pkg_plugin_free(void)
+
pkg_plugins_free(void)
{
-
	struct pkg_plugin *p = NULL;
+
	struct pkg_plugins *p = NULL;
	unsigned int i;

        while (!STAILQ_EMPTY(&ph)) {
                p = STAILQ_FIRST(&ph);
                STAILQ_REMOVE_HEAD(&ph, next);

-
		for (i = 0; i < N(pkg_plugin_kv); i++) {
+
		for (i = 0; i < N(pkg_plugins_kv); i++) {
			free(p->fields[i].key);
			free(p->fields[i].val);
		}
@@ -174,7 +174,7 @@ pkg_plugin_free(void)
}

int
-
pkg_plugin_list(struct pkg_plugin **plugin)
+
pkg_plugins_list(struct pkg_plugins **plugin)
{
	if ((*plugin) == NULL)
		(*plugin) = STAILQ_FIRST(&ph);
@@ -188,17 +188,17 @@ pkg_plugin_list(struct pkg_plugin **plugin)
}

int
-
pkg_plugin_init(void)
+
pkg_plugins_init(void)
{
-
	pkg_plugin_discover();
+
	pkg_plugins_discover();

	return (EPKG_OK);
}

int
-
pkg_plugin_shutdown(void)
+
pkg_plugins_shutdown(void)
{
-
	pkg_plugin_free();
+
	pkg_plugins_free();

	return (EPKG_OK);
}
modified pkg/main.c
@@ -242,7 +242,7 @@ main(int argc, char **argv)
	if (pkg_init(NULL) != EPKG_OK)
		errx(EX_SOFTWARE, "Cannot parse configuration file!");

-
	if (pkg_plugin_init() != EPKG_OK)
+
	if (pkg_plugins_init() != EPKG_OK)
		errx(EX_SOFTWARE, "Plugins cannot be loaded");

	if (version > 1) {
@@ -283,7 +283,7 @@ main(int argc, char **argv)
			printf("Repository: %s\n", buf ? buf : "none");
		}
		pkg_shutdown();
-
		pkg_plugin_shutdown();
+
		pkg_plugins_shutdown();
		exit(EX_OK);
	}

@@ -309,7 +309,7 @@ main(int argc, char **argv)

	if (command == NULL) {
		pkg_shutdown();
-
		pkg_plugin_shutdown();
+
		pkg_plugins_shutdown();
		usage();
		return (ret); /* Not reached but makes scanbuild happy */
	}
@@ -329,7 +329,7 @@ main(int argc, char **argv)
	}

	pkg_shutdown();
-
	pkg_plugin_shutdown();
+
	pkg_plugins_shutdown();
	
	return (ret);
}