tools: make independent from src/

Signed-off-by: Ran Benita <ran@unusedvar.com>
master
Ran Benita 2020-07-25 15:49:17 +03:00
parent d67c9cfffb
commit 0066e387bc
4 changed files with 33 additions and 17 deletions

View File

@ -532,11 +532,10 @@ if build_tools
'tools-internal', 'tools-internal',
'tools/tools-common.h', 'tools/tools-common.h',
'tools/tools-common.c', 'tools/tools-common.c',
include_directories: include_directories('src'),
dependencies: libxkbcommon_dep, dependencies: libxkbcommon_dep,
) )
tools_dep = declare_dependency( tools_dep = declare_dependency(
include_directories: [include_directories('src'), include_directories('tools')], include_directories: [include_directories('tools')],
link_with: libxkbcommon_tools_internal, link_with: libxkbcommon_tools_internal,
) )
@ -556,6 +555,7 @@ if build_tools
libxkbcommon_sources, libxkbcommon_sources,
dependencies: [tools_dep], dependencies: [tools_dep],
c_args: ['-DENABLE_PRIVATE_APIS'], c_args: ['-DENABLE_PRIVATE_APIS'],
include_directories: [include_directories('src')],
install: false) install: false)
configh_data.set10('HAVE_XKBCLI_COMPILE_KEYMAP', true) configh_data.set10('HAVE_XKBCLI_COMPILE_KEYMAP', true)
executable('xkbcli-how-to-type', executable('xkbcli-how-to-type',

View File

@ -31,9 +31,12 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "xkbcommon/xkbcommon.h"
#if ENABLE_PRIVATE_APIS
#include "xkbcomp/xkbcomp-priv.h" #include "xkbcomp/xkbcomp-priv.h"
#include "xkbcomp/rules.h" #include "xkbcomp/rules.h"
#include "xkbcommon/xkbcommon.h" #endif
#include "tools-common.h"
#define DEFAULT_INCLUDE_PATH_PLACEHOLDER "__defaults__" #define DEFAULT_INCLUDE_PATH_PLACEHOLDER "__defaults__"
@ -44,7 +47,8 @@ static enum output_format {
FORMAT_KCCGST, FORMAT_KCCGST,
FORMAT_KEYMAP_FROM_XKB, FORMAT_KEYMAP_FROM_XKB,
} output_format = FORMAT_KEYMAP; } output_format = FORMAT_KEYMAP;
static darray(const char *) includes; static const char *includes[64];
static size_t num_includes = 0;
static void static void
usage(char **argv) usage(char **argv)
@ -152,10 +156,18 @@ parse_options(int argc, char **argv, struct xkb_rule_names *names)
output_format = FORMAT_KEYMAP_FROM_XKB; output_format = FORMAT_KEYMAP_FROM_XKB;
break; break;
case OPT_INCLUDE: 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; break;
case OPT_INCLUDE_DEFAULTS: 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; break;
case OPT_RULES: case OPT_RULES:
names->rules = optarg; names->rules = optarg;
@ -307,7 +319,6 @@ main(int argc, char **argv)
.options = DEFAULT_XKB_OPTIONS, .options = DEFAULT_XKB_OPTIONS,
}; };
int rc = 1; int rc = 1;
const char **path;
if (argc <= 1) { if (argc <= 1) {
usage(argv); usage(argv);
@ -318,8 +329,8 @@ main(int argc, char **argv)
return EXIT_INVALID_USAGE; return EXIT_INVALID_USAGE;
/* Now fill in the layout */ /* Now fill in the layout */
if (isempty(names.layout)) { if (!names.layout || !*names.layout) {
if (!isempty(names.variant)) { if (names.variant && *names.variant) {
fprintf(stderr, "Error: a variant requires a layout\n"); fprintf(stderr, "Error: a variant requires a layout\n");
return EXIT_INVALID_USAGE; return EXIT_INVALID_USAGE;
} }
@ -335,14 +346,15 @@ main(int argc, char **argv)
xkb_context_set_log_verbosity(ctx, 10); xkb_context_set_log_verbosity(ctx, 10);
} }
if (darray_empty(includes)) if (num_includes == 0)
darray_append(includes, DEFAULT_INCLUDE_PATH_PLACEHOLDER); includes[num_includes++] = DEFAULT_INCLUDE_PATH_PLACEHOLDER;
darray_foreach(path, includes) { for (size_t i = 0; i < num_includes; i++) {
if (streq(*path, DEFAULT_INCLUDE_PATH_PLACEHOLDER)) const char *include = includes[i];
if (strcmp(include, DEFAULT_INCLUDE_PATH_PLACEHOLDER))
xkb_context_include_path_append_default(ctx); xkb_context_include_path_append_default(ctx);
else else
xkb_context_include_path_append(ctx, *path); xkb_context_include_path_append(ctx, include);
} }
if (output_format == FORMAT_RMLVO) { if (output_format == FORMAT_RMLVO) {

View File

@ -32,6 +32,7 @@
#include "config.h" #include "config.h"
#include <errno.h>
#include <limits.h> #include <limits.h>
#include <fcntl.h> #include <fcntl.h>
#include <stdlib.h> #include <stdlib.h>
@ -49,7 +50,6 @@
#include <termios.h> #include <termios.h>
#endif #endif
#include "utils.h"
#include "tools-common.h" #include "tools-common.h"
void void
@ -212,6 +212,7 @@ tools_exec_command(const char *prefix, int real_argc, char **real_argv)
char *argv[64] = {NULL}; char *argv[64] = {NULL};
char executable[PATH_MAX]; char executable[PATH_MAX];
const char *command; const char *command;
int rc;
if (((size_t)real_argc >= ARRAY_SIZE(argv))) { if (((size_t)real_argc >= ARRAY_SIZE(argv))) {
fprintf(stderr, "Too many arguments\n"); 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]; command = real_argv[0];
if (!snprintf_safe(executable, sizeof(executable), rc = snprintf(executable, sizeof(executable),
"%s/%s-%s", LIBXKBCOMMON_TOOL_PATH, prefix, command)) { "%s/%s-%s", LIBXKBCOMMON_TOOL_PATH, prefix, command);
if (rc < 0 || (size_t) rc >= sizeof(executable)) {
fprintf(stderr, "Failed to assemble command\n"); fprintf(stderr, "Failed to assemble command\n");
return EXIT_FAILURE; return EXIT_FAILURE;
} }

View File

@ -34,6 +34,8 @@
#include "xkbcommon/xkbcommon.h" #include "xkbcommon/xkbcommon.h"
#include "xkbcommon/xkbcommon-compose.h" #include "xkbcommon/xkbcommon-compose.h"
#define ARRAY_SIZE(arr) ((sizeof(arr) / sizeof(*(arr))))
void void
tools_print_keycode_state(struct xkb_state *state, tools_print_keycode_state(struct xkb_state *state,
struct xkb_compose_state *compose_state, struct xkb_compose_state *compose_state,