v03i028: mg 2a part 4 of 15
Bob Larson
BLARSON at ECLA.USC.EDU
Thu May 26 14:52:27 AEST 1988
comp.sources.misc: Volume 3, Issue 28
Submitted-By: "Bob Larson" <BLARSON at ECLA.USC.EDU>
Archive-Name: mg2a/Part4
# This is a shell archive.
# Remove everything above and including the cut line.
# Then run the rest of the file through sh.
#----cut here-----cut here-----cut here-----cut here----#
#!/bin/sh
# shar: Shell Archiver
# Run the following text with /bin/sh to create:
# kbd.c
# kbd.h
# key.h
# keymap.c
# line.c
# macro.h
# main.c
# This archive created: Tue May 17 18:06:01 1988
# By: blarson
cat << \SHAR_EOF > kbd.c
/*
* Terminal independent keyboard handling.
*/
#include "def.h"
#include "kbd.h"
#define EXTERN
#include "key.h"
#ifndef NO_MACRO
#include "macro.h"
#endif
#ifdef DO_METAKEY
#ifndef METABIT
#define METABIT 0x80
#endif
int use_metakey = TRUE;
/*
* Toggle the value of use_metakey
*/
do_meta(f, n)
{
if(f & FFARG) use_metakey = n > 0;
else use_metakey = !use_metakey;
ewprintf("Meta keys %sabled", use_metakey ? "en" : "dis");
return TRUE;
}
#endif
#ifdef BSMAP
static int bs_map = BSMAP;
/*
* Toggle backspace mapping
*/
bsmap(f, n)
{
if(f & FFARG) bs_map = n > 0;
else bs_map = ! bs_map;
ewprintf("Backspace mapping %sabled", bs_map ? "en" : "dis");
return TRUE;
}
#endif
#ifndef NO_DPROMPT
#define PROMPTL 80
char prompt[PROMPTL], *promptp;
#endif
static int pushed = FALSE;
static int pushedc;
VOID ungetkey(c)
int c;
{
#ifdef DO_METAKEY
if(use_metakey && pushed && c==CCHR('[')) pushedc |= METABIT;
else
#endif
pushedc = c;
pushed = TRUE;
}
int getkey(flag)
int flag;
{
int c;
char *keyname();
#ifndef NO_DPROMPT
if(flag && !pushed) {
if(prompt[0]!='\0' && ttwait()) {
ewprintf("%s", prompt); /* avoid problems with % */
update(); /* put the cursor back */
epresf = KPROMPT;
}
if(promptp > prompt) *(promptp-1) = ' ';
}
#endif
if(pushed) {
c = pushedc;
pushed = FALSE;
} else c = getkbd();
#ifdef BSMAP
if(bs_map)
if(c==CCHR('H')) c=CCHR('?');
else if(c==CCHR('?')) c=CCHR('H');
#endif
#ifdef DO_METAKEY
if(use_metakey && (c&METABIT)) {
pushedc = c & ~METABIT;
pushed = TRUE;
c = CCHR('[');
}
#endif
#ifndef NO_DPROMPT
if(flag && promptp < &prompt[PROMPTL - 5]) {
promptp = keyname(promptp, c);
*promptp++ = '-';
*promptp = '\0';
}
#endif
return c;
}
/*
* doscan scans a keymap for a keyboard character and returns a pointer
* to the function associated with that character. Sets ele to the
* keymap element the keyboard was found in as a side effect.
*/
MArt();
#endif
if (n < 0) return FALSE;
if (n == 0) return TRUE;
c = key.k_chars[key.k_count-1];
#ifndef NO_MACRO
if(macrodef && macrocount < MAXMACRO) {
if(f & FFARG) macrocount -= 2;
if(lastflag & CFINS) { /* last command was insert -- tack on end */
macrocount--;
if(maclcur->l_size < maclcur->l_used + n) {
if((lp = lallocx(maclcur->l_used + n)) == NULL)
return FALSE;
lp->l_fp = maclcur->l_fp;
lp->l_bp = maclcur->l_bp;
lp->l_fp->l_bp = lp->l_bp->l_fp = lp;
bcopy(
More information about the Comp.sources.misc
mailing list