[net.micro.amiga] Patch for 1.2 usa0 keymap

mic@ut-ngp.UUCP (Mic Kaczmarczik) (10/11/86)

[Picasso wasn't born in a day]

I finally got fed up with not being able to use CTRL-Space to set the
mark in Emacs, and the following program is the result.  Documentation
is in the header comment.

Enjoy,

--mic--

-----------------------It works best if you cut here--------------------
/*
 * (NOTE: This program is only useful under the 1.2 Workbench.  It
 * does not apply to version 1.1, which doesn't support resetting
 * the default keymap.)
 *
 * If you've used a version of Emacs on the Amiga under the 1.1 Workbench
 * and then started using 1.2, you may be wondering here all the META keys
 * went!
 *
 * Well, C-A decided to make the default American keymap generate the
 * same codes as the default European keymaps, which use ALT-ed codes
 * for special characters and such.  Luckily, the 1.1 default keymap
 * is still available; it's in the file devs:keymaps/usa0, and you can make
 * it your console device keymap using the command "setmap usa0".
 * I really prefer this for text editing using Emacs, since the ALT key
 * is equivalent to the META key -- which makes for much less typing!
 *
 * However, there are a couple of key combinations I constantly use
 * (or would like to use) that aren't standard in the usa0 keymap.
 * So, I got out my RKM and deciphered the keymap format enough to
 * make the changes you'll find in the following program.
 *
 * The program adds the following keys to the usa0 keymap:
 *
 *	Key combination	Code sent	Emacs usage
 *	---------------------------------------------------
 *	CTRL-Space	0x00		set-mark-command (very nice)
 *	ALT-CTRL-Space	0x80		(unbound)
 *	ALT-Delete	0xFF		backward-kill-word
 *	ALT-Backspace	0x88		(I bind it to backward-kill-word too)
 *
 *
 * I compiled this under Manx small model, but wrote it to be portable to
 * Lettuce. Once Mike Meyer found all the bugs in the copy I sent him, it
 * actually did compile and work! :-) To compile and link it using Manx,
 *
 *	cc -o usa0_patch.o usa0_patch.c
 *	ln -o Usa0_patch usa0_patch.o -lc
 *
 * Then (under the 1.2 Workbench!) type
 *	usa0_patch
 *	setmap usa9
 *
 * to create the new keymap file, and make it the default keymap for all
 * console devices opened thereafter.
 * 
 * NOTE: If you don't like the name "usa9", just change keymapname[]
 * and newkeymap[] to suit your taste.  The name *must* be 4 chars long,
 * to match the string "usa0".
 *
 * Mic Kaczmarczik
 * ...!ihnp4!seismo!ut-sally!ut-ngp!mic
 * mic@ngp.utexas.edu
 * CCEP001@UTADNX.BITNET
 */

#include <libraries/dos.h>
#include <libraries/dosextens.h>
#include <devices/keymap.h>

char keymapname[] = "usa9";		/* must be at least 4 characters long */
char newkeymap[] = "devs:keymaps/usa9";

struct FileHandle *Open();
LONG Read(), Write(), Close();

main()
{
	struct FileHandle *fh;
	LONG size;
	char buf[1024];			/* > than size of usa0 keymap (922)*/

	/* find and read keymap into memory */
	if ((fh = Open("devs:keymaps/usa0", MODE_OLDFILE)) == NULL)
		exit(10000);
	size = Read(fh, buf, (LONG) (sizeof buf));
	Close(fh);

	/* modify Space key */
	buf[0x00AC] |= KCF_CONTROL;	/* set new keytype		*/
	buf[0x01E4] = 0x80;		/* ALT-CTRL-Space = 0x80	*/
	buf[0x01E5] = 0x00;		/* CTRL-Space = 0x00 (NUL)	*/

	/* modify Backspace key */
	buf[0x00AD] = KCF_ALT;		/* new keytype			*/
	buf[0x01EA] = 0x88;		/* ALT-Backspace = 0x88		*/

	/* modify Delete key */
	buf[0x00B2] = KCF_ALT;		/* keytype = KCF_ALT		*/
	buf[0x01FE] = 0xFF;		/* ALT-Delete = 0xFF		*/

	/* Change name from usa0, to avoid name collision.		*/
	buf[0x0360] = keymapname[0];
	buf[0x0361] = keymapname[1];
	buf[0x0362] = keymapname[2];
	buf[0x0363] = keymapname[3];

	/* Write the new keymap file */
	if ((fh = Open(newkeymap, MODE_NEWFILE)) == NULL)
		exit(10000);
	Write(fh, buf, size);
	Close(fh);
	exit(0);
}