X-Git-Url: https://sigrok.org/gitweb/?p=sigrok-cli.git;a=blobdiff_plain;f=parsers.c;h=d575dce076c83660a0107d53884b4cade36b8b80;hp=59b1f6823aaa1f52b9243642f2e49c550329de06;hb=426d0cdaa91051c30d45055b3c10662fd392ea5a;hpb=66149c2013c0009c226770e5679ae63fd834bb78 diff --git a/parsers.c b/parsers.c index 59b1f68..d575dce 100644 --- a/parsers.c +++ b/parsers.c @@ -1,5 +1,5 @@ /* - * This file is part of the sigrok project. + * This file is part of the sigrok-cli project. * * Copyright (C) 2011 Bert Vermeulen * @@ -17,13 +17,12 @@ * along with this program. If not, see . */ +#include "sigrok-cli.h" #include #include #include #include #include -#include -#include "sigrok-cli.h" struct sr_probe *find_probe(GSList *probelist, const char *probename) { @@ -49,8 +48,8 @@ GSList *parse_probestring(struct sr_dev_inst *sdi, const char *probestring) char **tokens, **range, **names, *eptr, str[8]; if (!probestring || !probestring[0]) - /* All probes are enabled by default by the driver. */ - return NULL; + /* Use all probes by default. */ + return g_slist_copy(sdi->probes); ret = SR_OK; range = NULL; @@ -73,25 +72,25 @@ GSList *parse_probestring(struct sr_dev_inst *sdi, const char *probestring) /* Need exactly two arguments. */ g_critical("Invalid probe syntax '%s'.", tokens[i]); ret = SR_ERR; - break; + goto range_fail; } b = strtol(range[0], &eptr, 10); if (eptr == range[0] || *eptr != '\0') { g_critical("Invalid probe '%s'.", range[0]); ret = SR_ERR; - break; + goto range_fail; } e = strtol(range[1], NULL, 10); if (eptr == range[1] || *eptr != '\0') { g_critical("Invalid probe '%s'.", range[1]); ret = SR_ERR; - break; + goto range_fail; } if (b < 0 || b >= e) { g_critical("Invalid probe range '%s'.", tokens[i]); ret = SR_ERR; - break; + goto range_fail; } while (b <= e) { @@ -110,6 +109,10 @@ GSList *parse_probestring(struct sr_dev_inst *sdi, const char *probestring) probelist = g_slist_append(probelist, probe); b++; } +range_fail: + if (range) + g_strfreev(range); + if (ret != SR_OK) break; } else { @@ -117,6 +120,7 @@ GSList *parse_probestring(struct sr_dev_inst *sdi, const char *probestring) if (!names[0] || (names[1] && names[2])) { /* Need one or two arguments. */ g_critical("Invalid probe '%s'.", tokens[i]); + g_strfreev(names); ret = SR_ERR; break; } @@ -124,6 +128,7 @@ GSList *parse_probestring(struct sr_dev_inst *sdi, const char *probestring) probe = find_probe(sdi->probes, names[0]); if (!probe) { g_critical("unknown probe '%s'.", names[0]); + g_strfreev(names); ret = SR_ERR; break; } @@ -133,13 +138,10 @@ GSList *parse_probestring(struct sr_dev_inst *sdi, const char *probestring) probe->name = g_strdup(names[1]); } probelist = g_slist_append(probelist, probe); + + g_strfreev(names); } } - if (range) - g_strfreev(range); - - if (names) - g_strfreev(names); if (ret != SR_OK) { g_slist_free(probelist); @@ -181,7 +183,7 @@ GHashTable *parse_generic_arg(const char *arg, gboolean sep_first) return hash; } -char *strcanon(const char *str) +static char *strcanon(const char *str) { int p0, p1; char *s;