mirror of
https://github.com/rfivet/uemacs.git
synced 2024-12-18 07:16:23 -05:00
Clean up eval: local scope for gtfun, gtenv, gtusr. Review initial allocation of result buffer returned by gtfun.
This commit is contained in:
parent
57e5338ebd
commit
3ce31669ae
36
eval.c
36
eval.c
@ -294,12 +294,20 @@ static int putctext( char *iline)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static char *result ; /* string result */
|
||||||
|
static int ressize = 0 ; /* mark result as uninitialized */
|
||||||
|
|
||||||
/* Initialize the user variable list. */
|
/* Initialize the user variable list. */
|
||||||
void varinit(void)
|
void varinit(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < MAXVARS; i++)
|
for (i = 0; i < MAXVARS; i++)
|
||||||
uv[i].u_name[0] = 0;
|
uv[i].u_name[0] = 0;
|
||||||
|
|
||||||
|
if( ressize == 0) {
|
||||||
|
result = malloc( NSTRING) ;
|
||||||
|
ressize = NSTRING ;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -307,14 +315,11 @@ void varinit(void)
|
|||||||
*
|
*
|
||||||
* @fname: name of function to evaluate.
|
* @fname: name of function to evaluate.
|
||||||
*/
|
*/
|
||||||
char *gtfun(char *fname)
|
static char *gtfun( char *fname) {
|
||||||
{
|
int fnum ; /* index to function to eval */
|
||||||
int fnum; /* index to function to eval */
|
char argx[ 512] ; /* last argument, fixed sized allocation */
|
||||||
char argx[ 512] ;
|
|
||||||
char *arg1 ; /* value of first argument */
|
char *arg1 ; /* value of first argument */
|
||||||
char *arg2 ; /* value of second argument */
|
char *arg2 ; /* value of second argument */
|
||||||
static char *result ; /* string result */
|
|
||||||
static int ressize = 0 ; /* mark result as uninitialized */
|
|
||||||
char *retstr ; /* return value */
|
char *retstr ; /* return value */
|
||||||
|
|
||||||
/* look the function up in the function table */
|
/* look the function up in the function table */
|
||||||
@ -357,12 +362,6 @@ char *gtfun(char *fname)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if( ressize == 0) {
|
|
||||||
result = malloc( NSTRING) ;
|
|
||||||
ressize = NSTRING ;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* and now evaluate it! */
|
/* and now evaluate it! */
|
||||||
switch (fnum) {
|
switch (fnum) {
|
||||||
int sz ;
|
int sz ;
|
||||||
@ -554,12 +553,12 @@ char *gtfun(char *fname)
|
|||||||
exit(-11); /* never should get here */
|
exit(-11); /* never should get here */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( arg2)
|
||||||
|
free( arg2) ;
|
||||||
|
|
||||||
if( arg1)
|
if( arg1)
|
||||||
free( arg1) ;
|
free( arg1) ;
|
||||||
|
|
||||||
if( arg2)
|
|
||||||
free( arg2) ;
|
|
||||||
|
|
||||||
return retstr ;
|
return retstr ;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -568,9 +567,7 @@ char *gtfun(char *fname)
|
|||||||
*
|
*
|
||||||
* char *vname; name of user variable to fetch
|
* char *vname; name of user variable to fetch
|
||||||
*/
|
*/
|
||||||
char *gtusr(char *vname)
|
static char *gtusr( char *vname) {
|
||||||
{
|
|
||||||
|
|
||||||
int vnum; /* ordinal number of user var */
|
int vnum; /* ordinal number of user var */
|
||||||
|
|
||||||
/* scan the list looking for the user var name */
|
/* scan the list looking for the user var name */
|
||||||
@ -590,8 +587,7 @@ char *gtusr(char *vname)
|
|||||||
*
|
*
|
||||||
* char *vname; name of environment variable to retrieve
|
* char *vname; name of environment variable to retrieve
|
||||||
*/
|
*/
|
||||||
char *gtenv(char *vname)
|
static char *gtenv( char *vname) {
|
||||||
{
|
|
||||||
int vnum; /* ordinal number of var refrenced */
|
int vnum; /* ordinal number of var refrenced */
|
||||||
|
|
||||||
/* scan the list, looking for the referenced name */
|
/* scan the list, looking for the referenced name */
|
||||||
|
3
eval.h
3
eval.h
@ -39,9 +39,6 @@ extern long envram ; /* # of bytes current in use by malloc */
|
|||||||
int gettyp( char *token) ;
|
int gettyp( char *token) ;
|
||||||
|
|
||||||
void varinit( void) ;
|
void varinit( void) ;
|
||||||
char *gtfun( char *fname) ;
|
|
||||||
char *gtusr( char *vname) ;
|
|
||||||
char *gtenv( char *vname) ;
|
|
||||||
int setvar( int f, int n) ;
|
int setvar( int f, int n) ;
|
||||||
char *i_to_a( int i) ;
|
char *i_to_a( int i) ;
|
||||||
char *getval( char *token) ;
|
char *getval( char *token) ;
|
||||||
|
Loading…
Reference in New Issue
Block a user