2000-02-08 19:58:47 +00:00
|
|
|
/* vi: set sw=4 ts=4: */
|
1999-10-20 22:08:37 +00:00
|
|
|
/*
|
|
|
|
* Mini loadkmap implementation for busybox
|
|
|
|
*
|
|
|
|
* Copyright (C) 1998 Enrique Zanardi <ezanardi@ull.es>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2000-09-25 21:45:58 +00:00
|
|
|
#include "busybox.h"
|
1999-10-05 16:24:54 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
|
2000-10-25 16:48:15 +00:00
|
|
|
#define BINARY_KEYMAP_MAGIC "bkeymap"
|
|
|
|
|
2000-07-08 18:55:24 +00:00
|
|
|
/* From <linux/kd.h> */
|
|
|
|
struct kbentry {
|
|
|
|
unsigned char kb_table;
|
|
|
|
unsigned char kb_index;
|
|
|
|
unsigned short kb_value;
|
|
|
|
};
|
|
|
|
#define KDSKBENT 0x4B47 /* sets one entry in translation table */
|
|
|
|
|
|
|
|
/* From <linux/keyboard.h> */
|
|
|
|
#define NR_KEYS 128
|
|
|
|
#define MAX_NR_KEYMAPS 256
|
|
|
|
|
2000-02-08 19:58:47 +00:00
|
|
|
int loadkmap_main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
struct kbentry ke;
|
|
|
|
u_short *ibuff;
|
|
|
|
int i, j, fd, readsz, pos, ibuffsz = NR_KEYS * sizeof(u_short);
|
2000-10-25 16:48:15 +00:00
|
|
|
char flags[MAX_NR_KEYMAPS], buff[7];
|
1999-10-05 16:24:54 +00:00
|
|
|
|
2000-10-25 16:48:15 +00:00
|
|
|
if (argc != 1)
|
2000-04-19 03:59:10 +00:00
|
|
|
usage(loadkmap_usage);
|
|
|
|
|
2000-02-08 19:58:47 +00:00
|
|
|
fd = open("/dev/tty0", O_RDWR);
|
2000-10-25 16:48:15 +00:00
|
|
|
if (fd < 0)
|
|
|
|
fatalPerror("Error opening /dev/tty0");
|
2000-02-08 19:58:47 +00:00
|
|
|
|
|
|
|
read(0, buff, 7);
|
2000-10-25 16:48:15 +00:00
|
|
|
if (0 != strncmp(buff, BINARY_KEYMAP_MAGIC, 7))
|
|
|
|
fatalError("This is not a valid binary keymap.\n");
|
1999-10-05 16:24:54 +00:00
|
|
|
|
2000-10-25 16:48:15 +00:00
|
|
|
if (MAX_NR_KEYMAPS != read(0, flags, MAX_NR_KEYMAPS))
|
|
|
|
fatalPerror("Error reading keymap flags");
|
2000-02-08 19:58:47 +00:00
|
|
|
|
2000-09-13 02:46:14 +00:00
|
|
|
ibuff = (u_short *) xmalloc(ibuffsz);
|
1999-10-05 16:24:54 +00:00
|
|
|
|
2000-02-08 19:58:47 +00:00
|
|
|
for (i = 0; i < MAX_NR_KEYMAPS; i++) {
|
|
|
|
if (flags[i] == 1) {
|
|
|
|
pos = 0;
|
|
|
|
while (pos < ibuffsz) {
|
2000-10-25 16:48:15 +00:00
|
|
|
if ((readsz = read(0, (char *) ibuff + pos, ibuffsz - pos)) < 0)
|
|
|
|
fatalPerror("Error reading keymap");
|
2000-02-08 19:58:47 +00:00
|
|
|
pos += readsz;
|
|
|
|
}
|
|
|
|
for (j = 0; j < NR_KEYS; j++) {
|
|
|
|
ke.kb_index = j;
|
|
|
|
ke.kb_table = i;
|
|
|
|
ke.kb_value = ibuff[j];
|
|
|
|
ioctl(fd, KDSKBENT, &ke);
|
|
|
|
}
|
|
|
|
}
|
1999-10-05 16:24:54 +00:00
|
|
|
}
|
2000-03-23 01:09:18 +00:00
|
|
|
/* Don't bother to close files. Exit does that
|
|
|
|
* automagically, so we can save a few bytes */
|
|
|
|
/* close(fd); */
|
2000-10-25 16:48:15 +00:00
|
|
|
return EXIT_SUCCESS;
|
1999-10-05 16:24:54 +00:00
|
|
|
}
|