comparison th_config.c @ 159:fc914ff7a9b8

Rename a constant.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 07 Feb 2015 02:55:54 +0200
parents 23a79bd6c9d6
children a69764b4305f
comparison
equal deleted inserted replaced
158:79e904905dbf 159:fc914ff7a9b8
190 */ 190 */
191 enum 191 enum
192 { 192 {
193 PM_EOF, 193 PM_EOF,
194 PM_ERROR, 194 PM_ERROR,
195 PM_NORMAL, 195 PM_IDLE,
196 PM_COMMENT, 196 PM_COMMENT,
197 PM_NEXT, 197 PM_NEXT,
198 PM_KEYNAME, 198 PM_KEYNAME,
199 PM_KEYSET, 199 PM_KEYSET,
200 PM_STRING, 200 PM_STRING,
218 // Initialize values 218 // Initialize values
219 tmpCh = 0; 219 tmpCh = 0;
220 strPos = 0; 220 strPos = 0;
221 c = -1; 221 c = -1;
222 isFound = isStart = isError = validError = FALSE; 222 isFound = isStart = isError = validError = FALSE;
223 nextMode = prevMode = parseMode = PM_NORMAL; 223 nextMode = prevMode = parseMode = PM_IDLE;
224 224
225 if ((tmpStr = th_malloc(SET_MAX_BUF + 1)) == NULL) 225 if ((tmpStr = th_malloc(SET_MAX_BUF + 1)) == NULL)
226 goto out; 226 goto out;
227 227
228 // Parse the configuration 228 // Parse the configuration
232 { 232 {
233 // Get next character 233 // Get next character
234 switch (c = fgetc(ctx->fp)) 234 switch (c = fgetc(ctx->fp))
235 { 235 {
236 case EOF: 236 case EOF:
237 if (parseMode != PM_NORMAL) 237 if (parseMode != PM_IDLE)
238 { 238 {
239 th_ioctx_error(ctx, -1, "Unexpected end of file.\n"); 239 th_ioctx_error(ctx, -1, "Unexpected end of file.\n");
240 parseMode = PM_ERROR; 240 parseMode = PM_ERROR;
241 } 241 }
242 else 242 else
259 prevMode = PM_COMMENT; 259 prevMode = PM_COMMENT;
260 } 260 }
261 c = -1; 261 c = -1;
262 break; 262 break;
263 263
264 case PM_NORMAL: 264 case PM_IDLE:
265 // Normal parsing mode 265 // Normal parsing mode
266 if (c == '#') 266 if (c == '#')
267 { 267 {
268 prevMode = parseMode; 268 prevMode = parseMode;
269 parseMode = PM_COMMENT; 269 parseMode = PM_COMMENT;
455 } 455 }
456 } 456 }
457 else 457 else
458 { 458 {
459 prevMode = parseMode; 459 prevMode = parseMode;
460 parseMode = PM_NORMAL; 460 parseMode = PM_IDLE;
461 } 461 }
462 break; 462 break;
463 463
464 case PM_SECTION: 464 case PM_SECTION:
465 // Section parsing mode 465 // Section parsing mode
480 else if (res < 0) 480 else if (res < 0)
481 parseMode = PM_ERROR; 481 parseMode = PM_ERROR;
482 else 482 else
483 { 483 {
484 prevMode = parseMode; 484 prevMode = parseMode;
485 parseMode = PM_NORMAL; 485 parseMode = PM_IDLE;
486 } 486 }
487 } 487 }
488 break; 488 break;
489 489
490 case PM_STRING: 490 case PM_STRING:
504 switch (item->type) 504 switch (item->type)
505 { 505 {
506 case ITEM_HEX_TRIPLET: 506 case ITEM_HEX_TRIPLET:
507 *(item->v.val_int) = th_get_hex_triplet(tmpStr); 507 *(item->v.val_int) = th_get_hex_triplet(tmpStr);
508 prevMode = parseMode; 508 prevMode = parseMode;
509 parseMode = PM_NORMAL; 509 parseMode = PM_IDLE;
510 break; 510 break;
511 case ITEM_STRING: 511 case ITEM_STRING:
512 th_pstrcpy(item->v.val_str, tmpStr); 512 th_pstrcpy(item->v.val_str, tmpStr);
513 prevMode = parseMode; 513 prevMode = parseMode;
514 parseMode = PM_NORMAL; 514 parseMode = PM_IDLE;
515 break; 515 break;
516 case ITEM_STRING_LIST: 516 case ITEM_STRING_LIST:
517 th_llist_append(item->v.list, th_strdup(tmpStr)); 517 th_llist_append(item->v.list, th_strdup(tmpStr));
518 prevMode = parseMode; 518 prevMode = parseMode;
519 parseMode = PM_NEXT; 519 parseMode = PM_NEXT;
575 *(item->v.val_uint) = atol(tmpStr); 575 *(item->v.val_uint) = atol(tmpStr);
576 break; 576 break;
577 } 577 }
578 578
579 prevMode = parseMode; 579 prevMode = parseMode;
580 parseMode = PM_NORMAL; 580 parseMode = PM_IDLE;
581 } 581 }
582 else 582 else
583 { 583 {
584 // Error! Unexpected character. 584 // Error! Unexpected character.
585 th_ioctx_error(ctx, -1, 585 th_ioctx_error(ctx, -1,
645 else 645 else
646 { 646 {
647 *(item->v.val_bool) = tmpBool; 647 *(item->v.val_bool) = tmpBool;
648 648
649 prevMode = parseMode; 649 prevMode = parseMode;
650 parseMode = PM_NORMAL; 650 parseMode = PM_IDLE;
651 } 651 }
652 } 652 }
653 c = -1; 653 c = -1;
654 break; 654 break;
655 } 655 }