1 /*
2 * Copyright © 2017 Red Hat, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 */
23
24 #include "config.h"
25
26 #include <getopt.h>
27 #include <stdio.h>
28
29 #include <libinput-version.h>
30
31 #include "shared.h"
32
33 static void
usage(void)34 usage(void)
35 {
36 printf("Usage: libinput [--help|--version] <command> [<args>]\n"
37 "\n"
38 "Global options:\n"
39 " --help ...... show this help and exit\n"
40 " --version ... show version information and exit\n"
41 "\n"
42 "Commands:\n"
43 " list-devices\n"
44 " List all devices with their default configuration options\n"
45 "\n"
46 " debug-events\n"
47 " Print events to stdout\n"
48 "\n"
49 #if HAVE_DEBUG_GUI
50 " debug-gui\n"
51 " Display a simple GUI to visualize libinput's events.\n"
52 "\n"
53 #endif
54 " measure <feature>\n"
55 " Measure various device properties. See the man page for more info\n"
56 "\n"
57 " analyze <feature>\n"
58 " Analyze device events. See the man page for more info\n"
59 "\n"
60 " record\n"
61 " Record event stream from a device node. See the man page for more info\n"
62 "\n"
63 " replay\n"
64 " Replay a previously recorded event stream. See the man page for more info\n"
65 "\n");
66 }
67
68 enum global_opts {
69 GOPT_HELP = 1,
70 GOPT_VERSION,
71 };
72
73 int
main(int argc, char **argv)74 main(int argc, char **argv)
75 {
76 int option_index = 0;
77
78 while (1) {
79 int c;
80 static struct option opts[] = {
81 { "help", no_argument, 0, GOPT_HELP },
82 { "version", no_argument, 0, GOPT_VERSION },
83 { 0, 0, 0, 0}
84 };
85
86 c = getopt_long(argc, argv, "+h", opts, &option_index);
87 if (c == -1)
88 break;
89
90 switch(c) {
91 case 'h':
92 case GOPT_HELP:
93 usage();
94 return EXIT_SUCCESS;
95 case GOPT_VERSION:
96 printf("%s\n", LIBINPUT_VERSION);
97 return EXIT_SUCCESS;
98 default:
99 usage();
100 return EXIT_INVALID_USAGE;
101 }
102 }
103
104 if (optind >= argc) {
105 usage();
106 return EXIT_INVALID_USAGE;
107 }
108
109 argv += optind;
110 argc -= optind;
111
112 return tools_exec_command("libinput", argc, argv);
113 }
114