446 * @param *arg the string to be converted |
446 * @param *arg the string to be converted |
447 * @return Return true on success or false on failure |
447 * @return Return true on success or false on failure |
448 */ |
448 */ |
449 bool GetArgumentInteger(uint32 *value, const char *arg) |
449 bool GetArgumentInteger(uint32 *value, const char *arg) |
450 { |
450 { |
451 int result = sscanf(arg, "%u", value); |
451 char *endptr; |
452 |
452 |
453 /* Hexadecimal numbers start with 0x, so at least the first number has been parsed */ |
453 if (strcmp(arg, "on") == 0 || strcmp(arg, "true") == 0) { |
454 if (result == 1 && arg[0] == '0' && (arg[1] == 'x' || arg[1] == 'X')) |
454 *value = 1; |
455 result = sscanf(arg, "%x", value); |
455 return true; |
456 |
456 } |
457 if (result == 0 && (strcmp(arg, "on") == 0 || strcmp(arg, "true") == 0 )) {*value = 1; result = 1;} |
457 if (strcmp(arg, "off") == 0 || strcmp(arg, "false") == 0) { |
458 |
458 *value = 0; |
459 if (result == 0 && (strcmp(arg, "off") == 0 || strcmp(arg, "false") == 0)) {*value = 0; result = 1;} |
459 return true; |
460 |
460 } |
461 return !!result; |
461 |
|
462 *value = strtoul(arg, &endptr, 0); |
|
463 return (arg == endptr) ? false : true; |
462 } |
464 } |
463 |
465 |
464 /** |
466 /** |
465 * Perhaps ugly macro, but this saves us the trouble of writing the same function |
467 * Perhaps ugly macro, but this saves us the trouble of writing the same function |
466 * three types, just with different variables. Yes, templates would be handy. It was |
468 * three types, just with different variables. Yes, templates would be handy. It was |