tools: make independent from src/ Signed-off-by: Ran Benita <ran@unusedvar.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
diff --git a/meson.build b/meson.build
index 4d2f8e8..d7be3d4 100644
--- a/meson.build
+++ b/meson.build
@@ -532,11 +532,10 @@ if build_tools
'tools-internal',
'tools/tools-common.h',
'tools/tools-common.c',
- include_directories: include_directories('src'),
dependencies: libxkbcommon_dep,
)
tools_dep = declare_dependency(
- include_directories: [include_directories('src'), include_directories('tools')],
+ include_directories: [include_directories('tools')],
link_with: libxkbcommon_tools_internal,
)
@@ -556,6 +555,7 @@ if build_tools
libxkbcommon_sources,
dependencies: [tools_dep],
c_args: ['-DENABLE_PRIVATE_APIS'],
+ include_directories: [include_directories('src')],
install: false)
configh_data.set10('HAVE_XKBCLI_COMPILE_KEYMAP', true)
executable('xkbcli-how-to-type',
diff --git a/tools/compile-keymap.c b/tools/compile-keymap.c
index 370a67c..6308449 100644
--- a/tools/compile-keymap.c
+++ b/tools/compile-keymap.c
@@ -31,9 +31,12 @@
#include <stdlib.h>
#include <string.h>
+#include "xkbcommon/xkbcommon.h"
+#if ENABLE_PRIVATE_APIS
#include "xkbcomp/xkbcomp-priv.h"
#include "xkbcomp/rules.h"
-#include "xkbcommon/xkbcommon.h"
+#endif
+#include "tools-common.h"
#define DEFAULT_INCLUDE_PATH_PLACEHOLDER "__defaults__"
@@ -44,7 +47,8 @@ static enum output_format {
FORMAT_KCCGST,
FORMAT_KEYMAP_FROM_XKB,
} output_format = FORMAT_KEYMAP;
-static darray(const char *) includes;
+static const char *includes[64];
+static size_t num_includes = 0;
static void
usage(char **argv)
@@ -152,10 +156,18 @@ parse_options(int argc, char **argv, struct xkb_rule_names *names)
output_format = FORMAT_KEYMAP_FROM_XKB;
break;
case OPT_INCLUDE:
- darray_append(includes, optarg);
+ if (num_includes >= ARRAY_SIZE(includes)) {
+ fprintf(stderr, "error: too many includes\n");
+ exit(EXIT_INVALID_USAGE);
+ }
+ includes[num_includes++] = optarg;
break;
case OPT_INCLUDE_DEFAULTS:
- darray_append(includes, DEFAULT_INCLUDE_PATH_PLACEHOLDER);
+ if (num_includes >= ARRAY_SIZE(includes)) {
+ fprintf(stderr, "error: too many includes\n");
+ exit(EXIT_INVALID_USAGE);
+ }
+ includes[num_includes++] = DEFAULT_INCLUDE_PATH_PLACEHOLDER;
break;
case OPT_RULES:
names->rules = optarg;
@@ -307,7 +319,6 @@ main(int argc, char **argv)
.options = DEFAULT_XKB_OPTIONS,
};
int rc = 1;
- const char **path;
if (argc <= 1) {
usage(argv);
@@ -318,8 +329,8 @@ main(int argc, char **argv)
return EXIT_INVALID_USAGE;
/* Now fill in the layout */
- if (isempty(names.layout)) {
- if (!isempty(names.variant)) {
+ if (!names.layout || !*names.layout) {
+ if (names.variant && *names.variant) {
fprintf(stderr, "Error: a variant requires a layout\n");
return EXIT_INVALID_USAGE;
}
@@ -335,14 +346,15 @@ main(int argc, char **argv)
xkb_context_set_log_verbosity(ctx, 10);
}
- if (darray_empty(includes))
- darray_append(includes, DEFAULT_INCLUDE_PATH_PLACEHOLDER);
+ if (num_includes == 0)
+ includes[num_includes++] = DEFAULT_INCLUDE_PATH_PLACEHOLDER;
- darray_foreach(path, includes) {
- if (streq(*path, DEFAULT_INCLUDE_PATH_PLACEHOLDER))
+ for (size_t i = 0; i < num_includes; i++) {
+ const char *include = includes[i];
+ if (strcmp(include, DEFAULT_INCLUDE_PATH_PLACEHOLDER))
xkb_context_include_path_append_default(ctx);
else
- xkb_context_include_path_append(ctx, *path);
+ xkb_context_include_path_append(ctx, include);
}
if (output_format == FORMAT_RMLVO) {
diff --git a/tools/tools-common.c b/tools/tools-common.c
index db17880..0c1ffb9 100644
--- a/tools/tools-common.c
+++ b/tools/tools-common.c
@@ -32,6 +32,7 @@
#include "config.h"
+#include <errno.h>
#include <limits.h>
#include <fcntl.h>
#include <stdlib.h>
@@ -49,7 +50,6 @@
#include <termios.h>
#endif
-#include "utils.h"
#include "tools-common.h"
void
@@ -212,6 +212,7 @@ tools_exec_command(const char *prefix, int real_argc, char **real_argv)
char *argv[64] = {NULL};
char executable[PATH_MAX];
const char *command;
+ int rc;
if (((size_t)real_argc >= ARRAY_SIZE(argv))) {
fprintf(stderr, "Too many arguments\n");
@@ -220,8 +221,9 @@ tools_exec_command(const char *prefix, int real_argc, char **real_argv)
command = real_argv[0];
- if (!snprintf_safe(executable, sizeof(executable),
- "%s/%s-%s", LIBXKBCOMMON_TOOL_PATH, prefix, command)) {
+ rc = snprintf(executable, sizeof(executable),
+ "%s/%s-%s", LIBXKBCOMMON_TOOL_PATH, prefix, command);
+ if (rc < 0 || (size_t) rc >= sizeof(executable)) {
fprintf(stderr, "Failed to assemble command\n");
return EXIT_FAILURE;
}
diff --git a/tools/tools-common.h b/tools/tools-common.h
index bc6fa38..780720a 100644
--- a/tools/tools-common.h
+++ b/tools/tools-common.h
@@ -34,6 +34,8 @@
#include "xkbcommon/xkbcommon.h"
#include "xkbcommon/xkbcommon-compose.h"
+#define ARRAY_SIZE(arr) ((sizeof(arr) / sizeof(*(arr))))
+
void
tools_print_keycode_state(struct xkb_state *state,
struct xkb_compose_state *compose_state,