diff --git a/common/util.c b/common/util.c index 983f7141b..e2603d96a 100644 --- a/common/util.c +++ b/common/util.c @@ -78,10 +78,10 @@ compute_new_value_from_arg(const char *arg, double current_value) } /** Lookup for a function pointer from its name - * in the given name_func_link_t list - * \param funcname Function name - * \param list Function and name link list - * \return function pointer + * in the given name_func_link_t list. + * \param funcname Function name. + * \param list Function and name link list. + * \return Function pointer. */ void * name_func_lookup(const char *funcname, const name_func_link_t *list) @@ -96,6 +96,25 @@ name_func_lookup(const char *funcname, const name_func_link_t *list) return NULL; } +/** Lookup for a function name from its pointer + * in the given name_func_link_t list. + * \param funcp Function pointer. + * \param list Function and name link list. + * \return Name of the function. + */ +const char * +name_func_rlookup(void * funcp, const name_func_link_t *list) +{ + int i; + + if(funcp && list) + for(i = 0; list[i].name; i++) + if(funcp == list[i].func) + return list[i].name; + + return NULL; +} + position_t position_get_from_str(const char *pos) { diff --git a/common/util.h b/common/util.h index af0bc9a5b..e291b91a0 100644 --- a/common/util.h +++ b/common/util.h @@ -284,6 +284,7 @@ char * position_to_str(position_t); fuzzy_t fuzzy_get_from_str(const char *); double compute_new_value_from_arg(const char *, double); void *name_func_lookup(const char *, const name_func_link_t *); +const char * name_func_rlookup(void *, const name_func_link_t *); void a_exec(const char *); #endif