xref: /netbsd/sys/arch/amiga/stand/loadkmap/loadkmap.c (revision 36aa8db9)
1 /*	$NetBSD: loadkmap.c,v 1.8 2011/05/20 01:28:40 christos Exp $	*/
2 
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>
10 #include <unistd.h>
11 #include <fcntl.h>
12 
13 
14 void load_kmap(const char *);
15 void dump_kmap(void);
16 
17 int
main(int argc,char * argv[])18 main(int argc, char *argv[])
19 {
20   if (argc > 2)
21     {
22       fprintf (stderr, "%s keymap\n", argv[0]);
23       exit (1);
24     }
25 
26   if (argc == 1)
27     dump_kmap ();
28   else
29     load_kmap (argv[1]);
30 
31   exit (0);
32 }
33 
34 
35 void
load_kmap(const char * file)36 load_kmap(const char *file)
37 {
38   int fd;
39   char buf[sizeof (struct kbdmap)];
40 
41   if ((fd = open (file, 0)) >= 0)
42     {
43       if (read (fd, buf, sizeof (buf)) == sizeof (buf))
44 	{
45 	  if (ioctl (0, ITEIOCSKMAP, buf) == 0)
46 	    return;
47 	  else
48 	    perror ("ITEIOCSKMAP");
49 	}
50       else
51 	perror ("read kmap");
52 
53       close (fd);
54     }
55   else
56     perror ("open kmap");
57 }
58 
59 void
dump_kmap(void)60 dump_kmap(void)
61 {
62   char buf[sizeof (struct kbdmap)];
63   if (ioctl (0, ITEIOCGKMAP, buf) == 0)
64     write (1, buf, sizeof (buf));
65   else
66     perror ("ITEIOCGKMAP");
67 }
68