info.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. * Copyright © 2025 Pierre Le Marre <dev@wismill.eu>
  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 "xkbcommon/xkbcommon.h"
  11. #include "src/utils.h"
  12. #include "tools-common.h"
  13. static void
  14. usage(FILE *fp, char *progname)
  15. {
  16. fprintf(fp, "Usage: %s\n", progname);
  17. }
  18. static bool
  19. parse_options(int argc, char **argv)
  20. {
  21. enum options {
  22. OPT_HELP = 'h',
  23. OPT_VERSION = 'V',
  24. };
  25. static struct option opts[] = {
  26. {"help", no_argument, 0, OPT_HELP},
  27. {"version", no_argument, 0, OPT_VERSION},
  28. {0, 0, 0, 0},
  29. };
  30. while (1) {
  31. int option_index = 0;
  32. int opt = getopt_long(argc, argv, "hV", opts, &option_index);
  33. if (opt == -1)
  34. break;
  35. switch (opt) {
  36. case OPT_HELP:
  37. usage(stdout, argv[0]);
  38. exit(EXIT_SUCCESS);
  39. case OPT_VERSION:
  40. printf("%s\n", LIBXKBCOMMON_VERSION);
  41. exit(EXIT_SUCCESS);
  42. default:
  43. // invalid_usage:
  44. usage(stderr, argv[0]);
  45. return false;
  46. }
  47. }
  48. return true;
  49. }
  50. int
  51. main(int argc, char **argv)
  52. {
  53. setlocale(LC_ALL, "");
  54. if (!parse_options(argc, argv)) {
  55. return EXIT_INVALID_USAGE;
  56. }
  57. printf("Version: \"%s\"\n", LIBXKBCOMMON_VERSION);
  58. printf("Website: https://xkbcommon.org\n");
  59. printf("Tools path: \"%s\"\n", LIBXKBCOMMON_TOOL_PATH);
  60. /* Features */
  61. printf("Features:\n");
  62. printf(" Extensions directories: "
  63. #if HAVE_XKB_EXTENSIONS_DIRECTORIES
  64. "true"
  65. #else
  66. "false"
  67. #endif
  68. "\n");
  69. /* Built-in settings */
  70. printf("Built-in values:\n");
  71. static const struct {
  72. const char * var;
  73. const char * value;
  74. } builtins[] = {
  75. { "XKB_CONFIG_ROOT", DFLT_XKB_CONFIG_ROOT },
  76. { "XKB_CONFIG_LEGACY_ROOT", DFLT_XKB_LEGACY_ROOT },
  77. { "XKB_CONFIG_EXTRA_PATH", DFLT_XKB_CONFIG_EXTRA_PATH },
  78. { "XKB_CONFIG_UNVERSIONED_EXTENSIONS_PATH",
  79. #ifdef DFLT_XKB_CONFIG_UNVERSIONED_EXTENSIONS_PATH
  80. DFLT_XKB_CONFIG_UNVERSIONED_EXTENSIONS_PATH
  81. #else
  82. ""
  83. #endif
  84. },
  85. { "XKB_CONFIG_VERSIONED_EXTENSIONS_PATH",
  86. #ifdef DFLT_XKB_CONFIG_UNVERSIONED_EXTENSIONS_PATH
  87. DFLT_XKB_CONFIG_VERSIONED_EXTENSIONS_PATH
  88. #else
  89. ""
  90. #endif
  91. },
  92. { "XKB_DEFAULT_RULES", DEFAULT_XKB_RULES },
  93. { "XKB_DEFAULT_MODEL", DEFAULT_XKB_MODEL },
  94. { "XKB_DEFAULT_LAYOUT", DEFAULT_XKB_LAYOUT },
  95. { "XKB_DEFAULT_VARIANT", DEFAULT_XKB_VARIANT },
  96. { "XKB_DEFAULT_OPTIONS", DEFAULT_XKB_OPTIONS },
  97. { "XLOCALEDIR", XLOCALEDIR },
  98. };
  99. for (size_t v = 0; v < ARRAY_SIZE(builtins); v++) {
  100. printf(" %s: ", builtins[v].var);
  101. const char * const value = builtins[v].value;
  102. if (value)
  103. printf("\"%s\"\n", value);
  104. else
  105. printf("null\n");
  106. }
  107. struct xkb_context * const ctx = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
  108. /* Environment variable */
  109. printf("Environment variables:\n");
  110. static const char * vars[] = {
  111. "XKB_CONFIG_ROOT",
  112. "XKB_CONFIG_EXTRA_PATH",
  113. "XKB_CONFIG_UNVERSIONED_EXTENSIONS_PATH",
  114. "XKB_CONFIG_VERSIONED_EXTENSIONS_PATH",
  115. "XKB_DEFAULT_RULES",
  116. "XKB_DEFAULT_MODEL",
  117. "XKB_DEFAULT_LAYOUT",
  118. "XKB_DEFAULT_VARIANT",
  119. "XKB_DEFAULT_OPTIONS",
  120. "HOME",
  121. "XDG_CONFIG_HOME",
  122. "XLOCALEDIR",
  123. "XCOMPOSEFILE",
  124. };
  125. for (size_t v = 0; v < ARRAY_SIZE(vars); v++) {
  126. printf(" %s: ", vars[v]);
  127. const char * const value = secure_getenv(vars[v]);
  128. if (value)
  129. printf("\"%s\"\n", value);
  130. else
  131. printf("null\n");
  132. }
  133. /* Include paths */
  134. const unsigned int num_paths = xkb_context_num_include_paths(ctx);
  135. printf("XKB include paths:\n");
  136. for (unsigned int p = 0; p < num_paths; p++) {
  137. printf("- \"%s\"\n", xkb_context_include_path_get(ctx, p));
  138. }
  139. xkb_context_unref(ctx);
  140. return EXIT_SUCCESS;
  141. }