IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 13521


Ignore:
Timestamp:
May 24, 2007, 6:15:46 PM (19 years ago)
Author:
Paul Price
Message:

Change to allow integers to be specified as hexadecimal. This also
allows error checking (strtol instead of atoi).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/types/psArguments.c

    r13356 r13521  
    77 *  @author David Robbins, MHPCC
    88 *
    9  *  @version $Revision: 1.25 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2007-05-11 23:37:37 $
     9 *  @version $Revision: 1.26 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2007-05-25 04:15:46 $
    1111 *
    1212 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    132132
    133133
    134 #define ARG_READ_CASE(TYPE,FUNC) \
    135 case PS_TYPE_##TYPE: \
    136 item->data.TYPE = FUNC(argv[argnum]); \
    137 return psArgumentRemove(argnum, argc, argv);
     134#define ARG_READ_CASE_INT(TYPE,FUNC) \
     135case PS_TYPE_##TYPE: { \
     136    char *end; \
     137    item->data.TYPE = FUNC(argv[argnum], &end, 0); \
     138    if (end == argv[argnum]) { \
     139        psError(PS_ERR_IO, true, "Unable to read argument value for %s", item->name); \
     140        return false; \
     141    } \
     142    return psArgumentRemove(argnum, argc, argv); \
     143}
     144
     145#define ARG_READ_CASE_FLOAT(TYPE,FUNC) \
     146case PS_TYPE_##TYPE: { \
     147    char *end; \
     148    item->data.TYPE = FUNC(argv[argnum], &end); \
     149    if (end == argv[argnum]) { \
     150        psError(PS_ERR_IO, true, "Unable to read argument value for %s", item->name); \
     151        return false; \
     152    } \
     153    return psArgumentRemove(argnum, argc, argv); \
     154}
    138155
    139156static bool argumentRead(psMetadataItem *item, // Item to read into
     
    145162    switch(item->type)
    146163    {
    147         ARG_READ_CASE(U8,atoi);
    148         ARG_READ_CASE(U16,atoi);
    149         ARG_READ_CASE(U32,atoi);
    150         ARG_READ_CASE(U64,atoi);
    151         ARG_READ_CASE(S8,atoi);
    152         ARG_READ_CASE(S16,atoi);
    153         ARG_READ_CASE(S32,atoi);
    154         ARG_READ_CASE(S64,atoi);
    155         ARG_READ_CASE(F32,atof);
    156         ARG_READ_CASE(F64,atof);
     164        ARG_READ_CASE_INT(U8,strtol);
     165        ARG_READ_CASE_INT(U16,strtol);
     166        ARG_READ_CASE_INT(U32,strtol);
     167        ARG_READ_CASE_INT(U64,strtoll);
     168        ARG_READ_CASE_INT(S8,strtol);
     169        ARG_READ_CASE_INT(S16,strtol);
     170        ARG_READ_CASE_INT(S32,strtol);
     171        ARG_READ_CASE_INT(S64,strtoll);
     172        ARG_READ_CASE_FLOAT(F32,strtof);
     173        ARG_READ_CASE_FLOAT(F64,strtod);
    157174    case PS_DATA_BOOL:
    158175        // Turn option on; no optional argument to remove
Note: See TracChangeset for help on using the changeset viewer.