Mercurial > hg > th-libs
comparison th_config.c @ 771:c17eadc60c3d
Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 20 Feb 2023 23:33:45 +0200 |
parents | 31bc1ed07cf5 |
children | 4744e64ffa3a |
comparison
equal
deleted
inserted
replaced
770:79f888e4616f | 771:c17eadc60c3d |
---|---|
317 | 317 |
318 return res ? THERR_OK : THERR_INVALID_DATA; | 318 return res ? THERR_OK : THERR_INVALID_DATA; |
319 } | 319 } |
320 | 320 |
321 | 321 |
322 static int th_cfg_read_sect(th_ioctx *fh, th_cfgitem_t *sect, int nesting) | 322 static int th_cfg_read_sect(th_ioctx_t *fh, th_cfgitem_t *sect, int nesting) |
323 { | 323 { |
324 th_cfgparserctx_t ctx; | 324 th_cfgparserctx_t ctx; |
325 th_cfgitem_t *item = NULL; | 325 th_cfgitem_t *item = NULL; |
326 char *tmpStr = NULL; | 326 char *tmpStr = NULL; |
327 size_t strPos; | 327 size_t strPos; |
723 | 723 |
724 return ret; | 724 return ret; |
725 } | 725 } |
726 | 726 |
727 | 727 |
728 int th_cfg_read(th_ioctx *fh, th_cfgitem_t *cfg) | 728 int th_cfg_read(th_ioctx_t *fh, th_cfgitem_t *cfg) |
729 { | 729 { |
730 if (fh == NULL || cfg == NULL) | 730 if (fh == NULL || cfg == NULL) |
731 return THERR_NULLPTR; | 731 return THERR_NULLPTR; |
732 | 732 |
733 return th_cfg_read_sect(fh, cfg, 0); | 733 return th_cfg_read_sect(fh, cfg, 0); |
734 } | 734 } |
735 | 735 |
736 | 736 |
737 /* Write a configuration into file | 737 /* Write a configuration into file |
738 */ | 738 */ |
739 static bool th_print_indent_a(th_ioctx *fh, const int nesting, const char *fmt, va_list ap) | 739 static bool th_print_indent_a(th_ioctx_t *fh, const int nesting, const char *fmt, va_list ap) |
740 { | 740 { |
741 for (int i = 0; i < nesting * 4; i++) | 741 for (int i = 0; i < nesting * 4; i++) |
742 { | 742 { |
743 if (thfputc(' ', fh) == EOF) | 743 if (thfputc(' ', fh) == EOF) |
744 return false; | 744 return false; |
746 | 746 |
747 return thvfprintf(fh, fmt, ap) >= 0; | 747 return thvfprintf(fh, fmt, ap) >= 0; |
748 } | 748 } |
749 | 749 |
750 | 750 |
751 static bool th_print_indent(th_ioctx *fh, const int nesting, const char *fmt, ...) | 751 static bool th_print_indent(th_ioctx_t *fh, const int nesting, const char *fmt, ...) |
752 { | 752 { |
753 bool ret; | 753 bool ret; |
754 va_list ap; | 754 va_list ap; |
755 va_start(ap, fmt); | 755 va_start(ap, fmt); |
756 ret = th_print_indent_a(fh, nesting, fmt, ap); | 756 ret = th_print_indent_a(fh, nesting, fmt, ap); |
783 return false; | 783 return false; |
784 } | 784 } |
785 } | 785 } |
786 | 786 |
787 | 787 |
788 static bool th_cfg_write_string_escaped(th_ioctx *fh, const char *str, const char delim) | 788 static bool th_cfg_write_string_escaped(th_ioctx_t *fh, const char *str, const char delim) |
789 { | 789 { |
790 for (const char *ptr = str; *ptr; ptr++) | 790 for (const char *ptr = str; *ptr; ptr++) |
791 { | 791 { |
792 if (*ptr == delim) | 792 if (*ptr == delim) |
793 { | 793 { |
804 | 804 |
805 return true; | 805 return true; |
806 } | 806 } |
807 | 807 |
808 | 808 |
809 static int th_cfg_write_item(th_ioctx *fh, const th_cfgitem_t *item) | 809 static int th_cfg_write_item(th_ioctx_t *fh, const th_cfgitem_t *item) |
810 { | 810 { |
811 switch (item->type) | 811 switch (item->type) |
812 { | 812 { |
813 case ITEM_STRING: | 813 case ITEM_STRING: |
814 if (thfputc('"', fh) != EOF && | 814 if (thfputc('"', fh) != EOF && |
837 return -1; | 837 return -1; |
838 } | 838 } |
839 } | 839 } |
840 | 840 |
841 | 841 |
842 static int th_cfg_write_sect(th_ioctx *fh, const th_cfgitem_t *item, const int nesting) | 842 static int th_cfg_write_sect(th_ioctx_t *fh, const th_cfgitem_t *item, const int nesting) |
843 { | 843 { |
844 while (item != NULL) | 844 while (item != NULL) |
845 { | 845 { |
846 if (item->name == NULL) | 846 if (item->name == NULL) |
847 return THERR_NULLPTR; | 847 return THERR_NULLPTR; |
937 | 937 |
938 return THERR_OK; | 938 return THERR_OK; |
939 } | 939 } |
940 | 940 |
941 | 941 |
942 int th_cfg_write(th_ioctx *fh, const th_cfgitem_t *cfg) | 942 int th_cfg_write(th_ioctx_t *fh, const th_cfgitem_t *cfg) |
943 { | 943 { |
944 if (fh == NULL || cfg == NULL) | 944 if (fh == NULL || cfg == NULL) |
945 return THERR_NULLPTR; | 945 return THERR_NULLPTR; |
946 | 946 |
947 thfprintf(fh, "# Configuration written by %s %s\n\n", | 947 thfprintf(fh, "# Configuration written by %s %s\n\n", |