/alps/pcitool

To get this branch, use:
bzr branch http://darksoft.org/webbzr/alps/pcitool

« back to all changes in this revision

Viewing changes to pcilib/value.c

  • Committer: Suren A. Chilingaryan
  • Date: 2015-10-12 23:59:17 UTC
  • Revision ID: csa@suren.me-20151012235917-s5oi62kmu8khjl0t
Support writting register views

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
#include "value.h"
9
9
#include "error.h"
10
10
#include "unit.h"
 
11
#include "tools.h"
11
12
 
12
13
void pcilib_clean_value(pcilib_t *ctx, pcilib_value_t *val) {
13
14
    if (!val) return;
235
236
     case PCILIB_TYPE_LONG:
236
237
        switch (val->type) {
237
238
         case PCILIB_TYPE_STRING:
238
 
            if (sscanf(val->sval, "%li", &val->ival) != 1) {
 
239
            if (pcilib_isnumber(val->sval)) {
 
240
                if (sscanf(val->sval, "%li", &val->ival) != 1) {
 
241
                    pcilib_warning("Can't convert string (%s) to int", val->sval);
 
242
                    return PCILIB_ERROR_INVALID_DATA;
 
243
                }
 
244
                val->format = NULL;
 
245
            } else if (pcilib_isxnumber(val->sval)) {
 
246
                if (sscanf(val->sval, "%lx", &val->ival) != 1) {
 
247
                    pcilib_warning("Can't convert string (%s) to int", val->sval);
 
248
                    return PCILIB_ERROR_INVALID_DATA;
 
249
                }
 
250
                val->format = "0x%lx";
 
251
            } else {
239
252
                pcilib_warning("Can't convert string (%s) to int", val->sval);
240
253
                return PCILIB_ERROR_INVALID_DATA;
241
254
            }
242
 
            val->format = NULL;
243
255
            break;
244
256
         case PCILIB_TYPE_DOUBLE:
245
257
            val->ival = round(val->fval);