partially restore support for hex value parsing (requires leading "0x")

git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@1819 b68d4a1b-bc3d-0410-92ed-d4ac073336b7
master
Mike Frysinger 14 years ago
parent f8e53c6e0a
commit 7fe1437483

@ -1,3 +1,7 @@
2010-08-07 Mike Frysinger <vapier@gentoo.org>
* src/global/params.c (parse_param_lu): Accept unsigned values in hex format.
2010-07-31 Mike Frysinger <vapier@gentoo.org>
* src/bus/buses.c, src/flash/jedec.c, src/tap/cable.c: Convert to ARRAY_SIZE.

@ -180,10 +180,25 @@ urj_param_push_bool (const urj_param_t ***bp, int key, int val)
static int
parse_param_lu(const char *eq, long unsigned *lu)
{
if (sscanf(eq + 1, "%lu", lu) == 1)
return URJ_STATUS_OK;
eq += 1;
/* Handle hex values as well as decimal. While the C library will take
* care of this for us if we used the 'i' conversion modifier, that takes
* us into the signed/unsigned world. Unfortunately, the 'u' conversion
* modifier doesn't handle hex values transparently. So do it ourselves.
*/
if (strncmp(eq, "0x", 2))
{
if (sscanf(eq, "%lu", lu) == 1)
return URJ_STATUS_OK;
}
else
{
if (sscanf(eq, "%lx", lu) == 1)
return URJ_STATUS_OK;
}
urj_error_set (URJ_ERROR_SYNTAX, "need unsigned int, not '%s'", eq + 1);
urj_error_set (URJ_ERROR_SYNTAX, "need unsigned int, not '%s'", eq);
return URJ_STATUS_FAIL;
}

Loading…
Cancel
Save