/* the file pointer must be at the beginning of the section already! */
static int loadKeymap(gzFile stream) {
int console;
int kmap, key;
struct kbentry entry;
int keymaps[MAX_NR_KEYMAPS];
int count = 0;
int magic;
short keymap[NR_KEYS];
if (gzread(stream, &magic, sizeof(magic)) != sizeof(magic)) {
logMessage("failed to read kmap magic: %s", strerror(errno));
return INST_ERROR;
}
if (magic != KMAP_MAGIC) {
logMessage("bad magic for keymap!");
return INST_ERROR;
}
if (gzread(stream, keymaps, sizeof(keymaps)) != sizeof(keymaps)) {
logMessage("failed to read keymap header: %s", strerror(errno));
return INST_ERROR;
}
console = open("/dev/console", O_RDWR);
if (console < 0) {
logMessage("failed to open /dev/console: %s", strerror(errno));
return INST_ERROR;
}
for (kmap = 0; kmap < MAX_NR_KEYMAPS; kmap++) {
if (!keymaps[kmap]) continue;
if (gzread(stream, keymap, sizeof(keymap)) != sizeof(keymap)) {
logMessage("failed to read keymap data: %s", strerror(errno));
close(console);
return INST_ERROR;
}
int setupKeyboard(void) {
newtComponent form, okay, listbox, answer;
int num;
int rc;
gzFile f;
struct kmapHeader hdr;
struct kmapInfo * infoTable;
char buf[16384]; /* I hope this is big enough */
int i;
f = gzopen("/etc/keymaps.gz", "r");
if (!f) {
errorWindow("cannot open /etc/keymaps.gz: %s");
return INST_ERROR;
}
if (gzread(f, &hdr, sizeof(hdr)) != sizeof(hdr)) {
errorWindow("failed to read keymaps header: %s");
gzclose(f);
return INST_ERROR;
}
logMessage("%d keymaps are available", hdr.numEntries);
i = hdr.numEntries * sizeof(*infoTable);
infoTable = alloca(i);
if (gzread(f, infoTable, i) != i) {
errorWindow("failed to read keymap information: %s");
gzclose(f);
return INST_ERROR;
}
newtOpenWindow(20, 3, 40, 16, "Keyboard Type");
form = newtForm(NULL, NULL, 0);
newtFormAddComponent(form,
newtLabel(3, 1, "What type of keyboard do you have?"));
f = fopen(filename, "r");
if (!f) {
/* fail silently -- old bootdisks won't create this */
logMessage("failed to read keyboard configuration (proably ok)");
return 0;
}
/* this is a bit braindead -- we can steal better parsing from
kbdconfig if we ever need it */
if (!fgets(buf, sizeof(buf) - 1, f)) {
errorWindow("empty keyboard configuration file");
fclose(f);
return INST_ERROR;
}
fclose(f);
if (strncmp("KEYTABLE=", buf, 9)) {
errorWindow("unrecognized entry in keyboard configuration file");
return INST_ERROR;
}
chptr = buf + strlen(buf) - 1;
/* ignore the '\n' on the end */
*chptr-- = '\0';
if (*chptr == '"')
*chptr-- = '\0';
while (chptr > buf && *chptr != '.') chptr--;
if (*chptr == '.') *chptr-- = '\0';
while (chptr > buf && *chptr != '/') chptr--;
if (*chptr == '/') chptr++;