2013-05-20 01:16:08 -04:00
|
|
|
/* bind.c -- implements bind.h */
|
|
|
|
#include "bind.h"
|
|
|
|
|
2013-10-08 22:48:00 -04:00
|
|
|
/* bind.c
|
2005-05-31 11:50:56 -04:00
|
|
|
*
|
2013-10-08 22:48:00 -04:00
|
|
|
* This file is for functions having to do with key bindings,
|
|
|
|
* descriptions, help commands and startup file.
|
2005-05-31 11:50:56 -04:00
|
|
|
*
|
2013-10-08 22:48:00 -04:00
|
|
|
* Written 11-feb-86 by Daniel Lawrence
|
|
|
|
* Modified by Petri Kutvonen
|
2005-05-31 11:50:56 -04:00
|
|
|
*/
|
|
|
|
|
2010-06-11 00:32:18 -04:00
|
|
|
#include <stdio.h>
|
2013-10-08 21:43:15 -04:00
|
|
|
#include <string.h>
|
2010-11-14 21:10:03 -05:00
|
|
|
|
2013-10-09 01:43:32 -04:00
|
|
|
#include "estruct.h"
|
2013-06-04 23:48:40 -04:00
|
|
|
#include "bindable.h"
|
2013-05-28 01:25:14 -04:00
|
|
|
#include "buffer.h"
|
2013-05-28 02:57:03 -04:00
|
|
|
#include "display.h"
|
2013-05-31 01:04:52 -04:00
|
|
|
#include "ebind.h"
|
2013-05-25 00:37:03 -04:00
|
|
|
#include "exec.h"
|
2013-05-25 00:28:17 -04:00
|
|
|
#include "file.h"
|
2013-06-10 06:14:09 -04:00
|
|
|
#include "flook.h"
|
2013-05-28 02:46:44 -04:00
|
|
|
#include "input.h"
|
2010-11-14 21:10:03 -05:00
|
|
|
#include "line.h"
|
2013-05-31 01:18:10 -04:00
|
|
|
#include "names.h"
|
2013-05-28 00:47:48 -04:00
|
|
|
#include "window.h"
|
2013-05-17 09:17:16 -04:00
|
|
|
|
|
|
|
|
2015-02-15 22:39:16 -05:00
|
|
|
#if APROP
|
2015-02-22 03:22:48 -05:00
|
|
|
static int buildlist( char *mstring) ;
|
2015-02-15 22:39:16 -05:00
|
|
|
static int strinc( char *source, char *sub) ;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void cmdstr( int c, char *seq) ;
|
|
|
|
static unsigned int getckey( int mflag) ;
|
|
|
|
static unsigned int stock( char *keyname) ;
|
|
|
|
static int unbindchar( int c) ;
|
2013-06-10 06:14:09 -04:00
|
|
|
static char *getfname( fn_t) ;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2015-02-15 22:39:16 -05:00
|
|
|
|
2005-09-30 20:52:20 -04:00
|
|
|
int help(int f, int n)
|
2013-10-08 22:48:00 -04:00
|
|
|
{ /* give me some help!!!!
|
|
|
|
bring up a fake buffer and read the help file
|
|
|
|
into it with view mode */
|
|
|
|
struct window *wp; /* scaning pointer to windows */
|
|
|
|
struct buffer *bp; /* buffer pointer to help */
|
|
|
|
char *fname = NULL; /* ptr to file returned by flook() */
|
|
|
|
|
|
|
|
/* first check if we are already here */
|
|
|
|
bp = bfind( hlpfname, FALSE, BFINVS);
|
|
|
|
|
|
|
|
if (bp == NULL) {
|
|
|
|
fname = flook( hlpfname, FALSE);
|
|
|
|
if (fname == NULL) {
|
|
|
|
mlwrite("(Help file is not online)");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* split the current window to make room for the help stuff */
|
|
|
|
if (splitwind(FALSE, 1) == FALSE)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (bp == NULL) {
|
|
|
|
/* and read the stuff in */
|
|
|
|
if (getfile(fname, FALSE) == FALSE)
|
|
|
|
return FALSE;
|
|
|
|
} else
|
|
|
|
swbuffer(bp);
|
|
|
|
|
|
|
|
/* make this window in VIEW mode, update all mode lines */
|
|
|
|
curwp->w_bufp->b_mode |= MDVIEW;
|
|
|
|
curwp->w_bufp->b_flag |= BFINVS;
|
|
|
|
wp = wheadp;
|
|
|
|
while (wp != NULL) {
|
|
|
|
wp->w_flag |= WFMODE;
|
|
|
|
wp = wp->w_wndp;
|
|
|
|
}
|
|
|
|
return TRUE;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-09-30 20:52:20 -04:00
|
|
|
int deskey(int f, int n)
|
2013-10-08 22:48:00 -04:00
|
|
|
{ /* describe the command for a certain key */
|
|
|
|
int c; /* key to describe */
|
|
|
|
char *ptr; /* string pointer to scan output strings */
|
|
|
|
char outseq[NSTRING]; /* output buffer for command sequence */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2013-10-08 22:48:00 -04:00
|
|
|
/* prompt the user to type us a key to describe */
|
|
|
|
mlwrite(": describe-key ");
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2013-10-08 22:48:00 -04:00
|
|
|
/* get the command sequence to describe
|
|
|
|
change it to something we can print as well */
|
2015-02-09 06:27:49 -05:00
|
|
|
c = getckey( FALSE) ;
|
|
|
|
mlwrite( ": describe-key 0x%x, ", c) ;
|
|
|
|
cmdstr( c, &outseq[ 0]) ;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2013-10-08 22:48:00 -04:00
|
|
|
/* and dump it out */
|
|
|
|
ostring(outseq);
|
|
|
|
ostring(" ");
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2013-10-08 22:48:00 -04:00
|
|
|
/* find the right ->function */
|
|
|
|
if ((ptr = getfname(getbind(c))) == NULL)
|
|
|
|
ptr = "Not Bound";
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2013-10-08 22:48:00 -04:00
|
|
|
/* output the command sequence */
|
|
|
|
ostring(ptr);
|
|
|
|
return TRUE;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-09-30 20:52:20 -04:00
|
|
|
/*
|
|
|
|
* bindtokey:
|
2013-10-08 22:48:00 -04:00
|
|
|
* add a new key to the key binding table
|
2005-09-30 20:52:20 -04:00
|
|
|
*
|
2013-10-08 22:48:00 -04:00
|
|
|
* int f, n; command arguments [IGNORED]
|
2005-09-30 20:52:20 -04:00
|
|
|
*/
|
|
|
|
int bindtokey(int f, int n)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2013-10-08 22:48:00 -04:00
|
|
|
unsigned int c; /* command key to bind */
|
|
|
|
fn_t kfunc; /* ptr to the requested function to bind to */
|
|
|
|
struct key_tab *ktp; /* pointer into the command table */
|
|
|
|
int found; /* matched command flag */
|
|
|
|
char outseq[80]; /* output buffer for keystroke sequence */
|
|
|
|
|
|
|
|
/* prompt the user to type in a key to bind */
|
|
|
|
mlwrite(": bind-to-key ");
|
|
|
|
|
|
|
|
/* get the function name to bind it to */
|
|
|
|
kfunc = getname();
|
|
|
|
if (kfunc == NULL) {
|
|
|
|
mlwrite("(No such function)");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
ostring(" ");
|
|
|
|
|
|
|
|
/* get the command sequence to bind */
|
|
|
|
c = getckey((kfunc == metafn) || (kfunc == cex) ||
|
|
|
|
(kfunc == unarg) || (kfunc == ctrlg));
|
|
|
|
|
|
|
|
/* change it to something we can print as well */
|
|
|
|
cmdstr(c, &outseq[0]);
|
|
|
|
|
|
|
|
/* and dump it out */
|
|
|
|
ostring(outseq);
|
|
|
|
|
|
|
|
/* if the function is a prefix key */
|
|
|
|
if (kfunc == metafn || kfunc == cex ||
|
|
|
|
kfunc == unarg || kfunc == ctrlg) {
|
|
|
|
|
|
|
|
/* search for an existing binding for the prefix key */
|
|
|
|
ktp = &keytab[0];
|
|
|
|
found = FALSE;
|
|
|
|
while (ktp->k_fp != NULL) {
|
|
|
|
if (ktp->k_fp == kfunc)
|
|
|
|
unbindchar(ktp->k_code);
|
|
|
|
++ktp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* reset the appropriate global prefix variable */
|
|
|
|
if (kfunc == metafn)
|
|
|
|
metac = c;
|
|
|
|
if (kfunc == cex)
|
|
|
|
ctlxc = c;
|
|
|
|
if (kfunc == unarg)
|
|
|
|
reptc = c;
|
|
|
|
if (kfunc == ctrlg)
|
|
|
|
abortc = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* search the table to see if it exists */
|
|
|
|
ktp = &keytab[0];
|
|
|
|
found = FALSE;
|
|
|
|
while (ktp->k_fp != NULL) {
|
|
|
|
if (ktp->k_code == c) {
|
|
|
|
found = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++ktp;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found) { /* it exists, just change it then */
|
|
|
|
ktp->k_fp = kfunc;
|
|
|
|
} else { /* otherwise we need to add it to the end */
|
|
|
|
/* if we run out of binding room, bitch */
|
|
|
|
if (ktp >= &keytab[NBINDS]) {
|
|
|
|
mlwrite("Binding table FULL!");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ktp->k_code = c; /* add keycode */
|
|
|
|
ktp->k_fp = kfunc; /* and the function pointer */
|
|
|
|
++ktp; /* and make sure the next is null */
|
|
|
|
ktp->k_code = 0;
|
|
|
|
ktp->k_fp = NULL;
|
|
|
|
}
|
|
|
|
return TRUE;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-09-30 20:52:20 -04:00
|
|
|
/*
|
|
|
|
* unbindkey:
|
2013-10-08 22:48:00 -04:00
|
|
|
* delete a key from the key binding table
|
2005-09-30 20:52:20 -04:00
|
|
|
*
|
2013-10-08 22:48:00 -04:00
|
|
|
* int f, n; command arguments [IGNORED]
|
2005-09-30 20:52:20 -04:00
|
|
|
*/
|
2005-10-01 03:33:44 -04:00
|
|
|
int unbindkey(int f, int n)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2013-10-08 22:48:00 -04:00
|
|
|
int c; /* command key to unbind */
|
|
|
|
char outseq[80]; /* output buffer for keystroke sequence */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2013-10-08 22:48:00 -04:00
|
|
|
/* prompt the user to type in a key to unbind */
|
|
|
|
mlwrite(": unbind-key ");
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2013-10-08 22:48:00 -04:00
|
|
|
/* get the command sequence to unbind */
|
|
|
|
c = getckey(FALSE); /* get a command sequence */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2013-10-08 22:48:00 -04:00
|
|
|
/* change it to something we can print as well */
|
|
|
|
cmdstr(c, &outseq[0]);
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2013-10-08 22:48:00 -04:00
|
|
|
/* and dump it out */
|
|
|
|
ostring(outseq);
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2013-10-08 22:48:00 -04:00
|
|
|
/* if it isn't bound, bitch */
|
|
|
|
if (unbindchar(c) == FALSE) {
|
|
|
|
mlwrite("(Key not bound)");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-30 20:52:20 -04:00
|
|
|
/*
|
|
|
|
* unbindchar()
|
|
|
|
*
|
2013-10-08 22:48:00 -04:00
|
|
|
* int c; command key to unbind
|
2005-09-30 20:52:20 -04:00
|
|
|
*/
|
2015-02-15 22:39:16 -05:00
|
|
|
static int unbindchar( int c) {
|
2013-10-08 22:48:00 -04:00
|
|
|
struct key_tab *ktp; /* pointer into the command table */
|
|
|
|
struct key_tab *sktp; /* saved pointer into the command table */
|
|
|
|
int found; /* matched command flag */
|
|
|
|
|
|
|
|
/* search the table to see if the key exists */
|
|
|
|
ktp = &keytab[0];
|
|
|
|
found = FALSE;
|
|
|
|
while (ktp->k_fp != NULL) {
|
|
|
|
if (ktp->k_code == c) {
|
|
|
|
found = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++ktp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if it isn't bound, bitch */
|
|
|
|
if (!found)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* save the pointer and scan to the end of the table */
|
|
|
|
sktp = ktp;
|
|
|
|
while (ktp->k_fp != NULL)
|
|
|
|
++ktp;
|
|
|
|
--ktp; /* backup to the last legit entry */
|
|
|
|
|
|
|
|
/* copy the last entry to the current one */
|
|
|
|
sktp->k_code = ktp->k_code;
|
|
|
|
sktp->k_fp = ktp->k_fp;
|
|
|
|
|
|
|
|
/* null out the last one */
|
|
|
|
ktp->k_code = 0;
|
|
|
|
ktp->k_fp = NULL;
|
|
|
|
return TRUE;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-09-30 20:52:20 -04:00
|
|
|
/* describe bindings
|
|
|
|
* bring up a fake buffer and list the key bindings
|
|
|
|
* into it with view mode
|
|
|
|
*/
|
|
|
|
int desbind(int f, int n)
|
2013-10-08 22:48:00 -04:00
|
|
|
#if APROP
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2015-02-22 03:22:48 -05:00
|
|
|
buildlist( "") ;
|
2013-10-08 22:48:00 -04:00
|
|
|
return TRUE;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-09-30 20:52:20 -04:00
|
|
|
int apro(int f, int n)
|
2013-10-08 22:48:00 -04:00
|
|
|
{ /* Apropos (List functions that match a substring) */
|
|
|
|
char mstring[NSTRING]; /* string to match cmd names to */
|
|
|
|
int status; /* status return */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2013-10-08 22:48:00 -04:00
|
|
|
status = mlreply("Apropos string: ", mstring, NSTRING - 1);
|
2015-02-22 03:22:48 -05:00
|
|
|
if (status == ABORT)
|
2013-10-08 22:48:00 -04:00
|
|
|
return status;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2015-02-22 03:22:48 -05:00
|
|
|
return buildlist( mstring) ;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-09-30 20:52:20 -04:00
|
|
|
/*
|
|
|
|
* build a binding list (limited or full)
|
|
|
|
*
|
2015-02-22 03:22:48 -05:00
|
|
|
* char *mstring; match string if a partial list, "" matches all
|
2005-09-30 20:52:20 -04:00
|
|
|
*/
|
2015-02-22 03:22:48 -05:00
|
|
|
static int buildlist( char *mstring)
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
{
|
2013-10-08 22:48:00 -04:00
|
|
|
struct window *wp; /* scanning pointer to windows */
|
|
|
|
struct key_tab *ktp; /* pointer into the command table */
|
|
|
|
struct name_bind *nptr; /* pointer into the name binding table */
|
|
|
|
struct buffer *bp; /* buffer to put binding list into */
|
|
|
|
char outseq[80]; /* output buffer for keystroke sequence */
|
|
|
|
|
|
|
|
/* split the current window to make room for the binding list */
|
|
|
|
if (splitwind(FALSE, 1) == FALSE)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* and get a buffer for it */
|
|
|
|
bp = bfind("*Binding list*", TRUE, 0);
|
|
|
|
if (bp == NULL || bclear(bp) == FALSE) {
|
|
|
|
mlwrite("Can not display binding list");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* let us know this is in progress */
|
|
|
|
mlwrite("(Building binding list)");
|
|
|
|
|
|
|
|
/* disconect the current buffer */
|
|
|
|
if (--curbp->b_nwnd == 0) { /* Last use. */
|
|
|
|
curbp->b_dotp = curwp->w_dotp;
|
|
|
|
curbp->b_doto = curwp->w_doto;
|
|
|
|
curbp->b_markp = curwp->w_markp;
|
|
|
|
curbp->b_marko = curwp->w_marko;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* connect the current window to this buffer */
|
|
|
|
curbp = bp; /* make this buffer current in current window */
|
|
|
|
bp->b_mode = 0; /* no modes active in binding list */
|
|
|
|
bp->b_nwnd++; /* mark us as more in use */
|
|
|
|
wp = curwp;
|
|
|
|
wp->w_bufp = bp;
|
|
|
|
wp->w_linep = bp->b_linep;
|
|
|
|
wp->w_flag = WFHARD | WFFORCE;
|
|
|
|
wp->w_dotp = bp->b_dotp;
|
|
|
|
wp->w_doto = bp->b_doto;
|
|
|
|
wp->w_markp = NULL;
|
|
|
|
wp->w_marko = 0;
|
|
|
|
|
|
|
|
/* build the contents of this window, inserting it line by line */
|
2015-02-22 03:22:48 -05:00
|
|
|
for( nptr = &names[ 0] ; nptr->n_func != NULL ; nptr++) {
|
|
|
|
int cpos ; /* current position to use in outseq */
|
2013-10-08 22:48:00 -04:00
|
|
|
|
|
|
|
#if APROP
|
|
|
|
/* if we are executing an apropos command..... */
|
|
|
|
/* and current string doesn't include the search string */
|
2015-02-22 03:22:48 -05:00
|
|
|
if( *mstring && strinc( nptr->n_name, mstring) == FALSE)
|
|
|
|
continue ;
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
2015-02-22 03:22:48 -05:00
|
|
|
/* add in the command name */
|
|
|
|
strcpy(outseq, nptr->n_name);
|
|
|
|
cpos = strlen(outseq);
|
|
|
|
|
2013-10-08 22:48:00 -04:00
|
|
|
/* search down any keys bound to this */
|
|
|
|
ktp = &keytab[0];
|
|
|
|
while (ktp->k_fp != NULL) {
|
|
|
|
if (ktp->k_fp == nptr->n_func) {
|
|
|
|
/* padd out some spaces */
|
|
|
|
while (cpos < 28)
|
|
|
|
outseq[cpos++] = ' ';
|
|
|
|
|
|
|
|
/* add in the command sequence */
|
|
|
|
cmdstr(ktp->k_code, &outseq[cpos]);
|
|
|
|
strcat(outseq, "\n");
|
|
|
|
|
|
|
|
/* and add it as a line into the buffer */
|
|
|
|
if (linstr(outseq) != TRUE)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
cpos = 0; /* and clear the line */
|
|
|
|
}
|
|
|
|
++ktp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if no key was bound, we need to dump it anyway */
|
|
|
|
if (cpos > 0) {
|
|
|
|
outseq[cpos++] = '\n';
|
|
|
|
outseq[cpos] = 0;
|
|
|
|
if (linstr(outseq) != TRUE)
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
curwp->w_bufp->b_mode |= MDVIEW; /* put this buffer view mode */
|
|
|
|
curbp->b_flag &= ~BFCHG; /* don't flag this as a change */
|
|
|
|
wp->w_dotp = lforw(bp->b_linep); /* back to the beginning */
|
|
|
|
wp->w_doto = 0;
|
|
|
|
wp = wheadp; /* and update ALL mode lines */
|
|
|
|
while (wp != NULL) {
|
|
|
|
wp->w_flag |= WFMODE;
|
|
|
|
wp = wp->w_wndp;
|
|
|
|
}
|
|
|
|
mlwrite(""); /* clear the mode line */
|
|
|
|
return TRUE;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2013-10-08 22:48:00 -04:00
|
|
|
#if APROP
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2005-09-30 20:52:20 -04:00
|
|
|
/*
|
|
|
|
* does source include sub?
|
|
|
|
*
|
2013-10-08 22:48:00 -04:00
|
|
|
* char *source; string to search in
|
|
|
|
* char *sub; substring to look for
|
2005-09-30 20:52:20 -04:00
|
|
|
*/
|
2015-02-15 22:39:16 -05:00
|
|
|
static int strinc( char *source, char *sub) {
|
2013-10-08 22:48:00 -04:00
|
|
|
/* for each character in the source string */
|
2015-02-22 03:22:48 -05:00
|
|
|
for( ; *source ; source++) {
|
|
|
|
char *nxtsp ; /* next ptr into source */
|
|
|
|
char *tp ; /* ptr into substring */
|
|
|
|
|
|
|
|
nxtsp = source;
|
2013-10-08 22:48:00 -04:00
|
|
|
|
|
|
|
/* is the substring here? */
|
2015-02-22 03:22:48 -05:00
|
|
|
for( tp = sub ; *tp ; tp++)
|
|
|
|
if( *nxtsp++ != *tp)
|
|
|
|
break ;
|
2013-10-08 22:48:00 -04:00
|
|
|
|
|
|
|
/* yes, return a success */
|
2015-02-22 03:22:48 -05:00
|
|
|
if( *tp == 0)
|
|
|
|
return TRUE ;
|
2013-10-08 22:48:00 -04:00
|
|
|
}
|
2015-02-22 03:22:48 -05:00
|
|
|
|
|
|
|
return FALSE ;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-09-30 20:52:20 -04:00
|
|
|
/*
|
|
|
|
* get a command key sequence from the keyboard
|
|
|
|
*
|
2013-10-08 22:48:00 -04:00
|
|
|
* int mflag; going for a meta sequence?
|
2005-09-30 20:52:20 -04:00
|
|
|
*/
|
2015-02-15 22:39:16 -05:00
|
|
|
static unsigned int getckey( int mflag) {
|
2013-10-08 22:48:00 -04:00
|
|
|
unsigned int c; /* character fetched */
|
|
|
|
|
|
|
|
/* check to see if we are executing a command line */
|
|
|
|
if (clexec) {
|
2015-02-22 03:22:48 -05:00
|
|
|
char tok[ NSTRING] ; /* command incoming */
|
|
|
|
|
2015-01-07 23:46:46 -05:00
|
|
|
macarg( tok, sizeof tok) ; /* get the next token */
|
2013-10-08 22:48:00 -04:00
|
|
|
return stock(tok);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* or the normal way */
|
|
|
|
if (mflag)
|
|
|
|
c = get1key();
|
|
|
|
else
|
|
|
|
c = getcmd();
|
|
|
|
return c;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-09-30 20:52:20 -04:00
|
|
|
/*
|
|
|
|
* execute the startup file
|
|
|
|
*
|
2015-01-16 08:12:27 -05:00
|
|
|
* char *fname; name of startup file (null if default)
|
2005-09-30 20:52:20 -04:00
|
|
|
*/
|
2015-01-16 08:12:27 -05:00
|
|
|
int startup( const char *fname) {
|
|
|
|
if( !fname || *fname == 0) /* use default if empty parameter */
|
|
|
|
fname = rcfname ;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2015-01-16 08:12:27 -05:00
|
|
|
fname = flook( fname, TRUE) ; /* look up the startup file */
|
|
|
|
if( fname == NULL) /* if it isn't around, don't sweat it */
|
|
|
|
return TRUE ;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2015-01-16 08:12:27 -05:00
|
|
|
return dofile( fname) ; /* otherwise, execute the sucker */
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-09-30 20:52:20 -04:00
|
|
|
/*
|
|
|
|
* change a key command to a string we can print out
|
|
|
|
*
|
2013-10-08 22:48:00 -04:00
|
|
|
* int c; sequence to translate
|
|
|
|
* char *seq; destination string for sequence
|
2005-09-30 20:52:20 -04:00
|
|
|
*/
|
2015-02-15 22:39:16 -05:00
|
|
|
static void cmdstr( int c, char *seq) {
|
2013-10-08 22:48:00 -04:00
|
|
|
char *ptr; /* pointer into current position in sequence */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2013-10-08 22:48:00 -04:00
|
|
|
ptr = seq;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2013-10-08 22:48:00 -04:00
|
|
|
/* apply meta sequence if needed */
|
|
|
|
if (c & META) {
|
|
|
|
*ptr++ = 'M';
|
|
|
|
*ptr++ = '-';
|
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2013-10-08 22:48:00 -04:00
|
|
|
/* apply ^X sequence if needed */
|
|
|
|
if (c & CTLX) {
|
|
|
|
*ptr++ = '^';
|
|
|
|
*ptr++ = 'X';
|
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2013-10-08 22:48:00 -04:00
|
|
|
/* apply SPEC sequence if needed */
|
|
|
|
if (c & SPEC) {
|
|
|
|
*ptr++ = 'F';
|
|
|
|
*ptr++ = 'N';
|
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2013-10-08 22:48:00 -04:00
|
|
|
/* apply control sequence if needed */
|
|
|
|
if (c & CONTROL) {
|
|
|
|
*ptr++ = '^';
|
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2013-10-08 22:48:00 -04:00
|
|
|
/* and output the final sequence */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2013-10-08 22:48:00 -04:00
|
|
|
*ptr++ = c & 255; /* strip the prefixes */
|
2005-09-30 18:26:09 -04:00
|
|
|
|
2013-10-08 22:48:00 -04:00
|
|
|
*ptr = 0; /* terminate the string */
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-09-30 20:52:20 -04:00
|
|
|
/*
|
|
|
|
* This function looks a key binding up in the binding table
|
|
|
|
*
|
2013-10-08 22:48:00 -04:00
|
|
|
* int c; key to find what is bound to it
|
2005-09-30 20:52:20 -04:00
|
|
|
*/
|
|
|
|
int (*getbind(int c))(int, int)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2013-10-08 22:48:00 -04:00
|
|
|
struct key_tab *ktp;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2013-10-08 22:48:00 -04:00
|
|
|
ktp = &keytab[0]; /* Look in key table. */
|
|
|
|
while (ktp->k_fp != NULL) {
|
|
|
|
if (ktp->k_code == c)
|
|
|
|
return ktp->k_fp;
|
|
|
|
++ktp;
|
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2013-10-08 22:48:00 -04:00
|
|
|
/* no such binding */
|
|
|
|
return NULL;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-09-30 20:52:20 -04:00
|
|
|
/*
|
|
|
|
* getfname:
|
2013-10-08 22:48:00 -04:00
|
|
|
* This function takes a ptr to function and gets the name
|
|
|
|
* associated with it.
|
2005-09-30 20:52:20 -04:00
|
|
|
*/
|
2013-06-10 06:14:09 -04:00
|
|
|
static char *getfname(fn_t func)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2013-10-08 22:48:00 -04:00
|
|
|
struct name_bind *nptr; /* pointer into the name binding table */
|
|
|
|
|
|
|
|
/* skim through the table, looking for a match */
|
|
|
|
nptr = &names[0];
|
|
|
|
while (nptr->n_func != NULL) {
|
|
|
|
if (nptr->n_func == func)
|
|
|
|
return nptr->n_name;
|
|
|
|
++nptr;
|
|
|
|
}
|
|
|
|
return NULL;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-09-30 20:52:20 -04:00
|
|
|
/*
|
|
|
|
* match fname to a function in the names table
|
|
|
|
* and return any match or NULL if none
|
|
|
|
*
|
2013-10-08 22:48:00 -04:00
|
|
|
* char *fname; name to attempt to match
|
2005-09-30 20:52:20 -04:00
|
|
|
*/
|
|
|
|
int (*fncmatch(char *fname)) (int, int)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2013-10-08 22:48:00 -04:00
|
|
|
struct name_bind *ffp; /* pointer to entry in name binding table */
|
|
|
|
|
|
|
|
/* scan through the table, returning any match */
|
|
|
|
ffp = &names[0];
|
|
|
|
while (ffp->n_func != NULL) {
|
|
|
|
if (strcmp(fname, ffp->n_name) == 0)
|
|
|
|
return ffp->n_func;
|
|
|
|
++ffp;
|
|
|
|
}
|
|
|
|
return NULL;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-09-30 20:52:20 -04:00
|
|
|
/*
|
|
|
|
* stock:
|
2013-10-08 22:48:00 -04:00
|
|
|
* String key name TO Command Key
|
2005-09-30 20:52:20 -04:00
|
|
|
*
|
2013-10-08 22:48:00 -04:00
|
|
|
* char *keyname; name of key to translate to Command key form
|
2005-09-30 20:52:20 -04:00
|
|
|
*/
|
2015-02-15 22:39:16 -05:00
|
|
|
static unsigned int stock( char *keyname) {
|
2013-10-08 22:48:00 -04:00
|
|
|
unsigned int c; /* key sequence to return */
|
|
|
|
|
|
|
|
/* parse it up */
|
|
|
|
c = 0;
|
|
|
|
|
|
|
|
/* first, the META prefix */
|
|
|
|
if (*keyname == 'M' && *(keyname + 1) == '-') {
|
|
|
|
c = META;
|
|
|
|
keyname += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* next the function prefix */
|
|
|
|
if (*keyname == 'F' && *(keyname + 1) == 'N') {
|
|
|
|
c |= SPEC;
|
|
|
|
keyname += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* control-x as well... (but not with FN) */
|
|
|
|
if (*keyname == '^' && *(keyname + 1) == 'X' && !(c & SPEC)) {
|
|
|
|
c |= CTLX;
|
|
|
|
keyname += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* a control char? */
|
|
|
|
if (*keyname == '^' && *(keyname + 1) != 0) {
|
|
|
|
c |= CONTROL;
|
|
|
|
++keyname;
|
|
|
|
}
|
|
|
|
if (*keyname < 32) {
|
|
|
|
c |= CONTROL;
|
|
|
|
*keyname += 'A';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* make sure we are not lower case (not with function keys) */
|
|
|
|
if (*keyname >= 'a' && *keyname <= 'z' && !(c & SPEC))
|
|
|
|
*keyname -= 32;
|
|
|
|
|
|
|
|
/* the final sequence... */
|
2015-02-22 03:22:48 -05:00
|
|
|
c |= *keyname & 0xFFU ;
|
2013-10-08 22:48:00 -04:00
|
|
|
return c;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-09-30 20:52:20 -04:00
|
|
|
/*
|
|
|
|
* string key name to binding name....
|
|
|
|
*
|
2013-10-08 22:48:00 -04:00
|
|
|
* char *skey; name of keey to get binding for
|
2005-09-30 20:52:20 -04:00
|
|
|
*/
|
|
|
|
char *transbind(char *skey)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2013-10-08 22:48:00 -04:00
|
|
|
char *bindname;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2013-10-08 22:48:00 -04:00
|
|
|
bindname = getfname(getbind(stock(skey)));
|
|
|
|
if (bindname == NULL)
|
|
|
|
bindname = "ERROR";
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2013-10-08 22:48:00 -04:00
|
|
|
return bindname;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|