~ubuntu-branches/ubuntu/trusty/kbd/trusty

« back to all changes in this revision

Viewing changes to .pc/loadkeys_stdin.diff/src/loadkeys.y

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2013-02-18 13:25:55 UTC
  • mfrom: (1.1.22 sid)
  • Revision ID: package-import@ubuntu.com-20130218132555-9aiwvswlo12fo32s
Tags: 1.15.5-1ubuntu1
* Resynchronise with Debian.  Remaining changes:
  - Add setfont, kbd_mode, and loadkeys to initramfs for console-setup.
  - Use ckbcomp to get the keyboard layout if other data files are not
    available.
  - Depend on console-setup, and remove config file; we now only support
    systems using console-setup and so it no longer serves a purpose. The
    removed config file for console-screen has changed names from
    /etc/init.d/console-screen.kbd.sh to /etc/init.d/kbd.
  - Change loadkeys to find any console not in raw mode when invoked
    without an explicit console parameter, in case the foreground console
    is in raw mode.
  - Simplify maintainer scripts for conffile removal, using new features
    in debhelper 8.1.0.
  - Add setvtrgb to kbd-udeb.
* Fix incorrect keymap sanity check in loadkeys_ckbcomp.diff.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * loadkeys.y
3
 
 *
4
 
 * For history, see older versions.
5
 
 */
6
 
 
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
11
 
 
12
 
%{
13
 
#include <errno.h>
14
 
#include <stdio.h>
15
 
#include <getopt.h>
16
 
#include <stdlib.h>
17
 
#include <stdarg.h>
18
 
#include <string.h>
19
 
#include <fcntl.h>
20
 
#include <ctype.h>
21
 
#include <sys/param.h>
22
 
#include <sys/ioctl.h>
23
 
#include <linux/kd.h>
24
 
#include <linux/keyboard.h>
25
 
#include <unistd.h>
26
 
 
27
 
#include "paths.h"
28
 
#include "getfd.h"
29
 
#include "findfile.h"
30
 
#include "ksyms.h"
31
 
#include "modifiers.h"
32
 
#include "xmalloc.h"
33
 
#include "nls.h"
34
 
#include "version.h"
35
 
 
36
 
#define U(x) ((x) ^ 0xf000)
37
 
 
38
 
#ifdef KDSKBDIACRUC
39
 
typedef struct kbdiacruc accent_entry;
40
 
#else
41
 
typedef struct kbdiacr accent_entry;
42
 
#endif
43
 
 
44
 
#ifndef KT_LETTER
45
 
#define KT_LETTER KT_LATIN
46
 
#endif
47
 
 
48
 
#undef NR_KEYS
49
 
#define NR_KEYS 256
50
 
 
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 */
55
 
int alt_is_meta = 0;
56
 
 
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];
60
 
 
61
 
accent_entry accent_table[MAX_DIACR];
62
 
unsigned int accent_table_size = 0;
63
 
 
64
 
char key_is_constant[NR_KEYS];
65
 
char *keymap_was_set[MAX_NR_KEYMAPS];
66
 
char func_buf[4096];    /* should be allocated dynamically */
67
 
char *fp = func_buf;
68
 
 
69
 
int key_buf[MAX_NR_KEYMAPS];
70
 
int mod;
71
 
int private_error_ct = 0;
72
 
 
73
 
extern int rvalct;
74
 
extern struct kbsentry kbs_buf;
75
 
 
76
 
void lkfatal(const char *fmt, ...);
77
 
int yyerror(const char *s);
78
 
 
79
 
extern char *filename;
80
 
extern int line_nr;
81
 
 
82
 
extern void stack_push(FILE *fd, int ispipe, char *filename);
83
 
extern int prefer_unicode;
84
 
 
85
 
#include "ksyms.h"
86
 
int yylex(void);
87
 
 
88
 
static void attr_noreturn usage(void)
89
 
