1
0

libinput-tool.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. #include "config.h"
  24. #include <getopt.h>
  25. #include <libinput-version.h>
  26. #include <stdio.h>
  27. #include "shared.h"
  28. static void
  29. usage(void)
  30. {
  31. printf("Usage: libinput [--help|--version] <command> [<args>]\n"
  32. "\n"
  33. "Global options:\n"
  34. " --help ...... show this help and exit\n"
  35. " --version ... show version information and exit\n"
  36. "\n"
  37. "Commands:\n"
  38. " list-devices\n"
  39. " List all devices with their default configuration options\n"
  40. "\n"
  41. " debug-events\n"
  42. " Print events to stdout\n"
  43. "\n"
  44. #ifdef HAVE_DEBUG_GUI
  45. " debug-gui\n"
  46. " Display a simple GUI to visualize libinput's events.\n"
  47. "\n"
  48. #endif
  49. " measure <feature>\n"
  50. " Measure various device properties. See the man page for more info\n"
  51. "\n"
  52. " analyze <feature>\n"
  53. " Analyze device events. See the man page for more info\n"
  54. "\n"
  55. " record\n"
  56. " Record event stream from a device node. See the man page for more info\n"
  57. "\n"
  58. " replay\n"
  59. " Replay a previously recorded event stream. See the man page for more info\n"
  60. "\n");
  61. }
  62. enum global_opts {
  63. GOPT_HELP = 1,
  64. GOPT_VERSION,
  65. };
  66. int
  67. main(int argc, char **argv)
  68. {
  69. int option_index = 0;
  70. while (1) {
  71. int c;
  72. static struct option opts[] = {
  73. { "help", no_argument, 0, GOPT_HELP },
  74. { "version", no_argument, 0, GOPT_VERSION },
  75. { 0, 0, 0, 0 }
  76. };
  77. c = getopt_long(argc, argv, "+h", opts, &option_index);
  78. if (c == -1)
  79. break;
  80. switch (c) {
  81. case 'h':
  82. case GOPT_HELP:
  83. usage();
  84. return EXIT_SUCCESS;
  85. case GOPT_VERSION:
  86. printf("%s\n", LIBINPUT_VERSION);
  87. return EXIT_SUCCESS;
  88. default:
  89. usage();
  90. return EXIT_INVALID_USAGE;
  91. }
  92. }
  93. if (optind >= argc) {
  94. usage();
  95. return EXIT_INVALID_USAGE;
  96. }
  97. argv += optind;
  98. argc -= optind;
  99. return tools_exec_command("libinput", argc, argv);
  100. }