]> sigrok.org Git - sigrok-cli.git/commitdiff
parsers: optional case insensitive channel name lookup
authorGerhard Sittig <redacted>
Fri, 7 Apr 2023 16:34:11 +0000 (18:34 +0200)
committerGerhard Sittig <redacted>
Sun, 9 Apr 2023 22:18:50 +0000 (00:18 +0200)
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.

decode.c
parsers.c
sigrok-cli.h

index 1a0747c9023255ee5d0aed89cace6d983ae90d1d..fe5b968fdc0b6010a5b7bbb163b6e80f8fbf83ad 100644 (file)
--- 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);
index 59a7a91830220f573d7dd9abb85789fc0b038884..2aacefb089f184eeb18dfb8d5be8855dc5623811 100644 (file)
--- a/parsers.c
+++ b/parsers.c
@@ -25,7 +25,8 @@
 #include <glib.h>
 #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);
index 684aed99a8bd302da3ae8d88f6ff9e9be94ee867..b33b076bd1f82824d284395ed7ca4267fd3b516c 100644 (file)
@@ -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);