#include <stdint.h>
#include <stdlib.h>
#include <string.h>
-#include <sigrok.h>
-#include <sigrok-internal.h>
+#include "sigrok.h"
+#include "sigrok-internal.h"
/**
* Convert a numeric samplerate value to its "natural" string representation.
* 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;
multiplier = SR_GHZ(1);
break;
default:
- val = 0;
- multiplier = -1;
+ done = TRUE;
+ s--;
}
s++;
}
if (multiplier > 0)
- val *= multiplier;
+ *size *= multiplier;
+
+ if (*s && strcasecmp(s, "Hz"))
+ return SR_ERR;
- return val;
+ return SR_OK;
}
/**
return time_msec;
}
+
+gboolean sr_parse_boolstring(const char *boolstr)
+{
+ if (!boolstr)
+ return FALSE;
+
+ if (!g_strcasecmp(boolstr, "true") ||
+ !g_strcasecmp(boolstr, "yes") ||
+ !g_strcasecmp(boolstr, "on") ||
+ !g_strcasecmp(boolstr, "1"))
+ return TRUE;
+
+ return FALSE;
+}