Mercurial > hg > th-libs
changeset 203:7acdd3ab6900
Fix th_config for new th_ioctx API.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 11 Feb 2016 22:59:30 +0200 |
parents | b392293047da |
children | 55f429dff750 |
files | th_config.c th_config.h |
diffstat | 2 files changed, 38 insertions(+), 38 deletions(-) [+] |
line wrap: on
line diff
--- a/th_config.c Thu Feb 11 22:27:56 2016 +0200 +++ b/th_config.c Thu Feb 11 22:59:30 2016 +0200 @@ -207,7 +207,7 @@ #define VADDCH(ch) if (strPos < SET_MAX_BUF) { tmpStr[strPos++] = ch; } #define VISEND(ch) (ch == '\r' || ch == '\n' || ch == ';' || th_isspace(c) || ch == '#') -static int th_cfg_read_sect(th_ioctx_t *ctx, th_cfgitem_t *cfg, int nesting) +static int th_cfg_read_sect(th_ioctx *ctx, th_cfgitem_t *cfg, int nesting) { th_cfgitem_t *item = NULL; char *tmpStr = NULL; @@ -231,12 +231,12 @@ if (c == -1) { // Get next character - switch (c = fgetc(ctx->fp)) + switch (c = thfgetc(ctx)) { case EOF: if (parseMode != PM_IDLE) { - th_ioctx_error(ctx, -1, "Unexpected end of file.\n"); + th_io_error(ctx, -1, "Unexpected end of file.\n"); parseMode = PM_ERROR; } else @@ -280,7 +280,7 @@ goto out; else { - th_ioctx_error(ctx, -1, + th_io_error(ctx, -1, "Invalid nesting sequence encountered.\n"); parseMode = PM_ERROR; } @@ -295,7 +295,7 @@ else { // Error! Invalid character found - th_ioctx_error(ctx, -1, "Unexpected character '%c'.\n", c); + th_io_error(ctx, -1, "Unexpected character '%c'.\n", c); parseMode = PM_ERROR; } break; @@ -323,7 +323,7 @@ else { // Error! Key name string too long! - th_ioctx_error(ctx, -1, "Config key name too long!"); + th_io_error(ctx, -1, "Config key name too long!"); parseMode = PM_ERROR; } c = -1; @@ -332,7 +332,7 @@ { // Error! Invalid character found tmpStr[strPos] = 0; - th_ioctx_error(ctx, -1, + th_io_error(ctx, -1, "Unexpected character '%c' in key name '%s'.\n", c, tmpStr); parseMode = PM_ERROR; @@ -393,7 +393,7 @@ else { // Error! No configuration key by this name found - th_ioctx_error(ctx, -1, + th_io_error(ctx, -1, "No such configuration setting ('%s')\n", tmpStr); parseMode = PM_ERROR; @@ -404,7 +404,7 @@ else { // Error! '=' expected! - th_ioctx_error(ctx, -1, + th_io_error(ctx, -1, "Unexpected character '%c', assignation '=' was expected.\n", c); parseMode = PM_ERROR; @@ -468,7 +468,7 @@ if (c != '{') { // Error! Section start '{' expected! - th_ioctx_error(ctx, -1, + th_io_error(ctx, -1, "Unexpected character '%c', section start '{' was expected.\n", c); parseMode = PM_ERROR; @@ -531,7 +531,7 @@ else { // Error! String too long! - th_ioctx_error(ctx, -1, + th_io_error(ctx, -1, "String too long! Maximum is %d characters.", SET_MAX_BUF); parseMode = PM_ERROR; @@ -546,7 +546,7 @@ if (isStart && item->type == ITEM_UINT && c == '-') { // Error! Negative values not allowed for unsigned ints - th_ioctx_error(ctx, -1, + th_io_error(ctx, -1, "Negative value specified for %s, unsigned value expected.", item->name); parseMode = PM_ERROR; @@ -606,7 +606,7 @@ else { // Error! Unexpected character. - th_ioctx_error(ctx, -1, + th_io_error(ctx, -1, "Unexpected character '%c' for numeric setting '%s'.", c, item->name); parseMode = PM_ERROR; @@ -615,7 +615,7 @@ if (isError) { // Error! String too long! - th_ioctx_error(ctx, -1, + th_io_error(ctx, -1, "String too long! Maximum is %d characters.", SET_MAX_BUF); parseMode = PM_ERROR; @@ -655,7 +655,7 @@ if (isError) { - th_ioctx_error(ctx, -1, + th_io_error(ctx, -1, "Invalid boolean value for '%s'.\n", item->name); parseMode = PM_ERROR; @@ -680,7 +680,7 @@ } -int th_cfg_read(th_ioctx_t *ctx, th_cfgitem_t *cfg) +int th_cfg_read(th_ioctx *ctx, th_cfgitem_t *cfg) { if (ctx == NULL || cfg == NULL) return -1; @@ -691,22 +691,22 @@ /* Write a configuration into file */ -static void th_print_indent(th_ioctx_t *ctx, int nesting) +static void th_print_indent(th_ioctx *ctx, int nesting) { int i; for (i = 0; i < nesting * 2; i++) - fputc(' ', ctx->fp); + thfputc(' ', ctx); } -static int th_cfg_write_sect(th_ioctx_t *ctx, const th_cfgitem_t *item, int nesting) +static int th_cfg_write_sect(th_ioctx *ctx, const th_cfgitem_t *item, int nesting) { while (item != NULL) { if (item->type == ITEM_COMMENT) { th_print_indent(ctx, nesting); - if (fprintf(ctx->fp, "# %s\n", + if (thfprintf(ctx, "# %s\n", (item->name != NULL) ? item->name : "") < 0) return -1; } @@ -719,13 +719,13 @@ case ITEM_STRING: if (*(item->v.val_str) == NULL) { - if (fprintf(ctx->fp, "#%s = \"\"\n", + if (thfprintf(ctx, "#%s = \"\"\n", item->name) < 0) return -3; } else { - if (fprintf(ctx->fp, "%s = \"%s\"\n", + if (thfprintf(ctx, "%s = \"%s\"\n", item->name, *(item->v.val_str)) < 0) return -3; } @@ -734,7 +734,7 @@ case ITEM_STRING_LIST: if (*(item->v.list) == NULL) { - if (fprintf(ctx->fp, + if (thfprintf(ctx, "#%s = \"\", \"\"\n", item->name) < 0) return -3; } @@ -742,46 +742,46 @@ { th_llist_t *node = *(item->v.list); size_t n = th_llist_length(node); - if (fprintf(ctx->fp, "%s = ", item->name) < 0) + if (thfprintf(ctx, "%s = ", item->name) < 0) return -3; for (; node != NULL; node = node->next) { if (node->data != NULL) - fprintf(ctx->fp, "\"%s\"", (char *) node->data); + thfprintf(ctx, "\"%s\"", (char *) node->data); if (--n > 0) { - fprintf(ctx->fp, ",\n"); + thfprintf(ctx, ",\n"); th_print_indent(ctx, nesting); } } - if (fprintf(ctx->fp, "\n") < 0) + if (thfprintf(ctx, "\n") < 0) return -3; } break; case ITEM_INT: - if (fprintf(ctx->fp, "%s = %i\n", + if (thfprintf(ctx, "%s = %i\n", item->name, *(item->v.val_int)) < 0) return -4; break; case ITEM_UINT: - if (fprintf(ctx->fp, "%s = %d\n", + if (thfprintf(ctx, "%s = %d\n", item->name, *(item->v.val_uint)) < 0) return -5; break; case ITEM_FLOAT: - if (fprintf(ctx->fp, "%s = %1.5f\n", + if (thfprintf(ctx, "%s = %1.5f\n", item->name, *(item->v.val_float)) < 0) return -5; break; case ITEM_BOOL: - if (fprintf(ctx->fp, "%s = %s\n", item->name, + if (thfprintf(ctx, "%s = %s\n", item->name, *(item->v.val_bool) ? "yes" : "no") < 0) return -6; break; @@ -789,18 +789,18 @@ case ITEM_SECTION: { int res; - if (fprintf(ctx->fp, "%s = {\n", item->name) < 0) + if (thfprintf(ctx, "%s = {\n", item->name) < 0) return -7; res = th_cfg_write_sect(ctx, item->v.section, nesting + 1); if (res != 0) return res; - if (fprintf(ctx->fp, "}\n\n") < 0) + if (thfprintf(ctx, "}\n\n") < 0) return -8; } break; case ITEM_HEX_TRIPLET: - if (fprintf(ctx->fp, "%s = \"%06x\"\n", + if (thfprintf(ctx, "%s = \"%06x\"\n", item->name, *(item->v.val_int)) < 0) return -6; break; @@ -813,12 +813,12 @@ } -int th_cfg_write(th_ioctx_t *ctx, const th_cfgitem_t *cfg) +int th_cfg_write(th_ioctx *ctx, const th_cfgitem_t *cfg) { if (ctx == NULL || cfg == NULL) return -1; - fprintf(ctx->fp, "# Configuration written by %s %s\n\n", + thfprintf(ctx, "# Configuration written by %s %s\n\n", th_prog_desc, th_prog_version); return th_cfg_write_sect(ctx, cfg, 0);
--- a/th_config.h Thu Feb 11 22:27:56 2016 +0200 +++ b/th_config.h Thu Feb 11 22:59:30 2016 +0200 @@ -55,9 +55,9 @@ /* Functions */ -int th_cfg_read(th_ioctx_t *, th_cfgitem_t *); +int th_cfg_read(th_ioctx *, th_cfgitem_t *); void th_cfg_free(th_cfgitem_t *); -int th_cfg_write(th_ioctx_t *, const th_cfgitem_t *); +int th_cfg_write(th_ioctx *, const th_cfgitem_t *); int th_cfg_add_section(th_cfgitem_t **cfg, const char *name, th_cfgitem_t *data); int th_cfg_add_comment(th_cfgitem_t **cfg, const char *comment);