@@ -97,12 +97,67 @@ handle_match(const WacomMatch *m)
9797 pop ();
9898}
9999
100+ static WacomDevice *
101+ device_from_device_match (WacomDeviceDatabase * db , char * * parts )
102+ {
103+ WacomBusType bustype ;
104+ guint64 vid , pid ;
105+ const char * name = NULL ;
106+ const char * uniq = NULL ;
107+ WacomBuilder * builder ;
108+ WacomDevice * device ;
109+
110+ if (g_str_equal (parts [0 ], "usb" ))
111+ bustype = WBUSTYPE_USB ;
112+ else if (g_str_equal (parts [0 ], "serial" ))
113+ bustype = WBUSTYPE_SERIAL ;
114+ else if (g_str_equal (parts [0 ], "bluetooth" ))
115+ bustype = WBUSTYPE_BLUETOOTH ;
116+ else if (g_str_equal (parts [0 ], "i2c" ))
117+ bustype = WBUSTYPE_I2C ;
118+ else {
119+ fprintf (stderr , "Unknown bus type %s\n" , parts [0 ]);
120+ return NULL ;
121+ }
122+
123+ if (!g_ascii_string_to_unsigned (parts [1 ], 16 , 0 , 0xffff , & vid , NULL ) ||
124+ !g_ascii_string_to_unsigned (parts [2 ], 16 , 0 , 0xffff , & pid , NULL )) {
125+ fprintf (stderr , "Failed to parse vid/pid\n" );
126+ return NULL ;
127+ }
128+
129+ if (parts [3 ]) {
130+ name = parts [3 ];
131+ if (parts [4 ])
132+ uniq = parts [4 ];
133+ }
134+
135+ builder = libwacom_builder_new ();
136+ libwacom_builder_set_bustype (builder , bustype );
137+ libwacom_builder_set_usbid (builder , vid , pid );
138+ if (name )
139+ libwacom_builder_set_match_name (builder , name );
140+ if (name )
141+ libwacom_builder_set_uniq (builder , uniq );
142+
143+ device = libwacom_new_from_builder (db , builder , WFALLBACK_NONE , NULL );
144+ libwacom_builder_destroy (builder );
145+ return device ;
146+ }
147+
100148static int
101149handle_device (WacomDeviceDatabase * db , const char * path )
102150{
103151 WacomDevice * device ;
152+ char * * parts = g_strsplit (path , "|" , 5 );
153+
154+ if (parts && parts [0 ] && parts [1 ]) {
155+ device = device_from_device_match (db , parts );
156+ } else {
157+ device = libwacom_new_from_path (db , path , WFALLBACK_NONE , NULL );
158+ }
159+ g_strfreev (parts );
104160
105- device = libwacom_new_from_path (db , path , WFALLBACK_NONE , NULL );
106161 if (!device ) {
107162 fprintf (stderr , "Device not known to libwacom\n" );
108163 return EXIT_FAILURE ;
@@ -405,7 +460,8 @@ int main(int argc, char **argv)
405460 GError * error ;
406461 int rc ;
407462
408- context = g_option_context_new (NULL );
463+ context = g_option_context_new ("[/dev/input/event0 | \"usb|0123|abcd|some tablet\"]" );
464+ g_option_context_set_description (context , "The argument may be a device node or a single DeviceMatch string as listed in .tablet files." );
409465
410466 g_option_context_add_main_entries (context , opts , NULL );
411467 error = NULL ;
@@ -437,7 +493,7 @@ int main(int argc, char **argv)
437493 }
438494
439495 if (argc <= 1 ) {
440- fprintf (stderr , "Missing device node\n" );
496+ fprintf (stderr , "Missing device node or match string \n" );
441497 libwacom_database_destroy (db );
442498 return EXIT_FAILURE ;
443499 }
0 commit comments