summaryrefslogtreecommitdiff
path: root/console-tools/loadkmap.c
diff options
context:
space:
mode:
authorErik Andersen <andersen@codepoet.org>2000-02-08 19:58:47 +0000
committerErik Andersen <andersen@codepoet.org>2000-02-08 19:58:47 +0000
commite49d5ecbbe51718fa925b6890a735e5937cc2aa2 (patch)
treec90bda10731ad9333ce3b404f993354c9fc104b8 /console-tools/loadkmap.c
parentc0bf817bbc5c7867fbe8fb76d5c39f8ee802692f (diff)
downloadbusybox-w32-e49d5ecbbe51718fa925b6890a735e5937cc2aa2.tar.gz
busybox-w32-e49d5ecbbe51718fa925b6890a735e5937cc2aa2.tar.bz2
busybox-w32-e49d5ecbbe51718fa925b6890a735e5937cc2aa2.zip
Some formatting updates (ran the code through indent)
-Erik
Diffstat (limited to 'console-tools/loadkmap.c')
-rw-r--r--console-tools/loadkmap.c103
1 files changed, 53 insertions, 50 deletions
diff --git a/console-tools/loadkmap.c b/console-tools/loadkmap.c
index a228ca460..aa4f6bbc8 100644
--- a/console-tools/loadkmap.c
+++ b/console-tools/loadkmap.c
@@ -1,3 +1,4 @@
1/* vi: set sw=4 ts=4: */
1/* 2/*
2 * Mini loadkmap implementation for busybox 3 * Mini loadkmap implementation for busybox
3 * 4 *
@@ -29,61 +30,63 @@
29 30
30 31
31static const char loadkmap_usage[] = "loadkmap\n" 32static const char loadkmap_usage[] = "loadkmap\n"
32"\n" 33 "\n"
33"\tLoad a binary keyboard translation table from standard input.\n"
34"\n";
35 34
35 "\tLoad a binary keyboard translation table from standard input.\n"
36 "\n";
36 37
37int
38loadkmap_main(int argc, char * * argv)
39{
40 struct kbentry ke;
41 u_short *ibuff;
42 int i,j,fd,readsz,pos,ibuffsz=NR_KEYS * sizeof(u_short);
43 char flags[MAX_NR_KEYMAPS],magic[]="bkeymap",buff[7];
44 38
45 fd = open("/dev/tty0", O_RDWR); 39int loadkmap_main(int argc, char **argv)
46 if (fd < 0) { 40{
47 fprintf(stderr, "Error opening /dev/tty0: %s\n", strerror(errno)); 41 struct kbentry ke;
48 return 1; 42 u_short *ibuff;
49 } 43 int i, j, fd, readsz, pos, ibuffsz = NR_KEYS * sizeof(u_short);
44 char flags[MAX_NR_KEYMAPS], magic[] = "bkeymap", buff[7];
50 45
51 read(0,buff,7); 46 fd = open("/dev/tty0", O_RDWR);
52 if (0 != strncmp(buff,magic,7)) { 47 if (fd < 0) {
53 fprintf(stderr, "This is not a valid binary keymap.\n"); 48 fprintf(stderr, "Error opening /dev/tty0: %s\n", strerror(errno));
54 return 1; 49 return 1;
55 } 50 }
56 51
57 if ( MAX_NR_KEYMAPS != read(0,flags,MAX_NR_KEYMAPS) ) { 52 read(0, buff, 7);
58 fprintf(stderr, "Error reading keymap flags: %s\n", strerror(errno)); 53 if (0 != strncmp(buff, magic, 7)) {
59 return 1; 54 fprintf(stderr, "This is not a valid binary keymap.\n");
60 } 55 return 1;
56 }
61 57
62 ibuff=(u_short *) malloc(ibuffsz); 58 if (MAX_NR_KEYMAPS != read(0, flags, MAX_NR_KEYMAPS)) {
63 if (!ibuff) { 59 fprintf(stderr, "Error reading keymap flags: %s\n",
64 fprintf(stderr, "Out of memory.\n"); 60 strerror(errno));
65 return 1; 61 return 1;
66 } 62 }
63
64 ibuff = (u_short *) malloc(ibuffsz);
65 if (!ibuff) {
66 fprintf(stderr, "Out of memory.\n");
67 return 1;
68 }
67 69
68 for(i=0; i<MAX_NR_KEYMAPS; i++) { 70 for (i = 0; i < MAX_NR_KEYMAPS; i++) {
69 if (flags[i]==1){ 71 if (flags[i] == 1) {
70 pos=0; 72 pos = 0;
71 while (pos < ibuffsz) { 73 while (pos < ibuffsz) {
72 if ( (readsz = read(0,(char *)ibuff+pos,ibuffsz-pos)) < 0 ) { 74 if ((readsz = read(0, (char *) ibuff + pos, ibuffsz - pos))
73 fprintf(stderr, "Error reading keymap: %s\n", 75 < 0) {
74 strerror(errno)); 76 fprintf(stderr, "Error reading keymap: %s\n",
75 return 1; 77 strerror(errno));
76 } 78 return 1;
77 pos += readsz; 79 }
78 } 80 pos += readsz;
79 for(j=0; j<NR_KEYS; j++) { 81 }
80 ke.kb_index = j; 82 for (j = 0; j < NR_KEYS; j++) {
81 ke.kb_table = i; 83 ke.kb_index = j;
82 ke.kb_value = ibuff[j]; 84 ke.kb_table = i;
83 ioctl(fd, KDSKBENT, &ke); 85 ke.kb_value = ibuff[j];
84 } 86 ioctl(fd, KDSKBENT, &ke);
87 }
88 }
85 } 89 }
86 } 90 close(fd);
87 close (fd); 91 return 0;
88 return 0;
89} 92}