Mercurial > hg > th-libs
changeset 168:a2cd862315c5
Use th_get_boolean() in configuration parser.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 18 Feb 2015 21:13:52 +0200 |
parents | 7638fa9d191f |
children | a06a87b771ce 8e69e07e5aac |
files | th_config.c |
diffstat | 1 files changed, 21 insertions(+), 31 deletions(-) [+] |
line wrap: on
line diff
--- a/th_config.c Wed Feb 18 21:13:44 2015 +0200 +++ b/th_config.c Wed Feb 18 21:13:52 2015 +0200 @@ -605,47 +605,37 @@ // Boolean parsing mode if (isStart) { - tmpCh = c; isStart = FALSE; + strPos = 0; } - else if (VISEND(c)) - { - BOOL tmpBool = FALSE; - - // End of boolean parsing - switch (th_toupper(tmpCh)) - { - case 'Y': - case 'T': - case '1': - tmpBool = TRUE; - break; - case 'N': - case 'F': - case '0': - tmpBool = FALSE; - break; - - default: - isError = TRUE; - } - - if (isError) - { - th_ioctx_error(ctx, -1, - "Invalid boolean value for '%s'.\n", - item->name); - parseMode = PM_ERROR; - } + if (th_isalnum(c)) + { + VADDCH(c) else + isError = TRUE; + } + else + if (VISEND(c)) + { + BOOL tmpBool; + tmpStr[strPos] = 0; + isError = !th_get_boolean(tmpStr, &tmpBool); + if (!isError) { *(item->v.val_bool) = tmpBool; - prevMode = parseMode; parseMode = PM_IDLE; } } + + if (isError) + { + th_ioctx_error(ctx, -1, + "Invalid boolean value for '%s'.\n", + item->name); + parseMode = PM_ERROR; + } c = -1; break; }