4 static GHashTable *reg = NULL;
5 static ParseFunc func = NULL;
7 /* parse tokens from the [openbox] section of the rc file */
8 static void parse_rc_token(ParseTokenType type, union ParseToken token);
10 void destkey(gpointer key) { g_free(key); }
14 reg = g_hash_table_new_full(g_str_hash, g_str_equal, destkey, NULL);
17 parse_reg_section("openbox", parse_rc_token);
22 g_hash_table_destroy(reg);
25 void parse_reg_section(char *section, ParseFunc func)
27 if (g_hash_table_lookup(reg, section) != NULL)
28 g_warning("duplicate request for section '%s' in the rc file",
31 g_hash_table_insert(reg, g_ascii_strdown(section, -1), (void*)func);
34 void parse_free_token(ParseTokenType type, union ParseToken token)
40 case TOKEN_IDENTIFIER:
41 g_free(token.identifier);
57 void parse_set_section(char *section)
59 func = (ParseFunc)g_hash_table_lookup(reg, section);
62 void parse_token(ParseTokenType type, union ParseToken token)
68 static void parse_rc_token(ParseTokenType type, union ParseToken token)
70 static int got_eq = FALSE;
71 static ParseTokenType got_val = 0;
72 static char *id = NULL, *s = NULL;
77 if (type == TOKEN_IDENTIFIER) {
78 id = token.identifier;
81 yyerror("syntax error");
84 if (type == TOKEN_EQUALS) {
88 yyerror("syntax error");
90 } else if (!got_val) {
91 if (type == TOKEN_STRING) {
95 } else if (type == TOKEN_BOOL) {
99 } else if (type == TOKEN_INTEGER) {
104 yyerror("syntax error");
105 } else if (type != TOKEN_NEWLINE) {
106 yyerror("syntax error");
113 if (!config_set(id, Config_String, v))
114 yyerror("invalid value type");
118 if (!config_set(id, Config_Bool, v))
119 yyerror("invalid value type");
123 if (!config_set(id, Config_Integer, v))
124 yyerror("invalid value type");
127 g_assert_not_reached(); /* unhandled type got parsed */
136 parse_free_token(type, token);