fix CLI size string specification

accept "hz" as optional qualifier but nothing else
properly return an error instead of quietly returning zero size
This commit is contained in:
Bert Vermeulen 2011-11-27 19:31:25 +01:00
parent cb93f8a927
commit f64c14141b
3 changed files with 16 additions and 13 deletions

View File

@ -107,7 +107,7 @@ int sr_session_load(const char *filename)
device->plugin->set_configuration(devcnt, SR_HWCAP_CAPTUREFILE, val);
g_ptr_array_add(capturefiles, val);
} else if (!strcmp(keys[j], "samplerate")) {
tmp_u64 = sr_parse_sizestring(val);
sr_parse_sizestring(val, &tmp_u64);
device->plugin->set_configuration(devcnt, SR_HWCAP_SAMPLERATE, &tmp_u64);
} else if (!strcmp(keys[j], "unitsize")) {
tmp_u64 = strtoull(val, NULL, 10);

View File

@ -142,7 +142,7 @@ char *sr_samplerate_string(uint64_t samplerate);
char *sr_period_string(uint64_t frequency);
char **sr_parse_triggerstring(struct sr_device *device,
const char *triggerstring);
uint64_t sr_parse_sizestring(const char *sizestring);
int sr_parse_sizestring(const char *sizestring, uint64_t *size);
uint64_t sr_parse_timestring(const char *timestring);
gboolean sr_parse_boolstring(const char *boolstring);

View File

@ -186,19 +186,19 @@ char **sr_parse_triggerstring(struct sr_device *device,
* Spaces (but not other whitespace) between value and suffix are allowed.
*
* @param sizestring A string containing a (decimal) size value.
* @return The string's size value as uint64_t.
* @param size Pointer to uint64_t which will contain the string's size value.
* @return SR_OK or error code
*
* TODO: Error handling.
*/
uint64_t sr_parse_sizestring(const char *sizestring)
int sr_parse_sizestring(const char *sizestring, uint64_t *size)
{
int multiplier;
uint64_t val;
int multiplier, done;
char *s;
val = strtoull(sizestring, &s, 10);
*size = strtoull(sizestring, &s, 10);
multiplier = 0;
while (s && *s && multiplier == 0) {
done = FALSE;
while (s && *s && multiplier == 0 && !done) {
switch (*s) {
case ' ':
break;
@ -215,15 +215,18 @@ uint64_t sr_parse_sizestring(const char *sizestring)
multiplier = SR_GHZ(1);
break;
default:
val = 0;
multiplier = -1;
done = TRUE;
s--;
}
s++;
}
if (multiplier > 0)
val *= multiplier;
*size *= multiplier;
return val;
if (*s && strcasecmp(s, "Hz"))
return SR_ERR;
return SR_OK;
}
/**