summaryrefslogtreecommitdiffstats
path: root/contrib/syslinux-4.02/com32/modules/kbdmap.c
blob: f1c736d518d0010735e3955ec06f1df21069d56f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/* ----------------------------------------------------------------------- *
 *
 *   Copyright 2009 Intel Corporation; author: H. Peter Anvin
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 *   Boston MA 02110-1301, USA; either version 2 of the License, or
 *   (at your option) any later version; incorporated herein by reference.
 *
 * ----------------------------------------------------------------------- */

#include <stdio.h>
#include <string.h>
#include <console.h>
#include <syslinux/loadfile.h>
#include <syslinux/keyboard.h>

static inline void error(const char *msg)
{
    fputs(msg, stderr);
}

int main(int argc, char *argv[])
{
    const struct syslinux_keyboard_map *const kmap = syslinux_keyboard_map();
    size_t map_size;
    void *kbdmap;

    openconsole(&dev_null_r, &dev_stdcon_w);

    if (argc != 2) {
	error("Usage: kbdmap mapfile\n");
	return 1;
    }

    if (kmap->version != 1) {
	error("Syslinux core version mismatch\n");
	return 1;
    }

    if (loadfile(argv[1], &kbdmap, &map_size)) {
	error("Keyboard map file load error\n");
	return 1;
    }

    if (map_size != kmap->length) {
	error("Keyboard map file format error\n");
	return 1;
    }

    memcpy(kmap->map, kbdmap, map_size);
    return 0;
}