loadkmap.c revision 1.5
1/* $NetBSD: loadkmap.c,v 1.5 2009/03/14 14:45:57 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(file, set_sysmap) 46const char *file; 47int set_sysmap; 48{ 49 int fd; 50 char buf[sizeof (struct kbdmap)]; 51 int ioc; 52 53 ioc = set_sysmap ? ITEIOCSSKMAP : ITEIOCSKMAP; 54 55 if ((fd = open (file, 0)) >= 0) { 56 if (read (fd, buf, sizeof (buf)) == sizeof (buf)) { 57 if (ioctl (0, ioc, buf) == 0) { 58 close(fd); 59 return 0; 60 } 61 else perror("ITEIOCSKMAP"); 62 } 63 else perror("read kmap"); 64 65 close(fd); 66 } 67 else perror("open kmap"); 68 return 1; 69} 70 71int 72dump_kmap() 73{ 74 char buf[sizeof (struct kbdmap)]; 75 76 if (ioctl (0, ITEIOCGKMAP, buf) == 0) { 77 write (1, buf, sizeof (buf)); 78 return 0; 79 } 80 perror ("ITEIOCGKMAP"); 81 return 1; 82} 83