X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=strutil.c;h=9ad83d7f7804433cd0ec595aa901520be0a0d919;hb=6ac0db19f36ada4cfccf19bbd48ebdb4665bc9ff;hp=26296cea21419aee00f784e18fbefcf02b2a55be;hpb=79afc8cac4912f5e1025c608a10b05506a191be9;p=libsigrok.git diff --git a/strutil.c b/strutil.c index 26296cea..9ad83d7f 100644 --- a/strutil.c +++ b/strutil.c @@ -21,8 +21,8 @@ #include #include #include -#include "sigrok.h" -#include "sigrok-internal.h" +#include "libsigrok.h" +#include "libsigrok-internal.h" /** * Convert a numeric samplerate value to its "natural" string representation. @@ -170,16 +170,17 @@ SR_API char *sr_voltage_string(struct sr_rational *voltage) * contain the respective trigger type which is requested for the * respective probe (e.g. "r", "c", and so on). */ -SR_API char **sr_parse_triggerstring(struct sr_dev *dev, +SR_API char **sr_parse_triggerstring(const struct sr_dev_inst *sdi, const char *triggerstring) { GSList *l; struct sr_probe *probe; int max_probes, probenum, i; - char **tokens, **triggerlist, *trigger, *tc, *trigger_types; + char **tokens, **triggerlist, *trigger, *tc; + const char *trigger_types; gboolean error; - max_probes = g_slist_length(dev->probes); + max_probes = g_slist_length(sdi->probes); error = FALSE; if (!(triggerlist = g_try_malloc0(max_probes * sizeof(char *)))) { @@ -187,20 +188,18 @@ SR_API char **sr_parse_triggerstring(struct sr_dev *dev, return NULL; } - tokens = g_strsplit(triggerstring, ",", max_probes); - - trigger_types = dev->driver->dev_info_get(0, SR_DI_TRIGGER_TYPES); - if (!trigger_types) { - sr_err("strutil: %s: Device doesn't support any triggers.", - __func__); + if (sdi->driver->info_get(SR_DI_TRIGGER_TYPES, + (const void **)&trigger_types, sdi) != SR_OK) { + sr_err("strutil: %s: Device doesn't support any triggers.", __func__); return NULL; } + tokens = g_strsplit(triggerstring, ",", max_probes); for (i = 0; tokens[i]; i++) { if (tokens[i][0] < '0' || tokens[i][0] > '9') { /* Named probe */ probenum = 0; - for (l = dev->probes; l; l = l->next) { + for (l = sdi->probes; l; l = l->next) { probe = (struct sr_probe *)l->data; if (probe->enabled && !strncmp(probe->name, tokens[i], @@ -213,7 +212,7 @@ SR_API char **sr_parse_triggerstring(struct sr_dev *dev, probenum = strtol(tokens[i], NULL, 10); } - if (probenum < 1 || probenum > max_probes) { + if (probenum < 0 || probenum >= max_probes) { sr_err("strutil: Invalid probe (%d).", probenum); error = TRUE; break; @@ -229,7 +228,7 @@ SR_API char **sr_parse_triggerstring(struct sr_dev *dev, } } if (!error) - triggerlist[probenum - 1] = g_strdup(trigger); + triggerlist[probenum] = g_strdup(trigger); } } g_strfreev(tokens);