Hi!

jd could you check this patch? I compiled/run awesome with it without
any problems but I'm not confident with this patch since I don't know
the awesome codebase well.

It remove the WidgetList, name_func_link_t and related function and use
tokenize.gperf instead.

Cheers,
Alexandre Perrin.
From bd1923b5981023f748e1741b5bd69ada887e753b Mon Sep 17 00:00:00 2001
From: Perrin "kAworu" Alexandre <kaworu(a)kaworu,ch>
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 <kaworu(a)kaworu,ch>
---
 CMakeLists.txt           |   13 +------------
 build-utils/widgetgen.sh |   18 ------------------
 common/tokenize.gperf    |    5 +++++
 common/util.c            |   39 ---------------------------------------
 common/util.h            |   10 ----------
 widget.c                 |   26 +++++++++++++++++++++++---
 6 files changed, 29 insertions(+), 82 deletions(-)
 delete mode 100755 build-utils/widgetgen.sh

diff --git a/CMakeLists.txt b/CMakeLists.txt
index b4af79c..4075c17 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 ae71b0b..0000000
--- 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 c1313df..8713fdd 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 3c89e51..ed339d4 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 6d2c23c..794b929 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 : "")
 
@@ -348,8 +340,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 8311033..b76f966 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.
@@ -354,13 +352,35 @@ luaA_widget_new(lua_State *L)
     const char *align, *type;
     widget_t *w;
     widget_constructor_t *wc;
+    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:
+        wc = NULL;
+    }
+
+    if(wc)
     {
         w = widget_new(L);
         wc(w);
-- 
1.6.3.2

Attachment: pgpIocDcdqOGd.pgp
Description: PGP signature

Reply via email to