diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2021-03-19 11:38:30 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2021-03-19 13:55:34 +1000 |
commit | 021275c156f791cdd7594f1f3797b2f09e517113 (patch) | |
tree | e70914052f771d3ac7c95f459278fb8f843eba0b /tools/list-local-devices.c | |
parent | 3451479de28b0eed5267fa51e3d389170831ab1a (diff) | |
download | libwacom-021275c156f791cdd7594f1f3797b2f09e517113.tar.gz |
tools: add a --format argument to list-local-devices
This changes the default output format to a one-line format which is more
useful in most cases anyway. Example output:
Wacom Intuos3 4x6: /dev/input/event26 /dev/input/event25
Wacom Intuos Pro M: /dev/input/event24 /dev/input/event5 /dev/input/event4
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Diffstat (limited to 'tools/list-local-devices.c')
-rw-r--r-- | tools/list-local-devices.c | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/tools/list-local-devices.c b/tools/list-local-devices.c index 8acccc9..8274bfb 100644 --- a/tools/list-local-devices.c +++ b/tools/list-local-devices.c @@ -38,6 +38,11 @@ #include <glib.h> #include "libwacom.h" +static enum output_format { + ONELINE, + DATAFILE, +} output_format = ONELINE; + static char *database_path; /* Most devices have 2-3 event nodes, let's have a wrapper struct to group @@ -85,8 +90,37 @@ tablet_print(gpointer data, gpointer user_data) printf("---------------------------------------------------------------\n"); } +static void +print_str(gpointer data, gpointer user_data) +{ + printf("%s ", (char *)data); +} + +static void +tablet_print_oneline(gpointer data, gpointer user_data) +{ + struct tablet *d = data; + + printf("%s: ", libwacom_get_name(d->dev)); + g_list_foreach(d->nodes, print_str, NULL); + printf("\n"); +} + +static gboolean +check_format(const gchar *option_name, const gchar *value, gpointer data, GError **error) +{ + if (g_str_equal(value, "datafile")) + output_format = DATAFILE; + else if (g_str_equal(value, "oneline")) + output_format = ONELINE; + else + return FALSE; + return TRUE; +} + static GOptionEntry opts[] = { {"database", 0, 0, G_OPTION_ARG_FILENAME, &database_path, N_("Path to device database"), NULL }, + { "format", 0, 0, G_OPTION_ARG_CALLBACK, check_format, N_("Output format, one of 'oneline', 'datafile'"), NULL }, { .long_name = NULL} }; @@ -163,7 +197,16 @@ int main(int argc, char **argv) if (!tabletlist) fprintf(stderr, "Failed to find any devices.\n"); - g_list_foreach(tabletlist, tablet_print, NULL); + switch (output_format) { + case DATAFILE: + g_list_foreach(tabletlist, tablet_print, NULL); + break; + case ONELINE: + g_list_foreach(tabletlist, tablet_print_oneline, NULL); + break; + default: + abort(); + } g_list_free_full(tabletlist, tablet_destroy); g_dir_close(dir); |