Nick: heijligen E-mail: none Board: parse_pparam Contents: #include #include #include /* * 0 on success * -1 on name not found */ static int extract_programmer_param_string(const char *const name, char **string) { char* _string = extract_programmer_param_str(name); if (_string) return -1; *string = _string; return 0; } /* * 0 on success * -1 on name not found * -2 format error */ static int extract_programmer_param_frequency(const char *const name, unsigned long *frequency) { unsigned long _frequency; char *param_str; char *endptr; if (extract_programmer_param_string(name, ¶m_str)) return -1; errno = 0; _frequency = strtoul(param_str, &endptr, 10); if (errno !=0) { free(param_str); return -2; } if(*endptr != '\0') { /* nothing to do */ } else if (!strcasecmp(endptr, "hz")) { /* nothing to do */ } else if (!strcasecmp(endptr, "khz")) { _frequency *= 1000; } else if (!strcasecmp(endptr, "mhz")) { _frequency *= 1000000; } else if (!strcasecmp(endptr, "ghz")) { _frequency *= 1000000000; } else { free (param_str); return -2; } free(param_str); *frequency = _frequency; return 0; } /* * 0 on success * -1 on name not found * -2 format error */ static int extract_programmer_param_long(const char *const name, long *value) { long _value; char *param_str; char *endptr; if (extract_programmer_param_string(name, ¶m_str)) return -1; errno = 0; _value = strtol(param_str, &endptr, 10); if (errno || *endptr != '\0') { free(param_str); return -2; } free(param_str); *value = _value; return 0; }