]> Dogcows Code - chaz/openbox/blob - openbox/parse.c
change how rc parsing will work. a=b will be parsed in any [section] and given to...
[chaz/openbox] / openbox / parse.c
1 #include "parse.h"
2
3 static GHashTable *reg = NULL;
4
5 struct Functions {
6 ParseFunc func;
7 AssignParseFunc afunc;
8 } *funcs;
9
10 void destshit(gpointer key) { g_free(key); }
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 if (g_hash_table_lookup(reg, section) != NULL)
26 g_warning("duplicate request for section '%s' in the rc file",
27 section);
28 else {
29 struct Functions *f = g_new(struct Functions, 1);
30 f->func = func;
31 f->afunc = afunc;
32 g_hash_table_insert(reg, g_ascii_strdown(section, -1), f);
33 }
34 }
35
36 void parse_free_token(ParseToken *token)
37 {
38 GList *it;
39
40 switch (token->type) {
41 case TOKEN_STRING:
42 g_free(token->data.string);
43 break;
44 case TOKEN_IDENTIFIER:
45 g_free(token->data.identifier);
46 break;
47 case TOKEN_LIST:
48 for (it = token->data.list; it; it = it->next) {
49 parse_free_token(it->data);
50 g_free(it->data);
51 }
52 g_list_free(token->data.list);
53 break;
54 case TOKEN_REAL:
55 case TOKEN_INTEGER:
56 case TOKEN_BOOL:
57 case TOKEN_LBRACE:
58 case TOKEN_RBRACE:
59 case TOKEN_COMMA:
60 case TOKEN_NEWLINE:
61 break;
62 }
63 }
64
65 void parse_set_section(char *section)
66 {
67 funcs = g_hash_table_lookup(reg, section);
68 }
69
70 void parse_token(ParseToken *token)
71 {
72 if (funcs) {
73 if (funcs->func != NULL)
74 funcs->func(token);
75 else if (token->type != TOKEN_NEWLINE)
76 yyerror("syntax error");
77 }
78 }
79
80 void parse_assign(char *name, ParseToken *value)
81 {
82 if (funcs) {
83 if (funcs->afunc != NULL)
84 funcs->afunc(name, value);
85 else
86 yyerror("syntax error");
87 }
88 }
This page took 0.038658 seconds and 4 git commands to generate.