Mercurial > hg > th-libs
diff th_config.c @ 15:4adf7093060c
Sync.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 30 Oct 2010 17:48:40 +0300 |
parents | adcbcac66125 |
children | 0cea9c0cfce7 |
line wrap: on
line diff
--- a/th_config.c Sat Oct 30 17:47:41 2010 +0300 +++ b/th_config.c Sat Oct 30 17:48:40 2010 +0300 @@ -89,6 +89,21 @@ } +int th_config_add_hexvalue(cfgitem_t ** cfg, char * name, BOOL(*itemValidate) (cfgitem_t *), + int *itemData, int itemDef) +{ + cfgitem_t *node; + + node = th_config_add(cfg, name, ITEM_HEX_TRIPLET, itemValidate, (void *) itemData); + if (node == NULL) + return -1; + + *itemData = itemDef; + + return 0; +} + + /* Add unsigned integer type setting into give configuration */ int th_config_add_uint(cfgitem_t ** cfg, char * name, BOOL(*itemValidate) (cfgitem_t *), @@ -108,7 +123,7 @@ /* Add strint type setting into given configuration */ -int th_config_add_str(cfgitem_t ** cfg, char * name, BOOL(*itemValidate) (cfgitem_t *), +int th_config_add_string(cfgitem_t ** cfg, char * name, BOOL(*itemValidate) (cfgitem_t *), char ** itemData, char * itemDef) { cfgitem_t *node; @@ -328,6 +343,7 @@ if (isFound) { /* Okay, set next mode */ switch (item->type) { + case ITEM_HEX_TRIPLET: case ITEM_STRING: nextMode = PM_STRING; break; @@ -413,11 +429,14 @@ } else if (c == tmpCh) { /* End of string, set the value */ tmpStr[strPos] = 0; - th_pstrcpy((char **) item->data, tmpStr); - if (item->validate != NULL) { - if (!item->validate(item)) - validError = TRUE; + + if (item->type == ITEM_HEX_TRIPLET) { + } else if (item->type == ITEM_STRING) { + th_pstrcpy((char **) item->data, tmpStr); } + + if (item->validate != NULL && !item->validate(item)) + validError = TRUE; prevMode = parseMode; parseMode = PM_NORMAL; @@ -465,10 +484,8 @@ *((unsigned int *) item->data) = atol(tmpStr); break; } - if (item->validate != NULL) { - if (!item->validate(item)) - validError = TRUE; - } + if (item->validate != NULL && !item->validate(item)) + validError = TRUE; prevMode = parseMode; parseMode = PM_NORMAL; @@ -522,10 +539,9 @@ parseMode = PM_ERROR; } else { *((BOOL *) item->data) = tmpBool; - if (item->validate != NULL) { - if (!item->validate(item)) - validError = TRUE; - } + + if (item->validate != NULL && !item->validate(item)) + validError = TRUE; prevMode = parseMode; parseMode = PM_NORMAL; @@ -583,9 +599,14 @@ switch (item->type) { case ITEM_STRING: - if (fprintf(f->file, "%s = \"%s\"\n", - item->name, *((char **) item->data)) < 0) - return -3; + if (*((char **) item->data) == NULL) { + if (fprintf(f->file, "#%s = \"\"\n", item->name) < 0) + return -3; + } else { + if (fprintf(f->file, "%s = \"%s\"\n", + item->name, *((char **) item->data)) < 0) + return -3; + } break; case ITEM_INT: @@ -616,6 +637,13 @@ if (fprintf(f->file, "} # End of '%s'\n\n", item->name) < 0) return -8; } + break; + + case ITEM_HEX_TRIPLET: + if (fprintf(f->file, "%s = \"%06x\"\n", + item->name, *((int *) item->data)) < 0) + return -6; + break; } } item = item->next; @@ -641,3 +669,5 @@ return th_config_write_sect(&f, cfg, 0); } + +