2013-05-20 01:16:08 -04:00
|
|
|
/* bind.c -- implements bind.h */
|
|
|
|
#include "bind.h"
|
|
|
|
|
2021-08-05 00:09:21 -04:00
|
|
|
/* This file is for functions having to do with key bindings,
|
2013-10-08 22:48:00 -04:00
|
|
|
* 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>
|
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-06-04 23:48:40 -04:00
|
|
|
#include "bindable.h"
|
2013-05-28 01:25:14 -04:00
|
|
|
#include "buffer.h"
|
2021-08-09 03:24:33 -04:00
|
|
|
#include "display.h" /* upmode(), ostring() */
|
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"
|
2021-08-09 03:24:33 -04:00
|
|
|
#include "mlout.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-08-05 00:09:21 -04:00
|
|
|
static const char *getfname( unsigned keycode, const char *failmsg) ;
|
|
|
|
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2021-08-09 03:24:33 -04:00
|
|
|
/* give me some help!!!! bring up a fake buffer and read the help file into
|
|
|
|
it with view mode
|
|
|
|
*/
|
2021-07-29 21:30:12 -04:00
|
|
|
BINDABLE( help) {
|
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);
|
2021-08-09 03:24:33 -04:00
|
|
|
if( bp == curbp)
|
|
|
|
return TRUE ;
|
2013-10-08 22:48:00 -04:00
|
|
|
|
2021-08-05 00:09:21 -04:00
|
|
|
if( bp == NULL) {
|
|
|
|
fname = flook( hlpfname, FALSE) ;
|
|
|
|
if( fname == NULL)
|
2021-08-09 03:24:33 -04:00
|
|
|
return mloutfail( "(Help file is not online)") ;
|
2013-10-08 22:48:00 -04:00
|
|
|
}
|
|
|
|
|
2021-07-29 21:30:12 -04:00
|
|
|
/* split the current window to make room for the help stuff */
|
2021-08-09 03:24:33 -04:00
|
|
|
if( wheadp->w_wndp == NULL /* One window */
|
|
|
|
&& splitwind( FALSE, 1) == FALSE) /* Split it */
|
2021-07-29 21:30:12 -04:00
|
|
|
return FALSE ;
|
2013-10-08 22:48:00 -04:00
|
|
|
|
2021-08-09 03:24:33 -04:00
|
|
|
if( bp == NULL) {
|
|
|
|
/* and read the stuff in */
|
|
|
|
if( getfile( fname, FALSE) == FALSE)
|
|
|
|
return FALSE ;
|
2013-10-08 22:48:00 -04:00
|
|
|
} else
|
2021-08-09 03:24:33 -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() ;
|
2021-08-09 03:24:33 -04:00
|
|
|
return TRUE ;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2021-08-09 03:24:33 -04:00
|
|
|
|
2021-08-05 00:09:21 -04:00
|
|
|
static boolean invalidkey( void) {
|
2021-08-09 03:24:33 -04:00
|
|
|
return mloutfail( "(Invalid key sequence)") ;
|
2021-08-05 00:09:21 -04:00
|
|
|
}
|
|
|
|
|
2021-08-09 03:24:33 -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-08-09 03:24:33 -04:00
|
|
|
const char cmdname[] = "describe-key" ;
|
|
|
|
char outseq[ 8] ; /* output buffer for keystroke 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-08-09 03:24:33 -04:00
|
|
|
mloutfmt( "%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) ;
|
2021-08-09 03:24:33 -04:00
|
|
|
if( keycode == (unsigned) ~0)
|
|
|
|
return invalidkey() ;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2021-07-23 20:58:23 -04:00
|
|
|
/* output the command sequence */
|
2021-08-09 03:24:33 -04:00
|
|
|
mloutfmt( "%s %s: 0x%x, %s", cmdname, cmdstr( keycode, outseq), keycode,
|
2021-07-31 00:35:39 -04:00
|
|
|
getfname( keycode, "Not Bound")) ;
|
2021-07-23 20:58:23 -04:00
|
|
|
return TRUE ;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2021-08-09 03:24:33 -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-08-09 03:24:33 -04:00
|
|
|
kbind_p ktp ; /* pointer into the command table */
|
|
|
|
char outseq[ 8] ; /* 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-08-09 03:24:33 -04:00
|
|
|
mloutstr( "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-08-09 03:24:33 -04:00
|
|
|
nbind_p nbp = getname() ;
|
|
|
|
if( nbp == NULL) /* abort */
|
|
|
|
return FALSE ;
|
2021-07-20 20:16:11 -04:00
|
|
|
|
|
|
|
fnp_t kfunc = nbp->n_func ;
|
2021-08-05 00:09:21 -04:00
|
|
|
if( kfunc == NULL)
|
2021-08-09 03:24:33 -04:00
|
|
|
return mloutfail( "(No such function)") ;
|
2013-10-08 22:48:00 -04:00
|
|
|
|
2021-08-09 03:24:33 -04:00
|
|
|
mloutfmt( "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 */
|
2021-08-11 05:02:19 -04:00
|
|
|
boolean prefix_f = (kfunc == (fnp_t) metafn) || (kfunc == (fnp_t) cex) ||
|
|
|
|
(kfunc == (fnp_t) unarg) || (kfunc == (fnp_t) ctrlg) ;
|
2021-07-24 04:34:54 -04:00
|
|
|
int c = getckey( prefix_f) ;
|
2021-08-09 03:24:33 -04:00
|
|
|
if( c == ~0)
|
|
|
|
return invalidkey() ;
|
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 */
|
2021-08-09 03:24:33 -04:00
|
|
|
if( c == metac || c == ctlxc || c == reptc || c == abortc) {
|
2021-08-11 05:02:19 -04:00
|
|
|
if( (c == metac && kfunc == (fnp_t) metafn)
|
|
|
|
|| (c == ctlxc && kfunc == (fnp_t) cex)
|
|
|
|
|| (c == reptc && kfunc == (fnp_t) unarg)
|
|
|
|
|| (c == abortc && kfunc == (fnp_t) ctrlg))
|
2021-08-09 03:24:33 -04:00
|
|
|
return TRUE ; /* be silent if keep current */
|
|
|
|
|
|
|
|
return mloutfail( "(Can't bind to active prefix)") ;
|
|
|
|
}
|
2021-07-24 04:34:54 -04:00
|
|
|
|
2021-07-20 05:34:35 -04:00
|
|
|
/* if the function is a prefix key */
|
2021-08-09 03:24:33 -04:00
|
|
|
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) {
|
2021-08-09 03:24:33 -04:00
|
|
|
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 */
|
2021-08-11 05:02:19 -04:00
|
|
|
if( kfunc == (fnp_t) metafn)
|
2021-07-23 20:58:23 -04:00
|
|
|
metac = c ;
|
2021-08-11 05:02:19 -04:00
|
|
|
else if( kfunc == (fnp_t) cex)
|
2021-07-23 20:58:23 -04:00
|
|
|
ctlxc = c ;
|
2021-08-11 05:02:19 -04:00
|
|
|
if( kfunc == (fnp_t) unarg)
|
2021-07-23 20:58:23 -04:00
|
|
|
reptc = c ;
|
2021-08-11 05:02:19 -04:00
|
|
|
if( kfunc == (fnp_t) ctrlg)
|
2021-07-23 20:58:23 -04:00
|
|
|
abortc = c ;
|
2013-10-08 22:48:00 -04:00
|
|
|
}
|
|
|
|
|
2021-08-09 03:24:33 -04:00
|
|
|
ktp = setkeybinding( c, nbp) ;
|
|
|
|
if( ktp->k_code == 0)
|
|
|
|
return mloutfail( "Binding table FULL!") ;
|
2021-07-20 05:34:35 -04:00
|
|
|
|
2021-08-09 03:24:33 -04:00
|
|
|
return TRUE ;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2021-08-09 03:24:33 -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) {
|
2021-08-09 03:24:33 -04:00
|
|
|
char outseq[ 8] ; /* 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 */
|
2021-08-09 03:24:33 -04:00
|
|
|
mloutstr( "unbind-key: ") ;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2021-07-24 04:34:54 -04:00
|
|
|
/* get the command sequence to unbind */
|
2021-08-09 03:24:33 -04:00
|
|
|
int c = getckey( FALSE) ; /* get a command sequence */
|
|
|
|
if( c == ~0)
|
|
|
|
return invalidkey() ;
|
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 */
|
2021-08-09 03:24:33 -04:00
|
|
|
if( c == reptc || c == abortc)
|
|
|
|
return mloutfail( "(Can't unbind prefix)") ;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2021-07-24 04:34:54 -04:00
|
|
|
/* if it isn't bound, bitch */
|
2021-08-09 03:24:33 -04:00
|
|
|
if( delkeybinding( c) == FALSE)
|
|
|
|
return mloutfail( "(Key not bound)") ;
|
|
|
|
|
|
|
|
return TRUE ;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2021-08-09 03:24:33 -04:00
|
|
|
|
|
|
|
/* does source include sub?
|
2021-07-19 03:39:00 -04:00
|
|
|
*
|
|
|
|
* 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++) {
|
2021-08-09 03:24:33 -04:00
|
|
|
const char *nxtsp ; /* next ptr into source */
|
|
|
|
const char *tp ; /* ptr into substring */
|
2021-07-19 03:39:00 -04:00
|
|
|
|
|
|
|
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 ;
|
|
|
|
}
|
|
|
|
|
2021-08-09 03:24:33 -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
|
|
|
|
*/
|
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
|
|
|
}
|
|
|
|
|
2021-08-09 03:24:33 -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) {
|
2021-08-09 03:24:33 -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) ;
|
2021-08-09 03:24:33 -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
|
|
|
}
|
|
|
|
|
2021-08-09 03:24:33 -04:00
|
|
|
|
|
|
|
/* build a binding list (limited or full)
|
2005-09-30 20:52:20 -04:00
|
|
|
*
|
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) {
|
2021-08-09 03:24:33 -04:00
|
|
|
#define PADDING 28
|
|
|
|
char outseq[ PADDING + 8] ; /* output buffer for command + keystroke */
|
|
|
|
|
|
|
|
/* split the current window to make room for the binding list */
|
|
|
|
if( wheadp->w_wndp == NULL /* One window */
|
|
|
|
&& splitwind( FALSE, 1) == FALSE) /* Split it */
|
|
|
|
return FALSE ;
|
|
|
|
|
|
|
|
/* and get a buffer for it */
|
|
|
|
buffer_p bp = bfind( "*Binding list*", TRUE, 0) ;
|
2021-08-05 00:09:21 -04:00
|
|
|
if( bp == NULL || bclear( bp) == FALSE)
|
2021-08-09 03:24:33 -04:00
|
|
|
return mloutfail( "Can't display binding list") ;
|
2013-10-08 22:48:00 -04:00
|
|
|
|
2021-08-09 03:24:33 -04:00
|
|
|
/* let us know this is in progress */
|
|
|
|
mloutstr( "(Building binding list)") ;
|
2013-10-08 22:48:00 -04:00
|
|
|
|
2021-08-09 03:24:33 -04:00
|
|
|
/* disconnect 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 ;
|
2013-10-08 22:48:00 -04:00
|
|
|
}
|
|
|
|
|
2021-08-09 03:24:33 -04:00
|
|
|
/* 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 */
|
|
|
|
window_p 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 */
|
|
|
|
for( nbind_p nptr = names ; nptr->n_func != NULL ; nptr++) {
|
|
|
|
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)
|
2021-08-09 03:24:33 -04: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) ;
|
2021-08-09 03:24:33 -04:00
|
|
|
cpos = strlen( outseq) ;
|
2015-02-22 03:22:48 -05:00
|
|
|
|
2013-10-08 22:48:00 -04:00
|
|
|
/* search down any keys bound to this */
|
2021-08-09 03:24:33 -04:00
|
|
|
for( kbind_p ktp = keytab ; ktp->k_code != 0 ; ktp++) {
|
2021-07-23 20:58:23 -04:00
|
|
|
if( ktp->k_nbp == nptr) {
|
2021-08-09 03:24:33 -04:00
|
|
|
/* padd out some spaces */
|
|
|
|
while( cpos < PADDING)
|
|
|
|
outseq[ cpos++] = ' ' ;
|
2013-10-08 22:48:00 -04:00
|
|
|
|
2021-08-09 03:24:33 -04:00
|
|
|
/* add in the command sequence */
|
|
|
|
cmdstr( ktp->k_code, &outseq[ cpos]) ;
|
|
|
|
strcat( outseq, "\n") ;
|
2013-10-08 22:48:00 -04:00
|
|
|
|
2021-08-09 03:24:33 -04:00
|
|
|
/* and add it as a line into the buffer */
|
|
|
|
if( linstr( outseq) != TRUE)
|
|
|
|
return FALSE ;
|
2013-10-08 22:48:00 -04:00
|
|
|
|
2021-08-09 03:24:33 -04:00
|
|
|
cpos = 0 ; /* and clear the line */
|
2013-10-08 22:48:00 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if no key was bound, we need to dump it anyway */
|
2021-08-09 03:24:33 -04:00
|
|
|
if( cpos > 0) {
|
|
|
|
outseq[ cpos++] = '\n';
|
|
|
|
outseq[ cpos] = 0;
|
|
|
|
if( linstr( outseq) != TRUE)
|
|
|
|
return FALSE ;
|
2013-10-08 22:48:00 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-09 03:24:33 -04:00
|
|
|
bp->b_mode |= MDVIEW ; /* put this buffer view mode */
|
|
|
|
bp->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 ;
|
|
|
|
upmode() ; /* and update ALL mode lines */
|
|
|
|
mloutstr( "") ; /* clear the mode line */
|
|
|
|
return TRUE ;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2021-08-09 03:24:33 -04:00
|
|
|
|
|
|
|
/* get a command key sequence from the keyboard
|
2005-09-30 20:52:20 -04:00
|
|
|
*
|
2013-10-08 22:48:00 -04:00
|
|
|
* int mflag; going for a meta sequence?
|
2021-08-05 00:09:21 -04:00
|
|
|
* returns ~0 on failure
|
2005-09-30 20:52:20 -04:00
|
|
|
*/
|
2015-02-15 22:39:16 -05:00
|
|
|
static unsigned int getckey( int mflag) {
|
2021-08-09 03:24:33 -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) {
|
2021-08-09 03:24:33 -04:00
|
|
|
char *tok = getnewtokval() ; /* get the next token */
|
|
|
|
if( tok == NULL)
|
|
|
|
c = ~0 ; /* return invalid key on failure */
|
|
|
|
else {
|
|
|
|
c = stock( tok) ;
|
|
|
|
free( tok) ;
|
|
|
|
}
|
|
|
|
} else { /* or the normal way */
|
|
|
|
if( mflag)
|
|
|
|
c = get1key() ;
|
|
|
|
else
|
|
|
|
c = getcmd() ;
|
|
|
|
}
|
|
|
|
|
|
|
|
return c ;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2021-08-09 03:24:33 -04:00
|
|
|
|
|
|
|
/* execute the startup file
|
2005-09-30 20:52:20 -04:00
|
|
|
*
|
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) {
|
2021-08-09 03:24:33 -04:00
|
|
|
if( !fname || *fname == 0) /* use default if empty parameter */
|
|
|
|
fname = rcfname ;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2021-08-09 03:24:33 -04: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
|
|
|
|
2021-08-09 03:24:33 -04:00
|
|
|
return dofile( fname) ; /* otherwise, execute the sucker */
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2021-08-09 03:24:33 -04:00
|
|
|
|
|
|
|
/* change a key command to a string we can print out
|
2005-09-30 20:52:20 -04:00
|
|
|
*
|
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) {
|
2021-08-09 03:24:33 -04:00
|
|
|
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-08-11 05:02:19 -04:00
|
|
|
if( ctlxc & CTL_)
|
2021-08-09 03:24:33 -04:00
|
|
|
*ptr++ = '^' ;
|
2021-07-24 04:34:54 -04:00
|
|
|
|
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-08-05 00:09:21 -04:00
|
|
|
/* apply control sequence if needed */
|
2021-08-11 05:02:19 -04:00
|
|
|
if( c & CTL_)
|
2021-08-05 00:09:21 -04:00
|
|
|
*ptr++ = '^' ;
|
|
|
|
|
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
|
|
|
/* and output the final sequence */
|
2021-08-09 03:24:33 -04:00
|
|
|
ptr += unicode_to_utf8( c & ~PRFXMASK, ptr) ;
|
|
|
|
*ptr = 0 ; /* terminate the string */
|
|
|
|
return seq ;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2021-08-09 03:24:33 -04:00
|
|
|
|
2021-08-05 00:09:21 -04:00
|
|
|
static const char *getfname( unsigned keycode, const char *failmsg) {
|
2021-07-19 03:39:00 -04:00
|
|
|
/* takes a key code and gets the name of the function bound to it */
|
2021-08-09 03:24:33 -04:00
|
|
|
kbind_p kbp = getkeybinding( keycode) ;
|
|
|
|
if( kbp->k_code == 0)
|
|
|
|
return failmsg ;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2021-08-09 03:24:33 -04:00
|
|
|
const char *found = bind_name( kbp->k_nbp) ;
|
|
|
|
assert( *found) ;
|
|
|
|
return found ;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2021-08-09 03:24:33 -04:00
|
|
|
|
2021-08-05 00:09:21 -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
|
2021-08-07 01:46:14 -04:00
|
|
|
* fmt: [M-|^X][^][FN]X
|
2021-08-05 00:09:21 -04:00
|
|
|
* returns ~0 on invalid sequence
|
2005-09-30 20:52:20 -04:00
|
|
|
*/
|
2015-02-15 22:39:16 -05:00
|
|
|
static unsigned int stock( char *keyname) {
|
2021-08-05 00:09:21 -04:00
|
|
|
/* parse it up */
|
|
|
|
unsigned c = 0 ;
|
2013-10-08 22:48:00 -04:00
|
|
|
|
2021-08-07 01:46:14 -04:00
|
|
|
/* first, the prefix META or ^X */
|
2021-08-05 00:09:21 -04:00
|
|
|
if( *keyname == 'M' && keyname[ 1] == '-') {
|
|
|
|
c = META ;
|
|
|
|
keyname += 2 ;
|
2021-08-07 01:46:14 -04:00
|
|
|
} else if( *keyname == '^' && keyname[ 1] == 'X') {
|
|
|
|
c = CTLX ;
|
2021-08-05 00:09:21 -04:00
|
|
|
keyname += 2 ;
|
2013-10-08 22:48:00 -04:00
|
|
|
}
|
|
|
|
|
2021-08-05 00:09:21 -04:00
|
|
|
/* a control char? */
|
|
|
|
if( *keyname == '^' && keyname[ 1] != 0) {
|
2021-08-11 05:02:19 -04:00
|
|
|
c |= CTL_ ;
|
2021-08-05 00:09:21 -04:00
|
|
|
++keyname ;
|
2013-10-08 22:48:00 -04:00
|
|
|
}
|
|
|
|
|
2021-08-05 00:09:21 -04:00
|
|
|
/* next the function prefix */
|
|
|
|
if( *keyname == 'F' && keyname[ 1] == 'N') {
|
|
|
|
c |= SPEC ;
|
|
|
|
keyname += 2 ;
|
2013-10-08 22:48:00 -04:00
|
|
|
}
|
|
|
|
|
2021-08-05 00:09:21 -04:00
|
|
|
/* only one character left to parse */
|
2021-08-09 03:24:33 -04:00
|
|
|
if( !*keyname || keyname[1])
|
|
|
|
return ~0 ;
|
2021-08-05 00:09:21 -04:00
|
|
|
|
|
|
|
/* only way to redefine ^X is by quoting binary value */
|
|
|
|
if( *keyname < 32 || *keyname == 0x7F) {
|
2021-08-11 05:02:19 -04:00
|
|
|
c |= CTL_ ;
|
2021-08-05 00:09:21 -04:00
|
|
|
*keyname ^= 0x40 ;
|
2021-08-09 03:24:33 -04:00
|
|
|
} else if( c && !(c & SPEC)
|
|
|
|
&& *keyname >= 'a' && *keyname <= 'z')
|
|
|
|
/* make sure we are not lower case (not with function keys) */
|
2021-08-05 00:09:21 -04:00
|
|
|
*keyname -= 32 ;
|
2013-10-08 22:48:00 -04:00
|
|
|
|
2021-08-05 00:09:21 -04:00
|
|
|
/* the final sequence... */
|
2015-02-22 03:22:48 -05:00
|
|
|
c |= *keyname & 0xFFU ;
|
2021-08-05 00:09:21 -04:00
|
|
|
return c ;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2021-08-09 03:24:33 -04:00
|
|
|
|
|
|
|
/* string key name to binding name....
|
2005-09-30 20:52:20 -04:00
|
|
|
*
|
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) {
|
2021-08-09 03:24:33 -04:00
|
|
|
static const char failmsg[] = "ERROR" ;
|
2021-08-05 00:09:21 -04:00
|
|
|
|
2021-08-09 03:24:33 -04:00
|
|
|
unsigned c = stock( skey) ;
|
|
|
|
if( c == (unsigned) ~0)
|
|
|
|
return failmsg ;
|
|
|
|
else
|
|
|
|
return getfname( c, failmsg) ;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
2021-08-05 00:09:21 -04:00
|
|
|
|
|
|
|
/* end of bind.c */
|