]> icculus.org git repositories - dana/openbox.git/blob - obcl/obcl.h
add shit that i made in the last week!
[dana/openbox.git] / obcl / obcl.h
1 #ifndef __obcl_h
2 #define __obcl_h
3
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <glib.h>
7 #include <stdarg.h>
8
9 /* TEH MACROS FROM MOUNT DOOM */
10
11 #define CL_IS_NODE(X) \
12     (((CLNode*)(X))->type == CL_LIST || \
13      ((CLNode*)(X))->type == CL_BLOCK || \
14      ((CLNode*)(X))->type == CL_LISTBLOCK)
15 #define CL_NODE(X)    ((CLNode*)(X))
16 #define CL_ID(X)      (((CLNode*)(X))->u.lb.id)
17 #define CL_LIST(X)    (((CLNode*)(X))->u.lb.list)
18 #define CL_BLOCK(X)   (((CLNode*)(X))->u.lb.block)
19 #define CL_NUMVAL(X)  (((CLNode*)(X))->u.num)
20 #define CL_STRVAL(X)  (((CLNode*)(X))->u.str)
21 #define CL_LINE(X)    (((CLNode*)(X))->lineno)
22
23 #define CL_ASSERT_NODE(X) \
24     g_assert(CL_IS_NODE(X))
25 #define CL_ASSERT_NUM(X) \
26     g_assert(((CLNode*)(X))->type == CL_NUM)
27 #define CL_ASSERT_STR(X) \
28     g_assert(((CLNode*)(X))->type == CL_STR)
29
30 #define CL_LIST_NTH(X,Y)\
31     CL_NODE(g_list_nth(CL_LIST(X),(Y))->data)
32
33 typedef enum CLNodeType {
34     CL_ID,
35     CL_NUM,
36     CL_STR,
37     CL_LIST,
38     CL_BLOCK,
39     CL_LISTBLOCK
40 } CLNodeType;
41
42 typedef struct CLNode {
43     CLNodeType type;
44     int lineno;
45     union {
46         struct {
47             gchar *id;
48             GList *list;
49             GList *block;
50         } lb;
51         double num;
52         gchar *str;
53     } u;
54
55 } CLNode;
56
57 typedef void (*CLProcFunc)(CLNode *);
58
59 struct CLProcHandler;
60
61 typedef struct CLProc {
62     GHashTable *table;
63     struct CLProcHandler *default_h;
64 } CLProc;
65
66 typedef enum CLProcHandlerType {
67     CLPROC_FUNC,
68     CLPROC_PROC
69 } CLProcHandlerType;
70
71 typedef struct CLProcHandler {
72     CLProcHandlerType type;
73     union {
74         CLProcFunc func;
75         CLProc *proc;
76     } u;
77 } CLProcHandler;
78
79 GList *cl_parse(gchar *file);
80 GList *cl_parse_fh(FILE *file);
81
82 void cl_tree_free(GList *tree);
83 void cl_tree_print(GList *tree, int depth);
84
85 CLProcHandler *cl_proc_handler_new_func(CLProcFunc f);
86 CLProcHandler *cl_proc_handler_new_proc(CLProc *cp);
87 CLProc *cl_proc_new(void);
88 void cl_proc_free(CLProc *proc);
89 void cl_proc_add_handler(CLProc *proc, gchar *str,
90                          CLProcHandler *handler);
91 void cl_proc_add_handler_func(CLProc *proc, gchar *str,
92                               CLProcFunc func);
93 void cl_proc_add_handler_proc(CLProc *proc, gchar *str,
94                               CLProc *hproc);
95 void cl_proc_set_default(CLProc *proc, CLProcHandler *pf);
96 void cl_proc_register_keywords(CLProc *proc, ...);
97 void cl_process(GList *tree, CLProc *proc);
98
99 #endif /* __obcl_h */