mapkey, a program to set function keys for ISC 2... UNIX

Ken Keirnan kjk at PacBell.COM
Fri Sep 22 02:04:02 AEST 1989




There was enough response to my original posting about the availability
of "mapkey" (and posting source to this group) that I decided to take a
chance and post it.

Mapkey is a program to assign user defined values to the console keyboard
function keys 1-12 and several other keys.  This version is specific to
UNIX System V/386 release 3.2, and has only been tested on ISC UNIX 2.0.2.
The program can set or reset to default the value of single keys or, using
a mapfile, the values of one or more keys in a single invocation.  The file
I used for default key values, /usr/lib/keyboard/strings, may only exist
on the ISC version of UNIX 3.2.

I wrote "mapkey" because the "ttymap" program that came with my ISC 2.0.2
appears to be broken (or maybe I just can't figure out the manual entry :-)).


This program is hereby placed in public domain.


Ken Keirnan
Pacific Bell

kjk at PacBell.COM




# -------- CUT HERE -------- CUT HERE -------- CUT HERE --------
#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  Makefile README mapkey.1 mapkey.c mapkey.man
# Wrapped by kk1 at pt06b on Tue Sep 19 07:41:07 1989
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'Makefile' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Makefile'\"
else
echo shar: Extracting \"'Makefile'\" \(117 characters\)
sed "s/^X//" >'Makefile' <<'END_OF_FILE'
XLIBS =
XDEFMAP = \"/usr/lib/keyboard/strings\"
X
Xmapkey:	mapkey.c
X	$(CC) -DDEFMAP=$(DEFMAP) -o mapkey mapkey.c $(LIBS)
END_OF_FILE
if test 117 -ne `wc -c <'Makefile'`; then
    echo shar: \"'Makefile'\" unpacked with wrong size!
fi
# end of 'Makefile'
fi
if test -f 'README' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'README'\"
else
echo shar: Extracting \"'README'\" \(1327 characters\)
sed "s/^X//" >'README' <<'END_OF_FILE'
XOverview:
X
XMapkey is a program to assign user defined values to the console keyboard
Xfunction keys 1-12 and several other keys.  This version is specific to
XUNIX System V/386 release 3.2, and has only been tested on ISC UNIX 2.0.2.
XThe program can set or reset to default the value of single keys or, using
Xa mapfile, the values of one or more keys in a single invocation.  On ISC
X2.0.2 (I haven't seen other versions of Sys V/3.2) the function keys are
Xgiven values from 1 to 60 including the various shift/control key combinations.
XIn mapkey I chose to use the keywords "shift" and "ctrl" singly or in
Xcombination to select the appropriate variation of the function key, i.e.,
X
X		shift ctrl f10 "ps -eaf\r"
X
Xwould set the SHIFT-CTRL F10 key to the string "ps -eaf<cr>".
X
XI was inspired to write this when I couldn't get ISC's "ttymap" command
Xto function correctly.  I didn't attempt to duplicate "ttymap" (too much
Xwork!), but limited "mapkey" to what I use most.
X
XThe code is a completely original work and is free.  You will find no
Xcopyright notices but please don't sell copies, give it away.  If anybody
Xgets ambitious and turns mapkey into something wonderful, please send me
Xa copy.  Thanks :-).
X
XKen Keirnan
XPacific Bell
XSan Ramon, CA.
X
Xkjk at PacBell.COM
X(<backbone>!pacbell!kjk)
X
X
XP.S.
XThis may work under Xenix too.
END_OF_FILE
if test 1327 -ne `wc -c <'README'`; then
    echo shar: \"'README'\" unpacked with wrong size!
