9 char *themerc_titlebar_layout;
13 static void parse(char *path, int fd)
17 scanner = g_scanner_new(NULL);
18 g_scanner_input_file(scanner, fd);
20 while (g_scanner_get_next_token(scanner) != G_TOKEN_EOF) {
23 if (scanner->token != G_TOKEN_IDENTIFIER) {
24 g_scanner_unexp_token(scanner, scanner->token, NULL, NULL, NULL,
28 name = g_strdup(scanner->value.v_identifier);
30 g_scanner_get_next_token(scanner);
31 if (scanner->token != G_TOKEN_EQUAL_SIGN) {
32 g_scanner_unexp_token(scanner, scanner->token, NULL, NULL, NULL,
38 g_scanner_get_next_token(scanner);
39 if (scanner->token == G_TOKEN_STRING) {
40 val = g_strdup(scanner->value.v_identifier);
42 if (!g_ascii_strcasecmp(name, "engine")) {
43 if (themerc_engine != NULL) {
44 g_warning("%s:%d: '%s' already defined", path,
50 } else if (!g_ascii_strcasecmp(name, "theme")) {
51 if (themerc_theme != NULL) {
52 g_warning("%s:%d: '%s' already defined", path,
58 } else if (!g_ascii_strcasecmp(name, "font")) {
59 if (themerc_font != NULL) {
60 g_warning("%s:%d: '%s' already defined", path,
66 } else if (!g_ascii_strcasecmp(name, "titlebarlayout")) {
67 if (themerc_titlebar_layout != NULL) {
68 g_warning("%s:%d: '%s' already defined", path,
73 char *lowval = g_ascii_strup(val, -1);
74 int i, len = strlen(lowval);
76 for (i = 0; i < len; ++i) {
77 gboolean valid = FALSE;
88 g_warning("%s:%d: invalid titlebarlayout element "
89 "'%c'", path, scanner->line, lowval[i]);
94 themerc_titlebar_layout = lowval;
101 g_warning("%s:%d: invalid option '%s'", path,
102 scanner->line, name);
107 g_scanner_unexp_token(scanner, scanner->token, NULL, NULL, NULL,
115 void themerc_startup()
117 GIOChannel *chan = NULL;
121 themerc_engine = NULL;
122 themerc_theme = NULL;
124 themerc_titlebar_layout = NULL;
126 path = g_build_filename(g_get_home_dir(), ".openbox", "themerc", NULL);
128 chan = g_io_channel_new_file(path, "r", &error);
132 path = g_build_filename(THEMERCDIR, "themerc", NULL);
134 chan = g_io_channel_new_file(path, "r", &error);
138 parse(path, g_io_channel_unix_get_fd(chan));
140 g_io_channel_close(chan);
143 /* non-NULL defaults */
144 if (themerc_titlebar_layout == NULL)
145 themerc_titlebar_layout = g_strdup("NDLIMC");
146 if (themerc_font == NULL)
147 themerc_font = g_strdup("sans-8");
150 void themerc_shutdown()
152 if (themerc_engine != NULL) g_free(themerc_engine);
153 if (themerc_theme != NULL) g_free(themerc_theme);
154 if (themerc_font != NULL) g_free(themerc_font);
155 if (themerc_titlebar_layout != NULL) g_free(themerc_titlebar_layout);