|
Packit Service |
50ad14 |
/*
|
|
Packit Service |
50ad14 |
* dumpkeys.c
|
|
Packit Service |
50ad14 |
*
|
|
Packit Service |
50ad14 |
* derived from version 0.81 - aeb@cwi.nl
|
|
Packit Service |
50ad14 |
*/
|
|
Packit Service |
50ad14 |
#include "config.h"
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
#include <stdio.h>
|
|
Packit Service |
50ad14 |
#include <stdlib.h>
|
|
Packit Service |
50ad14 |
#include <ctype.h>
|
|
Packit Service |
50ad14 |
#include <fcntl.h>
|
|
Packit Service |
50ad14 |
#include <getopt.h>
|
|
Packit Service |
50ad14 |
#include <unistd.h>
|
|
Packit Service |
50ad14 |
#include <linux/kd.h>
|
|
Packit Service |
50ad14 |
#include <linux/keyboard.h>
|
|
Packit Service |
50ad14 |
#include <sys/ioctl.h>
|
|
Packit Service |
50ad14 |
#include <string.h>
|
|
Packit Service |
50ad14 |
#include <errno.h>
|
|
Packit Service |
50ad14 |
#include "ksyms.h"
|
|
Packit Service |
50ad14 |
#include "getfd.h"
|
|
Packit Service |
50ad14 |
#include "modifiers.h"
|
|
Packit Service |
50ad14 |
#include "nls.h"
|
|
Packit Service |
50ad14 |
#include "version.h"
|
|
Packit Service |
50ad14 |
#include "kbd_error.h"
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
static int fd;
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
static void __attribute__((noreturn))
|
|
Packit Service |
50ad14 |
usage(void)
|
|
Packit Service |
50ad14 |
{
|
|
Packit Service |
50ad14 |
fprintf(stderr, _("dumpkeys version %s"), PACKAGE_VERSION);
|
|
Packit Service |
50ad14 |
fprintf(stderr, _("\
|
|
Packit Service |
50ad14 |
\n\
|
|
Packit Service |
50ad14 |
usage: dumpkeys [options...]\n\
|
|
Packit Service |
50ad14 |
\n\
|
|
Packit Service |
50ad14 |
valid options are:\n\
|
|
Packit Service |
50ad14 |
\n\
|
|
Packit Service |
50ad14 |
-h --help display this help text\n\
|
|
Packit Service |
50ad14 |
-i --short-info display information about keyboard driver\n\
|
|
Packit Service |
50ad14 |
-l -s --long-info display above and symbols known to loadkeys\n\
|
|
Packit Service |
50ad14 |
-n --numeric display keytable in hexadecimal notation\n\
|
|
Packit Service |
50ad14 |
-f --full-table don't use short-hand notations, one row per keycode\n\
|
|
Packit Service |
50ad14 |
-1 --separate-lines one line per (modifier,keycode) pair\n\
|
|
Packit Service |
50ad14 |
-S --shape=\n\
|
|
Packit Service |
50ad14 |
-t --funcs-only display only the function key strings\n\
|
|
Packit Service |
50ad14 |
-k --keys-only display only key bindings\n\
|
|
Packit Service |
50ad14 |
-d --compose-only display only compose key combinations\n\
|
|
Packit Service |
50ad14 |
-c --charset="));
|
|
Packit Service |
50ad14 |
lk_list_charsets(stderr);
|
|
Packit Service |
50ad14 |
fprintf(stderr, _("\
|
|
Packit Service |
50ad14 |
interpret character action codes to be from the\n\
|
|
Packit Service |
50ad14 |
specified character set\n\
|
|
Packit Service |
50ad14 |
"));
|
|
Packit Service |
50ad14 |
fprintf(stderr, _("\
|
|
Packit Service |
50ad14 |
-v --verbose\n\
|
|
Packit Service |
50ad14 |
-V --version print version number\n\
|
|
Packit Service |
50ad14 |
"));
|
|
Packit Service |
50ad14 |
exit(1);
|
|
Packit Service |
50ad14 |
}
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
int main(int argc, char *argv[])
|
|
Packit Service |
50ad14 |
{
|
|
Packit Service |
50ad14 |
const char *short_opts = "hilvsnf1tkdS:c:V";
|
|
Packit Service |
50ad14 |
const struct option long_opts[] = {
|
|
Packit Service |
50ad14 |
{ "help", no_argument, NULL, 'h' },
|
|
Packit Service |
50ad14 |
{ "short-info", no_argument, NULL, 'i' },
|
|
Packit Service |
50ad14 |
{ "long-info", no_argument, NULL, 'l' },
|
|
Packit Service |
50ad14 |
{ "numeric", no_argument, NULL, 'n' },
|
|
Packit Service |
50ad14 |
{ "full-table", no_argument, NULL, 'f' },
|
|
Packit Service |
50ad14 |
{ "separate-lines", no_argument, NULL, '1' },
|
|
Packit Service |
50ad14 |
{ "shape", required_argument, NULL, 'S' },
|
|
Packit Service |
50ad14 |
{ "funcs-only", no_argument, NULL, 't' },
|
|
Packit Service |
50ad14 |
{ "keys-only", no_argument, NULL, 'k' },
|
|
Packit Service |
50ad14 |
{ "compose-only", no_argument, NULL, 'd' },
|
|
Packit Service |
50ad14 |
{ "charset", required_argument, NULL, 'c' },
|
|
Packit Service |
50ad14 |
{ "verbose", no_argument, NULL, 'v' },
|
|
Packit Service |
50ad14 |
{ "version", no_argument, NULL, 'V' },
|
|
Packit Service |
50ad14 |
{ NULL, 0, NULL, 0 }
|
|
Packit Service |
50ad14 |
};
|
|
Packit Service |
50ad14 |
int c, rc;
|
|
Packit Service |
50ad14 |
int kbd_mode;
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
char long_info = 0;
|
|
Packit Service |
50ad14 |
char short_info = 0;
|
|
Packit Service |
50ad14 |
char numeric = 0;
|
|
Packit Service |
50ad14 |
lk_table_shape table = LK_SHAPE_DEFAULT;
|
|
Packit Service |
50ad14 |
char funcs_only = 0;
|
|
Packit Service |
50ad14 |
char keys_only = 0;
|
|
Packit Service |
50ad14 |
char diac_only = 0;
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
struct lk_ctx *ctx;
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
set_progname(argv[0]);
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
setlocale(LC_ALL, "");
|
|
Packit Service |
50ad14 |
bindtextdomain(PACKAGE_NAME, LOCALEDIR);
|
|
Packit Service |
50ad14 |
textdomain(PACKAGE_NAME);
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
ctx = lk_init();
|
|
Packit Service |
50ad14 |
if (!ctx) {
|
|
Packit Service |
50ad14 |
exit(EXIT_FAILURE);
|
|
Packit Service |
50ad14 |
}
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
while ((c = getopt_long(argc, argv,
|
|
Packit Service |
50ad14 |
short_opts, long_opts, NULL)) != -1) {
|
|
Packit Service |
50ad14 |
switch (c) {
|
|
Packit Service |
50ad14 |
case 'i':
|
|
Packit Service |
50ad14 |
short_info = 1;
|
|
Packit Service |
50ad14 |
break;
|
|
Packit Service |
50ad14 |
case 's':
|
|
Packit Service |
50ad14 |
case 'l':
|
|
Packit Service |
50ad14 |
long_info = 1;
|
|
Packit Service |
50ad14 |
break;
|
|
Packit Service |
50ad14 |
case 'n':
|
|
Packit Service |
50ad14 |
numeric = 1;
|
|
Packit Service |
50ad14 |
break;
|
|
Packit Service |
50ad14 |
case 'f':
|
|
Packit Service |
50ad14 |
table = LK_SHAPE_FULL_TABLE;
|
|
Packit Service |
50ad14 |
break;
|
|
Packit Service |
50ad14 |
case '1':
|
|
Packit Service |
50ad14 |
table = LK_SHAPE_SEPARATE_LINES;
|
|
Packit Service |
50ad14 |
break;
|
|
Packit Service |
50ad14 |
case 'S':
|
|
Packit Service |
50ad14 |
table = atoi(optarg);
|
|
Packit Service |
50ad14 |
break;
|
|
Packit Service |
50ad14 |
case 't':
|
|
Packit Service |
50ad14 |
funcs_only = 1;
|
|
Packit Service |
50ad14 |
break;
|
|
Packit Service |
50ad14 |
case 'k':
|
|
Packit Service |
50ad14 |
keys_only = 1;
|
|
Packit Service |
50ad14 |
break;
|
|
Packit Service |
50ad14 |
case 'd':
|
|
Packit Service |
50ad14 |
diac_only = 1;
|
|
Packit Service |
50ad14 |
break;
|
|
Packit Service |
50ad14 |
case 'v':
|
|
Packit Service |
50ad14 |
lk_set_log_priority(ctx, LOG_INFO);
|
|
Packit Service |
50ad14 |
break;
|
|
Packit Service |
50ad14 |
case 'c':
|
|
Packit Service |
50ad14 |
if ((lk_set_charset(ctx, optarg)) != 0) {
|
|
Packit Service |
50ad14 |
fprintf(stderr, _("unknown charset %s - ignoring charset request\n"),
|
|
Packit Service |
50ad14 |
optarg);
|
|
Packit Service |
50ad14 |
usage();
|
|
Packit Service |
50ad14 |
}
|
|
Packit Service |
50ad14 |
printf("charset \"%s\"\n", optarg);
|
|
Packit Service |
50ad14 |
break;
|
|
Packit Service |
50ad14 |
case 'V':
|
|
Packit Service |
50ad14 |
print_version_and_exit();
|
|
Packit Service |
50ad14 |
case 'h':
|
|
Packit Service |
50ad14 |
case '?':
|
|
Packit Service |
50ad14 |
usage();
|
|
Packit Service |
50ad14 |
}
|
|
Packit Service |
50ad14 |
}
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
if (optind < argc)
|
|
Packit Service |
50ad14 |
usage();
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
if ((fd = getfd(NULL)) < 0)
|
|
Packit Service |
50ad14 |
kbd_error(EXIT_FAILURE, 0, _("Couldn't get a file descriptor referring to the console"));
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
/* check whether the keyboard is in Unicode mode */
|
|
Packit Service |
50ad14 |
if (ioctl(fd, KDGKBMODE, &kbd_mode)) {
|
|
Packit Service |
50ad14 |
fprintf(stderr, _("%s: error reading keyboard mode: %m\n"),
|
|
Packit Service |
50ad14 |
progname);
|
|
Packit Service |
50ad14 |
exit(EXIT_FAILURE);
|
|
Packit Service |
50ad14 |
}
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
if (kbd_mode == K_UNICODE) {
|
|
Packit Service |
50ad14 |
lk_set_parser_flags(ctx, LK_FLAG_PREFER_UNICODE);
|
|
Packit Service |
50ad14 |
}
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
if ((rc = lk_kernel_keymap(ctx, fd)) < 0)
|
|
Packit Service |
50ad14 |
goto fail;
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
if (short_info || long_info) {
|
|
Packit Service |
50ad14 |
lk_dump_summary(ctx, stdout, fd);
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
if (long_info) {
|
|
Packit Service |
50ad14 |
printf(_("Symbols recognized by %s:\n(numeric value, symbol)\n\n"),
|
|
Packit Service |
50ad14 |
progname);
|
|
Packit Service |
50ad14 |
lk_dump_symbols(ctx, stdout);
|
|
Packit Service |
50ad14 |
}
|
|
Packit Service |
50ad14 |
exit(EXIT_SUCCESS);
|
|
Packit Service |
50ad14 |
}
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
#ifdef KDGKBDIACR
|
|
Packit Service |
50ad14 |
if (!diac_only) {
|
|
Packit Service |
50ad14 |
#endif
|
|
Packit Service |
50ad14 |
if (!funcs_only) {
|
|
Packit Service |
50ad14 |
lk_dump_keymap(ctx, stdout, table, numeric);
|
|
Packit Service |
50ad14 |
}
|
|
Packit Service |
50ad14 |
#ifdef KDGKBDIACR
|
|
Packit Service |
50ad14 |
}
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
if (!funcs_only && !keys_only)
|
|
Packit Service |
50ad14 |
lk_dump_diacs(ctx, stdout);
|
|
Packit Service |
50ad14 |
#endif
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
fail:
|
|
Packit Service |
50ad14 |
lk_free(ctx);
|
|
Packit Service |
50ad14 |
close(fd);
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
if (rc < 0)
|
|
Packit Service |
50ad14 |
exit(EXIT_FAILURE);
|
|
Packit Service |
50ad14 |
|
|
Packit Service |
50ad14 |
exit(EXIT_SUCCESS);
|
|
Packit Service |
50ad14 |
}
|