]>
Dogcows Code - chaz/openbox/blob - openbox/parse.c
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(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(ParseToken
*token
)
38 switch (token
->type
) {
40 g_free(token
->data
.string
);
42 case TOKEN_IDENTIFIER
:
43 g_free(token
->data
.identifier
);
46 for (it
= token
->data
.list
; it
; it
= it
->next
) {
47 parse_free_token(it
->data
);
50 g_slist_free(token
->data
.list
);
64 void parse_set_section(char *section
)
66 func
= (ParseFunc
)g_hash_table_lookup(reg
, section
);
69 void parse_token(ParseToken
*token
)
75 static void parse_rc_token(ParseToken
*token
)
77 static int got_eq
= FALSE
;
78 static ParseTokenType got_val
= 0;
79 static char *id
= NULL
, *s
= NULL
;
84 if (token
->type
== TOKEN_IDENTIFIER
) {
85 id
= token
->data
.identifier
;
88 yyerror("syntax error");
91 if (token
->type
== TOKEN_EQUALS
) {
95 yyerror("syntax error");
97 } else if (!got_val
) {
98 if (token
->type
== TOKEN_STRING
) {
99 s
= token
->data
.string
;
100 got_val
= token
->type
;
102 } else if (token
->type
== TOKEN_BOOL
) {
103 b
= token
->data
.bool;
104 got_val
= token
->type
;
106 } else if (token
->type
== TOKEN_INTEGER
) {
107 i
= token
->data
.integer
;
108 got_val
= token
->type
;
111 yyerror("syntax error");
112 } else if (token
->type
!= TOKEN_NEWLINE
) {
113 yyerror("syntax error");
120 if (!config_set(id
, Config_String
, v
))
121 yyerror("invalid value type");
125 if (!config_set(id
, Config_Bool
, v
))
126 yyerror("invalid value type");
130 if (!config_set(id
, Config_Integer
, v
))
131 yyerror("invalid value type");
134 g_assert_not_reached(); /* unhandled type got parsed */
143 parse_free_token(token
);
This page took 0.037728 seconds and 4 git commands to generate.