]> Dogcows Code - chaz/openbox/blob - openbox/parse.c
rename "Slit" to "Dock".
[chaz/openbox] / openbox / parse.c
1 #include "parse.h"
2
3 static GHashTable *reg = NULL;
4
5 struct Functions {
6 ParseFunc f;
7 AssignParseFunc af;
8 } *funcs;
9
10 void destshit(gpointer shit) { g_free(shit); }
11
12 void parse_startup()
13 {
14 reg = g_hash_table_new_full(g_str_hash, g_str_equal, destshit, destshit);
15 funcs = NULL;
16 }
17
18 void parse_shutdown()
19 {
20 g_hash_table_destroy(reg);
21 }
22
23 void parse_reg_section(char *section, ParseFunc func, AssignParseFunc afunc)
24 {
25 struct Functions *f = g_new(struct Functions, 1);
26 f->f = func;
27 f->af = afunc;
28 g_hash_table_insert(reg, g_ascii_strdown(section, -1), f);
29 }
30
31 void parse_free_token(ParseToken *token)
32 {
33 GList *it;
34
35 switch (token->type) {
36 case TOKEN_STRING:
37 g_free(token->data.string);
38 break;
39 case TOKEN_IDENTIFIER:
40 g_free(token->data.identifier);
41 break;
42 case TOKEN_LIST:
43 for (it = token->data.list; it; it = it->next) {
44 parse_free_token(it->data);
45 g_free(it->data);
46 }
47 g_list_free(token->data.list);
48 break;
49 case TOKEN_REAL:
50 case TOKEN_INTEGER:
51 case TOKEN_BOOL:
52 case TOKEN_LBRACE:
53 case TOKEN_RBRACE:
54 case TOKEN_COMMA:
55 case TOKEN_NEWLINE:
56 break;
57 }
58 }
59
60 void parse_set_section(char *section)
61 {
62 char *sec;
63 sec = g_ascii_strdown(section, -1);
64 funcs = g_hash_table_lookup(reg, sec);
65 g_free(sec);
66 }
67
68 void parse_token(ParseToken *token)
69 {
70 if (funcs) {
71 if (funcs->f)
72 funcs->f(token);
73 else if (token->type != TOKEN_NEWLINE)
74 yyerror("syntax error");
75 }
76 }
77
78 void parse_assign(char *name, ParseToken *value)
79 {
80 if (funcs) {
81 if (funcs->af)
82 funcs->af(name, value);
83 else
84 yyerror("syntax error");
85 }
86 }
This page took 0.039879 seconds and 4 git commands to generate.