From 2e9457b666a303fab83aa17e33624f39de9a1dd7 Mon Sep 17 00:00:00 2001 From: "Suren A. Chilingaryan" Date: Tue, 13 Oct 2015 01:59:17 +0200 Subject: Support writting register views --- pcilib/value.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'pcilib/value.c') diff --git a/pcilib/value.c b/pcilib/value.c index 1a8cc45..42e7993 100644 --- a/pcilib/value.c +++ b/pcilib/value.c @@ -8,6 +8,7 @@ #include "value.h" #include "error.h" #include "unit.h" +#include "tools.h" void pcilib_clean_value(pcilib_t *ctx, pcilib_value_t *val) { if (!val) return; @@ -235,11 +236,22 @@ int pcilib_convert_value_type(pcilib_t *ctx, pcilib_value_t *val, pcilib_value_t case PCILIB_TYPE_LONG: switch (val->type) { case PCILIB_TYPE_STRING: - if (sscanf(val->sval, "%li", &val->ival) != 1) { + if (pcilib_isnumber(val->sval)) { + if (sscanf(val->sval, "%li", &val->ival) != 1) { + pcilib_warning("Can't convert string (%s) to int", val->sval); + return PCILIB_ERROR_INVALID_DATA; + } + val->format = NULL; + } else if (pcilib_isxnumber(val->sval)) { + if (sscanf(val->sval, "%lx", &val->ival) != 1) { + pcilib_warning("Can't convert string (%s) to int", val->sval); + return PCILIB_ERROR_INVALID_DATA; + } + val->format = "0x%lx"; + } else { pcilib_warning("Can't convert string (%s) to int", val->sval); return PCILIB_ERROR_INVALID_DATA; } - val->format = NULL; break; case PCILIB_TYPE_DOUBLE: val->ival = round(val->fval); -- cgit v1.2.3