{
90
 
        fprintf(stderr, _("loadkeys version %s\n"
91
 
                          "\n"
92
 
                          "Usage: loadkeys [option...] [mapfile...]\n"
93
 
                          "\n"
94
 
                          "Valid options are:\n"
95
 
                          "\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);
109
 
        exit(EXIT_FAILURE);
110
 
}
111
 
 
112
 
char **dirpath;
113
 
char *dirpath1[] = { "", DATADIR "/" KEYMAPDIR "/**", KERNDIR "/", 0 };
114
 
char *dirpath2[] = { 0, 0 };
115
 
char *suffixes[] = { "", ".kmap", ".map", 0 };
116
 
 
117
 
char **args;
118
 
int opta = 0;
119
 
int optb = 0;
120
 
int optd = 0;
121
 
int optm = 0;
122
 
int opts = 0;
123
 
int optu = 0;
124
 
int verbose = 0;
125
 
int quiet = 0;
126
 
int nocompose = 0;
127
 
 
128
 
int yyerror(const char *s)
129
 
{
130
 
        fprintf(stderr, "%s:%d: %s\n", filename, line_nr, s);
131
 
        private_error_ct++;
132
 
        return (0);
133
 
}
134
 
 
135
 
void attr_noreturn attr_format_1_2 lkfatal(const char *fmt, ...)
136
 
{
137
 
        va_list ap;
138
 
        va_start(ap, fmt);
139
 
        fprintf(stderr, "%s: %s:%d: ", progname, filename, line_nr);
140
 
        vfprintf(stderr, fmt, ap);
141
 
        fprintf(stderr, "\n");
142
 
        va_end(ap);
143
 
        exit(EXIT_FAILURE);
144
 
}
145
 
 
146
 
static void addmap(int i, int explicit)
147
 
{
148
 
        if (i < 0 || i >= MAX_NR_KEYMAPS)
149
 
                lkfatal(_("addmap called with bad index %d"), i);
150
 
 
151
 
        if (!defining[i]) {
152
 
                if (keymaps_line_seen && !explicit)
153
 
                        lkfatal(_("adding map %d violates explicit keymaps line"), i);
154
 
 
155
 
                defining[i] = 1;
156
 
                if (max_keymap <= i)
157
 
                        max_keymap = i + 1;
158
 
        }
159
 
}
160
 
 
161
 
/* unset a key */
162
 
static void killkey(int k_index, int k_table)
163
 
{
164
 
        /* roughly: addkey(k_index, k_table, K_HOLE); */
165
 
 
166
 
        if (k_index < 0 || k_index >= NR_KEYS)
167
 
                lkfatal(_("killkey called with bad index %d"), k_index);
168
 
 
169
 
        if (k_table < 0 || k_table >= MAX_NR_KEYMAPS)
170
 
                lkfatal(_("killkey called with bad table %d"), k_table);
171
 
 
172
 
        if (key_map[k_table])
173
 
                (key_map[k_table])[k_index] = K_HOLE;
174
 
 
175
 
        if (keymap_was_set[k_table])
176
 
                (keymap_was_set[k_table])[k_index] = 0;
177
 
}
178
 
 
179
 
static void addkey(int k_index, int k_table, int keycode)
180
 
{
181
 
        int i;
182
 
 
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);
187
 
 
188
 
        if (k_index < 0 || k_index >= NR_KEYS)
189
 
                lkfatal(_("addkey called with bad index %d"), k_index);
190
 
 
191
 
        if (k_table < 0 || k_table >= MAX_NR_KEYMAPS)
192
 
                lkfatal(_("addkey called with bad table %d"), k_table);
193
 
 
194
 
        if (!defining[k_table])
195
 
                addmap(k_table, 0);
196
 
 
197
 
        if (!key_map[k_table]) {
198
 
                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;
202
 
        }
203
 
 
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;
208
 
        }
209
 
 
210
 
        if (alt_is_meta && keycode == K_HOLE
211
 
            && (keymap_was_set[k_table])[k_index])
212
 
                return;
213
 
 
214
 
        (key_map[k_table])[k_index] = keycode;
215
 
        (keymap_was_set[k_table])[k_index] = 1;
216
 
 
217
 
        if (alt_is_meta) {
218
 
                int alttable = k_table | M_ALT;
219
 
                int type = KTYP(keycode);
220
 
                int val = KVAL(keycode);
221
 
 
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));
227
 
        }
228
 
}
229
 
 
230
 
static void addfunc(struct kbsentry kbs)
231
 
{
232
 
        int sh, i, x;
233
 
        char *ptr, *q, *r;
234
 
 
235
 
        x = kbs.kb_func;
236
 
 
237
 
        if (x >= MAX_NR_FUNC) {
238
 
                fprintf(stderr, _("%s: addfunc called with bad func %d\n"),
239
 
                        progname, kbs.kb_func);
240
 
                exit(EXIT_FAILURE);
241
 
        }
242
 
 
243
 
        q = func_table[x];
244
 
        if (q) {                /* throw out old previous def */
245
 
                sh = strlen(q) + 1;
246
 
                ptr = q + sh;
247
 
                while (ptr < fp)
248
 
                        *q++ = *ptr++;
249
 
                fp -= sh;
250
 
 
251
 
                for (i = x + 1; i < MAX_NR_FUNC; i++) {
252
 
                        if (func_table[i])
253
 
                                func_table[i] -= sh;
254
 
                }
255
 
        }
256
 
 
257
 
        ptr = func_buf;         /* find place for new def */
258
 
        for (i = 0; i < x; i++) {
259
 
                if (func_table[i]) {
260
 
                        ptr = func_table[i];
261
 
                        while (*ptr++) ;
262
 
                }
263
 
        }
264
 
 
265
 
        func_table[x] = ptr;
266
 
        sh = strlen((char *)kbs.kb_string) + 1;
267
 
 
268
 
        if (fp + sh > func_buf + sizeof(func_buf)) {
269
 
                fprintf(stderr, _("%s: addfunc: func_buf overflow\n"), progname);
270
 
                exit(EXIT_FAILURE);
271
 
        }
272
 
        q = fp;
273
 
        fp += sh;
274
 
        r = fp;
275
 
        while (q > ptr)
276
 
                *--r = *--q;
277
 
        strcpy(ptr, (char *)kbs.kb_string);
278
 
        for (i = x + 1; i < MAX_NR_FUNC; i++) {
279
 
                if (func_table[i])
280
 
                        func_table[i] += sh;
281
 
        }
282
 
}
283
 
 
284
 
static void compose(int diacr, int base, int res)
285
 
