[PATCH] Add the PRELUDE_PLUGIN_OPTION_DECLARE_INT_CB macro
Justus Winter <[email protected]> Wed, 24 Nov 2010 17:11:08 +0100
| Newsgroups | gmane.comp.security.ids.prelude.devel |
|---|---|
| Message-ID | <[email protected]> |
I created a macro that does the same as the PRELUDE_PLUGIN_OPTION_DECLARE_STRING_CB macro plus string to int conversion in the setter function proper error checking and propagation and int to string conversion in the getter. Signed-off-by: Justus Winter <[email protected]> --- src/include/prelude-plugin.h | 27 +++++++++++++++++++++++++++ 1 files changed, 27 insertions(+), 0 deletions(-) diff --git a/src/include/prelude-plugin.h b/src/include/prelude-plugin.h index c4c4ce3..e810668 100644 --- a/src/include/prelude-plugin.h +++ b/src/include/prelude-plugin.h @@ -106,6 +106,33 @@ static int prefix ## _get_ ## name( return 0; \ } +#define PRELUDE_PLUGIN_OPTION_DECLARE_INT_CB(prefix, type, name) \ +static int prefix ## _set_ ## name( \ + prelude_option_t *opt __attribute__((unused)), \ + const char *optarg, \ + prelude_string_t *err __attribute__((unused)), \ + void *context) \ +{ \ + char *endptr; \ + type *ptr = prelude_plugin_instance_get_plugin_data(context); \ + errno = 0; \ + ptr->name = strtol(optarg, &endptr, 10); \ + if (*endptr != '\0') \ + return prelude_error_verbose(PRELUDE_ERROR_GENERIC, \ + "Conversion to integer failed"); \ + return prelude_error_code_from_errno(errno); \ +} \ + \ + \ +static int prefix ## _get_ ## name( \ + prelude_option_t *opt __attribute__((unused)), \ + prelude_string_t *out, \ + void *context) \ +{ \ + type *ptr = prelude_plugin_instance_get_plugin_data(context); \ + prelude_string_sprintf(out, "%d", ptr->name); \ + return PRELUDE_ERROR_NO_ERROR; \ +} /* * -- 1.7.2.3 _______________________________________________ Prelude-devel site list [email protected] http://lists.prelude-technologies.com/mailman/listinfo/prelude-devel