xkbcli.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * Copyright © 2020 Red Hat, Inc.
  3. * SPDX-License-Identifier: MIT
  4. */
  5. #include "config.h"
  6. #include <getopt.h>
  7. #include <locale.h>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include "tools-common.h"
  11. static void
  12. usage(void)
  13. {
  14. printf("Usage: xkbcli [--help|-h] [--version|-V] <command> [<args>]\n"
  15. "\n"
  16. "Global options:\n"
  17. " -h, --help ...... show this help and exit\n"
  18. " -V, --version ... show version information and exit\n"
  19. /* WARNING: The following is parsed by the bash completion script.
  20. * Any change to the format (in particular to the indentation)
  21. * should kept in the script in sync. */
  22. "Commands:\n"
  23. #if HAVE_XKBCLI_INFO
  24. " info\n"
  25. " Print information about libxkbcommon configuration\n"
  26. "\n"
  27. #endif
  28. #if HAVE_XKBCLI_LIST
  29. " list\n"
  30. " List available rules, models, layouts, variants and options\n"
  31. "\n"
  32. #endif
  33. #if HAVE_XKBCLI_INTERACTIVE_WAYLAND || HAVE_XKBCLI_INTERACTIVE_X11
  34. " interactive\n"
  35. " Interactive debugger for XKB keymaps; automatically select from"
  36. " the following backends, if available: Wayland, X11 and evdev.\n"
  37. "\n"
  38. #endif
  39. #if HAVE_XKBCLI_INTERACTIVE_WAYLAND
  40. " interactive-wayland\n"
  41. " Interactive debugger for XKB keymaps for Wayland\n"
  42. "\n"
  43. #endif
  44. #if HAVE_XKBCLI_INTERACTIVE_X11
  45. " interactive-x11\n"
  46. " Interactive debugger for XKB keymaps for X11\n"
  47. "\n"
  48. #endif
  49. #if HAVE_XKBCLI_INTERACTIVE_EVDEV
  50. " interactive-evdev\n"
  51. " Interactive debugger for XKB keymaps for evdev\n"
  52. "\n"
  53. #endif
  54. #if HAVE_XKBCLI_DUMP_KEYMAP_WAYLAND || HAVE_XKBCLI_DUMP_KEYMAP_X11
  55. " dump-keymap\n"
  56. " Dump an XKB keymap from a Wayland or X11 compositor\n"
  57. "\n"
  58. #endif
  59. #if HAVE_XKBCLI_DUMP_KEYMAP_WAYLAND
  60. " dump-keymap-wayland\n"
  61. " Dump an XKB keymap from a Wayland compositor\n"
  62. "\n"
  63. #endif
  64. #if HAVE_XKBCLI_DUMP_KEYMAP_X11
  65. " dump-keymap-x11\n"
  66. " Dump an XKB keymap from an X server\n"
  67. "\n"
  68. #endif
  69. #if HAVE_XKBCLI_COMPILE_KEYMAP
  70. " compile-keymap\n"
  71. " Compile an XKB keymap\n"
  72. "\n"
  73. #endif
  74. #if HAVE_XKBCLI_COMPILE_COMPOSE
  75. " compile-compose\n"
  76. " Compile a Compose file\n"
  77. "\n"
  78. #endif
  79. #if HAVE_XKBCLI_HOW_TO_TYPE
  80. " how-to-type\n"
  81. " Print key sequences to type a Unicode codepoint\n"
  82. "\n"
  83. #endif
  84. );
  85. }
  86. int
  87. main(int argc, char **argv)
  88. {
  89. enum options {
  90. OPT_HELP = 1,
  91. OPT_VERSION,
  92. };
  93. int option_index = 0;
  94. setlocale(LC_ALL, "");
  95. while (1) {
  96. int c;
  97. static struct option opts[] = {
  98. { "help", no_argument, 0, OPT_HELP },
  99. { "version", no_argument, 0, OPT_VERSION },
  100. { 0, 0, 0, 0}
  101. };
  102. c = getopt_long(argc, argv, "+hV", opts, &option_index);
  103. if (c == -1)
  104. break;
  105. switch(c) {
  106. case 'h':
  107. case OPT_HELP:
  108. usage();
  109. return EXIT_SUCCESS;
  110. case 'V':
  111. case OPT_VERSION:
  112. printf("%s\n", LIBXKBCOMMON_VERSION);
  113. return EXIT_SUCCESS;
  114. default:
  115. usage();
  116. return EXIT_INVALID_USAGE;
  117. }
  118. }
  119. if (optind >= argc) {
  120. usage();
  121. return EXIT_INVALID_USAGE;
  122. }
  123. argv += optind;
  124. argc -= optind;
  125. return tools_exec_command("xkbcli", argc, (const char **) argv);
  126. }