comparison th_config.c @ 261:0db02b8d2d11

ISO C99 compatibility fixes.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 22 May 2011 02:10:42 +0300
parents 659b8229d015
children e694c02d6982
comparison
equal deleted inserted replaced
260:e97c764927ce 261:0db02b8d2d11
25 25
26 while (curr != NULL) { 26 while (curr != NULL) {
27 cfgitem_t *next = curr->next; 27 cfgitem_t *next = curr->next;
28 28
29 if (curr->type == ITEM_SECTION) 29 if (curr->type == ITEM_SECTION)
30 th_cfg_free((cfgitem_t *) curr->data); 30 th_cfg_free((cfgitem_t *) curr->v.data);
31 31
32 th_free(curr->name); 32 th_free(curr->name);
33 th_free(curr); 33 th_free(curr);
34 curr = next; 34 curr = next;
35 } 35 }
50 if (node == NULL) 50 if (node == NULL)
51 return NULL; 51 return NULL;
52 52
53 /* Set values */ 53 /* Set values */
54 node->type = type; 54 node->type = type;
55 node->data = data; 55 node->v.data = data;
56 node->name = th_strdup(name); 56 node->name = th_strdup(name);
57 57
58 /* Insert into linked list */ 58 /* Insert into linked list */
59 if (*cfg != NULL) { 59 if (*cfg != NULL) {
60 node->prev = (*cfg)->prev; 60 node->prev = (*cfg)->prev;
445 /* Error! Section start '{' expected! */ 445 /* Error! Section start '{' expected! */
446 th_cfg_error(f, 446 th_cfg_error(f,
447 "Unexpected character '%c', section start '{' was expected.\n", c); 447 "Unexpected character '%c', section start '{' was expected.\n", c);
448 parseMode = PM_ERROR; 448 parseMode = PM_ERROR;
449 } else { 449 } else {
450 int res = th_cfg_read_sect(f, (cfgitem_t *) item->data, nesting + 1); 450 int res = th_cfg_read_sect(f, item->v.section, nesting + 1);
451 c = -1; 451 c = -1;
452 if (res > 0) 452 if (res > 0)
453 validError = TRUE; 453 validError = TRUE;
454 else if (res < 0) 454 else if (res < 0)
455 parseMode = PM_ERROR; 455 parseMode = PM_ERROR;
471 /* End of string, set the value */ 471 /* End of string, set the value */
472 tmpStr[strPos] = 0; 472 tmpStr[strPos] = 0;
473 473
474 switch (item->type) { 474 switch (item->type) {
475 case ITEM_HEX_TRIPLET: 475 case ITEM_HEX_TRIPLET:
476 *(int *) item->data = th_get_hex_triplet(tmpStr); 476 *(item->v.val_int) = th_get_hex_triplet(tmpStr);
477 prevMode = parseMode; 477 prevMode = parseMode;
478 parseMode = PM_NORMAL; 478 parseMode = PM_NORMAL;
479 break; 479 break;
480 case ITEM_STRING: 480 case ITEM_STRING:
481 th_pstrcpy((char **) item->data, tmpStr); 481 th_pstrcpy(item->v.val_str, tmpStr);
482 prevMode = parseMode; 482 prevMode = parseMode;
483 parseMode = PM_NORMAL; 483 parseMode = PM_NORMAL;
484 break; 484 break;
485 case ITEM_STRING_LIST: 485 case ITEM_STRING_LIST:
486 th_llist_append(item->list, th_strdup(tmpStr)); 486 th_llist_append(item->v.list, th_strdup(tmpStr));
487 prevMode = parseMode; 487 prevMode = parseMode;
488 parseMode = PM_NEXT; 488 parseMode = PM_NEXT;
489 nextMode = PM_ARRAY; 489 nextMode = PM_ARRAY;
490 break; 490 break;
491 } 491 }
525 } else if (VISEND(c)) { 525 } else if (VISEND(c)) {
526 /* End of integer parsing mode */ 526 /* End of integer parsing mode */
527 tmpStr[strPos] = 0; 527 tmpStr[strPos] = 0;
528 switch (item->type) { 528 switch (item->type) {
529 case ITEM_INT: 529 case ITEM_INT:
530 *((int *) item->data) = atoi(tmpStr); 530 *(item->v.val_int) = atoi(tmpStr);
531 break; 531 break;
532 532
533 case ITEM_UINT: 533 case ITEM_UINT:
534 *((unsigned int *) item->data) = atol(tmpStr); 534 *(item->v.val_uint) = atol(tmpStr);
535 break; 535 break;
536 } 536 }
537 537
538 prevMode = parseMode; 538 prevMode = parseMode;
539 parseMode = PM_NORMAL; 539 parseMode = PM_NORMAL;
584 584
585 if (isError) { 585 if (isError) {
586 th_cfg_error(f, "Invalid boolean value for '%s'.\n", item->name); 586 th_cfg_error(f, "Invalid boolean value for '%s'.\n", item->name);
587 parseMode = PM_ERROR; 587 parseMode = PM_ERROR;
588 } else { 588 } else {
589 *((BOOL *) item->data) = tmpBool; 589 *(item->v.val_bool) = tmpBool;
590 590
591 prevMode = parseMode; 591 prevMode = parseMode;
592 parseMode = PM_NORMAL; 592 parseMode = PM_NORMAL;
593 } 593 }
594 } 594 }
642 if (item->name != NULL) { 642 if (item->name != NULL) {
643 th_print_indent(f, nesting); 643 th_print_indent(f, nesting);
644 644
645 switch (item->type) { 645 switch (item->type) {
646 case ITEM_STRING: 646 case ITEM_STRING:
647 if (*(item->val_str) == NULL) { 647 if (*(item->v.val_str) == NULL) {
648 if (fprintf(f->file, "#%s = \"\"\n", item->name) < 0) 648 if (fprintf(f->file, "#%s = \"\"\n", item->name) < 0)
649 return -3; 649 return -3;
650 } else { 650 } else {
651 if (fprintf(f->file, "%s = \"%s\"\n", 651 if (fprintf(f->file, "%s = \"%s\"\n",
652 item->name, *(item->val_str)) < 0) 652 item->name, *(item->v.val_str)) < 0)
653 return -3; 653 return -3;
654 } 654 }
655 break; 655 break;
656 656
657 case ITEM_STRING_LIST: 657 case ITEM_STRING_LIST:
658 if (*(item->list) == NULL) { 658 if (*(item->v.list) == NULL) {
659 if (fprintf(f->file, "#%s = \"\", \"\"\n", item->name) < 0) 659 if (fprintf(f->file, "#%s = \"\", \"\"\n", item->name) < 0)
660 return -3; 660 return -3;
661 } else { 661 } else {
662 qlist_t *node = *(item->list); 662 qlist_t *node = *(item->v.list);
663 size_t n = th_llist_length(node); 663 size_t n = th_llist_length(node);
664 if (fprintf(f->file, "%s = ", item->name) < 0) 664 if (fprintf(f->file, "%s = ", item->name) < 0)
665 return -3; 665 return -3;
666 666
667 while (node != NULL) { 667 while (node != NULL) {
679 } 679 }
680 break; 680 break;
681 681
682 case ITEM_INT: 682 case ITEM_INT:
683 if (fprintf(f->file, "%s = %i\n", 683 if (fprintf(f->file, "%s = %i\n",
684 item->name, *(item->val_int)) < 0) 684 item->name, *(item->v.val_int)) < 0)
685 return -4; 685 return -4;
686 break; 686 break;
687 687
688 case ITEM_UINT: 688 case ITEM_UINT:
689 if (fprintf(f->file, "%s = %d\n", 689 if (fprintf(f->file, "%s = %d\n",
690 item->name, *(item->val_uint)) < 0) 690 item->name, *(item->v.val_uint)) < 0)
691 return -5; 691 return -5;
692 break; 692 break;
693 693
694 case ITEM_BOOL: 694 case ITEM_BOOL:
695 if (fprintf(f->file, "%s = %s\n", 695 if (fprintf(f->file, "%s = %s\n",
696 item->name, *(item->val_bool) ? "yes" : "no") < 0) 696 item->name, *(item->v.val_bool) ? "yes" : "no") < 0)
697 return -6; 697 return -6;
698 break; 698 break;
699 699
700 case ITEM_SECTION: 700 case ITEM_SECTION:
701 { 701 {
702 int res; 702 int res;
703 if (fprintf(f->file, "%s = {\n", item->name) < 0) 703 if (fprintf(f->file, "%s = {\n", item->name) < 0)
704 return -7; 704 return -7;
705 res = th_cfg_write_sect(f, (cfgitem_t *) item->data, nesting + 1); 705 res = th_cfg_write_sect(f, item->v.section, nesting + 1);
706 if (res != 0) return res; 706 if (res != 0) return res;
707 if (fprintf(f->file, "}\n\n") < 0) 707 if (fprintf(f->file, "}\n\n") < 0)
708 return -8; 708 return -8;
709 } 709 }
710 break; 710 break;
711 711
712 case ITEM_HEX_TRIPLET: 712 case ITEM_HEX_TRIPLET:
713 if (fprintf(f->file, "%s = \"%06x\"\n", 713 if (fprintf(f->file, "%s = \"%06x\"\n",
714 item->name, *((int *) item->data)) < 0) 714 item->name, *(item->v.val_int)) < 0)
715 return -6; 715 return -6;
716 break; 716 break;
717 } 717 }
718 } 718 }
719 item = item->next; 719 item = item->next;