From 0066e387bcf5e77411ff5edb4896df69c3df72cd Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Sat, 25 Jul 2020 15:49:17 +0300 Subject: tools: make independent from src/ Signed-off-by: Ran Benita --- tools/compile-keymap.c | 36 ++++++++++++++++++++++++------------ tools/tools-common.c | 8 +++++--- tools/tools-common.h | 2 ++ 3 files changed, 31 insertions(+), 15 deletions(-) (limited to 'tools') 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 #include +#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 #include #include #include @@ -49,7 +50,6 @@ #include #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, -- cgit v1.2.1