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