annotate src/prefsparser.cc @ 2048:5060d415a85a

clickable menu items (even those introducing submenus) MUST have callbacks I clicked on the "Panel size" item itself instead of any of the options in its submenu, and: Segfault!
author corvid <corvid@lavabit.com>
date Thu, 26 May 2011 02:51:18 +0000
parents a204cc949c1a
children e1192fad2291
rev   line source
1053
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
1 /*
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
2 * Preferences parser
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
3 *
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
4 * Copyright (C) 2006-2009 Jorge Arellano Cid <jcid@dillo.org>
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
5 *
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
8 * the Free Software Foundation; either version 3 of the License, or
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
9 * (at your option) any later version.
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
10 */
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
11
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
12 #include <sys/types.h>
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
13 #include <stdlib.h>
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
14 #include <locale.h> /* for setlocale */
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
15
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
16 #include "prefs.h"
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
17 #include "misc.h"
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
18 #include "msg.h"
1729
44b04d308585 bring back bg_color dillorc option
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1644
diff changeset
19 #include "colors.h"
1053
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
20
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
21 #include "prefsparser.hh"
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
22
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
23 typedef enum {
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
24 PREFS_BOOL,
1729
44b04d308585 bring back bg_color dillorc option
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1644
diff changeset
25 PREFS_COLOR,
1053
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
26 PREFS_STRING,
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
27 PREFS_URL,
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
28 PREFS_INT32,
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
29 PREFS_DOUBLE,
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
30 PREFS_GEOMETRY,
1644
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1560
diff changeset
31 PREFS_FILTER,
1053
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
32 PREFS_PANEL_SIZE
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
33 } PrefType_t;
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
34
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
35 typedef struct SymNode_ {
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
36 const char *name;
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
37 void *pref;
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
38 PrefType_t type;
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
39 } SymNode_t;
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
40
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
41 /*
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
42 * Parse a name/value pair and set preferences accordingly.
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
43 */
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
44 int PrefsParser::parseOption(char *name, char *value)
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
45 {
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
46 const SymNode_t *node;
1059
7bec6cfe6b6b Switched a few remaining "unsigned int" to "uint_t"
Jorge Arellano Cid <jcid@dillo.org>
parents: 1053
diff changeset
47 uint_t i;
1729
44b04d308585 bring back bg_color dillorc option
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1644
diff changeset
48 int st;
1053
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
49
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
50 /* Symbol array, sorted alphabetically */
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
51 const SymNode_t symbols[] = {
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
52 { "allow_white_bg", &prefs.allow_white_bg, PREFS_BOOL },
1729
44b04d308585 bring back bg_color dillorc option
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1644
diff changeset
53 { "bg_color", &prefs.bg_color, PREFS_COLOR },
1053
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
54 { "buffered_drawing", &prefs.buffered_drawing, PREFS_INT32 },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
55 { "contrast_visited_color", &prefs.contrast_visited_color, PREFS_BOOL },
1326
02ef25700865 trim some spaces
corvid <corvid@lavabit.com>
parents: 1186
diff changeset
56 { "enterpress_forces_submit", &prefs.enterpress_forces_submit,
1053
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
57 PREFS_BOOL },
1644
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1560
diff changeset
58 { "filter_auto_requests", &prefs.filter_auto_requests, PREFS_FILTER },
1053
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
59 { "focus_new_tab", &prefs.focus_new_tab, PREFS_BOOL },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
60 { "font_cursive", &prefs.font_cursive, PREFS_STRING },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
61 { "font_factor", &prefs.font_factor, PREFS_DOUBLE },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
62 { "font_fantasy", &prefs.font_fantasy, PREFS_STRING },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
63 { "font_max_size", &prefs.font_max_size, PREFS_INT32 },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
64 { "font_min_size", &prefs.font_min_size, PREFS_INT32 },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
65 { "font_monospace", &prefs.font_monospace, PREFS_STRING },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
66 { "font_sans_serif", &prefs.font_sans_serif, PREFS_STRING },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
67 { "font_serif", &prefs.font_serif, PREFS_STRING },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
68 { "fullwindow_start", &prefs.fullwindow_start, PREFS_BOOL },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
69 { "geometry", NULL, PREFS_GEOMETRY },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
70 { "home", &prefs.home, PREFS_URL },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
71 { "http_language", &prefs.http_language, PREFS_STRING },
1530
356c339d0761 limit the number of simultaneous connections
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1525
diff changeset
72 { "http_max_conns", &prefs.http_max_conns, PREFS_INT32 },
1514
239f9fc6c313 backout: That way would make no_proxy complicated.
corvid <corvid@lavabit.com>
parents: 1513
diff changeset
73 { "http_proxy", &prefs.http_proxy, PREFS_URL },
1053
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
74 { "http_proxyuser", &prefs.http_proxyuser, PREFS_STRING },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
75 { "http_referer", &prefs.http_referer, PREFS_STRING },
1560
c47ab3201464 add http_user_agent preference
Alexander Voigt, corvid
parents: 1530
diff changeset
76 { "http_user_agent", &prefs.http_user_agent, PREFS_STRING },
1053
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
77 { "limit_text_width", &prefs.limit_text_width, PREFS_BOOL },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
78 { "load_images", &prefs.load_images, PREFS_BOOL },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
79 { "load_stylesheets", &prefs.load_stylesheets, PREFS_BOOL },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
80 { "middle_click_drags_page", &prefs.middle_click_drags_page,
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
81 PREFS_BOOL },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
82 { "middle_click_opens_new_tab", &prefs.middle_click_opens_new_tab,
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
83 PREFS_BOOL },
1991
a204cc949c1a Set middle click as default for close tab (+ right_click_closes_tab in dillorc)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1729
diff changeset
84 { "right_click_closes_tab", &prefs.right_click_closes_tab, PREFS_BOOL },
1053
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
85 { "no_proxy", &prefs.no_proxy, PREFS_STRING },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
86 { "panel_size", &prefs.panel_size, PREFS_PANEL_SIZE },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
87 { "parse_embedded_css", &prefs.parse_embedded_css, PREFS_BOOL },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
88 { "save_dir", &prefs.save_dir, PREFS_STRING },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
89 { "search_url", &prefs.search_url, PREFS_STRING },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
90 { "show_back", &prefs.show_back, PREFS_BOOL },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
91 { "show_bookmarks", &prefs.show_bookmarks, PREFS_BOOL },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
92 { "show_clear_url", &prefs.show_clear_url, PREFS_BOOL },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
93 { "show_extra_warnings", &prefs.show_extra_warnings, PREFS_BOOL },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
94 { "show_filemenu", &prefs.show_filemenu, PREFS_BOOL },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
95 { "show_forw", &prefs.show_forw, PREFS_BOOL },
1525
3c683905dbe3 Added a help button. It tries a local help file then dillo.org's one.
corvid, jcid
parents: 1514
diff changeset
96 { "show_help", &prefs.show_help, PREFS_BOOL },
1053
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
97 { "show_home", &prefs.show_home, PREFS_BOOL },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
98 { "show_msg", &prefs.show_msg, PREFS_BOOL },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
99 { "show_progress_box", &prefs.show_progress_box, PREFS_BOOL },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
100 { "show_reload", &prefs.show_reload, PREFS_BOOL },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
101 { "show_save", &prefs.show_save, PREFS_BOOL },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
102 { "show_search", &prefs.show_search, PREFS_BOOL },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
103 { "show_stop", &prefs.show_stop, PREFS_BOOL },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
104 { "show_tools", &prefs.show_tools, PREFS_BOOL },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
105 { "show_tooltip", &prefs.show_tooltip, PREFS_BOOL },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
106 { "show_url", &prefs.show_url, PREFS_BOOL },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
107 { "small_icons", &prefs.small_icons, PREFS_BOOL },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
108 { "start_page", &prefs.start_page, PREFS_URL },
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
109 { "w3c_plus_heuristics", &prefs.w3c_plus_heuristics, PREFS_BOOL }
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
110 };
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
111
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
112 node = NULL;
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
113 for (i = 0; i < sizeof(symbols) / sizeof(SymNode_t); i++) {
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
114 if (!strcmp(symbols[i].name, name)) {
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
115 node = & (symbols[i]);
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
116 break;
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
117 }
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
118 }
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
119
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
120 if (!node) {
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
121 MSG("prefs: {%s} is not a recognized token.\n", name);
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
122 return -1;
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
123 }
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
124
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
125 switch (node->type) {
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
126 case PREFS_BOOL:
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
127 *(bool_t *)node->pref = (!dStrcasecmp(value, "yes") ||
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
128 !dStrcasecmp(value, "true"));
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
129 break;
1729
44b04d308585 bring back bg_color dillorc option
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1644
diff changeset
130 case PREFS_COLOR:
44b04d308585 bring back bg_color dillorc option
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1644
diff changeset
131 *(int32_t *)node->pref = a_Color_parse(value, *(int32_t*)node->pref,&st);
44b04d308585 bring back bg_color dillorc option
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1644
diff changeset
132 break;
1053
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
133 case PREFS_STRING:
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
134 dFree(*(char **)node->pref);
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
135 *(char **)node->pref = dStrdup(value);
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
136 break;
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
137 case PREFS_URL:
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
138 a_Url_free(*(DilloUrl **)node->pref);
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
139 *(DilloUrl **)node->pref = a_Url_new(value, NULL);
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
140 break;
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
141 case PREFS_INT32:
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
142 *(int32_t *)node->pref = strtol(value, NULL, 10);
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
143 break;
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
144 case PREFS_DOUBLE:
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
145 *(double *)node->pref = strtod(value, NULL);
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
146 break;
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
147 case PREFS_GEOMETRY:
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
148 a_Misc_parse_geometry(value, &prefs.xpos, &prefs.ypos,
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
149 &prefs.width, &prefs.height);
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
150 break;
1644
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1560
diff changeset
151 case PREFS_FILTER:
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1560
diff changeset
152 if (!dStrcasecmp(value, "same_domain"))
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1560
diff changeset
153 prefs.filter_auto_requests = PREFS_FILTER_SAME_DOMAIN;
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1560
diff changeset
154 else {
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1560
diff changeset
155 if (dStrcasecmp(value, "allow_all"))
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1560
diff changeset
156 MSG_WARN("prefs: unrecognized value for filter_auto_requests\n");
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1560
diff changeset
157 prefs.filter_auto_requests = PREFS_FILTER_ALLOW_ALL;
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1560
diff changeset
158 }
2650456b8199 filter automatic requests
corvid <corvid@lavabit.com>
parents: 1560
diff changeset
159 break;
1053
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
160 case PREFS_PANEL_SIZE:
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
161 if (!dStrcasecmp(value, "tiny"))
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
162 prefs.panel_size = P_tiny;
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
163 else if (!dStrcasecmp(value, "small"))
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
164 prefs.panel_size = P_small;
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
165 else if (!dStrcasecmp(value, "large"))
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
166 prefs.panel_size = P_large;
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
167 else /* default to "medium" */
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
168 prefs.panel_size = P_medium;
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
169 break;
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
170 default:
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
171 MSG_WARN("prefs: {%s} IS recognized but not handled!\n", name);
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
172 break; /* Not reached */
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
173 }
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
174
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
175 if (prefs.limit_text_width) {
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
176 /* BUG: causes 100% CPU usage with <button> or <input type="image"> */
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
177 MSG_WARN("Disabling limit_text_width preference (currently broken).\n");
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
178 prefs.limit_text_width = FALSE;
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
179 }
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
180
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
181 return 0;
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
182 }
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
183
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
184 /*
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
185 * Parses the dillorc and sets the values in the prefs structure.
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
186 */
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
187 void PrefsParser::parse(FILE *fp)
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
188 {
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
189 char *line, *name, *value, *oldLocale;
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
190 int st;
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
191
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
192 // changing the LC_NUMERIC locale (temporarily) to C
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
193 // avoids parsing problems with float numbers
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
194 oldLocale = dStrdup(setlocale(LC_NUMERIC, NULL));
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
195 setlocale(LC_NUMERIC, "C");
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
196
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
197 // scan the file line by line
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
198 while ((line = dGetline(fp)) != NULL) {
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
199 st = dParser_parse_rc_line(&line, &name, &value);
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
200
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
201 if (st == 0) {
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
202 _MSG("prefsparser: name=%s, value=%s\n", name, value);
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
203 parseOption(name, value);
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
204 } else if (st < 0) {
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
205 MSG_ERR("prefsparser: Syntax error in dillorc:"
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
206 " name=\"%s\" value=\"%s\"\n", name, value);
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
207 }
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
208
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
209 dFree(line);
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
210 }
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
211 fclose(fp);
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
212
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
213 // restore the old numeric locale
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
214 setlocale(LC_NUMERIC, oldLocale);
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
215 dFree(oldLocale);
64e078b7a711 Refactor the preferences parser
Tim Nieradzik, Jorge Arellano Cid
parents:
diff changeset
216 }