{
286
 
        accent_entry *ptr;
287
 
        int direction;
288
 
 
289
 
#ifdef KDSKBDIACRUC
290
 
        if (prefer_unicode)
291
 
                direction = TO_UNICODE;
292
 
        else
293
 
#endif
294
 
                direction = TO_8BIT;
295
 
 
296
 
        if (accent_table_size == MAX_DIACR) {
297
 
                fprintf(stderr, _("compose table overflow\n"));
298
 
                exit(EXIT_FAILURE);
299
 
        }
300
 
 
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);
305
 
}
306
 
 
307
 
static int defkeys(int fd, int kbd_mode)
308
 
{
309
 
        struct kbentry ke;
310
 
        int ct = 0;
311
 
        int i, j, fail;
312
 
 
313
 
        if (optu) {
314
 
                /* temporarily switch to K_UNICODE while defining keys */
315
 
                if (ioctl(fd, KDSKBMODE, K_UNICODE)) {
316
 
                        perror("KDSKBMODE");
317
 
                        fprintf(stderr, _("%s: could not switch to Unicode mode\n"), progname);
318
 
                        exit(EXIT_FAILURE);
319
 
                }
320
 
        }
321
 
 
322
 
        for (i = 0; i < MAX_NR_KEYMAPS; i++) {
323
 
                if (key_map[i]) {
324
 
                        for (j = 0; j < NR_KEYS; j++) {
325
 
                                if ((keymap_was_set[i])[j]) {
326
 
                                        ke.kb_index = j;
327
 
                                        ke.kb_table = i;
328
 
                                        ke.kb_value = (key_map[i])[j];
329
 
 
330
 
                                        fail =
331
 
                                            ioctl(fd, KDSKBENT,
332
 
                                                  (unsigned long)&ke);
333
 
                                        if (fail) {
334
 
                                                if (errno == EPERM) {
335
 
                                                        fprintf(stderr,
336
 
                                                                _("Keymap %d: Permission denied\n"),
337
 
                                                                i);
338
 
                                                        j = NR_KEYS;
339
 
                                                        continue;
340
 
                                                }
341
 
                                                perror("KDSKBENT");
342
 
                                        } else
343
 
                                                ct++;
344
 
                                        if (verbose)
345
 
                                                printf(_("keycode %d, table %d = %d%s\n"),
346
 
                                                       j, i, (key_map[i])[j],
347
 
                                                       fail ? _("    FAILED") :
348
 
                                                       "");
349
 
                                        else if (fail)
350
 
                                                fprintf(stderr,
351
 
                                                        _("failed to bind key %d to value %d\n"),
352
 
                                                        j, (key_map[i])[j]);
353
 
                                }
354
 
                        }
355
 
                        xfree(key_map[i]);
356
 
                        xfree(keymap_was_set[i]);
357
 
 
358
 
                } else if (keymaps_line_seen && !defining[i]) {
359
 
                        /* deallocate keymap */
360
 
                        ke.kb_index = 0;
361
 
                        ke.kb_table = i;
362
 
                        ke.kb_value = K_NOSUCHMAP;
363
 
 
364
 
                        if (verbose > 1)
365
 
                                printf(_("deallocate keymap %d\n"), i);
366
 
 
367
 
                        if (ioctl(fd, KDSKBENT, (unsigned long)&ke)) {
368
 
                                if (errno != EINVAL) {
369
 
                                        perror("KDSKBENT");
370
 
                                        fprintf(stderr,
371
 
                                                _("%s: could not deallocate keymap %d\n"),
372
 
                                                progname, i);
373
 
                                        exit(EXIT_FAILURE);
374
 
                                }
375
 
                                /* probably an old kernel */
376
 
                                /* clear keymap by hand */
377
 
                                for (j = 0; j < NR_KEYS; j++) {
378
 
                                        ke.kb_index = j;
379
 
                                        ke.kb_table = i;
380
 
                                        ke.kb_value = K_HOLE;
381
 
                                        if (ioctl
382
 
                                            (fd, KDSKBENT,
383
 
                                             (unsigned long)&ke)) {
384
 
                                                if (errno == EINVAL && i >= 16)
385
 
                                                        break;  /* old kernel */
386
 
                                                perror("KDSKBENT");
387
 
                                                fprintf(stderr,
388
 
                                                        _("%s: cannot deallocate or clear keymap\n"),
389
 
                                                        progname);
390
 
                                                exit(EXIT_FAILURE);
391
 
                                        }
392
 
                                }
393
 
                        }
394
 
                }
395
 
        }
396
 
 
397
 
        if (optu && ioctl(fd, KDSKBMODE, kbd_mode)) {
398
 
                perror("KDSKBMODE");
399
 
                fprintf(stderr,
400
 
                        _("%s: could not return to original keyboard mode\n"),
401
 
                        progname);
402
 
                exit(EXIT_FAILURE);
403
 
        }
404
 
 
405
 
        return ct;
406
 
}
407
 
 
408
 
static char *ostr(char *s)
409
 
{
410
 
        int lth = strlen(s);
411
 
        char *ns0 = xmalloc(4 * lth + 1);
412
 
        char *ns = ns0;
413
 
 
414
 
        while (*s) {
415
 
                switch (*s) {
416
 
                case '\n':
417
 
                        *ns++ = '\\';
418
 
                        *ns++ = 'n';
419
 
                        break;
420
 
                case '\033':
421
 
                        *ns++ = '\\';
422
 
                        *ns++ = '0';
423
 
                        *ns++ = '3';
424
 
                        *ns++ = '3';
425
 
                        break;
426
 
                default:
427
 
                        *ns++ = *s;
428
 
                }
429
 
                s++;
430
 
        }
431
 
        *ns = 0;
432
 
        return ns0;
433
 
}
434
 
 
435
 
