summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2016-07-07 16:15:39 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2016-07-07 20:05:05 +1000
commita5a4232800f5ccb8308b03ce458924ec71cb334d (patch)
treebd0d5a826b0726bc22ab2c6bd5f59733727d7dce
parente206859b8342be6e9502eabe8b0fc33043cc30d9 (diff)
downloadlibwacom-a5a4232800f5ccb8308b03ce458924ec71cb334d.tar.gz
Move printing and freeing a WacomMatch into helper functions
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
-rw-r--r--libwacom/libwacom.c59
-rw-r--r--libwacom/libwacomint.h1
2 files changed, 34 insertions, 26 deletions
diff --git a/libwacom/libwacom.c b/libwacom/libwacom.c
index d20b66c..b093021 100644
--- a/libwacom/libwacom.c
+++ b/libwacom/libwacom.c
@@ -696,13 +696,34 @@ static void print_integrated_flags_for_device (int fd, const WacomDevice *device
dprintf(fd, "\n");
}
+static void print_match(int fd, const WacomMatch *match)
+{
+ const char *name = libwacom_match_get_name(match);
+ WacomBusType type = libwacom_match_get_bustype(match);
+ int vendor = libwacom_match_get_vendor_id(match);
+ int product = libwacom_match_get_product_id(match);
+ const char *bus_name;
+
+ switch(type) {
+ case WBUSTYPE_BLUETOOTH: bus_name = "bluetooth"; break;
+ case WBUSTYPE_USB: bus_name = "usb"; break;
+ case WBUSTYPE_SERIAL: bus_name = "serial"; break;
+ case WBUSTYPE_I2C: bus_name = "i2c"; break;
+ case WBUSTYPE_UNKNOWN: bus_name = "unknown"; break;
+ default: g_assert_not_reached(); break;
+ }
+ dprintf(fd, "%s:%04x:%04x", bus_name, vendor, product);
+ if (name)
+ dprintf(fd, ":%s", name);
+ dprintf(fd, ";");
+}
void
libwacom_print_device_description(int fd, const WacomDevice *device)
{
const WacomMatch **match;
WacomClass class;
- const char *bus_name, *class_name;
+ const char *class_name;
class = libwacom_get_class(device);
switch(class) {
@@ -724,25 +745,8 @@ libwacom_print_device_description(int fd, const WacomDevice *device)
dprintf(fd, "[Device]\n");
dprintf(fd, "Name=%s\n", libwacom_get_name(device));
dprintf(fd, "DeviceMatch=");
- for (match = libwacom_get_matches(device); *match; match++) {
- const char *name = libwacom_match_get_name(*match);
- WacomBusType type = libwacom_match_get_bustype(*match);
- int vendor = libwacom_match_get_vendor_id(*match);
- int product = libwacom_match_get_product_id(*match);
-
- switch(type) {
- case WBUSTYPE_BLUETOOTH: bus_name = "bluetooth"; break;
- case WBUSTYPE_USB: bus_name = "usb"; break;
- case WBUSTYPE_SERIAL: bus_name = "serial"; break;
- case WBUSTYPE_I2C: bus_name = "i2c"; break;
- case WBUSTYPE_UNKNOWN: bus_name = "unknown"; break;
- default: g_assert_not_reached(); break;
- }
- dprintf(fd, "%s:%04x:%04x", bus_name, vendor, product);
- if (name)
- dprintf(fd, ":%s", name);
- dprintf(fd, ";");
- }
+ for (match = libwacom_get_matches(device); *match; match++)
+ print_match(fd, *match);
dprintf(fd, "\n");
dprintf(fd, "Class=%s\n", class_name);
@@ -768,6 +772,13 @@ libwacom_print_device_description(int fd, const WacomDevice *device)
print_buttons_for_device(fd, device);
}
+void
+libwacom_match_destroy(WacomMatch *match)
+{
+ g_free (match->match);
+ g_free (match->name);
+ g_free (match);
+}
void
libwacom_destroy(WacomDevice *device)
@@ -779,12 +790,8 @@ libwacom_destroy(WacomDevice *device)
g_free (device->name);
g_free (device->layout);
-
- for (i = 0; i < device->nmatches; i++) {
- g_free (device->matches[i]->match);
- g_free (device->matches[i]->name);
- g_free (device->matches[i]);
- }
+ for (i = 0; i < device->nmatches; i++)
+ libwacom_match_destroy(device->matches[i]);
g_free (device->matches);
g_free (device->supported_styli);
g_free (device->status_leds);
diff --git a/libwacom/libwacomint.h b/libwacom/libwacomint.h
index 825f9e9..af47bd5 100644
--- a/libwacom/libwacomint.h
+++ b/libwacom/libwacomint.h
@@ -121,6 +121,7 @@ struct _WacomError {
void libwacom_error_set(WacomError *error, enum WacomErrorCode code, const char *msg, ...);
void libwacom_stylus_destroy(WacomStylus *stylus);
void libwacom_update_match(WacomDevice *device, const char *name, WacomBusType bus, int vendor_id, int product_id);
+void libwacom_match_destroy(WacomMatch *match);
WacomBusType bus_from_str (const char *str);
const char *bus_to_str (WacomBusType bus);