]> Dogcows Code - chaz/openbox/commitdiff
node processing code/macros, and other fixes
authorMarius Nita <marius@cs.pdx.edu>
Tue, 15 Apr 2003 00:13:03 +0000 (00:13 +0000)
committerMarius Nita <marius@cs.pdx.edu>
Tue, 15 Apr 2003 00:13:03 +0000 (00:13 +0000)
obcl/Makefile
obcl/foo.conf
obcl/main.c
obcl/obcl.c
obcl/obcl.h

index 03c3a5dc761caa8028b523115ab6773de9544ce1..1284a735c7bbde42f370f2c73616075f217af51e 100644 (file)
@@ -3,7 +3,7 @@ LIBS=`pkg-config --libs glib-2.0` -ll
 
 targets = cltest
 
-sources = obcl.c main.c parse.c lex.c
+sources = obcl.c main.c parse.c lex.c process.c
 headers = obcl.h
 
 .PHONY: all clean
index 648bb01c547490bbc2d7b8f64f6bc306628e254c..b1fc57f47d21cea1643662f1449917351d9f2c14 100644 (file)
@@ -1,21 +1,4 @@
-include "meh.conf";
-include "bummy.conf";
-
-section mouse {
-    mbind titlebar, frame {
-        event click;
-        button middle;
-        action lower;
-    }
-
-    mbind frame {
-        event click;
-        button right;
-        action launch_nukes;
-    }
-}
-
-section theme {
-    theme "merry";
-    font "tahoma-12 bold";
-}
+foo "marius", 23;
+foo "kyle", 15;
+foo "soren", 7;
+bah "blef","bummy";
index 9ae109a900337361fd9bdcfe8162275f29cb3e6b..a38b4cf67bff0f53fbf09c6633bb31efabb9fbb1 100644 (file)
@@ -1,9 +1,32 @@
 #include "obcl.h"
 
+void process_foo(CLNode *node)
+{
+    if (CL_IS_NODE(node)) {
+        printf("foo name: %s\n"
+               "foo age: %.2f\n",
+               CL_STRVAL(CL_LIST_NTH(node,0)),
+               CL_NUMVAL(CL_LIST_NTH(node,1)));
+    }
+}
+
+void process_bah(CLNode *node)
+{
+    printf("handling bah\n");
+}
+
 int main()
 {
     GList *lst = cl_parse("foo.conf");
-    cl_tree_print(lst,0);
-    cl_tree_free(lst);
+/*     cl_tree_print(lst,0); */
+/*     cl_tree_free(lst); */
+
+    
+    CLProc *p = cl_proc_new();
+    cl_proc_add_handler_func(p, "foo", process_foo);
+    cl_proc_add_handler_func(p, "bah", process_bah);
+
+    cl_process(lst, p);
+
     return 0;
 }
