From 7fe1437483bb145c70589652427d0520c1034a46 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Sat, 7 Aug 2010 21:42:24 +0000 Subject: [PATCH] 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 --- urjtag/ChangeLog | 4 ++++ urjtag/src/global/params.c | 21 ++++++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/urjtag/ChangeLog b/urjtag/ChangeLog index 0b7ab970..3346ae38 100644 --- a/urjtag/ChangeLog +++ b/urjtag/ChangeLog @@ -1,3 +1,7 @@ +2010-08-07 Mike Frysinger + + * src/global/params.c (parse_param_lu): Accept unsigned values in hex format. + 2010-07-31 Mike Frysinger * src/bus/buses.c, src/flash/jedec.c, src/tap/cable.c: Convert to ARRAY_SIZE. diff --git a/urjtag/src/global/params.c b/urjtag/src/global/params.c index 733baa75..6f9d9de9 100644 --- a/urjtag/src/global/params.c +++ b/urjtag/src/global/params.c @@ -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; }