mirror of
https://github.com/rfivet/uemacs.git
synced 2024-12-19 15:56:24 -05:00
Review function table format.
This commit is contained in:
parent
d57257d653
commit
70a5812928
227
eval.c
227
eval.c
@ -183,98 +183,67 @@ static const char *envars[] = {
|
|||||||
|
|
||||||
enum function_type {
|
enum function_type {
|
||||||
NILNAMIC = 0,
|
NILNAMIC = 0,
|
||||||
MONAMIC,
|
MONAMIC = (1 << 6),
|
||||||
DYNAMIC,
|
DYNAMIC = (2 << 6),
|
||||||
TRINAMIC,
|
TRINAMIC = (3 << 6),
|
||||||
|
} ;
|
||||||
|
|
||||||
|
enum function_code {
|
||||||
|
UFADD = 0, UFSUB, UFTIMES, UFDIV, UFMOD, UFNEG,
|
||||||
|
UFCAT, UFLEFT, UFRIGHT, UFMID, UFNOT, UFEQUAL,
|
||||||
|
UFLESS, UFGREATER, UFSEQUAL, UFSLESS, UFSGREAT, UFIND,
|
||||||
|
UFAND, UFOR, UFLENGTH, UFUPPER, UFLOWER, UFTRUTH,
|
||||||
|
UFASCII, UFCHR, UFGTKEY, UFRND, UFABS, UFSINDEX,
|
||||||
|
UFENV, UFBIND, UFEXIST, UFFIND, UFBAND, UFBOR,
|
||||||
|
UFBXOR, UFBNOT, UFXLATE,
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
/* List of recognized user functions. */
|
/* List of recognized user functions. */
|
||||||
static struct {
|
static struct {
|
||||||
const char f_name[ 4] ;
|
const char f_name[ 4] ;
|
||||||
const enum function_type f_type ;
|
const int f_type ;
|
||||||
} funcs[] = {
|
} funcs[] = {
|
||||||
{ "add", DYNAMIC }, /* add two numbers together */
|
{ "add", UFADD | DYNAMIC }, /* add two numbers together */
|
||||||
{ "sub", DYNAMIC }, /* subtraction */
|
{ "sub", UFSUB | DYNAMIC }, /* subtraction */
|
||||||
{ "tim", DYNAMIC }, /* multiplication */
|
{ "tim", UFTIMES | DYNAMIC }, /* multiplication */
|
||||||
{ "div", DYNAMIC }, /* division */
|
{ "div", UFDIV | DYNAMIC }, /* division */
|
||||||
{ "mod", DYNAMIC }, /* mod */
|
{ "mod", UFMOD | DYNAMIC }, /* mod */
|
||||||
{ "neg", MONAMIC }, /* negate */
|
{ "neg", UFNEG | MONAMIC }, /* negate */
|
||||||
{ "cat", DYNAMIC }, /* concatinate string */
|
{ "cat", UFCAT | DYNAMIC }, /* concatinate string */
|
||||||
{ "lef", DYNAMIC }, /* left string(string, len) */
|
{ "lef", UFLEFT | DYNAMIC }, /* left string(string, len) */
|
||||||
{ "rig", DYNAMIC }, /* right string(string, pos) */
|
{ "rig", UFRIGHT | DYNAMIC }, /* right string(string, pos) */
|
||||||
{ "mid", TRINAMIC }, /* mid string(string, pos, len) */
|
{ "mid", UFMID | TRINAMIC }, /* mid string(string, pos, len) */
|
||||||
{ "not", MONAMIC }, /* logical not */
|
{ "not", UFNOT | MONAMIC }, /* logical not */
|
||||||
{ "equ", DYNAMIC }, /* logical equality check */
|
{ "equ", UFEQUAL | DYNAMIC }, /* logical equality check */
|
||||||
{ "les", DYNAMIC }, /* logical less than */
|
{ "les", UFLESS | DYNAMIC }, /* logical less than */
|
||||||
{ "gre", DYNAMIC }, /* logical greater than */
|
{ "gre", UFGREATER | DYNAMIC }, /* logical greater than */
|
||||||
{ "seq", DYNAMIC }, /* string logical equality check */
|
{ "seq", UFSEQUAL | DYNAMIC }, /* string logical equality check */
|
||||||
{ "sle", DYNAMIC }, /* string logical less than */
|
{ "sle", UFSLESS | DYNAMIC }, /* string logical less than */
|
||||||
{ "sgr", DYNAMIC }, /* string logical greater than */
|
{ "sgr", UFSGREAT | DYNAMIC }, /* string logical greater than */
|
||||||
{ "ind", MONAMIC }, /* evaluate indirect value */
|
{ "ind", UFIND | MONAMIC }, /* evaluate indirect value */
|
||||||
{ "and", DYNAMIC }, /* logical and */
|
{ "and", UFAND | DYNAMIC }, /* logical and */
|
||||||
{ "or", DYNAMIC }, /* logical or */
|
{ "or", UFOR | DYNAMIC }, /* logical or */
|
||||||
{ "len", MONAMIC }, /* string length */
|
{ "len", UFLENGTH | MONAMIC }, /* string length */
|
||||||
{ "upp", MONAMIC }, /* uppercase string */
|
{ "upp", UFUPPER | MONAMIC }, /* uppercase string */
|
||||||
{ "low", MONAMIC }, /* lower case string */
|
{ "low", UFLOWER | MONAMIC }, /* lower case string */
|
||||||
{ "tru", MONAMIC }, /* Truth of the universe logical test */
|
{ "tru", UFTRUTH | MONAMIC }, /* Truth of the universe logical test */
|
||||||
{ "asc", MONAMIC }, /* char to integer conversion */
|
{ "asc", UFASCII | MONAMIC }, /* char to integer conversion */
|
||||||
{ "chr", MONAMIC }, /* integer to char conversion */
|
{ "chr", UFCHR | MONAMIC }, /* integer to char conversion */
|
||||||
{ "gtk", NILNAMIC }, /* get 1 charater */
|
{ "gtk", UFGTKEY | NILNAMIC }, /* get 1 charater */
|
||||||
{ "rnd", MONAMIC }, /* get a random number */
|
{ "rnd", UFRND | MONAMIC }, /* get a random number */
|
||||||
{ "abs", MONAMIC }, /* absolute value of a number */
|
{ "abs", UFABS | MONAMIC }, /* absolute value of a number */
|
||||||
{ "sin", DYNAMIC }, /* find the index of one string in another */
|
{ "sin", UFSINDEX | DYNAMIC }, /* find the index of one string in another */
|
||||||
{ "env", MONAMIC }, /* retrieve a system environment var */
|
{ "env", UFENV | MONAMIC }, /* retrieve a system environment var */
|
||||||
{ "bin", MONAMIC }, /* loopup what function name is bound to a key */
|
{ "bin", UFBIND | MONAMIC }, /* loopup what function name is bound to a key */
|
||||||
{ "exi", MONAMIC }, /* check if a file exists */
|
{ "exi", UFEXIST | MONAMIC }, /* check if a file exists */
|
||||||
{ "fin", MONAMIC }, /* look for a file on the path... */
|
{ "fin", UFFIND | MONAMIC }, /* look for a file on the path... */
|
||||||
{ "ban", DYNAMIC }, /* bitwise and 9-10-87 jwm */
|
{ "ban", UFBAND | DYNAMIC }, /* bitwise and 9-10-87 jwm */
|
||||||
{ "bor", DYNAMIC }, /* bitwise or 9-10-87 jwm */
|
{ "bor", UFBOR | DYNAMIC }, /* bitwise or 9-10-87 jwm */
|
||||||
{ "bxo", DYNAMIC }, /* bitwise xor 9-10-87 jwm */
|
{ "bxo", UFBXOR | DYNAMIC }, /* bitwise xor 9-10-87 jwm */
|
||||||
{ "bno", MONAMIC }, /* bitwise not */
|
{ "bno", UFBNOT | MONAMIC }, /* bitwise not */
|
||||||
{ "xla", TRINAMIC }, /* XLATE character string translation */
|
{ "xla", UFXLATE | TRINAMIC }, /* XLATE character string translation */
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
/* And its preprocesor definitions. */
|
|
||||||
|
|
||||||
#define UFADD 0
|
|
||||||
#define UFSUB 1
|
|
||||||
#define UFTIMES 2
|
|
||||||
#define UFDIV 3
|
|
||||||
#define UFMOD 4
|
|
||||||
#define UFNEG 5
|
|
||||||
#define UFCAT 6
|
|
||||||
#define UFLEFT 7
|
|
||||||
#define UFRIGHT 8
|
|
||||||
#define UFMID 9
|
|
||||||
#define UFNOT 10
|
|
||||||
#define UFEQUAL 11
|
|
||||||
#define UFLESS 12
|
|
||||||
#define UFGREATER 13
|
|
||||||
#define UFSEQUAL 14
|
|
||||||
#define UFSLESS 15
|
|
||||||
#define UFSGREAT 16
|
|
||||||
#define UFIND 17
|
|
||||||
#define UFAND 18
|
|
||||||
#define UFOR 19
|
|
||||||
#define UFLENGTH 20
|
|
||||||
#define UFUPPER 21
|
|
||||||
#define UFLOWER 22
|
|
||||||
#define UFTRUTH 23
|
|
||||||
#define UFASCII 24
|
|
||||||
#define UFCHR 25
|
|
||||||
#define UFGTKEY 26
|
|
||||||
#define UFRND 27
|
|
||||||
#define UFABS 28
|
|
||||||
#define UFSINDEX 29
|
|
||||||
#define UFENV 30
|
|
||||||
#define UFBIND 31
|
|
||||||
#define UFEXIST 32
|
|
||||||
#define UFFIND 33
|
|
||||||
#define UFBAND 34
|
|
||||||
#define UFBOR 35
|
|
||||||
#define UFBXOR 36
|
|
||||||
#define UFBNOT 37
|
|
||||||
#define UFXLATE 38
|
|
||||||
|
|
||||||
/* User variables */
|
/* User variables */
|
||||||
static struct user_variable uv[MAXVARS + 1];
|
static struct user_variable uv[MAXVARS + 1];
|
||||||
@ -388,30 +357,30 @@ static char *gtfun( char *fname) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* and now evaluate it! */
|
/* and now evaluate it! */
|
||||||
switch (fnum) {
|
switch( funcs[ fnum].f_type) {
|
||||||
int sz ;
|
int sz ;
|
||||||
|
|
||||||
case UFADD:
|
case UFADD | DYNAMIC:
|
||||||
retstr = i_to_a( atoi( arg1) + atoi( argx)) ;
|
retstr = i_to_a( atoi( arg1) + atoi( argx)) ;
|
||||||
break ;
|
break ;
|
||||||
case UFSUB:
|
case UFSUB | DYNAMIC:
|
||||||
retstr = i_to_a( atoi( arg1) - atoi( argx)) ;
|
retstr = i_to_a( atoi( arg1) - atoi( argx)) ;
|
||||||
break ;
|
break ;
|
||||||
case UFTIMES:
|
case UFTIMES | DYNAMIC:
|
||||||
retstr = i_to_a( atoi( arg1) * atoi( argx)) ;
|
retstr = i_to_a( atoi( arg1) * atoi( argx)) ;
|
||||||
break ;
|
break ;
|
||||||
case UFDIV:
|
case UFDIV | DYNAMIC:
|
||||||
sz = atoi( argx) ;
|
sz = atoi( argx) ;
|
||||||
retstr = (sz == 0) ? errorm : i_to_a( atoi( arg1) / sz) ;
|
retstr = (sz == 0) ? errorm : i_to_a( atoi( arg1) / sz) ;
|
||||||
break ;
|
break ;
|
||||||
case UFMOD:
|
case UFMOD | DYNAMIC:
|
||||||
sz = atoi( argx) ;
|
sz = atoi( argx) ;
|
||||||
retstr = (sz == 0) ? errorm : i_to_a( atoi( arg1) % sz) ;
|
retstr = (sz == 0) ? errorm : i_to_a( atoi( arg1) % sz) ;
|
||||||
break ;
|
break ;
|
||||||
case UFNEG:
|
case UFNEG | MONAMIC:
|
||||||
retstr = i_to_a( -atoi( argx)) ;
|
retstr = i_to_a( -atoi( argx)) ;
|
||||||
break ;
|
break ;
|
||||||
case UFCAT: {
|
case UFCAT | DYNAMIC: {
|
||||||
int sz1 ;
|
int sz1 ;
|
||||||
|
|
||||||
sz1 = strlen( arg1) ;
|
sz1 = strlen( arg1) ;
|
||||||
@ -427,7 +396,7 @@ static char *gtfun( char *fname) {
|
|||||||
retstr = result ;
|
retstr = result ;
|
||||||
}
|
}
|
||||||
break ;
|
break ;
|
||||||
case UFLEFT:
|
case UFLEFT | DYNAMIC:
|
||||||
sz = atoi( argx) ;
|
sz = atoi( argx) ;
|
||||||
if( sz >= ressize) {
|
if( sz >= ressize) {
|
||||||
free( result) ;
|
free( result) ;
|
||||||
@ -439,7 +408,7 @@ static char *gtfun( char *fname) {
|
|||||||
result[ sz] = 0 ;
|
result[ sz] = 0 ;
|
||||||
retstr = result ;
|
retstr = result ;
|
||||||
break ;
|
break ;
|
||||||
case UFRIGHT:
|
case UFRIGHT | DYNAMIC:
|
||||||
sz = atoi( argx) ;
|
sz = atoi( argx) ;
|
||||||
if( sz >= ressize) {
|
if( sz >= ressize) {
|
||||||
free( result) ;
|
free( result) ;
|
||||||
@ -449,7 +418,7 @@ static char *gtfun( char *fname) {
|
|||||||
|
|
||||||
retstr = strcpy( result, &arg1[ strlen( arg1) - sz]) ;
|
retstr = strcpy( result, &arg1[ strlen( arg1) - sz]) ;
|
||||||
break ;
|
break ;
|
||||||
case UFMID:
|
case UFMID | TRINAMIC:
|
||||||
sz = atoi( argx) ;
|
sz = atoi( argx) ;
|
||||||
if( sz >= ressize) {
|
if( sz >= ressize) {
|
||||||
free( result) ;
|
free( result) ;
|
||||||
@ -461,40 +430,48 @@ static char *gtfun( char *fname) {
|
|||||||
result[ sz] = 0 ;
|
result[ sz] = 0 ;
|
||||||
retstr = result ;
|
retstr = result ;
|
||||||
break ;
|
break ;
|
||||||
case UFNOT:
|
case UFNOT | MONAMIC:
|
||||||
retstr = ltos( stol( argx) == FALSE) ;
|
retstr = ltos( stol( argx) == FALSE) ;
|
||||||
break ;
|
break ;
|
||||||
case UFEQUAL:
|
case UFEQUAL | DYNAMIC:
|
||||||
retstr = ltos( atoi( arg1) == atoi( argx)) ;
|
retstr = ltos( atoi( arg1) == atoi( argx)) ;
|
||||||
break ;
|
break ;
|
||||||
case UFLESS:
|
case UFLESS | DYNAMIC:
|
||||||
retstr = ltos( atoi( arg1) < atoi( argx)) ;
|
retstr = ltos( atoi( arg1) < atoi( argx)) ;
|
||||||
break ;
|
break ;
|
||||||
case UFGREATER:
|
case UFGREATER | DYNAMIC:
|
||||||
retstr = ltos( atoi( arg1) > atoi( argx)) ;
|
retstr = ltos( atoi( arg1) > atoi( argx)) ;
|
||||||
break ;
|
break ;
|
||||||
case UFSEQUAL:
|
case UFSEQUAL | DYNAMIC:
|
||||||
retstr = ltos( strcmp( arg1, argx) == 0) ;
|
retstr = ltos( strcmp( arg1, argx) == 0) ;
|
||||||
break ;
|
break ;
|
||||||
case UFSLESS:
|
case UFSLESS | DYNAMIC:
|
||||||
retstr = ltos( strcmp( arg1, argx) < 0) ;
|
retstr = ltos( strcmp( arg1, argx) < 0) ;
|
||||||
break ;
|
break ;
|
||||||
case UFSGREAT:
|
case UFSGREAT | DYNAMIC:
|
||||||
retstr = ltos( strcmp( arg1, argx) > 0) ;
|
retstr = ltos( strcmp( arg1, argx) > 0) ;
|
||||||
break ;
|
break ;
|
||||||
case UFIND:
|
case UFIND | MONAMIC:
|
||||||
retstr = strcpy( result, getval( argx)) ;
|
retstr = getval( argx) ;
|
||||||
|
sz = strlen( retstr) + 1 ;
|
||||||
|
if( sz > ressize) {
|
||||||
|
free( result) ;
|
||||||
|
result = malloc( sz) ;
|
||||||
|
ressize = sz ;
|
||||||
|
}
|
||||||
|
|
||||||
|
retstr = strcpy( result, retstr) ;
|
||||||
break ;
|
break ;
|
||||||
case UFAND:
|
case UFAND | DYNAMIC:
|
||||||
retstr = ltos( stol( arg1) && stol( argx)) ;
|
retstr = ltos( stol( arg1) && stol( argx)) ;
|
||||||
break ;
|
break ;
|
||||||
case UFOR:
|
case UFOR | DYNAMIC:
|
||||||
retstr = ltos( stol( arg1) || stol( argx)) ;
|
retstr = ltos( stol( arg1) || stol( argx)) ;
|
||||||
break ;
|
break ;
|
||||||
case UFLENGTH:
|
case UFLENGTH | MONAMIC:
|
||||||
retstr = i_to_a( strlen( argx)) ;
|
retstr = i_to_a( strlen( argx)) ;
|
||||||
break ;
|
break ;
|
||||||
case UFUPPER:
|
case UFUPPER | MONAMIC:
|
||||||
sz = strlen( argx) ;
|
sz = strlen( argx) ;
|
||||||
if( sz >= ressize) {
|
if( sz >= ressize) {
|
||||||
free( result) ;
|
free( result) ;
|
||||||
@ -504,7 +481,7 @@ static char *gtfun( char *fname) {
|
|||||||
|
|
||||||
retstr = mkupper( result, argx) ;
|
retstr = mkupper( result, argx) ;
|
||||||
break ;
|
break ;
|
||||||
case UFLOWER:
|
case UFLOWER | MONAMIC:
|
||||||
sz = strlen( argx) ;
|
sz = strlen( argx) ;
|
||||||
if( sz >= ressize) {
|
if( sz >= ressize) {
|
||||||
free( result) ;
|
free( result) ;
|
||||||
@ -515,10 +492,10 @@ static char *gtfun( char *fname) {
|
|||||||
strcpy( result, argx) ; /* result is at least as long as argx */
|
strcpy( result, argx) ; /* result is at least as long as argx */
|
||||||
retstr = mklower( result) ;
|
retstr = mklower( result) ;
|
||||||
break ;
|
break ;
|
||||||
case UFTRUTH:
|
case UFTRUTH | MONAMIC:
|
||||||
retstr = ltos( atoi( argx) == 42) ;
|
retstr = ltos( atoi( argx) == 42) ;
|
||||||
break ;
|
break ;
|
||||||
case UFASCII: {
|
case UFASCII | MONAMIC: {
|
||||||
unicode_t c ;
|
unicode_t c ;
|
||||||
|
|
||||||
utf8_to_unicode( argx, 0, 4, &c) ;
|
utf8_to_unicode( argx, 0, 4, &c) ;
|
||||||
@ -526,7 +503,7 @@ static char *gtfun( char *fname) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
break ;
|
break ;
|
||||||
case UFCHR: {
|
case UFCHR | MONAMIC: {
|
||||||
unicode_t c ;
|
unicode_t c ;
|
||||||
|
|
||||||
c = atoi( argx) ;
|
c = atoi( argx) ;
|
||||||
@ -540,12 +517,12 @@ static char *gtfun( char *fname) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
break ;
|
break ;
|
||||||
case UFGTKEY:
|
case UFGTKEY | NILNAMIC:
|
||||||
result[0] = tgetc();
|
result[0] = tgetc();
|
||||||
result[1] = 0;
|
result[1] = 0;
|
||||||
retstr = result ;
|
retstr = result ;
|
||||||
break ;
|
break ;
|
||||||
case UFRND:
|
case UFRND | MONAMIC:
|
||||||
sz = abs( atoi( argx)) ;
|
sz = abs( atoi( argx)) ;
|
||||||
if( sz == 0)
|
if( sz == 0)
|
||||||
sz = ernd() ;
|
sz = ernd() ;
|
||||||
@ -554,13 +531,13 @@ static char *gtfun( char *fname) {
|
|||||||
|
|
||||||
retstr = i_to_a( sz) ;
|
retstr = i_to_a( sz) ;
|
||||||
break ;
|
break ;
|
||||||
case UFABS:
|
case UFABS | MONAMIC:
|
||||||
retstr = i_to_a( abs( atoi( argx))) ;
|
retstr = i_to_a( abs( atoi( argx))) ;
|
||||||
break ;
|
break ;
|
||||||
case UFSINDEX:
|
case UFSINDEX | DYNAMIC:
|
||||||
retstr = i_to_a( sindex( arg1, argx)) ;
|
retstr = i_to_a( sindex( arg1, argx)) ;
|
||||||
break ;
|
break ;
|
||||||
case UFENV:
|
case UFENV | MONAMIC:
|
||||||
#if ENVFUNC
|
#if ENVFUNC
|
||||||
retstr = getenv( argx) ;
|
retstr = getenv( argx) ;
|
||||||
if( retstr == NULL)
|
if( retstr == NULL)
|
||||||
@ -569,30 +546,30 @@ static char *gtfun( char *fname) {
|
|||||||
retstr = "" ;
|
retstr = "" ;
|
||||||
#endif
|
#endif
|
||||||
break ;
|
break ;
|
||||||
case UFBIND:
|
case UFBIND | MONAMIC:
|
||||||
retstr = transbind( argx) ;
|
retstr = transbind( argx) ;
|
||||||
break ;
|
break ;
|
||||||
case UFEXIST:
|
case UFEXIST | MONAMIC:
|
||||||
retstr = ltos( fexist( argx)) ;
|
retstr = ltos( fexist( argx)) ;
|
||||||
break ;
|
break ;
|
||||||
case UFFIND:
|
case UFFIND | MONAMIC:
|
||||||
retstr = flook( argx, TRUE) ;
|
retstr = flook( argx, TRUE) ;
|
||||||
if( retstr == NULL)
|
if( retstr == NULL)
|
||||||
retstr = "" ;
|
retstr = "" ;
|
||||||
break ;
|
break ;
|
||||||
case UFBAND:
|
case UFBAND | DYNAMIC:
|
||||||
retstr = i_to_a( atoi( arg1) & atoi( argx)) ;
|
retstr = i_to_a( atoi( arg1) & atoi( argx)) ;
|
||||||
break ;
|
break ;
|
||||||
case UFBOR:
|
case UFBOR | DYNAMIC:
|
||||||
retstr = i_to_a( atoi( arg1) | atoi( argx)) ;
|
retstr = i_to_a( atoi( arg1) | atoi( argx)) ;
|
||||||
break ;
|
break ;
|
||||||
case UFBXOR:
|
case UFBXOR | DYNAMIC:
|
||||||
retstr = i_to_a( atoi( arg1) ^ atoi( argx)) ;
|
retstr = i_to_a( atoi( arg1) ^ atoi( argx)) ;
|
||||||
break ;
|
break ;
|
||||||
case UFBNOT:
|
case UFBNOT | DYNAMIC:
|
||||||
retstr = i_to_a( ~atoi( argx)) ;
|
retstr = i_to_a( ~atoi( argx)) ;
|
||||||
break ;
|
break ;
|
||||||
case UFXLATE:
|
case UFXLATE | TRINAMIC:
|
||||||
retstr = xlat( arg1, arg2, argx) ;
|
retstr = xlat( arg1, arg2, argx) ;
|
||||||
break ;
|
break ;
|
||||||
default:
|
default:
|
||||||
|
Loading…
Reference in New Issue
Block a user