Mercurial > ~mikael > mcabber > hg
comparison 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 |
comparison
equal
deleted
inserted
replaced
292:96917f04c841 | 293:d0295e735768 |
---|---|
69 // to NULL and return FALSE. | 69 // to NULL and return FALSE. |
70 // | 70 // |
71 // The called should g_free() *pkey and *pval (if not NULL) after use. | 71 // The called should g_free() *pkey and *pval (if not NULL) after use. |
72 guint parse_assigment(gchar *assignment, const gchar **pkey, const gchar **pval) | 72 guint parse_assigment(gchar *assignment, const gchar **pkey, const gchar **pval) |
73 { | 73 { |
74 char *key, *val, *t; | 74 char *key, *val, *t, *p; |
75 | 75 |
76 *pkey = *pval = NULL; | 76 *pkey = *pval = NULL; |
77 | 77 |
78 key = assignment; | 78 key = assignment; |
79 // Remove leading spaces in option name | 79 // Remove leading spaces in option name |
80 while ((!isalnum(*key)) && (*key != '=') && *key) { | 80 while ((!isalnum(*key)) && (*key != '=') && *key) { |
81 //if (!isblank(*key)) | 81 //if (!isblank(*key)) |
82 // scr_LogPrint("Error in setting parsing!\n"); | 82 // scr_LogPrint("Error in assignment parsing!"); |
83 key++; | 83 key++; |
84 } | 84 } |
85 if (!*key) return FALSE; // Empty assignment | 85 if (!*key) return FALSE; // Empty assignment |
86 | 86 |
87 if (*key == '=') { | 87 if (*key == '=') { |
88 //scr_LogPrint("Cannot parse setting!\n"); | 88 //scr_LogPrint("Cannot parse assignment!"); |
89 return FALSE; | 89 return FALSE; |
90 } | 90 } |
91 // Ok, key points to the option name | 91 // Ok, key points to the option name |
92 | 92 |
93 for (val = key+1 ; *val && (*val != '=') ; val++) | 93 for (val = key+1 ; *val && (*val != '=') ; val++) |
94 if (!isalnum(*val) && !isblank(*val) && (*val != '_') && (*val != '-')) { | 94 if (!isalnum(*val) && !isblank(*val) && (*val != '_') && (*val != '-')) { |
95 // Key should only have alnum chars... | 95 // Key should only have alnum chars... |
96 //scr_LogPrint("Error in setting parsing!\n"); | 96 //scr_LogPrint("Error in assignment parsing!"); |
97 return FALSE; | 97 return FALSE; |
98 } | 98 } |
99 // Remove trailing spaces in option name: | 99 // Remove trailing spaces in option name: |
100 for (t = val-1 ; t > key && isblank(*t) ; t--) | 100 for (t = val-1 ; t > key && isblank(*t) ; t--) |
101 ; | 101 ; |
102 // Check for embedded whitespace characters | |
103 for (p = key; p < t; p++) { | |
104 if (isblank(*p)) { | |
105 //scr_LogPrint("Error in assignment parsing!" | |
106 // " (Name should not contain space chars)"); | |
107 return FALSE; | |
108 } | |
109 } | |
110 | |
102 *pkey = g_strndup(key, t+1-key); | 111 *pkey = g_strndup(key, t+1-key); |
103 | 112 |
104 if (!*val) return FALSE; // Not an assignment | 113 if (!*val) return FALSE; // Not an assignment |
105 | 114 |
106 // Remove leading and trailing spaces in option value: | 115 // Remove leading and trailing spaces in option value: |