diff --git a/bind.c b/bind.c index b2c7ba7..1821861 100644 --- a/bind.c +++ b/bind.c @@ -39,15 +39,15 @@ static unsigned int stock( char *keyname) ; static const char *getfname( unsigned keycode, char *failmsg) ; -int help(int f, int n) -{ /* give me some help!!!! - bring up a fake buffer and read the help file - into it with view mode */ - struct buffer *bp; /* buffer pointer to help */ +BINDABLE( help) { +/* give me some help!!!! + bring up a fake buffer and read the help file into it with view mode */ char *fname = NULL; /* ptr to file returned by flook() */ - /* first check if we are already here */ - bp = bfind( hlpfname, FALSE, BFINVS); +/* first check if we are already here */ + buffer_p bp = bfind( hlpfname, FALSE, BFINVS); + if( bp == curbp) + return TRUE ; if (bp == NULL) { 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 */ - if (splitwind(FALSE, 1) == FALSE) - return FALSE; +/* 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 ; if (bp == NULL) { /* and read the stuff in */ if (getfile(fname, FALSE) == FALSE) return FALSE; } else - swbuffer(bp); + swbuffer( bp) ; /* make this window in VIEW mode, update all mode lines */ curwp->w_bufp->b_mode |= MDVIEW; @@ -100,14 +101,14 @@ BINDABLE( deskey) { * int f, n; command arguments [IGNORED] */ 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 */ /* prompt the user to type in a key to bind */ mlwrite("bind-to-key: "); /* get the function name to bind it to */ - const name_bind *nbp = getname() ; + nbind_p nbp = getname() ; if( nbp == NULL) /* abort */ return FALSE ; @@ -268,8 +269,8 @@ int apro( int f, int n) { static int buildlist( char *mstring) { #endif struct window *wp; /* scanning pointer to windows */ - key_tab *ktp; /* pointer into the command table */ - const name_bind *nptr;/* pointer into the name binding table */ + kbind_p ktp; /* pointer into the command table */ + nbind_p nptr;/* pointer into the name binding table */ struct buffer *bp; /* buffer to put binding list into */ 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 */ -key_tab *getkeybind( unsigned c) { - key_tab *ktp ; +kbind_p getkeybind( unsigned c) { + kbind_p ktp ; for( ktp = keytab ; ktp->k_code != 0 ; ktp++) if (ktp->k_code == c) @@ -464,7 +465,7 @@ key_tab *getkeybind( unsigned c) { static const char *getfname( unsigned keycode, char *failmsg) { /* 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) return failmsg ; diff --git a/bind.h b/bind.h index 8a4fe90..bacba1e 100644 --- a/bind.h +++ b/bind.h @@ -19,7 +19,7 @@ int desbind( int f, int n) ; int startup( const char *fname) ; /* 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 */ #endif diff --git a/exec.c b/exec.c index d9d82b2..0f2f3a1 100644 --- a/exec.c +++ b/exec.c @@ -90,7 +90,7 @@ int namedcmd( int f, int n) { mlwrite("execute-named-cmd: "); /* and now get the function name to execute */ - const name_bind *nbp = getname() ; + nbind_p nbp = getname() ; if( nbp == NULL) /* abort */ return FALSE ; @@ -190,7 +190,7 @@ static int docmd( char *cline) { } /* 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 ; if( fnc == NULL) { mlwrite("(No such Function)"); diff --git a/execute.c b/execute.c index d1e3ac7..f0738a6 100644 --- a/execute.c +++ b/execute.c @@ -213,7 +213,7 @@ int execute( int c, int f, int n) { int status ; /* if the keystroke is a bound function...do it */ - key_tab *ktp = getkeybind( c) ; + kbind_p ktp = getkeybind( c) ; if( ktp->k_code != 0) { thisflag = 0 ; assert( ktp->k_nbp != NULL) ; @@ -338,7 +338,7 @@ void kbd_loop( void) { newc = getcmd() ; update( FALSE) ; do { - key_tab *ktp ; + kbind_p ktp ; fnp_t execfunc ; if( c == newc diff --git a/input.c b/input.c index 616d670..a095cc2 100644 --- a/input.c +++ b/input.c @@ -162,11 +162,11 @@ int ectoc( int c) { * that pressing a will attempt to complete an unfinished command * name if it is unique. */ -const name_bind *getname( void) { +nbind_p getname( void) { int cpos; /* current column on screen output */ - const name_bind *ffp; /* first ptr to entry in name binding table */ - const name_bind *cffp; /* current ptr to entry in name binding table */ - const name_bind *lffp; /* last ptr to entry in name binding table */ + nbind_p ffp; /* first ptr to entry in name binding table */ + nbind_p cffp; /* current 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 */ /* starting at the beginning of the string buffer */ diff --git a/input.h b/input.h index bcb125a..b9bd06d 100644 --- a/input.h +++ b/input.h @@ -29,7 +29,7 @@ int newmlargt( char **outbufref, const char *prompt, int size) ; int ectoc( int c) ; /* Get a command name from the command line or interactively */ -const name_bind *getname( void) ; +nbind_p getname( void) ; int tgetc( void) ; int get1key( void) ; diff --git a/main.c b/main.c index dd507c2..253fa7a 100644 --- a/main.c +++ b/main.c @@ -164,15 +164,10 @@ int main(int argc, char **argv) } } - /* Initialize the editor. */ - if( !init_bindings()) { /* initialize mapping of function to name and key */ - return( EXIT_FAILURE) ; - } - - vtinit(); /* Display */ + vtinit() ; /* Display */ mloutfmt = mlwrite ; - edinit("main"); /* Buffers, windows */ - varinit(); /* user variables */ + edinit( "main") ; /* Bindings, buffers, windows */ + varinit() ; /* user variables */ viewflag = FALSE; /* view mode defaults off in command line */ 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 * file by default, and we want the buffer name to be right. */ -static void edinit(char *bname) -{ - struct buffer *bp; +static void edinit( char *bname) { + buffer_p bp; struct window *wp; - if( NULL == (bp = bfind( bname, TRUE, 0)) /* First buffer */ - || NULL == (blistp = bfind( "*List*", TRUE, BFINVS)) /* Buffer list buffer */ - || NULL == (wp = (struct window *) malloc( sizeof( struct window)))) { /* First window */ + if( !init_bindings() /* initialize mapping of function to name and key */ + || NULL == (bp = bfind( bname, TRUE, 0)) /* First buffer */ + || NULL == (blistp = bfind( "*List*", TRUE, BFINVS)) /* Buffer list */ + || NULL == (wp = malloc( sizeof *wp))) { /* First window */ fputs( "First initialisation failed!\n", stderr) ; exit( EXIT_FAILURE) ; } diff --git a/names.c b/names.c index 4b94876..c6b93e2 100644 --- a/names.c +++ b/names.c @@ -275,7 +275,7 @@ const name_bind names[] = { 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 */ @@ -290,7 +290,7 @@ boolean init_bindings( void) { keytab->k_nbp = NULL ; /* Add default key bindings */ - const name_bind *nbp ; + nbind_p nbp ; for( nbp = names ; nbp->n_func != NULL ; nbp++) { /* Check entries and strict order */ assert( (nbp->n_name != NULL) && @@ -301,7 +301,7 @@ boolean init_bindings( void) { /* Add key definition */ 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 * key code re-definition */ assert( (++ktp)->k_code == 0) ; @@ -317,7 +317,7 @@ boolean init_bindings( void) { assert( nbp->n_keycode && (nbp->n_name == NULL)) ; /* Look for corresponding function and add extra key binding */ - const name_bind *fnbp ; + nbind_p fnbp ; for( fnbp = names ; fnbp->n_func != NULL ; fnbp++) if( fnbp->n_func == nbp->n_func) { setkeybinding( nbp->n_keycode, fnbp) ; @@ -331,8 +331,8 @@ boolean init_bindings( void) { return TRUE ; } -key_tab *setkeybinding( unsigned key, const name_bind *nbp) { - key_tab *ktp ; +kbind_p setkeybinding( unsigned key, nbind_p nbp) { + kbind_p ktp ; /* search the table to see if it exists */ 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]) { /* out of binding room */ int newsize = ktsize + 10 ; - key_tab *newkeytab = realloc( keytab, newsize * sizeof *keytab) ; + kbind_p newkeytab = realloc( keytab, newsize * sizeof *keytab) ; if( newkeytab == NULL) /* out of space */ return ktp ; @@ -366,13 +366,13 @@ key_tab *setkeybinding( unsigned key, const name_bind *nbp) { } 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 */ for( ktp = keytab ; ktp->k_code != 0 ; ktp++) { if( ktp->k_code == key) { /* 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) ; ktp -= 1 ; /* backup to the last legit entry */ @@ -392,7 +392,7 @@ boolean delkeybinding( unsigned key) { #define BINARY 1 -const name_bind *fncmatch( char *name) { +nbind_p fncmatch( char *name) { #ifdef BINARY int found = lastnmidx ; int low = 0 ; @@ -411,7 +411,7 @@ const name_bind *fncmatch( char *name) { return &names[ found] ; #else - const name_bind *nbp ; + nbind_p nbp ; for( nbp = names ; nbp->n_func != NULL ; nbp++) if( !strcmp( name, bind_name( nbp))) break ; diff --git a/names.h b/names.h index 11ed227..64bf210 100644 --- a/names.h +++ b/names.h @@ -7,36 +7,39 @@ /* 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)) ; /* Structure for the name binding table. */ typedef struct { - const char *n_name ; /* name starting with one tag character */ - fnp_t n_func ; /* function the name is bound to */ - unsigned n_keycode ; /* default key assignment, 0 when none */ + const char *n_name ; /* name starting with one tag character */ + fnp_t n_func ; /* function the name is bound to */ + unsigned n_keycode ; /* default key assignment, 0 when none */ } name_bind ; +typedef const name_bind *nbind_p ; + #define bind_name( p) (&( p)->n_name[ 1]) #define bind_tag( p) ( p)->n_name[ 0] + /* Structure for the key bindings table. */ typedef struct { - unsigned k_code ; /* Key code */ - const name_bind *k_nbp ; /* entry in name to function map table */ -} key_tab ; + unsigned k_code ; /* Key code */ + nbind_p k_nbp ; /* entry in name to function map table */ +} *kbind_p ; -extern const name_bind names[] ; /* name to function mapping table */ -extern key_tab *keytab ; /* key bind to functions table */ +extern const name_bind names[] ; /* name to function mapping table */ +extern kbind_p keytab ; /* key bind to functions table */ 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) ; -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( nullproc) ;