Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / arch / atari / stand / loadkmap / loadkmap.c
blob9f4bae4b41ffff99a90d13f303e892a4501860aa
1 /* $NetBSD: loadkmap.c,v 1.7 2009/03/14 21:04:07 dsl Exp $ */
3 #include <sys/types.h>
4 #include <sys/stat.h>
5 #include <sys/ioctl.h>
6 #include "../../dev/iteioctl.h"
7 #include "../../dev/kbdmap.h"
8 #include <stdio.h>
9 #include <stdlib.h>
12 int load_kmap(const char *, int);
13 int dump_kmap();
15 int
16 main(int argc, char *argv[])
18 int set_sysmap = 0;
19 char *mapfile;
20 int rc = 0;
22 if (argc > 2) {
23 if ((argc == 3) && !strcmp(argv[1], "-f")) {
24 mapfile = argv[2];
25 set_sysmap = 1;
27 else {
28 fprintf(stderr, "%s [-f] keymap\n", argv[0]);
29 exit(1);
32 else mapfile = argv[1];
34 if (argc == 1)
35 rc = dump_kmap();
36 else rc = load_kmap(mapfile, set_sysmap);
38 exit (rc);
42 int
43 load_kmap(const char *file, int set_sysmap)
45 int fd;
46 char buf[sizeof (struct kbdmap)];
47 int ioc;
49 ioc = set_sysmap ? ITEIOCSSKMAP : ITEIOCSKMAP;
51 if ((fd = open (file, 0)) >= 0) {
52 if (read (fd, buf, sizeof (buf)) == sizeof (buf)) {
53 if (ioctl (0, ioc, buf) == 0) {
54 close(fd);
55 return 0;
57 else perror("ITEIOCSKMAP");
59 else perror("read kmap");
61 close(fd);
63 else perror("open kmap");
64 return 1;
67 int
68 dump_kmap(void)
70 char buf[sizeof (struct kbdmap)];
72 if (ioctl (0, ITEIOCGKMAP, buf) == 0) {
73 write (1, buf, sizeof (buf));
74 return 0;
76 perror ("ITEIOCGKMAP");
77 return 1;