From: Gerhard Sittig Date: Fri, 7 Apr 2023 16:34:11 +0000 (+0200) Subject: parsers: optional case insensitive channel name lookup X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=a2dbd8488c1d18c39d55ebbf6e4c3c83db0296ba;p=sigrok-cli.git parsers: optional case insensitive channel name lookup Prepare the parsers.c:find_channel() routine to optionally lookup channels by case insensitive name matches. Stick with case sensitive comparison in all existing call sites. --- diff --git a/decode.c b/decode.c index 1a0747c..fe5b968 100644 --- a/decode.c +++ b/decode.c @@ -278,7 +278,7 @@ static void map_pd_inst_channels(void *key, void *value, void *user_data) (char *)channel_id); continue; } - ch = find_channel(channel_list, channel_target); + ch = find_channel(channel_list, channel_target, TRUE); if (!ch) { g_printerr("cli: No channel with name \"%s\" found.\n", (char *)channel_target); diff --git a/parsers.c b/parsers.c index 59a7a91..2aacefb 100644 --- a/parsers.c +++ b/parsers.c @@ -25,7 +25,8 @@ #include #include "sigrok-cli.h" -struct sr_channel *find_channel(GSList *channellist, const char *channelname) +struct sr_channel *find_channel(GSList *channellist, const char *channelname, + gboolean exact_case) { struct sr_channel *ch; GSList *l; @@ -33,8 +34,13 @@ struct sr_channel *find_channel(GSList *channellist, const char *channelname) ch = NULL; for (l = channellist; l; l = l->next) { ch = l->data; - if (!strcmp(ch->name, channelname)) - break; + if (exact_case) { + if (strcmp(ch->name, channelname) == 0) + break; + } else { + if (g_ascii_strcasecmp(ch->name, channelname) == 0) + break; + } } ch = l ? l->data : NULL; @@ -105,7 +111,7 @@ GSList *parse_channelstring(struct sr_dev_inst *sdi, const char *channelstring) ret = SR_ERR; break; } - ch = find_channel(channels, str); + ch = find_channel(channels, str, TRUE); if (!ch) { g_critical("unknown channel '%d'.", b); ret = SR_ERR; @@ -130,7 +136,7 @@ range_fail: break; } - ch = find_channel(channels, names[0]); + ch = find_channel(channels, names[0], TRUE); if (!ch) { g_critical("unknown channel '%s'.", names[0]); g_strfreev(names); diff --git a/sigrok-cli.h b/sigrok-cli.h index 684aed9..b33b076 100644 --- a/sigrok-cli.h +++ b/sigrok-cli.h @@ -103,7 +103,8 @@ void map_pd_channels(struct sr_dev_inst *sdi); #endif /* parsers.c */ -struct sr_channel *find_channel(GSList *channellist, const char *channelname); +struct sr_channel *find_channel(GSList *channellist, const char *channelname, + gboolean exact_case); GSList *parse_channelstring(struct sr_dev_inst *sdi, const char *channelstring); int parse_triggerstring(const struct sr_dev_inst *sdi, const char *s, struct sr_trigger **trigger);