loadkmap.c revision 1.2
1/* $NetBSD: loadkmap.c,v 1.2 1995/07/24 05:47:48 leo 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 10 11void load_kmap __P((const char *, int)); 12void dump_kmap(); 13 14int 15main(argc, argv) 16 int argc; 17 char *argv[]; 18{ 19 int set_sysmap = 0; 20 char *mapfile; 21 22 if (argc > 2) { 23 if ((argc == 3) && !strcmp(argv[1], "-f")) { 24 mapfile = argv[2]; 25 set_sysmap = 1; 26 } 27 else { 28 fprintf(stderr, "%s [-f] keymap\n", argv[0]); 29 exit(1); 30 } 31 } 32 else mapfile = argv[1]; 33 34 if (argc == 1) 35 dump_kmap(); 36 else load_kmap(mapfile, set_sysmap); 37 38 exit (0); 39} 40 41 42void 43load_kmap(file, set_sysmap) 44const char *file; 45int set_sysmap; 46{ 47 int fd; 48 char buf[sizeof (struct kbdmap)]; 49 int ioc; 50 51 ioc = set_sysmap ? ITEIOCSSKMAP : ITEIOCSKMAP; 52 53 if ((fd = open (file, 0)) >= 0) { 54 if (read (fd, buf, sizeof (buf)) == sizeof (buf)) { 55 if (ioctl (0, ioc, buf) == 0) 56 return; 57 else perror("ITEIOCSKMAP"); 58 } 59 else perror("read kmap"); 60 61 close(fd); 62 } 63 else perror("open kmap"); 64} 65 66void 67dump_kmap() 68{ 69 char buf[sizeof (struct kbdmap)]; 70 71 if (ioctl (0, ITEIOCGKMAP, buf) == 0) 72 write (1, buf, sizeof (buf)); 73 else perror ("ITEIOCGKMAP"); 74} 75