diff options
author | Suren A. Chilingaryan <csa@suren.me> | 2015-10-13 01:59:17 +0200 |
---|---|---|
committer | Suren A. Chilingaryan <csa@suren.me> | 2015-10-13 01:59:17 +0200 |
commit | 2e9457b666a303fab83aa17e33624f39de9a1dd7 (patch) | |
tree | 7e1b46b4ca64a8eccb7122df33a32c48239d4c62 /pcilib/value.c | |
parent | 1200eca62c4c47617fa60033f9a0ee25bd26c431 (diff) | |
download | pcitool-2e9457b666a303fab83aa17e33624f39de9a1dd7.tar.gz pcitool-2e9457b666a303fab83aa17e33624f39de9a1dd7.tar.bz2 pcitool-2e9457b666a303fab83aa17e33624f39de9a1dd7.tar.xz pcitool-2e9457b666a303fab83aa17e33624f39de9a1dd7.zip |
Support writting register views
Diffstat (limited to 'pcilib/value.c')
-rw-r--r-- | pcilib/value.c | 16 |
1 files changed, 14 insertions, 2 deletions
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); |