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
|
|
|
*/
|
|
|
|
|
2021-07-20 05:34:35 -04:00
|
|
|
#include <assert.h>
|
2010-06-11 00:32:18 -04:00
|
|
|
#include <stdio.h>
|
2015-09-27 09:11:51 -04:00
|
|
|
#include <stdlib.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-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"
|
2019-06-19 07:49:20 -04:00
|
|
|
#include "util.h"
|
2013-05-28 00:47:48 -04:00
|
|
|
#include "window.h"
|
2013-05-17 09:17:16 -04:00
|
|
|
|
|
|
|
|
2015-02-22 03:22:48 -05:00
|
|
|
static int buildlist( char *mstring) ;
|
2021-07-31 00:35:39 -04:00
|
|
|
static char *cmdstr( unsigned c, char *seq) ;
|
2015-02-15 22:39:16 -05:00
|
|
|
static unsigned int getckey( int mflag) ;
|
|
|
|
static unsigned int stock( char *keyname) ;
|
2021-07-19 03:39:00 -04:00
|
|
|
static const char *getfname( unsigned keycode, char *failmsg) ;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2015-02-15 22:39:16 -05:00
|
|
|
|
2021-07-29 21:30:12 -04:00
|
|
|
BINDABLE( help) {
|
|
|
|
/* give me some help!!!!
|
|
|
|
bring up a fake buffer and read the help file into it with view mode */
|
2013-10-08 22:48:00 -04:00
|
|
|
char *fname = NULL; /* ptr to file returned by flook() */
|
|
|
|
|
2021-07-29 21:30:12 -04:00
|
|
|
/* first check if we are already here */
|
|
|
|
buffer_p bp = bfind( hlpfname, FALSE, BFINVS);
|
|
|
|
if( bp == curbp)
|
|
|
|
return TRUE ;
|
2013-10-08 22:48:00 -04:00
|
|
|
|
|
|
|
if (bp == NULL) {
|
|
|
|
fname = flook( hlpfname, FALSE);
|
|
|
|
if (fname == NULL) {
|
|
|
|
mlwrite("(Help file is not online)");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-29 21:30:12 -04:00
|
|
|
/* split the current window to make room for the help stuff */
|
|
|
|
if( wheadp->w_wndp == NULL /* One window */
|
|
|
|
&& splitwind( FALSE, 1) == FALSE) /* Split it */
|
|
|
|
return FALSE ;
|
2013-10-08 22:48:00 -04:00
|
|
|
|
|
|
|
if (bp == NULL) {
|
|
|
|
/* and read the stuff in */
|
|
|
|
if (getfile(fname, FALSE) == FALSE)
|
|
|
|
return FALSE;
|
|
|
|
} else
|
2021-07-29 21:30:12 -04:00
|
|
|
swbuffer( bp) ;
|
2013-10-08 22:48:00 -04:00
|
|
|
|
|
|
|
/* make this window in VIEW mode, update all mode lines */
|
|
|
|
curwp->w_bufp->b_mode |= MDVIEW;
|
|
|
|
curwp->w_bufp->b_flag |= BFINVS;
|
2015-10-22 03:26:07 -04:00
|
|
|
upmode() ;
|
2013-10-08 22:48:00 -04:00
|
|
|
return TRUE;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2021-07-19 03:39:00 -04:00
|
|
|
/* describe the command for a certain key */
|
2021-07-23 20:58:23 -04:00
|
|
|
BINDABLE( deskey) {
|
2021-07-31 00:35:39 -04:00
|
|
|
const char cmdname[] = "describe-key" ;
|
2021-07-23 20:58:23 -04:00
|
|
|
char outseq[ NSTRING] ; /* output buffer for command sequence */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2021-07-23 20:58:23 -04:00
|
|
|
/* prompt the user to type a key to describe */
|
2021-07-31 00:35:39 -04:00
|
|
|
mlwrite( "%s: ", cmdname) ;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2021-07-23 20:58:23 -04:00
|
|
|
/* get the command sequence to describe
|
|
|
|
* change it to something we can print as well */
|
2021-07-31 00:35:39 -04:00
|
|
|
unsigned keycode = getckey( FALSE) ;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2021-07-23 20:58:23 -04:00
|
|
|
/* output the command sequence */
|
2021-07-31 00:35:39 -04:00
|
|
|
mlwrite( "%s %s: 0x%x, %s", cmdname, cmdstr( keycode, outseq), keycode,
|
|
|
|
getfname( keycode, "Not Bound")) ;
|
2021-07-23 20:58:23 -04:00
|
|
|
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
|
|
|
*/
|
2021-07-23 20:58:23 -04:00
|
|
|
BINDABLE( bindtokey) {
|
2021-07-29 21:30:12 -04:00
|
|
|
kbind_p ktp ; /* pointer into the command table */
|
2021-07-20 05:34:35 -04:00
|
|
|
char outseq[ 80] ; /* output buffer for keystroke sequence */
|
2013-10-08 22:48:00 -04:00
|
|
|
|
2021-07-20 05:34:35 -04:00
|
|
|
/* prompt the user to type in a key to bind */
|
2021-07-23 20:58:23 -04:00
|
|
|
mlwrite("bind-to-key: ");
|
2013-10-08 22:48:00 -04:00
|
|
|
|
2021-07-20 05:34:35 -04:00
|
|
|
/* get the function name to bind it to */
|
2021-07-29 21:30:12 -04:00
|
|
|
nbind_p nbp = getname() ;
|
2021-07-20 20:16:11 -04:00
|
|
|
if( nbp == NULL) /* abort */
|
|
|
|
return FALSE ;
|
|
|
|
|
|
|
|
fnp_t kfunc = nbp->n_func ;
|
2021-07-20 05:34:35 -04:00
|
|
|
if( kfunc == NULL) {
|
|
|
|
mlwrite( "(No such function)") ;
|
|
|
|
return FALSE ;
|
2013-10-08 22:48:00 -04:00
|
|
|
}
|
|
|
|
|
2021-07-23 20:58:23 -04:00
|
|
|
mlwrite( "bind-to-key %s: ", bind_name( nbp)) ;
|
2013-10-08 22:48:00 -04:00
|
|
|
|
2021-07-20 05:34:35 -04:00
|
|
|
/* get the command sequence to bind */
|
|
|
|
boolean prefix_f = (kfunc == metafn) || (kfunc == cex) ||
|
|
|
|
(kfunc == unarg) || (kfunc == ctrlg) ;
|
2021-07-24 04:34:54 -04:00
|
|
|
int c = getckey( prefix_f) ;
|
2013-10-08 22:48:00 -04:00
|
|
|
|
2021-07-20 05:34:35 -04:00
|
|
|
/* change it to something we can print as well */
|
|
|
|
/* and dump it out */
|
2021-07-31 00:35:39 -04:00
|
|
|
ostring( cmdstr( c, outseq)) ;
|
2013-10-08 22:48:00 -04:00
|
|
|
|
2021-07-24 04:34:54 -04:00
|
|
|
/* key sequence can't be an active prefix key */
|
|
|
|
if( c == metac || c == ctlxc || c == reptc || c == abortc) {
|
|
|
|
if( (c == metac && kfunc == metafn)
|
|
|
|
|| (c == ctlxc && kfunc == cex)
|
|
|
|
|| (c == reptc && kfunc == unarg)
|
|
|
|
|| (c == abortc && kfunc == ctrlg))
|
|
|
|
return TRUE ;
|
|
|
|
|
|
|
|
mlwrite( "(Can't bind to active prefix)") ;
|
|
|
|
return FALSE ;
|
|
|
|
}
|
|
|
|
|
2021-07-20 05:34:35 -04:00
|
|
|
/* if the function is a prefix key */
|
|
|
|
if( prefix_f) {
|
2021-07-24 04:34:54 -04:00
|
|
|
/* remove existing binding for the prefix */
|
2021-07-23 20:58:23 -04:00
|
|
|
for( ktp = keytab ; ktp->k_code != 0 ; ktp++)
|
2021-07-24 04:34:54 -04:00
|
|
|
if( ktp->k_nbp == nbp) {
|
|
|
|
delkeybinding( ktp->k_code) ;
|
|
|
|
break ;
|
|
|
|
}
|
2013-10-08 22:48:00 -04:00
|
|
|
|
2021-07-23 20:58:23 -04:00
|
|
|
/* set the appropriate global prefix variable */
|
|
|
|
if( kfunc == metafn)
|
|
|
|
metac = c ;
|
|
|
|
else if( kfunc == cex)
|
|
|
|
ctlxc = c ;
|
|
|
|
if( kfunc == unarg)
|
|
|
|
reptc = c ;
|
|
|
|
if( kfunc == ctrlg)
|
|
|
|
abortc = c ;
|
2013-10-08 22:48:00 -04:00
|
|
|
}
|
|
|
|
|
2021-07-24 04:34:54 -04:00
|
|
|
ktp = setkeybinding( c, nbp) ;
|
|
|
|
if( ktp->k_code == 0) {
|
2021-07-20 05:34:35 -04:00
|
|
|
mlwrite( "Binding table FULL!") ;
|
2021-07-24 04:34:54 -04:00
|
|
|
return FALSE ;
|
|
|
|
}
|
2021-07-20 05:34:35 -04:00
|
|
|
|
2021-07-24 04:34:54 -04:00
|
|
|
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
|
|
|
*/
|
2021-07-24 04:34:54 -04:00
|
|
|
BINDABLE( unbindkey) {
|
|
|
|
char outseq[ 80] ; /* output buffer for keystroke sequence */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2021-07-24 04:34:54 -04:00
|
|
|
/* prompt the user to type in a key to unbind */
|
|
|
|
mlwrite( "unbind-key: ") ;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2021-07-24 04:34:54 -04:00
|
|
|
/* get the command sequence to unbind */
|
|
|
|
int c = getckey( FALSE) ; /* get a command sequence */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2021-07-24 04:34:54 -04:00
|
|
|
/* change it to something we can print as well */
|
|
|
|
/* and dump it out */
|
2021-07-31 00:35:39 -04:00
|
|
|
ostring( cmdstr( c, outseq)) ;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2021-07-24 04:34:54 -04:00
|
|
|
/* prefix key sequence can't be undound, just redefined */
|
|
|
|
if( c == reptc || c == abortc) {
|
|
|
|
mlwrite( "(Can't unbind prefix)") ;
|
|
|
|
return FALSE ;
|
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2021-07-24 04:34:54 -04:00
|
|
|
/* if it isn't bound, bitch */
|
|
|
|
if( delkeybinding( c) == FALSE) {
|
|
|
|
mlwrite( "(Key not bound)") ;
|
|
|
|
return FALSE ;
|
2013-10-08 22:48:00 -04:00
|
|
|
}
|
2021-07-24 04:34:54 -04:00
|
|
|
|
|
|
|
return TRUE ;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2021-07-19 03:39:00 -04:00
|
|
|
/*
|
|
|
|
* does source include sub?
|
|
|
|
*
|
|
|
|
* char *source; string to search in
|
|
|
|
* char *sub; substring to look for
|
|
|
|
*/
|
|
|
|
static boolean strinc( const char *source, const char *sub) {
|
|
|
|
/* for each character in the source string */
|
|
|
|
for( ; *source ; source++) {
|
|
|
|
const char *nxtsp ; /* next ptr into source */
|
|
|
|
const char *tp ; /* ptr into substring */
|
|
|
|
|
|
|
|
nxtsp = source;
|
|
|
|
|
|
|
|
/* is the substring here? */
|
|
|
|
for( tp = sub ; *tp ; tp++)
|
|
|
|
if( *nxtsp++ != *tp)
|
|
|
|
break ;
|
|
|
|
|
|
|
|
/* yes, return a success */
|
|
|
|
if( *tp == 0)
|
|
|
|
return TRUE ;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE ;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
*/
|
2021-07-30 04:24:52 -04:00
|
|
|
BINDABLE( desbind) {
|
2015-09-30 20:03:14 -04:00
|
|
|
return buildlist( "") ;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2015-09-30 20:03:14 -04:00
|
|
|
/* Apropos (List functions that match a substring) */
|
2021-07-30 04:24:52 -04:00
|
|
|
BINDABLE( apro) {
|
2015-09-30 20:03:14 -04:00
|
|
|
char *mstring ; /* string to match cmd names to */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2021-07-30 04:24:52 -04:00
|
|
|
int status = newmlarg( &mstring, "apropos: ", 0) ;
|
2015-09-30 20:03:14 -04:00
|
|
|
if( status == TRUE) {
|
|
|
|
status = buildlist( mstring) ;
|
|
|
|
free( mstring) ;
|
|
|
|
} else if( status == FALSE)
|
|
|
|
status = buildlist( "") ; /* build list of all commands */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2015-09-30 20:03:14 -04:00
|
|
|
return status ;
|
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-09-30 20:03:14 -04:00
|
|
|
static int buildlist( char *mstring) {
|
2013-10-08 22:48:00 -04:00
|
|
|
struct window *wp; /* scanning pointer to windows */
|
2021-07-29 21:30:12 -04:00
|
|
|
kbind_p ktp; /* pointer into the command table */
|
|
|
|
nbind_p nptr;/* pointer into the name binding table */
|
2013-10-08 22:48:00 -04:00
|
|
|
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 */
|
2021-07-30 04:24:52 -04:00
|
|
|
if( wheadp->w_wndp == NULL /* One window */
|
|
|
|
&& splitwind( FALSE, 1) == FALSE) /* Split it */
|
2013-10-08 22:48:00 -04:00
|
|
|
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)");
|
|
|
|
|
2021-07-30 04:24:52 -04:00
|
|
|
/* disconnect the current buffer */
|
2013-10-08 22:48:00 -04:00
|
|
|
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 */
|
2021-07-19 03:39:00 -04:00
|
|
|
for( nptr = names ; nptr->n_func != NULL ; nptr++) {
|
2015-02-22 03:22:48 -05:00
|
|
|
int cpos ; /* current position to use in outseq */
|
2013-10-08 22:48:00 -04:00
|
|
|
|
|
|
|
/* if we are executing an apropos command..... */
|
2021-07-30 04:24:52 -04:00
|
|
|
/* and current string doesn't include the search string */
|
2021-07-19 23:24:32 -04:00
|
|
|
if( *mstring && strinc( bind_name( nptr), mstring) == FALSE)
|
2015-02-22 03:22:48 -05:00
|
|
|
continue ;
|
2021-07-30 04:24:52 -04:00
|
|
|
|
2015-02-22 03:22:48 -05:00
|
|
|
/* add in the command name */
|
2021-07-19 23:24:32 -04:00
|
|
|
mystrscpy( outseq, bind_name( nptr), sizeof outseq) ;
|
2015-02-22 03:22:48 -05:00
|
|
|
cpos = strlen(outseq);
|
|
|
|
|
2013-10-08 22:48:00 -04:00
|
|
|
/* search down any keys bound to this */
|
2021-07-23 20:58:23 -04:00
|
|
|
for( ktp = keytab ; ktp->k_code != 0 ; ktp++) {
|
|
|
|
if( ktp->k_nbp == nptr) {
|
2013-10-08 22:48:00 -04:00
|
|
|
/* 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 */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-22 03:26:07 -04:00
|
|
|
bp->b_mode |= MDVIEW; /* put this buffer view mode */
|
|
|
|
bp->b_flag &= ~BFCHG; /* don't flag this as a change */
|
2013-10-08 22:48:00 -04:00
|
|
|
wp->w_dotp = lforw(bp->b_linep); /* back to the beginning */
|
|
|
|
wp->w_doto = 0;
|
2015-10-22 03:26:07 -04:00
|
|
|
upmode() ; /* and update ALL mode lines */
|
2013-10-08 22:48:00 -04:00
|
|
|
mlwrite(""); /* clear the mode line */
|
|
|
|
return TRUE;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
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) {
|
2015-07-16 22:01:17 -04:00
|
|
|
unsigned int c ; /* character fetched */
|
2013-10-08 22:48:00 -04:00
|
|
|
|
|
|
|
/* check to see if we are executing a command line */
|
2015-07-16 22:01:17 -04:00
|
|
|
if( clexec) {
|
2015-09-27 09:11:51 -04:00
|
|
|
char *tok ; /* command incoming */
|
|
|
|
|
|
|
|
tok = getnewtokval() ; /* get the next token */
|
|
|
|
if( tok == NULL)
|
2015-07-16 22:01:17 -04:00
|
|
|
c = 0 ; /* return dummy key on failure */
|
2015-09-27 09:11:51 -04:00
|
|
|
else {
|
2015-07-16 22:01:17 -04:00
|
|
|
c = stock( tok) ;
|
2015-09-27 09:11:51 -04:00
|
|
|
free( tok) ;
|
|
|
|
}
|
2015-07-16 22:01:17 -04:00
|
|
|
} else { /* 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) {
|
2017-05-05 20:51:02 -04:00
|
|
|
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 */
|
2017-05-05 20:51:02 -04:00
|
|
|
if( fname == NULL) /* if it isn't around, don't sweat it */
|
|
|
|
return TRUE ;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2017-05-05 20:51:02 -04: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
|
|
|
*/
|
2021-07-31 00:35:39 -04:00
|
|
|
static char *cmdstr( unsigned c, char *seq) {
|
|
|
|
char *ptr = seq ; /* pointer into current position in sequence */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2021-07-31 00:35:39 -04:00
|
|
|
/* apply meta sequence if needed */
|
|
|
|
if( c & META) {
|
2013-10-08 22:48:00 -04:00
|
|
|
*ptr++ = 'M';
|
|
|
|
*ptr++ = '-';
|
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2021-07-31 00:35:39 -04:00
|
|
|
/* apply ^X sequence if needed */
|
|
|
|
if( c & CTLX) {
|
2021-07-30 04:24:52 -04:00
|
|
|
if( ctlxc & CTRL)
|
2021-07-24 04:34:54 -04:00
|
|
|
*ptr++ = '^' ;
|
|
|
|
|
2021-07-31 00:35:39 -04:00
|
|
|
*ptr++ = ctlxc & ~PRFXMASK ;
|
2013-10-08 22:48:00 -04:00
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2021-07-31 00:35:39 -04:00
|
|
|
/* apply SPEC sequence if needed */
|
|
|
|
if( c & SPEC) {
|
|
|
|
*ptr++ = 'F' ;
|
|
|
|
*ptr++ = 'N' ;
|
2013-10-08 22:48:00 -04:00
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2021-07-31 00:35:39 -04:00
|
|
|
/* apply control sequence if needed */
|
|
|
|
if( c & CTRL)
|
|
|
|
*ptr++ = '^' ;
|
2005-09-30 18:26:09 -04:00
|
|
|
|
2021-07-31 00:35:39 -04:00
|
|
|
/* and output the final sequence */
|
|
|
|
ptr += unicode_to_utf8( c & ~PRFXMASK, ptr) ;
|
|
|
|
*ptr = 0 ; /* terminate the string */
|
|
|
|
return seq ;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2021-07-19 03:39:00 -04:00
|
|
|
static const char *getfname( unsigned keycode, char *failmsg) {
|
|
|
|
/* takes a key code and gets the name of the function bound to it */
|
2021-07-30 04:24:52 -04:00
|
|
|
kbind_p kbp = getkeybinding( keycode) ;
|
2021-07-23 20:58:23 -04:00
|
|
|
if( kbp->k_code == 0)
|
2021-07-19 03:39:00 -04:00
|
|
|
return failmsg ;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2021-07-20 05:34:35 -04:00
|
|
|
const char *found = bind_name( kbp->k_nbp) ;
|
|
|
|
assert( *found) ;
|
2021-07-23 20:58:23 -04:00
|
|
|
return found ;
|
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) {
|
2021-07-30 04:24:52 -04:00
|
|
|
c |= CTRL;
|
2013-10-08 22:48:00 -04:00
|
|
|
++keyname;
|
|
|
|
}
|
|
|
|
if (*keyname < 32) {
|
2021-07-30 04:24:52 -04:00
|
|
|
c |= CTRL;
|
2013-10-08 22:48:00 -04:00
|
|
|
*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....
|
|
|
|
*
|
2021-07-19 03:39:00 -04:00
|
|
|
* char *skey; name of key to get binding for
|
2005-09-30 20:52:20 -04:00
|
|
|
*/
|
2021-07-19 03:39:00 -04:00
|
|
|
const char *transbind( char *skey) {
|
|
|
|
return getfname( stock( skey), "ERROR") ;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|