static int deffuncs(int fd)
436
 
{
437
 
        int i, ct = 0;
438
 
        char *ptr;
439
 
 
440
 
        for (i = 0; i < MAX_NR_FUNC; i++) {
441
 
                kbs_buf.kb_func = i;
442
 
 
443
 
                if ((ptr = func_table[i])) {
444
 
                        strcpy((char *)kbs_buf.kb_string, ptr);
445
 
                        if (ioctl(fd, KDSKBSENT, (unsigned long)&kbs_buf))
446
 
                                fprintf(stderr,
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]);
450
 
                        else
451
 
                                ct++;
452
 
                } else if (opts) {
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]);
457
 
                        else
458
 
                                ct++;
459
 
                }
460
 
        }
461
 
        return ct;
462
 
}
463
 
 
464
 
static int defdiacs(int fd)
465
 
{
466
 
        unsigned int i, count;
467
 
        struct kbdiacrs kd;
468
 
#ifdef KDSKBDIACRUC
469
 
        struct kbdiacrsuc kdu;
470
 
#endif
471
 
 
472
 
        count = accent_table_size;
473
 
        if (count > MAX_DIACR) {
474
 
                count = MAX_DIACR;
475
 
                fprintf(stderr, _("too many compose definitions\n"));
476
 
        }
477
 
#ifdef KDSKBDIACRUC
478
 
        if (prefer_unicode) {
479
 
                kdu.kb_cnt = count;
480
 
 
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;
485
 
                }
486
 
 
487
 
                if (ioctl(fd, KDSKBDIACRUC, (unsigned long)&kdu)) {
488
 
                        perror("KDSKBDIACRUC");
489
 
                        exit(EXIT_FAILURE);
490
 
                }
491
 
        } else
492
 
#endif
493
 
        {
494
 
                kd.kb_cnt = count;
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;
499
 
                }
500
 
 
501
 
                if (ioctl(fd, KDSKBDIACR, (unsigned long)&kd)) {
502
 
                        perror("KDSKBDIACR");
503
 
                        exit(EXIT_FAILURE);
504
 
                }
505
 
        }
506
 
 
507
 
        return kd.kb_cnt;
508
 
}
509
 
 
510
 
static void do_constant_key(int i, u_short key)
511
 
{
512
 
        int typ, val, j;
513
 
 
514
 
        typ = KTYP(key);
515
 
        val = KVAL(key);
516
 
 
517
 
        if ((typ == KT_LATIN || typ == KT_LETTER) &&
518
 
            ((val >= 'a' && val <= 'z') || (val >= 'A' && val <= 'Z'))) {
519
 
                u_short defs[16];
520
 
                defs[0] = K(KT_LETTER, val);
521
 
                defs[1] = K(KT_LETTER, val ^ 32);
522
 
                defs[2] = defs[0];
523
 
                defs[3] = defs[1];
524
 
 
525
 
                for (j = 4; j < 8; j++)
526
 
                        defs[j] = K(KT_LATIN, val & ~96);
527
 
 
528
 
                for (j = 8; j < 16; j++)
529
 
                        defs[j] = K(KT_META, KVAL(defs[j - 8]));
530
 
 
531
 
                for (j = 0; j < max_keymap; j++) {
532
 
                        if (!defining[j])
533
 
                                continue;
534
 
 
535
 
                        if (j > 0 &&
536
 
                            keymap_was_set[j] && (keymap_was_set[j])[i])
537
 
                                continue;
538
 
 
539
 
                        addkey(i, j, defs[j % 16]);
540
 
                }
541
 
 
542
 
        } else {
543
 
                /* do this also for keys like Escape,
544
 
                   as promised in the man page */
545
 
                for (j = 1; j < max_keymap; j++) {
546
 
                        if (defining[j] &&
547
 
                            (!(keymap_was_set[j]) || !(keymap_was_set[j])[i]))
548
 
                                addkey(i, j, key);
549
 
                }
550
 
        }
551
 
}
552
 
 
553
 
static void do_constant(void)
554
 
{
555
 
        int i, r0 = 0;
556
 
 
557
 
        if (keymaps_line_seen) {
558
 
                while (r0 < max_keymap && !defining[r0])
559
 
                        r0++;
560
 
        }
561
 
 
562
 
        for (i = 0; i < NR_KEYS; i++) {
563
 
                if (key_is_constant[i]) {
564
 
                        u_short key;
565
 
 
566
 
                        if (!key_map[r0])
567
 
                                lkfatal(_("impossible error in do_constant"));
568
 
 
569
 
                        key = (key_map[r0])[i];
570
 
                        do_constant_key(i, key);
571
 
                }
572
 
        }
573
 
}
574
 
 
575
 
static void loadkeys(char *console, int kbd_mode)
576
 
