# HG changeset patch # User Matti Hamalainen # Date 1688238771 -10800 # Node ID 08bbfb5239fc21a400f36b5f92e55870c6471172 # Parent 4744e64ffa3abee103af9d51db2d65b90ac3badf s/ITEM_/CFG_ITEM_/g' diff -r 4744e64ffa3a -r 08bbfb5239fc tests.c --- a/tests.c Sat Jul 01 20:33:45 2023 +0300 +++ b/tests.c Sat Jul 01 22:12:51 2023 +0300 @@ -401,11 +401,11 @@ { switch (node->type) { - case ITEM_STRING: + case CFG_ITEM_STRING: th_free(*(node->v.val_str)); break; - case ITEM_STRING_LIST: + case CFG_ITEM_STRING_LIST: break; } } diff -r 4744e64ffa3a -r 08bbfb5239fc th_config.c --- a/th_config.c Sat Jul 01 20:33:45 2023 +0300 +++ b/th_config.c Sat Jul 01 22:12:51 2023 +0300 @@ -26,7 +26,7 @@ { th_cfgitem_t *next = (th_cfgitem_t *) node->node.next; - if (node->type == ITEM_SECTION) + if (node->type == CFG_ITEM_SECTION) th_cfg_free((th_cfgitem_t *) node->v.data, freefunc); else if (freefunc != NULL) @@ -69,7 +69,7 @@ */ int th_cfg_add_int(th_cfgitem_t **cfg, const char *name, int *itemData, int defValue) { - th_cfgitem_t *node = th_cfg_add(cfg, name, ITEM_INT, (void *) itemData); + th_cfgitem_t *node = th_cfg_add(cfg, name, CFG_ITEM_INT, (void *) itemData); if (node == NULL) return THERR_MALLOC; @@ -82,7 +82,7 @@ int th_cfg_add_hexvalue(th_cfgitem_t **cfg, const char *name, unsigned int *itemData, unsigned int defValue) { - th_cfgitem_t *node = th_cfg_add(cfg, name, ITEM_HEX_TRIPLET, (void *) itemData); + th_cfgitem_t *node = th_cfg_add(cfg, name, CFG_ITEM_HEX_TRIPLET, (void *) itemData); if (node == NULL) return THERR_MALLOC; @@ -97,7 +97,7 @@ int th_cfg_add_uint(th_cfgitem_t **cfg, const char *name, unsigned int *itemData, unsigned int defValue) { - th_cfgitem_t *node = th_cfg_add(cfg, name, ITEM_UINT, (void *) itemData); + th_cfgitem_t *node = th_cfg_add(cfg, name, CFG_ITEM_UINT, (void *) itemData); if (node == NULL) return THERR_MALLOC; @@ -112,7 +112,7 @@ int th_cfg_add_string(th_cfgitem_t **cfg, const char *name, char **itemData, char *defValue) { - th_cfgitem_t *node = th_cfg_add(cfg, name, ITEM_STRING, (void *) itemData); + th_cfgitem_t *node = th_cfg_add(cfg, name, CFG_ITEM_STRING, (void *) itemData); if (node == NULL) return THERR_MALLOC; @@ -127,7 +127,7 @@ int th_cfg_add_bool(th_cfgitem_t **cfg, const char *name, bool *itemData, bool defValue) { - th_cfgitem_t *node = th_cfg_add(cfg, name, ITEM_BOOL, (void *) itemData); + th_cfgitem_t *node = th_cfg_add(cfg, name, CFG_ITEM_BOOL, (void *) itemData); if (node == NULL) return THERR_MALLOC; @@ -141,7 +141,7 @@ */ int th_cfg_add_comment(th_cfgitem_t **cfg, const char *comment) { - th_cfgitem_t *node = th_cfg_add(cfg, comment, ITEM_COMMENT, NULL); + th_cfgitem_t *node = th_cfg_add(cfg, comment, CFG_ITEM_COMMENT, NULL); if (node == NULL) return THERR_MALLOC; @@ -153,7 +153,7 @@ */ int th_cfg_add_section(th_cfgitem_t **cfg, const char *name, th_cfgitem_t *sect) { - th_cfgitem_t *node = th_cfg_add(cfg, name, ITEM_SECTION, (void *) sect); + th_cfgitem_t *node = th_cfg_add(cfg, name, CFG_ITEM_SECTION, (void *) sect); if (node == NULL) return THERR_MALLOC; @@ -168,7 +168,7 @@ if (data == NULL) return THERR_NULLPTR; - if ((node = th_cfg_add(cfg, name, ITEM_STRING_LIST, (void *) data)) == NULL) + if ((node = th_cfg_add(cfg, name, CFG_ITEM_STRING_LIST, (void *) data)) == NULL) return THERR_MALLOC; return THERR_OK; @@ -238,22 +238,22 @@ { switch (type) { - case ITEM_HEX_TRIPLET: - case ITEM_STRING: + case CFG_ITEM_HEX_TRIPLET: + case CFG_ITEM_STRING: return PM_STRING; - case ITEM_INT: - case ITEM_UINT: - case ITEM_FLOAT: + case CFG_ITEM_INT: + case CFG_ITEM_UINT: + case CFG_ITEM_FLOAT: return PM_NUMERIC; - case ITEM_BOOL: + case CFG_ITEM_BOOL: return PM_BOOL; - case ITEM_SECTION: + case CFG_ITEM_SECTION: return PM_SECTION; - case ITEM_STRING_LIST: + case CFG_ITEM_STRING_LIST: return PM_LIST; default: @@ -268,15 +268,15 @@ switch (item->type) { - case ITEM_HEX_TRIPLET: + case CFG_ITEM_HEX_TRIPLET: res = th_get_hex_triplet(str, item->v.val_uint); break; - case ITEM_STRING: + case CFG_ITEM_STRING: th_pstr_cpy(item->v.val_str, str); break; - case ITEM_STRING_LIST: + case CFG_ITEM_STRING_LIST: { char *tmp; if ((tmp = th_strdup(str)) != NULL) @@ -292,19 +292,19 @@ } break; - case ITEM_INT: + case CFG_ITEM_INT: *(item->v.val_int) = atoi(str); break; - case ITEM_UINT: + case CFG_ITEM_UINT: *(item->v.val_uint) = atol(str); break; - case ITEM_FLOAT: + case CFG_ITEM_FLOAT: *(item->v.val_float) = atof(str); break; - case ITEM_BOOL: + case CFG_ITEM_BOOL: res = th_get_boolean(str, item->v.val_bool); break; @@ -466,7 +466,7 @@ for (item = sect, found = false; item != NULL && !found; ) { - if (item->type != ITEM_COMMENT && + if (item->type != CFG_ITEM_COMMENT && item->name != NULL && strcmp(item->name, tmpStr) == 0) found = true; @@ -606,7 +606,7 @@ case PM_NUMERIC: // Integer parsing mode - if (isStart && item->type == ITEM_UINT && ctx.ch == '-') + if (isStart && item->type == CFG_ITEM_UINT && ctx.ch == '-') { // Error! Negative values not allowed for unsigned ints ret = th_io_error(fh, THERR_INVALID_DATA, @@ -622,7 +622,7 @@ ret = THERR_INVALID_DATA; } else - if (isStart && item->type == ITEM_FLOAT && ctx.ch == '.') + if (isStart && item->type == CFG_ITEM_FLOAT && ctx.ch == '.') { fpSet = true; VADDCH('0') @@ -634,7 +634,7 @@ ret = THERR_INVALID_DATA; } else - if (item->type == ITEM_FLOAT && ctx.ch == '.' && !fpSet) + if (item->type == CFG_ITEM_FLOAT && ctx.ch == '.' && !fpSet) { fpSet = true; VADDCH(ctx.ch) @@ -763,20 +763,20 @@ { switch (item->type) { - case ITEM_STRING: + case CFG_ITEM_STRING: return (*(item->v.val_str) != NULL); - case ITEM_STRING_LIST: + case CFG_ITEM_STRING_LIST: return (*(item->v.list) != NULL); - case ITEM_SECTION: + case CFG_ITEM_SECTION: return true; - case ITEM_INT: - case ITEM_UINT: - case ITEM_FLOAT: - case ITEM_BOOL: - case ITEM_HEX_TRIPLET: + case CFG_ITEM_INT: + case CFG_ITEM_UINT: + case CFG_ITEM_FLOAT: + case CFG_ITEM_BOOL: + case CFG_ITEM_HEX_TRIPLET: return true; default: @@ -810,7 +810,7 @@ { switch (item->type) { - case ITEM_STRING: + case CFG_ITEM_STRING: if (thfputc('"', fh) != EOF && th_cfg_write_string_escaped(fh, *(item->v.val_str), '"') && thfputc('"', fh) != EOF) @@ -818,19 +818,19 @@ else return -1; - case ITEM_INT: + case CFG_ITEM_INT: return thfprintf(fh, "%d", *(item->v.val_int)); - case ITEM_UINT: + case CFG_ITEM_UINT: return thfprintf(fh, "%u", *(item->v.val_uint)); - case ITEM_FLOAT: + case CFG_ITEM_FLOAT: return thfprintf(fh, "%1.5f", *(item->v.val_float)); - case ITEM_BOOL: + case CFG_ITEM_BOOL: return thfprintf(fh, "%s", *(item->v.val_bool) ? "yes" : "no"); - case ITEM_HEX_TRIPLET: + case CFG_ITEM_HEX_TRIPLET: return thfprintf(fh, "\"%06x\"", *(item->v.val_int)); default: @@ -846,7 +846,7 @@ if (item->name == NULL) return THERR_NULLPTR; - if (item->type == ITEM_COMMENT) + if (item->type == CFG_ITEM_COMMENT) { bool lineStart = true, lineFeed = false; @@ -880,7 +880,7 @@ thfprintf(fh, "\n"); } else - if (item->type == ITEM_SECTION) + if (item->type == CFG_ITEM_SECTION) { int res; @@ -894,7 +894,7 @@ return THERR_FWRITE; } else - if (item->type == ITEM_STRING_LIST) + if (item->type == CFG_ITEM_STRING_LIST) { if (!th_cfg_is_item_valid(item)) { @@ -970,7 +970,7 @@ match = false; // Recurse to section - if (!match && item->type == ITEM_SECTION) + if (!match && item->type == CFG_ITEM_SECTION) { th_cfgitem_t *tmp = th_cfg_find_do(item->v.section, name, type); if (tmp != NULL) @@ -993,7 +993,7 @@ th_cfgitem_t *node; if (section != NULL) - node = th_cfg_find_do(cfg, section, ITEM_SECTION); + node = th_cfg_find_do(cfg, section, CFG_ITEM_SECTION); else node = cfg; diff -r 4744e64ffa3a -r 08bbfb5239fc th_config.h --- a/th_config.h Sat Jul 01 20:33:45 2023 +0300 +++ b/th_config.h Sat Jul 01 22:12:51 2023 +0300 @@ -20,20 +20,20 @@ // // Definitions // -enum ITEM_TYPE +enum CFG_ITEM_TYPE { - ITEM_SECTION = 1, - ITEM_COMMENT, + CFG_ITEM_SECTION = 1, + CFG_ITEM_COMMENT, - ITEM_STRING, - ITEM_INT, - ITEM_UINT, - ITEM_BOOL, - ITEM_FLOAT, - ITEM_HEX_TRIPLET, + CFG_ITEM_STRING, + CFG_ITEM_INT, + CFG_ITEM_UINT, + CFG_ITEM_BOOL, + CFG_ITEM_FLOAT, + CFG_ITEM_HEX_TRIPLET, - ITEM_STRING_LIST, - ITEM_HEX_TRIPLET_LIST + CFG_ITEM_STRING_LIST, + CFG_ITEM_HEX_TRIPLET_LIST };