Debian Codegraph @

tools/list-compatible-styli.c

raw
1 /*
2 * Copyright © 2019 Red Hat, Inc.
3 *
4 * Permission to use, copy, modify, distribute, and sell this software
5 * and its documentation for any purpose is hereby granted without
6 * fee, provided that the above copyright notice appear in all copies
7 * and that both that copyright notice and this permission notice
8 * appear in supporting documentation, and that the name of Red Hat
9 * not be used in advertising or publicity pertaining to distribution
10 * of the software without specific, written prior permission. Red
11 * Hat makes no representations about the suitability of this software
12 * for any purpose. It is provided "as is" without express or implied
13 * warranty.
14 *
15 * THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
17 * NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
19 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
20 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
21 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 *
23 * Authors:
24 * Peter Hutterer <[email protected]>
25 */
26
27 #include "config.h"
28
29 #define _GNU_SOURCE
30 #include <assert.h>
31 #include <glib.h>
32 #include <libgen.h>
33 #include <stdio.h>
34 #include <string.h>
35 #include <unistd.h>
36
37 #include "libwacom.h"
38
39 static void
40 print_device_info(const WacomDeviceDatabase *db,
41 const WacomDevice *device)
42 {
43 g_autofree WacomStylus const **styli = NULL;
44 int nstyli;
45
46 printf("- name: '%s'\n", libwacom_get_name(device));
47 if (libwacom_get_model_name(device)) {
48 printf(" model: '%s'\n", libwacom_get_model_name(device));
49 }
50 if (!libwacom_has_stylus(device)) {
51 printf(" styli: [] # no styli defined\n");
52 return;
53 }
54
55 printf(" styli:\n");
56
57 styli = libwacom_get_styli(device, &nstyli);
58 for (int i = 0; i < nstyli; i++) {
59 const WacomStylus *s = styli[i];
60 char id[64];
61
62 snprintf(id, sizeof(id), "0x%x", libwacom_stylus_get_id(s));
63 printf(" - { id: %*s'%s', name: '%s' }\n",
64 (int)(7 - strlen(id)),
65 " ",
66 id,
67 libwacom_stylus_get_name(s));
68 }
69 }
70
71 int
72 main(int argc,
73 char **argv)
74 {
75 WacomDeviceDatabase *db;
76 WacomDevice **list, **p;
77
78 if (argc > 1) {
79 printf("Usage: %s [--help] - list compatible styli\n",
80 basename(argv[0]));
81 return g_str_equal(argv[1], "--help");
82 }
83
84 db = libwacom_database_new_for_path(DATABASEPATH);
85
86 list = libwacom_list_devices_from_database(db, NULL);
87 if (!list) {
88 fprintf(stderr, "Failed to load device database.\n");
89 return 1;
90 }
91
92 for (p = list; *p; p++)
93 print_device_info(db, (WacomDevice *)*p);
94
95 libwacom_database_destroy(db);
96 g_free(list);
97
98 return 0;
99 }
100
101 /* vim: set noexpandtab tabstop=8 shiftwidth=8: */