{
577
 
        int fd;
578
 
        int keyct, funcct, diacct = 0;
579
 
 
580
 
        fd = getfd(console);
581
 
        keyct = defkeys(fd, kbd_mode);
582
 
        funcct = deffuncs(fd);
583
 
 
584
 
        if (verbose) {
585
 
                printf(_("\nChanged %d %s and %d %s.\n"),
586
 
                       keyct, (keyct == 1) ? _("key") : _("keys"),
587
 
                       funcct, (funcct == 1) ? _("string") : _("strings"));
588
 
        }
589
 
 
590
 
        if (accent_table_size > 0 || nocompose) {
591
 
                diacct = defdiacs(fd);
592
 
 
593
 
                if (verbose) {
594
 
                        printf(_("Loaded %d compose %s.\n"),
595
 
                               diacct, (diacct == 1) ? _("definition") : _("definitions"));
596
 
                }
597
 
 
598
 
        } else if (verbose) {
599
 
                printf(_("(No change in compose definitions.)\n"));
600
 
        }
601
 
}
602
 
 
603
 
static void strings_as_usual(void)
604
 
{
605
 
        /*
606
 
         * 26 strings, mostly inspired by the VT100 family
607
 
         */
608
 
        char *stringvalues[30] = {
609
 
                /* F1 .. F20 */
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
619
 
        };
620
 
        int i;
621
 
 
622
 
        for (i = 0; i < 30; i++) {
623
 
                if (stringvalues[i]) {
624
 
                        struct kbsentry ke;
625
 
                        ke.kb_func = i;
626
 
                        strncpy((char *)ke.kb_string, stringvalues[i],
627
 
                                sizeof(ke.kb_string));
628
 
                        ke.kb_string[sizeof(ke.kb_string) - 1] = 0;
629
 
                        addfunc(ke);
630
 
                }
631
 
        }
632
 
}
633
 
 
634
 
static void compose_as_usual(char *charset)
635
 
{
636
 
        if (charset && strcmp(charset, "iso-8859-1")) {
637
 
                fprintf(stderr, _("loadkeys: don't know how to compose for %s\n"),
638
 
                        charset);
639
 
                exit(EXIT_FAILURE);
640
 
 
641
 
        } else {
642
 
                struct ccc {
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 }
679
 
                };
680
 
                int i;
681
 
                for (i = 0; i < 68; i++) {
682
 
                        struct ccc ptr = def_latin1_composes[i];
683
 
                        compose(ptr.c1, ptr.c2, ptr.c3);
684
 
                }
685
 
        }
686
 
}
687
 
 
688
 
/*
689
 
 * mktable.c
690
 
 *
691
 
 */
692
 
static char *modifiers[8] = {
693
 
        "shift", "altgr", "ctrl", "alt", "shl", "shr", "ctl", "ctr"
694
 
};
695
 
 
696
 
static char *mk_mapname(char modifier)
697
 
{
698
 
        static char buf[60];
699
 
        int i;
700
 
 
701
 
        if (!modifier)
702
 
                return "plain";
703
 
        buf[0] = 0;
704
 
        for (i = 0; i < 8; i++)
705
 
                if (modifier & (1 << i)) {
706
 
                        if (buf[0])
707
 
                                strcat(buf, "_");
708
 
                        strcat(buf, modifiers[i]);
709
 
                }
710
 
        return buf;
711
 
}
712
 
 
713
 
static void outchar(unsigned char c, int comma)
714
 
{
715
 
        printf("'");
716
 
        printf((c == '\'' || c == '\\') ? "\\%c" : isgraph(c) ? "%c"
717
 
               : "\\%03o", c);
718
 
        printf(comma ? "', " : "'");
719
 
}
720
 
 
721
 
static void attr_noreturn mktable(void)
722
 
