mirror of
https://github.com/rfivet/uemacs.git
synced 2025-01-11 10:46:59 -05:00
Refactoring gtfun(), function evaluation core.
This commit is contained in:
parent
2758464a2e
commit
18a0fbe57f
344
eval.c
344
eval.c
@ -8,7 +8,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
@ -31,8 +30,6 @@
|
|||||||
#include "version.h"
|
#include "version.h"
|
||||||
#include "window.h"
|
#include "window.h"
|
||||||
|
|
||||||
#define MAXVARS 255
|
|
||||||
|
|
||||||
/* Macro argument token types */
|
/* Macro argument token types */
|
||||||
|
|
||||||
#define TKNUL 0 /* end-of-string */
|
#define TKNUL 0 /* end-of-string */
|
||||||
@ -71,14 +68,16 @@ static int saveflag = 0 ; /* Flags, saved with the $target var */
|
|||||||
long envram = 0l ; /* # of bytes current in use by malloc */
|
long envram = 0l ; /* # of bytes current in use by malloc */
|
||||||
|
|
||||||
|
|
||||||
/* Max #chars in a var name. */
|
/* User variables ******************************************/
|
||||||
#define NVSIZE 10
|
#define MAXVARS 255
|
||||||
|
#define NVSIZE 10 /* Max #chars in a var name. */
|
||||||
|
|
||||||
/* Structure to hold user variables and their definitions. */
|
/* Structure to hold user variables and their definitions. */
|
||||||
struct user_variable {
|
static struct {
|
||||||
char u_name[NVSIZE + 1]; /* name of user variable */
|
char u_name[ NVSIZE + 1] ; /* name of user variable */
|
||||||
char *u_value; /* value (string) */
|
char *u_value ; /* value (string) */
|
||||||
};
|
} uv[ MAXVARS + 1] ;
|
||||||
|
|
||||||
|
|
||||||
static char errorm[] = "ERROR" ; /* error literal */
|
static char errorm[] = "ERROR" ; /* error literal */
|
||||||
|
|
||||||
@ -137,7 +136,7 @@ static const char *envars[] = {
|
|||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
/* And its preprocesor definitions. */
|
/* And its preprocessor definitions. */
|
||||||
|
|
||||||
#define EVFILLCOL 0
|
#define EVFILLCOL 0
|
||||||
#define EVPAGELEN 1
|
#define EVPAGELEN 1
|
||||||
@ -190,6 +189,9 @@ enum function_type {
|
|||||||
TRINAMIC = (3 << 6)
|
TRINAMIC = (3 << 6)
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
#define ARGCOUNT( ft) (ft >> 6)
|
||||||
|
#define FUNID( ft) (ft & ((1 << 6) - 1))
|
||||||
|
|
||||||
enum function_code {
|
enum function_code {
|
||||||
UFADD = 0, UFSUB, UFTIMES, UFDIV, UFMOD, UFNEG,
|
UFADD = 0, UFSUB, UFTIMES, UFDIV, UFMOD, UFNEG,
|
||||||
UFCAT, UFLEFT, UFRIGHT, UFMID, UFNOT, UFEQUAL,
|
UFCAT, UFLEFT, UFRIGHT, UFMID, UFNOT, UFEQUAL,
|
||||||
@ -204,7 +206,7 @@ enum function_code {
|
|||||||
static struct {
|
static struct {
|
||||||
const char f_name[ 4] ;
|
const char f_name[ 4] ;
|
||||||
const int f_type ;
|
const int f_type ;
|
||||||
} funcs[] = {
|
} const funcs[] = {
|
||||||
{ "abs", UFABS | MONAMIC }, /* absolute value of a number */
|
{ "abs", UFABS | MONAMIC }, /* absolute value of a number */
|
||||||
{ "add", UFADD | DYNAMIC }, /* add two numbers together */
|
{ "add", UFADD | DYNAMIC }, /* add two numbers together */
|
||||||
{ "and", UFAND | DYNAMIC }, /* logical and */
|
{ "and", UFAND | DYNAMIC }, /* logical and */
|
||||||
@ -247,20 +249,17 @@ static struct {
|
|||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
|
||||||
/* User variables */
|
|
||||||
static struct user_variable uv[MAXVARS + 1];
|
|
||||||
|
|
||||||
/* When emacs' command interpetor needs to get a variable's name,
|
/* When emacs' command interpetor needs to get a variable's name,
|
||||||
* rather than it's value, it is passed back as a variable description
|
* rather than it's value, it is passed back as a variable description
|
||||||
* structure. The v_num field is a index into the appropriate variable table.
|
* structure. The v_num field is a index into the appropriate variable table.
|
||||||
*/
|
*/
|
||||||
struct variable_description {
|
typedef struct {
|
||||||
int v_type; /* Type of variable. */
|
int v_type ; /* Type of variable. */
|
||||||
int v_num; /* Ordinal pointer to variable in list. */
|
int v_num ; /* Ordinal pointer to variable in list. */
|
||||||
};
|
} variable_description ;
|
||||||
|
|
||||||
static void findvar( char *var, struct variable_description *vd, int size) ;
|
static void findvar( char *var, variable_description *vd, int size) ;
|
||||||
static int svar( struct variable_description *var, char *value) ;
|
static int svar( variable_description *var, char *value) ;
|
||||||
static char *i_to_a( int i) ;
|
static char *i_to_a( int i) ;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -309,25 +308,22 @@ void varinit(void)
|
|||||||
seed = time( NULL) ;
|
seed = time( NULL) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Evaluate a function.
|
/* Evaluate a function.
|
||||||
*
|
*
|
||||||
* @fname: name of function to evaluate.
|
* @fname: name of function to evaluate.
|
||||||
*/
|
*/
|
||||||
static const char *gtfun( char *fname) {
|
static const char *gtfun( char *fname) {
|
||||||
unsigned fnum ; /* index to function to eval */
|
char *argv[ 3] ;
|
||||||
char *arg1 ; /* value of first argument */
|
const char *retstr ; /* return value */
|
||||||
char *arg2 ; /* value of second argument */
|
int i ;
|
||||||
char *arg3 ; /* last argument */
|
|
||||||
const char *retstr ; /* return value */
|
|
||||||
int low, high ; /* binary search indexes */
|
|
||||||
|
|
||||||
/* look the function up in the function table */
|
/* look the function up in the function table */
|
||||||
fname[3] = 0; /* only first 3 chars significant */
|
fname[ 3] = 0 ; /* only first 3 chars significant */
|
||||||
mklower(fname); /* and let it be upper or lower case */
|
mklower( fname) ; /* and let it be upper or lower case */
|
||||||
fnum = ARRAY_SIZE( funcs) ;
|
unsigned fnum = ARRAY_SIZE( funcs) ; /* index to function to eval */
|
||||||
low = 0 ;
|
int low = 0 ; /* binary search low bound */
|
||||||
high = fnum - 1 ;
|
int high = fnum - 1 ; /* binary search high bound */
|
||||||
do {
|
do {
|
||||||
int s, cur ;
|
int s, cur ;
|
||||||
|
|
||||||
@ -342,85 +338,68 @@ static const char *gtfun( char *fname) {
|
|||||||
low = cur + 1 ;
|
low = cur + 1 ;
|
||||||
} while( low <= high) ;
|
} while( low <= high) ;
|
||||||
|
|
||||||
/* return errorm on a bad reference */
|
/* return errorm on a bad reference */
|
||||||
if (fnum == ARRAY_SIZE(funcs))
|
if( fnum == ARRAY_SIZE( funcs))
|
||||||
return errorm;
|
return errorm ;
|
||||||
|
|
||||||
arg1 = arg2 = arg3 = NULL ;
|
/* fetch arguments */
|
||||||
assert( clexec == TRUE) ; /* means macarg can be replaced by gettokval */
|
assert( clexec == TRUE) ; /* means macarg can be replaced by gettokval */
|
||||||
/* if needed, retrieve the first argument */
|
int argc = ARGCOUNT( funcs[ fnum].f_type) ;
|
||||||
if (funcs[fnum].f_type >= MONAMIC) {
|
for( int i = 0 ; i < argc ; i++) {
|
||||||
arg1 = getnewtokval() ;
|
argv[ i] = getnewtokval() ;
|
||||||
if( arg1 == NULL)
|
if( argv[ i] == NULL) {
|
||||||
return errorm;
|
while( i > 0)
|
||||||
|
free( argv[ --i]) ;
|
||||||
|
|
||||||
/* if needed, retrieve the second argument */
|
return errorm ;
|
||||||
if (funcs[fnum].f_type >= DYNAMIC) {
|
|
||||||
arg2 = getnewtokval() ;
|
|
||||||
if( arg2 == NULL) {
|
|
||||||
free( arg1) ;
|
|
||||||
return errorm;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* if needed, retrieve the third argument */
|
|
||||||
if (funcs[fnum].f_type >= TRINAMIC) {
|
|
||||||
arg3 = getnewtokval() ;
|
|
||||||
if( arg3 == NULL) {
|
|
||||||
free( arg1) ;
|
|
||||||
free( arg2) ;
|
|
||||||
return errorm;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* and now evaluate it! */
|
/* and now evaluate it! */
|
||||||
switch( funcs[ fnum].f_type) {
|
switch( FUNID( funcs[ fnum].f_type)) {
|
||||||
int sz ;
|
int sz, sz1 ;
|
||||||
|
unicode_t c ;
|
||||||
|
|
||||||
case UFADD | DYNAMIC:
|
case UFADD:
|
||||||
retstr = i_to_a( atoi( arg1) + atoi( arg2)) ;
|
retstr = i_to_a( atoi( argv[ 0]) + atoi( argv[ 1])) ;
|
||||||
break ;
|
break ;
|
||||||
case UFSUB | DYNAMIC:
|
case UFSUB:
|
||||||
retstr = i_to_a( atoi( arg1) - atoi( arg2)) ;
|
retstr = i_to_a( atoi( argv[ 0]) - atoi( argv[ 1])) ;
|
||||||
break ;
|
break ;
|
||||||
case UFTIMES | DYNAMIC:
|
case UFTIMES:
|
||||||
retstr = i_to_a( atoi( arg1) * atoi( arg2)) ;
|
retstr = i_to_a( atoi( argv[ 0]) * atoi( argv[ 1])) ;
|
||||||
break ;
|
break ;
|
||||||
case UFDIV | DYNAMIC:
|
case UFDIV:
|
||||||
sz = atoi( arg2) ;
|
sz = atoi( argv[ 1]) ;
|
||||||
retstr = (sz == 0) ? errorm : i_to_a( atoi( arg1) / sz) ;
|
retstr = (sz == 0) ? errorm : i_to_a( atoi( argv[ 0]) / sz) ;
|
||||||
break ;
|
break ;
|
||||||
case UFMOD | DYNAMIC:
|
case UFMOD:
|
||||||
sz = atoi( arg2) ;
|
sz = atoi( argv[ 1]) ;
|
||||||
retstr = (sz == 0) ? errorm : i_to_a( atoi( arg1) % sz) ;
|
retstr = (sz == 0) ? errorm : i_to_a( atoi( argv[ 0]) % sz) ;
|
||||||
break ;
|
break ;
|
||||||
case UFNEG | MONAMIC:
|
case UFNEG:
|
||||||
retstr = i_to_a( -atoi( arg1)) ;
|
retstr = i_to_a( -atoi( argv[ 0])) ;
|
||||||
break ;
|
break ;
|
||||||
case UFCAT | DYNAMIC: {
|
case UFCAT:
|
||||||
int sz1 ;
|
sz1 = strlen( argv[ 0]) ;
|
||||||
|
sz = sz1 + strlen( argv[ 1]) + 1 ;
|
||||||
sz1 = strlen( arg1) ;
|
|
||||||
sz = sz1 + strlen( arg2) + 1 ;
|
|
||||||
if( sz > ressize) {
|
if( sz > ressize) {
|
||||||
free( result) ;
|
free( result) ;
|
||||||
result = malloc( sz) ;
|
result = malloc( sz) ;
|
||||||
ressize = sz ;
|
ressize = sz ;
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy( result, arg1) ;
|
strcpy( result, argv[ 0]) ;
|
||||||
strcpy( &result[ sz1], arg2) ;
|
strcpy( &result[ sz1], argv[ 1]) ;
|
||||||
retstr = result ;
|
retstr = result ;
|
||||||
}
|
|
||||||
break ;
|
break ;
|
||||||
case UFLEFT | DYNAMIC: {
|
case UFLEFT:
|
||||||
int sz1 = strlen( arg1) ;
|
sz1 = strlen( argv[ 0]) ;
|
||||||
sz = 0 ;
|
sz = 0 ;
|
||||||
for( int i = atoi( arg2) ; i > 0 ; i -= 1) {
|
for( int i = atoi( argv[ 1]) ; i > 0 ; i -= 1) {
|
||||||
unicode_t c ;
|
unicode_t c ;
|
||||||
|
|
||||||
sz += utf8_to_unicode( arg1, sz, sz1, &c) ;
|
sz += utf8_to_unicode( argv[ 0], sz, sz1, &c) ;
|
||||||
if( sz == sz1)
|
if( sz == sz1)
|
||||||
break ;
|
break ;
|
||||||
}
|
}
|
||||||
@ -431,36 +410,32 @@ static const char *gtfun( char *fname) {
|
|||||||
ressize = sz + 1 ;
|
ressize = sz + 1 ;
|
||||||
}
|
}
|
||||||
|
|
||||||
mystrscpy( result, arg1, sz + 1) ;
|
mystrscpy( result, argv[ 0], sz + 1) ;
|
||||||
retstr = result ;
|
retstr = result ;
|
||||||
}
|
|
||||||
break ;
|
break ;
|
||||||
case UFRIGHT | DYNAMIC:
|
case UFRIGHT:
|
||||||
sz = atoi( arg2) ;
|
sz = atoi( argv[ 1]) ;
|
||||||
if( sz >= ressize) {
|
if( sz >= ressize) {
|
||||||
free( result) ;
|
free( result) ;
|
||||||
result = malloc( sz + 1) ;
|
result = malloc( sz + 1) ;
|
||||||
ressize = sz + 1 ;
|
ressize = sz + 1 ;
|
||||||
}
|
}
|
||||||
|
|
||||||
retstr = strcpy( result, &arg1[ strlen( arg1) - sz]) ;
|
retstr = strcpy( result, &(argv[ 0][ strlen( argv[ 0]) - sz])) ;
|
||||||
break ;
|
break ;
|
||||||
case UFMID | TRINAMIC: {
|
case UFMID:
|
||||||
int i ;
|
sz1 = strlen( argv[ 0]) ;
|
||||||
unicode_t c ;
|
|
||||||
|
|
||||||
int sz1 = strlen( arg1) ;
|
|
||||||
int start = 0 ;
|
int start = 0 ;
|
||||||
for( i = atoi( arg2) - 1 ; i > 0 ; i -= 1) {
|
for( i = atoi( argv[ 1]) - 1 ; i > 0 ; i -= 1) {
|
||||||
start += utf8_to_unicode( arg1, start, sz1, &c) ;
|
start += utf8_to_unicode( argv[ 0], start, sz1, &c) ;
|
||||||
if( start == sz1)
|
if( start == sz1)
|
||||||
break ;
|
break ;
|
||||||
}
|
}
|
||||||
|
|
||||||
sz = start ;
|
sz = start ;
|
||||||
if( sz < sz1)
|
if( sz < sz1)
|
||||||
for( i = atoi( arg3) ; i > 0 ; i -= 1) {
|
for( i = atoi( argv[ 2]) ; i > 0 ; i -= 1) {
|
||||||
sz += utf8_to_unicode( arg1, sz, sz1, &c) ;
|
sz += utf8_to_unicode( argv[ 0], sz, sz1, &c) ;
|
||||||
if( sz == sz1)
|
if( sz == sz1)
|
||||||
break ;
|
break ;
|
||||||
}
|
}
|
||||||
@ -472,33 +447,32 @@ static const char *gtfun( char *fname) {
|
|||||||
ressize = sz + 1 ;
|
ressize = sz + 1 ;
|
||||||
}
|
}
|
||||||
|
|
||||||
mystrscpy( result, &arg1[ start], sz + 1) ;
|
mystrscpy( result, &(argv[ 0][ start]), sz + 1) ;
|
||||||
retstr = result ;
|
retstr = result ;
|
||||||
}
|
|
||||||
break ;
|
break ;
|
||||||
case UFNOT | MONAMIC:
|
case UFNOT:
|
||||||
retstr = ltos( stol( arg1) == FALSE) ;
|
retstr = ltos( stol( argv[ 0]) == FALSE) ;
|
||||||
break ;
|
break ;
|
||||||
case UFEQUAL | DYNAMIC:
|
case UFEQUAL:
|
||||||
retstr = ltos( atoi( arg1) == atoi( arg2)) ;
|
retstr = ltos( atoi( argv[ 0]) == atoi( argv[ 1])) ;
|
||||||
break ;
|
break ;
|
||||||
case UFLESS | DYNAMIC:
|
case UFLESS:
|
||||||
retstr = ltos( atoi( arg1) < atoi( arg2)) ;
|
retstr = ltos( atoi( argv[ 0]) < atoi( argv[ 1])) ;
|
||||||
break ;
|
break ;
|
||||||
case UFGREATER | DYNAMIC:
|
case UFGREATER:
|
||||||
retstr = ltos( atoi( arg1) > atoi( arg2)) ;
|
retstr = ltos( atoi( argv[ 0]) > atoi( argv[ 1])) ;
|
||||||
break ;
|
break ;
|
||||||
case UFSEQUAL | DYNAMIC:
|
case UFSEQUAL:
|
||||||
retstr = ltos( strcmp( arg1, arg2) == 0) ;
|
retstr = ltos( strcmp( argv[ 0], argv[ 1]) == 0) ;
|
||||||
break ;
|
break ;
|
||||||
case UFSLESS | DYNAMIC:
|
case UFSLESS:
|
||||||
retstr = ltos( strcmp( arg1, arg2) < 0) ;
|
retstr = ltos( strcmp( argv[ 0], argv[ 1]) < 0) ;
|
||||||
break ;
|
break ;
|
||||||
case UFSGREAT | DYNAMIC:
|
case UFSGREAT:
|
||||||
retstr = ltos( strcmp( arg1, arg2) > 0) ;
|
retstr = ltos( strcmp( argv[ 0], argv[ 1]) > 0) ;
|
||||||
break ;
|
break ;
|
||||||
case UFIND | MONAMIC:
|
case UFIND:
|
||||||
retstr = getval( arg1) ;
|
retstr = getval( argv[ 0]) ;
|
||||||
sz = strlen( retstr) + 1 ;
|
sz = strlen( retstr) + 1 ;
|
||||||
if( sz > ressize) {
|
if( sz > ressize) {
|
||||||
free( result) ;
|
free( result) ;
|
||||||
@ -508,123 +482,109 @@ static const char *gtfun( char *fname) {
|
|||||||
|
|
||||||
retstr = strcpy( result, retstr) ;
|
retstr = strcpy( result, retstr) ;
|
||||||
break ;
|
break ;
|
||||||
case UFAND | DYNAMIC:
|
case UFAND:
|
||||||
retstr = ltos( stol( arg1) && stol( arg2)) ;
|
retstr = ltos( stol( argv[ 0]) && stol( argv[ 1])) ;
|
||||||
break ;
|
break ;
|
||||||
case UFOR | DYNAMIC:
|
case UFOR:
|
||||||
retstr = ltos( stol( arg1) || stol( arg2)) ;
|
retstr = ltos( stol( argv[ 0]) || stol( argv[ 1])) ;
|
||||||
break ;
|
break ;
|
||||||
case UFLENGTH | MONAMIC:
|
case UFLENGTH:
|
||||||
retstr = i_to_a( strlen( arg1)) ;
|
retstr = i_to_a( strlen( argv[ 0])) ;
|
||||||
break ;
|
break ;
|
||||||
case UFUPPER | MONAMIC:
|
case UFUPPER:
|
||||||
sz = strlen( arg1) ;
|
sz = strlen( argv[ 0]) ;
|
||||||
if( sz >= ressize) {
|
if( sz >= ressize) {
|
||||||
free( result) ;
|
free( result) ;
|
||||||
result = malloc( sz + 1) ;
|
result = malloc( sz + 1) ;
|
||||||
ressize = sz + 1 ;
|
ressize = sz + 1 ;
|
||||||
}
|
}
|
||||||
|
|
||||||
retstr = mkupper( result, arg1) ;
|
retstr = mkupper( result, argv[ 0]) ;
|
||||||
break ;
|
break ;
|
||||||
case UFLOWER | MONAMIC:
|
case UFLOWER:
|
||||||
sz = strlen( arg1) ;
|
sz = strlen( argv[ 0]) ;
|
||||||
if( sz >= ressize) {
|
if( sz >= ressize) {
|
||||||
free( result) ;
|
free( result) ;
|
||||||
result = malloc( sz + 1) ;
|
result = malloc( sz + 1) ;
|
||||||
ressize = sz + 1 ;
|
ressize = sz + 1 ;
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy( result, arg1) ; /* result is at least as long as arg1 */
|
strcpy( result, argv[ 0]) ; /* result is at least as long as argv[ 0] */
|
||||||
retstr = mklower( result) ;
|
retstr = mklower( result) ;
|
||||||
break ;
|
break ;
|
||||||
case UFTRUTH | MONAMIC:
|
case UFTRUTH:
|
||||||
retstr = ltos( atoi( arg1) == 42) ;
|
retstr = ltos( atoi( argv[ 0]) == 42) ;
|
||||||
break ;
|
break ;
|
||||||
case UFASCII | MONAMIC: {
|
case UFASCII:
|
||||||
unicode_t c ;
|
utf8_to_unicode( argv[ 0], 0, 4, &c) ;
|
||||||
|
|
||||||
utf8_to_unicode( arg1, 0, 4, &c) ;
|
|
||||||
retstr = i_to_a( c) ;
|
retstr = i_to_a( c) ;
|
||||||
|
break ;
|
||||||
|
case UFCHR:
|
||||||
|
c = atoi( argv[ 0]) ;
|
||||||
|
if( c > 0x10FFFF)
|
||||||
|
retstr = errorm ;
|
||||||
|
else {
|
||||||
|
sz = unicode_to_utf8( c, result) ;
|
||||||
|
result[ sz] = 0 ;
|
||||||
|
retstr = result ;
|
||||||
}
|
}
|
||||||
|
|
||||||
break ;
|
break ;
|
||||||
case UFCHR | MONAMIC: {
|
case UFGTKEY:
|
||||||
unicode_t c ;
|
|
||||||
|
|
||||||
c = atoi( arg1) ;
|
|
||||||
if( c > 0x10FFFF)
|
|
||||||
retstr = errorm ;
|
|
||||||
else {
|
|
||||||
sz = unicode_to_utf8( c, result) ;
|
|
||||||
result[ sz] = 0 ;
|
|
||||||
retstr = result ;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
break ;
|
|
||||||
case UFGTKEY | NILNAMIC:
|
|
||||||
result[0] = tgetc();
|
result[0] = tgetc();
|
||||||
result[1] = 0;
|
result[1] = 0;
|
||||||
retstr = result ;
|
retstr = result ;
|
||||||
break ;
|
break ;
|
||||||
case UFRND | MONAMIC:
|
case UFRND:
|
||||||
retstr = i_to_a( ernd( atoi( arg1))) ;
|
retstr = i_to_a( ernd( atoi( argv[ 0]))) ;
|
||||||
break ;
|
break ;
|
||||||
case UFABS | MONAMIC:
|
case UFABS:
|
||||||
retstr = i_to_a( abs( atoi( arg1))) ;
|
retstr = i_to_a( abs( atoi( argv[ 0]))) ;
|
||||||
break ;
|
break ;
|
||||||
case UFSINDEX | DYNAMIC:
|
case UFSINDEX:
|
||||||
retstr = i_to_a( sindex( arg1, arg2)) ;
|
retstr = i_to_a( sindex( argv[ 0], argv[ 1])) ;
|
||||||
break ;
|
break ;
|
||||||
case UFENV | MONAMIC:
|
case UFENV:
|
||||||
#if ENVFUNC
|
#if ENVFUNC
|
||||||
retstr = getenv( arg1) ;
|
retstr = getenv( argv[ 0]) ;
|
||||||
if( retstr == NULL)
|
if( retstr == NULL)
|
||||||
retstr = "" ;
|
|
||||||
#else
|
|
||||||
retstr = "" ;
|
|
||||||
#endif
|
#endif
|
||||||
|
retstr = "" ;
|
||||||
|
|
||||||
break ;
|
break ;
|
||||||
case UFBIND | MONAMIC:
|
case UFBIND:
|
||||||
retstr = transbind( arg1) ;
|
retstr = transbind( argv[ 0]) ;
|
||||||
break ;
|
break ;
|
||||||
case UFEXIST | MONAMIC:
|
case UFEXIST:
|
||||||
retstr = ltos( fexist( arg1)) ;
|
retstr = ltos( fexist( argv[ 0])) ;
|
||||||
break ;
|
break ;
|
||||||
case UFFIND | MONAMIC:
|
case UFFIND:
|
||||||
retstr = flook( arg1, TRUE) ;
|
retstr = flook( argv[ 0], TRUE) ;
|
||||||
if( retstr == NULL)
|
if( retstr == NULL)
|
||||||
retstr = "" ;
|
retstr = "" ;
|
||||||
break ;
|
break ;
|
||||||
case UFBAND | DYNAMIC:
|
case UFBAND:
|
||||||
retstr = i_to_a( atoi( arg1) & atoi( arg2)) ;
|
retstr = i_to_a( atoi( argv[ 0]) & atoi( argv[ 1])) ;
|
||||||
break ;
|
break ;
|
||||||
case UFBOR | DYNAMIC:
|
case UFBOR:
|
||||||
retstr = i_to_a( atoi( arg1) | atoi( arg2)) ;
|
retstr = i_to_a( atoi( argv[ 0]) | atoi( argv[ 1])) ;
|
||||||
break ;
|
break ;
|
||||||
case UFBXOR | DYNAMIC:
|
case UFBXOR:
|
||||||
retstr = i_to_a( atoi( arg1) ^ atoi( arg2)) ;
|
retstr = i_to_a( atoi( argv[ 0]) ^ atoi( argv[ 1])) ;
|
||||||
break ;
|
break ;
|
||||||
case UFBNOT | MONAMIC:
|
case UFBNOT:
|
||||||
retstr = i_to_a( ~atoi( arg1)) ;
|
retstr = i_to_a( ~atoi( argv[ 0])) ;
|
||||||
break ;
|
break ;
|
||||||
case UFXLATE | TRINAMIC:
|
case UFXLATE:
|
||||||
retstr = xlat( arg1, arg2, arg3) ;
|
retstr = xlat( argv[ 0], argv[ 1], argv[ 2]) ;
|
||||||
break ;
|
break ;
|
||||||
default:
|
default:
|
||||||
assert( FALSE) ; /* never should get here */
|
assert( FALSE) ; /* never should get here */
|
||||||
retstr = errorm ;
|
retstr = errorm ;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( arg3)
|
while( argc > 0)
|
||||||
free( arg3) ;
|
free( argv[ --argc]) ;
|
||||||
|
|
||||||
if( arg2)
|
|
||||||
free( arg2) ;
|
|
||||||
|
|
||||||
if( arg1)
|
|
||||||
free( arg1) ;
|
|
||||||
|
|
||||||
return retstr ;
|
return retstr ;
|
||||||
}
|
}
|
||||||
@ -795,7 +755,7 @@ static char *gtenv( char *vname) {
|
|||||||
*/
|
*/
|
||||||
BINDABLE( setvar) {
|
BINDABLE( setvar) {
|
||||||
int status; /* status return */
|
int status; /* status return */
|
||||||
struct variable_description vd; /* variable num/type */
|
variable_description vd ; /* variable num/type */
|
||||||
char var[NVSIZE + 2]; /* name of variable to fetch %1234567890\0 */
|
char var[NVSIZE + 2]; /* name of variable to fetch %1234567890\0 */
|
||||||
char *value ; /* value to set variable to */
|
char *value ; /* value to set variable to */
|
||||||
|
|
||||||
@ -883,7 +843,7 @@ int mdbugout( char *fmt, ...) {
|
|||||||
* @vd: structure to hold type and pointer.
|
* @vd: structure to hold type and pointer.
|
||||||
* @size: size of variable array.
|
* @size: size of variable array.
|
||||||
*/
|
*/
|
||||||
static void findvar(char *var, struct variable_description *vd, int size)
|
static void findvar(char *var, variable_description *vd, int size)
|
||||||
{
|
{
|
||||||
unsigned vnum = 0 ; /* subscript in variable arrays */
|
unsigned vnum = 0 ; /* subscript in variable arrays */
|
||||||
int vtype; /* type to return */
|
int vtype; /* type to return */
|
||||||
@ -939,7 +899,7 @@ fvar:
|
|||||||
* @var: variable to set.
|
* @var: variable to set.
|
||||||
* @value: value to set to.
|
* @value: value to set to.
|
||||||
*/
|
*/
|
||||||
static int svar(struct variable_description *var, char *value)
|
static int svar( variable_description *var, char *value)
|
||||||
{
|
{
|
||||||
int vnum; /* ordinal number of var refrenced */
|
int vnum; /* ordinal number of var refrenced */
|
||||||
int vtype; /* type of variable to set */
|
int vtype; /* type of variable to set */
|
||||||
|
Loading…
Reference in New Issue
Block a user