Mercurial > irccd
changeset 1111:ae8b91ec4e4a
lib: const all the things
author | David Demelier <markand@malikania.fr> |
---|---|
date | Thu, 21 Oct 2021 13:56:05 +0200 |
parents | 8c53096eef1e |
children | 2cde6684b536 |
files | irccd/dl-plugin.c irccd/js-plugin.c irccd/peer.c lib/irccd/plugin.c lib/irccd/plugin.h man/libirccd.3 plugins/links/links.c tests/test-dl-plugin.c |
diffstat | 8 files changed, 43 insertions(+), 42 deletions(-) [+] |
line wrap: on
line diff
--- a/irccd/dl-plugin.c Wed Oct 20 16:02:13 2021 +0200 +++ b/irccd/dl-plugin.c Thu Oct 21 13:56:05 2021 +0200 @@ -84,19 +84,19 @@ void *handle; }; -typedef const char * (*get_option_fn)(const char *); -typedef const char * (*get_path_fn)(const char *); -typedef const char * (*get_template_fn)(const char *); -typedef const char ** (*get_options_fn)(void); -typedef const char ** (*get_paths_fn)(void); -typedef const char ** (*get_templates_fn)(void); -typedef void (*event_fn)(const struct irc_event *); -typedef int (*load_fn)(void); -typedef void (*reload_fn)(void); -typedef void (*unload_fn)(void); -typedef void (*set_option_fn)(const char *, const char *); -typedef void (*set_path_fn)(const char *, const char *); -typedef void (*set_template_fn)(const char *, const char *); +typedef const char * (*get_option_fn)(const char *); +typedef const char * (*get_path_fn)(const char *); +typedef const char * (*get_template_fn)(const char *); +typedef const char * const * (*get_options_fn)(void); +typedef const char * const * (*get_paths_fn)(void); +typedef const char * const * (*get_templates_fn)(void); +typedef void (*event_fn)(const struct irc_event *); +typedef int (*load_fn)(void); +typedef void (*reload_fn)(void); +typedef void (*unload_fn)(void); +typedef void (*set_option_fn)(const char *, const char *); +typedef void (*set_path_fn)(const char *, const char *); +typedef void (*set_template_fn)(const char *, const char *); static inline const char * symbol(const struct self *self, const char *func) @@ -133,7 +133,7 @@ return NULL; } -static const char ** +static const char * const * get_templates(struct irc_plugin *plg) { INVOKE_NA(plg, "get_templates", get_templates_fn); @@ -155,7 +155,7 @@ return NULL; } -static const char ** +static const char * const * get_paths(struct irc_plugin *plg) { INVOKE_NA(plg, "get_paths", get_paths_fn); @@ -177,7 +177,7 @@ return NULL; } -static const char ** +static const char * const * get_options(struct irc_plugin *plg) { INVOKE_NA(plg, "get_options", get_options_fn);
--- a/irccd/js-plugin.c Wed Oct 20 16:02:13 2021 +0200 +++ b/irccd/js-plugin.c Thu Oct 21 13:56:05 2021 +0200 @@ -170,7 +170,7 @@ free(stack); } -static const char ** +static const char * const * get_table(duk_context *ctx, const char *name, char ***ptable) { char **list = NULL; @@ -194,7 +194,7 @@ freelist(*ptable); *ptable = list; - return (const char **)list; + return (const char * const *)list; } static void @@ -235,7 +235,7 @@ return get_value(js->ctx, JSAPI_PLUGIN_PROP_TEMPLATES, key); } -static const char ** +static const char * const * get_templates(struct irc_plugin *plg) { struct self *js = plg->data; @@ -259,7 +259,7 @@ return get_value(js->ctx, JSAPI_PLUGIN_PROP_PATHS, key); } -static const char ** +static const char * const * get_paths(struct irc_plugin *plg) { struct self *js = plg->data; @@ -283,7 +283,7 @@ return get_value(js->ctx, JSAPI_PLUGIN_PROP_OPTIONS, key); } -static const char ** +static const char * const * get_options(struct irc_plugin *plg) { struct self *js = plg->data;
--- a/irccd/peer.c Wed Oct 20 16:02:13 2021 +0200 +++ b/irccd/peer.c Thu Oct 21 13:56:05 2021 +0200 @@ -39,7 +39,7 @@ typedef void (*plugin_set_fn)(struct irc_plugin *, const char *, const char *); typedef const char * (*plugin_get_fn)(struct irc_plugin *, const char *); -typedef const char ** (*plugin_list_fn)(struct irc_plugin *); +typedef const char * const * (*plugin_list_fn)(struct irc_plugin *); static size_t parse(char *line, const char **args, size_t max) @@ -126,7 +126,8 @@ plugin_get_fn get, plugin_list_fn list) { - const char *args[3] = {0}, *value, **keys; + const char *args[3] = {0}, *value; + const char * const *keys; char out[IRC_BUF_LEN]; FILE *fp; struct irc_plugin *plg; @@ -151,12 +152,12 @@ keys = list(plg); /* Compute the number of keys found. */ - for (const char **key = keys; key && *key; ++key) + for (const char * const *key = keys; key && *key; ++key) keysz++; fprintf(fp, "OK %zu\n", keysz); - for (const char **key = keys; key && *key; ++key) { + for (const char * const *key = keys; key && *key; ++key) { value = get(plg, *key); fprintf(fp, "%s=%s\n", *key, value ? value : ""); }
--- a/lib/irccd/plugin.c Wed Oct 20 16:02:13 2021 +0200 +++ b/lib/irccd/plugin.c Thu Oct 21 13:56:05 2021 +0200 @@ -44,7 +44,7 @@ return NULL; } -const char ** +const char * const * irc_plugin_get_templates(struct irc_plugin *plg) { assert(plg); @@ -78,7 +78,7 @@ return NULL; } -const char ** +const char * const * irc_plugin_get_paths(struct irc_plugin *plg) { assert(plg); @@ -112,7 +112,7 @@ return NULL; } -const char ** +const char * const * irc_plugin_get_options(struct irc_plugin *plg) { assert(plg);
--- a/lib/irccd/plugin.h Wed Oct 20 16:02:13 2021 +0200 +++ b/lib/irccd/plugin.h Thu Oct 21 13:56:05 2021 +0200 @@ -38,15 +38,15 @@ void (*set_template)(struct irc_plugin *, const char *, const char *); const char *(*get_template)(struct irc_plugin *, const char *); - const char **(*get_templates)(struct irc_plugin *); + const char * const *(*get_templates)(struct irc_plugin *); void (*set_path)(struct irc_plugin *, const char *, const char *); const char *(*get_path)(struct irc_plugin *, const char *); - const char **(*get_paths)(struct irc_plugin *); + const char * const *(*get_paths)(struct irc_plugin *); void (*set_option)(struct irc_plugin *, const char *, const char *); const char *(*get_option)(struct irc_plugin *, const char *); - const char **(*get_options)(struct irc_plugin *); + const char * const *(*get_options)(struct irc_plugin *); int (*load)(struct irc_plugin *); void (*reload)(struct irc_plugin *); @@ -71,7 +71,7 @@ const char * irc_plugin_get_template(struct irc_plugin *, const char *); -const char ** +const char * const * irc_plugin_get_templates(struct irc_plugin *); void @@ -80,7 +80,7 @@ const char * irc_plugin_get_path(struct irc_plugin *, const char *); -const char ** +const char * const * irc_plugin_get_paths(struct irc_plugin *); void @@ -89,7 +89,7 @@ const char * irc_plugin_get_option(struct irc_plugin *, const char *); -const char ** +const char * const * irc_plugin_get_options(struct irc_plugin *); int
--- a/man/libirccd.3 Wed Oct 20 16:02:13 2021 +0200 +++ b/man/libirccd.3 Thu Oct 21 13:56:05 2021 +0200 @@ -38,11 +38,11 @@ .Fn <prefix>_get_template "const char *key" .Ft const char * .Fn <prefix>_get_path "const char *key" -.Ft const char ** +.Ft const char * const * .Fn <prefix>_get_options "void" -.Ft const char ** +.Ft const char * const * .Fn <prefix>_get_templates "void" -.Ft const char ** +.Ft const char * const * .Fn <prefix>_get_paths "void" .Ft int .Fn <prefix>_load "void"
--- a/plugins/links/links.c Wed Oct 20 16:02:13 2021 +0200 +++ b/plugins/links/links.c Thu Oct 21 13:56:05 2021 +0200 @@ -327,7 +327,7 @@ return NULL; } -const char ** +const char * const * links_get_templates(void) { static const char *keys[] = { "info", NULL }; @@ -355,7 +355,7 @@ return NULL; } -const char ** +const char * const * links_get_options(void) { static const char *keys[] = { "timeout", NULL };
--- a/tests/test-dl-plugin.c Wed Oct 20 16:02:13 2021 +0200 +++ b/tests/test-dl-plugin.c Thu Oct 21 13:56:05 2021 +0200 @@ -61,7 +61,7 @@ GREATEST_TEST options_list(void) { - const char **options = irc_plugin_get_options(plugin); + const char * const *options = irc_plugin_get_options(plugin); GREATEST_ASSERT_STR_EQ("option-1", options[0]); GREATEST_ASSERT(!options[1]); @@ -88,7 +88,7 @@ GREATEST_TEST paths_list(void) { - const char **paths = irc_plugin_get_paths(plugin); + const char * const *paths = irc_plugin_get_paths(plugin); GREATEST_ASSERT_STR_EQ("path-1", paths[0]); GREATEST_ASSERT(!paths[1]); @@ -115,7 +115,7 @@ GREATEST_TEST templates_list(void) { - const char **templates = irc_plugin_get_templates(plugin); + const char * const *templates = irc_plugin_get_templates(plugin); GREATEST_ASSERT_STR_EQ("template-1", templates[0]); GREATEST_ASSERT(!templates[1]);