{
723
 
        int j;
724
 
        unsigned int i, imax;
725
 
 
726
 
        char *ptr;
727
 
        unsigned int maxfunc;
728
 
        unsigned int keymap_count = 0;
729
 
 
730
 
        printf(
731
 
/* not to be translated... */
732
 
                      "/* Do not edit this file! It was automatically generated by   */\n");
733
 
        printf
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");
738
 
 
739
 
        for (i = 0; i < MAX_NR_KEYMAPS; i++)
740
 
                if (key_map[i]) {
741
 
                        keymap_count++;
742
 
                        if (i)
743
 
                                printf("static ");
744
 
                        printf("u_short %s_map[NR_KEYS] = {", mk_mapname(i));
745
 
                        for (j = 0; j < NR_KEYS; j++) {
746
 
                                if (!(j % 8))
747
 
                                        printf("\n");
748
 
                                printf("\t0x%04x,", U((key_map[i])[j]));
749
 
                        }
750
 
                        printf("\n};\n\n");
751
 
                }
752
 
 
753
 
        for (imax = MAX_NR_KEYMAPS - 1; imax > 0; imax--)
754
 
                if (key_map[imax])
755
 
                        break;
756
 
        printf("ushort *key_maps[MAX_NR_KEYMAPS] = {");
757
 
        for (i = 0; i <= imax; i++) {
758
 
                printf((i % 4) ? " " : "\n\t");
759
 
                if (key_map[i])
760
 
                        printf("%s_map,", mk_mapname(i));
761
 
                else
762
 
                        printf("0,");
763
 
        }
764
 
        if (imax < MAX_NR_KEYMAPS - 1)
765
 
                printf("\t0");
766
 
        printf("\n};\n\nunsigned int keymap_count = %d;\n\n", keymap_count);
767
 
 
768
 
/* uglified just for xgettext - it complains about nonterminated strings */
769
 
        printf("/*\n"
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"
773
 
               " */\n" "\n");
774
 
        for (maxfunc = MAX_NR_FUNC; maxfunc; maxfunc--)
775
 
                if (func_table[maxfunc - 1])
776
 
                        break;
777
 
 
778
 
        printf("char func_buf[] = {\n");
779
 
        for (i = 0; i < maxfunc; i++) {
780
 
                ptr = func_table[i];
781
 
                if (ptr) {
782
 
                        printf("\t");
783
 
                        for (; *ptr; ptr++)
784
 
                                outchar(*ptr, 1);
785
 
                        printf("0, \n");
786
 
                }
787
 
        }
788
 
        if (!maxfunc)
789
 
                printf("\t0\n");
790
 
        printf("};\n\n");
791
 
 
792
 
        printf("char *funcbufptr = func_buf;\n"
793
 
               "int funcbufsize = sizeof(func_buf);\n"
794
 
               "int funcbufleft = 0;          /* space left */\n" "\n");
795
 
 
796
 
        printf("char *func_table[MAX_NR_FUNC] = {\n");
797
 
        for (i = 0; i < maxfunc; i++) {
798
 
                if (func_table[i])
799
 
                        printf("\tfunc_buf + %ld,\n",
800
 
                               (long)(func_table[i] - func_buf));
801
 
                else
802
 
                        printf("\t0,\n");
803
 
        }
804
 
        if (maxfunc < MAX_NR_FUNC)
805
 
                printf("\t0,\n");
806
 
        printf("};\n");
807
 
 
808
 
#ifdef KDSKBDIACRUC
809
 
        if (prefer_unicode) {
810
 
                printf("\nstruct kbdiacruc accent_table[MAX_DIACR] = {\n");
811
 
                for (i = 0; i < accent_table_size; i++) {
812
 
                        printf("\t{");
813
 
                        outchar(accent_table[i].diacr, 1);
814
 
                        outchar(accent_table[i].base, 1);
815
 
                        printf("0x%04x},", accent_table[i].result);
816
 
                        if (i % 2)
817
 
                                printf("\n");
818
 
                }
819
 
                if (i % 2)
820
 
                        printf("\n");
821
 
                printf("};\n\n");
822
 
        } else
823
 
#endif
824
 
        {
825
 
                printf("\nstruct kbdiacr accent_table[MAX_DIACR] = {\n");
826
 
                for (i = 0; i < accent_table_size; i++) {
827
 
                        printf("\t{");
828
 
                        outchar(accent_table[i].diacr, 1);
829
 
                        outchar(accent_table[i].base, 1);
830
 
                        outchar(accent_table[i].result, 0);
831
 
                        printf("},");
832
 
                        if (i % 2)
833
 
                                printf("\n");
834
 
                }
835
 
                if (i % 2)
836
 
                        printf("\n");
837
 
                printf("};\n\n");
838
 
        }
839
 
        printf("unsigned int accent_table_size = %d;\n", accent_table_size);
840
 
 
841
 
        exit(0);
842
 
}
843
 
 
844
 
static void attr_noreturn bkeymap(void)
845
 
{
846
 
        int i, j;
847
 
 
848
 
        //u_char *p;
849
 
        char flag, magic[] = "bkeymap";
850
 
        unsigned short v;
851
 
 
852
 
        if (write(1, magic, 7) == -1)
853
 
                goto fail;
854
 
        for (i = 0; i < MAX_NR_KEYMAPS; i++) {
855
 
                flag = key_map[i] ? 1 : 0;
856
 
                if (write(1, &flag, 1) == -1)
857
 
                        goto fail;
858
 
        }
859
 
        for (i = 0; i < MAX_NR_KEYMAPS; i++) {
860
 
                if (key_map[i]) {
861
 
                        for (j = 0; j < NR_KEYS / 2; j++) {
862
 
                                v = key_map[i][j];
863
 
                                if (write(1, &v, 2) == -1)
864
 
                                        goto fail;
865
 
                        }
866
 
                }
867
 
        }
868
 
        exit(0);
869
 
 
870
 
 fail:  fprintf(stderr, _("Error writing map to file\n"));
871
 
        exit(1);
872
 
}
873
 
 
874
 
%}
875
 
 
876
 
%%
877
 
keytable        :
878
 
                | keytable line
879
 
                ;
880
 
line            : EOL
881
 
                | charsetline
882
 
                | altismetaline
883
 
                | usualstringsline
884
 
                | usualcomposeline
885
 
                | keymapline
886
 
                | fullline
887
 
                | singleline
888
 
                | strline
889
 
                | compline
890
 
                ;
891
 
charsetline     : CHARSET STRLITERAL EOL
892
 
                        {
893
 
                                set_charset((char *) kbs_buf.kb_string);
894
 
                        }
895
 
                ;
896
 
altismetaline   : ALT_IS_META EOL
897
 
                        {
898
 
                                alt_is_meta = 1;
899
 
                        }
900
 
                ;
901
 
usualstringsline: STRINGS AS USUAL EOL
902
 
                        {
903
 
                                strings_as_usual();
904
 
                        }
905
 
                ;
906
 
usualcomposeline: COMPOSE AS USUAL FOR STRLITERAL EOL
907
 
                        {
908
 
                                compose_as_usual((char *) kbs_buf.kb_string);
909
 
                        }
910
 
                  | COMPOSE AS USUAL EOL
911
 
                        {
912
 
                                compose_as_usual(0);
913
 
                        }
914
 
                ;
915
 
