• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 	       "  debug-gui\n"
50 	       "	Display a simple GUI to visualize libinput's events.\n"
51 	       "\n"
52 	       "  measure <feature>\n"
53 	       "	Measure various device properties. See the man page for more info\n"
54 	       "\n"
55 	       "  analyze <feature>\n"
56 	       "	Analyze device events. See the man page for more info\n"
57 	       "\n"
58 	       "  record\n"
59 	       "	Record event stream from a device node. See the man page for more info\n"
60 	       "\n"
61 	       "  replay\n"
62 	       "	Replay a previously recorded event stream. See the man page for more info\n"
63 	       "\n");
64 }
65 
66 enum global_opts {
67 	GOPT_HELP = 1,
68 	GOPT_VERSION,
69 };
70 
71 int
main(int argc,char ** argv)72 main(int argc, char **argv)
73 {
74 	int option_index = 0;
75 
76 	while (1) {
77 		int c;
78 		static struct option opts[] = {
79 			{ "help",	no_argument,	0, GOPT_HELP },
80 			{ "version",	no_argument,	0, GOPT_VERSION },
81 			{ 0, 0, 0, 0}
82 		};
83 
84 		c = getopt_long(argc, argv, "+h", opts, &option_index);
85 		if (c == -1)
86 			break;
87 
88 		switch(c) {
89 		case 'h':
90 		case GOPT_HELP:
91 			usage();
92 			return EXIT_SUCCESS;
93 		case GOPT_VERSION:
94 			printf("%s\n", LIBINPUT_VERSION);
95 			return EXIT_SUCCESS;
96 		default:
97 			usage();
98 			return EXIT_INVALID_USAGE;
99 		}
100 	}
101 
102 	if (optind >= argc) {
103 		usage();
104 		return EXIT_INVALID_USAGE;
105 	}
106 
107 	argv += optind;
108 	argc -= optind;
109 
110 	return tools_exec_command("libinput", argc, argv);
111 }
112