X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=strutil.c;h=ea69a2af628b43a6be95c7977863336fbe5da3c1;hb=ebb781a69f1128fab5a9eedd39a548cba8ceccbb;hp=014c2c2ce16538dbacc1d72bd7276fb73f9c04c1;hpb=bf978d355345a7cc3ae7dc6199cc25952aaa182f;p=libsigrok.git diff --git a/strutil.c b/strutil.c index 014c2c2c..ea69a2af 100644 --- a/strutil.c +++ b/strutil.c @@ -175,7 +175,7 @@ SR_API char **sr_parse_triggerstring(struct sr_dev *dev, } if (probenum < 1 || probenum > max_probes) { - sr_err("strutil: Invalid probe (%d).\n", probenum); + sr_err("strutil: Invalid probe (%d).", probenum); error = TRUE; break; } @@ -184,7 +184,7 @@ SR_API char **sr_parse_triggerstring(struct sr_dev *dev, for (tc = ++trigger; *tc; tc++) { if (strchr(trigger_types, *tc) == NULL) { sr_err("strutil: Unsupported trigger " - "type '%c'.\n", *tc); + "type '%c'.", *tc); error = TRUE; break; } @@ -306,11 +306,41 @@ SR_API 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")) + if (!g_ascii_strncasecmp(boolstr, "true", 4) || + !g_ascii_strncasecmp(boolstr, "yes", 3) || + !g_ascii_strncasecmp(boolstr, "on", 2) || + !g_ascii_strncasecmp(boolstr, "1", 1)) return TRUE; return FALSE; } + +SR_API int sr_parse_period(const char *periodstr, struct sr_rational *r) +{ + char *s; + + r->p = strtoull(periodstr, &s, 10); + if (r->p == 0 && s == periodstr) + /* No digits found. */ + return SR_ERR_ARG; + + if (s && *s) { + while (*s == ' ') + s++; + if (!strcmp(s, "ns")) + r->q = 1000000000L; + else if (!strcmp(s, "us")) + r->q = 1000000; + else if (!strcmp(s, "ms")) + r->q = 1000; + else if (!strcmp(s, "s")) + r->q = 1; + else + /* Must have a time suffix. */ + return SR_ERR_ARG; + } + + return SR_OK; +} + +