comparison src/core/ngx_config_file.c @ 37:9fe40e51d4a3

nginx-0.0.1-2002-12-23-21:22:18 import
author Igor Sysoev <igor@sysoev.ru>
date Mon, 23 Dec 2002 18:22:18 +0000
parents c14d7232b11f
children d5d4f3bba6f0
comparison
equal deleted inserted replaced
36:c14d7232b11f 37:9fe40e51d4a3
177 ngx_hunk_t *h; 177 ngx_hunk_t *h;
178 178
179 found = 0; 179 found = 0;
180 need_space = 0; 180 need_space = 0;
181 last_space = 1; 181 last_space = 1;
182 len = 0;
183 quoted = s_quoted = d_quoted = 0; 182 quoted = s_quoted = d_quoted = 0;
184 183
185 cf->args->nelts = 0; 184 cf->args->nelts = 0;
186 h = cf->conf_file->hunk; 185 h = cf->conf_file->hunk;
186 start = h->pos.mem;
187 187
188 ngx_log_debug(cf->log, "TOKEN START"); 188 ngx_log_debug(cf->log, "TOKEN START");
189 189
190 for (start = h->pos.mem; /* void */ ; /* void */) { 190 for ( ;; ) {
191 191
192 if (h->pos.mem >= h->last.mem) { 192 if (h->pos.mem >= h->last.mem) {
193 if (cf->conf_file->file.offset 193 if (cf->conf_file->file.offset
194 >= ngx_file_size(cf->conf_file->file.info)) { 194 >= ngx_file_size(cf->conf_file->file.info)) {
195 return NGX_FILE_DONE; 195 return NGX_FILE_DONE;
213 h->last.mem = h->pos.mem + n; 213 h->last.mem = h->pos.mem + n;
214 } 214 }
215 215
216 ch = *h->pos.mem++; 216 ch = *h->pos.mem++;
217 217
218 #if 0
218 ngx_log_debug(cf->log, "%d:%d:%d:%d:%d '%c'" _ 219 ngx_log_debug(cf->log, "%d:%d:%d:%d:%d '%c'" _
219 last_space _ need_space _ 220 last_space _ need_space _
220 quoted _ s_quoted _ d_quoted _ ch); 221 quoted _ s_quoted _ d_quoted _ ch);
222 #endif
221 223
222 if (ch == LF) { 224 if (ch == LF) {
223 cf->conf_file->line++; 225 cf->conf_file->line++;
226 }
227
228 if (quoted) {
229 quoted = 0;
230 continue;
224 } 231 }
225 232
226 if (need_space) { 233 if (need_space) {
227 if (ch == ' ' || ch == '\t' || ch == CR || ch == LF) { 234 if (ch == ' ' || ch == '\t' || ch == CR || ch == LF) {
228 last_space = 1; 235 last_space = 1;
235 } 242 }
236 243
237 return NGX_ERROR; 244 return NGX_ERROR;
238 } 245 }
239 246
240 if (quoted) {
241 quoted = 0;
242 continue;
243 }
244
245 len++;
246
247 if (last_space) { 247 if (last_space) {
248 if (ch == ' ' || ch == '\t' || ch == CR || ch == LF) { 248 if (ch == ' ' || ch == '\t' || ch == CR || ch == LF) {
249 len = 0;
250 continue; 249 continue;
251 } 250 }
252 251
253 start = h->pos.mem - 1; 252 start = h->pos.mem - 1;
254 253
255 switch (ch) { 254 switch (ch) {
255
256 case ';':
257 case '{':
258 return NGX_OK;
256 259
257 case '\\': 260 case '\\':
258 quoted = 1; 261 quoted = 1;
259 last_space = 0; 262 last_space = 0;
260 continue; 263 continue;
261 264
262 case '"': 265 case '"':
263 start++; 266 start++;
264 len--;
265 d_quoted = 1; 267 d_quoted = 1;
266 last_space = 0; 268 last_space = 0;
267 continue; 269 continue;
268 270
269 case '\'': 271 case '\'':
270 start++; 272 start++;
271 len--;
272 s_quoted = 1; 273 s_quoted = 1;
273 last_space = 0; 274 last_space = 0;
274 continue; 275 continue;
275 276
276 default: 277 default:
283 continue; 284 continue;
284 } 285 }
285 286
286 if (d_quoted) { 287 if (d_quoted) {
287 if (ch == '"') { 288 if (ch == '"') {
288 len--;
289 d_quoted = 0; 289 d_quoted = 0;
290 need_space = 1; 290 need_space = 1;
291 found = 1; 291 found = 1;
292 } 292 }
293 293
294 } else if (s_quoted) { 294 } else if (s_quoted) {
295 if (ch == '\'') { 295 if (ch == '\'') {
296 len--;
297 s_quoted = 0; 296 s_quoted = 0;
298 need_space = 1; 297 need_space = 1;
299 found = 1; 298 found = 1;
300 } 299 }
301 300
302 } else if (ch == ' ' || ch == '\t' || ch == CR || ch == LF 301 } else if (ch == ' ' || ch == '\t' || ch == CR || ch == LF
303 || ch == ';' || ch == '{') { 302 || ch == ';' || ch == '{') {
304 len--;
305 last_space = 1; 303 last_space = 1;
306 found = 1; 304 found = 1;
307 } 305 }
308 306
309 if (found) { 307 if (found) {
310 ngx_test_null(word, ngx_push_array(cf->args), NGX_ERROR); 308 ngx_test_null(word, ngx_push_array(cf->args), NGX_ERROR);
311 ngx_test_null(word->data, ngx_palloc(cf->pool, len + 1), 309 ngx_test_null(word->data,
310 ngx_palloc(cf->pool, h->pos.mem - start + 1),
312 NGX_ERROR); 311 NGX_ERROR);
313 word->len = len; 312
314 313 for (dst = word->data, src = start, len = 0;
315 for (dst = word->data, src = start;
316 src < h->pos.mem - 1; 314 src < h->pos.mem - 1;
317 /* void */) 315 len++)
318 { 316 {
319 if (*src == '\\') { 317 if (*src == '\\') {
320 src++; 318 src++;
321 } 319 }
322 *dst++ = *src++; 320 *dst++ = *src++;
323 } 321 }
324 *dst = '\0'; 322 *dst = '\0';
323 word->len = len;
325 324
326 ngx_log_debug(cf->log, "FOUND %d:'%s'" _ word->len _ word->data); 325 ngx_log_debug(cf->log, "FOUND %d:'%s'" _ word->len _ word->data);
327 326
328 if (ch == ';' || ch == '{') { 327 if (ch == ';' || ch == '{') {
329 return NGX_OK; 328 return NGX_OK;
330 } 329 }
331 330
332 found = 0; 331 found = 0;
333 len = 0;
334 } 332 }
335 } 333 }
336 } 334 }
337 } 335 }
338 336