diff options
author | Roy Marples <roy@marples.name> | 2007-04-11 12:44:47 +0000 |
---|---|---|
committer | Roy Marples <roy@marples.name> | 2007-04-11 12:44:47 +0000 |
commit | e6674b2caee26d2421215d29977cb91d5731ec8a (patch) | |
tree | 330ef9a3fd817a50ed62438e346e560be08f19fe /src/rc-plugin.c | |
parent | 55884f7959e1c80e573eb7cc3c8749197c11c4c9 (diff) |
Cuddle up to LKML C style
Diffstat (limited to 'src/rc-plugin.c')
-rw-r--r-- | src/rc-plugin.c | 157 |
1 files changed, 74 insertions, 83 deletions
diff --git a/src/rc-plugin.c b/src/rc-plugin.c index f7cd3686..15ab149d 100644 --- a/src/rc-plugin.c +++ b/src/rc-plugin.c @@ -19,103 +19,94 @@ typedef struct plugin { - char *name; - void *handle; - int (*hook) (rc_hook_t hook, const char *name); - struct plugin *next; + char *name; + void *handle; + int (*hook) (rc_hook_t hook, const char *name); + struct plugin *next; } plugin_t; static plugin_t *plugins = NULL; void rc_plugin_load (void) { - char **files; - char *file; - int i; - plugin_t *plugin = plugins; - - /* Ensure some sanity here */ - rc_plugin_unload (); - - if (! rc_exists (RC_PLUGINDIR)) - return; - - files = rc_ls_dir (NULL, RC_PLUGINDIR, 0); - STRLIST_FOREACH (files, file, i) - { - char *p = rc_strcatpaths (RC_PLUGINDIR, file, NULL); - void *h = dlopen (p, RTLD_LAZY); - char *func; - void *f; - int len; - - if (! h) - { - eerror ("dlopen `%s': %s", p, dlerror ()); - free (p); - continue; - } - - func = file; - file = strsep (&func, "."); - len = strlen (file) + 7; - func = rc_xmalloc (sizeof (char *) * len); - snprintf (func, len, "_%s_hook", file); - - f = dlsym (h, func); - if (! f) - { - eerror ("`%s' does not expose the symbol `%s'", p, func); - dlclose (h); - } - else - { - if (plugin) - { - plugin->next = rc_xmalloc (sizeof (plugin_t)); - plugin = plugin->next; - } - else - plugin = plugins = rc_xmalloc (sizeof (plugin_t)); - - memset (plugin, 0, sizeof (plugin_t)); - plugin->name = strdup (file); - plugin->handle = h; - plugin->hook = f; - } - - free (func); - free (p); - } - - rc_strlist_free (files); + char **files; + char *file; + int i; + plugin_t *plugin = plugins; + + /* Ensure some sanity here */ + rc_plugin_unload (); + + if (! rc_exists (RC_PLUGINDIR)) + return; + + files = rc_ls_dir (NULL, RC_PLUGINDIR, 0); + STRLIST_FOREACH (files, file, i) { + char *p = rc_strcatpaths (RC_PLUGINDIR, file, NULL); + void *h = dlopen (p, RTLD_LAZY); + char *func; + void *f; + int len; + + if (! h) { + eerror ("dlopen `%s': %s", p, dlerror ()); + free (p); + continue; + } + + func = file; + file = strsep (&func, "."); + len = strlen (file) + 7; + func = rc_xmalloc (sizeof (char *) * len); + snprintf (func, len, "_%s_hook", file); + + f = dlsym (h, func); + if (! f) { + eerror ("`%s' does not expose the symbol `%s'", p, func); + dlclose (h); + } else { + if (plugin) { + plugin->next = rc_xmalloc (sizeof (plugin_t)); + plugin = plugin->next; + } else + plugin = plugins = rc_xmalloc (sizeof (plugin_t)); + + memset (plugin, 0, sizeof (plugin_t)); + plugin->name = strdup (file); + plugin->handle = h; + plugin->hook = f; + } + + free (func); + free (p); + } + + rc_strlist_free (files); } void rc_plugin_run (rc_hook_t hook, const char *value) { - plugin_t *plugin = plugins; + plugin_t *plugin = plugins; - while (plugin) - { - if (plugin->hook) - plugin->hook (hook, value); + while (plugin) { + if (plugin->hook) + plugin->hook (hook, value); - plugin = plugin->next; - } + plugin = plugin->next; + } } void rc_plugin_unload (void) { - plugin_t *plugin = plugins; - plugin_t *next; - - while (plugin) - { - next = plugin->next; - dlclose (plugin->handle); - free (plugin->name); - free (plugin); - plugin = next; - } - plugins = NULL; + plugin_t *plugin = plugins; + plugin_t *next; + + while (plugin) { + next = plugin->next; + dlclose (plugin->handle); + free (plugin->name); + free (plugin); + plugin = next; + } + plugins = NULL; } |