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