]> sigrok.org Git - sigrok-cli.git/blobdiff - parsers.c
cli: option to specify which annotation(s) to show
[sigrok-cli.git] / parsers.c
index 47f11a0bee454ecbbd139e81161bae273a14a18a..707bcdd5a7e67e5b93c20aec127704bd8a76eef1 100644 (file)
--- a/parsers.c
+++ b/parsers.c
@@ -44,8 +44,7 @@ char **parse_probestring(int max_probes, const char *probestring)
                        range = g_strsplit(tokens[i], "-", 2);
                        if (!range[0] || !range[1] || range[2]) {
                                /* Need exactly two arguments. */
-                               printf("Invalid probe syntax '%s'.\n",
-                                      tokens[i]);
+                               g_critical("Invalid probe syntax '%s'.", tokens[i]);
                                error = TRUE;
                                break;
                        }
@@ -53,8 +52,7 @@ char **parse_probestring(int max_probes, const char *probestring)
                        b = strtol(range[0], NULL, 10);
                        e = strtol(range[1], NULL, 10);
                        if (b < 1 || e > max_probes || b >= e) {
-                               printf("Invalid probe range '%s'.\n",
-                                      tokens[i]);
+                               g_critical("Invalid probe range '%s'.", tokens[i]);
                                error = TRUE;
                                break;
                        }
@@ -67,7 +65,7 @@ char **parse_probestring(int max_probes, const char *probestring)
                } else {
                        tmp = strtol(tokens[i], NULL, 10);
                        if (tmp < 1 || tmp > max_probes) {
-                               printf("Invalid probe %d.\n", tmp);
+                               g_critical("Invalid probe %d.", tmp);
                                error = TRUE;
                                break;
                        }
@@ -164,11 +162,11 @@ struct sr_dev *parse_devstring(const char *devstring)
                 * no need to let them all scan
                 */
                dev = NULL;
-               drivers = sr_hw_list();
+               drivers = sr_driver_list();
                for (i = 0; drivers[i]; i++) {
                        if (strcmp(drivers[i]->name, devstring))
                                continue;
-                       num_devs = sr_hw_init(drivers[i]);
+                       num_devs = sr_driver_init(drivers[i]);
                        if (num_devs == 1) {
                                devs = sr_dev_list();
                                dev = devs->data;
@@ -183,3 +181,36 @@ struct sr_dev *parse_devstring(const char *devstring)
 
        return dev;
 }
+
+char *strcanon(char *str)
+{
+       int p0, p1;
+       char *s;
+
+       /* Returns newly allocated string. */
+       s = g_ascii_strdown(str, -1);
+       for (p0 = p1 = 0; str[p0]; p0++) {
+               if ((s[p0] >= 'a' && s[p0] <= 'z')
+                               || (s[p0] >= '0' && s[p0] <= '9'))
+                       s[p1++] = s[p0];
+       }
+       s[p1] = '\0';
+
+       return s;
+}
+
+
+int canon_cmp(char *str1, char *str2)
+{
+       int ret;
+       char *s1, *s2;
+
+       s1 = strcanon(str1);
+       s2 = strcanon(str2);
+       ret = g_ascii_strcasecmp(s1, s2);
+       g_free(s2);
+       g_free(s1);
+
+       return ret;
+}
+