summaryrefslogtreecommitdiff
path: root/sys/arch/atari/stand/loadkmap/loadkmap.c
blob: 6002ba43c8963f8daa6dfaeb70e3cec7ab65db53 (plain)
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*	$NetBSD: loadkmap.c,v 1.3 2002/04/12 22:09:28 leo Exp $	*/

#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include "../../dev/iteioctl.h"
#include "../../dev/kbdmap.h"
#include <stdio.h>


int load_kmap __P((const char *, int));
int dump_kmap(); 

int
main(argc, argv)
     int argc;
     char *argv[];
{
	int	set_sysmap = 0;
	char	*mapfile;
	int	rc = 0;

	if (argc > 2) {
		if ((argc == 3) && !strcmp(argv[1], "-f")) {
			mapfile = argv[2];
			set_sysmap = 1;
		}
		else {
			fprintf(stderr, "%s [-f] keymap\n", argv[0]);
			exit(1);
		}
	}
	else mapfile = argv[1];

	if (argc == 1)
		rc = dump_kmap();
	else rc = load_kmap(mapfile, set_sysmap);

	exit (rc);
}


int
load_kmap(file, set_sysmap)
const char	*file;
int		set_sysmap;
{
	int	fd;
	char	buf[sizeof (struct kbdmap)];
	int	ioc;

	ioc = set_sysmap ? ITEIOCSSKMAP : ITEIOCSKMAP;
	
	if ((fd = open (file, 0)) >= 0) {
		if (read (fd, buf, sizeof (buf)) == sizeof (buf)) {
			if (ioctl (0, ioc, buf) == 0) {
				close(fd);
				return 0;
			}
			else perror("ITEIOCSKMAP");
		}
		else perror("read kmap");

		close(fd);
	}
	else perror("open kmap");
	return 1;
}

int
dump_kmap()
{
	char buf[sizeof (struct kbdmap)];

	if (ioctl (0, ITEIOCGKMAP, buf) == 0) {
		write (1, buf, sizeof (buf));
		return 0;
	}
	perror ("ITEIOCGKMAP");
	return 1;
}