From 92c9208cd447e75edd321c20574f63eeadd90e94 Mon Sep 17 00:00:00 2001 From: Renaud Fivet Date: Mon, 19 Jul 2021 15:39:00 +0800 Subject: [PATCH] start tagging uEMACS functions that are not compatible with view mode. --- .gitattributes | 1 + bind.c | 150 ++++++++------------- bind.h | 10 +- display.c | 4 +- display.h | 4 +- ebind.c | 54 ++++---- ebind.h | 18 ++- exec.c | 35 +++-- execute.c | 12 +- fnp_t.h | 7 + input.c | 46 +++++-- input.h | 9 +- names.c | 344 ++++++++++++++++++++++++------------------------- names.h | 17 ++- word.c | 15 ++- 15 files changed, 372 insertions(+), 354 deletions(-) create mode 100644 .gitattributes create mode 100644 fnp_t.h diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..176a458 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto diff --git a/bind.c b/bind.c index f7fddf9..7227b7d 100644 --- a/bind.c +++ b/bind.c @@ -31,14 +31,13 @@ #if APROP static int buildlist( char *mstring) ; -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( unsigned c) ; -static char *getfname( fn_t) ; +static const char *getfname( unsigned keycode, char *failmsg) ; int help(int f, int n) @@ -77,10 +76,9 @@ int help(int f, int n) return TRUE; } -int deskey(int f, int n) -{ /* describe the command for a certain key */ +int deskey( int f, int n) { +/* 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 */ /* prompt the user to type us a key to describe */ @@ -96,12 +94,8 @@ int deskey(int f, int n) ostring(outseq); ostring(" "); - /* find the right ->function */ - if ((ptr = getfname(getbind(c))) == NULL) - ptr = "Not Bound"; - /* output the command sequence */ - ostring(ptr); + ostring( getfname( c, "Not Bound")) ; return TRUE; } @@ -114,7 +108,7 @@ int deskey(int f, int n) int bindtokey(int f, int n) { unsigned int c; /* command key to bind */ - fn_t kfunc; /* ptr to the requested function to bind to */ + fnp_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 */ @@ -123,7 +117,7 @@ int bindtokey(int f, int n) mlwrite(": bind-to-key "); /* get the function name to bind it to */ - kfunc = getname(); + kfunc = getname()->n_func ; if (kfunc == NULL) { mlwrite("(No such function)"); return FALSE; @@ -266,6 +260,35 @@ static int unbindchar( unsigned c) { return TRUE; } +#if APROP +/* + * 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 ; +} +#endif + /* describe bindings * bring up a fake buffer and list the key bindings * into it with view mode @@ -299,7 +322,7 @@ static int buildlist( char *mstring) { #endif 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 */ + const 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 */ @@ -339,7 +362,7 @@ static int buildlist( char *mstring) { wp->w_marko = 0; /* build the contents of this window, inserting it line by line */ - for( nptr = &names[ 0] ; nptr->n_func != NULL ; nptr++) { + for( nptr = names ; nptr->n_func != NULL ; nptr++) { int cpos ; /* current position to use in outseq */ #if APROP @@ -391,36 +414,6 @@ static int buildlist( char *mstring) { return TRUE; } -#if APROP - -/* - * does source include sub? - * - * char *source; string to search in - * char *sub; substring to look for - */ -static int strinc( char *source, char *sub) { - /* for each character in the source string */ - for( ; *source ; source++) { - char *nxtsp ; /* next ptr into source */ - 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 ; -} -#endif - /* * get a command key sequence from the keyboard * @@ -512,57 +505,25 @@ static void cmdstr( int c, char *seq) { * * int c; key to find what is bound to it */ -fn_t getbind( unsigned c) { - struct key_tab *ktp; +fnp_t getbind( unsigned c) { + struct key_tab *ktp ; - ktp = &keytab[0]; /* Look in key table. */ - while (ktp->k_fp != NULL) { + for( ktp = keytab ; ktp->k_fp != NULL ; ktp++) if (ktp->k_code == c) - return ktp->k_fp; - ++ktp; - } + return ktp->k_fp ; /* no such binding */ - return NULL; + return NULL ; } -/* - * getfname: - * This function takes a ptr to function and gets the name - * associated with it. - */ -static char *getfname(fn_t func) -{ - struct name_bind *nptr; /* pointer into the name binding table */ +static const char *getfname( unsigned keycode, char *failmsg) { +/* takes a key code and gets the name of the function bound to it */ + fnp_t func = getbind( keycode) ; + if( func == NULL) + return failmsg ; - /* 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; -} - -/* - * match fname to a function in the names table - * and return any match or NULL if none - * - * char *fname; name to attempt to match - */ -int (*fncmatch(char *fname)) (int, int) -{ - 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; + const char *found = getnamebind( func)->n_name ; + return *found ? found : failmsg ; } /* @@ -618,15 +579,8 @@ static unsigned int stock( char *keyname) { /* * string key name to binding name.... * - * char *skey; name of keey to get binding for + * char *skey; name of key to get binding for */ -char *transbind(char *skey) -{ - char *bindname; - - bindname = getfname(getbind(stock(skey))); - if (bindname == NULL) - bindname = "ERROR"; - - return bindname; +const char *transbind( char *skey) { + return getfname( stock( skey), "ERROR") ; } diff --git a/bind.h b/bind.h index 7a543c1..141c3f4 100644 --- a/bind.h +++ b/bind.h @@ -1,23 +1,21 @@ #ifndef _BIND_H_ #define _BIND_H_ +#include "fnp_t.h" + #define APROP 1 /* Add code for Apropos command */ #if APROP int apro( int f, int n) ; #endif -/* Some global fuction declarations. */ -typedef int (*fn_t)(int, int); - int help( int f, int n) ; int deskey( int f, int n) ; int bindtokey( int f, int n) ; int unbindkey( int f, int n) ; int desbind( int f, int n) ; int startup( const char *fname) ; -fn_t getbind( unsigned keycode) ; -fn_t fncmatch( char *) ; -char *transbind( char *skey) ; +fnp_t getbind( unsigned keycode) ; +const char *transbind( char *skey) ; #endif diff --git a/display.c b/display.c index 3cd42d5..70f4b3c 100644 --- a/display.c +++ b/display.c @@ -1283,7 +1283,7 @@ static void mlputc( unicode_t c) { * * char *s; string to output */ -void ostring( char *s) { +void ostring( const char *s) { unsigned char c ; if( discmd) @@ -1553,7 +1553,7 @@ void echoc( unicode_t c) { * * char *s; string to output */ -void echos( char *s) { +void echos( const char *s) { unicode_t c ; if( disinp) diff --git a/display.h b/display.h index 0f94d1a..b244df1 100644 --- a/display.h +++ b/display.h @@ -27,9 +27,9 @@ void movecursor( int row, int col) ; void mlerase( void) ; void vmlwrite( const char *fmt, va_list ap) ; void mlwrite( const char *fmt, ...) ; -void ostring( char *s) ; +void ostring( const char *s) ; void echoc( unicode_t c) ; -void echos( char *s) ; +void echos( const char *s) ; void rubout( void) ; void getscreensize( int *widthp, int *heightp) ; diff --git a/ebind.c b/ebind.c index 04df09d..9f1c78a 100644 --- a/ebind.c +++ b/ebind.c @@ -34,19 +34,19 @@ * characters of the command. This explains the funny location of the * control-X commands. */ -struct key_tab keytab[NBINDS] = { +key_tab keytab[ NBINDS] = { {CONTROL | '?', backdel}, - {CONTROL | 'A', (fn_t) gotobol} + {CONTROL | 'A', (fnp_t) gotobol} , - {CONTROL | 'B', (fn_t) backchar} + {CONTROL | 'B', (fnp_t) backchar} , {CONTROL | 'C', insspace} , {CONTROL | 'D', forwdel} , - {CONTROL | 'E', (fn_t) gotoeol} + {CONTROL | 'E', (fnp_t) gotoeol} , - {CONTROL | 'F', (fn_t) forwchar} + {CONTROL | 'F', (fnp_t) forwchar} , {CONTROL | 'G', ctrlg} , @@ -62,11 +62,11 @@ struct key_tab keytab[NBINDS] = { , {CONTROL | 'M', insert_newline} , - {CONTROL | 'N', (fn_t) forwline} + {CONTROL | 'N', (fnp_t) forwline} , {CONTROL | 'O', openline} , - {CONTROL | 'P', (fn_t) backline} + {CONTROL | 'P', (fnp_t) backline} , {CONTROL | 'Q', quote} , @@ -74,11 +74,11 @@ struct key_tab keytab[NBINDS] = { , {CONTROL | 'S', forwsearch} , - {CONTROL | 'T', (fn_t) twiddle} + {CONTROL | 'T', (fnp_t) twiddle} , {CONTROL | 'U', unarg} , - {CONTROL | 'V', (fn_t) forwpage} + {CONTROL | 'V', (fnp_t) forwpage} , {CONTROL | 'W', killregion} , @@ -86,7 +86,7 @@ struct key_tab keytab[NBINDS] = { , {CONTROL | 'Y', yank} , - {CONTROL | 'Z', (fn_t) backpage} + {CONTROL | 'Z', (fnp_t) backpage} , {CONTROL | ']', metafn} , @@ -139,7 +139,7 @@ struct key_tab keytab[NBINDS] = { , {CTLX | CONTROL | 'W', filewrite} , - {CTLX | CONTROL | 'X', (fn_t) swapmark} + {CTLX | CONTROL | 'X', (fnp_t) swapmark} , {CTLX | CONTROL | 'Z', shrinkwind} , @@ -248,17 +248,17 @@ struct key_tab keytab[NBINDS] = { #endif {META | CONTROL | 'Z', scrnextup} , - {META | ' ', (fn_t) setmark} + {META | ' ', (fnp_t) setmark} , {META | '?', help} , {META | '!', reposition} , - {META | '.', (fn_t) setmark} + {META | '.', (fnp_t) setmark} , - {META | '>', (fn_t) gotoeob} + {META | '>', (fnp_t) gotoeob} , - {META | '<', (fn_t) gotobob} + {META | '<', (fnp_t) gotobob} , {META | '~', unmark} , @@ -309,7 +309,7 @@ struct key_tab keytab[NBINDS] = { #endif {META | 'U', upperword} , - {META | 'V', (fn_t) backpage} + {META | 'V', (fnp_t) backpage} , {META | 'W', copyregion} , @@ -319,33 +319,33 @@ struct key_tab keytab[NBINDS] = { , #if VT220 - {SPEC | '1', (fn_t) gotobob /* fisearch */} + {SPEC | '1', (fnp_t) gotobob /* fisearch */} , /* VT220 keys */ {SPEC | '2', yank} , {SPEC | '3', forwdel /* killregion */} , - {SPEC | '4', (fn_t) gotoeob /* setmark */} + {SPEC | '4', (fnp_t) gotoeob /* setmark */} , - {SPEC | '5', (fn_t) backpage} + {SPEC | '5', (fnp_t) backpage} , - {SPEC | '6', (fn_t) forwpage} + {SPEC | '6', (fnp_t) forwpage} , - {SPEC | 'A', (fn_t) backline} + {SPEC | 'A', (fnp_t) backline} , - {SPEC | 'B', (fn_t) forwline} + {SPEC | 'B', (fnp_t) forwline} , - {SPEC | 'C', (fn_t) forwchar} + {SPEC | 'C', (fnp_t) forwchar} , - {SPEC | 'D', (fn_t) backchar} + {SPEC | 'D', (fnp_t) backchar} , {SPEC | 'c', metafn} , - {SPEC | 'd', (fn_t) backchar} + {SPEC | 'd', (fnp_t) backchar} , - {SPEC | 'e', (fn_t) forwline} + {SPEC | 'e', (fnp_t) forwline} , - {SPEC | 'f', (fn_t) gotobob} + {SPEC | 'f', (fnp_t) gotobob} , {SPEC | 'h', help} , diff --git a/ebind.h b/ebind.h index 0b0f1d4..83dd710 100644 --- a/ebind.h +++ b/ebind.h @@ -1,9 +1,15 @@ +#ifndef _EBIND_H_ +#define _EBIND_H_ + +#include "fnp_t.h" + /* Structure for the table of initial key bindings. */ -struct key_tab { - unsigned k_code ; /* Key code */ - int (*k_fp)( int, int) ; /* Routine to handle it */ -} ; +typedef struct key_tab { + unsigned k_code ; /* Key code */ + fnp_t k_fp ; /* Routine to handle it */ +} key_tab ; -#define NBINDS 256 /* max # of bound keys */ -extern struct key_tab keytab[ NBINDS] ; /* key bind to functions table */ +#define NBINDS 256 /* max # of bound keys */ +extern key_tab keytab[ NBINDS] ; /* key bind to functions table */ +#endif diff --git a/exec.c b/exec.c index 6b01bd3..bef62b7 100644 --- a/exec.c +++ b/exec.c @@ -85,22 +85,23 @@ static int macarg( char *tok, int toksz) ; /* * Execute a named command even if it is not bound. */ -int namedcmd(int f, int n) -{ - fn_t kfunc; /* ptr to the requexted function to bind to */ - +int namedcmd( int f, int n) { /* prompt the user to type a named command */ mlwrite(": "); /* and now get the function name to execute */ - kfunc = getname(); + const name_bind *nbp = getname() ; + fnp_t kfunc = nbp->n_func ; if (kfunc == NULL) { mlwrite("(No such function)"); return FALSE; } + if( nbp->tag && (curbp->b_mode & MDVIEW)) + return rdonly() ; + /* and then execute the command */ - return kfunc(f, n); + return kfunc(f, n) ; } static int docmd( char *cline) ; @@ -145,7 +146,6 @@ int execcmd( int f, int n) { static int docmd( char *cline) { int f; /* default argument flag */ int n; /* numeric repeat value */ - fn_t fnc; /* function to execute */ int status; /* return status of function */ boolean oldcle ; /* old contents of clexec flag */ char *oldestr; /* original exec string */ @@ -187,19 +187,26 @@ static int docmd( char *cline) { } /* and match the token to see if it exists */ - if ((fnc = fncmatch(tkn)) == NULL) { + const name_bind *nbp = fncmatch( tkn) ; + fnp_t fnc = nbp->n_func ; + if( fnc == NULL) { mlwrite("(No such Function)"); execstr = oldestr; return FALSE; } - /* save the arguments and go execute the command */ - oldcle = clexec; /* save old clexec flag */ - clexec = TRUE; /* in cline execution */ - status = (*fnc) (f, n); /* call the function */ + if( nbp->tag && (curbp->b_mode & MDVIEW)) + status = rdonly() ; + else { + /* save the arguments and go execute the command */ + oldcle = clexec; /* save old clexec flag */ + clexec = TRUE; /* in cline execution */ + status = fnc( f, n) ; /* call the function */ + clexec = oldcle; /* restore clexec flag */ + execstr = oldestr; + } + cmdstatus = status; /* save the status */ - clexec = oldcle; /* restore clexec flag */ - execstr = oldestr; return status; } diff --git a/execute.c b/execute.c index 03fd733..365860f 100644 --- a/execute.c +++ b/execute.c @@ -210,13 +210,17 @@ static void fmatch( int ch) { */ int execute( int c, int f, int n) { int status ; - fn_t execfunc ; /* if the keystroke is a bound function...do it */ - execfunc = getbind( c) ; + fnp_t execfunc = getbind( c) ; if( execfunc != NULL) { thisflag = 0 ; - status = execfunc( f, n) ; + const name_bind *nbp = getnamebind( execfunc) ; + if( nbp->tag && curbp->b_mode & MDVIEW) + status = rdonly() ; + else + status = execfunc( f, n) ; + lastflag = thisflag ; return status ; } @@ -330,7 +334,7 @@ void kbd_loop( void) { newc = getcmd() ; update( FALSE) ; do { - fn_t execfunc ; + fnp_t execfunc ; if( c == newc && (execfunc = getbind( c)) != NULL diff --git a/fnp_t.h b/fnp_t.h new file mode 100644 index 0000000..87e50c0 --- /dev/null +++ b/fnp_t.h @@ -0,0 +1,7 @@ +#ifndef __FNP_T_H__ +#define __FNP_T_H__ + +/* Generic uEMACS function pointer type */ +typedef int (*fnp_t)( int, int) ; + +#endif diff --git a/input.c b/input.c index fe127b4..ec5f05e 100644 --- a/input.c +++ b/input.c @@ -157,17 +157,45 @@ int ectoc( int c) { return c ; } +/* + * match fname to a function in the names table + * and return any match or NULL if none + * + * char *fname; name to attempt to match + */ +const name_bind *fncmatch( char *fname) { + const name_bind *ffp ; /* pointer to entry in name binding table */ + + /* scan through the table, returning any match */ + for( ffp = names ; ffp->n_func != NULL ; ffp++) + if( strcmp( fname, ffp->n_name) == 0) + break ; + + return ffp ; +} + + +const name_bind *getnamebind( fnp_t func) { + const name_bind *nptr ; /* pointer into the name binding table */ + + /* skim through the table, looking for a match */ + for( nptr = names ; nptr->n_func != NULL ; nptr++) + if (nptr->n_func == func) + break ; + + return nptr ; +} + /* * get a command name from the command line. Command completion means * that pressing a will attempt to complete an unfinished command * name if it is unique. */ -fn_t getname(void) -{ +const name_bind *getname( void) { int cpos; /* current column on screen output */ - struct name_bind *ffp; /* first ptr to entry in name binding table */ - struct name_bind *cffp; /* current ptr to entry in name binding table */ - struct name_bind *lffp; /* last ptr to entry in name binding table */ + 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 */ char buf[NSTRING]; /* buffer to hold tentative command name */ /* starting at the beginning of the string buffer */ @@ -177,7 +205,7 @@ fn_t getname(void) if (clexec) { if( TRUE != gettokval( buf, sizeof buf)) return NULL; - return fncmatch(&buf[0]); + return fncmatch( buf) ; } /* build a name string from the keyboard */ @@ -191,7 +219,7 @@ fn_t getname(void) buf[cpos] = 0; /* and match it off */ - return fncmatch(&buf[0]); + return fncmatch( buf) ; } else if (c == ectoc(abortc)) { /* Bell, abort */ ctrlg(FALSE, 0); @@ -217,7 +245,7 @@ fn_t getname(void) /* <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< */ /* attempt a completion */ buf[cpos] = 0; /* terminate it for us */ - ffp = &names[0]; /* scan for matches */ + ffp = names ; /* scan for matches */ while (ffp->n_func != NULL) { if (strncmp(buf, ffp->n_name, strlen(buf)) == 0) { @@ -229,7 +257,7 @@ fn_t getname(void) /* no...we match, print it */ echos( ffp->n_name + cpos) ; TTflush(); - return ffp->n_func; + return ffp ; } else { /* << << << << << << << << << << << << << << << << << */ /* try for a partial match against the list */ diff --git a/input.h b/input.h index 487cb0f..2bc53de 100644 --- a/input.h +++ b/input.h @@ -1,7 +1,7 @@ #ifndef _INPUT_H_ #define _INPUT_H_ -#include "bind.h" +#include "names.h" typedef enum { @@ -26,7 +26,12 @@ int mlyesno( const char *prompt) ; int newmlarg( char **outbufref, const char *prompt, int size) ; int newmlargt( char **outbufref, const char *prompt, int size) ; int ectoc( int c) ; -fn_t getname( void) ; + +/* Look up in names to function association table */ +const name_bind *fncmatch( char *) ; +const name_bind *getname( void) ; +const name_bind *getnamebind( fnp_t func) ; + int tgetc( void) ; int get1key( void) ; int getcmd( void) ; diff --git a/names.c b/names.c index 7403f41..6530670 100644 --- a/names.c +++ b/names.c @@ -8,8 +8,6 @@ * function. */ -#include - #include "basic.h" #include "bind.h" #include "bindable.h" @@ -27,209 +25,211 @@ #include "window.h" #include "word.h" -struct name_bind names[] = { - {"abort-command", ctrlg}, - {"add-mode", setemode}, - {"add-global-mode", setgmode}, +const name_bind names[] = { + {"abort-command", ctrlg, 0} , + {"add-mode", setemode, 0} , + {"add-global-mode", setgmode, 0} , #if APROP - {"apropos", apro}, + {"apropos", apro, 0} , #endif - {"backward-character", (fn_t) backchar}, - {"begin-macro", ctlxlp}, - {"beginning-of-file", (fn_t) gotobob}, - {"beginning-of-line", (fn_t) gotobol}, - {"bind-to-key", bindtokey}, - {"buffer-position", showcpos}, - {"case-region-lower", lowerregion}, - {"case-region-upper", upperregion}, - {"case-word-capitalize", capword}, - {"case-word-lower", lowerword}, - {"case-word-upper", upperword}, - {"change-file-name", filename}, - {"change-screen-size", newsize}, - {"change-screen-width", newwidth}, - {"clear-and-redraw", redraw}, - {"clear-message-line", clrmes}, - {"copy-region", copyregion}, + {"backward-character", (fnp_t) backchar, 0} , + {"begin-macro", ctlxlp, 0} , + {"beginning-of-file", (fnp_t) gotobob, 0} , + {"beginning-of-line", (fnp_t) gotobol, 0} , + {"bind-to-key", bindtokey, 0} , + {"buffer-position", showcpos, 0} , + {"case-region-lower", lowerregion, 0} , + {"case-region-upper", upperregion, 0} , + {"case-word-capitalize", capword, 0} , + {"case-word-lower", lowerword, 0} , + {"case-word-upper", upperword, 0} , + {"change-file-name", filename, 0} , + {"change-screen-size", newsize, 0} , + {"change-screen-width", newwidth, 0} , + {"clear-and-redraw", redraw, 0} , + {"clear-message-line", clrmes, 0} , + {"copy-region", copyregion, 0} , #if WORDPRO - {"count-words", wordcount}, + {"count-words", wordcount, 0} , #endif - {"ctlx-prefix", cex}, - {"delete-blank-lines", deblank}, - {"delete-buffer", killbuffer}, - {"delete-mode", delmode}, - {"delete-global-mode", delgmode}, - {"delete-next-character", forwdel}, - {"delete-next-word", delfword}, - {"delete-other-windows", onlywind}, - {"delete-previous-character", backdel}, - {"delete-previous-word", delbword}, - {"delete-window", delwind}, - {"describe-bindings", desbind}, - {"describe-key", deskey}, + {"ctlx-prefix", cex, 0} , + {"delete-blank-lines", deblank, 0} , + {"delete-buffer", killbuffer, 0} , + {"delete-mode", delmode, 0} , + {"delete-global-mode", delgmode, 0} , + {"delete-next-character", forwdel, 0} , + {"delete-next-word", delfword, 0} , + {"delete-other-windows", onlywind, 0} , + {"delete-previous-character", backdel, 0} , + {"delete-previous-word", delbword, 0} , + {"delete-window", delwind, 0} , + {"describe-bindings", desbind, 0} , + {"describe-key", deskey, 0} , #if AEDIT - {"detab-line", detab}, + {"detab-line", detab, 0} , #endif - {"end-macro", ctlxrp}, - {"end-of-file", (fn_t) gotoeob}, - {"end-of-line", (fn_t) gotoeol}, + {"end-macro", ctlxrp, 0} , + {"end-of-file", (fnp_t) gotoeob, 0} , + {"end-of-line", (fnp_t) gotoeol, 0} , #if AEDIT - {"entab-line", entab}, + {"entab-line", entab, 0} , #endif - {"exchange-point-and-mark", (fn_t) swapmark}, - {"execute-buffer", execbuf}, - {"execute-command-line", execcmd}, - {"execute-file", execfile}, - {"execute-macro", ctlxe}, - {"execute-macro-1", cbuf1}, - {"execute-macro-2", cbuf2}, - {"execute-macro-3", cbuf3}, - {"execute-macro-4", cbuf4}, - {"execute-macro-5", cbuf5}, - {"execute-macro-6", cbuf6}, - {"execute-macro-7", cbuf7}, - {"execute-macro-8", cbuf8}, - {"execute-macro-9", cbuf9}, - {"execute-macro-10", cbuf10}, - {"execute-macro-11", cbuf11}, - {"execute-macro-12", cbuf12}, - {"execute-macro-13", cbuf13}, - {"execute-macro-14", cbuf14}, - {"execute-macro-15", cbuf15}, - {"execute-macro-16", cbuf16}, - {"execute-macro-17", cbuf17}, - {"execute-macro-18", cbuf18}, - {"execute-macro-19", cbuf19}, - {"execute-macro-20", cbuf20}, - {"execute-macro-21", cbuf21}, - {"execute-macro-22", cbuf22}, - {"execute-macro-23", cbuf23}, - {"execute-macro-24", cbuf24}, - {"execute-macro-25", cbuf25}, - {"execute-macro-26", cbuf26}, - {"execute-macro-27", cbuf27}, - {"execute-macro-28", cbuf28}, - {"execute-macro-29", cbuf29}, - {"execute-macro-30", cbuf30}, - {"execute-macro-31", cbuf31}, - {"execute-macro-32", cbuf32}, - {"execute-macro-33", cbuf33}, - {"execute-macro-34", cbuf34}, - {"execute-macro-35", cbuf35}, - {"execute-macro-36", cbuf36}, - {"execute-macro-37", cbuf37}, - {"execute-macro-38", cbuf38}, - {"execute-macro-39", cbuf39}, - {"execute-macro-40", cbuf40}, - {"execute-named-command", namedcmd}, + {"exchange-point-and-mark", (fnp_t) swapmark, 0} , + {"execute-buffer", execbuf, 0} , + {"execute-command-line", execcmd, 0} , + {"execute-file", execfile, 0} , + {"execute-macro", ctlxe, 0} , + {"execute-macro-1", cbuf1, 0} , + {"execute-macro-2", cbuf2, 0} , + {"execute-macro-3", cbuf3, 0} , + {"execute-macro-4", cbuf4, 0} , + {"execute-macro-5", cbuf5, 0} , + {"execute-macro-6", cbuf6, 0} , + {"execute-macro-7", cbuf7, 0} , + {"execute-macro-8", cbuf8, 0} , + {"execute-macro-9", cbuf9, 0} , + {"execute-macro-10", cbuf10, 0} , + {"execute-macro-11", cbuf11, 0} , + {"execute-macro-12", cbuf12, 0} , + {"execute-macro-13", cbuf13, 0} , + {"execute-macro-14", cbuf14, 0} , + {"execute-macro-15", cbuf15, 0} , + {"execute-macro-16", cbuf16, 0} , + {"execute-macro-17", cbuf17, 0} , + {"execute-macro-18", cbuf18, 0} , + {"execute-macro-19", cbuf19, 0} , + {"execute-macro-20", cbuf20, 0} , + {"execute-macro-21", cbuf21, 0} , + {"execute-macro-22", cbuf22, 0} , + {"execute-macro-23", cbuf23, 0} , + {"execute-macro-24", cbuf24, 0} , + {"execute-macro-25", cbuf25, 0} , + {"execute-macro-26", cbuf26, 0} , + {"execute-macro-27", cbuf27, 0} , + {"execute-macro-28", cbuf28, 0} , + {"execute-macro-29", cbuf29, 0} , + {"execute-macro-30", cbuf30, 0} , + {"execute-macro-31", cbuf31, 0} , + {"execute-macro-32", cbuf32, 0} , + {"execute-macro-33", cbuf33, 0} , + {"execute-macro-34", cbuf34, 0} , + {"execute-macro-35", cbuf35, 0} , + {"execute-macro-36", cbuf36, 0} , + {"execute-macro-37", cbuf37, 0} , + {"execute-macro-38", cbuf38, 0} , + {"execute-macro-39", cbuf39, 0} , + {"execute-macro-40", cbuf40, 0} , + {"execute-named-command", namedcmd, 0} , #if PROC - {"execute-procedure", execproc}, + {"execute-procedure", execproc, 0} , #endif - {"execute-program", execprg}, - {"exit-emacs", quit}, + {"execute-program", execprg, 0} , + {"exit-emacs", quit, 0} , #if WORDPRO - {"fill-paragraph", fillpara}, + {"fill-paragraph", fillpara, 1} , #endif - {"filter-buffer", filter_buffer}, - {"find-file", filefind}, - {"forward-character", (fn_t) forwchar}, - {"goto-line", gotoline}, + {"filter-buffer", filter_buffer, 0} , + {"find-file", filefind, 0} , + {"forward-character", (fnp_t) forwchar, 0} , + {"goto-line", gotoline, 0} , #if CFENCE - {"goto-matching-fence", getfence}, + {"goto-matching-fence", getfence, 0} , #endif - {"grow-window", enlargewind}, - {"handle-tab", insert_tab}, - {"hunt-forward", forwhunt}, - {"hunt-backward", backhunt}, - {"help", help}, - {"i-shell", spawncli}, + {"grow-window", enlargewind, 0} , + {"handle-tab", insert_tab, 0} , + {"hunt-forward", forwhunt, 0} , + {"hunt-backward", backhunt, 0} , + {"help", help, 0} , + {"i-shell", spawncli, 0} , #if ISRCH - {"incremental-search", fisearch}, + {"incremental-search", fisearch, 0} , #endif - {"insert-file", insfile}, - {"insert-space", insspace}, - {"insert-string", istring}, + {"insert-file", insfile, 0} , + {"insert-space", insspace, 0} , + {"insert-string", istring, 1} , #if WORDPRO #if PKCODE - {"justify-paragraph", justpara}, + {"justify-paragraph", justpara, 1} , #endif - {"kill-paragraph", killpara}, + {"kill-paragraph", killpara, 1} , #endif - {"kill-region", killregion}, - {"kill-to-end-of-line", killtext}, - {"list-buffers", listbuffers}, - {"meta-prefix", metafn}, - {"move-window-down", mvdnwind}, - {"move-window-up", mvupwind}, - {"name-buffer", namebuffer}, - {"newline", insert_newline}, - {"newline-and-indent", indent}, - {"next-buffer", nextbuffer}, - {"next-line", (fn_t) forwline}, - {"next-page", (fn_t) forwpage}, + {"kill-region", killregion, 0} , + {"kill-to-end-of-line", killtext, 0} , + {"list-buffers", listbuffers, 0} , + {"meta-prefix", metafn, 0} , + {"move-window-down", mvdnwind, 0} , + {"move-window-up", mvupwind, 0} , + {"name-buffer", namebuffer, 0} , + {"newline", insert_newline, 0} , + {"newline-and-indent", indent, 0} , + {"next-buffer", nextbuffer, 0} , + {"next-line", (fnp_t) forwline, 0} , + {"next-page", (fnp_t) forwpage, 0} , #if WORDPRO - {"next-paragraph", gotoeop}, + {"next-paragraph", gotoeop, 0} , #endif - {"next-window", nextwind}, - {"next-word", forwword}, - {"nop", nullproc}, - {"open-line", openline}, - {"overwrite-string", ovstring}, - {"pipe-command", pipecmd}, - {"previous-line", (fn_t) backline}, - {"previous-page", (fn_t) backpage}, + {"next-window", nextwind, 0} , + {"next-word", forwword, 0} , + {"nop", nullproc, 0} , + {"open-line", openline, 0} , + {"overwrite-string", ovstring, 0} , + {"pipe-command", pipecmd, 0} , + {"previous-line", (fnp_t) backline, 0} , + {"previous-page", (fnp_t) backpage, 0} , #if WORDPRO - {"previous-paragraph", gotobop}, + {"previous-paragraph", gotobop, 0} , #endif - {"previous-window", prevwind}, - {"previous-word", backword}, - {"query-replace-string", qreplace}, - {"quick-exit", quickexit}, - {"quote-character", quote}, - {"read-file", fileread}, - {"redraw-display", reposition}, - {"resize-window", resize}, - {"restore-window", restwnd}, - {"replace-string", sreplace}, + {"previous-window", prevwind, 0} , + {"previous-word", backword, 0} , + {"query-replace-string", qreplace, 0} , + {"quick-exit", quickexit, 0} , + {"quote-character", quote, 0} , + {"read-file", fileread, 0} , + {"redraw-display", reposition, 0} , + {"resize-window", resize, 0} , + {"restore-window", restwnd, 0} , + {"replace-string", sreplace, 0} , #if ISRCH - {"reverse-incremental-search", risearch}, + {"reverse-incremental-search", risearch, 0} , #endif #if PROC - {"run", execproc}, + {"run", execproc, 0} , #endif - {"save-file", filesave}, - {"save-window", savewnd}, - {"scroll-next-up", scrnextup}, - {"scroll-next-down", scrnextdw}, - {"search-forward", forwsearch}, - {"search-reverse", backsearch}, - {"select-buffer", usebuffer}, - {"set", setvar}, - {"set-fill-column", setfillcol}, - {"set-mark", (fn_t) setmark}, - {"shell-command", spawn}, - {"shrink-window", shrinkwind}, - {"split-current-window", splitwind}, - {"store-macro", storemac}, + {"save-file", filesave, 0} , + {"save-window", savewnd, 0} , + {"scroll-next-up", scrnextup, 0} , + {"scroll-next-down", scrnextdw, 0} , + {"search-forward", forwsearch, 0} , + {"search-reverse", backsearch, 0} , + {"select-buffer", usebuffer, 0} , + {"set", setvar, 0} , + {"set-fill-column", setfillcol, 0} , + {"set-mark", (fnp_t) setmark, 0} , + {"shell-command", spawn, 0} , + {"shrink-window", shrinkwind, 0} , + {"split-current-window", splitwind, 0} , + {"store-macro", storemac, 0} , #if PROC - {"store-procedure", storeproc}, + {"store-procedure", storeproc, 0} , #endif #if BSD | SVR4 - {"suspend-emacs", bktoshell}, + {"suspend-emacs", bktoshell, 0} , #endif - {"transpose-characters", (fn_t) twiddle}, + {"transpose-characters", (fnp_t) twiddle, 0} , #if AEDIT - {"trim-line", trim}, + {"trim-line", trim, 0} , #endif - {"unbind-key", unbindkey}, - {"universal-argument", unarg}, - {"unmark-buffer", unmark}, - {"update-screen", upscreen}, - {"view-file", viewfile}, - {"wrap-word", wrapword}, - {"write-file", filewrite}, - {"write-message", writemsg}, - {"yank", yank}, + {"unbind-key", unbindkey, 0} , + {"universal-argument", unarg, 0} , + {"unmark-buffer", unmark, 0} , + {"update-screen", upscreen, 0} , + {"view-file", viewfile, 0} , + {"wrap-word", wrapword, 0} , + {"write-file", filewrite, 0} , + {"write-message", writemsg, 0} , + {"yank", yank, 0} , - {"", NULL} + {"", NULL, 0} }; + +/* end of names.c */ diff --git a/names.h b/names.h index 700b304..6bc1944 100644 --- a/names.h +++ b/names.h @@ -1,8 +1,15 @@ +#ifndef _NAMES_H_ +#define _NAMES_H_ + +#include "fnp_t.h" + /* Structure for the name binding table. */ -struct name_bind { - char *n_name; /* name of function key */ - int (*n_func)(int, int); /* function name is bound to */ -}; +typedef struct name_bind { + const char *n_name ; /* name of function key */ + fnp_t n_func ; /* function name is bound to */ + char tag ; /* view mode compatibility tag */ +} name_bind ; -extern struct name_bind names[];/* name to function table */ +extern const name_bind names[] ; /* name to function table */ +#endif diff --git a/word.c b/word.c index adf4356..8f1d83c 100644 --- a/word.c +++ b/word.c @@ -10,6 +10,7 @@ * Modified by Petri Kutvonen */ +#include #include #include /* malloc, free */ #include /* memcpy */ @@ -358,8 +359,8 @@ static int parafillnjustify( int f, int n, int justify_f) { int dotflag = 0 ; /* was the last char a period? */ int leftmarg = 0 ; /* left marginal */ - if (curbp->b_mode & MDVIEW) /* don't allow this command if */ - return rdonly(); /* we are in read only mode */ + assert( !(curbp->b_mode & MDVIEW)) ; + if (fillcol == 0) { /* no fill column set */ mloutstr( "No fill column set") ; return FALSE; @@ -507,8 +508,6 @@ int justpara( int f, int n) { */ int killpara(int f, int n) { - int status; /* returned status of functions */ - while (n--) { /* for each paragraph to delete */ /* mark out the end and beginning of the para to delete */ @@ -523,13 +522,15 @@ int killpara(int f, int n) curwp->w_doto = 0; /* force us to the beginning of line */ /* and delete it */ - if ((status = killregion(FALSE, 1)) != TRUE) - return status; + int status = killregion( FALSE, 1) ; + if( status != TRUE) + return status ; /* and clean up the 2 extra lines */ ldelete(2L, TRUE); } - return TRUE; + + return TRUE ; }