annotate mcabber/src/settings.c @ 293:d0295e735768

Assignment lvalue (key, option name, alias...) cannnot contain spaces
author Mikael Berthe <mikael@lilotux.net>
date Sat, 09 Jul 2005 09:50:01 +0100
parents 1eea0fa0955e
children 871e53769084
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
279
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
1 /*
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
2 * settings.c -- Configuration stuff
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
3 *
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
4 * Copyright (C) 2005 Mikael Berthe <bmikael@lists.lilotux.net>
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
5 *
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or (at
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
9 * your option) any later version.
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
10 *
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful, but
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
14 * General Public License for more details.
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
15 *
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
17 * along with this program; if not, write to the Free Software
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
19 * USA
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
20 */
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
21
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
22 #include <strings.h>
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
23 #include <stdlib.h>
280
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
24 #include <ctype.h>
279
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
25
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
26 #include "settings.h"
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
27
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
28 static GSList *option;
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
29 static GSList *alias;
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
30 static GSList *binding;
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
31
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
32
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
33 typedef struct {
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
34 gchar *name;
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
35 gchar *value;
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
36 } T_setting;
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
37
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
38 inline GSList **get_list_ptr(guint type)
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
39 {
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
40 if (type == SETTINGS_TYPE_OPTION) return &option;
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
41 else if (type == SETTINGS_TYPE_ALIAS) return &alias;
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
42 else if (type == SETTINGS_TYPE_BINDING) return &binding;
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
43 return NULL;
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
44 }
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
45
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
46 // Return a pointer to the node with the requested key, or NULL if none found
281
f562b9af2de7 Add "const" specifier in prototypes
Mikael Berthe <mikael@lilotux.net>
parents: 280
diff changeset
47 GSList *settings_find(GSList *list, const gchar *key)
279
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
48 {
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
49 GSList *ptr;
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
50
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
51 if (!list) return NULL;
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
52
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
53 for (ptr = list ; ptr; ptr = g_slist_next(ptr))
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
54 if (!strcasecmp(key, ((T_setting*)ptr->data)->name))
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
55 break;
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
56
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
57 return ptr;
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
58 }
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
59
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
60 /* -- */
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
61
280
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
62 // parse_assigment(assignment, pkey, pval)
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
63 // Read assignment and split it to key, value
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
64 //
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
65 // If this is an assignment, the function will return TRUE and
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
66 // set *pkey and *pval (*pval is set to NULL if value field is empty).
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
67 //
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
68 // If this isn't a assignment (no = char), the function will set *pval
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
69 // to NULL and return FALSE.
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
70 //
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
71 // The called should g_free() *pkey and *pval (if not NULL) after use.
281
f562b9af2de7 Add "const" specifier in prototypes
Mikael Berthe <mikael@lilotux.net>
parents: 280
diff changeset
72 guint parse_assigment(gchar *assignment, const gchar **pkey, const gchar **pval)
280
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
73 {
293
d0295e735768 Assignment lvalue (key, option name, alias...) cannnot contain spaces
Mikael Berthe <mikael@lilotux.net>
parents: 288
diff changeset
74 char *key, *val, *t, *p;
280
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
75
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
76 *pkey = *pval = NULL;
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
77
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
78 key = assignment;
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
79 // Remove leading spaces in option name
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
80 while ((!isalnum(*key)) && (*key != '=') && *key) {
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
81 //if (!isblank(*key))
293
d0295e735768 Assignment lvalue (key, option name, alias...) cannnot contain spaces
Mikael Berthe <mikael@lilotux.net>
parents: 288
diff changeset
82 // scr_LogPrint("Error in assignment parsing!");
280
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
83 key++;
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
84 }
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
85 if (!*key) return FALSE; // Empty assignment
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
86
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
87 if (*key == '=') {
293
d0295e735768 Assignment lvalue (key, option name, alias...) cannnot contain spaces
Mikael Berthe <mikael@lilotux.net>
parents: 288
diff changeset
88 //scr_LogPrint("Cannot parse assignment!");
280
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
89 return FALSE;
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
90 }
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
91 // Ok, key points to the option name
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
92
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
93 for (val = key+1 ; *val && (*val != '=') ; val++)
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
94 if (!isalnum(*val) && !isblank(*val) && (*val != '_') && (*val != '-')) {
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
95 // Key should only have alnum chars...
293
d0295e735768 Assignment lvalue (key, option name, alias...) cannnot contain spaces
Mikael Berthe <mikael@lilotux.net>
parents: 288
diff changeset
96 //scr_LogPrint("Error in assignment parsing!");
280
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
97 return FALSE;
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
98 }
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
99 // Remove trailing spaces in option name:
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
100 for (t = val-1 ; t > key && isblank(*t) ; t--)
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
101 ;
293
d0295e735768 Assignment lvalue (key, option name, alias...) cannnot contain spaces
Mikael Berthe <mikael@lilotux.net>
parents: 288
diff changeset
102 // Check for embedded whitespace characters
d0295e735768 Assignment lvalue (key, option name, alias...) cannnot contain spaces
Mikael Berthe <mikael@lilotux.net>
parents: 288
diff changeset
103 for (p = key; p < t; p++) {
d0295e735768 Assignment lvalue (key, option name, alias...) cannnot contain spaces
Mikael Berthe <mikael@lilotux.net>
parents: 288
diff changeset
104 if (isblank(*p)) {
d0295e735768 Assignment lvalue (key, option name, alias...) cannnot contain spaces
Mikael Berthe <mikael@lilotux.net>
parents: 288
diff changeset
105 //scr_LogPrint("Error in assignment parsing!"
d0295e735768 Assignment lvalue (key, option name, alias...) cannnot contain spaces
Mikael Berthe <mikael@lilotux.net>
parents: 288
diff changeset
106 // " (Name should not contain space chars)");
d0295e735768 Assignment lvalue (key, option name, alias...) cannnot contain spaces
Mikael Berthe <mikael@lilotux.net>
parents: 288
diff changeset
107 return FALSE;
d0295e735768 Assignment lvalue (key, option name, alias...) cannnot contain spaces
Mikael Berthe <mikael@lilotux.net>
parents: 288
diff changeset
108 }
d0295e735768 Assignment lvalue (key, option name, alias...) cannnot contain spaces
Mikael Berthe <mikael@lilotux.net>
parents: 288
diff changeset
109 }
d0295e735768 Assignment lvalue (key, option name, alias...) cannnot contain spaces
Mikael Berthe <mikael@lilotux.net>
parents: 288
diff changeset
110
280
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
111 *pkey = g_strndup(key, t+1-key);
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
112
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
113 if (!*val) return FALSE; // Not an assignment
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
114
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
115 // Remove leading and trailing spaces in option value:
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
116 for (val++; *val && isblank(*val) ; val++) ;
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
117 for (t = val ; *t ; t++) ;
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
118 for (t-- ; t >= val && isblank(*t) ; t--) ;
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
119
282
87d6ac21cd1b Fix "Cannot unset option" bug
Mikael Berthe <mikael@lilotux.net>
parents: 281
diff changeset
120 if (t < val) return TRUE; // no value (variable reset for example)
280
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
121
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
122 *pval = g_strndup(val, t+1-val);
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
123 return TRUE;
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
124 }
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
125
281
f562b9af2de7 Add "const" specifier in prototypes
Mikael Berthe <mikael@lilotux.net>
parents: 280
diff changeset
126 void settings_set(guint type, const gchar *key, const gchar *value)
279
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
127 {
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
128 GSList **plist;
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
129 GSList *sptr;
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
130 T_setting *setting;
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
131
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
132 plist = get_list_ptr(type);
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
133 if (!plist) return;
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
134
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
135 sptr = settings_find(*plist, key);
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
136 if (sptr) {
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
137 // The setting has been found. We will update it or delete it.
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
138 setting = (T_setting*)sptr->data;
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
139 if (setting->value)
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
140 g_free(setting->value);
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
141 if (!value) {
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
142 // Let's remove the setting
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
143 g_free(setting->name);
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
144 *plist = g_slist_delete_link(*plist, sptr);
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
145 } else {
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
146 // Let's update the setting
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
147 setting->value = g_strdup(value);
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
148 }
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
149 } else if (value) {
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
150 setting = g_new(T_setting, 1);
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
151 setting->name = g_strdup(key);
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
152 setting->value = g_strdup(value);
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
153 *plist = g_slist_append(*plist, setting);
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
154 }
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
155 }
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
156
281
f562b9af2de7 Add "const" specifier in prototypes
Mikael Berthe <mikael@lilotux.net>
parents: 280
diff changeset
157 void settings_del(guint type, const gchar *key)
279
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
158 {
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
159 settings_set(type, key, NULL);
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
160 }
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
161
281
f562b9af2de7 Add "const" specifier in prototypes
Mikael Berthe <mikael@lilotux.net>
parents: 280
diff changeset
162 const gchar *settings_get(guint type, const gchar *key)
279
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
163 {
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
164 GSList **plist;
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
165 GSList *sptr;
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
166 T_setting *setting;
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
167
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
168 plist = get_list_ptr(type);
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
169 sptr = settings_find(*plist, key);
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
170 if (!sptr) return NULL;
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
171
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
172 setting = (T_setting*)sptr->data;
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
173 return setting->value;
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
174 }
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
175
281
f562b9af2de7 Add "const" specifier in prototypes
Mikael Berthe <mikael@lilotux.net>
parents: 280
diff changeset
176 int settings_get_int(guint type, const gchar *key)
279
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
177 {
281
f562b9af2de7 Add "const" specifier in prototypes
Mikael Berthe <mikael@lilotux.net>
parents: 280
diff changeset
178 const gchar *setval = settings_get(type, key);
279
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
179
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
180 if (setval) return atoi(setval);
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
181 return 0;
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
182 }
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
183
288
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 282
diff changeset
184 // Return the command the key is bound to, or NULL.
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 282
diff changeset
185 const gchar *isbound(int key)
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 282
diff changeset
186 {
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 282
diff changeset
187 gchar asciikey[16];
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 282
diff changeset
188 g_snprintf(asciikey, 15, "%d", key);
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 282
diff changeset
189 return settings_get(SETTINGS_TYPE_BINDING, asciikey);
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 282
diff changeset
190 }
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 282
diff changeset
191