emacs keymap for AT386?
James Van Artsdalen
james at bigtex.cactus.org
Wed Sep 19 03:15:08 AEST 1990
In <22073 at grebyn.com>, ckp at grebyn.UUCP (Checkpoint Technologies) wrote:
> Has anyone implemented an AT386 keymap for GNU emacs? I'd like to
> be able to use the arrows, to use Page Up and Page Down, and I'd like
> Alt to work for Meta. I'm willing to sacrifice the Meta-[ current
> functionality. I'm using Interactive Unix 2.2. Thanks.
ksh is happier too. This seems to work under SysVr4 also, though that
may be an accident. Those of you with keyboards with too many keys
will need to add stuff to this. -j is "James' mapping".
This is one of those barely-started, not-quite-finished programs. I
hadn't even read the sources for over 2 years. No, I don't remember
what's supposed to be in that 'puts("")' at the end, but it's just a
display routine, so no harm. I suspect there are more general ways to
do this. :-)
#include <stdio.h>
#include <sys/types.h>
#include <sys/at_ansi.h>
#include <sys/kd.h>
#include <sysexits.h>
keymap_t map;
main(argc, argv)
int argc;
char **argv;
{
int opt_print = 0;
int opt_james = 0;
int c;
char *opt_file = NULL;
char *opt_dump = NULL;
extern char *optarg;
extern int optind;
while ((c = getopt(argc, argv, "pjf:d:")) != -1) {
switch (c) {
case 'p':
opt_print = 1;
break;
case 'f':
if (opt_file) {
fputs("Only one -f file allowed.\n", stderr);
exit(EX_USAGE);
}
opt_file = optarg;
break;
case 'd':
if (opt_dump) {
fputs("Only one -d file allowed.\n", stderr);
exit(EX_USAGE);
}
opt_dump = optarg;
break;
case 'j':
opt_james = 1;
break;
default:
fprintf(stderr, "Usage: %s [ options ]\n", argv[0]);
exit(EX_USAGE);
}
}
if (argc == 1) {
show_keys();
exit(EX_OK);
}
if (opt_file)
set_file(opt_file);
if (opt_james)
set_james();
if (opt_dump)
dump_file(opt_dump);
if (opt_print) {
show_keys();
exit(EX_OK);
}
}
dump_file(file)
char *file;
{
FILE *f;
if (ioctl(fileno(stdin), GIO_KEYMAP, &map) == -1)
perror("ioctl(GIO_KEYMAP)");
f = fopen(file, "w");
if (!f)
perror("fopen()");
else if (fwrite(&map, sizeof(map), 1, f) != 1)
perror("fwrite()");
else if (fclose(f))
perror("fclose()");
}
set_file(file)
char *file;
{
FILE *f;
int size;
if (ioctl(fileno(stdin), GIO_KEYMAP, &map) == -1)
perror("ioctl(GIO_KEYMAP)");
size = map.n_keys;
f = fopen(file, "r");
if (!f)
perror("fopen()");
else if (fread(&map, sizeof(map), 1, f) != 1)
perror("fread()");
else if (fclose(f))
perror("fclose()");
else if (map.n_keys != size || map.key[0].map[0] || map.key[0].map[1] ||
map.key[0].map[2] || map.key[0].map[3] || map.key[0].map[4] ||
map.key[0].map[5] || map.key[0].map[6] || map.key[0].map[7])
fputs("Corrupt keymap file\n", stderr);
else if (ioctl(fileno(stdin), PIO_KEYMAP, &map) == -1)
perror("ioctl(PIO_KEYMAP)");
}
set_james()
{
int i;
if (ioctl(fileno(stdin), GIO_KEYMAP, &map) == -1)
perror("ioctl(GIO_KEYMAP)");
map.key[3].map[CTRL] = 0; /* "2" */
map.key[7].map[CTRL] = 0x1e; /* "6" */
map.key[12].map[CTRL] = 0x1f; /* "-" */
map.key[2].map[SHFCTL] = 0x21; /* 1 */
map.key[4].map[SHFCTL] = 0x23; /* 3 */
map.key[5].map[SHFCTL] = 0x24; /* 4 */
map.key[6].map[SHFCTL] = 0x25; /* 5 */
map.key[8].map[SHFCTL] = 0x26; /* 7 */
map.key[9].map[SHFCTL] = 0x2a; /* 8 */
map.key[10].map[SHFCTL] = 0x28; /* 9 */
map.key[11].map[SHFCTL] = 0x29; /* 0 */
map.key[13].map[SHFCTL] = 0x2b; /* = */
map.key[14].map[NORMAL] = 0x7f; /* backspace */
map.key[14].map[CTRL] = 0x08;
map.key[14].map[SHIFT] = 0x08;
map.key[14].map[SHFCTL] = 0x08;
map.key[15].map[SHIFT] = 0x09; /* tab */
map.key[15].map[SHFCTL] = 0x09;
for (i = 1; i <= 15; i++) { /* ESC, 1-9, 0, -, =, backspace tab */
map.key[i].spcl = 0;
map.key[i].map[ALT] = map.key[i].map[NORMAL] | 0x80;
map.key[i].map[ALTSHF] = map.key[i].map[SHIFT] | 0x80;
map.key[i].map[ALTCTL] = map.key[i].map[CTRL] | 0x80;
map.key[i].map[ALTSHFCTL] = map.key[i].map[SHFCTL] | 0x80;
}
map.key[26].map[SHFCTL] = 0x1b;
map.key[27].map[SHFCTL] = 0x1d;
map.key[28].map[CTRL] = 0x0d; /* enter */
map.key[28].map[SHFCTL] = 0x0d;
for (i = 16; i <= 28; i++) { /* qwertyuiop[] enter */
map.key[i].spcl = 0;
map.key[i].map[ALT] = map.key[i].map[NORMAL] | 0x80;
map.key[i].map[ALTSHF] = map.key[i].map[SHIFT] | 0x80;
map.key[i].map[ALTCTL] = map.key[i].map[CTRL] | 0x80;
map.key[i].map[ALTSHFCTL] = map.key[i].map[SHFCTL] | 0x80;
}
map.key[41].map[SHFCTL] = 0x7e; /* ` */
for (i = 30; i <= 41; i++) { /* asdfghjkl;'` */
map.key[i].spcl = 0;
map.key[i].map[ALT] = map.key[i].map[NORMAL] | 0x80;
map.key[i].map[ALTSHF] = map.key[i].map[SHIFT] | 0x80;
map.key[i].map[ALTCTL] = map.key[i].map[CTRL] | 0x80;
map.key[i].map[ALTSHFCTL] = map.key[i].map[SHFCTL] | 0x80;
}
for (i = 43; i <= 53; i++) { /* \zxcvbnm,./ */
map.key[i].spcl = 0;
map.key[i].map[ALT] = map.key[i].map[NORMAL] | 0x80;
map.key[i].map[ALTSHF] = map.key[i].map[SHIFT] | 0x80;
map.key[i].map[ALTCTL] = map.key[i].map[CTRL] | 0x80;
map.key[i].map[ALTSHFCTL] = map.key[i].map[SHFCTL] | 0x80;
}
map.key[71].spcl = 0; /* Home */
map.key[72].spcl = 0; /* Up */
map.key[73].spcl = 0; /* PgUp */
map.key[75].spcl = 0; /* Left */
map.key[77].spcl = 0; /* Right */
map.key[79].spcl = 0; /* End */
map.key[80].spcl = 0; /* Down */
map.key[81].spcl = 0; /* PgDn */
map.key[83].spcl = 0; /* Del */
map.key[71].map[NORMAL] = 0x01; /* Home */
map.key[72].map[NORMAL] = 0x10; /* Up */
map.key[73].map[NORMAL] = 0xf6; /* PgUp */
map.key[75].map[NORMAL] = 0x02; /* Left */
map.key[77].map[NORMAL] = 0x06; /* Right */
map.key[79].map[NORMAL] = 0x05; /* End */
map.key[80].map[NORMAL] = 0x0e; /* Down */
map.key[81].map[NORMAL] = 0x16; /* PgDn */
map.key[83].map[NORMAL] = 0x04; /* Del */
map.key[71].map[CTRL] = map.key[71].map[NORMAL]; /* Home */
map.key[72].map[CTRL] = map.key[72].map[NORMAL]; /* Up */
map.key[73].map[CTRL] = 0xbc; /* PgUp */
map.key[75].map[CTRL] = 0x82; /* Left */
map.key[77].map[CTRL] = 0x86; /* Right */
map.key[79].map[CTRL] = map.key[79].map[NORMAL]; /* End */
map.key[80].map[CTRL] = map.key[80].map[NORMAL]; /* Down */
map.key[81].map[CTRL] = 0xbe; /* PgDn */
map.key[83].map[CTRL] = 0x7f; /* Del */
map.key[71].map[ALT] = map.key[71].map[NORMAL] | 0x80; /* Home */
map.key[72].map[ALT] = map.key[72].map[NORMAL] | 0x80; /* Up */
map.key[73].map[ALT] = 0xbc; /* PgUp */
map.key[75].map[ALT] = map.key[75].map[NORMAL] | 0x80; /* Left */
map.key[77].map[ALT] = map.key[77].map[NORMAL] | 0x80; /* Right */
map.key[79].map[ALT] = map.key[79].map[NORMAL] | 0x80; /* End */
map.key[80].map[ALT] = map.key[80].map[NORMAL] | 0x80; /* Down */
map.key[81].map[ALT] = 0xbe; /* PgDn */
map.key[83].map[ALT] = map.key[83].map[NORMAL] | 0x80; /* Del */
map.key[71].map[ALTSHF] = map.key[71].map[SHIFT] | 0x80; /* Home */
map.key[72].map[ALTSHF] = map.key[72].map[SHIFT] | 0x80; /* Up */
map.key[73].map[ALTSHF] = map.key[73].map[SHIFT] | 0x80; /* PgUp */
map.key[75].map[ALTSHF] = map.key[75].map[SHIFT] | 0x80; /* Left */
map.key[77].map[ALTSHF] = map.key[77].map[SHIFT] | 0x80; /* Right */
map.key[79].map[ALTSHF] = map.key[79].map[SHIFT] | 0x80; /* End */
map.key[80].map[ALTSHF] = map.key[80].map[SHIFT] | 0x80; /* Down */
map.key[81].map[ALTSHF] = map.key[81].map[SHIFT] | 0x80; /* PgDn */
map.key[83].map[ALTSHF] = map.key[83].map[SHIFT] | 0x80; /* Del */
map.key[71].map[ALTCTL] = map.key[71].map[CTRL] | 0x80; /* Home */
map.key[72].map[ALTCTL] = map.key[72].map[CTRL] | 0x80; /* Up */
map.key[73].map[ALTCTL] = map.key[73].map[CTRL]; /* PgUp */
map.key[75].map[ALTCTL] = map.key[75].map[CTRL]; /* Left */
map.key[77].map[ALTCTL] = map.key[77].map[CTRL]; /* Right */
map.key[79].map[ALTCTL] = map.key[79].map[CTRL] | 0x80; /* End */
map.key[80].map[ALTCTL] = map.key[80].map[CTRL] | 0x80; /* Down */
map.key[81].map[ALTCTL] = map.key[81].map[CTRL]; /* PgDn */
map.key[83].map[ALTCTL] = map.key[83].map[CTRL] | 0x80; /* Del */
map.key[71].map[ALTSHFCTL] = map.key[71].map[SHFCTL] | 0x80; /* Home */
map.key[72].map[ALTSHFCTL] = map.key[72].map[SHFCTL] | 0x80; /* Up */
map.key[73].map[ALTSHFCTL] = map.key[73].map[SHFCTL] | 0x80; /* PgUp */
map.key[75].map[ALTSHFCTL] = map.key[75].map[SHFCTL] | 0x80; /* Left */
map.key[77].map[ALTSHFCTL] = map.key[77].map[SHFCTL] | 0x80; /* Right */
map.key[79].map[ALTSHFCTL] = map.key[79].map[SHFCTL] | 0x80; /* End */
map.key[80].map[ALTSHFCTL] = map.key[80].map[SHFCTL] | 0x80; /* Down */
map.key[81].map[ALTSHFCTL] = map.key[81].map[SHFCTL] | 0x80; /* PgDn */
map.key[83].map[ALTSHFCTL] = map.key[83].map[SHFCTL] | 0x80; /* Del */
if (ioctl(fileno(stdin), PIO_KEYMAP, &map) == -1) {
perror("ioctl(PIO_KEYMAP)");
exit(1);
}
}
/* unaccounted keys:
*
* control.
* left shift.
* alt.
* right shift.
* caps lock.
* num lock.
* scroll lock.
* SysReq.
*
*/
char *names[NUM_KEYS] = { 0,
"ESC", /* 1 */
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9", /* 10 */
"0",
"-",
"=",
"backspace",
"tab",
"q",
"w",
"e",
"r",
"t", /* 20 */
"y",
"u",
"i",
"o",
"p",
"[",
"]",
"enter",
"control?",
"a", /* 30 */
"s",
"d",
"f",
"g",
"h",
"j",
"k",
"l",
";",
"'", /* 40 */
"`",
"huh? 42",
"\\",
"z",
"x",
"c",
"v",
"b",
"n",
"m", /* 50 */
",",
".",
"/",
"huh? 54",
"PrtSc",
"huh? 56",
"huh? 57",
"huh? 58",
"F1? 59",
"F2? 60", /* 60 */
"F3? 61",
"F4? 62",
"F5? 63",
"F6? 64",
"F7? 65",
"F8? 66",
"F9? 67",
"F10? 68",
"huh? 69",
"huh? 70", /* 70 */
"Home",
"Up",
"PgUp",
"Minus",
"Left",
"Center",
"Right",
"Plus",
"End",
"Down", /* 80 */
"PgDn",
"Ins",
"Del" /* 83 */
};
show_keys()
{
int i;
if (ioctl(fileno(stdin), GIO_KEYMAP, &map) == -1) {
perror("ioctl(GIO_KEYMAP)");
exit(1);
}
printf("size: %d\n", map.n_keys);
for (i = 0; i < map.n_keys; i++) {
printf("\nkey: %3d\tspecial: %2x\tflags: %2x", i,
(int) map.key[i].spcl, (int) map.key[i].flgs);
if (names[i])
printf("\t\tcap: \"%s\"", names[i]);
puts("");
printf("\tnorm:\t%2x\tshift:\t%2x\tctrl:\t%2x\tshft-ctrl:\t%2x\n",
map.key[i].map[0], map.key[i].map[1], map.key[i].map[2],
map.key[i].map[3]);
printf(" alt norm:\t%2x\tshift:\t%2x\tctrl:\t%2x\tshft-ctrl:\t%2x\n",
map.key[i].map[4], map.key[i].map[5], map.key[i].map[6],
map.key[i].map[7]);
}
}
--
James R. Van Artsdalen james at bigtex.cactus.org "Live Free or Die"
Dell Computer Co 9505 Arboretum Blvd Austin TX 78759 512-338-8789
More information about the Comp.unix.sysv386
mailing list