keymapline      : KEYMAPS range EOL
916
 
                        {
917
 
                                keymaps_line_seen = 1;
918
 
                        }
919
 
                ;
920
 
range           : range COMMA range0
921
 
                | range0
922
 
                ;
923
 
range0          : NUMBER DASH NUMBER
924
 
                        {
925
 
                                int i;
926
 
                                for (i = $1; i <= $3; i++)
927
 
                                        addmap(i,1);
928
 
                        }
929
 
                | NUMBER
930
 
                        {
931
 
                                addmap($1,1);
932
 
                        }
933
 
                ;
934
 
strline         : STRING LITERAL EQUALS STRLITERAL EOL
935
 
                        {
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);
940
 
                                addfunc(kbs_buf);
941
 
                        }
942
 
                ;
943
 
compline        : COMPOSE compsym compsym TO compsym EOL
944
 
                        {
945
 
                                compose($2, $3, $5);
946
 
                        }
947
 
                 | COMPOSE compsym compsym TO rvalue EOL
948
 
                        {
949
 
                                compose($2, $3, $5);
950
 
                        }
951
 
                ;
952
 
compsym         : CCHAR         {       $$ = $1;                }
953
 
                | UNUMBER       {       $$ = $1 ^ 0xf000;       }
954
 
                ;
955
 
singleline      :       {
956
 
                                mod = 0;
957
 
                        }
958
 
                  modifiers KEYCODE NUMBER EQUALS rvalue EOL
959
 
                        {
960
 
                                addkey($4, mod, $6);
961
 
                        }
962
 
                | PLAIN KEYCODE NUMBER EQUALS rvalue EOL
963
 
                        {
964
 
                                addkey($3, 0, $5);
965
 
                        }
966
 
                ;
967
 
modifiers       : modifiers modifier
968
 
                | modifier
969
 
                ;
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;   }
979
 
                ;
980
 
fullline        : KEYCODE NUMBER EQUALS rvalue0 EOL
981
 
                        {
982
 
                                int i, j;
983
 
 
984
 
                                if (rvalct == 1) {
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;
989
 
 
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++) {
994
 
                                                if (defining[j])
995
 
                                                        killkey($2, j);
996
 
                                        }
997
 
                                }
998
 
 
999
 
                                if (keymaps_line_seen) {
1000
 
                                        i = 0;
1001
 
 
1002
 
                                        for (j = 0; j < max_keymap; j++) {
1003
 
                                                if (defining[j]) {
1004
 
                                                        if (rvalct != 1 || i == 0)
1005
 
                                                                addkey($2, j, (i < rvalct) ? key_buf[i] : K_HOLE);
1006
 
                                                        i++;
1007
 
                                                }
1008
 
                                        }
1009
 
 
1010
 
                                        if (i < rvalct)
1011
 
                                                lkfatal(_("too many (%d) entries on one line"), rvalct);
1012
 
                                } else {
1013
 
                                        for (i = 0; i < rvalct; i++)
1014
 
                                                addkey($2, i, key_buf[i]);
1015
 
                                }
1016
 
                        }
1017
 
                ;
1018
 
 
1019
 
rvalue0         :
1020
 
                | rvalue1 rvalue0
1021
 
                ;
1022
 
rvalue1         : rvalue
1023
 
                        {
1024
 
                                if (rvalct >= MAX_NR_KEYMAPS)
1025
 
                                        lkfatal(_("too many key definitions on one line"));
1026
 
                                key_buf[rvalct++] = $1;
1027
 
                        }
1028
 
                ;
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);                        }
1035
 
                ;
1036
 
%%
1037
 
 
1038
 
int main(int argc, char *argv[])
1039
 
{
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 }
1055
 
        };
1056
 
        int c, i;
1057
 
        int fd;
1058
 
        int kbd_mode;
1059
 
        int kd_mode;
1060
 
        char *console = NULL;
1061
 
 
1062
 
        set_progname(argv[0]);
1063
 
 
1064
 
        setlocale(LC_ALL, "");
1065
 
        bindtextdomain(PACKAGE_NAME, LOCALEDIR);
1066
 
        textdomain(PACKAGE_NAME);
1067
 
 
1068
 
        while ((c = getopt_long(argc, argv, short_opts, long_opts, NULL)) != -1) {
1069
 
                switch (c) {
1070
 
                case 'a':
1071
 
                        opta = 1;
1072
 
                        break;
1073
 
                case 'b':
1074
 
                        optb = 1;
1075
 
                        break;
1076
 
                case 'c':
1077
 
                        nocompose = 1;
1078
 
                        break;
1079
 
                case 'C':
1080
 
                        console = optarg;
1081
 
                        break;
1082
 
                case 'd':
1083
 
                        optd = 1;
1084
 
                        break;
1085
 
                case 'm':
1086
 
                        optm = 1;
1087
 
                        break;
1088
 
                case 's':
1089
 
                        opts = 1;
1090
 
                        break;
1091
 
                case 'u':
1092
 
                        optu = 1;
1093
 
                        break;
1094
 
                case 'q':
1095
 
                        quiet = 1;
1096
 
                        break;
1097
 
                case 'v':
1098
 
                        verbose++;
1099
 
                        break;
1100
 
                case 'V':
1101
 
                        print_version_and_exit();
1102
 
                case 'h':
1103
 
                case '?':
1104
 
                        usage();
1105
 
                }
1106
 
        }
