Skip to content

Commit

Permalink
Rework match_from_string
Browse files Browse the repository at this point in the history
No functional changes, this just preps the way for more optional
elements in the match string.
  • Loading branch information
whot committed Mar 18, 2024
1 parent 280e3dc commit 2134c56
Showing 1 changed file with 29 additions and 15 deletions.
44 changes: 29 additions & 15 deletions libwacom/libwacom-database.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,23 +163,37 @@ make_match_string (const char *name, WacomBusType bus, int vendor_id, int produc
}

static gboolean
match_from_string(const char *str, WacomBusType *bus, int *vendor_id, int *product_id, char **name)
match_from_string(const char *str_in, WacomBusType *bus, int *vendor_id, int *product_id, char **name)
{
int rc = 1, len = 0;
char busstr[64];

rc = sscanf(str, "%63[^|]|%x|%x|%n", busstr, vendor_id, product_id, &len);
if (len > 0) {
/* Grumble grumble scanf handling of %n */
*name = g_strdup(str+len);
} else if (rc == 3) {
*name = NULL;
} else {
return FALSE;
}
*bus = bus_from_str (busstr);
gboolean rc = FALSE;
guint64 num;
char *str = g_strdup(str_in);
char **components = NULL;

return TRUE;
if (g_str_has_suffix(str_in, ";"))
str[strlen(str) - 1] = '\0';

components = g_strsplit(str, "|", 16);
if (!components[0] || !components[1] || !components[2])
goto out;

*bus = bus_from_str (components[0]);
if (!g_ascii_string_to_unsigned(components[1], 16, 0, 0xffff, &num, NULL))
goto out;
*vendor_id = (int)num;

if (!g_ascii_string_to_unsigned(components[2], 16, 0, 0xffff, &num, NULL))
goto out;
*product_id = (int)num;

if (components[3])
*name = g_strdup(components[3]);

rc = TRUE;
out:
free(str);
g_strfreev(components);
return rc;
}

static WacomMatch *
Expand Down

0 comments on commit 2134c56

Please sign in to comment.