long debug_get_num_option(const char *name, long dfault) { long result; const char *str; str = os_get_option(name); if(!str) result = dfault; else { long sign; char c; c = *str++; if(c == '-') { sign = -1; c = *str++; } else { sign = 1; } result = 0; while('0' <= c && c <= '9') { result = result*10 + (c - '0'); c = *str++; } result *= sign; } if (debug_get_option_should_print()) debug_printf("%s: %s = %li\n", __FUNCTION__, name, result); return result; }
boolean debug_get_bool_option(const char *name, boolean dfault) { const char *str = os_get_option(name); boolean result; if(str == NULL) result = dfault; else if(!util_strcmp(str, "n")) result = FALSE; else if(!util_strcmp(str, "no")) result = FALSE; else if(!util_strcmp(str, "0")) result = FALSE; else if(!util_strcmp(str, "f")) result = FALSE; else if(!util_strcmp(str, "F")) result = FALSE; else if(!util_strcmp(str, "false")) result = FALSE; else if(!util_strcmp(str, "FALSE")) result = FALSE; else result = TRUE; if (debug_get_option_should_print()) debug_printf("%s: %s = %s\n", __FUNCTION__, name, result ? "TRUE" : "FALSE"); return result; }
const char * debug_get_option(const char *name, const char *dfault) { const char *result; result = os_get_option(name); if(!result) result = dfault; if (debug_get_option_should_print()) debug_printf("%s: %s = %s\n", __FUNCTION__, name, result ? result : "(null)"); return result; }
uint64_t debug_get_flags_option(const char *name, const struct debug_named_value *flags, uint64_t dfault) { uint64_t result; const char *str; const struct debug_named_value *orig = flags; unsigned namealign = 0; str = os_get_option(name); if (!str) result = dfault; else if (!util_strcmp(str, "help")) { result = dfault; _debug_printf("%s: help for %s:\n", __FUNCTION__, name); for (; flags->name; ++flags) namealign = MAX2(namealign, strlen(flags->name)); for (flags = orig; flags->name; ++flags) _debug_printf("| %*s [0x%0*"PRIx64"]%s%s\n", namealign, flags->name, (int)sizeof(uint64_t)*CHAR_BIT/4, flags->value, flags->desc ? " " : "", flags->desc ? flags->desc : ""); } else { result = 0; while (flags->name) { if (str_has_option(str, flags->name)) result |= flags->value; ++flags; } } if (debug_get_option_should_print()) { if (str) { debug_printf("%s: %s = 0x%"PRIx64" (%s)\n", __FUNCTION__, name, result, str); } else { debug_printf("%s: %s = 0x%"PRIx64"\n", __FUNCTION__, name, result); } } return result; }
long debug_get_num_option(const char *name, long dfault) { long result; const char *str; str = os_get_option(name); if (!str) { result = dfault; } else { char *endptr; result = strtol(str, &endptr, 0); if (str == endptr) { /* Restore the default value when no digits were found. */ result = dfault; } } if (debug_get_option_should_print()) debug_printf("%s: %s = %li\n", __FUNCTION__, name, result); return result; }