comparison mcabber/src/settings.c @ 280:68ce34b4243b

Add parse_assigment() function Add parse_assigment() to parse options/aliases/bindings lines.
author Mikael Berthe <mikael@lilotux.net>
date Wed, 06 Jul 2005 21:28:37 +0100
parents f5dd437c057b
children f562b9af2de7
comparison
equal deleted inserted replaced
279:f5dd437c057b 280:68ce34b4243b
19 * USA 19 * USA
20 */ 20 */
21 21
22 #include <strings.h> 22 #include <strings.h>
23 #include <stdlib.h> 23 #include <stdlib.h>
24 #include <ctype.h>
24 25
25 #include "settings.h" 26 #include "settings.h"
26 27
27 static GSList *option; 28 static GSList *option;
28 static GSList *alias; 29 static GSList *alias;
55 56
56 return ptr; 57 return ptr;
57 } 58 }
58 59
59 /* -- */ 60 /* -- */
61
62 // parse_assigment(assignment, pkey, pval)
63 // Read assignment and split it to key, value
64 //
65 // If this is an assignment, the function will return TRUE and
66 // set *pkey and *pval (*pval is set to NULL if value field is empty).
67 //
68 // If this isn't a assignment (no = char), the function will set *pval
69 // to NULL and return FALSE.
70 //
71 // The called should g_free() *pkey and *pval (if not NULL) after use.
72 guint parse_assigment(gchar *assignment, gchar **pkey, gchar **pval)
73 {
74 char *key, *val, *t;
75
76 *pkey = *pval = NULL;
77
78 key = assignment;
79 // Remove leading spaces in option name
80 while ((!isalnum(*key)) && (*key != '=') && *key) {
81 //if (!isblank(*key))
82 // scr_LogPrint("Error in setting parsing!\n");
83 key++;
84 }
85 if (!*key) return FALSE; // Empty assignment
86
87 if (*key == '=') {
88 //scr_LogPrint("Cannot parse setting!\n");
89 return FALSE;
90 }
91 // Ok, key points to the option name
92
93 for (val = key+1 ; *val && (*val != '=') ; val++)
94 if (!isalnum(*val) && !isblank(*val) && (*val != '_') && (*val != '-')) {
95 // Key should only have alnum chars...
96 //scr_LogPrint("Error in setting parsing!\n");
97 return FALSE;
98 }
99 // Remove trailing spaces in option name:
100 for (t = val-1 ; t > key && isblank(*t) ; t--)
101 ;
102 *pkey = g_strndup(key, t+1-key);
103
104 if (!*val) return FALSE; // Not an assignment
105
106 // Remove leading and trailing spaces in option value:
107 for (val++; *val && isblank(*val) ; val++) ;
108 for (t = val ; *t ; t++) ;
109 for (t-- ; t >= val && isblank(*t) ; t--) ;
110
111 if (t < val) return FALSE; // no value (variable reset for example)
112
113 *pval = g_strndup(val, t+1-val);
114 return TRUE;
115 }
60 116
61 void settings_set(guint type, gchar *key, gchar *value) 117 void settings_set(guint type, gchar *key, gchar *value)
62 { 118 {
63 GSList **plist; 119 GSList **plist;
64 GSList *sptr; 120 GSList *sptr;