1107
 
 
1108
 
        if (optu && opta) {
1109
 
                fprintf(stderr,
1110
 
                        _("%s: Options --unicode and --ascii are mutually exclusive\n"),
1111
 
                        progname);
1112
 
                exit(EXIT_FAILURE);
1113
 
        }
1114
 
 
1115
 
        prefer_unicode = optu;
1116
 
 
1117
 
        if (!optm && !optb) {
1118
 
                /* check whether the keyboard is in Unicode mode */
1119
 
                fd = getfd(console);
1120
 
 
1121
 
                if (ioctl(fd, KDGKBMODE, &kbd_mode)) {
1122
 
                        perror("KDGKBMODE");
1123
 
                        fprintf(stderr, _("%s: error reading keyboard mode\n"),
1124
 
                                progname);
1125
 
                        exit(EXIT_FAILURE);
1126
 
                }
1127
 
 
1128
 
                if (kbd_mode == K_UNICODE) {
1129
 
                        if (opta) {
1130
 
                                fprintf(stderr,
1131
 
                                        _("%s: warning: loading non-Unicode keymap on Unicode console\n"
1132
 
                                          "    (perhaps you want to do `kbd_mode -a'?)\n"),
1133
 
                                        progname);
1134
 
                        } else {
1135
 
                                prefer_unicode = 1;
1136
 
                        }
1137
 
 
1138
 
                        /* reset -u option if keyboard is in K_UNICODE anyway */
1139
 
                        optu = 0;
1140
 
                } else if (optu
1141
 
                           && (ioctl(fd, KDGETMODE, &kd_mode) || (kd_mode != KD_GRAPHICS)))
1142
 
                        fprintf(stderr,
1143
 
                                _("%s: warning: loading Unicode keymap on non-Unicode console\n"
1144
 
                                  "    (perhaps you want to do `kbd_mode -u'?)\n"),
1145
 
                                progname);
1146
 
 
1147
 
                close(fd);
1148
 
        }
1149
 
 
1150
 
        for (i = optind; argv[i]; i++) {
1151
 
                FILE *f;
1152
 
                char *ev;
1153
 
 
1154
 
                dirpath = dirpath1;
1155
 
                if ((ev = getenv("LOADKEYS_KEYMAP_PATH")) != NULL) {
1156
 
                        if (!quiet && !optm)
1157
 
                                fprintf(stdout, _("Searching in %s\n"), ev);
1158
 
 
1159
 
                        dirpath2[0] = ev;
1160
 
                        dirpath = dirpath2;
1161
 
                }
1162
 
 
1163
 
                if (optd) {
1164
 
                        /* first read default map - search starts in . */
1165
 
                        optd = 0;
1166
 
                        if ((f = findfile(DEFMAP, dirpath, suffixes)) == NULL) {
1167
 
                                fprintf(stderr, _("Cannot find %s\n"), DEFMAP);
1168
 
                                exit(EXIT_FAILURE);
1169
 
                        }
1170
 
                        goto gotf;
1171
 
                }
1172
 
 
1173
 
                if (!strcmp(argv[i], "-")) {
1174
 
                        f = stdin;
1175
 
                        strcpy(pathname, "<stdin>");
1176
 
 
1177
 
                } else if ((f = findfile(argv[i], dirpath, suffixes)) == NULL) {
1178
 
                        fprintf(stderr, _("cannot open file %s\n"), argv[i]);
1179
 
                        exit(EXIT_FAILURE);
1180
 
                }
1181
 
 
1182
 
 gotf:
1183
 
                if (!quiet && !optm)
1184
 
                        fprintf(stdout, _("Loading %s\n"), pathname);
1185
 
 
1186
 
                stack_push(f, 0, pathname);
1187
 
 
1188
 
                if (yyparse()) {
1189
 
                        fprintf(stderr, _("syntax error in map file\n"));
1190
 
 
1191
 
                        if (!optm)
1192
 
                                fprintf(stderr,
1193
 
                                        _("key bindings not changed\n"));
1194
 
                        exit(EXIT_FAILURE);
1195
 
                }
1196
 
        }
1197
 
 
1198
 
        do_constant();
1199
 
 
1200
 
        if (optb) {
1201
 
                bkeymap();
1202
 
 
1203
 
        } else if (optm) {
1204
 
                mktable();
1205
 
 
1206
 
        } else if (console) {
1207
 
                char *buf = strdup(console);    /* make writable */
1208
 
                char *e, *s = buf;
1209
 
                while (*s) {
1210
 
                        char ch;
1211
 
 
1212
 
                        while (*s == ' ' || *s == '\t' || *s == ',')
1213
 
                                s++;
1214
 
                        e = s;
1215
 
                        while (*e && *e != ' ' && *e != '\t' && *e != ',')
1216
 
                                e++;
1217
 
                        ch = *e;
1218
 
                        *e = '\0';
1219
 
 
1220
 
                        if (verbose)
1221
 
                                printf("%s\n", s);
1222
 
 
1223
 
                        loadkeys(s, kbd_mode);
1224
 
 
1225
 
                        *e = ch;
1226
 
                        s = e;
1227
 
                }
1228
 
                free(buf);
1229
 
 
1230
 
        } else {
1231
 
                loadkeys(NULL, kbd_mode);
1232
 
        }
1233
 
        exit(EXIT_SUCCESS);
1234
 
}