1
0
mirror of https://github.com/rfivet/uemacs.git synced 2024-12-18 07:16:23 -05:00

Review apropos/buildlist/strinc.

Potential sign extension issue while converting key description to keycode.
This commit is contained in:
Renaud 2015-02-22 16:22:48 +08:00
parent 61f5fe7e2d
commit e8bb7b1ea2

57
bind.c
View File

@ -28,13 +28,13 @@
#if APROP #if APROP
static int buildlist( char *mstring) ;
static int strinc( char *source, char *sub) ; static int strinc( char *source, char *sub) ;
#endif #endif
static void cmdstr( int c, char *seq) ; static void cmdstr( int c, char *seq) ;
static unsigned int getckey( int mflag) ; static unsigned int getckey( int mflag) ;
static unsigned int stock( char *keyname) ; static unsigned int stock( char *keyname) ;
static int buildlist( int type, char *mstring) ;
static int unbindchar( int c) ; static int unbindchar( int c) ;
static char *getfname( fn_t) ; static char *getfname( fn_t) ;
@ -276,7 +276,7 @@ static int unbindchar( int c) {
int desbind(int f, int n) int desbind(int f, int n)
#if APROP #if APROP
{ {
buildlist(TRUE, ""); buildlist( "") ;
return TRUE; return TRUE;
} }
@ -286,26 +286,24 @@ int apro(int f, int n)
int status; /* status return */ int status; /* status return */
status = mlreply("Apropos string: ", mstring, NSTRING - 1); status = mlreply("Apropos string: ", mstring, NSTRING - 1);
if (status != TRUE) if (status == ABORT)
return status; return status;
return buildlist(FALSE, mstring); return buildlist( mstring) ;
} }
/* /*
* build a binding list (limited or full) * build a binding list (limited or full)
* *
* int type; true = full list, false = partial list * char *mstring; match string if a partial list, "" matches all
* char *mstring; match string if a partial list
*/ */
static int buildlist( int type, char *mstring) static int buildlist( char *mstring)
#endif #endif
{ {
struct window *wp; /* scanning pointer to windows */ struct window *wp; /* scanning pointer to windows */
struct key_tab *ktp; /* pointer into the command table */ struct key_tab *ktp; /* pointer into the command table */
struct name_bind *nptr; /* pointer into the name binding table */ struct name_bind *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 */
int cpos; /* current position to use in outseq */
char outseq[80]; /* output buffer for keystroke sequence */ char outseq[80]; /* output buffer for keystroke sequence */
/* split the current window to make room for the binding list */ /* split the current window to make room for the binding list */
@ -344,20 +342,19 @@ static int buildlist( int type, char *mstring)
wp->w_marko = 0; wp->w_marko = 0;
/* build the contents of this window, inserting it line by line */ /* build the contents of this window, inserting it line by line */
nptr = &names[0]; for( nptr = &names[ 0] ; nptr->n_func != NULL ; nptr++) {
while (nptr->n_func != NULL) { int cpos ; /* current position to use in outseq */
#if APROP
/* if we are executing an apropos command..... */
/* and current string doesn't include the search string */
if( *mstring && strinc( nptr->n_name, mstring) == FALSE)
continue ;
#endif
/* add in the command name */ /* add in the command name */
strcpy(outseq, nptr->n_name); strcpy(outseq, nptr->n_name);
cpos = strlen(outseq); cpos = strlen(outseq);
#if APROP
/* if we are executing an apropos command..... */
if (type == FALSE &&
/* and current string doesn't include the search string */
strinc(outseq, mstring) == FALSE)
goto fail;
#endif
/* search down any keys bound to this */ /* search down any keys bound to this */
ktp = &keytab[0]; ktp = &keytab[0];
while (ktp->k_fp != NULL) { while (ktp->k_fp != NULL) {
@ -386,9 +383,6 @@ static int buildlist( int type, char *mstring)
if (linstr(outseq) != TRUE) if (linstr(outseq) != TRUE)
return FALSE; return FALSE;
} }
fail: /* and on to the next name */
++nptr;
} }
curwp->w_bufp->b_mode |= MDVIEW; /* put this buffer view mode */ curwp->w_bufp->b_mode |= MDVIEW; /* put this buffer view mode */
@ -413,31 +407,23 @@ static int buildlist( int type, char *mstring)
* char *sub; substring to look for * char *sub; substring to look for
*/ */
static int strinc( char *source, char *sub) { static int strinc( char *source, char *sub) {
char *sp; /* ptr into source */ /* for each character in the source string */
for( ; *source ; source++) {
char *nxtsp ; /* next ptr into source */ char *nxtsp ; /* next ptr into source */
char *tp ; /* ptr into substring */ char *tp ; /* ptr into substring */
/* for each character in the source string */ nxtsp = source;
sp = source;
while (*sp) {
tp = sub;
nxtsp = sp;
/* is the substring here? */ /* is the substring here? */
while (*tp) { for( tp = sub ; *tp ; tp++)
if( *nxtsp++ != *tp) if( *nxtsp++ != *tp)
break ; break ;
else
tp++;
}
/* yes, return a success */ /* yes, return a success */
if( *tp == 0) if( *tp == 0)
return TRUE ; return TRUE ;
/* no, onward */
sp++;
} }
return FALSE ; return FALSE ;
} }
#endif #endif
@ -449,10 +435,11 @@ static int strinc( char *source, char *sub) {
*/ */
static unsigned int getckey( int mflag) { static unsigned int getckey( int mflag) {
unsigned int c; /* character fetched */ unsigned int c; /* character fetched */
char tok[NSTRING]; /* command incoming */
/* check to see if we are executing a command line */ /* check to see if we are executing a command line */
if (clexec) { if (clexec) {
char tok[ NSTRING] ; /* command incoming */
macarg( tok, sizeof tok) ; /* get the next token */ macarg( tok, sizeof tok) ; /* get the next token */
return stock(tok); return stock(tok);
} }
@ -627,7 +614,7 @@ static unsigned int stock( char *keyname) {
*keyname -= 32; *keyname -= 32;
/* the final sequence... */ /* the final sequence... */
c |= *keyname; c |= *keyname & 0xFFU ;
return c; return c;
} }