tools: add ability to print the KcCGST components for rmlvo-to-keymap
This makes the rmlvo-to-kccgst tool obsolete. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>master
parent
09d6b96540
commit
fd39147175
|
@ -520,7 +520,6 @@ tools_dep = declare_dependency(
|
|||
)
|
||||
|
||||
if cc.has_header_symbol('getopt.h', 'getopt_long', prefix: '#define _GNU_SOURCE')
|
||||
executable('xkbcommon-rmlvo-to-kccgst', 'tools/rmlvo-to-kccgst.c', dependencies: tools_dep)
|
||||
executable('xkbcommon-rmlvo-to-keymap', 'tools/rmlvo-to-keymap.c', dependencies: tools_dep)
|
||||
executable('xkbcommon-print-compiled-keymap', 'tools/print-compiled-keymap.c', dependencies: tools_dep)
|
||||
executable('xkbcommon-how-to-type', 'tools/how-to-type.c', dependencies: tools_dep)
|
||||
|
|
|
@ -1,106 +0,0 @@
|
|||
/*
|
||||
* Copyright © 2012 Ran Benita <ran234@gmail.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <unistd.h>
|
||||
#include <getopt.h>
|
||||
|
||||
#include "xkbcomp/xkbcomp-priv.h"
|
||||
#include "xkbcomp/rules.h"
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
struct xkb_rule_names rmlvo = { NULL };
|
||||
struct xkb_context *ctx;
|
||||
struct xkb_component_names kccgst;
|
||||
|
||||
static struct option opts[] = {
|
||||
{"help", no_argument, 0, 'h'},
|
||||
{"rules", required_argument, 0, 'r'},
|
||||
{"model", required_argument, 0, 'm'},
|
||||
{"layout", required_argument, 0, 'l'},
|
||||
{"variant", required_argument, 0, 'v'},
|
||||
{"options", required_argument, 0, 'o'},
|
||||
{0, 0, 0, 0},
|
||||
};
|
||||
|
||||
while (1) {
|
||||
int c;
|
||||
int option_index = 0;
|
||||
|
||||
c = getopt_long(argc, argv, "r:m:l:v:o:h", opts, &option_index);
|
||||
if (c == -1)
|
||||
break;
|
||||
|
||||
switch (c) {
|
||||
case 'r':
|
||||
rmlvo.rules = optarg;
|
||||
break;
|
||||
case 'm':
|
||||
rmlvo.model = optarg;
|
||||
break;
|
||||
case 'l':
|
||||
rmlvo.layout = optarg;
|
||||
break;
|
||||
case 'v':
|
||||
rmlvo.variant = optarg;
|
||||
break;
|
||||
case 'o':
|
||||
rmlvo.options = optarg;
|
||||
break;
|
||||
case 'h':
|
||||
case '?':
|
||||
fprintf(stderr, "Usage: %s [-r <rules>] [-m <model>] "
|
||||
"[-l <layout>] [-v <variant>] [-o <options>]\n",
|
||||
argv[0]);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
ctx = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
|
||||
if (!ctx) {
|
||||
fprintf(stderr, "Failed to get xkb context\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
xkb_context_sanitize_rule_names(ctx, &rmlvo);
|
||||
|
||||
if (!xkb_components_from_rules(ctx, &rmlvo, &kccgst))
|
||||
return 1;
|
||||
|
||||
printf("xkb_keymap {\n"
|
||||
" xkb_keycodes { include \"%s\" };\n"
|
||||
" xkb_types { include \"%s\" };\n"
|
||||
" xkb_compat { include \"%s\" };\n"
|
||||
" xkb_symbols { include \"%s\" };\n"
|
||||
"};\n", kccgst.keycodes, kccgst.types, kccgst.compat, kccgst.symbols);
|
||||
|
||||
free(kccgst.keycodes);
|
||||
free(kccgst.types);
|
||||
free(kccgst.compat);
|
||||
free(kccgst.symbols);
|
||||
xkb_context_unref(ctx);
|
||||
return 0;
|
||||
}
|
|
@ -31,8 +31,16 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "xkbcomp/xkbcomp-priv.h"
|
||||
#include "xkbcomp/rules.h"
|
||||
#include "xkbcommon/xkbcommon.h"
|
||||
|
||||
static bool verbose = false;
|
||||
static enum output_format {
|
||||
FORMAT_KEYMAP,
|
||||
FORMAT_KCCGST,
|
||||
} output_format = FORMAT_KEYMAP;
|
||||
|
||||
static void
|
||||
usage(char **argv)
|
||||
{
|
||||
|
@ -43,6 +51,8 @@ usage(char **argv)
|
|||
"Options:\n"
|
||||
" --verbose\n"
|
||||
" Enable verbose debugging output\n"
|
||||
" --kccgst\n"
|
||||
" Print a keymap which only includes the KcCGST component names instead of the full keymap\n"
|
||||
"\n"
|
||||
"XKB-specific options:\n"
|
||||
" --rules <rules>\n"
|
||||
|
@ -63,10 +73,11 @@ usage(char **argv)
|
|||
}
|
||||
|
||||
static bool
|
||||
parse_options(int argc, char **argv, bool *verbose, struct xkb_rule_names *names)
|
||||
parse_options(int argc, char **argv, struct xkb_rule_names *names)
|
||||
{
|
||||
enum options {
|
||||
OPT_VERBOSE,
|
||||
OPT_KCCGST,
|
||||
OPT_RULES,
|
||||
OPT_MODEL,
|
||||
OPT_LAYOUT,
|
||||
|
@ -76,6 +87,7 @@ parse_options(int argc, char **argv, bool *verbose, struct xkb_rule_names *names
|
|||
static struct option opts[] = {
|
||||
{"help", no_argument, 0, 'h'},
|
||||
{"verbose", no_argument, 0, OPT_VERBOSE},
|
||||
{"kccgst", no_argument, 0, OPT_KCCGST},
|
||||
{"rules", required_argument, 0, OPT_RULES},
|
||||
{"model", required_argument, 0, OPT_MODEL},
|
||||
{"layout", required_argument, 0, OPT_LAYOUT},
|
||||
|
@ -96,7 +108,10 @@ parse_options(int argc, char **argv, bool *verbose, struct xkb_rule_names *names
|
|||
usage(argv);
|
||||
exit(0);
|
||||
case OPT_VERBOSE:
|
||||
*verbose = true;
|
||||
verbose = true;
|
||||
break;
|
||||
case OPT_KCCGST:
|
||||
output_format = FORMAT_KCCGST;
|
||||
break;
|
||||
case OPT_RULES:
|
||||
names->rules = optarg;
|
||||
|
@ -123,11 +138,48 @@ parse_options(int argc, char **argv, bool *verbose, struct xkb_rule_names *names
|
|||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
print_kccgst(struct xkb_context *ctx, const struct xkb_rule_names *rmlvo)
|
||||
{
|
||||
struct xkb_component_names kccgst;
|
||||
|
||||
if (!xkb_components_from_rules(ctx, rmlvo, &kccgst))
|
||||
return false;
|
||||
|
||||
printf("xkb_keymap {\n"
|
||||
" xkb_keycodes { include \"%s\" };\n"
|
||||
" xkb_types { include \"%s\" };\n"
|
||||
" xkb_compat { include \"%s\" };\n"
|
||||
" xkb_symbols { include \"%s\" };\n"
|
||||
"};\n",
|
||||
kccgst.keycodes, kccgst.types, kccgst.compat, kccgst.symbols);
|
||||
free(kccgst.keycodes);
|
||||
free(kccgst.types);
|
||||
free(kccgst.compat);
|
||||
free(kccgst.symbols);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
print_keymap(struct xkb_context *ctx, const struct xkb_rule_names *rmlvo)
|
||||
{
|
||||
struct xkb_keymap *keymap;
|
||||
|
||||
keymap = xkb_keymap_new_from_names(ctx, rmlvo, XKB_KEYMAP_COMPILE_NO_FLAGS);
|
||||
if (keymap == NULL)
|
||||
return false;
|
||||
|
||||
printf("%s\n", xkb_keymap_get_as_string(keymap,
|
||||
XKB_KEYMAP_FORMAT_TEXT_V1));
|
||||
xkb_keymap_unref(keymap);
|
||||
return true;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
struct xkb_context *ctx;
|
||||
struct xkb_keymap *keymap;
|
||||
struct xkb_rule_names names = {
|
||||
.rules = NULL,
|
||||
.model = NULL,
|
||||
|
@ -135,15 +187,14 @@ main(int argc, char **argv)
|
|||
.variant = NULL,
|
||||
.options = NULL,
|
||||
};
|
||||
int rc;
|
||||
bool verbose = false;
|
||||
int rc = 1;
|
||||
|
||||
if (argc <= 1) {
|
||||
usage(argv);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!parse_options(argc, argv, &verbose, &names))
|
||||
if (!parse_options(argc, argv, &names))
|
||||
return 1;
|
||||
|
||||
ctx = xkb_context_new(XKB_CONTEXT_NO_DEFAULT_INCLUDES);
|
||||
|
@ -154,16 +205,15 @@ main(int argc, char **argv)
|
|||
xkb_context_set_log_verbosity(ctx, 10);
|
||||
}
|
||||
|
||||
xkb_context_sanitize_rule_names(ctx, &names);
|
||||
xkb_context_include_path_append_default(ctx);
|
||||
|
||||
keymap = xkb_keymap_new_from_names(ctx, &names, XKB_KEYMAP_COMPILE_NO_FLAGS);
|
||||
rc = (keymap == NULL);
|
||||
if (output_format == FORMAT_KEYMAP) {
|
||||
rc = print_keymap(ctx, &names) ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
} else if (output_format == FORMAT_KCCGST) {
|
||||
rc = print_kccgst(ctx, &names) ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (rc == 0)
|
||||
printf("%s\n", xkb_keymap_get_as_string(keymap,
|
||||
XKB_KEYMAP_FORMAT_TEXT_V1));
|
||||
|
||||
xkb_keymap_unref(keymap);
|
||||
xkb_context_unref(ctx);
|
||||
|
||||
return rc;
|
||||
|
|
Loading…
Reference in New Issue