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