Signed-off-by: Peter Hutterer <[email protected]>
---
 libwacom/libwacom.c    | 59 ++++++++++++++++++++++++++++----------------------
 libwacom/libwacomint.h |  1 +
 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);
-- 
2.7.4


------------------------------------------------------------------------------
Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San
Francisco, CA to explore cutting-edge tech and listen to tech luminaries
present their vision of the future. This family event has something for
everyone, including kids. Get more information and register today.
http://sdm.link/attshape
_______________________________________________
Linuxwacom-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel

Reply via email to