4
* For history, see older versions.
7
%token EOL NUMBER LITERAL CHARSET KEYMAPS KEYCODE EQUALS
8
%token PLAIN SHIFT CONTROL ALT ALTGR SHIFTL SHIFTR CTRLL CTRLR CAPSSHIFT
9
%token COMMA DASH STRING STRLITERAL COMPOSE TO CCHAR ERROR PLUS
10
%token UNUMBER ALT_IS_META STRINGS AS USUAL ON FOR
21
#include <sys/param.h>
22
#include <sys/ioctl.h>
24
#include <linux/keyboard.h>
31
#include "modifiers.h"
36
#define U(x) ((x) ^ 0xf000)
39
typedef struct kbdiacruc accent_entry;
41
typedef struct kbdiacr accent_entry;
45
#define KT_LETTER KT_LATIN
51
/* What keymaps are we defining? */
52
char defining[MAX_NR_KEYMAPS];
53
char keymaps_line_seen = 0;
54
int max_keymap = 0; /* from here on, defining[] is false */
57
/* the kernel structures we want to set or print */
58
u_short *key_map[MAX_NR_KEYMAPS];
59
char *func_table[MAX_NR_FUNC];
61
accent_entry accent_table[MAX_DIACR];
62
unsigned int accent_table_size = 0;
64
char key_is_constant[NR_KEYS];
65
char *keymap_was_set[MAX_NR_KEYMAPS];
66
char func_buf[4096]; /* should be allocated dynamically */
69
int key_buf[MAX_NR_KEYMAPS];
71
int private_error_ct = 0;
74
extern struct kbsentry kbs_buf;
76
void lkfatal(const char *fmt, ...);
77
int yyerror(const char *s);
79
extern char *filename;
82
extern void stack_push(FILE *fd, int ispipe, char *filename);
83
extern int prefer_unicode;
88
static void attr_noreturn usage(void)
90
fprintf(stderr, _("loadkeys version %s\n"
92
"Usage: loadkeys [option...] [mapfile...]\n"
94
"Valid options are:\n"
96
" -a --ascii force conversion to ASCII\n"
97
" -b --bkeymap output a binary keymap to stdout\n"
98
" -c --clearcompose clear kernel compose table\n"
99
" -C <cons1,cons2,...> --console=<cons1,cons2,...>\n"
100
" the console device(s) to be used\n"
101
" -d --default load \"%s\"\n"
102
" -h --help display this help text\n"
103
" -m --mktable output a \"defkeymap.c\" to stdout\n"
104
" -q --quiet suppress all normal output\n"
105
" -s --clearstrings clear kernel string table\n"
106
" -u --unicode force conversion to Unicode\n"
107
" -v --verbose report the changes\n"),
108
PACKAGE_VERSION, DEFMAP);
113
char *dirpath1[] = { "", DATADIR "/" KEYMAPDIR "/**", KERNDIR "/", 0 };
114
char *dirpath2[] = { 0, 0 };
115
char *suffixes[] = { "", ".kmap", ".map", 0 };
128
int yyerror(const char *s)
130
fprintf(stderr, "%s:%d: %s\n", filename, line_nr, s);
135
void attr_noreturn attr_format_1_2 lkfatal(const char *fmt, ...)
139
fprintf(stderr, "%s: %s:%d: ", progname, filename, line_nr);
140
vfprintf(stderr, fmt, ap);
141
fprintf(stderr, "\n");
146
static void addmap(int i, int explicit)
148
if (i < 0 || i >= MAX_NR_KEYMAPS)
149
lkfatal(_("addmap called with bad index %d"), i);
152
if (keymaps_line_seen && !explicit)
153
lkfatal(_("adding map %d violates explicit keymaps line"), i);
162
static void killkey(int k_index, int k_table)
164
/* roughly: addkey(k_index, k_table, K_HOLE); */
166
if (k_index < 0 || k_index >= NR_KEYS)
167
lkfatal(_("killkey called with bad index %d"), k_index);
169
if (k_table < 0 || k_table >= MAX_NR_KEYMAPS)
170
lkfatal(_("killkey called with bad table %d"), k_table);
172
if (key_map[k_table])
173
(key_map[k_table])[k_index] = K_HOLE;
175
if (keymap_was_set[k_table])
176
(keymap_was_set[k_table])[k_index] = 0;
179
static void addkey(int k_index, int k_table, int keycode)
183
if (keycode == CODE_FOR_UNKNOWN_KSYM)
184
/* is safer not to be silent in this case,
185
* it can be caused by coding errors as well. */
186
lkfatal(_("addkey called with bad keycode %d"), keycode);
188
if (k_index < 0 || k_index >= NR_KEYS)
189
lkfatal(_("addkey called with bad index %d"), k_index);
191
if (k_table < 0 || k_table >= MAX_NR_KEYMAPS)
192
lkfatal(_("addkey called with bad table %d"), k_table);
194
if (!defining[k_table])
197
if (!key_map[k_table]) {
199
(u_short *) xmalloc(NR_KEYS * sizeof(u_short));
200
for (i = 0; i < NR_KEYS; i++)
201
(key_map[k_table])[i] = K_HOLE;
204
if (!keymap_was_set[k_table]) {
205
keymap_was_set[k_table] = (char *)xmalloc(NR_KEYS);
206
for (i = 0; i < NR_KEYS; i++)
207
(keymap_was_set[k_table])[i] = 0;
210
if (alt_is_meta && keycode == K_HOLE
211
&& (keymap_was_set[k_table])[k_index])
214
(key_map[k_table])[k_index] = keycode;
215
(keymap_was_set[k_table])[k_index] = 1;
218
int alttable = k_table | M_ALT;
219
int type = KTYP(keycode);
220
int val = KVAL(keycode);
222
if (alttable != k_table && defining[alttable] &&
223
(!keymap_was_set[alttable] ||
224
!(keymap_was_set[alttable])[k_index]) &&
225
(type == KT_LATIN || type == KT_LETTER) && val < 128)
226
addkey(k_index, alttable, K(KT_META, val));
230
static void addfunc(struct kbsentry kbs)
237
if (x >= MAX_NR_FUNC) {
238
fprintf(stderr, _("%s: addfunc called with bad func %d\n"),
239
progname, kbs.kb_func);
244
if (q) { /* throw out old previous def */
251
for (i = x + 1; i < MAX_NR_FUNC; i++) {
257
ptr = func_buf; /* find place for new def */
258
for (i = 0; i < x; i++) {
266
sh = strlen((char *)kbs.kb_string) + 1;
268
if (fp + sh > func_buf + sizeof(func_buf)) {
269
fprintf(stderr, _("%s: addfunc: func_buf overflow\n"), progname);
277
strcpy(ptr, (char *)kbs.kb_string);
278
for (i = x + 1; i < MAX_NR_FUNC; i++) {
284
static void compose(int diacr, int base, int res)
291
direction = TO_UNICODE;
296
if (accent_table_size == MAX_DIACR) {
297
fprintf(stderr, _("compose table overflow\n"));
301
ptr = &accent_table[accent_table_size++];
302
ptr->diacr = convert_code(diacr, direction);
303
ptr->base = convert_code(base, direction);
304
ptr->result = convert_code(res, direction);
307
static int defkeys(int fd, int kbd_mode)
314
/* temporarily switch to K_UNICODE while defining keys */
315
if (ioctl(fd, KDSKBMODE, K_UNICODE)) {
317
fprintf(stderr, _("%s: could not switch to Unicode mode\n"), progname);
322
for (i = 0; i < MAX_NR_KEYMAPS; i++) {
324
for (j = 0; j < NR_KEYS; j++) {
325
if ((keymap_was_set[i])[j]) {
328
ke.kb_value = (key_map[i])[j];
334
if (errno == EPERM) {
336
_("Keymap %d: Permission denied\n"),
345
printf(_("keycode %d, table %d = %d%s\n"),
346
j, i, (key_map[i])[j],
347
fail ? _(" FAILED") :
351
_("failed to bind key %d to value %d\n"),
356
xfree(keymap_was_set[i]);
358
} else if (keymaps_line_seen && !defining[i]) {
359
/* deallocate keymap */
362
ke.kb_value = K_NOSUCHMAP;
365
printf(_("deallocate keymap %d\n"), i);
367
if (ioctl(fd, KDSKBENT, (unsigned long)&ke)) {
368
if (errno != EINVAL) {
371
_("%s: could not deallocate keymap %d\n"),
375
/* probably an old kernel */
376
/* clear keymap by hand */
377
for (j = 0; j < NR_KEYS; j++) {
380
ke.kb_value = K_HOLE;
383
(unsigned long)&ke)) {
384
if (errno == EINVAL && i >= 16)
385
break; /* old kernel */
388
_("%s: cannot deallocate or clear keymap\n"),
397
if (optu && ioctl(fd, KDSKBMODE, kbd_mode)) {
400
_("%s: could not return to original keyboard mode\n"),
408
static char *ostr(char *s)
411
char *ns0 = xmalloc(4 * lth + 1);
435
static int deffuncs(int fd)
440
for (i = 0; i < MAX_NR_FUNC; i++) {
443
if ((ptr = func_table[i])) {
444
strcpy((char *)kbs_buf.kb_string, ptr);
445
if (ioctl(fd, KDSKBSENT, (unsigned long)&kbs_buf))
447
_("failed to bind string '%s' to function %s\n"),
448
ostr((char *)kbs_buf.kb_string),
449
syms[KT_FN].table[kbs_buf.kb_func]);
453
kbs_buf.kb_string[0] = 0;
454
if (ioctl(fd, KDSKBSENT, (unsigned long)&kbs_buf))
455
fprintf(stderr, _("failed to clear string %s\n"),
456
syms[KT_FN].table[kbs_buf.kb_func]);
464
static int defdiacs(int fd)
466
unsigned int i, count;
469
struct kbdiacrsuc kdu;
472
count = accent_table_size;
473
if (count > MAX_DIACR) {
475
fprintf(stderr, _("too many compose definitions\n"));
478
if (prefer_unicode) {
481
for (i = 0; i < kdu.kb_cnt; i++) {
482
kdu.kbdiacruc[i].diacr = accent_table[i].diacr;
483
kdu.kbdiacruc[i].base = accent_table[i].base;
484
kdu.kbdiacruc[i].result = accent_table[i].result;
487
if (ioctl(fd, KDSKBDIACRUC, (unsigned long)&kdu)) {
488
perror("KDSKBDIACRUC");
495
for (i = 0; i < kd.kb_cnt; i++) {
496
kd.kbdiacr[i].diacr = accent_table[i].diacr;
497
kd.kbdiacr[i].base = accent_table[i].base;
498
kd.kbdiacr[i].result = accent_table[i].result;
501
if (ioctl(fd, KDSKBDIACR, (unsigned long)&kd)) {
502
perror("KDSKBDIACR");
510
static void do_constant_key(int i, u_short key)
517
if ((typ == KT_LATIN || typ == KT_LETTER) &&
518
((val >= 'a' && val <= 'z') || (val >= 'A' && val <= 'Z'))) {
520
defs[0] = K(KT_LETTER, val);
521
defs[1] = K(KT_LETTER, val ^ 32);
525
for (j = 4; j < 8; j++)
526
defs[j] = K(KT_LATIN, val & ~96);
528
for (j = 8; j < 16; j++)
529
defs[j] = K(KT_META, KVAL(defs[j - 8]));
531
for (j = 0; j < max_keymap; j++) {
536
keymap_was_set[j] && (keymap_was_set[j])[i])
539
addkey(i, j, defs[j % 16]);
543
/* do this also for keys like Escape,
544
as promised in the man page */
545
for (j = 1; j < max_keymap; j++) {
547
(!(keymap_was_set[j]) || !(keymap_was_set[j])[i]))
553
static void do_constant(void)
557
if (keymaps_line_seen) {
558
while (r0 < max_keymap && !defining[r0])
562
for (i = 0; i < NR_KEYS; i++) {
563
if (key_is_constant[i]) {
567
lkfatal(_("impossible error in do_constant"));
569
key = (key_map[r0])[i];
570
do_constant_key(i, key);
575
static void loadkeys(char *console, int kbd_mode)
578
int keyct, funcct, diacct = 0;
581
keyct = defkeys(fd, kbd_mode);
582
funcct = deffuncs(fd);
585
printf(_("\nChanged %d %s and %d %s.\n"),
586
keyct, (keyct == 1) ? _("key") : _("keys"),
587
funcct, (funcct == 1) ? _("string") : _("strings"));
590
if (accent_table_size > 0 || nocompose) {
591
diacct = defdiacs(fd);
594
printf(_("Loaded %d compose %s.\n"),
595
diacct, (diacct == 1) ? _("definition") : _("definitions"));
598
} else if (verbose) {
599
printf(_("(No change in compose definitions.)\n"));
603
static void strings_as_usual(void)
606
* 26 strings, mostly inspired by the VT100 family
608
char *stringvalues[30] = {
610
"\033[[A", "\033[[B", "\033[[C", "\033[[D", "\033[[E",
611
"\033[17~", "\033[18~", "\033[19~", "\033[20~", "\033[21~",
612
"\033[23~", "\033[24~", "\033[25~", "\033[26~",
613
"\033[28~", "\033[29~",
614
"\033[31~", "\033[32~", "\033[33~", "\033[34~",
615
/* Find, Insert, Remove, Select, Prior */
616
"\033[1~", "\033[2~", "\033[3~", "\033[4~", "\033[5~",
617
/* Next, Macro, Help, Do, Pause */
618
"\033[6~", 0, 0, 0, 0
622
for (i = 0; i < 30; i++) {
623
if (stringvalues[i]) {
626
strncpy((char *)ke.kb_string, stringvalues[i],
627
sizeof(ke.kb_string));
628
ke.kb_string[sizeof(ke.kb_string) - 1] = 0;
634
static void compose_as_usual(char *charset)
636
if (charset && strcmp(charset, "iso-8859-1")) {
637
fprintf(stderr, _("loadkeys: don't know how to compose for %s\n"),
643
unsigned char c1, c2, c3;
644
} def_latin1_composes[68] = {
645
{ '`', 'A', 0300 }, { '`', 'a', 0340 },
646
{ '\'', 'A', 0301 }, { '\'', 'a', 0341 },
647
{ '^', 'A', 0302 }, { '^', 'a', 0342 },
648
{ '~', 'A', 0303 }, { '~', 'a', 0343 },
649
{ '"', 'A', 0304 }, { '"', 'a', 0344 },
650
{ 'O', 'A', 0305 }, { 'o', 'a', 0345 },
651
{ '0', 'A', 0305 }, { '0', 'a', 0345 },
652
{ 'A', 'A', 0305 }, { 'a', 'a', 0345 },
653
{ 'A', 'E', 0306 }, { 'a', 'e', 0346 },
654
{ ',', 'C', 0307 }, { ',', 'c', 0347 },
655
{ '`', 'E', 0310 }, { '`', 'e', 0350 },
656
{ '\'', 'E', 0311 }, { '\'', 'e', 0351 },
657
{ '^', 'E', 0312 }, { '^', 'e', 0352 },
658
{ '"', 'E', 0313 }, { '"', 'e', 0353 },
659
{ '`', 'I', 0314 }, { '`', 'i', 0354 },
660
{ '\'', 'I', 0315 }, { '\'', 'i', 0355 },
661
{ '^', 'I', 0316 }, { '^', 'i', 0356 },
662
{ '"', 'I', 0317 }, { '"', 'i', 0357 },
663
{ '-', 'D', 0320 }, { '-', 'd', 0360 },
664
{ '~', 'N', 0321 }, { '~', 'n', 0361 },
665
{ '`', 'O', 0322 }, { '`', 'o', 0362 },
666
{ '\'', 'O', 0323 }, { '\'', 'o', 0363 },
667
{ '^', 'O', 0324 }, { '^', 'o', 0364 },
668
{ '~', 'O', 0325 }, { '~', 'o', 0365 },
669
{ '"', 'O', 0326 }, { '"', 'o', 0366 },
670
{ '/', 'O', 0330 }, { '/', 'o', 0370 },
671
{ '`', 'U', 0331 }, { '`', 'u', 0371 },
672
{ '\'', 'U', 0332 }, { '\'', 'u', 0372 },
673
{ '^', 'U', 0333 }, { '^', 'u', 0373 },
674
{ '"', 'U', 0334 }, { '"', 'u', 0374 },
675
{ '\'', 'Y', 0335 }, { '\'', 'y', 0375 },
676
{ 'T', 'H', 0336 }, { 't', 'h', 0376 },
677
{ 's', 's', 0337 }, { '"', 'y', 0377 },
678
{ 's', 'z', 0337 }, { 'i', 'j', 0377 }
681
for (i = 0; i < 68; i++) {
682
struct ccc ptr = def_latin1_composes[i];
683
compose(ptr.c1, ptr.c2, ptr.c3);
692
static char *modifiers[8] = {
693
"shift", "altgr", "ctrl", "alt", "shl", "shr", "ctl", "ctr"
696
static char *mk_mapname(char modifier)
704
for (i = 0; i < 8; i++)
705
if (modifier & (1 << i)) {
708
strcat(buf, modifiers[i]);
713
static void outchar(unsigned char c, int comma)
716
printf((c == '\'' || c == '\\') ? "\\%c" : isgraph(c) ? "%c"
718
printf(comma ? "', " : "'");
721
static void attr_noreturn mktable(void)
724
unsigned int i, imax;
727
unsigned int maxfunc;
728
unsigned int keymap_count = 0;
731
/* not to be translated... */
732
"/* Do not edit this file! It was automatically generated by */\n");
734
("/* loadkeys --mktable defkeymap.map > defkeymap.c */\n\n");
735
printf("#include <linux/types.h>\n");
736
printf("#include <linux/keyboard.h>\n");
737
printf("#include <linux/kd.h>\n\n");
739
for (i = 0; i < MAX_NR_KEYMAPS; i++)
744
printf("u_short %s_map[NR_KEYS] = {", mk_mapname(i));
745
for (j = 0; j < NR_KEYS; j++) {
748
printf("\t0x%04x,", U((key_map[i])[j]));
753
for (imax = MAX_NR_KEYMAPS - 1; imax > 0; imax--)
756
printf("ushort *key_maps[MAX_NR_KEYMAPS] = {");
757
for (i = 0; i <= imax; i++) {
758
printf((i % 4) ? " " : "\n\t");
760
printf("%s_map,", mk_mapname(i));
764
if (imax < MAX_NR_KEYMAPS - 1)
766
printf("\n};\n\nunsigned int keymap_count = %d;\n\n", keymap_count);
768
/* uglified just for xgettext - it complains about nonterminated strings */
770
" * Philosophy: most people do not define more strings, but they who do\n"
771
" * often want quite a lot of string space. So, we statically allocate\n"
772
" * the default and allocate dynamically in chunks of 512 bytes.\n"
774
for (maxfunc = MAX_NR_FUNC; maxfunc; maxfunc--)
775
if (func_table[maxfunc - 1])
778
printf("char func_buf[] = {\n");
779
for (i = 0; i < maxfunc; i++) {
792
printf("char *funcbufptr = func_buf;\n"
793
"int funcbufsize = sizeof(func_buf);\n"
794
"int funcbufleft = 0; /* space left */\n" "\n");
796
printf("char *func_table[MAX_NR_FUNC] = {\n");
797
for (i = 0; i < maxfunc; i++) {
799
printf("\tfunc_buf + %ld,\n",
800
(long)(func_table[i] - func_buf));
804
if (maxfunc < MAX_NR_FUNC)
809
if (prefer_unicode) {
810
printf("\nstruct kbdiacruc accent_table[MAX_DIACR] = {\n");
811
for (i = 0; i < accent_table_size; i++) {
813
outchar(accent_table[i].diacr, 1);
814
outchar(accent_table[i].base, 1);
815
printf("0x%04x},", accent_table[i].result);
825
printf("\nstruct kbdiacr accent_table[MAX_DIACR] = {\n");
826
for (i = 0; i < accent_table_size; i++) {
828
outchar(accent_table[i].diacr, 1);
829
outchar(accent_table[i].base, 1);
830
outchar(accent_table[i].result, 0);
839
printf("unsigned int accent_table_size = %d;\n", accent_table_size);
844
static void attr_noreturn bkeymap(void)
849
char flag, magic[] = "bkeymap";
852
if (write(1, magic, 7) == -1)
854
for (i = 0; i < MAX_NR_KEYMAPS; i++) {
855
flag = key_map[i] ? 1 : 0;
856
if (write(1, &flag, 1) == -1)
859
for (i = 0; i < MAX_NR_KEYMAPS; i++) {
861
for (j = 0; j < NR_KEYS / 2; j++) {
863
if (write(1, &v, 2) == -1)
870
fail: fprintf(stderr, _("Error writing map to file\n"));
891
charsetline : CHARSET STRLITERAL EOL
893
set_charset((char *) kbs_buf.kb_string);
896
altismetaline : ALT_IS_META EOL
901
usualstringsline: STRINGS AS USUAL EOL
906
usualcomposeline: COMPOSE AS USUAL FOR STRLITERAL EOL
908
compose_as_usual((char *) kbs_buf.kb_string);
910
| COMPOSE AS USUAL EOL
915
keymapline : KEYMAPS range EOL
917
keymaps_line_seen = 1;
920
range : range COMMA range0
923
range0 : NUMBER DASH NUMBER
926
for (i = $1; i <= $3; i++)
934
strline : STRING LITERAL EQUALS STRLITERAL EOL
936
if (KTYP($2) != KT_FN)
937
lkfatal(_("'%s' is not a function key symbol"),
938
syms[KTYP($2)].table[KVAL($2)]);
939
kbs_buf.kb_func = KVAL($2);
943
compline : COMPOSE compsym compsym TO compsym EOL
947
| COMPOSE compsym compsym TO rvalue EOL
952
compsym : CCHAR { $$ = $1; }
953
| UNUMBER { $$ = $1 ^ 0xf000; }
958
modifiers KEYCODE NUMBER EQUALS rvalue EOL
962
| PLAIN KEYCODE NUMBER EQUALS rvalue EOL
967
modifiers : modifiers modifier
970
modifier : SHIFT { mod |= M_SHIFT; }
971
| CONTROL { mod |= M_CTRL; }
972
| ALT { mod |= M_ALT; }
973
| ALTGR { mod |= M_ALTGR; }
974
| SHIFTL { mod |= M_SHIFTL; }
975
| SHIFTR { mod |= M_SHIFTR; }
976
| CTRLL { mod |= M_CTRLL; }
977
| CTRLR { mod |= M_CTRLR; }
978
| CAPSSHIFT { mod |= M_CAPSSHIFT; }
980
fullline : KEYCODE NUMBER EQUALS rvalue0 EOL
985
/* Some files do not have a keymaps line, and
986
* we have to wait until all input has been read
987
* before we know which maps to fill. */
988
key_is_constant[$2] = 1;
990
/* On the other hand, we now have include files,
991
* and it should be possible to override lines
992
* from an include file. So, kill old defs. */
993
for (j = 0; j < max_keymap; j++) {
999
if (keymaps_line_seen) {
1002
for (j = 0; j < max_keymap; j++) {
1004
if (rvalct != 1 || i == 0)
1005
addkey($2, j, (i < rvalct) ? key_buf[i] : K_HOLE);
1011
lkfatal(_("too many (%d) entries on one line"), rvalct);
1013
for (i = 0; i < rvalct; i++)
1014
addkey($2, i, key_buf[i]);
1024
if (rvalct >= MAX_NR_KEYMAPS)
1025
lkfatal(_("too many key definitions on one line"));
1026
key_buf[rvalct++] = $1;
1029
rvalue : NUMBER { $$ = convert_code($1, TO_AUTO); }
1030
| PLUS NUMBER { $$ = add_capslock($2); }
1031
| UNUMBER { $$ = convert_code($1^0xf000, TO_AUTO); }
1032
| PLUS UNUMBER { $$ = add_capslock($2^0xf000); }
1033
| LITERAL { $$ = $1; }
1034
| PLUS LITERAL { $$ = add_capslock($2); }
1038
int main(int argc, char *argv[])
1040
const char *short_opts = "abcC:dhmsuqvV";
1041
const struct option long_opts[] = {
1042
{ "console", required_argument, NULL, 'C'},
1043
{ "ascii", no_argument, NULL, 'a' },
1044
{ "bkeymap", no_argument, NULL, 'b' },
1045
{ "clearcompose", no_argument, NULL, 'c' },
1046
{ "default", no_argument, NULL, 'd' },
1047
{ "help", no_argument, NULL, 'h' },
1048
{ "mktable", no_argument, NULL, 'm' },
1049
{ "clearstrings", no_argument, NULL, 's' },
1050
{ "unicode", no_argument, NULL, 'u' },
1051
{ "quiet", no_argument, NULL, 'q' },
1052
{ "verbose", no_argument, NULL, 'v' },
1053
{ "version", no_argument, NULL, 'V' },
1054
{ NULL, 0, NULL, 0 }
1060
char *console = NULL;
1062
set_progname(argv[0]);
1064
setlocale(LC_ALL, "");
1065
bindtextdomain(PACKAGE_NAME, LOCALEDIR);
1066
textdomain(PACKAGE_NAME);
1068
while ((c = getopt_long(argc, argv, short_opts, long_opts, NULL)) != -1) {
1101
print_version_and_exit();
1110
_("%s: Options --unicode and --ascii are mutually exclusive\n"),
1115
prefer_unicode = optu;
1117
if (!optm && !optb) {
1118
/* check whether the keyboard is in Unicode mode */
1119
fd = getfd(console);
1121
if (ioctl(fd, KDGKBMODE, &kbd_mode)) {
1122
perror("KDGKBMODE");
1123
fprintf(stderr, _("%s: error reading keyboard mode\n"),
1128
if (kbd_mode == K_UNICODE) {
1131
_("%s: warning: loading non-Unicode keymap on Unicode console\n"
1132
" (perhaps you want to do `kbd_mode -a'?)\n"),
1138
/* reset -u option if keyboard is in K_UNICODE anyway */
1141
&& (ioctl(fd, KDGETMODE, &kd_mode) || (kd_mode != KD_GRAPHICS)))
1143
_("%s: warning: loading Unicode keymap on non-Unicode console\n"
1144
" (perhaps you want to do `kbd_mode -u'?)\n"),
1150
for (i = optind; argv[i]; i++) {
1155
if ((ev = getenv("LOADKEYS_KEYMAP_PATH")) != NULL) {
1156
if (!quiet && !optm)
1157
fprintf(stdout, _("Searching in %s\n"), ev);
1164
/* first read default map - search starts in . */
1166
if ((f = findfile(DEFMAP, dirpath, suffixes)) == NULL) {
1167
fprintf(stderr, _("Cannot find %s\n"), DEFMAP);
1173
if (!strcmp(argv[i], "-")) {
1175
strcpy(pathname, "<stdin>");
1177
} else if ((f = findfile(argv[i], dirpath, suffixes)) == NULL) {
1178
fprintf(stderr, _("cannot open file %s\n"), argv[i]);
1183
if (!quiet && !optm)
1184
fprintf(stdout, _("Loading %s\n"), pathname);
1186
stack_push(f, 0, pathname);
1189
fprintf(stderr, _("syntax error in map file\n"));
1193
_("key bindings not changed\n"));
1206
} else if (console) {
1207
char *buf = strdup(console); /* make writable */
1212
while (*s == ' ' || *s == '\t' || *s == ',')
1215
while (*e && *e != ' ' && *e != '\t' && *e != ',')
1223
loadkeys(s, kbd_mode);
1231
loadkeys(NULL, kbd_mode);