mirror of
https://github.com/rfivet/uemacs.git
synced 2024-12-18 23:36:23 -05:00
Revise types for names and keys bindings.
This commit is contained in:
parent
735aefc166
commit
22bbd0417c
37
bind.c
37
bind.c
@ -39,15 +39,15 @@ static unsigned int stock( char *keyname) ;
|
|||||||
static const char *getfname( unsigned keycode, char *failmsg) ;
|
static const char *getfname( unsigned keycode, char *failmsg) ;
|
||||||
|
|
||||||
|
|
||||||
int help(int f, int n)
|
BINDABLE( help) {
|
||||||
{ /* give me some help!!!!
|
/* give me some help!!!!
|
||||||
bring up a fake buffer and read the help file
|
bring up a fake buffer and read the help file into it with view mode */
|
||||||
into it with view mode */
|
|
||||||
struct buffer *bp; /* buffer pointer to help */
|
|
||||||
char *fname = NULL; /* ptr to file returned by flook() */
|
char *fname = NULL; /* ptr to file returned by flook() */
|
||||||
|
|
||||||
/* first check if we are already here */
|
/* first check if we are already here */
|
||||||
bp = bfind( hlpfname, FALSE, BFINVS);
|
buffer_p bp = bfind( hlpfname, FALSE, BFINVS);
|
||||||
|
if( bp == curbp)
|
||||||
|
return TRUE ;
|
||||||
|
|
||||||
if (bp == NULL) {
|
if (bp == NULL) {
|
||||||
fname = flook( hlpfname, FALSE);
|
fname = flook( hlpfname, FALSE);
|
||||||
@ -57,16 +57,17 @@ int help(int f, int n)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* split the current window to make room for the help stuff */
|
/* split the current window to make room for the help stuff */
|
||||||
if (splitwind(FALSE, 1) == FALSE)
|
if( wheadp->w_wndp == NULL /* One window */
|
||||||
return FALSE;
|
&& splitwind( FALSE, 1) == FALSE) /* Split it */
|
||||||
|
return FALSE ;
|
||||||
|
|
||||||
if (bp == NULL) {
|
if (bp == NULL) {
|
||||||
/* and read the stuff in */
|
/* and read the stuff in */
|
||||||
if (getfile(fname, FALSE) == FALSE)
|
if (getfile(fname, FALSE) == FALSE)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
} else
|
} else
|
||||||
swbuffer(bp);
|
swbuffer( bp) ;
|
||||||
|
|
||||||
/* make this window in VIEW mode, update all mode lines */
|
/* make this window in VIEW mode, update all mode lines */
|
||||||
curwp->w_bufp->b_mode |= MDVIEW;
|
curwp->w_bufp->b_mode |= MDVIEW;
|
||||||
@ -100,14 +101,14 @@ BINDABLE( deskey) {
|
|||||||
* int f, n; command arguments [IGNORED]
|
* int f, n; command arguments [IGNORED]
|
||||||
*/
|
*/
|
||||||
BINDABLE( bindtokey) {
|
BINDABLE( bindtokey) {
|
||||||
key_tab *ktp ; /* pointer into the command table */
|
kbind_p ktp ; /* pointer into the command table */
|
||||||
char outseq[ 80] ; /* output buffer for keystroke sequence */
|
char outseq[ 80] ; /* output buffer for keystroke sequence */
|
||||||
|
|
||||||
/* prompt the user to type in a key to bind */
|
/* prompt the user to type in a key to bind */
|
||||||
mlwrite("bind-to-key: ");
|
mlwrite("bind-to-key: ");
|
||||||
|
|
||||||
/* get the function name to bind it to */
|
/* get the function name to bind it to */
|
||||||
const name_bind *nbp = getname() ;
|
nbind_p nbp = getname() ;
|
||||||
if( nbp == NULL) /* abort */
|
if( nbp == NULL) /* abort */
|
||||||
return FALSE ;
|
return FALSE ;
|
||||||
|
|
||||||
@ -268,8 +269,8 @@ int apro( int f, int n) {
|
|||||||
static int buildlist( char *mstring) {
|
static int buildlist( char *mstring) {
|
||||||
#endif
|
#endif
|
||||||
struct window *wp; /* scanning pointer to windows */
|
struct window *wp; /* scanning pointer to windows */
|
||||||
key_tab *ktp; /* pointer into the command table */
|
kbind_p ktp; /* pointer into the command table */
|
||||||
const name_bind *nptr;/* pointer into the name binding table */
|
nbind_p nptr;/* pointer into the name binding table */
|
||||||
struct buffer *bp; /* buffer to put binding list into */
|
struct buffer *bp; /* buffer to put binding list into */
|
||||||
char outseq[80]; /* output buffer for keystroke sequence */
|
char outseq[80]; /* output buffer for keystroke sequence */
|
||||||
|
|
||||||
@ -452,8 +453,8 @@ static void cmdstr( int c, char *seq) {
|
|||||||
*
|
*
|
||||||
* int c; key to find what is bound to it
|
* int c; key to find what is bound to it
|
||||||
*/
|
*/
|
||||||
key_tab *getkeybind( unsigned c) {
|
kbind_p getkeybind( unsigned c) {
|
||||||
key_tab *ktp ;
|
kbind_p ktp ;
|
||||||
|
|
||||||
for( ktp = keytab ; ktp->k_code != 0 ; ktp++)
|
for( ktp = keytab ; ktp->k_code != 0 ; ktp++)
|
||||||
if (ktp->k_code == c)
|
if (ktp->k_code == c)
|
||||||
@ -464,7 +465,7 @@ key_tab *getkeybind( unsigned c) {
|
|||||||
|
|
||||||
static const char *getfname( unsigned keycode, char *failmsg) {
|
static const char *getfname( unsigned keycode, char *failmsg) {
|
||||||
/* takes a key code and gets the name of the function bound to it */
|
/* takes a key code and gets the name of the function bound to it */
|
||||||
key_tab *kbp = getkeybind( keycode) ;
|
kbind_p kbp = getkeybind( keycode) ;
|
||||||
if( kbp->k_code == 0)
|
if( kbp->k_code == 0)
|
||||||
return failmsg ;
|
return failmsg ;
|
||||||
|
|
||||||
|
2
bind.h
2
bind.h
@ -19,7 +19,7 @@ int desbind( int f, int n) ;
|
|||||||
int startup( const char *fname) ;
|
int startup( const char *fname) ;
|
||||||
|
|
||||||
/* find a key to function association in the key to function mapping table */
|
/* find a key to function association in the key to function mapping table */
|
||||||
key_tab *getkeybind( unsigned keycode) ; /* by key code */
|
kbind_p getkeybind( unsigned keycode) ; /* by key code */
|
||||||
const char *transbind( char *skey) ; /* by string representation of key */
|
const char *transbind( char *skey) ; /* by string representation of key */
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
4
exec.c
4
exec.c
@ -90,7 +90,7 @@ int namedcmd( int f, int n) {
|
|||||||
mlwrite("execute-named-cmd: ");
|
mlwrite("execute-named-cmd: ");
|
||||||
|
|
||||||
/* and now get the function name to execute */
|
/* and now get the function name to execute */
|
||||||
const name_bind *nbp = getname() ;
|
nbind_p nbp = getname() ;
|
||||||
if( nbp == NULL) /* abort */
|
if( nbp == NULL) /* abort */
|
||||||
return FALSE ;
|
return FALSE ;
|
||||||
|
|
||||||
@ -190,7 +190,7 @@ static int docmd( char *cline) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* and match the token to see if it exists */
|
/* and match the token to see if it exists */
|
||||||
const name_bind *nbp = fncmatch( tkn) ;
|
nbind_p nbp = fncmatch( tkn) ;
|
||||||
fnp_t fnc = nbp->n_func ;
|
fnp_t fnc = nbp->n_func ;
|
||||||
if( fnc == NULL) {
|
if( fnc == NULL) {
|
||||||
mlwrite("(No such Function)");
|
mlwrite("(No such Function)");
|
||||||
|
@ -213,7 +213,7 @@ int execute( int c, int f, int n) {
|
|||||||
int status ;
|
int status ;
|
||||||
|
|
||||||
/* if the keystroke is a bound function...do it */
|
/* if the keystroke is a bound function...do it */
|
||||||
key_tab *ktp = getkeybind( c) ;
|
kbind_p ktp = getkeybind( c) ;
|
||||||
if( ktp->k_code != 0) {
|
if( ktp->k_code != 0) {
|
||||||
thisflag = 0 ;
|
thisflag = 0 ;
|
||||||
assert( ktp->k_nbp != NULL) ;
|
assert( ktp->k_nbp != NULL) ;
|
||||||
@ -338,7 +338,7 @@ void kbd_loop( void) {
|
|||||||
newc = getcmd() ;
|
newc = getcmd() ;
|
||||||
update( FALSE) ;
|
update( FALSE) ;
|
||||||
do {
|
do {
|
||||||
key_tab *ktp ;
|
kbind_p ktp ;
|
||||||
fnp_t execfunc ;
|
fnp_t execfunc ;
|
||||||
|
|
||||||
if( c == newc
|
if( c == newc
|
||||||
|
8
input.c
8
input.c
@ -162,11 +162,11 @@ int ectoc( int c) {
|
|||||||
* that pressing a <SPACE> will attempt to complete an unfinished command
|
* that pressing a <SPACE> will attempt to complete an unfinished command
|
||||||
* name if it is unique.
|
* name if it is unique.
|
||||||
*/
|
*/
|
||||||
const name_bind *getname( void) {
|
nbind_p getname( void) {
|
||||||
int cpos; /* current column on screen output */
|
int cpos; /* current column on screen output */
|
||||||
const name_bind *ffp; /* first ptr to entry in name binding table */
|
nbind_p ffp; /* first ptr to entry in name binding table */
|
||||||
const name_bind *cffp; /* current ptr to entry in name binding table */
|
nbind_p cffp; /* current ptr to entry in name binding table */
|
||||||
const name_bind *lffp; /* last ptr to entry in name binding table */
|
nbind_p lffp; /* last ptr to entry in name binding table */
|
||||||
char buf[NSTRING]; /* buffer to hold tentative command name */
|
char buf[NSTRING]; /* buffer to hold tentative command name */
|
||||||
|
|
||||||
/* starting at the beginning of the string buffer */
|
/* starting at the beginning of the string buffer */
|
||||||
|
2
input.h
2
input.h
@ -29,7 +29,7 @@ int newmlargt( char **outbufref, const char *prompt, int size) ;
|
|||||||
int ectoc( int c) ;
|
int ectoc( int c) ;
|
||||||
|
|
||||||
/* Get a command name from the command line or interactively */
|
/* Get a command name from the command line or interactively */
|
||||||
const name_bind *getname( void) ;
|
nbind_p getname( void) ;
|
||||||
|
|
||||||
int tgetc( void) ;
|
int tgetc( void) ;
|
||||||
int get1key( void) ;
|
int get1key( void) ;
|
||||||
|
23
main.c
23
main.c
@ -164,15 +164,10 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialize the editor. */
|
vtinit() ; /* Display */
|
||||||
if( !init_bindings()) { /* initialize mapping of function to name and key */
|
|
||||||
return( EXIT_FAILURE) ;
|
|
||||||
}
|
|
||||||
|
|
||||||
vtinit(); /* Display */
|
|
||||||
mloutfmt = mlwrite ;
|
mloutfmt = mlwrite ;
|
||||||
edinit("main"); /* Buffers, windows */
|
edinit( "main") ; /* Bindings, buffers, windows */
|
||||||
varinit(); /* user variables */
|
varinit() ; /* user variables */
|
||||||
|
|
||||||
viewflag = FALSE; /* view mode defaults off in command line */
|
viewflag = FALSE; /* view mode defaults off in command line */
|
||||||
gotoflag = FALSE; /* set to off to begin with */
|
gotoflag = FALSE; /* set to off to begin with */
|
||||||
@ -331,14 +326,14 @@ int main(int argc, char **argv)
|
|||||||
* as an argument, because the main routine may have been told to read in a
|
* as an argument, because the main routine may have been told to read in a
|
||||||
* file by default, and we want the buffer name to be right.
|
* file by default, and we want the buffer name to be right.
|
||||||
*/
|
*/
|
||||||
static void edinit(char *bname)
|
static void edinit( char *bname) {
|
||||||
{
|
buffer_p bp;
|
||||||
struct buffer *bp;
|
|
||||||
struct window *wp;
|
struct window *wp;
|
||||||
|
|
||||||
if( NULL == (bp = bfind( bname, TRUE, 0)) /* First buffer */
|
if( !init_bindings() /* initialize mapping of function to name and key */
|
||||||
|| NULL == (blistp = bfind( "*List*", TRUE, BFINVS)) /* Buffer list buffer */
|
|| NULL == (bp = bfind( bname, TRUE, 0)) /* First buffer */
|
||||||
|| NULL == (wp = (struct window *) malloc( sizeof( struct window)))) { /* First window */
|
|| NULL == (blistp = bfind( "*List*", TRUE, BFINVS)) /* Buffer list */
|
||||||
|
|| NULL == (wp = malloc( sizeof *wp))) { /* First window */
|
||||||
fputs( "First initialisation failed!\n", stderr) ;
|
fputs( "First initialisation failed!\n", stderr) ;
|
||||||
exit( EXIT_FAILURE) ;
|
exit( EXIT_FAILURE) ;
|
||||||
}
|
}
|
||||||
|
22
names.c
22
names.c
@ -275,7 +275,7 @@ const name_bind names[] = {
|
|||||||
static int lastnmidx = 0 ; /* index of last name entry */
|
static int lastnmidx = 0 ; /* index of last name entry */
|
||||||
|
|
||||||
|
|
||||||
key_tab *keytab ;
|
kbind_p keytab ;
|
||||||
static int ktsize = 140 ; /* last check: need at least 133 + 1 */
|
static int ktsize = 140 ; /* last check: need at least 133 + 1 */
|
||||||
|
|
||||||
|
|
||||||
@ -290,7 +290,7 @@ boolean init_bindings( void) {
|
|||||||
keytab->k_nbp = NULL ;
|
keytab->k_nbp = NULL ;
|
||||||
|
|
||||||
/* Add default key bindings */
|
/* Add default key bindings */
|
||||||
const name_bind *nbp ;
|
nbind_p nbp ;
|
||||||
for( nbp = names ; nbp->n_func != NULL ; nbp++) {
|
for( nbp = names ; nbp->n_func != NULL ; nbp++) {
|
||||||
/* Check entries and strict order */
|
/* Check entries and strict order */
|
||||||
assert( (nbp->n_name != NULL) &&
|
assert( (nbp->n_name != NULL) &&
|
||||||
@ -301,7 +301,7 @@ boolean init_bindings( void) {
|
|||||||
|
|
||||||
/* Add key definition */
|
/* Add key definition */
|
||||||
if( nbp->n_keycode) {
|
if( nbp->n_keycode) {
|
||||||
key_tab *ktp = setkeybinding( nbp->n_keycode, nbp) ;
|
kbind_p ktp = setkeybinding( nbp->n_keycode, nbp) ;
|
||||||
/* check it was indeed an insertion at end of table not a
|
/* check it was indeed an insertion at end of table not a
|
||||||
* key code re-definition */
|
* key code re-definition */
|
||||||
assert( (++ktp)->k_code == 0) ;
|
assert( (++ktp)->k_code == 0) ;
|
||||||
@ -317,7 +317,7 @@ boolean init_bindings( void) {
|
|||||||
assert( nbp->n_keycode && (nbp->n_name == NULL)) ;
|
assert( nbp->n_keycode && (nbp->n_name == NULL)) ;
|
||||||
|
|
||||||
/* Look for corresponding function and add extra key binding */
|
/* Look for corresponding function and add extra key binding */
|
||||||
const name_bind *fnbp ;
|
nbind_p fnbp ;
|
||||||
for( fnbp = names ; fnbp->n_func != NULL ; fnbp++)
|
for( fnbp = names ; fnbp->n_func != NULL ; fnbp++)
|
||||||
if( fnbp->n_func == nbp->n_func) {
|
if( fnbp->n_func == nbp->n_func) {
|
||||||
setkeybinding( nbp->n_keycode, fnbp) ;
|
setkeybinding( nbp->n_keycode, fnbp) ;
|
||||||
@ -331,8 +331,8 @@ boolean init_bindings( void) {
|
|||||||
return TRUE ;
|
return TRUE ;
|
||||||
}
|
}
|
||||||
|
|
||||||
key_tab *setkeybinding( unsigned key, const name_bind *nbp) {
|
kbind_p setkeybinding( unsigned key, nbind_p nbp) {
|
||||||
key_tab *ktp ;
|
kbind_p ktp ;
|
||||||
|
|
||||||
/* search the table to see if it exists */
|
/* search the table to see if it exists */
|
||||||
for( ktp = keytab ; ktp->k_code != 0 ; ktp++)
|
for( ktp = keytab ; ktp->k_code != 0 ; ktp++)
|
||||||
@ -347,7 +347,7 @@ key_tab *setkeybinding( unsigned key, const name_bind *nbp) {
|
|||||||
if( ktp == &keytab[ ktsize - 1]) {
|
if( ktp == &keytab[ ktsize - 1]) {
|
||||||
/* out of binding room */
|
/* out of binding room */
|
||||||
int newsize = ktsize + 10 ;
|
int newsize = ktsize + 10 ;
|
||||||
key_tab *newkeytab = realloc( keytab, newsize * sizeof *keytab) ;
|
kbind_p newkeytab = realloc( keytab, newsize * sizeof *keytab) ;
|
||||||
if( newkeytab == NULL)
|
if( newkeytab == NULL)
|
||||||
/* out of space */
|
/* out of space */
|
||||||
return ktp ;
|
return ktp ;
|
||||||
@ -366,13 +366,13 @@ key_tab *setkeybinding( unsigned key, const name_bind *nbp) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
boolean delkeybinding( unsigned key) {
|
boolean delkeybinding( unsigned key) {
|
||||||
key_tab *ktp ; /* pointer into the key binding table */
|
kbind_p ktp ; /* pointer into the key binding table */
|
||||||
|
|
||||||
/* search the table to see if the key exists */
|
/* search the table to see if the key exists */
|
||||||
for( ktp = keytab ; ktp->k_code != 0 ; ktp++) {
|
for( ktp = keytab ; ktp->k_code != 0 ; ktp++) {
|
||||||
if( ktp->k_code == key) {
|
if( ktp->k_code == key) {
|
||||||
/* save the pointer and scan to the end of the table */
|
/* save the pointer and scan to the end of the table */
|
||||||
key_tab *sav_ktp = ktp ;
|
kbind_p sav_ktp = ktp ;
|
||||||
while( (++ktp)->k_code != 0) ;
|
while( (++ktp)->k_code != 0) ;
|
||||||
ktp -= 1 ; /* backup to the last legit entry */
|
ktp -= 1 ; /* backup to the last legit entry */
|
||||||
|
|
||||||
@ -392,7 +392,7 @@ boolean delkeybinding( unsigned key) {
|
|||||||
|
|
||||||
#define BINARY 1
|
#define BINARY 1
|
||||||
|
|
||||||
const name_bind *fncmatch( char *name) {
|
nbind_p fncmatch( char *name) {
|
||||||
#ifdef BINARY
|
#ifdef BINARY
|
||||||
int found = lastnmidx ;
|
int found = lastnmidx ;
|
||||||
int low = 0 ;
|
int low = 0 ;
|
||||||
@ -411,7 +411,7 @@ const name_bind *fncmatch( char *name) {
|
|||||||
|
|
||||||
return &names[ found] ;
|
return &names[ found] ;
|
||||||
#else
|
#else
|
||||||
const name_bind *nbp ;
|
nbind_p nbp ;
|
||||||
for( nbp = names ; nbp->n_func != NULL ; nbp++)
|
for( nbp = names ; nbp->n_func != NULL ; nbp++)
|
||||||
if( !strcmp( name, bind_name( nbp)))
|
if( !strcmp( name, bind_name( nbp)))
|
||||||
break ;
|
break ;
|
||||||
|
25
names.h
25
names.h
@ -7,36 +7,39 @@
|
|||||||
|
|
||||||
|
|
||||||
/* Bindable uEMACS function pointer type and definition template */
|
/* Bindable uEMACS function pointer type and definition template */
|
||||||
#define BINDABLE( fname) int fname( int f, int n)
|
#define BINDABLE( fname) int fname( int f, int n)
|
||||||
|
|
||||||
typedef BINDABLE( (*fnp_t)) ;
|
typedef BINDABLE( (*fnp_t)) ;
|
||||||
|
|
||||||
|
|
||||||
/* Structure for the name binding table. */
|
/* Structure for the name binding table. */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const char *n_name ; /* name starting with one tag character */
|
const char *n_name ; /* name starting with one tag character */
|
||||||
fnp_t n_func ; /* function the name is bound to */
|
fnp_t n_func ; /* function the name is bound to */
|
||||||
unsigned n_keycode ; /* default key assignment, 0 when none */
|
unsigned n_keycode ; /* default key assignment, 0 when none */
|
||||||
} name_bind ;
|
} name_bind ;
|
||||||
|
|
||||||
|
typedef const name_bind *nbind_p ;
|
||||||
|
|
||||||
#define bind_name( p) (&( p)->n_name[ 1])
|
#define bind_name( p) (&( p)->n_name[ 1])
|
||||||
#define bind_tag( p) ( p)->n_name[ 0]
|
#define bind_tag( p) ( p)->n_name[ 0]
|
||||||
|
|
||||||
|
|
||||||
/* Structure for the key bindings table. */
|
/* Structure for the key bindings table. */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
unsigned k_code ; /* Key code */
|
unsigned k_code ; /* Key code */
|
||||||
const name_bind *k_nbp ; /* entry in name to function map table */
|
nbind_p k_nbp ; /* entry in name to function map table */
|
||||||
} key_tab ;
|
} *kbind_p ;
|
||||||
|
|
||||||
|
|
||||||
extern const name_bind names[] ; /* name to function mapping table */
|
extern const name_bind names[] ; /* name to function mapping table */
|
||||||
extern key_tab *keytab ; /* key bind to functions table */
|
extern kbind_p keytab ; /* key bind to functions table */
|
||||||
|
|
||||||
|
|
||||||
boolean init_bindings( void) ;
|
boolean init_bindings( void) ;
|
||||||
key_tab *setkeybinding( unsigned key, const name_bind *nbp) ;
|
kbind_p setkeybinding( unsigned key, nbind_p nbp) ;
|
||||||
boolean delkeybinding( unsigned key) ;
|
boolean delkeybinding( unsigned key) ;
|
||||||
const name_bind *fncmatch( char *name) ; /* look up by name */
|
nbind_p fncmatch( char *name) ; /* look up by name */
|
||||||
|
|
||||||
/* bindable functions mapped to prefix keys and hooks */
|
/* bindable functions mapped to prefix keys and hooks */
|
||||||
BINDABLE( nullproc) ;
|
BINDABLE( nullproc) ;
|
||||||
|
Loading…
Reference in New Issue
Block a user