MCPcopy Create free account
hub / github.com/dillo-browser/dillo / parseOption

Function parseOption

src/prefsparser.cc:54–143  ·  view source on GitHub ↗

* Parse a name/value pair and set preferences accordingly. */

Source from the content-addressed store, hash-verified

52 * Parse a name/value pair and set preferences accordingly.
53 */
54static int parseOption(char *name, char *value,
55 SymNode_t *symbols, int n_symbols)
56{
57 SymNode_t *node;
58 int i;
59 int st;
60
61 node = NULL;
62 for (i = 0; i < n_symbols; i++) {
63 if (!strcmp(symbols[i].name, name)) {
64 node = & (symbols[i]);
65 break;
66 }
67 }
68
69 if (!node) {
70 MSG("prefs: {%s} is not a recognized token.\n", name);
71 return -1;
72 }
73
74 switch (node->type) {
75 case PREFS_BOOL:
76 *(bool_t *)node->pref = (!dStrAsciiCasecmp(value, "yes") ||
77 !dStrAsciiCasecmp(value, "true"));
78 break;
79 case PREFS_COLOR:
80 *(int32_t *)node->pref = a_Color_parse(value, *(int32_t*)node->pref,&st);
81 if (st == 1)
82 MSG("prefs: Color '%s' not recognized.\n", value);
83 break;
84 case PREFS_STRING:
85 dFree(*(char **)node->pref);
86 *(char **)node->pref = dStrdup(value);
87 break;
88 case PREFS_STRINGS:
89 {
90 Dlist *lp = *(Dlist **)node->pref;
91 if (node->count == 0) {
92 /* override the default */
93 for (i = 0; i < dList_length(lp); i++) {
94 void *data = dList_nth_data(lp, i);
95 dList_remove(lp, data);
96 dFree(data);
97 }
98 }
99 dList_append(lp, dStrdup(value));
100 break;
101 }
102 case PREFS_URL:
103 a_Url_free(*(DilloUrl **)node->pref);
104 *(DilloUrl **)node->pref = a_Url_new(value, NULL);
105 break;
106 case PREFS_INT32:
107 *(int32_t *)node->pref = strtol(value, NULL, 10);
108 break;
109 case PREFS_DOUBLE:
110 *(double *)node->pref = strtod(value, NULL);
111 break;

Callers 1

parseMethod · 0.85

Calls 11

dStrAsciiCasecmpFunction · 0.85
a_Color_parseFunction · 0.85
dFreeFunction · 0.85
dStrdupFunction · 0.85
dList_lengthFunction · 0.85
dList_nth_dataFunction · 0.85
dList_removeFunction · 0.85
dList_appendFunction · 0.85
a_Url_freeFunction · 0.85
a_Url_newFunction · 0.85
a_Misc_parse_geometryFunction · 0.85

Tested by

no test coverage detected