index a4b58eec2e9cc0f87bc5fdb889b42a9e6e8a0b06..408a67ce19162db2df5bc5d911ad576d4b8eef34 100644 (file)
@@ -57,24 +57,24 @@ void cl_tree_print(GList *tree, int depth)
 
         switch(tmp->type) {
         case CL_ID:
-            printf("--ID-- %s\n", tmp->u.str);
+            printf("[ID] '%s'\n", tmp->u.str);
             break;
         case CL_STR:
-            printf("--STR-- %s\n", tmp->u.str);
+            printf("[STR] '%s'\n", tmp->u.str);
             break;
         case CL_NUM:
-            printf("--NUM-- %.2f\n", tmp->u.num);
+            printf("[NUM] %.2f\n", tmp->u.num);
             break;
         case CL_LIST:
-            printf("--LIST-- %s\n", tmp->u.lb.id);
+            printf("[LIST] '%s'\n", tmp->u.lb.id);
             cl_tree_print(tmp->u.lb.list, depth+2);
             break;
         case CL_BLOCK:
-            printf("--BLOCK-- %s\n", tmp->u.lb.id);
+            printf("[BLOCK] '%s'\n", tmp->u.lb.id);
             cl_tree_print(tmp->u.lb.block, depth+2);
             break;
         case CL_LISTBLOCK:
-            printf("--LISTBLOCK-- %s\n", tmp->u.lb.id);
+            printf("[LISTBLOCK] %s\n", tmp->u.lb.id);
             cl_tree_print(tmp->u.lb.list, depth+2);
             printf("\n");
             cl_tree_print(tmp->u.lb.block, depth+2);
index 1002964d76a75e5235ea17e58971b97ed415817f..37a04161a3c718bae21d6a8df742a935721c9f21 100644 (file)
@@ -4,6 +4,31 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <glib.h>
+#include <stdarg.h>
+
+/* TEH MACROS FROM MOUNT DOOM */
+
+#define CL_IS_NODE(X) \
+    (((CLNode*)(X))->type == CL_LIST || \
+     ((CLNode*)(X))->type == CL_BLOCK || \
+     ((CLNode*)(X))->type == CL_LISTBLOCK)
+#define CL_NODE(X)    ((CLNode*)(X))
+#define CL_ID(X)      (((CLNode*)(X))->u.lb.id)
+#define CL_LIST(X)    (((CLNode*)(X))->u.lb.list)
+#define CL_BLOCK(X)   (((CLNode*)(X))->u.lb.block)
+#define CL_NUMVAL(X)  (((CLNode*)(X))->u.num)
+#define CL_STRVAL(X)  (((CLNode*)(X))->u.str)
+#define CL_LINE(X)    (((CLNode*)(X))->lineno)
+
+#define CL_ASSERT_NODE(X) \
+    g_assert(CL_IS_NODE(X))
+#define CL_ASSERT_NUM(X) \
+    g_assert(((CLNode*)(X))->type == CL_NUM)
+#define CL_ASSERT_STR(X) \
+    g_assert(((CLNode*)(X))->type == CL_STR)
+
+#define CL_LIST_NTH(X,Y)\
+    CL_NODE(g_list_nth(CL_LIST(X),(Y))->data)
 
 typedef enum CLNodeType {
     CL_ID,
@@ -16,6 +41,7 @@ typedef enum CLNodeType {
 
 typedef struct CLNode {
     CLNodeType type;
+    int lineno;
     union {
         struct {
             gchar *id;
@@ -28,12 +54,44 @@ typedef struct CLNode {
 
 } CLNode;
 
+typedef void (*CLProcFunc)(CLNode *);
+
+struct CLProcHandler;
+
+typedef struct CLProc {
+    GHashTable *table;
+    struct CLProcHandler *default_h;
+} CLProc;
+
+typedef enum CLProcHandlerType {
+    CLPROC_FUNC,
+    CLPROC_PROC
+} CLProcHandlerType;
+
+typedef struct CLProcHandler {
+    CLProcHandlerType type;
+    union {
+        CLProcFunc func;
+        CLProc *proc;
+    } u;
+} CLProcHandler;
+
 GList *cl_parse(gchar *file);
 GList *cl_parse_fh(FILE *file);
 
 void cl_tree_free(GList *tree);
 void cl_tree_print(GList *tree, int depth);
 
-void cl_tree_process(GList *tree);
+CLProcHandler *cl_proc_handler_new_func(CLProcFunc f);
+CLProcHandler *cl_proc_handler_new_proc(CLProc *cp);
+CLProc *cl_proc_new(void);
+void cl_proc_free(CLProc *proc);
+void cl_proc_add_handler(CLProc *proc, gchar *str,
+                         CLProcHandler *handler);
+void cl_proc_add_handler_func(CLProc *proc, gchar *str,
+                              CLProcFunc func);
+void cl_proc_set_default(CLProc *proc, CLProcHandler *pf);
+void cl_proc_register_keywords(CLProc *proc, ...);
+void cl_process(GList *tree, CLProc *proc);
 
 #endif /* __obcl_h */
This page took 0.027538 seconds and 4 git commands to generate.