src/server/config/serverconfig.c

changeset 459
f21b4ff81c01
parent 455
e52a9fc670d2
child 464
0a29110b94ec
equal deleted inserted replaced
458:15bf3c1796f2 459:f21b4ff81c01
46 } 46 }
47 47
48 ConfigParser2 parser; 48 ConfigParser2 parser;
49 memset(&parser, 0, sizeof(ConfigParser2)); 49 memset(&parser, 0, sizeof(ConfigParser2));
50 parser.mp = mp; 50 parser.mp = mp;
51 parser.filename = file;
51 parser.allow_hierarchy = true; 52 parser.allow_hierarchy = true;
52 parser.delim = ""; 53 parser.delim = "";
53 ConfigNode *root = serverconfig_load_file(&parser, file); 54 ConfigNode *root = serverconfig_load_file(&parser, file);
54 if(!root) { 55 if(!root) {
55 cxMempoolDestroy(mp); 56 cxMempoolDestroy(mp);
124 for(i=start;i<content.length;i++) { 125 for(i=start;i<content.length;i++) {
125 char c = content.ptr[i]; 126 char c = content.ptr[i];
126 if(c == '\n') { 127 if(c == '\n') {
127 if(quote) { 128 if(quote) {
128 *pos = i; 129 *pos = i;
130 log_ereport(
131 LOG_FAILURE,
132 "cfgparser: file %s:%d:%d: error: %s",
133 parser->filename,
134 parser->linenum,
135 parser->linepos+2,
136 "missing '\"' character before end of line");
129 return token; // error 137 return token; // error
130 } else if(start == i) { 138 } else if(start == i) {
131 // single newline char token 139 // single newline char token
132 type = CFG_TOKEN_NEWLINE; 140 type = CFG_TOKEN_NEWLINE;
133 token_begin = i; 141 token_begin = i;
134 token_end = i+1; 142 token_end = i+1;
143 parser->linenum++;
144 parser->linepos = 0;
135 break; 145 break;
136 } 146 }
137 147
138 token_end = i; 148 token_end = i;
139 if(token_begin < 0) { 149 if(token_begin < 0) {
177 } 187 }
178 } else if(token_begin < 0) { 188 } else if(token_begin < 0) {
179 token_begin = i; 189 token_begin = i;
180 } 190 }
181 prev = c; 191 prev = c;
192
193 parser->linepos++;
182 } 194 }
183 195
184 *pos = i + 1; 196 *pos = i + 1;
185 197
186 if(token_begin < 0) { 198 if(token_begin < 0) {
187 return token; // error 199 return token; // error or EOF
188 } 200 }
189 201
190 token.type = type; 202 token.type = type;
191 token.content = cx_strsubsl(content, token_begin, token_end - token_begin); 203 token.content = cx_strsubsl(content, token_begin, token_end - token_begin);
192 return token; 204 return token;
246 } 258 }
247 259
248 ConfigNode* serverconfig_parse(ConfigParser2 *parser, cxstring content) { 260 ConfigNode* serverconfig_parse(ConfigParser2 *parser, cxstring content) {
249 CxMempool *mp = parser->mp; 261 CxMempool *mp = parser->mp;
250 CxAllocator *a = (CxAllocator*)mp->allocator; 262 CxAllocator *a = (CxAllocator*)mp->allocator;
263
264 parser->linenum = 1;
265 parser->linepos = 1;
251 266
252 if(!parser->delim) { 267 if(!parser->delim) {
253 parser->delim = ""; 268 parser->delim = "";
254 } 269 }
255 270

mercurial