From 319f2d55bc7bef5b9efa99b2ff52ee67b9b7bcda Mon Sep 17 00:00:00 2001 From: "Perrin \"kAworu\" Alexandre" Date: Wed, 17 Jun 2009 15:57:10 +0200 Subject: [PATCH] removed WidgetList, name_func_link_t and related function use tokenize.gperf instead. Signed-off-by: Perrin "kAworu" Alexandre Signed-off-by: Julien Danjou --- CMakeLists.txt | 13 +------------ build-utils/widgetgen.sh | 18 ------------------ common/tokenize.gperf | 5 +++++ common/util.c | 39 --------------------------------------- common/util.h | 10 ---------- widget.c | 28 ++++++++++++++++++++++++---- 6 files changed, 30 insertions(+), 83 deletions(-) delete mode 100755 build-utils/widgetgen.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index b4af79cce..4075c1706 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -99,16 +99,6 @@ target_link_libraries(${PROJECT_AWE_NAME} ${AWESOME_REQUIRED_LIBRARIES} ${AWESOME_OPTIONAL_LIBRARIES}) -# {{{ Generated sources -add_custom_command( - COMMAND ${SOURCE_DIR}/build-utils/widgetgen.sh - ARGS > ${BUILD_DIR}/widgetgen.h - OUTPUT ${BUILD_DIR}/widgetgen.h - WORKING_DIRECTORY ${SOURCE_DIR} - DEPENDS ${SOURCE_DIR}/widget.h - COMMENT "Generating widgetgen.h" - VERBATIM) - # atoms file(MAKE_DIRECTORY ${BUILD_DIR}/common) add_custom_command( @@ -149,8 +139,7 @@ add_custom_command( COMMENT "Generating common/tokenize.c") add_custom_target(generated_sources - DEPENDS ${BUILD_DIR}/widgetgen.h - ${BUILD_DIR}/common/atoms-intern.h + DEPENDS ${BUILD_DIR}/common/atoms-intern.h ${BUILD_DIR}/common/atoms-extern.h ${BUILD_DIR}/common/tokenize.c ${BUILD_DIR}/common/tokenize.h) diff --git a/build-utils/widgetgen.sh b/build-utils/widgetgen.sh deleted file mode 100755 index ae71b0bd3..000000000 --- a/build-utils/widgetgen.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/sh -top_srcdir="${1-.}" -echo "/* This file is autogenerated by" `basename $0` "*/" -echo -echo "const name_func_link_t WidgetList[] =" -echo "{" -for file in ${top_srcdir}/widget.h -do - echo " /* $file */" - grep '^widget_constructor_t ' "$file" | cut -d' ' -f2 | cut -d\; -f1 | while read widget - do - shortname=`echo $widget | cut -d_ -f2` - echo " {\"$shortname\", sizeof(\"$shortname\") - 1, $widget}," - done -done - -echo " {NULL, 0, NULL}" -echo "};" diff --git a/common/tokenize.gperf b/common/tokenize.gperf index c1313df4f..8713fdd26 100644 --- a/common/tokenize.gperf +++ b/common/tokenize.gperf @@ -37,6 +37,7 @@ font_height fullscreen gap geometry +graph group_id grow height @@ -45,6 +46,7 @@ icon icon_name id image +imagebox instance key key_press @@ -79,6 +81,7 @@ plot_data_add plot_properties_set position press +progressbar release resize right @@ -94,7 +97,9 @@ south start sticky system +systray text +textbox ticks_count ticks_gap titlebar diff --git a/common/util.c b/common/util.c index 3c89e519c..ed339d482 100644 --- a/common/util.c +++ b/common/util.c @@ -57,45 +57,6 @@ _warn(int line, const char *fct, const char *fmt, ...) fprintf(stderr, "\n"); } -/** Lookup for a function pointer from its name - * in the given name_func_link_t list. - * \param funcname Function name. - * \param len The function name length. - * \param list Function and name link list. - * \return Function pointer. - */ -void * -name_func_lookup(const char *funcname, size_t len, const name_func_link_t *list) -{ - int i; - - if(funcname && list) - for(i = 0; list[i].name; i++) - if(len == list[i].len && !a_strcmp(funcname, list[i].name)) - return list[i].func; - - 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; -} - /** Get a position type from a string. * \param pos The position. * \param len The string length, -1 if unknown. diff --git a/common/util.h b/common/util.h index 5353d1608..019cc953f 100644 --- a/common/util.h +++ b/common/util.h @@ -52,14 +52,6 @@ typedef enum Left } position_t; -/** Link a name to a function */ -typedef struct -{ - const char *name; - size_t len; - void *func; -} name_func_link_t; - /** \brief replace \c NULL strings with emtpy strings */ #define NONULL(x) (x ? x : "") @@ -350,8 +342,6 @@ position_t position_fromstr(const char *, ssize_t); const char * position_tostr(position_t); orientation_t orientation_fromstr(const char *, ssize_t); const char * orientation_tostr(orientation_t); -void *name_func_lookup(const char *, size_t, const name_func_link_t *); -const char * name_func_rlookup(void *, const name_func_link_t *); void a_exec(const char *); #endif diff --git a/widget.c b/widget.c index 831103345..b43775a15 100644 --- a/widget.c +++ b/widget.c @@ -32,8 +32,6 @@ #include "common/atoms.h" #include "common/xutil.h" -#include "widgetgen.h" - DO_LUA_TOSTRING(widget_t, widget, "widget") /** Collect a widget structure. @@ -353,14 +351,36 @@ luaA_widget_new(lua_State *L) { const char *align, *type; widget_t *w; - widget_constructor_t *wc; + widget_constructor_t *wc = NULL; + awesome_token_t token; size_t len; luaA_checktable(L, 2); type = luaA_getopt_lstring(L, 2, "type", NULL, &len); - if((wc = name_func_lookup(type, len, WidgetList))) + switch((token = a_tokenize(type, len))) + { + case A_TK_TEXTBOX: + wc = widget_textbox; + break; + case A_TK_PROGRESSBAR: + wc = widget_progressbar; + break; + case A_TK_GRAPH: + wc = widget_graph; + break; + case A_TK_SYSTRAY: + wc = widget_systray; + break; + case A_TK_IMAGEBOX: + wc = widget_imagebox; + break; + default: + break; + } + + if(wc) { w = widget_new(L); wc(w);