dos2unix
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@6242 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
797d7c5701
commit
89ecc93992
|
@ -1,161 +1,161 @@
|
||||||
/* A conio implementation for Mingw/Dev-C++.
|
/* A conio implementation for Mingw/Dev-C++.
|
||||||
*
|
*
|
||||||
* Written by:
|
* Written by:
|
||||||
* Hongli Lai <hongli@telekabel.nl>
|
* Hongli Lai <hongli@telekabel.nl>
|
||||||
* tkorrovi <tkorrovi@altavista.net> on 2002/02/26.
|
* tkorrovi <tkorrovi@altavista.net> on 2002/02/26.
|
||||||
* Andrew Westcott <ajwestco@users.sourceforge.net>
|
* Andrew Westcott <ajwestco@users.sourceforge.net>
|
||||||
*
|
*
|
||||||
* Offered for use in the public domain without any warranty.
|
* Offered for use in the public domain without any warranty.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _CONIO_H_
|
#ifndef _CONIO_H_
|
||||||
#define _CONIO_H_
|
#define _CONIO_H_
|
||||||
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define BLINK 0
|
#define BLINK 0
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
BLACK,
|
BLACK,
|
||||||
BLUE,
|
BLUE,
|
||||||
GREEN,
|
GREEN,
|
||||||
CYAN,
|
CYAN,
|
||||||
RED,
|
RED,
|
||||||
MAGENTA,
|
MAGENTA,
|
||||||
BROWN,
|
BROWN,
|
||||||
LIGHTGRAY,
|
LIGHTGRAY,
|
||||||
DARKGRAY,
|
DARKGRAY,
|
||||||
LIGHTBLUE,
|
LIGHTBLUE,
|
||||||
LIGHTGREEN,
|
LIGHTGREEN,
|
||||||
LIGHTCYAN,
|
LIGHTCYAN,
|
||||||
LIGHTRED,
|
LIGHTRED,
|
||||||
LIGHTMAGENTA,
|
LIGHTMAGENTA,
|
||||||
YELLOW,
|
YELLOW,
|
||||||
WHITE
|
WHITE
|
||||||
} COLORS;
|
} COLORS;
|
||||||
|
|
||||||
|
|
||||||
#define cgets _cgets
|
#define cgets _cgets
|
||||||
#define cprintf _cprintf
|
#define cprintf _cprintf
|
||||||
#define cputs _cputs
|
#define cputs _cputs
|
||||||
#define cscanf _cscanf
|
#define cscanf _cscanf
|
||||||
#define ScreenClear clrscr
|
#define ScreenClear clrscr
|
||||||
|
|
||||||
/* blinkvideo */
|
/* blinkvideo */
|
||||||
|
|
||||||
void clreol (void);
|
void clreol (void);
|
||||||
void clrscr (void);
|
void clrscr (void);
|
||||||
|
|
||||||
int _conio_gettext (int left, int top, int right, int bottom,
|
int _conio_gettext (int left, int top, int right, int bottom,
|
||||||
char *str);
|
char *str);
|
||||||
/* _conio_kbhit */
|
/* _conio_kbhit */
|
||||||
|
|
||||||
void delline (void);
|
void delline (void);
|
||||||
|
|
||||||
/* gettextinfo */
|
/* gettextinfo */
|
||||||
void gotoxy(int x, int y);
|
void gotoxy(int x, int y);
|
||||||
/*
|
/*
|
||||||
highvideo
|
highvideo
|
||||||
insline
|
insline
|
||||||
intensevideo
|
intensevideo
|
||||||
lowvideo
|
lowvideo
|
||||||
movetext
|
movetext
|
||||||
normvideo
|
normvideo
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void gotoxy(int x, int y);
|
void gotoxy(int x, int y);
|
||||||
|
|
||||||
void puttext (int left, int top, int right, int bottom, char *str);
|
void puttext (int left, int top, int right, int bottom, char *str);
|
||||||
|
|
||||||
// Screen Variables
|
// Screen Variables
|
||||||
|
|
||||||
/* ScreenCols
|
/* ScreenCols
|
||||||
ScreenGetChar
|
ScreenGetChar
|
||||||
ScreenGetCursor
|
ScreenGetCursor
|
||||||
ScreenMode
|
ScreenMode
|
||||||
ScreenPutChar
|
ScreenPutChar
|
||||||
ScreenPutString
|
ScreenPutString
|
||||||
ScreenRetrieve
|
ScreenRetrieve
|
||||||
ScreenRows
|
ScreenRows
|
||||||
ScreenSetCursor
|
ScreenSetCursor
|
||||||
ScreenUpdate
|
ScreenUpdate
|
||||||
ScreenUpdateLine
|
ScreenUpdateLine
|
||||||
ScreenVisualBell
|
ScreenVisualBell
|
||||||
_set_screen_lines */
|
_set_screen_lines */
|
||||||
|
|
||||||
void _setcursortype (int type);
|
void _setcursortype (int type);
|
||||||
|
|
||||||
void textattr (int _attr);
|
void textattr (int _attr);
|
||||||
|
|
||||||
void textbackground (int color);
|
void textbackground (int color);
|
||||||
|
|
||||||
void textcolor (int color);
|
void textcolor (int color);
|
||||||
|
|
||||||
/* textmode */
|
/* textmode */
|
||||||
|
|
||||||
int wherex (void);
|
int wherex (void);
|
||||||
|
|
||||||
int wherey (void);
|
int wherey (void);
|
||||||
|
|
||||||
/* window */
|
/* window */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* The code below was part of Mingw's conio.h */
|
/* The code below was part of Mingw's conio.h */
|
||||||
/*
|
/*
|
||||||
* conio.h
|
* conio.h
|
||||||
*
|
*
|
||||||
* Low level console I/O functions. Pretty please try to use the ANSI
|
* Low level console I/O functions. Pretty please try to use the ANSI
|
||||||
* standard ones if you are writing new code.
|
* standard ones if you are writing new code.
|
||||||
*
|
*
|
||||||
* This file is part of the Mingw32 package.
|
* This file is part of the Mingw32 package.
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Created by Colin Peters <colin@bird.fu.is.saga-u.ac.jp>
|
* Created by Colin Peters <colin@bird.fu.is.saga-u.ac.jp>
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS NOT COPYRIGHTED
|
* THIS SOFTWARE IS NOT COPYRIGHTED
|
||||||
*
|
*
|
||||||
* This source code is offered for use in the public domain. You may
|
* This source code is offered for use in the public domain. You may
|
||||||
* use, modify or distribute it freely.
|
* use, modify or distribute it freely.
|
||||||
*
|
*
|
||||||
* This code is distributed in the hope that it will be useful but
|
* This code is distributed in the hope that it will be useful but
|
||||||
* WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
|
* WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
|
||||||
* DISCLAMED. This includes but is not limited to warranties of
|
* DISCLAMED. This includes but is not limited to warranties of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
*
|
*
|
||||||
* $Revision: 1.4 $
|
* $Revision: 1.4 $
|
||||||
* $Author: hongli $
|
* $Author: hongli $
|
||||||
* $Date: 2002/04/26 19:31:25 $
|
* $Date: 2002/04/26 19:31:25 $
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
char* _cgets (char*);
|
char* _cgets (char*);
|
||||||
int _cprintf (const char*, ...);
|
int _cprintf (const char*, ...);
|
||||||
int _cputs (const char*);
|
int _cputs (const char*);
|
||||||
int _cscanf (char*, ...);
|
int _cscanf (char*, ...);
|
||||||
|
|
||||||
int _getch (void);
|
int _getch (void);
|
||||||
int _getche (void);
|
int _getche (void);
|
||||||
int _kbhit (void);
|
int _kbhit (void);
|
||||||
int _putch (int);
|
int _putch (int);
|
||||||
int _ungetch (int);
|
int _ungetch (int);
|
||||||
|
|
||||||
|
|
||||||
int getch (void);
|
int getch (void);
|
||||||
int getche (void);
|
int getche (void);
|
||||||
int kbhit (void);
|
int kbhit (void);
|
||||||
int putch (int);
|
int putch (int);
|
||||||
int ungetch (int);
|
int ungetch (int);
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* _CONIO_H_ */
|
#endif /* _CONIO_H_ */
|
||||||
|
|
|
@ -1,29 +1,29 @@
|
||||||
/*
|
/*
|
||||||
File: exprconf.h
|
File: exprconf.h
|
||||||
Auth: Brian Allen Vanderburg II
|
Auth: Brian Allen Vanderburg II
|
||||||
Date: Thursday, October 20, 2005
|
Date: Thursday, October 20, 2005
|
||||||
Desc: Configuration for ExprEval
|
Desc: Configuration for ExprEval
|
||||||
|
|
||||||
This file is part of ExprEval.
|
This file is part of ExprEval.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __BAVII_EXPRCONF_H
|
#ifndef __BAVII_EXPRCONF_H
|
||||||
#define __BAVII_EXPRCONF_H
|
#define __BAVII_EXPRCONF_H
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Error checking level
|
Error checking level
|
||||||
|
|
||||||
0: Don't check any errors (don't use errno). Divide by 0
|
0: Don't check any errors (don't use errno). Divide by 0
|
||||||
is avoided and the part that divides by 0 is 0. For example
|
is avoided and the part that divides by 0 is 0. For example
|
||||||
'4+1/0' is 4.
|
'4+1/0' is 4.
|
||||||
|
|
||||||
1: Check math errors.
|
1: Check math errors.
|
||||||
*/
|
*/
|
||||||
#define EXPR_ERROR_LEVEL_NONE 0
|
#define EXPR_ERROR_LEVEL_NONE 0
|
||||||
#define EXPR_ERROR_LEVEL_CHECK 1
|
#define EXPR_ERROR_LEVEL_CHECK 1
|
||||||
|
|
||||||
#ifndef EXPR_ERROR_LEVEL
|
#ifndef EXPR_ERROR_LEVEL
|
||||||
#define EXPR_ERROR_LEVEL EXPR_ERROR_LEVEL_CHECK
|
#define EXPR_ERROR_LEVEL EXPR_ERROR_LEVEL_CHECK
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* __BAVII_EXPRCONF_H */
|
#endif /* __BAVII_EXPRCONF_H */
|
||||||
|
|
|
@ -1,268 +1,268 @@
|
||||||
/*
|
/*
|
||||||
File: expreval.c
|
File: expreval.c
|
||||||
Auth: Brian Allen Vanderburg II
|
Auth: Brian Allen Vanderburg II
|
||||||
Date: Wednesday, April 30, 2003
|
Date: Wednesday, April 30, 2003
|
||||||
Desc: Evaluation routines for the ExprEval library
|
Desc: Evaluation routines for the ExprEval library
|
||||||
|
|
||||||
This file is part of ExprEval.
|
This file is part of ExprEval.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Includes */
|
/* Includes */
|
||||||
#include "exprincl.h"
|
#include "exprincl.h"
|
||||||
|
|
||||||
#include "exprpriv.h"
|
#include "exprpriv.h"
|
||||||
|
|
||||||
/* Defines for error checking */
|
/* Defines for error checking */
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#if(EXPR_ERROR_LEVEL >= EXPR_ERROR_LEVEL_CHECK)
|
#if(EXPR_ERROR_LEVEL >= EXPR_ERROR_LEVEL_CHECK)
|
||||||
#define EXPR_RESET_ERR() errno = 0
|
#define EXPR_RESET_ERR() errno = 0
|
||||||
#define EXPR_CHECK_ERR() if(errno) return EXPR_ERROR_OUTOFRANGE
|
#define EXPR_CHECK_ERR() if(errno) return EXPR_ERROR_OUTOFRANGE
|
||||||
#else
|
#else
|
||||||
#define EXPR_RESET_ERR()
|
#define EXPR_RESET_ERR()
|
||||||
#define EXPR_CHECK_ERR()
|
#define EXPR_CHECK_ERR()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* This routine will evaluate an expression */
|
/* This routine will evaluate an expression */
|
||||||
int exprEval(exprObj *obj, EXPRTYPE *val)
|
int exprEval(exprObj *obj, EXPRTYPE *val)
|
||||||
{
|
{
|
||||||
EXPRTYPE dummy;
|
EXPRTYPE dummy;
|
||||||
|
|
||||||
if(val == NULL)
|
if(val == NULL)
|
||||||
val = &dummy;
|
val = &dummy;
|
||||||
|
|
||||||
/* Make sure it was parsed successfully */
|
/* Make sure it was parsed successfully */
|
||||||
if(!obj->parsedbad && obj->parsedgood && obj->headnode)
|
if(!obj->parsedbad && obj->parsedgood && obj->headnode)
|
||||||
{
|
{
|
||||||
/* Do NOT reset the break count. Let is accumulate
|
/* Do NOT reset the break count. Let is accumulate
|
||||||
between calls until breaker function is called */
|
between calls until breaker function is called */
|
||||||
return exprEvalNode(obj, obj->headnode, 0, val);
|
return exprEvalNode(obj, obj->headnode, 0, val);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return EXPR_ERROR_BADEXPR;
|
return EXPR_ERROR_BADEXPR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Evaluate a node */
|
/* Evaluate a node */
|
||||||
int exprEvalNode(exprObj *obj, exprNode *nodes, int curnode, EXPRTYPE *val)
|
int exprEvalNode(exprObj *obj, exprNode *nodes, int curnode, EXPRTYPE *val)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
int pos;
|
int pos;
|
||||||
EXPRTYPE d1, d2;
|
EXPRTYPE d1, d2;
|
||||||
|
|
||||||
if(obj == NULL || nodes == NULL)
|
if(obj == NULL || nodes == NULL)
|
||||||
return EXPR_ERROR_NULLPOINTER;
|
return EXPR_ERROR_NULLPOINTER;
|
||||||
|
|
||||||
/* Update n to point to correct node */
|
/* Update n to point to correct node */
|
||||||
nodes += curnode;
|
nodes += curnode;
|
||||||
|
|
||||||
/* Check breaker count */
|
/* Check breaker count */
|
||||||
if(obj->breakcur-- <= 0)
|
if(obj->breakcur-- <= 0)
|
||||||
{
|
{
|
||||||
/* Reset count before returning */
|
/* Reset count before returning */
|
||||||
obj->breakcur = obj->breakcount;
|
obj->breakcur = obj->breakcount;
|
||||||
|
|
||||||
if(exprGetBreakResult(obj))
|
if(exprGetBreakResult(obj))
|
||||||
{
|
{
|
||||||
return EXPR_ERROR_BREAK;
|
return EXPR_ERROR_BREAK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(nodes->type)
|
switch(nodes->type)
|
||||||
{
|
{
|
||||||
case EXPR_NODETYPE_MULTI:
|
case EXPR_NODETYPE_MULTI:
|
||||||
{
|
{
|
||||||
/* Multi for multiple expressions in one string */
|
/* Multi for multiple expressions in one string */
|
||||||
for(pos = 0; pos < nodes->data.oper.nodecount; pos++)
|
for(pos = 0; pos < nodes->data.oper.nodecount; pos++)
|
||||||
{
|
{
|
||||||
err = exprEvalNode(obj, nodes->data.oper.nodes, pos, val);
|
err = exprEvalNode(obj, nodes->data.oper.nodes, pos, val);
|
||||||
if(err)
|
if(err)
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case EXPR_NODETYPE_ADD:
|
case EXPR_NODETYPE_ADD:
|
||||||
{
|
{
|
||||||
/* Addition */
|
/* Addition */
|
||||||
err = exprEvalNode(obj, nodes->data.oper.nodes, 0, &d1);
|
err = exprEvalNode(obj, nodes->data.oper.nodes, 0, &d1);
|
||||||
|
|
||||||
if(!err)
|
if(!err)
|
||||||
err = exprEvalNode(obj, nodes->data.oper.nodes, 1, &d2);
|
err = exprEvalNode(obj, nodes->data.oper.nodes, 1, &d2);
|
||||||
|
|
||||||
if(!err)
|
if(!err)
|
||||||
*val = d1 + d2;
|
*val = d1 + d2;
|
||||||
else
|
else
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case EXPR_NODETYPE_SUBTRACT:
|
case EXPR_NODETYPE_SUBTRACT:
|
||||||
{
|
{
|
||||||
/* Subtraction */
|
/* Subtraction */
|
||||||
err = exprEvalNode(obj, nodes->data.oper.nodes, 0, &d1);
|
err = exprEvalNode(obj, nodes->data.oper.nodes, 0, &d1);
|
||||||
|
|
||||||
if(!err)
|
if(!err)
|
||||||
err = exprEvalNode(obj, nodes->data.oper.nodes, 1, &d2);
|
err = exprEvalNode(obj, nodes->data.oper.nodes, 1, &d2);
|
||||||
|
|
||||||
if(!err)
|
if(!err)
|
||||||
*val = d1 - d2;
|
*val = d1 - d2;
|
||||||
else
|
else
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case EXPR_NODETYPE_MULTIPLY:
|
case EXPR_NODETYPE_MULTIPLY:
|
||||||
{
|
{
|
||||||
/* Multiplication */
|
/* Multiplication */
|
||||||
err = exprEvalNode(obj, nodes->data.oper.nodes, 0, &d1);
|
err = exprEvalNode(obj, nodes->data.oper.nodes, 0, &d1);
|
||||||
|
|
||||||
if(!err)
|
if(!err)
|
||||||
err = exprEvalNode(obj, nodes->data.oper.nodes, 1, &d2);
|
err = exprEvalNode(obj, nodes->data.oper.nodes, 1, &d2);
|
||||||
|
|
||||||
if(!err)
|
if(!err)
|
||||||
*val = d1 * d2;
|
*val = d1 * d2;
|
||||||
else
|
else
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case EXPR_NODETYPE_DIVIDE:
|
case EXPR_NODETYPE_DIVIDE:
|
||||||
{
|
{
|
||||||
/* Division */
|
/* Division */
|
||||||
err = exprEvalNode(obj, nodes->data.oper.nodes, 0, &d1);
|
err = exprEvalNode(obj, nodes->data.oper.nodes, 0, &d1);
|
||||||
|
|
||||||
if(!err)
|
if(!err)
|
||||||
err = exprEvalNode(obj, nodes->data.oper.nodes, 1, &d2);
|
err = exprEvalNode(obj, nodes->data.oper.nodes, 1, &d2);
|
||||||
|
|
||||||
if(!err)
|
if(!err)
|
||||||
{
|
{
|
||||||
if(d2 != 0.0)
|
if(d2 != 0.0)
|
||||||
*val = d1 / d2;
|
*val = d1 / d2;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#if(EXPR_ERROR_LEVEL >= EXPR_ERROR_LEVEL_CHECK)
|
#if(EXPR_ERROR_LEVEL >= EXPR_ERROR_LEVEL_CHECK)
|
||||||
return EXPR_ERROR_DIVBYZERO;
|
return EXPR_ERROR_DIVBYZERO;
|
||||||
#else
|
#else
|
||||||
*val = 0.0;
|
*val = 0.0;
|
||||||
return EXPR_ERROR_NOERROR;
|
return EXPR_ERROR_NOERROR;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case EXPR_NODETYPE_EXPONENT:
|
case EXPR_NODETYPE_EXPONENT:
|
||||||
{
|
{
|
||||||
/* Exponent */
|
/* Exponent */
|
||||||
err = exprEvalNode(obj, nodes->data.oper.nodes, 0, &d1);
|
err = exprEvalNode(obj, nodes->data.oper.nodes, 0, &d1);
|
||||||
|
|
||||||
if(!err)
|
if(!err)
|
||||||
err = exprEvalNode(obj, nodes->data.oper.nodes, 1, &d2);
|
err = exprEvalNode(obj, nodes->data.oper.nodes, 1, &d2);
|
||||||
|
|
||||||
if(!err)
|
if(!err)
|
||||||
{
|
{
|
||||||
EXPR_RESET_ERR();
|
EXPR_RESET_ERR();
|
||||||
*val = pow(d1, d2);
|
*val = pow(d1, d2);
|
||||||
EXPR_CHECK_ERR();
|
EXPR_CHECK_ERR();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case EXPR_NODETYPE_NEGATE:
|
case EXPR_NODETYPE_NEGATE:
|
||||||
{
|
{
|
||||||
/* Negative value */
|
/* Negative value */
|
||||||
err = exprEvalNode(obj, nodes->data.oper.nodes, 0, &d1);
|
err = exprEvalNode(obj, nodes->data.oper.nodes, 0, &d1);
|
||||||
|
|
||||||
if(!err)
|
if(!err)
|
||||||
*val = -d1;
|
*val = -d1;
|
||||||
else
|
else
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
case EXPR_NODETYPE_VALUE:
|
case EXPR_NODETYPE_VALUE:
|
||||||
{
|
{
|
||||||
/* Directly access the value */
|
/* Directly access the value */
|
||||||
*val = nodes->data.value.value;
|
*val = nodes->data.value.value;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case EXPR_NODETYPE_VARIABLE:
|
case EXPR_NODETYPE_VARIABLE:
|
||||||
{
|
{
|
||||||
/* Directly access the variable or constant */
|
/* Directly access the variable or constant */
|
||||||
*val = *(nodes->data.variable.vaddr);
|
*val = *(nodes->data.variable.vaddr);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case EXPR_NODETYPE_ASSIGN:
|
case EXPR_NODETYPE_ASSIGN:
|
||||||
{
|
{
|
||||||
/* Evaluate assignment subnode */
|
/* Evaluate assignment subnode */
|
||||||
err = exprEvalNode(obj, nodes->data.assign.node, 0, val);
|
err = exprEvalNode(obj, nodes->data.assign.node, 0, val);
|
||||||
|
|
||||||
if(!err)
|
if(!err)
|
||||||
{
|
{
|
||||||
/* Directly assign the variable */
|
/* Directly assign the variable */
|
||||||
*(nodes->data.assign.vaddr) = *val;
|
*(nodes->data.assign.vaddr) = *val;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case EXPR_NODETYPE_FUNCTION:
|
case EXPR_NODETYPE_FUNCTION:
|
||||||
{
|
{
|
||||||
/* Evaluate the function */
|
/* Evaluate the function */
|
||||||
if(nodes->data.function.fptr == NULL)
|
if(nodes->data.function.fptr == NULL)
|
||||||
{
|
{
|
||||||
/* No function pointer means we are not using
|
/* No function pointer means we are not using
|
||||||
function solvers. See if the function has a
|
function solvers. See if the function has a
|
||||||
type to solve directly. */
|
type to solve directly. */
|
||||||
switch(nodes->data.function.type)
|
switch(nodes->data.function.type)
|
||||||
{
|
{
|
||||||
/* This is to keep the file from being too crowded.
|
/* This is to keep the file from being too crowded.
|
||||||
See exprilfs.h for the definitions. */
|
See exprilfs.h for the definitions. */
|
||||||
#include "exprilfs.h"
|
#include "exprilfs.h"
|
||||||
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
return EXPR_ERROR_UNKNOWN;
|
return EXPR_ERROR_UNKNOWN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Call the correct function */
|
/* Call the correct function */
|
||||||
return (*(nodes->data.function.fptr))(obj,
|
return (*(nodes->data.function.fptr))(obj,
|
||||||
nodes->data.function.nodes, nodes->data.function.nodecount,
|
nodes->data.function.nodes, nodes->data.function.nodecount,
|
||||||
nodes->data.function.refs, nodes->data.function.refcount, val);
|
nodes->data.function.refs, nodes->data.function.refcount, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
/* Unknown node type */
|
/* Unknown node type */
|
||||||
return EXPR_ERROR_UNKNOWN;
|
return EXPR_ERROR_UNKNOWN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return EXPR_ERROR_NOERROR;
|
return EXPR_ERROR_NOERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,127 +1,127 @@
|
||||||
/*
|
/*
|
||||||
File: expreval.h
|
File: expreval.h
|
||||||
Auth: Brian Allen Vanderburg II
|
Auth: Brian Allen Vanderburg II
|
||||||
Date: Thursday, April 24, 2003
|
Date: Thursday, April 24, 2003
|
||||||
Desc: Main include file for ExprEval library
|
Desc: Main include file for ExprEval library
|
||||||
|
|
||||||
This file is part of ExprEval.
|
This file is part of ExprEval.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/* Include once */
|
/* Include once */
|
||||||
#ifndef __BAVII_EXPREVAL_H
|
#ifndef __BAVII_EXPREVAL_H
|
||||||
#define __BAVII_EXPREVAL_H
|
#define __BAVII_EXPREVAL_H
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* Define type of data to use */
|
/* Define type of data to use */
|
||||||
typedef double EXPRTYPE;
|
typedef double EXPRTYPE;
|
||||||
|
|
||||||
/* Defines for various things */
|
/* Defines for various things */
|
||||||
|
|
||||||
/* Max id size */
|
/* Max id size */
|
||||||
#define EXPR_MAXIDENTSIZE 255
|
#define EXPR_MAXIDENTSIZE 255
|
||||||
|
|
||||||
/* Error values */
|
/* Error values */
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
EXPR_ERROR_UNKNOWN = -1, /* Unknown error */
|
EXPR_ERROR_UNKNOWN = -1, /* Unknown error */
|
||||||
EXPR_ERROR_NOERROR = 0, /* No Error */
|
EXPR_ERROR_NOERROR = 0, /* No Error */
|
||||||
EXPR_ERROR_MEMORY, /* Memory allocation failed */
|
EXPR_ERROR_MEMORY, /* Memory allocation failed */
|
||||||
EXPR_ERROR_NULLPOINTER, /* Null pointer passed to function */
|
EXPR_ERROR_NULLPOINTER, /* Null pointer passed to function */
|
||||||
EXPR_ERROR_NOTFOUND, /* Item not found in a list */
|
EXPR_ERROR_NOTFOUND, /* Item not found in a list */
|
||||||
EXPR_ERROR_UNMATCHEDCOMMENT, /* Unmatched comment tags */
|
EXPR_ERROR_UNMATCHEDCOMMENT, /* Unmatched comment tags */
|
||||||
EXPR_ERROR_INVALIDCHAR, /* Invalid characters in expression */
|
EXPR_ERROR_INVALIDCHAR, /* Invalid characters in expression */
|
||||||
EXPR_ERROR_ALREADYEXISTS, /* An item already called create */
|
EXPR_ERROR_ALREADYEXISTS, /* An item already called create */
|
||||||
EXPR_ERROR_ALREADYPARSEDBAD, /* Expression parsed already, but unsuccessfully. call free or clear */
|
EXPR_ERROR_ALREADYPARSEDBAD, /* Expression parsed already, but unsuccessfully. call free or clear */
|
||||||
EXPR_ERROR_ALREADYPARSEDGOOD, /* Expression parsed already, successfully, call free or clear */
|
EXPR_ERROR_ALREADYPARSEDGOOD, /* Expression parsed already, successfully, call free or clear */
|
||||||
EXPR_ERROR_EMPTYEXPR, /* Empty expression string passed to parse */
|
EXPR_ERROR_EMPTYEXPR, /* Empty expression string passed to parse */
|
||||||
EXPR_ERROR_UNMATCHEDPAREN, /* Unmatched parenthesis */
|
EXPR_ERROR_UNMATCHEDPAREN, /* Unmatched parenthesis */
|
||||||
EXPR_ERROR_SYNTAX, /* Syntax error in expression */
|
EXPR_ERROR_SYNTAX, /* Syntax error in expression */
|
||||||
EXPR_ERROR_MISSINGSEMICOLON, /* Missing semicolon at end of expression */
|
EXPR_ERROR_MISSINGSEMICOLON, /* Missing semicolon at end of expression */
|
||||||
EXPR_ERROR_BADIDENTIFIER, /* Identifier was to big or not formed right */
|
EXPR_ERROR_BADIDENTIFIER, /* Identifier was to big or not formed right */
|
||||||
EXPR_ERROR_NOSUCHFUNCTION, /* Function does not exist in function list */
|
EXPR_ERROR_NOSUCHFUNCTION, /* Function does not exist in function list */
|
||||||
EXPR_ERROR_BADNUMBERARGUMENTS, /* Bad number of arguments in a function call */
|
EXPR_ERROR_BADNUMBERARGUMENTS, /* Bad number of arguments in a function call */
|
||||||
EXPR_ERROR_BADEXPR, /* This is a bad expression to evaluate. It has not been parsed or has unsuccessfully */
|
EXPR_ERROR_BADEXPR, /* This is a bad expression to evaluate. It has not been parsed or has unsuccessfully */
|
||||||
EXPR_ERROR_UNABLETOASSIGN, /* Unable to do an assignment, maybe no variable list */
|
EXPR_ERROR_UNABLETOASSIGN, /* Unable to do an assignment, maybe no variable list */
|
||||||
EXPR_ERROR_DIVBYZERO, /* Attempted a division by zero */
|
EXPR_ERROR_DIVBYZERO, /* Attempted a division by zero */
|
||||||
EXPR_ERROR_NOVARLIST, /* No variable list found but one is needed */
|
EXPR_ERROR_NOVARLIST, /* No variable list found but one is needed */
|
||||||
EXPR_ERROR_BREAK, /* Expression was broken by break function */
|
EXPR_ERROR_BREAK, /* Expression was broken by break function */
|
||||||
EXPR_ERROR_CONSTANTASSIGN, /* Assignment to a constant */
|
EXPR_ERROR_CONSTANTASSIGN, /* Assignment to a constant */
|
||||||
EXPR_ERROR_REFCONSTANT, /* Constant used as a reference parameter */
|
EXPR_ERROR_REFCONSTANT, /* Constant used as a reference parameter */
|
||||||
EXPR_ERROR_OUTOFRANGE, /* A bad value was passed to a function */
|
EXPR_ERROR_OUTOFRANGE, /* A bad value was passed to a function */
|
||||||
|
|
||||||
EXPR_ERROR_USER /* Custom errors should be larger than this */
|
EXPR_ERROR_USER /* Custom errors should be larger than this */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Macros */
|
/* Macros */
|
||||||
|
|
||||||
/* Forward declarations */
|
/* Forward declarations */
|
||||||
typedef struct _exprNode exprNode;
|
typedef struct _exprNode exprNode;
|
||||||
typedef struct _exprFuncList exprFuncList;
|
typedef struct _exprFuncList exprFuncList;
|
||||||
typedef struct _exprValList exprValList;
|
typedef struct _exprValList exprValList;
|
||||||
typedef struct _exprObj exprObj;
|
typedef struct _exprObj exprObj;
|
||||||
|
|
||||||
/* Function types */
|
/* Function types */
|
||||||
typedef int (*exprFuncType)(exprObj *obj, exprNode *nodes, int nodecount, EXPRTYPE **refs, int refcount, EXPRTYPE *val);
|
typedef int (*exprFuncType)(exprObj *obj, exprNode *nodes, int nodecount, EXPRTYPE **refs, int refcount, EXPRTYPE *val);
|
||||||
typedef int (*exprBreakFuncType)(exprObj *obj);
|
typedef int (*exprBreakFuncType)(exprObj *obj);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Functions */
|
/* Functions */
|
||||||
|
|
||||||
/* Version information function */
|
/* Version information function */
|
||||||
void exprGetVersion(int *major, int *minor);
|
void exprGetVersion(int *major, int *minor);
|
||||||
|
|
||||||
/* Functions for function lists */
|
/* Functions for function lists */
|
||||||
int exprFuncListCreate(exprFuncList **flist);
|
int exprFuncListCreate(exprFuncList **flist);
|
||||||
int exprFuncListAdd(exprFuncList *flist, char *name, exprFuncType ptr, int min, int max, int refmin, int refmax);
|
int exprFuncListAdd(exprFuncList *flist, char *name, exprFuncType ptr, int min, int max, int refmin, int refmax);
|
||||||
int exprFuncListFree(exprFuncList *flist);
|
int exprFuncListFree(exprFuncList *flist);
|
||||||
int exprFuncListClear(exprFuncList *flist);
|
int exprFuncListClear(exprFuncList *flist);
|
||||||
int exprFuncListInit(exprFuncList *flist);
|
int exprFuncListInit(exprFuncList *flist);
|
||||||
|
|
||||||
/* Functions for value lists */
|
/* Functions for value lists */
|
||||||
int exprValListCreate(exprValList **vlist);
|
int exprValListCreate(exprValList **vlist);
|
||||||
int exprValListAdd(exprValList *vlist, char *name, EXPRTYPE val);
|
int exprValListAdd(exprValList *vlist, char *name, EXPRTYPE val);
|
||||||
int exprValListSet(exprValList *vlist, char *name, EXPRTYPE val);
|
int exprValListSet(exprValList *vlist, char *name, EXPRTYPE val);
|
||||||
int exprValListGet(exprValList *vlist, char *name, EXPRTYPE *val);
|
int exprValListGet(exprValList *vlist, char *name, EXPRTYPE *val);
|
||||||
int exprValListAddAddress(exprValList *vlist, char *name, EXPRTYPE *addr);
|
int exprValListAddAddress(exprValList *vlist, char *name, EXPRTYPE *addr);
|
||||||
int exprValListGetAddress(exprValList *vlist, char *name, EXPRTYPE **addr);
|
int exprValListGetAddress(exprValList *vlist, char *name, EXPRTYPE **addr);
|
||||||
void *exprValListGetNext(exprValList *vlist, char **name, EXPRTYPE *value, EXPRTYPE** addr, void *cookie);
|
void *exprValListGetNext(exprValList *vlist, char **name, EXPRTYPE *value, EXPRTYPE** addr, void *cookie);
|
||||||
int exprValListFree(exprValList *vlist);
|
int exprValListFree(exprValList *vlist);
|
||||||
int exprValListClear(exprValList *vlist);
|
int exprValListClear(exprValList *vlist);
|
||||||
int exprValListInit(exprValList *vlist);
|
int exprValListInit(exprValList *vlist);
|
||||||
|
|
||||||
/* Functions for expression objects */
|
/* Functions for expression objects */
|
||||||
int exprCreate(exprObj **obj, exprFuncList *flist, exprValList *vlist, exprValList *clist,
|
int exprCreate(exprObj **obj, exprFuncList *flist, exprValList *vlist, exprValList *clist,
|
||||||
exprBreakFuncType breaker, void *userdata);
|
exprBreakFuncType breaker, void *userdata);
|
||||||
int exprFree(exprObj *obj);
|
int exprFree(exprObj *obj);
|
||||||
int exprClear(exprObj *obj);
|
int exprClear(exprObj *obj);
|
||||||
int exprParse(exprObj *obj, char *expr);
|
int exprParse(exprObj *obj, char *expr);
|
||||||
int exprEval(exprObj *obj, EXPRTYPE *val);
|
int exprEval(exprObj *obj, EXPRTYPE *val);
|
||||||
int exprEvalNode(exprObj *obj, exprNode *nodes, int curnode, EXPRTYPE *val);
|
int exprEvalNode(exprObj *obj, exprNode *nodes, int curnode, EXPRTYPE *val);
|
||||||
exprFuncList *exprGetFuncList(exprObj *obj);
|
exprFuncList *exprGetFuncList(exprObj *obj);
|
||||||
exprValList *exprGetVarList(exprObj *obj);
|
exprValList *exprGetVarList(exprObj *obj);
|
||||||
exprValList *exprGetConstList(exprObj *obj);
|
exprValList *exprGetConstList(exprObj *obj);
|
||||||
exprBreakFuncType exprGetBreakFunc(exprObj *obj);
|
exprBreakFuncType exprGetBreakFunc(exprObj *obj);
|
||||||
int exprGetBreakResult(exprObj *obj);
|
int exprGetBreakResult(exprObj *obj);
|
||||||
void* exprGetUserData(exprObj *obj);
|
void* exprGetUserData(exprObj *obj);
|
||||||
void exprSetUserData(exprObj *obj, void *userdata);
|
void exprSetUserData(exprObj *obj, void *userdata);
|
||||||
void exprSetBreakCount(exprObj *obj, int count);
|
void exprSetBreakCount(exprObj *obj, int count);
|
||||||
void exprGetErrorPosition(exprObj *obj, int *start, int *end);
|
void exprGetErrorPosition(exprObj *obj, int *start, int *end);
|
||||||
|
|
||||||
/* Other useful routines */
|
/* Other useful routines */
|
||||||
int exprValidIdent(char *name);
|
int exprValidIdent(char *name);
|
||||||
|
|
||||||
/* Name mangling */
|
/* Name mangling */
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* __BAVII_EXPREVAL_H */
|
#endif /* __BAVII_EXPREVAL_H */
|
||||||
|
|
|
@ -1,329 +1,329 @@
|
||||||
/*
|
/*
|
||||||
File: exprfunc.c
|
File: exprfunc.c
|
||||||
Auth: Brian Allen Vanderburg II
|
Auth: Brian Allen Vanderburg II
|
||||||
Date: Thursday, April 24, 2003
|
Date: Thursday, April 24, 2003
|
||||||
Desc: Expression function list routines
|
Desc: Expression function list routines
|
||||||
|
|
||||||
This file is part of ExprEval.
|
This file is part of ExprEval.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Includes */
|
/* Includes */
|
||||||
#include "exprincl.h"
|
#include "exprincl.h"
|
||||||
|
|
||||||
#include "exprpriv.h"
|
#include "exprpriv.h"
|
||||||
#include "exprmem.h"
|
#include "exprmem.h"
|
||||||
|
|
||||||
/* Internal functions */
|
/* Internal functions */
|
||||||
static exprFunc *exprCreateFunc(char *name, exprFuncType ptr, int type, int min, int max, int refmin, int refmax);
|
static exprFunc *exprCreateFunc(char *name, exprFuncType ptr, int type, int min, int max, int refmin, int refmax);
|
||||||
static void exprFuncListFreeData(exprFunc *func);
|
static void exprFuncListFreeData(exprFunc *func);
|
||||||
|
|
||||||
|
|
||||||
/* This function creates the function list, */
|
/* This function creates the function list, */
|
||||||
int exprFuncListCreate(exprFuncList **flist)
|
int exprFuncListCreate(exprFuncList **flist)
|
||||||
{
|
{
|
||||||
exprFuncList *tmp;
|
exprFuncList *tmp;
|
||||||
|
|
||||||
if(flist == NULL)
|
if(flist == NULL)
|
||||||
return EXPR_ERROR_NULLPOINTER;
|
return EXPR_ERROR_NULLPOINTER;
|
||||||
|
|
||||||
*flist = NULL; /* Set to NULL initially */
|
*flist = NULL; /* Set to NULL initially */
|
||||||
|
|
||||||
tmp = exprAllocMem(sizeof(exprFuncList));
|
tmp = exprAllocMem(sizeof(exprFuncList));
|
||||||
|
|
||||||
if(tmp == NULL)
|
if(tmp == NULL)
|
||||||
return EXPR_ERROR_MEMORY; /* Could not allocate memory */
|
return EXPR_ERROR_MEMORY; /* Could not allocate memory */
|
||||||
|
|
||||||
/* Update pointer */
|
/* Update pointer */
|
||||||
*flist = tmp;
|
*flist = tmp;
|
||||||
|
|
||||||
return EXPR_ERROR_NOERROR;
|
return EXPR_ERROR_NOERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add a function to the list */
|
/* Add a function to the list */
|
||||||
int exprFuncListAdd(exprFuncList *flist, char *name, exprFuncType ptr, int min, int max, int refmin, int refmax)
|
int exprFuncListAdd(exprFuncList *flist, char *name, exprFuncType ptr, int min, int max, int refmin, int refmax)
|
||||||
{
|
{
|
||||||
exprFunc *tmp;
|
exprFunc *tmp;
|
||||||
exprFunc *cur;
|
exprFunc *cur;
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
if(flist == NULL)
|
if(flist == NULL)
|
||||||
return EXPR_ERROR_NULLPOINTER;
|
return EXPR_ERROR_NULLPOINTER;
|
||||||
|
|
||||||
/* Make sure the name is valid */
|
/* Make sure the name is valid */
|
||||||
if(!exprValidIdent(name))
|
if(!exprValidIdent(name))
|
||||||
return EXPR_ERROR_BADIDENTIFIER;
|
return EXPR_ERROR_BADIDENTIFIER;
|
||||||
|
|
||||||
/* Fix values only if none are negative (negative values mean no limit) */
|
/* Fix values only if none are negative (negative values mean no limit) */
|
||||||
|
|
||||||
/* if both are neg, no min or max number of args */
|
/* if both are neg, no min or max number of args */
|
||||||
/* if min is neg, max pos, no min number of args but a maximum */
|
/* if min is neg, max pos, no min number of args but a maximum */
|
||||||
/* if min is pos, max neg, there is a min number of args, but no max */
|
/* if min is pos, max neg, there is a min number of args, but no max */
|
||||||
/* if both pos, then a min and max limit. We swap to make sure it works
|
/* if both pos, then a min and max limit. We swap to make sure it works
|
||||||
right. I.E. Min of 3 and max of 2 would make function unusable */
|
right. I.E. Min of 3 and max of 2 would make function unusable */
|
||||||
if(min >= 0 && max >= 0)
|
if(min >= 0 && max >= 0)
|
||||||
{
|
{
|
||||||
if(min > max)
|
if(min > max)
|
||||||
{
|
{
|
||||||
result = min;
|
result = min;
|
||||||
min = max;
|
min = max;
|
||||||
max = result;
|
max = result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(refmin >= 0 && refmax >= 0)
|
if(refmin >= 0 && refmax >= 0)
|
||||||
{
|
{
|
||||||
if(refmin > refmax)
|
if(refmin > refmax)
|
||||||
{
|
{
|
||||||
result = refmin;
|
result = refmin;
|
||||||
refmin = max;
|
refmin = max;
|
||||||
refmax = result;
|
refmax = result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(flist->head == NULL)
|
if(flist->head == NULL)
|
||||||
{
|
{
|
||||||
/* Create the node right here */
|
/* Create the node right here */
|
||||||
tmp = exprCreateFunc(name, ptr, EXPR_NODETYPE_FUNCTION, min, max, refmin, refmax);
|
tmp = exprCreateFunc(name, ptr, EXPR_NODETYPE_FUNCTION, min, max, refmin, refmax);
|
||||||
|
|
||||||
if(tmp == NULL)
|
if(tmp == NULL)
|
||||||
return EXPR_ERROR_MEMORY;
|
return EXPR_ERROR_MEMORY;
|
||||||
|
|
||||||
flist->head = tmp;
|
flist->head = tmp;
|
||||||
return EXPR_ERROR_NOERROR;
|
return EXPR_ERROR_NOERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* See if it already exists */
|
/* See if it already exists */
|
||||||
cur = flist->head;
|
cur = flist->head;
|
||||||
|
|
||||||
while(cur)
|
while(cur)
|
||||||
{
|
{
|
||||||
result = strcmp(name, cur->fname);
|
result = strcmp(name, cur->fname);
|
||||||
|
|
||||||
if(result == 0)
|
if(result == 0)
|
||||||
return EXPR_ERROR_ALREADYEXISTS;
|
return EXPR_ERROR_ALREADYEXISTS;
|
||||||
|
|
||||||
cur = cur->next;
|
cur = cur->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* It did not exist, so add it at the head */
|
/* It did not exist, so add it at the head */
|
||||||
tmp = exprCreateFunc(name, ptr, EXPR_NODETYPE_FUNCTION, min, max, refmin, refmax);
|
tmp = exprCreateFunc(name, ptr, EXPR_NODETYPE_FUNCTION, min, max, refmin, refmax);
|
||||||
|
|
||||||
if(tmp == NULL)
|
if(tmp == NULL)
|
||||||
return EXPR_ERROR_MEMORY;
|
return EXPR_ERROR_MEMORY;
|
||||||
|
|
||||||
tmp->next = flist->head;
|
tmp->next = flist->head;
|
||||||
flist->head = tmp;
|
flist->head = tmp;
|
||||||
return EXPR_ERROR_NOERROR;
|
return EXPR_ERROR_NOERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add a function node type to the list
|
/* Add a function node type to the list
|
||||||
This works pretty much the same way, except the function
|
This works pretty much the same way, except the function
|
||||||
pointer is NULL and the node type specifies the function
|
pointer is NULL and the node type specifies the function
|
||||||
to do. exprEvalNode handles this, instead of calling
|
to do. exprEvalNode handles this, instead of calling
|
||||||
a function solver. */
|
a function solver. */
|
||||||
int exprFuncListAddType(exprFuncList *flist, char *name, int type, int min, int max, int refmin, int refmax)
|
int exprFuncListAddType(exprFuncList *flist, char *name, int type, int min, int max, int refmin, int refmax)
|
||||||
{
|
{
|
||||||
exprFunc *tmp;
|
exprFunc *tmp;
|
||||||
exprFunc *cur;
|
exprFunc *cur;
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
if(flist == NULL)
|
if(flist == NULL)
|
||||||
return EXPR_ERROR_NULLPOINTER;
|
return EXPR_ERROR_NULLPOINTER;
|
||||||
|
|
||||||
/* Make sure the name is valid */
|
/* Make sure the name is valid */
|
||||||
if(!exprValidIdent(name))
|
if(!exprValidIdent(name))
|
||||||
return EXPR_ERROR_BADIDENTIFIER;
|
return EXPR_ERROR_BADIDENTIFIER;
|
||||||
|
|
||||||
/* Fix values only if none are negative (negative values mean no limit) */
|
/* Fix values only if none are negative (negative values mean no limit) */
|
||||||
|
|
||||||
/* if both are neg, no min or max number of args */
|
/* if both are neg, no min or max number of args */
|
||||||
/* if min is neg, max pos, no min number of args but a maximum */
|
/* if min is neg, max pos, no min number of args but a maximum */
|
||||||
/* if min is pos, max neg, there is a min number of args, but no max */
|
/* if min is pos, max neg, there is a min number of args, but no max */
|
||||||
/* if both pos, then a min and max limit. We swap to make sure it works
|
/* if both pos, then a min and max limit. We swap to make sure it works
|
||||||
right. I.E. Min of 3 and max of 2 would make function unusable */
|
right. I.E. Min of 3 and max of 2 would make function unusable */
|
||||||
if(min >= 0 && max >= 0)
|
if(min >= 0 && max >= 0)
|
||||||
{
|
{
|
||||||
if(min > max)
|
if(min > max)
|
||||||
{
|
{
|
||||||
result = min;
|
result = min;
|
||||||
min = max;
|
min = max;
|
||||||
max = result;
|
max = result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(refmin >= 0 && refmax >= 0)
|
if(refmin >= 0 && refmax >= 0)
|
||||||
{
|
{
|
||||||
if(refmin > refmax)
|
if(refmin > refmax)
|
||||||
{
|
{
|
||||||
result = refmin;
|
result = refmin;
|
||||||
refmin = max;
|
refmin = max;
|
||||||
refmax = result;
|
refmax = result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(flist->head == NULL)
|
if(flist->head == NULL)
|
||||||
{
|
{
|
||||||
/* Create the node right here */
|
/* Create the node right here */
|
||||||
tmp = exprCreateFunc(name, NULL, type, min, max, refmin, refmax);
|
tmp = exprCreateFunc(name, NULL, type, min, max, refmin, refmax);
|
||||||
|
|
||||||
if(tmp == NULL)
|
if(tmp == NULL)
|
||||||
return EXPR_ERROR_MEMORY;
|
return EXPR_ERROR_MEMORY;
|
||||||
|
|
||||||
flist->head = tmp;
|
flist->head = tmp;
|
||||||
return EXPR_ERROR_NOERROR;
|
return EXPR_ERROR_NOERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* See if it already exists */
|
/* See if it already exists */
|
||||||
cur = flist->head;
|
cur = flist->head;
|
||||||
|
|
||||||
while(cur)
|
while(cur)
|
||||||
{
|
{
|
||||||
result = strcmp(name, cur->fname);
|
result = strcmp(name, cur->fname);
|
||||||
|
|
||||||
if(result == 0)
|
if(result == 0)
|
||||||
return EXPR_ERROR_ALREADYEXISTS;
|
return EXPR_ERROR_ALREADYEXISTS;
|
||||||
|
|
||||||
cur = cur->next;
|
cur = cur->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* It did not exist, so add it at the head */
|
/* It did not exist, so add it at the head */
|
||||||
tmp = exprCreateFunc(name, NULL, type, min, max, refmin, refmax);
|
tmp = exprCreateFunc(name, NULL, type, min, max, refmin, refmax);
|
||||||
|
|
||||||
if(tmp == NULL)
|
if(tmp == NULL)
|
||||||
return EXPR_ERROR_MEMORY;
|
return EXPR_ERROR_MEMORY;
|
||||||
|
|
||||||
tmp->next = flist->head;
|
tmp->next = flist->head;
|
||||||
flist->head = tmp;
|
flist->head = tmp;
|
||||||
return EXPR_ERROR_NOERROR;
|
return EXPR_ERROR_NOERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Get the function from a list along with it's min an max data */
|
/* Get the function from a list along with it's min an max data */
|
||||||
int exprFuncListGet(exprFuncList *flist, char *name, exprFuncType *ptr, int *type, int *min, int *max, int *refmin, int *refmax)
|
int exprFuncListGet(exprFuncList *flist, char *name, exprFuncType *ptr, int *type, int *min, int *max, int *refmin, int *refmax)
|
||||||
{
|
{
|
||||||
exprFunc *cur;
|
exprFunc *cur;
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
if(flist == NULL)
|
if(flist == NULL)
|
||||||
return EXPR_ERROR_NULLPOINTER;
|
return EXPR_ERROR_NULLPOINTER;
|
||||||
|
|
||||||
if(name == NULL || name[0] == '\0')
|
if(name == NULL || name[0] == '\0')
|
||||||
return EXPR_ERROR_NOTFOUND;
|
return EXPR_ERROR_NOTFOUND;
|
||||||
|
|
||||||
/* Search for the item */
|
/* Search for the item */
|
||||||
cur = flist->head;
|
cur = flist->head;
|
||||||
|
|
||||||
while(cur)
|
while(cur)
|
||||||
{
|
{
|
||||||
result = strcmp(name, cur->fname);
|
result = strcmp(name, cur->fname);
|
||||||
|
|
||||||
if(result == 0)
|
if(result == 0)
|
||||||
{
|
{
|
||||||
/* We found it. */
|
/* We found it. */
|
||||||
*ptr = cur->fptr;
|
*ptr = cur->fptr;
|
||||||
*min = cur->min;
|
*min = cur->min;
|
||||||
*max = cur->max;
|
*max = cur->max;
|
||||||
*refmin = cur->refmin;
|
*refmin = cur->refmin;
|
||||||
*refmax = cur->refmax;
|
*refmax = cur->refmax;
|
||||||
*type = cur->type;
|
*type = cur->type;
|
||||||
|
|
||||||
/* return now */
|
/* return now */
|
||||||
return EXPR_ERROR_NOERROR;
|
return EXPR_ERROR_NOERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
cur = cur->next;
|
cur = cur->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If we got here, we did not find the item in the list */
|
/* If we got here, we did not find the item in the list */
|
||||||
return EXPR_ERROR_NOTFOUND;
|
return EXPR_ERROR_NOTFOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This routine will free the function list */
|
/* This routine will free the function list */
|
||||||
int exprFuncListFree(exprFuncList *flist)
|
int exprFuncListFree(exprFuncList *flist)
|
||||||
{
|
{
|
||||||
/* Make sure it exists, if not it is not error */
|
/* Make sure it exists, if not it is not error */
|
||||||
if(flist == NULL)
|
if(flist == NULL)
|
||||||
return EXPR_ERROR_NOERROR;
|
return EXPR_ERROR_NOERROR;
|
||||||
|
|
||||||
/* Free the nodes */
|
/* Free the nodes */
|
||||||
exprFuncListFreeData(flist->head);
|
exprFuncListFreeData(flist->head);
|
||||||
|
|
||||||
/* Free the container */
|
/* Free the container */
|
||||||
exprFreeMem(flist);
|
exprFreeMem(flist);
|
||||||
|
|
||||||
return EXPR_ERROR_NOERROR;
|
return EXPR_ERROR_NOERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This routine will clear the function list */
|
/* This routine will clear the function list */
|
||||||
int exprFuncListClear(exprFuncList *flist)
|
int exprFuncListClear(exprFuncList *flist)
|
||||||
{
|
{
|
||||||
if(flist == NULL)
|
if(flist == NULL)
|
||||||
return EXPR_ERROR_NOERROR;
|
return EXPR_ERROR_NOERROR;
|
||||||
|
|
||||||
/* Free the nodes only */
|
/* Free the nodes only */
|
||||||
if(flist->head)
|
if(flist->head)
|
||||||
{
|
{
|
||||||
exprFuncListFreeData(flist->head);
|
exprFuncListFreeData(flist->head);
|
||||||
|
|
||||||
flist->head = NULL;
|
flist->head = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return EXPR_ERROR_NOERROR;
|
return EXPR_ERROR_NOERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This routine will free any child nodes, and then free itself */
|
/* This routine will free any child nodes, and then free itself */
|
||||||
void exprFuncListFreeData(exprFunc *func)
|
void exprFuncListFreeData(exprFunc *func)
|
||||||
{
|
{
|
||||||
exprFunc *next;
|
exprFunc *next;
|
||||||
|
|
||||||
while(func)
|
while(func)
|
||||||
{
|
{
|
||||||
/* Remember the next item */
|
/* Remember the next item */
|
||||||
next = func->next;
|
next = func->next;
|
||||||
|
|
||||||
/* Free name */
|
/* Free name */
|
||||||
exprFreeMem(func->fname);
|
exprFreeMem(func->fname);
|
||||||
|
|
||||||
/* Free ourself */
|
/* Free ourself */
|
||||||
exprFreeMem(func);
|
exprFreeMem(func);
|
||||||
|
|
||||||
func = next;
|
func = next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This routine will create the function object */
|
/* This routine will create the function object */
|
||||||
exprFunc *exprCreateFunc(char *name, exprFuncType ptr, int type, int min, int max, int refmin, int refmax)
|
exprFunc *exprCreateFunc(char *name, exprFuncType ptr, int type, int min, int max, int refmin, int refmax)
|
||||||
{
|
{
|
||||||
exprFunc *tmp;
|
exprFunc *tmp;
|
||||||
char *vtmp;
|
char *vtmp;
|
||||||
|
|
||||||
/* We already checked the name in exprFuncListAdd */
|
/* We already checked the name in exprFuncListAdd */
|
||||||
|
|
||||||
/* Create it */
|
/* Create it */
|
||||||
tmp = exprAllocMem(sizeof(exprFunc));
|
tmp = exprAllocMem(sizeof(exprFunc));
|
||||||
if(tmp == NULL)
|
if(tmp == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
/* Allocate space for the name */
|
/* Allocate space for the name */
|
||||||
vtmp = exprAllocMem(strlen(name) + 1);
|
vtmp = exprAllocMem(strlen(name) + 1);
|
||||||
|
|
||||||
if(vtmp == NULL)
|
if(vtmp == NULL)
|
||||||
{
|
{
|
||||||
exprFreeMem(tmp);
|
exprFreeMem(tmp);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Copy the data over */
|
/* Copy the data over */
|
||||||
strcpy(vtmp, name);
|
strcpy(vtmp, name);
|
||||||
tmp->fname = vtmp;
|
tmp->fname = vtmp;
|
||||||
tmp->fptr = ptr;
|
tmp->fptr = ptr;
|
||||||
tmp->min = min;
|
tmp->min = min;
|
||||||
tmp->max = max;
|
tmp->max = max;
|
||||||
tmp->refmin = refmin;
|
tmp->refmin = refmin;
|
||||||
tmp->refmax = refmax;
|
tmp->refmax = refmax;
|
||||||
tmp->type = type;
|
tmp->type = type;
|
||||||
|
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,112 +1,112 @@
|
||||||
/*
|
/*
|
||||||
File: exprincl.h
|
File: exprincl.h
|
||||||
Auth: Brian Allen Vanderburg II
|
Auth: Brian Allen Vanderburg II
|
||||||
Date: Thursday, April 24, 2003
|
Date: Thursday, April 24, 2003
|
||||||
Desc: Includes, macros, etc needed by this library
|
Desc: Includes, macros, etc needed by this library
|
||||||
|
|
||||||
This file is part of ExprEval.
|
This file is part of ExprEval.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __BAVII_EXPRINCL_H
|
#ifndef __BAVII_EXPRINCL_H
|
||||||
#define __BAVII_EXPRINCL_H
|
#define __BAVII_EXPRINCL_H
|
||||||
|
|
||||||
|
|
||||||
/* Includes and macros and whatnot for building the library */
|
/* Includes and macros and whatnot for building the library */
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#if (_MSC_VER >= 1400) // VC8+
|
#if (_MSC_VER >= 1400) // VC8+
|
||||||
#ifndef _CRT_SECURE_NO_DEPRECATE
|
#ifndef _CRT_SECURE_NO_DEPRECATE
|
||||||
#define _CRT_SECURE_NO_DEPRECATE
|
#define _CRT_SECURE_NO_DEPRECATE
|
||||||
#endif
|
#endif
|
||||||
#ifndef _CRT_NONSTDC_NO_DEPRECATE
|
#ifndef _CRT_NONSTDC_NO_DEPRECATE
|
||||||
#define _CRT_NONSTDC_NO_DEPRECATE
|
#define _CRT_NONSTDC_NO_DEPRECATE
|
||||||
#endif
|
#endif
|
||||||
#endif // VC8+
|
#endif // VC8+
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Memory routines. memory.h for VC++, mem.h for BC++ */
|
/* Memory routines. memory.h for VC++, mem.h for BC++ */
|
||||||
#ifdef __TURBOC__
|
#ifdef __TURBOC__
|
||||||
#include <mem.h>
|
#include <mem.h>
|
||||||
#else
|
#else
|
||||||
#include <memory.h>
|
#include <memory.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Memory allocation */
|
/* Memory allocation */
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
|
|
||||||
/* String routines */
|
/* String routines */
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* Character manipulation routines */
|
/* Character manipulation routines */
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
/* Standard routines */
|
/* Standard routines */
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
/* Math routines */
|
/* Math routines */
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
/* Time */
|
/* Time */
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
|
|
||||||
/* Math constants. VC++ does not seem to have these */
|
/* Math constants. VC++ does not seem to have these */
|
||||||
#ifndef M_E
|
#ifndef M_E
|
||||||
#define M_E 2.7182818284590452354
|
#define M_E 2.7182818284590452354
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef M_LOG2E
|
#ifndef M_LOG2E
|
||||||
#define M_LOG2E 1.4426950408889634074
|
#define M_LOG2E 1.4426950408889634074
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef M_LOG10E
|
#ifndef M_LOG10E
|
||||||
#define M_LOG10E 0.43429448190325182765
|
#define M_LOG10E 0.43429448190325182765
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef M_LN2
|
#ifndef M_LN2
|
||||||
#define M_LN2 0.69314718055994530942
|
#define M_LN2 0.69314718055994530942
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef M_LN10
|
#ifndef M_LN10
|
||||||
#define M_LN10 2.30258509299404568402
|
#define M_LN10 2.30258509299404568402
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef M_PI
|
#ifndef M_PI
|
||||||
#define M_PI 3.14159265358979323846
|
#define M_PI 3.14159265358979323846
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef M_PI_2
|
#ifndef M_PI_2
|
||||||
#define M_PI_2 1.57079632679489661923
|
#define M_PI_2 1.57079632679489661923
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef M_PI_4
|
#ifndef M_PI_4
|
||||||
#define M_PI_4 0.78539816339744830962
|
#define M_PI_4 0.78539816339744830962
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef M_1_PI
|
#ifndef M_1_PI
|
||||||
#define M_1_PI 0.31830988618379067154
|
#define M_1_PI 0.31830988618379067154
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef M_2_PI
|
#ifndef M_2_PI
|
||||||
#define M_2_PI 0.63661977236758134308
|
#define M_2_PI 0.63661977236758134308
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef M_1_SQRTPI
|
#ifndef M_1_SQRTPI
|
||||||
#define M_1_SQRTPI 0.56418958354776
|
#define M_1_SQRTPI 0.56418958354776
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef M_2_SQRTPI
|
#ifndef M_2_SQRTPI
|
||||||
#define M_2_SQRTPI 1.12837916709551257390
|
#define M_2_SQRTPI 1.12837916709551257390
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef M_SQRT2
|
#ifndef M_SQRT2
|
||||||
#define M_SQRT2 1.41421356237309504880
|
#define M_SQRT2 1.41421356237309504880
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef M_1_SQRT2
|
#ifndef M_1_SQRT2
|
||||||
#define M_1_SQRT2 0.70710678118654752440
|
#define M_1_SQRT2 0.70710678118654752440
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* __BAVII_EXPRINCL_H */
|
#endif /* __BAVII_EXPRINCL_H */
|
||||||
|
|
|
@ -1,115 +1,115 @@
|
||||||
/*
|
/*
|
||||||
File: exprinit.c
|
File: exprinit.c
|
||||||
Auth: Brian Allen Vanderburg II
|
Auth: Brian Allen Vanderburg II
|
||||||
Date: Thursday, May 1, 2003
|
Date: Thursday, May 1, 2003
|
||||||
Desc: Extra functions and routines for ExprEval
|
Desc: Extra functions and routines for ExprEval
|
||||||
|
|
||||||
This file is part of ExprEval.
|
This file is part of ExprEval.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Include files */
|
/* Include files */
|
||||||
#include "exprincl.h"
|
#include "exprincl.h"
|
||||||
|
|
||||||
#include "exprpriv.h"
|
#include "exprpriv.h"
|
||||||
|
|
||||||
|
|
||||||
/* Macro for adding a function node type */
|
/* Macro for adding a function node type */
|
||||||
#define EXPR_ADDFUNC_TYPE(name, type, argmin, argmax, refmin, refmax) \
|
#define EXPR_ADDFUNC_TYPE(name, type, argmin, argmax, refmin, refmax) \
|
||||||
err = exprFuncListAddType(flist, name, type, argmin, argmax, refmin, refmax); \
|
err = exprFuncListAddType(flist, name, type, argmin, argmax, refmin, refmax); \
|
||||||
if(err != EXPR_ERROR_NOERROR) \
|
if(err != EXPR_ERROR_NOERROR) \
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
/* Macro for adding a constant */
|
/* Macro for adding a constant */
|
||||||
#define EXPR_ADDCONST(name, val) \
|
#define EXPR_ADDCONST(name, val) \
|
||||||
err = exprValListAdd(vlist, name, val); \
|
err = exprValListAdd(vlist, name, val); \
|
||||||
if(err != EXPR_ERROR_NOERROR) \
|
if(err != EXPR_ERROR_NOERROR) \
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
/* Call this function to initialize these functions into a function list */
|
/* Call this function to initialize these functions into a function list */
|
||||||
int exprFuncListInit(exprFuncList *flist)
|
int exprFuncListInit(exprFuncList *flist)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if(flist == NULL)
|
if(flist == NULL)
|
||||||
return EXPR_ERROR_NULLPOINTER;
|
return EXPR_ERROR_NULLPOINTER;
|
||||||
|
|
||||||
EXPR_ADDFUNC_TYPE("abs", EXPR_NODEFUNC_ABS, 1, 1, 0, 0);
|
EXPR_ADDFUNC_TYPE("abs", EXPR_NODEFUNC_ABS, 1, 1, 0, 0);
|
||||||
EXPR_ADDFUNC_TYPE("mod", EXPR_NODEFUNC_MOD, 2, 2, 0, 0);
|
EXPR_ADDFUNC_TYPE("mod", EXPR_NODEFUNC_MOD, 2, 2, 0, 0);
|
||||||
EXPR_ADDFUNC_TYPE("ipart", EXPR_NODEFUNC_IPART, 1, 1, 0, 0);
|
EXPR_ADDFUNC_TYPE("ipart", EXPR_NODEFUNC_IPART, 1, 1, 0, 0);
|
||||||
EXPR_ADDFUNC_TYPE("fpart", EXPR_NODEFUNC_FPART, 1, 1, 0, 0);
|
EXPR_ADDFUNC_TYPE("fpart", EXPR_NODEFUNC_FPART, 1, 1, 0, 0);
|
||||||
EXPR_ADDFUNC_TYPE("min", EXPR_NODEFUNC_MIN, 1, -1, 0, 0);
|
EXPR_ADDFUNC_TYPE("min", EXPR_NODEFUNC_MIN, 1, -1, 0, 0);
|
||||||
EXPR_ADDFUNC_TYPE("max", EXPR_NODEFUNC_MAX, 1, -1, 0, 0);
|
EXPR_ADDFUNC_TYPE("max", EXPR_NODEFUNC_MAX, 1, -1, 0, 0);
|
||||||
EXPR_ADDFUNC_TYPE("pow", EXPR_NODEFUNC_POW, 2, 2, 0, 0);
|
EXPR_ADDFUNC_TYPE("pow", EXPR_NODEFUNC_POW, 2, 2, 0, 0);
|
||||||
EXPR_ADDFUNC_TYPE("sqrt", EXPR_NODEFUNC_SQRT, 1, 1, 0, 0);
|
EXPR_ADDFUNC_TYPE("sqrt", EXPR_NODEFUNC_SQRT, 1, 1, 0, 0);
|
||||||
EXPR_ADDFUNC_TYPE("sin", EXPR_NODEFUNC_SIN, 1, 1, 0, 0);
|
EXPR_ADDFUNC_TYPE("sin", EXPR_NODEFUNC_SIN, 1, 1, 0, 0);
|
||||||
EXPR_ADDFUNC_TYPE("sinh", EXPR_NODEFUNC_SINH, 1, 1, 0, 0);
|
EXPR_ADDFUNC_TYPE("sinh", EXPR_NODEFUNC_SINH, 1, 1, 0, 0);
|
||||||
EXPR_ADDFUNC_TYPE("asin", EXPR_NODEFUNC_ASIN, 1, 1, 0, 0);
|
EXPR_ADDFUNC_TYPE("asin", EXPR_NODEFUNC_ASIN, 1, 1, 0, 0);
|
||||||
EXPR_ADDFUNC_TYPE("cos", EXPR_NODEFUNC_COS, 1, 1, 0, 0);
|
EXPR_ADDFUNC_TYPE("cos", EXPR_NODEFUNC_COS, 1, 1, 0, 0);
|
||||||
EXPR_ADDFUNC_TYPE("cosh", EXPR_NODEFUNC_COSH, 1, 1, 0, 0);
|
EXPR_ADDFUNC_TYPE("cosh", EXPR_NODEFUNC_COSH, 1, 1, 0, 0);
|
||||||
EXPR_ADDFUNC_TYPE("acos", EXPR_NODEFUNC_ACOS, 1, 1, 0, 0);
|
EXPR_ADDFUNC_TYPE("acos", EXPR_NODEFUNC_ACOS, 1, 1, 0, 0);
|
||||||
EXPR_ADDFUNC_TYPE("tan", EXPR_NODEFUNC_TAN, 1, 1, 0, 0);
|
EXPR_ADDFUNC_TYPE("tan", EXPR_NODEFUNC_TAN, 1, 1, 0, 0);
|
||||||
EXPR_ADDFUNC_TYPE("tanh", EXPR_NODEFUNC_TANH, 1, 1, 0, 0);
|
EXPR_ADDFUNC_TYPE("tanh", EXPR_NODEFUNC_TANH, 1, 1, 0, 0);
|
||||||
EXPR_ADDFUNC_TYPE("atan", EXPR_NODEFUNC_ATAN, 1, 1, 0, 0);
|
EXPR_ADDFUNC_TYPE("atan", EXPR_NODEFUNC_ATAN, 1, 1, 0, 0);
|
||||||
EXPR_ADDFUNC_TYPE("atan2", EXPR_NODEFUNC_ATAN2, 2, 2, 0, 0);
|
EXPR_ADDFUNC_TYPE("atan2", EXPR_NODEFUNC_ATAN2, 2, 2, 0, 0);
|
||||||
EXPR_ADDFUNC_TYPE("log", EXPR_NODEFUNC_LOG, 1, 1, 0, 0);
|
EXPR_ADDFUNC_TYPE("log", EXPR_NODEFUNC_LOG, 1, 1, 0, 0);
|
||||||
EXPR_ADDFUNC_TYPE("pow10", EXPR_NODEFUNC_POW10, 1, 1, 0, 0);
|
EXPR_ADDFUNC_TYPE("pow10", EXPR_NODEFUNC_POW10, 1, 1, 0, 0);
|
||||||
EXPR_ADDFUNC_TYPE("ln", EXPR_NODEFUNC_LN, 1, 1, 0, 0);
|
EXPR_ADDFUNC_TYPE("ln", EXPR_NODEFUNC_LN, 1, 1, 0, 0);
|
||||||
EXPR_ADDFUNC_TYPE("exp", EXPR_NODEFUNC_EXP, 1, 1, 0, 0);
|
EXPR_ADDFUNC_TYPE("exp", EXPR_NODEFUNC_EXP, 1, 1, 0, 0);
|
||||||
EXPR_ADDFUNC_TYPE("logn", EXPR_NODEFUNC_LOGN, 2, 2, 0, 0);
|
EXPR_ADDFUNC_TYPE("logn", EXPR_NODEFUNC_LOGN, 2, 2, 0, 0);
|
||||||
EXPR_ADDFUNC_TYPE("ceil", EXPR_NODEFUNC_CEIL, 1, 1, 0, 0);
|
EXPR_ADDFUNC_TYPE("ceil", EXPR_NODEFUNC_CEIL, 1, 1, 0, 0);
|
||||||
EXPR_ADDFUNC_TYPE("floor", EXPR_NODEFUNC_FLOOR, 1, 1, 0, 0);
|
EXPR_ADDFUNC_TYPE("floor", EXPR_NODEFUNC_FLOOR, 1, 1, 0, 0);
|
||||||
EXPR_ADDFUNC_TYPE("rand", EXPR_NODEFUNC_RAND, 0, 0, 1, 1);
|
EXPR_ADDFUNC_TYPE("rand", EXPR_NODEFUNC_RAND, 0, 0, 1, 1);
|
||||||
EXPR_ADDFUNC_TYPE("random", EXPR_NODEFUNC_RANDOM, 2, 2, 1, 1);
|
EXPR_ADDFUNC_TYPE("random", EXPR_NODEFUNC_RANDOM, 2, 2, 1, 1);
|
||||||
EXPR_ADDFUNC_TYPE("randomize", EXPR_NODEFUNC_RANDOMIZE, 0, 0, 1, 1);
|
EXPR_ADDFUNC_TYPE("randomize", EXPR_NODEFUNC_RANDOMIZE, 0, 0, 1, 1);
|
||||||
EXPR_ADDFUNC_TYPE("deg", EXPR_NODEFUNC_DEG, 1, 1, 0, 0);
|
EXPR_ADDFUNC_TYPE("deg", EXPR_NODEFUNC_DEG, 1, 1, 0, 0);
|
||||||
EXPR_ADDFUNC_TYPE("rad", EXPR_NODEFUNC_RAD, 1, 1, 0, 0);
|
EXPR_ADDFUNC_TYPE("rad", EXPR_NODEFUNC_RAD, 1, 1, 0, 0);
|
||||||
EXPR_ADDFUNC_TYPE("recttopolr", EXPR_NODEFUNC_RECTTOPOLR, 2, 2, 0, 0);
|
EXPR_ADDFUNC_TYPE("recttopolr", EXPR_NODEFUNC_RECTTOPOLR, 2, 2, 0, 0);
|
||||||
EXPR_ADDFUNC_TYPE("recttopola", EXPR_NODEFUNC_RECTTOPOLA, 2, 2, 0, 0);
|
EXPR_ADDFUNC_TYPE("recttopola", EXPR_NODEFUNC_RECTTOPOLA, 2, 2, 0, 0);
|
||||||
EXPR_ADDFUNC_TYPE("poltorectx", EXPR_NODEFUNC_POLTORECTX, 2, 2, 0, 0);
|
EXPR_ADDFUNC_TYPE("poltorectx", EXPR_NODEFUNC_POLTORECTX, 2, 2, 0, 0);
|
||||||
EXPR_ADDFUNC_TYPE("poltorecty", EXPR_NODEFUNC_POLTORECTY, 2, 2, 0, 0);
|
EXPR_ADDFUNC_TYPE("poltorecty", EXPR_NODEFUNC_POLTORECTY, 2, 2, 0, 0);
|
||||||
EXPR_ADDFUNC_TYPE("if", EXPR_NODEFUNC_IF, 3, 3, 0, 0);
|
EXPR_ADDFUNC_TYPE("if", EXPR_NODEFUNC_IF, 3, 3, 0, 0);
|
||||||
EXPR_ADDFUNC_TYPE("select", EXPR_NODEFUNC_SELECT, 3, 4, 0, 0);
|
EXPR_ADDFUNC_TYPE("select", EXPR_NODEFUNC_SELECT, 3, 4, 0, 0);
|
||||||
EXPR_ADDFUNC_TYPE("equal", EXPR_NODEFUNC_EQUAL, 2, 2, 0, 0);
|
EXPR_ADDFUNC_TYPE("equal", EXPR_NODEFUNC_EQUAL, 2, 2, 0, 0);
|
||||||
EXPR_ADDFUNC_TYPE("above", EXPR_NODEFUNC_ABOVE, 2, 2, 0, 0);
|
EXPR_ADDFUNC_TYPE("above", EXPR_NODEFUNC_ABOVE, 2, 2, 0, 0);
|
||||||
EXPR_ADDFUNC_TYPE("below", EXPR_NODEFUNC_BELOW, 2, 2, 0, 0);
|
EXPR_ADDFUNC_TYPE("below", EXPR_NODEFUNC_BELOW, 2, 2, 0, 0);
|
||||||
EXPR_ADDFUNC_TYPE("avg", EXPR_NODEFUNC_AVG, 1, -1, 0, 0);
|
EXPR_ADDFUNC_TYPE("avg", EXPR_NODEFUNC_AVG, 1, -1, 0, 0);
|
||||||
EXPR_ADDFUNC_TYPE("clip", EXPR_NODEFUNC_CLIP, 3, 3, 0, 0);
|
EXPR_ADDFUNC_TYPE("clip", EXPR_NODEFUNC_CLIP, 3, 3, 0, 0);
|
||||||
EXPR_ADDFUNC_TYPE("clamp", EXPR_NODEFUNC_CLAMP, 3, 3, 0, 0);
|
EXPR_ADDFUNC_TYPE("clamp", EXPR_NODEFUNC_CLAMP, 3, 3, 0, 0);
|
||||||
EXPR_ADDFUNC_TYPE("pntchange", EXPR_NODEFUNC_PNTCHANGE, 5, 5, 0, 0);
|
EXPR_ADDFUNC_TYPE("pntchange", EXPR_NODEFUNC_PNTCHANGE, 5, 5, 0, 0);
|
||||||
EXPR_ADDFUNC_TYPE("poly", EXPR_NODEFUNC_POLY, 2, -1, 0, 0);
|
EXPR_ADDFUNC_TYPE("poly", EXPR_NODEFUNC_POLY, 2, -1, 0, 0);
|
||||||
EXPR_ADDFUNC_TYPE("and", EXPR_NODEFUNC_AND, 2, 2, 0, 0);
|
EXPR_ADDFUNC_TYPE("and", EXPR_NODEFUNC_AND, 2, 2, 0, 0);
|
||||||
EXPR_ADDFUNC_TYPE("or", EXPR_NODEFUNC_OR, 2, 2, 0, 0);
|
EXPR_ADDFUNC_TYPE("or", EXPR_NODEFUNC_OR, 2, 2, 0, 0);
|
||||||
EXPR_ADDFUNC_TYPE("not", EXPR_NODEFUNC_NOT, 1 ,1, 0, 0);
|
EXPR_ADDFUNC_TYPE("not", EXPR_NODEFUNC_NOT, 1 ,1, 0, 0);
|
||||||
EXPR_ADDFUNC_TYPE("for", EXPR_NODEFUNC_FOR, 4, -1, 0, 0);
|
EXPR_ADDFUNC_TYPE("for", EXPR_NODEFUNC_FOR, 4, -1, 0, 0);
|
||||||
EXPR_ADDFUNC_TYPE("many", EXPR_NODEFUNC_MANY, 1, -1, 0, 0);
|
EXPR_ADDFUNC_TYPE("many", EXPR_NODEFUNC_MANY, 1, -1, 0, 0);
|
||||||
|
|
||||||
return EXPR_ERROR_NOERROR;
|
return EXPR_ERROR_NOERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Call this function to initialize some constants into a value list */
|
/* Call this function to initialize some constants into a value list */
|
||||||
int exprValListInit(exprValList *vlist)
|
int exprValListInit(exprValList *vlist)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if(vlist == NULL)
|
if(vlist == NULL)
|
||||||
return EXPR_ERROR_NULLPOINTER;
|
return EXPR_ERROR_NULLPOINTER;
|
||||||
|
|
||||||
EXPR_ADDCONST("M_E", M_E);
|
EXPR_ADDCONST("M_E", M_E);
|
||||||
EXPR_ADDCONST("M_LOG2E", M_LOG2E);
|
EXPR_ADDCONST("M_LOG2E", M_LOG2E);
|
||||||
EXPR_ADDCONST("M_LOG10E", M_LOG10E);
|
EXPR_ADDCONST("M_LOG10E", M_LOG10E);
|
||||||
EXPR_ADDCONST("M_LN2", M_LN2);
|
EXPR_ADDCONST("M_LN2", M_LN2);
|
||||||
EXPR_ADDCONST("M_LN10", M_LN10);
|
EXPR_ADDCONST("M_LN10", M_LN10);
|
||||||
EXPR_ADDCONST("M_PI", M_PI);
|
EXPR_ADDCONST("M_PI", M_PI);
|
||||||
EXPR_ADDCONST("M_PI_2", M_PI_2);
|
EXPR_ADDCONST("M_PI_2", M_PI_2);
|
||||||
EXPR_ADDCONST("M_PI_4", M_PI_4);
|
EXPR_ADDCONST("M_PI_4", M_PI_4);
|
||||||
EXPR_ADDCONST("M_1_PI", M_1_PI);
|
EXPR_ADDCONST("M_1_PI", M_1_PI);
|
||||||
EXPR_ADDCONST("M_2_PI", M_2_PI);
|
EXPR_ADDCONST("M_2_PI", M_2_PI);
|
||||||
EXPR_ADDCONST("M_1_SQRTPI", M_1_SQRTPI);
|
EXPR_ADDCONST("M_1_SQRTPI", M_1_SQRTPI);
|
||||||
EXPR_ADDCONST("M_2_SQRTPI", M_2_SQRTPI);
|
EXPR_ADDCONST("M_2_SQRTPI", M_2_SQRTPI);
|
||||||
EXPR_ADDCONST("M_SQRT2", M_SQRT2);
|
EXPR_ADDCONST("M_SQRT2", M_SQRT2);
|
||||||
EXPR_ADDCONST("M_1_SQRT2", M_1_SQRT2);
|
EXPR_ADDCONST("M_1_SQRT2", M_1_SQRT2);
|
||||||
|
|
||||||
return EXPR_ERROR_NOERROR;
|
return EXPR_ERROR_NOERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,39 +1,39 @@
|
||||||
/*
|
/*
|
||||||
File: exprmem.c
|
File: exprmem.c
|
||||||
Auth: Brian Allen Vanderburg II
|
Auth: Brian Allen Vanderburg II
|
||||||
Date: Wednesday, April 30, 2003
|
Date: Wednesday, April 30, 2003
|
||||||
Desc: Memory functions for ExprEval
|
Desc: Memory functions for ExprEval
|
||||||
|
|
||||||
This file is part of ExprEval.
|
This file is part of ExprEval.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Includes */
|
/* Includes */
|
||||||
#include "exprincl.h"
|
#include "exprincl.h"
|
||||||
|
|
||||||
#include "exprmem.h"
|
#include "exprmem.h"
|
||||||
|
|
||||||
/* Allocate memory and zero it */
|
/* Allocate memory and zero it */
|
||||||
void* exprAllocMem(size_t size)
|
void* exprAllocMem(size_t size)
|
||||||
{
|
{
|
||||||
void *data = malloc(size);
|
void *data = malloc(size);
|
||||||
|
|
||||||
if(data)
|
if(data)
|
||||||
{
|
{
|
||||||
memset(data, 0, size);
|
memset(data, 0, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Free memory */
|
/* Free memory */
|
||||||
void exprFreeMem(void *data)
|
void exprFreeMem(void *data)
|
||||||
{
|
{
|
||||||
if(data)
|
if(data)
|
||||||
free(data);
|
free(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Allocate a list of nodes */
|
/* Allocate a list of nodes */
|
||||||
exprNode *exprAllocNodes(size_t count)
|
exprNode *exprAllocNodes(size_t count)
|
||||||
{
|
{
|
||||||
return exprAllocMem(count * sizeof(exprNode));
|
return exprAllocMem(count * sizeof(exprNode));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +1,21 @@
|
||||||
/*
|
/*
|
||||||
File: exprmem.h
|
File: exprmem.h
|
||||||
Auth: Brian Allen Vanderburg II
|
Auth: Brian Allen Vanderburg II
|
||||||
Date: Wednesday, April 30, 2003
|
Date: Wednesday, April 30, 2003
|
||||||
Desc: Memory functions for ExprEval
|
Desc: Memory functions for ExprEval
|
||||||
|
|
||||||
This file is part of ExprEval.
|
This file is part of ExprEval.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __BAVII_EXPRMEM_H
|
#ifndef __BAVII_EXPRMEM_H
|
||||||
#define __BAVII_EXPRMEM_H
|
#define __BAVII_EXPRMEM_H
|
||||||
|
|
||||||
/* Needed for exprNode */
|
/* Needed for exprNode */
|
||||||
#include "exprpriv.h"
|
#include "exprpriv.h"
|
||||||
|
|
||||||
void* exprAllocMem(size_t size);
|
void* exprAllocMem(size_t size);
|
||||||
void exprFreeMem(void *data);
|
void exprFreeMem(void *data);
|
||||||
exprNode *exprAllocNodes(size_t count);
|
exprNode *exprAllocNodes(size_t count);
|
||||||
|
|
||||||
|
|
||||||
#endif /* __BAVII_EXPRMEM_H */
|
#endif /* __BAVII_EXPRMEM_H */
|
||||||
|
|
|
@ -1,237 +1,237 @@
|
||||||
/*
|
/*
|
||||||
File: exprobj.c
|
File: exprobj.c
|
||||||
Auth: Brian Allen Vanderburg II
|
Auth: Brian Allen Vanderburg II
|
||||||
Date: Tuesday, April 29, 2003
|
Date: Tuesday, April 29, 2003
|
||||||
Desc: Functions for the exprObj type
|
Desc: Functions for the exprObj type
|
||||||
|
|
||||||
This file is part of ExprEval.
|
This file is part of ExprEval.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Includes */
|
/* Includes */
|
||||||
#include "exprincl.h"
|
#include "exprincl.h"
|
||||||
|
|
||||||
#include "exprpriv.h"
|
#include "exprpriv.h"
|
||||||
#include "exprmem.h"
|
#include "exprmem.h"
|
||||||
|
|
||||||
/* Internal functions */
|
/* Internal functions */
|
||||||
static void exprFreeNodeData(exprNode *node);
|
static void exprFreeNodeData(exprNode *node);
|
||||||
|
|
||||||
|
|
||||||
/* Function to create an expression object */
|
/* Function to create an expression object */
|
||||||
int exprCreate(exprObj **obj, exprFuncList *flist, exprValList *vlist, exprValList *clist,
|
int exprCreate(exprObj **obj, exprFuncList *flist, exprValList *vlist, exprValList *clist,
|
||||||
exprBreakFuncType breaker, void *userdata)
|
exprBreakFuncType breaker, void *userdata)
|
||||||
{
|
{
|
||||||
exprObj *tmp;
|
exprObj *tmp;
|
||||||
|
|
||||||
/* Allocate memory for the object */
|
/* Allocate memory for the object */
|
||||||
tmp = exprAllocMem(sizeof(exprObj));
|
tmp = exprAllocMem(sizeof(exprObj));
|
||||||
|
|
||||||
if(tmp == NULL)
|
if(tmp == NULL)
|
||||||
return EXPR_ERROR_MEMORY;
|
return EXPR_ERROR_MEMORY;
|
||||||
|
|
||||||
|
|
||||||
/* Assign data */
|
/* Assign data */
|
||||||
tmp->flist = flist;
|
tmp->flist = flist;
|
||||||
tmp->vlist = vlist;
|
tmp->vlist = vlist;
|
||||||
tmp->clist = clist;
|
tmp->clist = clist;
|
||||||
tmp->breakerfunc = breaker;
|
tmp->breakerfunc = breaker;
|
||||||
tmp->userdata = userdata;
|
tmp->userdata = userdata;
|
||||||
tmp->breakcount = 100000; /* Default breaker count setting */
|
tmp->breakcount = 100000; /* Default breaker count setting */
|
||||||
tmp->breakcur = 0;
|
tmp->breakcur = 0;
|
||||||
|
|
||||||
/* Update pointer */
|
/* Update pointer */
|
||||||
*obj = tmp;
|
*obj = tmp;
|
||||||
|
|
||||||
return EXPR_ERROR_NOERROR;
|
return EXPR_ERROR_NOERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Free the expression */
|
/* Free the expression */
|
||||||
int exprFree(exprObj *obj)
|
int exprFree(exprObj *obj)
|
||||||
{
|
{
|
||||||
if(obj == NULL)
|
if(obj == NULL)
|
||||||
return EXPR_ERROR_NOERROR;
|
return EXPR_ERROR_NOERROR;
|
||||||
|
|
||||||
/* First free the node data */
|
/* First free the node data */
|
||||||
exprFreeNodeData(obj->headnode);
|
exprFreeNodeData(obj->headnode);
|
||||||
exprFreeMem(obj->headnode);
|
exprFreeMem(obj->headnode);
|
||||||
|
|
||||||
/* Free ourself */
|
/* Free ourself */
|
||||||
exprFreeMem(obj);
|
exprFreeMem(obj);
|
||||||
|
|
||||||
return EXPR_ERROR_NOERROR;
|
return EXPR_ERROR_NOERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Clear expression, keep lists, etc */
|
/* Clear expression, keep lists, etc */
|
||||||
int exprClear(exprObj *obj)
|
int exprClear(exprObj *obj)
|
||||||
{
|
{
|
||||||
if(obj == NULL)
|
if(obj == NULL)
|
||||||
return EXPR_ERROR_NOERROR;
|
return EXPR_ERROR_NOERROR;
|
||||||
|
|
||||||
/* Free the node data only, keep function, variable, constant lists */
|
/* Free the node data only, keep function, variable, constant lists */
|
||||||
exprFreeNodeData(obj->headnode);
|
exprFreeNodeData(obj->headnode);
|
||||||
exprFreeMem(obj->headnode);
|
exprFreeMem(obj->headnode);
|
||||||
|
|
||||||
obj->headnode = NULL;
|
obj->headnode = NULL;
|
||||||
obj->parsedbad = 0;
|
obj->parsedbad = 0;
|
||||||
obj->parsedgood = 0;
|
obj->parsedgood = 0;
|
||||||
|
|
||||||
return EXPR_ERROR_NOERROR;
|
return EXPR_ERROR_NOERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Get functions to get information about the expression object */
|
/* Get functions to get information about the expression object */
|
||||||
|
|
||||||
/* Get the function list */
|
/* Get the function list */
|
||||||
exprFuncList *exprGetFuncList(exprObj *obj)
|
exprFuncList *exprGetFuncList(exprObj *obj)
|
||||||
{
|
{
|
||||||
return (obj == NULL) ? NULL : obj->flist;
|
return (obj == NULL) ? NULL : obj->flist;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the variable list */
|
/* Get the variable list */
|
||||||
exprValList *exprGetVarList(exprObj *obj)
|
exprValList *exprGetVarList(exprObj *obj)
|
||||||
{
|
{
|
||||||
return (obj == NULL) ? NULL : obj->vlist;
|
return (obj == NULL) ? NULL : obj->vlist;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the constant list */
|
/* Get the constant list */
|
||||||
exprValList *exprGetConstList(exprObj *obj)
|
exprValList *exprGetConstList(exprObj *obj)
|
||||||
{
|
{
|
||||||
return (obj == NULL) ? NULL : obj->clist;
|
return (obj == NULL) ? NULL : obj->clist;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the breaker function */
|
/* Get the breaker function */
|
||||||
exprBreakFuncType exprGetBreakFunc(exprObj *obj)
|
exprBreakFuncType exprGetBreakFunc(exprObj *obj)
|
||||||
{
|
{
|
||||||
return (obj == NULL) ? NULL : obj->breakerfunc;
|
return (obj == NULL) ? NULL : obj->breakerfunc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check for break status */
|
/* Check for break status */
|
||||||
int exprGetBreakResult(exprObj *obj)
|
int exprGetBreakResult(exprObj *obj)
|
||||||
{
|
{
|
||||||
if(obj == NULL)
|
if(obj == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if(obj->breakerfunc == NULL)
|
if(obj->breakerfunc == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return (*(obj->breakerfunc))(obj);
|
return (*(obj->breakerfunc))(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the user data */
|
/* Get the user data */
|
||||||
void *exprGetUserData(exprObj *obj)
|
void *exprGetUserData(exprObj *obj)
|
||||||
{
|
{
|
||||||
return (obj == NULL) ? NULL : obj->userdata;
|
return (obj == NULL) ? NULL : obj->userdata;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Set functions to set certain data */
|
/* Set functions to set certain data */
|
||||||
|
|
||||||
/* Set user data */
|
/* Set user data */
|
||||||
void exprSetUserData(exprObj *obj, void *userdata)
|
void exprSetUserData(exprObj *obj, void *userdata)
|
||||||
{
|
{
|
||||||
if(obj)
|
if(obj)
|
||||||
obj->userdata = userdata;
|
obj->userdata = userdata;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Set breaker count */
|
/* Set breaker count */
|
||||||
void exprSetBreakCount(exprObj *obj, int count)
|
void exprSetBreakCount(exprObj *obj, int count)
|
||||||
{
|
{
|
||||||
if(obj)
|
if(obj)
|
||||||
{
|
{
|
||||||
/* If count is negative, make it positive */
|
/* If count is negative, make it positive */
|
||||||
if(count < 0)
|
if(count < 0)
|
||||||
count = -count;
|
count = -count;
|
||||||
|
|
||||||
obj->breakcount = count;
|
obj->breakcount = count;
|
||||||
|
|
||||||
/* Make sure the current value is not bigger than count */
|
/* Make sure the current value is not bigger than count */
|
||||||
if(obj->breakcur > count)
|
if(obj->breakcur > count)
|
||||||
obj->breakcur = count;
|
obj->breakcur = count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get error position */
|
/* Get error position */
|
||||||
void exprGetErrorPosition(exprObj *obj, int *start, int *end)
|
void exprGetErrorPosition(exprObj *obj, int *start, int *end)
|
||||||
{
|
{
|
||||||
if(obj)
|
if(obj)
|
||||||
{
|
{
|
||||||
if(start)
|
if(start)
|
||||||
*start = obj->starterr;
|
*start = obj->starterr;
|
||||||
|
|
||||||
if(end)
|
if(end)
|
||||||
*end = obj->enderr;
|
*end = obj->enderr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This function will free a node's data */
|
/* This function will free a node's data */
|
||||||
static void exprFreeNodeData(exprNode *node)
|
static void exprFreeNodeData(exprNode *node)
|
||||||
{
|
{
|
||||||
int pos;
|
int pos;
|
||||||
|
|
||||||
if(node == NULL)
|
if(node == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* free data based on type */
|
/* free data based on type */
|
||||||
switch(node->type)
|
switch(node->type)
|
||||||
{
|
{
|
||||||
case EXPR_NODETYPE_ADD:
|
case EXPR_NODETYPE_ADD:
|
||||||
case EXPR_NODETYPE_SUBTRACT:
|
case EXPR_NODETYPE_SUBTRACT:
|
||||||
case EXPR_NODETYPE_MULTIPLY:
|
case EXPR_NODETYPE_MULTIPLY:
|
||||||
case EXPR_NODETYPE_DIVIDE:
|
case EXPR_NODETYPE_DIVIDE:
|
||||||
case EXPR_NODETYPE_EXPONENT:
|
case EXPR_NODETYPE_EXPONENT:
|
||||||
case EXPR_NODETYPE_NEGATE:
|
case EXPR_NODETYPE_NEGATE:
|
||||||
case EXPR_NODETYPE_MULTI:
|
case EXPR_NODETYPE_MULTI:
|
||||||
/* Free operation data */
|
/* Free operation data */
|
||||||
if(node->data.oper.nodes)
|
if(node->data.oper.nodes)
|
||||||
{
|
{
|
||||||
for(pos = 0; pos < node->data.oper.nodecount; pos++)
|
for(pos = 0; pos < node->data.oper.nodecount; pos++)
|
||||||
exprFreeNodeData(&(node->data.oper.nodes[pos]));
|
exprFreeNodeData(&(node->data.oper.nodes[pos]));
|
||||||
|
|
||||||
exprFreeMem(node->data.oper.nodes);
|
exprFreeMem(node->data.oper.nodes);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
case EXPR_NODETYPE_VALUE:
|
case EXPR_NODETYPE_VALUE:
|
||||||
/* Nothing to free for value */
|
/* Nothing to free for value */
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case EXPR_NODETYPE_VARIABLE:
|
case EXPR_NODETYPE_VARIABLE:
|
||||||
/* Nothing to free for variable */
|
/* Nothing to free for variable */
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case EXPR_NODETYPE_FUNCTION:
|
case EXPR_NODETYPE_FUNCTION:
|
||||||
/* Free data of each subnode */
|
/* Free data of each subnode */
|
||||||
if(node->data.function.nodes)
|
if(node->data.function.nodes)
|
||||||
{
|
{
|
||||||
for(pos = 0; pos < node->data.function.nodecount; pos++)
|
for(pos = 0; pos < node->data.function.nodecount; pos++)
|
||||||
exprFreeNodeData(&(node->data.function.nodes[pos]));
|
exprFreeNodeData(&(node->data.function.nodes[pos]));
|
||||||
|
|
||||||
/* Free the subnode array */
|
/* Free the subnode array */
|
||||||
exprFreeMem(node->data.function.nodes);
|
exprFreeMem(node->data.function.nodes);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Free reference variable list */
|
/* Free reference variable list */
|
||||||
if(node->data.function.refs)
|
if(node->data.function.refs)
|
||||||
exprFreeMem(node->data.function.refs);
|
exprFreeMem(node->data.function.refs);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case EXPR_NODETYPE_ASSIGN:
|
case EXPR_NODETYPE_ASSIGN:
|
||||||
/* Free subnode data */
|
/* Free subnode data */
|
||||||
if(node->data.assign.node)
|
if(node->data.assign.node)
|
||||||
{
|
{
|
||||||
exprFreeNodeData(node->data.assign.node);
|
exprFreeNodeData(node->data.assign.node);
|
||||||
|
|
||||||
/* Free the subnode */
|
/* Free the subnode */
|
||||||
exprFreeMem(node->data.assign.node);
|
exprFreeMem(node->data.assign.node);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,215 +1,215 @@
|
||||||
/*
|
/*
|
||||||
File: exprpriv.h
|
File: exprpriv.h
|
||||||
Auth: Brian Allen Vanderburg II
|
Auth: Brian Allen Vanderburg II
|
||||||
Date: Tuesday, February 28, 2006
|
Date: Tuesday, February 28, 2006
|
||||||
Desc: Private include file for ExprEval library
|
Desc: Private include file for ExprEval library
|
||||||
|
|
||||||
This file is part of ExprEval.
|
This file is part of ExprEval.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/* Include once */
|
/* Include once */
|
||||||
#ifndef __BAVII_EXPRPRIV_H
|
#ifndef __BAVII_EXPRPRIV_H
|
||||||
#define __BAVII_EXPRPRIV_H
|
#define __BAVII_EXPRPRIV_H
|
||||||
|
|
||||||
/* Need some definitions, NULL, etc */
|
/* Need some definitions, NULL, etc */
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
/* Include config and main expreval header */
|
/* Include config and main expreval header */
|
||||||
#include "expreval.h"
|
#include "expreval.h"
|
||||||
#include "exprconf.h"
|
#include "exprconf.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Version number
|
Version number
|
||||||
*/
|
*/
|
||||||
#define EXPR_VERSIONMAJOR 2
|
#define EXPR_VERSIONMAJOR 2
|
||||||
#define EXPR_VERSIONMINOR 7
|
#define EXPR_VERSIONMINOR 7
|
||||||
|
|
||||||
/* Node types */
|
/* Node types */
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
EXPR_NODETYPE_UNKNOWN = 0,
|
EXPR_NODETYPE_UNKNOWN = 0,
|
||||||
EXPR_NODETYPE_MULTI,
|
EXPR_NODETYPE_MULTI,
|
||||||
EXPR_NODETYPE_ADD,
|
EXPR_NODETYPE_ADD,
|
||||||
EXPR_NODETYPE_SUBTRACT,
|
EXPR_NODETYPE_SUBTRACT,
|
||||||
EXPR_NODETYPE_MULTIPLY,
|
EXPR_NODETYPE_MULTIPLY,
|
||||||
EXPR_NODETYPE_DIVIDE,
|
EXPR_NODETYPE_DIVIDE,
|
||||||
EXPR_NODETYPE_EXPONENT,
|
EXPR_NODETYPE_EXPONENT,
|
||||||
EXPR_NODETYPE_NEGATE,
|
EXPR_NODETYPE_NEGATE,
|
||||||
EXPR_NODETYPE_VALUE,
|
EXPR_NODETYPE_VALUE,
|
||||||
EXPR_NODETYPE_VARIABLE,
|
EXPR_NODETYPE_VARIABLE,
|
||||||
EXPR_NODETYPE_ASSIGN,
|
EXPR_NODETYPE_ASSIGN,
|
||||||
EXPR_NODETYPE_FUNCTION
|
EXPR_NODETYPE_FUNCTION
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Functions can be evaluated directly in EXPREVAL. If fptr
|
/* Functions can be evaluated directly in EXPREVAL. If fptr
|
||||||
is NULL, type is used to determine what the function is */
|
is NULL, type is used to determine what the function is */
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
EXPR_NODEFUNC_UNKNOWN = 0,
|
EXPR_NODEFUNC_UNKNOWN = 0,
|
||||||
EXPR_NODEFUNC_ABS,
|
EXPR_NODEFUNC_ABS,
|
||||||
EXPR_NODEFUNC_MOD,
|
EXPR_NODEFUNC_MOD,
|
||||||
EXPR_NODEFUNC_IPART,
|
EXPR_NODEFUNC_IPART,
|
||||||
EXPR_NODEFUNC_FPART,
|
EXPR_NODEFUNC_FPART,
|
||||||
EXPR_NODEFUNC_MIN,
|
EXPR_NODEFUNC_MIN,
|
||||||
EXPR_NODEFUNC_MAX,
|
EXPR_NODEFUNC_MAX,
|
||||||
EXPR_NODEFUNC_POW,
|
EXPR_NODEFUNC_POW,
|
||||||
EXPR_NODEFUNC_SQRT,
|
EXPR_NODEFUNC_SQRT,
|
||||||
EXPR_NODEFUNC_SIN,
|
EXPR_NODEFUNC_SIN,
|
||||||
EXPR_NODEFUNC_SINH,
|
EXPR_NODEFUNC_SINH,
|
||||||
EXPR_NODEFUNC_ASIN,
|
EXPR_NODEFUNC_ASIN,
|
||||||
EXPR_NODEFUNC_COS,
|
EXPR_NODEFUNC_COS,
|
||||||
EXPR_NODEFUNC_COSH,
|
EXPR_NODEFUNC_COSH,
|
||||||
EXPR_NODEFUNC_ACOS,
|
EXPR_NODEFUNC_ACOS,
|
||||||
EXPR_NODEFUNC_TAN,
|
EXPR_NODEFUNC_TAN,
|
||||||
EXPR_NODEFUNC_TANH,
|
EXPR_NODEFUNC_TANH,
|
||||||
EXPR_NODEFUNC_ATAN,
|
EXPR_NODEFUNC_ATAN,
|
||||||
EXPR_NODEFUNC_ATAN2,
|
EXPR_NODEFUNC_ATAN2,
|
||||||
EXPR_NODEFUNC_LOG,
|
EXPR_NODEFUNC_LOG,
|
||||||
EXPR_NODEFUNC_POW10,
|
EXPR_NODEFUNC_POW10,
|
||||||
EXPR_NODEFUNC_LN,
|
EXPR_NODEFUNC_LN,
|
||||||
EXPR_NODEFUNC_EXP,
|
EXPR_NODEFUNC_EXP,
|
||||||
EXPR_NODEFUNC_LOGN,
|
EXPR_NODEFUNC_LOGN,
|
||||||
EXPR_NODEFUNC_CEIL,
|
EXPR_NODEFUNC_CEIL,
|
||||||
EXPR_NODEFUNC_FLOOR,
|
EXPR_NODEFUNC_FLOOR,
|
||||||
EXPR_NODEFUNC_RAND,
|
EXPR_NODEFUNC_RAND,
|
||||||
EXPR_NODEFUNC_RANDOM,
|
EXPR_NODEFUNC_RANDOM,
|
||||||
EXPR_NODEFUNC_RANDOMIZE,
|
EXPR_NODEFUNC_RANDOMIZE,
|
||||||
EXPR_NODEFUNC_DEG,
|
EXPR_NODEFUNC_DEG,
|
||||||
EXPR_NODEFUNC_RAD,
|
EXPR_NODEFUNC_RAD,
|
||||||
EXPR_NODEFUNC_RECTTOPOLR,
|
EXPR_NODEFUNC_RECTTOPOLR,
|
||||||
EXPR_NODEFUNC_RECTTOPOLA,
|
EXPR_NODEFUNC_RECTTOPOLA,
|
||||||
EXPR_NODEFUNC_POLTORECTX,
|
EXPR_NODEFUNC_POLTORECTX,
|
||||||
EXPR_NODEFUNC_POLTORECTY,
|
EXPR_NODEFUNC_POLTORECTY,
|
||||||
EXPR_NODEFUNC_IF,
|
EXPR_NODEFUNC_IF,
|
||||||
EXPR_NODEFUNC_SELECT,
|
EXPR_NODEFUNC_SELECT,
|
||||||
EXPR_NODEFUNC_EQUAL,
|
EXPR_NODEFUNC_EQUAL,
|
||||||
EXPR_NODEFUNC_ABOVE,
|
EXPR_NODEFUNC_ABOVE,
|
||||||
EXPR_NODEFUNC_BELOW,
|
EXPR_NODEFUNC_BELOW,
|
||||||
EXPR_NODEFUNC_AVG,
|
EXPR_NODEFUNC_AVG,
|
||||||
EXPR_NODEFUNC_CLIP,
|
EXPR_NODEFUNC_CLIP,
|
||||||
EXPR_NODEFUNC_CLAMP,
|
EXPR_NODEFUNC_CLAMP,
|
||||||
EXPR_NODEFUNC_PNTCHANGE,
|
EXPR_NODEFUNC_PNTCHANGE,
|
||||||
EXPR_NODEFUNC_POLY,
|
EXPR_NODEFUNC_POLY,
|
||||||
EXPR_NODEFUNC_AND,
|
EXPR_NODEFUNC_AND,
|
||||||
EXPR_NODEFUNC_OR,
|
EXPR_NODEFUNC_OR,
|
||||||
EXPR_NODEFUNC_NOT,
|
EXPR_NODEFUNC_NOT,
|
||||||
EXPR_NODEFUNC_FOR,
|
EXPR_NODEFUNC_FOR,
|
||||||
EXPR_NODEFUNC_MANY
|
EXPR_NODEFUNC_MANY
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Forward declarations */
|
/* Forward declarations */
|
||||||
typedef struct _exprFunc exprFunc;
|
typedef struct _exprFunc exprFunc;
|
||||||
typedef struct _exprVal exprVal;
|
typedef struct _exprVal exprVal;
|
||||||
|
|
||||||
/* Expression object */
|
/* Expression object */
|
||||||
struct _exprObj
|
struct _exprObj
|
||||||
{
|
{
|
||||||
struct _exprFuncList *flist; /* Functions */
|
struct _exprFuncList *flist; /* Functions */
|
||||||
struct _exprValList *vlist; /* Variables */
|
struct _exprValList *vlist; /* Variables */
|
||||||
struct _exprValList *clist; /* Constants */
|
struct _exprValList *clist; /* Constants */
|
||||||
struct _exprNode *headnode; /* Head parsed node */
|
struct _exprNode *headnode; /* Head parsed node */
|
||||||
|
|
||||||
exprBreakFuncType breakerfunc; /* Break function type */
|
exprBreakFuncType breakerfunc; /* Break function type */
|
||||||
|
|
||||||
void *userdata; /* User data, can be any 32 bit value */
|
void *userdata; /* User data, can be any 32 bit value */
|
||||||
int parsedgood; /* non-zero if successfully parsed */
|
int parsedgood; /* non-zero if successfully parsed */
|
||||||
int parsedbad; /* non-zero if parsed but unsuccessful */
|
int parsedbad; /* non-zero if parsed but unsuccessful */
|
||||||
int breakcount; /* how often to check the breaker function */
|
int breakcount; /* how often to check the breaker function */
|
||||||
int breakcur; /* do we check the breaker function yet */
|
int breakcur; /* do we check the breaker function yet */
|
||||||
int starterr; /* start position of an error */
|
int starterr; /* start position of an error */
|
||||||
int enderr; /* end position of an error */
|
int enderr; /* end position of an error */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Object for a function */
|
/* Object for a function */
|
||||||
struct _exprFunc
|
struct _exprFunc
|
||||||
{
|
{
|
||||||
char *fname; /* Name of the function */
|
char *fname; /* Name of the function */
|
||||||
exprFuncType fptr; /* Function pointer */
|
exprFuncType fptr; /* Function pointer */
|
||||||
int min, max; /* Min and max args for the function. */
|
int min, max; /* Min and max args for the function. */
|
||||||
int refmin, refmax; /* Min and max ref. variables for the function */
|
int refmin, refmax; /* Min and max ref. variables for the function */
|
||||||
int type; /* Function node type. exprEvalNOde solves the function */
|
int type; /* Function node type. exprEvalNOde solves the function */
|
||||||
|
|
||||||
struct _exprFunc *next; /* For linked list */
|
struct _exprFunc *next; /* For linked list */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Function list object */
|
/* Function list object */
|
||||||
struct _exprFuncList
|
struct _exprFuncList
|
||||||
{
|
{
|
||||||
struct _exprFunc *head;
|
struct _exprFunc *head;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Object for values */
|
/* Object for values */
|
||||||
struct _exprVal
|
struct _exprVal
|
||||||
{
|
{
|
||||||
char *vname; /* Name of the value */
|
char *vname; /* Name of the value */
|
||||||
EXPRTYPE vval; /* Value of the value */
|
EXPRTYPE vval; /* Value of the value */
|
||||||
EXPRTYPE *vptr; /* Pointer to a value. Used only if not NULL */
|
EXPRTYPE *vptr; /* Pointer to a value. Used only if not NULL */
|
||||||
|
|
||||||
struct _exprVal *next; /* For linked list */
|
struct _exprVal *next; /* For linked list */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Value list */
|
/* Value list */
|
||||||
struct _exprValList
|
struct _exprValList
|
||||||
{
|
{
|
||||||
struct _exprVal *head;
|
struct _exprVal *head;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Expression node type */
|
/* Expression node type */
|
||||||
struct _exprNode
|
struct _exprNode
|
||||||
{
|
{
|
||||||
int type; /* Node type */
|
int type; /* Node type */
|
||||||
|
|
||||||
union _data /* Union of info for various types */
|
union _data /* Union of info for various types */
|
||||||
{
|
{
|
||||||
struct _oper
|
struct _oper
|
||||||
{
|
{
|
||||||
struct _exprNode *nodes; /* Operation arguments */
|
struct _exprNode *nodes; /* Operation arguments */
|
||||||
int nodecount; /* Number of arguments */
|
int nodecount; /* Number of arguments */
|
||||||
} oper;
|
} oper;
|
||||||
|
|
||||||
struct _variable
|
struct _variable
|
||||||
{
|
{
|
||||||
EXPRTYPE *vaddr; /* Used if EXPR_FAST_VAR_ACCESS defined */
|
EXPRTYPE *vaddr; /* Used if EXPR_FAST_VAR_ACCESS defined */
|
||||||
} variable;
|
} variable;
|
||||||
|
|
||||||
struct _value
|
struct _value
|
||||||
{
|
{
|
||||||
EXPRTYPE value; /* Value if type is value */
|
EXPRTYPE value; /* Value if type is value */
|
||||||
} value;
|
} value;
|
||||||
|
|
||||||
struct _assign /* Assignment struct */
|
struct _assign /* Assignment struct */
|
||||||
{
|
{
|
||||||
EXPRTYPE *vaddr; /* Used if EXPR_FAST_VAR_ACCESS defined */
|
EXPRTYPE *vaddr; /* Used if EXPR_FAST_VAR_ACCESS defined */
|
||||||
struct _exprNode *node; /* Node to evaluate */
|
struct _exprNode *node; /* Node to evaluate */
|
||||||
} assign;
|
} assign;
|
||||||
|
|
||||||
struct _function
|
struct _function
|
||||||
{
|
{
|
||||||
exprFuncType fptr; /* Function pointer */
|
exprFuncType fptr; /* Function pointer */
|
||||||
struct _exprNode *nodes; /* Array of argument nodes */
|
struct _exprNode *nodes; /* Array of argument nodes */
|
||||||
int nodecount; /* Number of argument nodes */
|
int nodecount; /* Number of argument nodes */
|
||||||
EXPRTYPE **refs; /* Reference variables */
|
EXPRTYPE **refs; /* Reference variables */
|
||||||
int refcount; /* Number of variable references (not a reference counter) */
|
int refcount; /* Number of variable references (not a reference counter) */
|
||||||
int type; /* Type of function for exprEvalNode if fptr is NULL */
|
int type; /* Type of function for exprEvalNode if fptr is NULL */
|
||||||
} function;
|
} function;
|
||||||
} data;
|
} data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Functions for function lists */
|
/* Functions for function lists */
|
||||||
int exprFuncListAddType(exprFuncList *flist, char *name, int type, int min, int max, int refmin, int refmax);
|
int exprFuncListAddType(exprFuncList *flist, char *name, int type, int min, int max, int refmin, int refmax);
|
||||||
int exprFuncListGet(exprFuncList *flist, char *name, exprFuncType *ptr, int *type, int *min, int *max, int *refmin, int *refmax);
|
int exprFuncListGet(exprFuncList *flist, char *name, exprFuncType *ptr, int *type, int *min, int *max, int *refmin, int *refmax);
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* __BAVII_EXPRPRIV_H */
|
#endif /* __BAVII_EXPRPRIV_H */
|
||||||
|
|
||||||
|
|
|
@ -1,43 +1,43 @@
|
||||||
/*
|
/*
|
||||||
File: exprutil.c
|
File: exprutil.c
|
||||||
Auth: Brian Allen Vanderburg II
|
Auth: Brian Allen Vanderburg II
|
||||||
Date: Monday, April 28, 2003
|
Date: Monday, April 28, 2003
|
||||||
Desc: Utility functions for use by this library
|
Desc: Utility functions for use by this library
|
||||||
|
|
||||||
This file is part of ExprEval.
|
This file is part of ExprEval.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Include files */
|
/* Include files */
|
||||||
#include "exprincl.h"
|
#include "exprincl.h"
|
||||||
|
|
||||||
#include "exprpriv.h"
|
#include "exprpriv.h"
|
||||||
|
|
||||||
|
|
||||||
/* Return the version number */
|
/* Return the version number */
|
||||||
void exprGetVersion(int *major, int *minor)
|
void exprGetVersion(int *major, int *minor)
|
||||||
{
|
{
|
||||||
*major = EXPR_VERSIONMAJOR;
|
*major = EXPR_VERSIONMAJOR;
|
||||||
*minor = EXPR_VERSIONMINOR;
|
*minor = EXPR_VERSIONMINOR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This utility function determines if an identifier is valid */
|
/* This utility function determines if an identifier is valid */
|
||||||
int exprValidIdent(char *name)
|
int exprValidIdent(char *name)
|
||||||
{
|
{
|
||||||
if(name == NULL) /* Null string */
|
if(name == NULL) /* Null string */
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* First must be letter or underscore */
|
/* First must be letter or underscore */
|
||||||
if(isalpha(*name) || *name == '_')
|
if(isalpha(*name) || *name == '_')
|
||||||
name++; /* Point to next letter */
|
name++; /* Point to next letter */
|
||||||
else
|
else
|
||||||
return 0; /* Not letter or underscore, maybe empty*/
|
return 0; /* Not letter or underscore, maybe empty*/
|
||||||
|
|
||||||
/* others can be letter, number, or underscore */
|
/* others can be letter, number, or underscore */
|
||||||
while(isalnum(*name) || *name == '_')
|
while(isalnum(*name) || *name == '_')
|
||||||
name++;
|
name++;
|
||||||
|
|
||||||
/* When the while breaks out, we should be at the end */
|
/* When the while breaks out, we should be at the end */
|
||||||
return (*name == '\0') ? 1 : 0;
|
return (*name == '\0') ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,395 +1,395 @@
|
||||||
/*
|
/*
|
||||||
File: exprval.c
|
File: exprval.c
|
||||||
Auth: Brian Allen Vanderburg II
|
Auth: Brian Allen Vanderburg II
|
||||||
Date: Thursday, April 24, 2003
|
Date: Thursday, April 24, 2003
|
||||||
Desc: Value lists for variables and constants
|
Desc: Value lists for variables and constants
|
||||||
|
|
||||||
This file is part of ExprEval.
|
This file is part of ExprEval.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Includes */
|
/* Includes */
|
||||||
#include "exprincl.h"
|
#include "exprincl.h"
|
||||||
|
|
||||||
#include "exprpriv.h"
|
#include "exprpriv.h"
|
||||||
#include "exprmem.h"
|
#include "exprmem.h"
|
||||||
|
|
||||||
|
|
||||||
/* Internal functions */
|
/* Internal functions */
|
||||||
static exprVal *exprCreateVal(char *name, EXPRTYPE val, EXPRTYPE *addr);
|
static exprVal *exprCreateVal(char *name, EXPRTYPE val, EXPRTYPE *addr);
|
||||||
static void exprValListFreeData(exprVal *val);
|
static void exprValListFreeData(exprVal *val);
|
||||||
static void exprValListResetData(exprVal *val);
|
static void exprValListResetData(exprVal *val);
|
||||||
|
|
||||||
/* This function creates the value list, */
|
/* This function creates the value list, */
|
||||||
int exprValListCreate(exprValList **vlist)
|
int exprValListCreate(exprValList **vlist)
|
||||||
{
|
{
|
||||||
exprValList *tmp;
|
exprValList *tmp;
|
||||||
|
|
||||||
if(vlist == NULL)
|
if(vlist == NULL)
|
||||||
return EXPR_ERROR_NULLPOINTER;
|
return EXPR_ERROR_NULLPOINTER;
|
||||||
|
|
||||||
*vlist = NULL; /* Set to NULL initially */
|
*vlist = NULL; /* Set to NULL initially */
|
||||||
|
|
||||||
tmp = exprAllocMem(sizeof(exprValList));
|
tmp = exprAllocMem(sizeof(exprValList));
|
||||||
|
|
||||||
if(tmp == NULL)
|
if(tmp == NULL)
|
||||||
return EXPR_ERROR_MEMORY; /* Could not allocate memory */
|
return EXPR_ERROR_MEMORY; /* Could not allocate memory */
|
||||||
|
|
||||||
/* Update pointer */
|
/* Update pointer */
|
||||||
*vlist = tmp;
|
*vlist = tmp;
|
||||||
|
|
||||||
return EXPR_ERROR_NOERROR;
|
return EXPR_ERROR_NOERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add a value to the list */
|
/* Add a value to the list */
|
||||||
int exprValListAdd(exprValList *vlist, char *name, EXPRTYPE val)
|
int exprValListAdd(exprValList *vlist, char *name, EXPRTYPE val)
|
||||||
{
|
{
|
||||||
exprVal *tmp;
|
exprVal *tmp;
|
||||||
exprVal *cur;
|
exprVal *cur;
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
if(vlist == NULL)
|
if(vlist == NULL)
|
||||||
return EXPR_ERROR_NULLPOINTER;
|
return EXPR_ERROR_NULLPOINTER;
|
||||||
|
|
||||||
/* Make sure the name is valid */
|
/* Make sure the name is valid */
|
||||||
if(!exprValidIdent(name))
|
if(!exprValidIdent(name))
|
||||||
return EXPR_ERROR_BADIDENTIFIER;
|
return EXPR_ERROR_BADIDENTIFIER;
|
||||||
|
|
||||||
if(vlist->head == NULL)
|
if(vlist->head == NULL)
|
||||||
{
|
{
|
||||||
/* Create the node right here */
|
/* Create the node right here */
|
||||||
tmp = exprCreateVal(name, val, NULL);
|
tmp = exprCreateVal(name, val, NULL);
|
||||||
|
|
||||||
if(tmp == NULL)
|
if(tmp == NULL)
|
||||||
return EXPR_ERROR_MEMORY;
|
return EXPR_ERROR_MEMORY;
|
||||||
|
|
||||||
vlist->head = tmp;
|
vlist->head = tmp;
|
||||||
return EXPR_ERROR_NOERROR;
|
return EXPR_ERROR_NOERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* See if already exists */
|
/* See if already exists */
|
||||||
cur = vlist->head;
|
cur = vlist->head;
|
||||||
|
|
||||||
while(cur)
|
while(cur)
|
||||||
{
|
{
|
||||||
result = strcmp(name, cur->vname);
|
result = strcmp(name, cur->vname);
|
||||||
|
|
||||||
if(result == 0)
|
if(result == 0)
|
||||||
return EXPR_ERROR_ALREADYEXISTS;
|
return EXPR_ERROR_ALREADYEXISTS;
|
||||||
|
|
||||||
cur = cur->next;
|
cur = cur->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We did not find it, create it and add it to the beginning */
|
/* We did not find it, create it and add it to the beginning */
|
||||||
tmp = exprCreateVal(name, val, NULL);
|
tmp = exprCreateVal(name, val, NULL);
|
||||||
|
|
||||||
if(tmp == NULL)
|
if(tmp == NULL)
|
||||||
return EXPR_ERROR_MEMORY;
|
return EXPR_ERROR_MEMORY;
|
||||||
|
|
||||||
tmp->next = vlist->head;
|
tmp->next = vlist->head;
|
||||||
vlist->head = tmp;
|
vlist->head = tmp;
|
||||||
|
|
||||||
return EXPR_ERROR_NOERROR;
|
return EXPR_ERROR_NOERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set a value in the list */
|
/* Set a value in the list */
|
||||||
int exprValListSet(exprValList *vlist, char *name, EXPRTYPE val)
|
int exprValListSet(exprValList *vlist, char *name, EXPRTYPE val)
|
||||||
{
|
{
|
||||||
exprVal *cur;
|
exprVal *cur;
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
if(vlist == NULL)
|
if(vlist == NULL)
|
||||||
return EXPR_ERROR_NULLPOINTER;
|
return EXPR_ERROR_NULLPOINTER;
|
||||||
|
|
||||||
if(name == NULL || name[0] == '\0')
|
if(name == NULL || name[0] == '\0')
|
||||||
return EXPR_ERROR_NOTFOUND;
|
return EXPR_ERROR_NOTFOUND;
|
||||||
|
|
||||||
/* Find and set it */
|
/* Find and set it */
|
||||||
cur = vlist->head;
|
cur = vlist->head;
|
||||||
|
|
||||||
while(cur)
|
while(cur)
|
||||||
{
|
{
|
||||||
result = strcmp(name, cur->vname);
|
result = strcmp(name, cur->vname);
|
||||||
|
|
||||||
if(result == 0)
|
if(result == 0)
|
||||||
{
|
{
|
||||||
if(cur->vptr)
|
if(cur->vptr)
|
||||||
*(cur->vptr) = val;
|
*(cur->vptr) = val;
|
||||||
else
|
else
|
||||||
cur->vval = val;
|
cur->vval = val;
|
||||||
|
|
||||||
return EXPR_ERROR_NOERROR;
|
return EXPR_ERROR_NOERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
cur = cur->next;
|
cur = cur->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
return EXPR_ERROR_NOTFOUND;
|
return EXPR_ERROR_NOTFOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the value from a list */
|
/* Get the value from a list */
|
||||||
int exprValListGet(exprValList *vlist, char *name, EXPRTYPE *val)
|
int exprValListGet(exprValList *vlist, char *name, EXPRTYPE *val)
|
||||||
{
|
{
|
||||||
exprVal *cur;
|
exprVal *cur;
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
if(vlist == NULL)
|
if(vlist == NULL)
|
||||||
return EXPR_ERROR_NULLPOINTER;
|
return EXPR_ERROR_NULLPOINTER;
|
||||||
|
|
||||||
if(name == NULL || name[0] == '\0')
|
if(name == NULL || name[0] == '\0')
|
||||||
return EXPR_ERROR_NOTFOUND;
|
return EXPR_ERROR_NOTFOUND;
|
||||||
|
|
||||||
/* Search for the item */
|
/* Search for the item */
|
||||||
cur = vlist->head;
|
cur = vlist->head;
|
||||||
|
|
||||||
while(cur)
|
while(cur)
|
||||||
{
|
{
|
||||||
result = strcmp(name, cur->vname);
|
result = strcmp(name, cur->vname);
|
||||||
|
|
||||||
if(result == 0)
|
if(result == 0)
|
||||||
{
|
{
|
||||||
/* We found it. */
|
/* We found it. */
|
||||||
if(cur->vptr)
|
if(cur->vptr)
|
||||||
*val = *(cur->vptr);
|
*val = *(cur->vptr);
|
||||||
else
|
else
|
||||||
*val = cur->vval;
|
*val = cur->vval;
|
||||||
|
|
||||||
/* return now */
|
/* return now */
|
||||||
return EXPR_ERROR_NOERROR;
|
return EXPR_ERROR_NOERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
cur = cur->next;
|
cur = cur->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If we got here, we did not find the item in the list */
|
/* If we got here, we did not find the item in the list */
|
||||||
return EXPR_ERROR_NOTFOUND;
|
return EXPR_ERROR_NOTFOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add an address to the list */
|
/* Add an address to the list */
|
||||||
int exprValListAddAddress(exprValList *vlist, char *name, EXPRTYPE *addr)
|
int exprValListAddAddress(exprValList *vlist, char *name, EXPRTYPE *addr)
|
||||||
{
|
{
|
||||||
exprVal *tmp;
|
exprVal *tmp;
|
||||||
exprVal *cur;
|
exprVal *cur;
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
if(vlist == NULL)
|
if(vlist == NULL)
|
||||||
return EXPR_ERROR_NULLPOINTER;
|
return EXPR_ERROR_NULLPOINTER;
|
||||||
|
|
||||||
/* Make sure the name is valid */
|
/* Make sure the name is valid */
|
||||||
if(!exprValidIdent(name))
|
if(!exprValidIdent(name))
|
||||||
return EXPR_ERROR_BADIDENTIFIER;
|
return EXPR_ERROR_BADIDENTIFIER;
|
||||||
|
|
||||||
if(vlist->head == NULL)
|
if(vlist->head == NULL)
|
||||||
{
|
{
|
||||||
/* Create the node right here */
|
/* Create the node right here */
|
||||||
tmp = exprCreateVal(name, (EXPRTYPE)0.0, addr);
|
tmp = exprCreateVal(name, (EXPRTYPE)0.0, addr);
|
||||||
|
|
||||||
if(tmp == NULL)
|
if(tmp == NULL)
|
||||||
return EXPR_ERROR_MEMORY;
|
return EXPR_ERROR_MEMORY;
|
||||||
|
|
||||||
vlist->head = tmp;
|
vlist->head = tmp;
|
||||||
return EXPR_ERROR_NOERROR;
|
return EXPR_ERROR_NOERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* See if it already exists */
|
/* See if it already exists */
|
||||||
cur = vlist->head;
|
cur = vlist->head;
|
||||||
|
|
||||||
while(cur)
|
while(cur)
|
||||||
{
|
{
|
||||||
result = strcmp(name, cur->vname);
|
result = strcmp(name, cur->vname);
|
||||||
|
|
||||||
if(result == 0)
|
if(result == 0)
|
||||||
return EXPR_ERROR_ALREADYEXISTS;
|
return EXPR_ERROR_ALREADYEXISTS;
|
||||||
|
|
||||||
cur = cur->next;
|
cur = cur->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add it to the list */
|
/* Add it to the list */
|
||||||
tmp = exprCreateVal(name, (EXPRTYPE)0.0, addr);
|
tmp = exprCreateVal(name, (EXPRTYPE)0.0, addr);
|
||||||
|
|
||||||
if(tmp == NULL)
|
if(tmp == NULL)
|
||||||
return EXPR_ERROR_MEMORY;
|
return EXPR_ERROR_MEMORY;
|
||||||
|
|
||||||
tmp->next = vlist->head;
|
tmp->next = vlist->head;
|
||||||
vlist->head = tmp;
|
vlist->head = tmp;
|
||||||
|
|
||||||
return EXPR_ERROR_NOERROR;
|
return EXPR_ERROR_NOERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get memory address of a variable value in a value list */
|
/* Get memory address of a variable value in a value list */
|
||||||
int exprValListGetAddress(exprValList *vlist, char *name, EXPRTYPE **addr)
|
int exprValListGetAddress(exprValList *vlist, char *name, EXPRTYPE **addr)
|
||||||
{
|
{
|
||||||
exprVal *cur;
|
exprVal *cur;
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
/* Not found yet */
|
/* Not found yet */
|
||||||
*addr = NULL;
|
*addr = NULL;
|
||||||
|
|
||||||
if(vlist == NULL || addr == NULL)
|
if(vlist == NULL || addr == NULL)
|
||||||
return EXPR_ERROR_NULLPOINTER;
|
return EXPR_ERROR_NULLPOINTER;
|
||||||
|
|
||||||
|
|
||||||
if(name == NULL || name[0] == '\0')
|
if(name == NULL || name[0] == '\0')
|
||||||
return EXPR_ERROR_NOTFOUND;
|
return EXPR_ERROR_NOTFOUND;
|
||||||
|
|
||||||
/* Search for the item */
|
/* Search for the item */
|
||||||
cur = vlist->head;
|
cur = vlist->head;
|
||||||
|
|
||||||
while(cur)
|
while(cur)
|
||||||
{
|
{
|
||||||
result = strcmp(name, cur->vname);
|
result = strcmp(name, cur->vname);
|
||||||
|
|
||||||
if(result == 0)
|
if(result == 0)
|
||||||
{
|
{
|
||||||
/* We found it. */
|
/* We found it. */
|
||||||
if(cur->vptr)
|
if(cur->vptr)
|
||||||
*addr = cur->vptr;
|
*addr = cur->vptr;
|
||||||
else
|
else
|
||||||
*addr = &(cur->vval);
|
*addr = &(cur->vval);
|
||||||
|
|
||||||
/* return now */
|
/* return now */
|
||||||
return EXPR_ERROR_NOERROR;
|
return EXPR_ERROR_NOERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
cur = cur->next;
|
cur = cur->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If we got here, we did not find it in the list */
|
/* If we got here, we did not find it in the list */
|
||||||
return EXPR_ERROR_NOTFOUND;
|
return EXPR_ERROR_NOTFOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This function is used to enumerate the values in a value list */
|
/* This function is used to enumerate the values in a value list */
|
||||||
void *exprValListGetNext(exprValList *vlist, char **name, EXPRTYPE *value, EXPRTYPE** addr, void *cookie)
|
void *exprValListGetNext(exprValList *vlist, char **name, EXPRTYPE *value, EXPRTYPE** addr, void *cookie)
|
||||||
{
|
{
|
||||||
exprVal *cur;
|
exprVal *cur;
|
||||||
|
|
||||||
if(vlist == NULL)
|
if(vlist == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
/* Get the current item */
|
/* Get the current item */
|
||||||
cur = (exprVal*)cookie;
|
cur = (exprVal*)cookie;
|
||||||
|
|
||||||
/* Find the next item */
|
/* Find the next item */
|
||||||
if(cur == NULL)
|
if(cur == NULL)
|
||||||
cur = vlist->head;
|
cur = vlist->head;
|
||||||
else
|
else
|
||||||
cur = cur->next;
|
cur = cur->next;
|
||||||
|
|
||||||
/* Set up the data */
|
/* Set up the data */
|
||||||
if(cur)
|
if(cur)
|
||||||
{
|
{
|
||||||
if(name)
|
if(name)
|
||||||
*name = cur->vname;
|
*name = cur->vname;
|
||||||
|
|
||||||
if(value)
|
if(value)
|
||||||
{
|
{
|
||||||
if(cur->vptr)
|
if(cur->vptr)
|
||||||
*value = *(cur->vptr);
|
*value = *(cur->vptr);
|
||||||
else
|
else
|
||||||
*value = cur->vval;
|
*value = cur->vval;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(addr)
|
if(addr)
|
||||||
{
|
{
|
||||||
if(cur->vptr)
|
if(cur->vptr)
|
||||||
*addr = cur->vptr;
|
*addr = cur->vptr;
|
||||||
else
|
else
|
||||||
*addr = &(cur->vval);
|
*addr = &(cur->vval);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If there was no value, return NULL, otherwise, return the item */
|
/* If there was no value, return NULL, otherwise, return the item */
|
||||||
return (void*)cur;
|
return (void*)cur;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This routine will free the value list */
|
/* This routine will free the value list */
|
||||||
int exprValListFree(exprValList *vlist)
|
int exprValListFree(exprValList *vlist)
|
||||||
{
|
{
|
||||||
/* Make sure it exists, if not it is not error */
|
/* Make sure it exists, if not it is not error */
|
||||||
if(vlist == NULL)
|
if(vlist == NULL)
|
||||||
return EXPR_ERROR_NOERROR;
|
return EXPR_ERROR_NOERROR;
|
||||||
|
|
||||||
/* Free the nodes */
|
/* Free the nodes */
|
||||||
exprValListFreeData(vlist->head);
|
exprValListFreeData(vlist->head);
|
||||||
|
|
||||||
/* Freethe container */
|
/* Freethe container */
|
||||||
exprFreeMem(vlist);
|
exprFreeMem(vlist);
|
||||||
|
|
||||||
return EXPR_ERROR_NOERROR;
|
return EXPR_ERROR_NOERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This routine will reset the value list to 0.0 */
|
/* This routine will reset the value list to 0.0 */
|
||||||
int exprValListClear(exprValList *vlist)
|
int exprValListClear(exprValList *vlist)
|
||||||
{
|
{
|
||||||
if(vlist == NULL)
|
if(vlist == NULL)
|
||||||
return EXPR_ERROR_NOERROR;
|
return EXPR_ERROR_NOERROR;
|
||||||
|
|
||||||
exprValListResetData(vlist->head);
|
exprValListResetData(vlist->head);
|
||||||
|
|
||||||
return EXPR_ERROR_NOERROR;
|
return EXPR_ERROR_NOERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This routine will free any child nodes, and then free itself */
|
/* This routine will free any child nodes, and then free itself */
|
||||||
static void exprValListFreeData(exprVal *val)
|
static void exprValListFreeData(exprVal *val)
|
||||||
{
|
{
|
||||||
exprVal *next;
|
exprVal *next;
|
||||||
|
|
||||||
while(val)
|
while(val)
|
||||||
{
|
{
|
||||||
/* Remember the next */
|
/* Remember the next */
|
||||||
next = val->next;
|
next = val->next;
|
||||||
|
|
||||||
/* Free name */
|
/* Free name */
|
||||||
exprFreeMem(val->vname);
|
exprFreeMem(val->vname);
|
||||||
|
|
||||||
/* Free ourself */
|
/* Free ourself */
|
||||||
exprFreeMem(val);
|
exprFreeMem(val);
|
||||||
|
|
||||||
val = next;
|
val = next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This routine will reset variables to 0.0 */
|
/* This routine will reset variables to 0.0 */
|
||||||
static void exprValListResetData(exprVal *val)
|
static void exprValListResetData(exprVal *val)
|
||||||
{
|
{
|
||||||
while(val)
|
while(val)
|
||||||
{
|
{
|
||||||
/* Reset data */
|
/* Reset data */
|
||||||
if(val->vptr)
|
if(val->vptr)
|
||||||
*(val->vptr) = 0.0;
|
*(val->vptr) = 0.0;
|
||||||
|
|
||||||
val->vval = 0.0;
|
val->vval = 0.0;
|
||||||
|
|
||||||
val = val->next;
|
val = val->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This routine will create the value object */
|
/* This routine will create the value object */
|
||||||
static exprVal *exprCreateVal(char *name, EXPRTYPE val, EXPRTYPE *addr)
|
static exprVal *exprCreateVal(char *name, EXPRTYPE val, EXPRTYPE *addr)
|
||||||
{
|
{
|
||||||
exprVal *tmp;
|
exprVal *tmp;
|
||||||
char *vtmp;
|
char *vtmp;
|
||||||
|
|
||||||
/* Name already tested in exprValListAdd */
|
/* Name already tested in exprValListAdd */
|
||||||
|
|
||||||
/* Create it */
|
/* Create it */
|
||||||
tmp = exprAllocMem(sizeof(exprVal));
|
tmp = exprAllocMem(sizeof(exprVal));
|
||||||
if(tmp == NULL)
|
if(tmp == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
/* Allocate space for the name */
|
/* Allocate space for the name */
|
||||||
vtmp = exprAllocMem(strlen(name) + 1);
|
vtmp = exprAllocMem(strlen(name) + 1);
|
||||||
|
|
||||||
if(vtmp == NULL)
|
if(vtmp == NULL)
|
||||||
{
|
{
|
||||||
exprFreeMem(tmp);
|
exprFreeMem(tmp);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Copy the data over */
|
/* Copy the data over */
|
||||||
strcpy(vtmp, name);
|
strcpy(vtmp, name);
|
||||||
tmp->vname = vtmp;
|
tmp->vname = vtmp;
|
||||||
tmp->vval = val;
|
tmp->vval = val;
|
||||||
tmp->vptr = addr;
|
tmp->vptr = addr;
|
||||||
|
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue