#include <stdint.h>
#include <string.h>
#include <glib.h>
-#include <sigrok.h>
+#include <libsigrok/libsigrok.h>
#include "sigrok-cli.h"
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;
}
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;
}
} 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;
}
return dev;
}
+
+char *strcanon(const 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(const char *str1, const 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;
+}