1
0
mirror of https://github.com/rfivet/uemacs.git synced 2024-06-12 14:40:41 +00:00

Use binary search for name to function lookup. Fix name mapping table order. Rework test scripts.

This commit is contained in:
Renaud 2021-07-21 16:40:36 +08:00
parent 6f7d89b1ac
commit 521d96fbda
7 changed files with 45 additions and 35 deletions

View File

@ -67,3 +67,4 @@ set %D 0 # looking EAST
beginning-of-file beginning-of-file
set $curline 3 set $curline 3
set $curcol 1 set $curcol 1
unmark-buffer

2
eval.c
View File

@ -35,8 +35,6 @@
#define MAXVARS 255 #define MAXVARS 255
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
/* Macro argument token types */ /* Macro argument token types */
#define TKNUL 0 /* end-of-string */ #define TKNUL 0 /* end-of-string */

View File

@ -61,3 +61,8 @@ set %NC &asc "█"
!endwhile !endwhile
set $curline 3 set $curline 3
set $curcol 1 set $curcol 1
select-buffer stack
unmark-buffer
select-buffer %thisbuf
unmark-buffer
delete-buffer stack

18
input.c
View File

@ -157,24 +157,6 @@ int ectoc( int c) {
return 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, bind_name( ffp)) == 0)
break ;
return ffp ;
}
const name_bind *getfncnb( fnp_t func) { const name_bind *getfncnb( fnp_t func) {
const name_bind *nptr ; /* pointer into the name binding table */ const name_bind *nptr ; /* pointer into the name binding table */

View File

@ -29,7 +29,6 @@ int newmlargt( char **outbufref, const char *prompt, int size) ;
int ectoc( int c) ; int ectoc( int c) ;
/* Look up in names to function association table */ /* Look up in names to function association table */
const name_bind *fncmatch( char *name) ; /* by name */
const name_bind *getname( void) ; /* interactively */ const name_bind *getname( void) ; /* interactively */
const name_bind *getfncnb( fnp_t func) ; /* by function */ const name_bind *getfncnb( fnp_t func) ; /* by function */

51
names.c
View File

@ -8,6 +8,8 @@
* processing. * processing.
*/ */
#include <string.h>
#include "basic.h" #include "basic.h"
#include "bind.h" #include "bind.h"
#include "bindable.h" #include "bindable.h"
@ -22,13 +24,14 @@
#include "random.h" #include "random.h"
#include "search.h" #include "search.h"
#include "spawn.h" #include "spawn.h"
#include "util.h"
#include "window.h" #include "window.h"
#include "word.h" #include "word.h"
const name_bind names[] = { const name_bind names[] = {
{" abort-command", ctrlg} , {" abort-command", ctrlg} ,
{" add-mode", setemode} ,
{" add-global-mode", setgmode} , {" add-global-mode", setgmode} ,
{" add-mode", setemode} ,
#if APROP #if APROP
{" apropos", apro} , {" apropos", apro} ,
#endif #endif
@ -55,8 +58,8 @@ const name_bind names[] = {
{" ctlx-prefix", cex} , {" ctlx-prefix", cex} ,
{"!delete-blank-lines", deblank} , {"!delete-blank-lines", deblank} ,
{" delete-buffer", killbuffer} , {" delete-buffer", killbuffer} ,
{" delete-mode", delmode} ,
{" delete-global-mode", delgmode} , {" delete-global-mode", delgmode} ,
{" delete-mode", delmode} ,
{"!delete-next-character", forwdel} , {"!delete-next-character", forwdel} ,
{"!delete-next-word", delfword} , {"!delete-next-word", delfword} ,
{" delete-other-windows", onlywind} , {" delete-other-windows", onlywind} ,
@ -80,14 +83,6 @@ const name_bind names[] = {
{" execute-file", execfile} , {" execute-file", execfile} ,
{" execute-macro", ctlxe} , {" execute-macro", ctlxe} ,
{" execute-macro-1", cbuf1} , {" 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-10", cbuf10} ,
{" execute-macro-11", cbuf11} , {" execute-macro-11", cbuf11} ,
{" execute-macro-12", cbuf12} , {" execute-macro-12", cbuf12} ,
@ -98,6 +93,7 @@ const name_bind names[] = {
{" execute-macro-17", cbuf17} , {" execute-macro-17", cbuf17} ,
{" execute-macro-18", cbuf18} , {" execute-macro-18", cbuf18} ,
{" execute-macro-19", cbuf19} , {" execute-macro-19", cbuf19} ,
{" execute-macro-2", cbuf2} ,
{" execute-macro-20", cbuf20} , {" execute-macro-20", cbuf20} ,
{" execute-macro-21", cbuf21} , {" execute-macro-21", cbuf21} ,
{" execute-macro-22", cbuf22} , {" execute-macro-22", cbuf22} ,
@ -108,6 +104,7 @@ const name_bind names[] = {
{" execute-macro-27", cbuf27} , {" execute-macro-27", cbuf27} ,
{" execute-macro-28", cbuf28} , {" execute-macro-28", cbuf28} ,
{" execute-macro-29", cbuf29} , {" execute-macro-29", cbuf29} ,
{" execute-macro-3", cbuf3} ,
{" execute-macro-30", cbuf30} , {" execute-macro-30", cbuf30} ,
{" execute-macro-31", cbuf31} , {" execute-macro-31", cbuf31} ,
{" execute-macro-32", cbuf32} , {" execute-macro-32", cbuf32} ,
@ -118,7 +115,13 @@ const name_bind names[] = {
{" execute-macro-37", cbuf37} , {" execute-macro-37", cbuf37} ,
{" execute-macro-38", cbuf38} , {" execute-macro-38", cbuf38} ,
{" execute-macro-39", cbuf39} , {" execute-macro-39", cbuf39} ,
{" execute-macro-4", cbuf4} ,
{" execute-macro-40", cbuf40} , {" execute-macro-40", cbuf40} ,
{" execute-macro-5", cbuf5} ,
{" execute-macro-6", cbuf6} ,
{" execute-macro-7", cbuf7} ,
{" execute-macro-8", cbuf8} ,
{" execute-macro-9", cbuf9} ,
{" execute-named-command", namedcmd} , {" execute-named-command", namedcmd} ,
#if PROC #if PROC
{" execute-procedure", execproc} , {" execute-procedure", execproc} ,
@ -137,9 +140,9 @@ const name_bind names[] = {
#endif #endif
{" grow-window", enlargewind} , {" grow-window", enlargewind} ,
{"!handle-tab", insert_tab} , {"!handle-tab", insert_tab} ,
{" hunt-forward", forwhunt} ,
{" hunt-backward", backhunt} ,
{" help", help} , {" help", help} ,
{" hunt-backward", backhunt} ,
{" hunt-forward", forwhunt} ,
{" i-shell", spawncli} , {" i-shell", spawncli} ,
#if ISRCH #if ISRCH
{" incremental-search", fisearch} , {" incremental-search", fisearch} ,
@ -186,9 +189,9 @@ const name_bind names[] = {
{"!quote-character", quote} , {"!quote-character", quote} ,
{"!read-file", fileread} , {"!read-file", fileread} ,
{" redraw-display", reposition} , {" redraw-display", reposition} ,
{"!replace-string", sreplace} ,
{" resize-window", resize} , {" resize-window", resize} ,
{" restore-window", restwnd} , {" restore-window", restwnd} ,
{"!replace-string", sreplace} ,
#if ISRCH #if ISRCH
{" reverse-incremental-search", risearch} , {" reverse-incremental-search", risearch} ,
#endif #endif
@ -197,8 +200,8 @@ const name_bind names[] = {
#endif #endif
{"!save-file", filesave} , {"!save-file", filesave} ,
{" save-window", savewnd} , {" save-window", savewnd} ,
{" scroll-next-up", scrnextup} ,
{" scroll-next-down", scrnextdw} , {" scroll-next-down", scrnextdw} ,
{" scroll-next-up", scrnextup} ,
{" search-forward", forwsearch} , {" search-forward", forwsearch} ,
{" search-reverse", backsearch} , {" search-reverse", backsearch} ,
{" select-buffer", usebuffer} , {" select-buffer", usebuffer} ,
@ -232,4 +235,24 @@ const name_bind names[] = {
{" ", NULL} {" ", NULL}
}; };
const name_bind *fncmatch( char *name) {
int found = ARRAY_SIZE( names) - 1 ; /* index of last entry/ catch all */
int low = 0 ;
int high = found - 1 ;
do {
int cur = (high + low) / 2 ;
int s = strcmp( name, bind_name( &names[ cur])) ;
if( s < 0)
high = cur - 1 ;
else if( s == 0) {
found = cur ;
break ;
} else
low = cur + 1 ;
} while( low <= high) ;
return &names[ found] ;
}
/* end of names.c */ /* end of names.c */

View File

@ -15,4 +15,6 @@ typedef struct name_bind {
extern const name_bind names[] ; /* name to function mapping table */ extern const name_bind names[] ; /* name to function mapping table */
const name_bind *fncmatch( char *name) ; /* look up by name */
#endif #endif