1
0
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:
Renaud 2015-01-09 15:35:03 +08:00
parent 57e5338ebd
commit 3ce31669ae
2 changed files with 16 additions and 23 deletions

36
eval.c
View File

@ -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. */
void varinit(void)
{
int i;
for (i = 0; i < MAXVARS; i++)
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.
*/
char *gtfun(char *fname)
{
int fnum; /* index to function to eval */
char argx[ 512] ;
static char *gtfun( char *fname) {
int fnum ; /* index to function to eval */
char argx[ 512] ; /* last argument, fixed sized allocation */
char *arg1 ; /* value of first argument */
char *arg2 ; /* value of second argument */
static char *result ; /* string result */
static int ressize = 0 ; /* mark result as uninitialized */
char *retstr ; /* return value */
/* 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! */
switch (fnum) {
int sz ;
@ -554,12 +553,12 @@ char *gtfun(char *fname)
exit(-11); /* never should get here */
}
if( arg2)
free( arg2) ;
if( arg1)
free( arg1) ;
if( arg2)
free( arg2) ;
return retstr ;
}
@ -568,9 +567,7 @@ char *gtfun(char *fname)
*
* char *vname; name of user variable to fetch
*/
char *gtusr(char *vname)
{
static char *gtusr( char *vname) {
int vnum; /* ordinal number of user var */
/* 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 *gtenv(char *vname)
{
static char *gtenv( char *vname) {
int vnum; /* ordinal number of var refrenced */
/* scan the list, looking for the referenced name */

3
eval.h
View File

@ -39,9 +39,6 @@ extern long envram ; /* # of bytes current in use by malloc */
int gettyp( char *token) ;
void varinit( void) ;
char *gtfun( char *fname) ;
char *gtusr( char *vname) ;
char *gtenv( char *vname) ;
int setvar( int f, int n) ;
char *i_to_a( int i) ;
char *getval( char *token) ;