Mercurial > hg > th-libs
diff th_config.c @ 453:efd33accdc81
Break backwards compatibility by renaming BOOL, TRUE and FALSE to lowercase.
Introduce optional but default use of stdbool.h.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 02 Jan 2018 22:56:03 +0200 |
parents | 1920a31927b2 |
children | 85fa3d333556 |
line wrap: on
line diff
--- a/th_config.c Wed Oct 25 22:32:07 2017 +0300 +++ b/th_config.c Tue Jan 02 22:56:03 2018 +0200 @@ -129,11 +129,11 @@ /* Add boolean type setting into given configuration */ int th_cfg_add_bool(th_cfgitem_t **cfg, const char *name, - BOOL *itemData, BOOL defValue) + bool *itemData, bool defValue) { th_cfgitem_t *node; - node = th_cfg_add(cfg, name, ITEM_BOOL, (void *) itemData); + node = th_cfg_add(cfg, name, ITEM_bool, (void *) itemData); if (node == NULL) return -1; @@ -199,7 +199,7 @@ PM_KEYSET, PM_STRING, PM_NUMERIC, - PM_BOOL, + PM_bool, PM_SECTION, PM_ARRAY }; @@ -213,13 +213,13 @@ char *tmpStr = NULL; size_t strPos; int c, parseMode, prevMode, nextMode, tmpCh; - BOOL isFound, isStart, isError, validError, fpSet; + bool isFound, isStart, isError, validError, fpSet; // Initialize values tmpCh = 0; strPos = 0; c = -1; - fpSet = isFound = isStart = isError = validError = FALSE; + fpSet = isFound = isStart = isError = validError = false; nextMode = prevMode = parseMode = PM_IDLE; if ((tmpStr = th_malloc(SET_MAX_BUF + 1)) == NULL) @@ -345,12 +345,12 @@ { // Find key from configuration tmpStr[strPos] = 0; - isFound = FALSE; + isFound = false; item = cfg; while (item != NULL && !isFound) { if (item->name != NULL && strcmp(item->name, tmpStr) == 0) - isFound = TRUE; + isFound = true; else item = (th_cfgitem_t *) item->node.next; } @@ -376,8 +376,8 @@ nextMode = PM_NUMERIC; break; - case ITEM_BOOL: - nextMode = PM_BOOL; + case ITEM_bool: + nextMode = PM_bool; break; case ITEM_SECTION: @@ -387,8 +387,8 @@ prevMode = parseMode; parseMode = PM_NEXT; - isStart = TRUE; - fpSet = FALSE; + isStart = true; + fpSet = false; strPos = 0; } else @@ -450,7 +450,7 @@ { case ITEM_STRING_LIST: c = -1; - isStart = TRUE; + isStart = true; prevMode = parseMode; parseMode = PM_NEXT; nextMode = PM_STRING; @@ -479,7 +479,7 @@ int res = th_cfg_read_sect(ctx, item->v.section, nesting + 1); c = -1; if (res > 0) - validError = TRUE; + validError = true; else if (res < 0) parseMode = PM_ERROR; else @@ -496,7 +496,7 @@ { // Start of string, get delimiter tmpCh = c; - isStart = FALSE; + isStart = false; strPos = 0; } else if (c == tmpCh) @@ -556,31 +556,31 @@ { VADDCH(c) else - isError = TRUE; + isError = true; } else if (isStart && item->type == ITEM_FLOAT && c == '.') { - fpSet = TRUE; + fpSet = true; VADDCH('0') else - isError = TRUE; + isError = true; VADDCH(c) else - isError = TRUE; + isError = true; } else if (item->type == ITEM_FLOAT && c == '.' && !fpSet) { - fpSet = TRUE; + fpSet = true; VADDCH(c) else - isError = TRUE; + isError = true; } else if (th_isdigit(c)) { VADDCH(c) else - isError = TRUE; + isError = true; } else if (VISEND(c)) { @@ -622,15 +622,15 @@ parseMode = PM_ERROR; } - isStart = FALSE; + isStart = false; c = -1; break; - case PM_BOOL: + case PM_bool: // Boolean parsing mode if (isStart) { - isStart = FALSE; + isStart = false; strPos = 0; } @@ -638,12 +638,12 @@ { VADDCH(c) else - isError = TRUE; + isError = true; } else if (VISEND(c)) { - BOOL tmpBool; + bool tmpBool; tmpStr[strPos] = 0; isError = !th_get_boolean(tmpStr, &tmpBool); if (!isError) @@ -781,7 +781,7 @@ return -5; break; - case ITEM_BOOL: + case ITEM_bool: if (thfprintf(ctx, "%s = %s\n", item->name, *(item->v.val_bool) ? "yes" : "no") < 0) return -6; @@ -830,17 +830,17 @@ * Name MUST be defined. Section can be NULL and type -1, * first matching item will be returned. */ -static th_cfgitem_t *th_cfg_find_do(th_cfgitem_t *item, BOOL *sect, const char *section, const char *name, const int type) +static th_cfgitem_t *th_cfg_find_do(th_cfgitem_t *item, bool *sect, const char *section, const char *name, const int type) { while (item != NULL) { - BOOL match = TRUE; + bool match = true; if (item->type == ITEM_SECTION) { // Check section name if set if (section != NULL && strcmp(section, item->name) == 0) - *sect = TRUE; + *sect = true; // Recurse to sub-section th_cfgitem_t *tmp = th_cfg_find_do(item->v.section, sect, section, name, type); @@ -850,11 +850,11 @@ else // Has type check been set, and does it match? if (type != -1 && item->type != type) - match = FALSE; + match = false; else // Check name (not section name, tho) if (strcmp(name, item->name) != 0) - match = FALSE; + match = false; // Do we have a match? if (*sect && match) @@ -867,10 +867,10 @@ th_cfgitem_t *th_cfg_find(th_cfgitem_t *cfg, const char *section, const char *name, const int type) { - BOOL sect = FALSE; + bool sect = false; if (section == NULL) - sect = TRUE; + sect = true; return th_cfg_find_do(cfg, §, section, name, type); }