fi
# end of 'README'
fi
if test -f 'mapkey.1' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'mapkey.1'\"
else
echo shar: Extracting \"'mapkey.1'\" \(3339 characters\)
sed "s/^X//" >'mapkey.1' <<'END_OF_FILE'
X.TH MAPKEY 1 "" "" ""
X.SH NAME
Xmapkey \- set the value of console function keys
X.SH SYNOPSIS
X.B mapkey
X[
X.B \-p|\-r
X] [
X.B shift
X] [
X.B ctrl
X] fn [
X.B value
X]
X.br
X.B mapkey
X[
X.B \-p|\-r
X]
X.B \-m
Xmapfile
X.br
X.B mapkey
X.B \-p|\-r
X.SH DESCRIPTION
X.I Mapkey
Xis a utility for setting, resetting or printing the character strings
Xgenerated by function keys 1-12 and several other special keys on the
Xconsole keyboard.
X.P
XThe first form of
X.I mapkey
Xis used for setting, resetting or printing the value of single keys.
XIf the optional arguments
X.B shift
Xand/or
X.B ctrl
Xare used, they should be specified as the literal strings "shift" and
X"ctrl".  The argument
X.I fn
Xis the name of the function key and should be from the following
Xlist:
X.sp
X.TS
Xcenter;
Xl l l l l l l l .
Xf1	f2	f3	f4	f5	f6	f7	f8
Xf9	f10	f11	f12	home	up	pgup	minus
Xleft	center	right	plus	end	down	pgdn	ins
X.TE
X.sp
XWhen setting keys, if the
X.I value
Xargument is missing, the selected key will be reset to its default value.
XTo remove a key definition completely,
X.I value
Xmust be given as the empty string "".
X.I Value
Xmust be surrounded by single or double (' or ") quotes if it
Xcontains embedded spaces.
X.I Value
Xmay also contain any of the following special escapes which will be
Xexpanded as specified below:
X.TP
X\e\e,\eb,\ef,\en,\er,\et,\ev
XExpands to backslash, backspace, form feed, newline, carriage return, tab
Xand vertical tab respectively.
X.TP
X\e0n
XWhere
X.I n
Xis 1 to 3 octal digits expands to the character with that value.
X.TP
X\e',\e",\e^,\e$
XThese escapes are used to hide any special meaning of the character
Xfollowing the backslash so they can be included literally in the
X.I value
Xstring.  Note that
X.B mapkey
Xis usually smart enough to determine when the backslash
Xis not required (such as a ^ or $ followed by a space or at the end of a
Xline, or a single quote inside a double quoted string).
X.TP
X^c
XGenerates a control character from the character
X.IR c . 
XFor example
X.B ^M
X(or
X.BR ^m )
Xgenerates a control-M.
X.TP
X$ENV or ${ENV}
XThis escape is replaced with the string value of the shell environment
Xvariable
X.IR ENV .
XAs in the shell, the second form should be used if not followed by
Xthe end of the string or a space character.
X.P
XThe total length of
X.I value
Xis currently limited to 29 characters.
X.I Value
Xstrings are ignored when the print option
X.B \-p
Xis specified.  This is usefull for printing the current value of all keys
Xdefined in a map file (see below).
Xfile.
X.P
XThe second form of the command is used to set or print multiple key values
Xfrom a file of key descriptions.  The format of lines in
X.I mapfile
Xis the same as the first form of the command, above, minus the
X.B mapkey
Xcommand name.
XThe last form of
X.I mapkey
Xprints the value of all keys (option
X.BR \-p )
Xor resets all keys to default values (option
X.BR \-r ).
X.P
XWhen the
X.B \-r
Xoption is specified in the first or second form of the command, all
Xkeys are reset to default values before the key(s) is(are) set as requested
Xon the remainder of the command line.  Note that the
X.B \-p
Xand
X.B \-r
Xoptions are mutually exclusive.
X.SH FILES
X/usr/lib/keyboard/strings, default function key strings
X.SH "SEE ALSO"
Xkd(7)
X.SH CAVEATS
XInvoking
X.B mapkey
Xfrom a non-console terminal or redirecting the standard input
Xwill cause the program to fail.  The program works fine from virtual
Xconsoles.
END_OF_FILE
if test 3339 -ne `wc -c <'mapkey.1'`; then
    echo shar: \"'mapkey.1'\" unpacked with wrong size!
fi
# end of 'mapkey.1'
fi
if test -f 'mapkey.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'mapkey.c'\"
else
echo shar: Extracting \"'mapkey.c'\" \(12250 characters\)
sed "s/^X//" >'mapkey.c' <<'END_OF_FILE'
X/*
X * mapkey - set value of console function keys
X *
X *	Mapkey is specific to UNIX System V/386 release 3.2 or later.
X *	This program uses the Xenix SETKEY console ioctl() call to set
X *	keys, and expects the default key values to be in
X *
X *		/usr/lib/keyboard/strings
X */
X#include <sys/types.h>
X#include <sys/at_ansi.h>
X#include <sys/kd.h>
X#include <stdio.h>
X#include <ctype.h>
X
X#define FPR	(void)fprintf
X
X/*
X * This is a 512 byte file containing the default function key mapping.
X */
X#define DEFMAP	"/usr/lib/keyboard/strings"
X
X#define DFSIZ	512
X#define LBSIZ	512
X#define NFUNC	60
X
X/*
X * Add these values to the regular function keys (f1-f12)
X * to obtain the SHIFT, CTRL and SHIFT-CTRL versions.
X */
X#define SHIFTVAL	12
X#define CTRLVAL		24
X
Xchar *shift = "shift";
Xchar *ctrl = "ctrl";
X
Xchar defmap[DFSIZ+2];	/* default function key values buffer */
Xchar *defstr[NFUNC];	/* pointers to the default values */
Xchar lbuf[LBSIZ];	/* general purpose line buffer */
Xchar *mapfile = NULL;	/* user supplied file of function key defs */
X
Xchar *strcpy();
Xchar *strchr();
Xchar *getenv();
Xchar *expand();
X
Xint ctrlflg = 0;	/* set CTRL value of key */
Xint shiftflg = 0;	/* set SHIFT value of key */
Xint havedefs = 0;	/* sucessfully got default key values */
Xint reset = 0;		/* reset all default values */
Xint prkey = 0;		/* print value of key(s) */
Xint line = 0;		/* input line number from mapfile */
X
Xvoid exit();
X
X/*
X * KEYS structure contains names of function and special keys
X * along with key value used in ioctl() call.
X */
Xstruct KEYS {
X	char *kw;
X	int   kv;
X} keys[] = {
X	"f1",		1,
X	"f2",		2,
X	"f3",		3,
X	"f4",		4,
X	"f5",		5,
X	"f6",		6,
X	"f7",		7,
X	"f8",		8,
X	"f9",		9,
X	"f10",		10,
X	"f11",		11,
X	"f12",		12,
X	"home",		49,
X	"up",		50,
X	"pgup",		51,
X	"minus",	52,
X	"left",		53,
X	"center",	54,
X	"right",	55,
X	"plus",		56,
X	"end",		57,
X	"down",		58,
X	"pgdn",		59,
X	"ins",		60,
X	(char *)0,	0,
X};
X
X/*
X * "keyname" - names of function and special keys for printing
X */
Xchar *keyname[] = {
X	"",
X	"f1",		"f2",		"f3",		"f4",
X	"f5",		"f6",		"f7",		"f8",
X	"f9",		"f10",		"f11",		"f12",
X	"s f1",		"s f2",		"s f3",		"s f4",
X	"s f5",		"s f6",		"s f7",		"s f8",
X	"s f9",		"s f10",	"s f11",	"s f12",
X	"c f1",		"c f2",		"c f3",		"c f4",
X	"c f5",		"c f6",		"c f7",		"c f8",
X	"c f9",		"c f10",	"c f11",	"c f12",
X	"s-c f1",	"s-c f2",	"s-c f3",	"s-c f4",
X	"s-c f5",	"s-c f6",	"s-c f7",	"s-c f8",
X	"s-c f9",	"s-c f10",	"s-c f11",	"s-c f12",
X	"home",		"up",		"pgup",		"minus",
X	"left",		"center",	"right",	"plus",
X	"end",		"down",		"pgdn",		"ins",
X	(char *)0,
X};
X
Xmain(argc, argv)
Xint argc;
Xchar **argv;
X{
X	extern int optind;
X	extern char *optarg;
X	register c;
X
X	/* print help */
X	if (argc == 1 || argc == 2 && strcmp(argv[1], "help") == 0) {
X		usage();
X		help();
X		exit(0);
X	}
X	while ((c = getopt(argc, argv, "m:pr")) != EOF)
X		switch (c) {
X
X		case 'm':		/* file of key values */
X			mapfile = optarg;
X			break;
X
X		case 'p':		/* only print value */
X			prkey = 1;
X			break;
X
X		case 'r':		/* reset to default values */
X			reset = 1;
X			break;
X
X		case '?':
X			usage();
X			exit(1);
X		}
X
X	getdef();
X
X	if (prkey && reset) {
X		FPR(stderr, "\"-p\" and \"-r\" options are mutually exclusive\n");
X		exit(1);
X	}
X	if (reset)
X		keyreset();
X	if (mapfile) {
X		if (!dofile())
X			return(1);
X	} else if (prkey && optind >= argc) {
X		if (!prall())
X			return(1);
X	} else if (!dokey(argv + optind))
X		return(1);
X
X	return(0);
X}
X
X/*
X * dofile - process a file of function key assignments
X */
Xdofile()
X{
X	register FILE *fp;
X	char *farr[25];
X
X	if ((fp = fopen(mapfile, "r")) == NULL) {
X		FPR(stderr, "Can't open mapfile: %s\n", mapfile);
X		return(0);
X	}
X	/*
X	 * Read line by line, parse into fields and set the key value.
X	 */
X	while (getline(fp, lbuf)) {
X		if (!parse(lbuf, farr))
X			return(0);
X		if (!dokey(farr))
X			return(0);
X	}
X	(void)fclose(fp);
X
X	return(1);
X}
X
X/*
X * parse - break a line into fields.
X *
X *	Parse understands about quoted fields (single or double
X *	quotes) but does no translation of embedded escapes.
X */
Xparse(li, ar)
Xregister char *li;
Xchar **ar;
X{
X	register char **arr = ar;
X	char quote = 0;
X
X	for (;;) {
X		while (isspace(*li))
X			li++;
X		if (*li == 0)
X			break;
X		if (*li == '\'' || *li == '"')
X			quote = *li++;
X		else
X			quote = '\0';
X		*arr++ = li;
X		while (*li) {
X			if (quote) {
X				if (*li == '\\' && *(li+1) == quote)
X					li++;
X				else if (*li == quote)
X					break;
X			} else if (isspace(*li))
X				break;
X			li++;
X		}
X		if (quote && *li == '\0') {
X			prerr("unmatched quote\n");
X			return(0);
X		}
X		if (*li)
X			*li++ = 0; 
X	}
X	*arr = NULL;
X
X	return(arr - ar);
X}
X
X/*
X * getline - get a line from file pointer "fp" and store in buffer "buf"
X *
X *	Getline ignores empty lines (but updates the line count) and eats
X *	up leading white space on lines.
X */
Xgetline(fp, buf)
Xregister FILE *fp; 
Xchar *buf;
X{
X	register char *cp = buf;
X	register c;
X
X	do {
X		while ((c = getc(fp)) != '\n' && c != EOF) {
X			if (isspace(c) && cp == buf)
X				continue;
X			*cp++ = c;
X		}
X		if (c == EOF && cp == buf)
X			return(0);
X		line++;
X	} while (cp == buf);
X
X	*cp = 0;
X
X	return(1);
X}
X
X/*
X * dokey - extract function key assignment data from the array of fields
X *	   "arr" and set, reset or print) the key.
X */
Xdokey(arr)
Xchar **arr;
X{
X	register char **ap;
X	register char *value = NULL;
X	register key = 0;
X	char valbuf[128];
X	char *keyn;
X
X	if (arr[0] == NULL)
X		return(0);
X	for (ap = arr; *ap; ap++) {
X		if (!key) {
X			lowercase(*ap);
X
X			/* CTRL */
X			if (strcmp(*ap, ctrl) == 0) {
X				if (ctrlflg) {
X					prerr("only one \"ctrl\" allowed\n");
X					return(0);
X				}
X				ctrlflg = 1;
X			/* SHIFT */
X			} else if (strcmp(*ap, shift) == 0) {
X				if (shiftflg) {
X					prerr("only one \"shift\" allowed\n");
X					return(0);
X				}
X				shiftflg = 1;
X			} else if (key = lookup(*ap)) {
X				keyn = *ap;
X			} else {
X				prerr("unknown keyword: %s\n", *ap);
X				return(0);
X			}
X
X		} else {
X			if (*(ap+1) == NULL)
X				value = *ap;
X			else {
X				prerr("only one definition may follow key\n");
X				return(0);
X			}
X		}
X	}
X	if (key == 0) {
X		prerr("missing function key\n");
X		return(0);
X	} else if (key > 12 && (ctrlflg || shiftflg)) {
X		prerr("\"ctrl\", \"shift\" not allowed with \"%s\"\n", keyn);
X		return(0);
X	}
X	if (shiftflg)
X		key += SHIFTVAL;
X	if (ctrlflg)
X		key += CTRLVAL;
X
X	if (prkey) {
X		/*
X		 * Just print the key value ignoring any set string.
X		 */
X		if (!putkey(key))
X			return(0);
X	} else {
X		/*
X		 * If we have a new value, expand escapes, otherwise,
X		 * reset to the default value.
X		 */
X		if (value)
X			value = expand(valbuf, value);
X		else
X			value = defstr[key-1];
X
X		if (strlen(value) > (MAXFK - 1)) {
X			prerr("%s key definition string too long\n", keyn);
X			return(0);
X		}
X
X		setfunc(key, value);
X	}
X
X	return(key);
X}
X
X/*
X * lowercase - map a string to lower case
X */
Xlowercase(s)
Xregister char *s;
X{
X	while (*s) {
X		*s = tolower(*s);
X		s++;
X	}
X}
X
X/*
X * keyreset - reset all function keys to the default values.
X */
Xkeyreset()
X{
X	register i;
X
X	for (i = 0; i < NFUNC; i++)
X		setfunc(i+1, defstr[i]);
X}
X
X/*
X * lookup - get function key value from lookup table
X */
Xlookup(s)
Xregister char *s;
X{
X	register struct KEYS *kp;
X
X	for (kp = keys; kp->kw; kp++)
X		if (strcmp(kp->kw, s) == 0)
X			return(kp->kv);
X	return(0);
X}
X
X/*
X * setfunc - set function key number "k" to value "s"
X */
Xsetfunc(k, s)
Xregister k;
Xregister char *s;
X{
X	struct fkeyarg fk;
X
X	fk.keynum = k;
X	/*
X	 * Note: the following line generates noise from lint about
X	 * arg1 because "keydef" is defined as unsigned_char array.
X	 */
X	(void)strcpy(fk.keydef, s);
X	fk.flen = strlen(s);
X	if (ioctl(0, SETFKEY, &fk) < 0) {
X		FPR(stderr, "Must be on console\n");
X		exit(1);
X	}
X}
X
X/*
X * usage - print command usage
X */
Xusage()
X{
X	FPR(stderr, "Usage:   mapkey [-p | -r] [ctrl] [shift] fn [value]\n");
X	FPR(stderr, "         mapkey [-p | -r] -m mapfile\n");
X	FPR(stderr, "         mapkey -p | -r\n");
X}
X
Xhelp() {
X	FPR(stderr, "\nOptions: -m mapfile\tload key values from file \"mapfile\"\n\n");
X	FPR(stderr, "         -p\t\print current key values\n");
X	FPR(stderr, "         -r\t\treset all keys to default values\n");
X	FPR(stderr, "Where \"fn\" is one of the following:\n");
X	FPR(stderr, "f1\tf2\tf3\tf4\tf5\tf6\tf7\tf8\n");
X	FPR(stderr, "f9\tf10\tf11\tf12\thome\tup\tpgup\tminus\n");
X	FPR(stderr, "left\tcenter\tright\tplus\tend\tdown\tpgdn\tins\n\n");
X	FPR(stderr, "and \"value\" is the definition. \"Value\" may contain spaces if\n");
X	FPR(stderr, "if surrounded by quotes (' or \"), and may contain the following:\n");
X	FPR(stderr, "\\\\ - backslash\t\t\\b - backspace\t\t\\f - form feed\n");
X	FPR(stderr, "\\n - newline\t\t\\r - carriage return\t\\t - tab\n");
X	FPR(stderr, "\\v - vertical tab\t\\0n - character value, \"n\" = 1-3 octal digits\n\n");
X	FPR(stderr, "^c\tmakes character \"c\" a control character\n\n");
X	FPR(stderr, "$ENV or\n");
X	FPR(stderr, "${ENV}\texpands to value of shell environment variable \"ENV\"\n");
X}
X
X/*
X * getdef - get function key default values from DEFMAP file
X */
Xgetdef()
X{
X	register fd, i;
X	register char *cp;
X
X	havedefs = 0;
X	if ((fd = open(DEFMAP, 0)) == -1) {
X		FPR(stderr, "Warning: can't open key defaults: %s\n",DEFMAP);
X		return;
X	}
X	if (read(fd, defmap, DFSIZ) != DFSIZ) {
X		FPR(stderr, "Warning: possibly damaged: %s\n", DEFMAP);
X		if (reset)
X			return;
X	}
X	for (i = 0, cp = defmap; i < NFUNC; i++) {
X		defstr[i] = cp;
X		while (*cp++ && (cp - defmap) < DFSIZ)
X			;
X		if ((cp - defmap) >= DFSIZ && i < (NFUNC-1)) {
X			FPR(stderr, "Warning: possibly damaged: %s\n",DEFMAP);
X			if (reset)
X				return;
X			break;
X		}
X	}
X	while (i < NFUNC)
X		defstr[i] = "";
X	havedefs = 1;
X}
X
X/*
X * expand - translate character excapes in function key definitions.
X */
Xchar *
Xexpand(to, fr)
Xregister char *to, *fr;
X{
X	register c, n;
X	char *tosave = to;
X
X	while (c = *fr++) {
X		if (c == '\\') {	/* Special escapes */
X			switch(c = *fr++) {
X
X			case '\\':	/* backslash */
X				c = '\\';
X				break;
X			case 'b':	/* backspace */
X				c = '\b';
X				break;
X			case 'f':	/* form feed */
X				c = '\f';
X				break;
X			case 'n':	/* newline */
X				c = '\n';
X				break;
X			case 'r':	/* carriage return */
X				c = '\r';
X				break;
X			case 't':	/* tab */
X				c = '\t';
X				break;
X			case 'v':	/* vertical tab */
X				c = '\v';
X				break;
X			case '0':	/* octal character value */
X				c = n = 0;
X				while (*fr >= '0' && *fr <= '7' && n++ < 3) {
X					c <<= 3;
X					c |= (*fr++ - '0');
X				}
X				break;
X			case 0:		/* end of input string */
X				--fr;
X				continue;
X			/*
X			 * default: Any character not in the switch above
X			 *	    is printed "as is".  This is useful to
X			 *	    remove the special meaning of ^ and $.
X			 */
X			}
X		/* Make control character */
X		} else if (c == '^' && *fr && !isspace(*fr)) {
X			c = *fr++ & 037;
X		/* Environment variable */
X		} else if (c == '$' && *fr && !isspace(*fr)
X		    && *fr != '\\' && *fr != '^') {
X			char *endch, *ev;
X			char evbuf[LBSIZ];
X
X			/*
X			 * Allow either format: $VAR or ${VAR}
X			 */
X			if (*fr == '{') {
X				endch = "}";
X				fr++;
X			} else
X				endch = " \t";
X			ev = evbuf;
X			while (*fr && strchr(endch, *fr) == NULL)
X				*ev++ = *fr++;
X			*ev = 0;
X			if (*fr == '}')
X				fr++;
X			if ((ev = getenv(evbuf)) != NULL)
X				while (*ev)
X					*to++ = *ev++;
X			continue;
X		}
X		*to++ = c;
X	}
X	*to = 0;
X
X	return(tosave);
X}
X
Xprall()
X{
X	register i;
X
X	for (i = 1; i <= NFUNC; i++)
X		if (!putkey(i))
X			return(0);
X
X	return(1);
X}
X
Xputkey(i)
Xregister i;
X{
X	register j;
X	struct fkeyarg fk;
X
X	fk.keynum = i;
X	if (ioctl(0, GETFKEY, &fk) < 0) {
X		(void)fprintf(stderr, "Must be on console\n");
X		return(0);
X	}
X	(void)printf("%s\t= ", keyname[i]);
X	for (j = 0; j < fk.flen; j++) {
X		if (j)
X			(void)printf(",");
X		if (fk.keydef[j] == 0177)
X			(void)printf("DEL");
X		/*
X		 * Lint gets funny about "fk.keydef" because of
X		 * unsigned chars.
X		 */
X		else if (iscntrl(fk.keydef[j]))
X			(void)printf("^%c", (fk.keydef[j] | 0100));
X		else
X			(void)printf("%c", fk.keydef[j]);
X	}
X	(void)printf("\n");
X
X	return(1);
X}
X
X/*
X * prerr - print error messages
X *
X *	All arguments to prerr should be string values.  If function
X *	key values are from a user supplied mapfile, the input line
X *	number is also printed.
X */
X/* VARARGS */
Xprerr(fmt, s1, s2, s3)
Xchar *fmt, *s1, *s2, *s3;
X{
X	if (mapfile)
X		FPR(stderr, "%s: input line %d - ", mapfile, line);
X	FPR(stderr, fmt, s1, s2, s3);
X}
END_OF_FILE
if test 12250 -ne `wc -c <'mapkey.c'`; then
    echo shar: \"'mapkey.c'\" unpacked with wrong size!
fi
# end of 'mapkey.c'
fi
if test -f 'mapkey.man' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'mapkey.man'\"
else
echo shar: Extracting \"'mapkey.man'\" \(3799 characters\)
sed "s/^X//" >'mapkey.man' <<'END_OF_FILE'
X
X
X
X	  MAPKEY(1)		       386/ix			  MAPKEY(1)
X
X
X
X	  NAME
X	       mapkey -	set the	value of console function keys
X
X	  SYNOPSIS
X	       mapkey [	-p|-r ]	[ shift	] [ ctrl ] fn [	value ]
X	       mapkey [	-p|-r ]	-m mapfile
X	       mapkey -p|-r
X
X	  DESCRIPTION
X	       Mapkey is a utility for setting,	resetting or printing the
X	       character strings generated by function keys 1-12 and
X	       several other special keys on the console keyboard.
X
X	       The first form of mapkey	is used	for setting, resetting or
X	       printing	the value of single keys.  If the optional argu-
X	       ments shift and/or ctrl are used, they should be	specified
X	       as the literal strings "shift" and "ctrl".  The argument	fn
X	       is the name of the function key and should be from the fol-
X	       lowing list:
X
X		f1     f2	f3	f4     f5     f6     f7	    f8
X		f9     f10	f11	f12    home   up     pgup   minus
X		left   center	right	plus   end    down   pgdn   ins
X
X	       When setting keys, if the value argument	is missing, the
X	       selected	key will be reset to its default value.	 To remove
X	       a key definition	completely, value must be given	as the
X	       empty string "".	 Value must be surrounded by single or dou-
X	       ble (' or ") quotes if it contains embedded spaces.  Value
X	       may also	contain	any of the following special escapes which
X	       will be expanded	as specified below:
X
X	       \\,\b,\f,\n,\r,\t,\v
X		    Expands to backslash, backspace, form feed,	newline,
X		    carriage return, tab and vertical tab respectively.
X
X	       \0n  Where n is 1 to 3 octal digits expands to the character
X		    with that value.
X
X	       \',\",\^,\$
X		    These escapes are used to hide any special meaning of
X		    the	character following the	backslash so they can be
X		    included literally in the value string.  Note that map-
X		    key	is usually smart enough	to determine when the
X		    backslash is not required (such as a ^ or $	followed by
X		    a space or at the end of a line, or	a single quote
X		    inside a double quoted string).
X
X	       ^c   Generates a	control	character from the character c.
X		    For	example	^M (or ^m) generates a control-M.
X
X	       $ENV or ${ENV}
X		    This escape	is replaced with the string value of the
X
X
X	  Rev.							     Page 1
X
X
X
X
X
X
X	  MAPKEY(1)		       386/ix			  MAPKEY(1)
X
X
X
X		    shell environment variable ENV.  As	in the shell, the
X		    second form	should be used if not followed by the end
X		    of the string or a space character.
X
X	       The total length	of value is currently limited to 29 charac-
X	       ters.  Value strings are	ignored	when the print option -p is
X	       specified.  This	is usefull for printing	the current value
X	       of all keys defined in a	map file (see below).  file.
X
X	       The second form of the command is used to set or	print mul-
X	       tiple key values	from a file of key descriptions.  The for-
X	       mat of lines in mapfile is the same as the first	form of	the
X	       command,	above, minus the mapkey	command	name.  The last
X	       form of mapkey prints the value of all keys (option -p) or
X	       resets all keys to default values (option -r).
X
X	       When the	-r option is specified in the first or second form
X	       of the command, all keys	are reset to default values before
X	       the key(s) is(are) set as requested on the remainder of the
X	       command line.  Note that	the -p and -r options are mutually
X	       exclusive.
X
X	  FILES
X	       /usr/lib/keyboard/strings, default function key strings
X
X	  SEE ALSO
X	       kd(7)
X
X	  CAVEATS
X	       Invoking	mapkey from a non-console terminal or redirecting
X	       the standard input will cause the program to fail.  The pro-
X	       gram works fine from virtual consoles.
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X	  Rev.							     Page 2
X
X
X
END_OF_FILE
if test 3799 -ne `wc -c <'mapkey.man'`; then
    echo shar: \"'mapkey.man'\" unpacked with wrong size!
fi
# end of 'mapkey.man'
fi
echo shar: End of shell archive.
exit 0
-- 

Ken Keirnan - Pacific Bell - {att,bellcore,sun,ames,pyramid}!pacbell!pbhyf!kjk
  San Ramon, California	                    kjk at pbhyf.PacBell.COM



More information about the Comp.unix.i386 mailing list