- Adapted indenation to new agreed upon system
- Added support for second generation scriptcontext based counter
This commit is contained in:
215
fupa.c
215
fupa.c
@@ -47,127 +47,102 @@
|
||||
#include "splitter.h"
|
||||
#include "fupa.h"
|
||||
|
||||
int EvaluateFuPa(pFuncTemplate pTemplate, int iFunc, int argc, char *argv[],
|
||||
FuPaResult *pRes)
|
||||
{
|
||||
TokenList *pList = NULL;
|
||||
TokenList *pCurrent;
|
||||
int i;
|
||||
int iRet = -1;
|
||||
|
||||
pList = SplitArguments(argc,argv);
|
||||
if(!pList)
|
||||
{
|
||||
strcpy(pRes->pError,"ERROR: cannot parse argument list");
|
||||
return iRet;
|
||||
}
|
||||
int EvaluateFuPa(pFuncTemplate pTemplate, int iFunc, int argc,
|
||||
char *argv[], FuPaResult * pRes)
|
||||
{
|
||||
TokenList *pList = NULL;
|
||||
TokenList *pCurrent;
|
||||
int i;
|
||||
int iRet = -1;
|
||||
|
||||
/* first one must be name, try locate that one first */
|
||||
pCurrent = pList;
|
||||
for(i = 0; i < iFunc; i++)
|
||||
{
|
||||
if(strcmp(pCurrent->text,pTemplate[i].name) == 0)
|
||||
{
|
||||
iRet = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(iRet == -1)
|
||||
{
|
||||
sprintf(pRes->pError,"ERROR: function %s not available",pCurrent->text);
|
||||
goto end;
|
||||
}
|
||||
pList = SplitArguments(argc, argv);
|
||||
if (!pList) {
|
||||
strcpy(pRes->pError, "ERROR: cannot parse argument list");
|
||||
return iRet;
|
||||
}
|
||||
|
||||
/* now try to find arguments */
|
||||
pRes->iArgs = pTemplate[iRet].iArgs;
|
||||
for(i = 0; i < pRes->iArgs; i++)
|
||||
{
|
||||
pCurrent = pCurrent->pNext;
|
||||
/* check presence */
|
||||
if(!pCurrent)
|
||||
{
|
||||
if(pTemplate[iRet].pArgs[i] == FUPAOPT)
|
||||
{
|
||||
pRes->Arg[i].iVal = 0;
|
||||
goto end;
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(pRes->pError,"ERROR: Insufficient number of arguments to %s",
|
||||
pTemplate[iRet].name);
|
||||
iRet = -1;
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
/* check type, optional first */
|
||||
if(pTemplate[iRet].pArgs[i] == FUPAOPT)
|
||||
{
|
||||
pRes->Arg[i].iVal = 1;
|
||||
strcpy(pRes->Arg[i].text,pCurrent->text);
|
||||
if(pCurrent->Type == eInt)
|
||||
{
|
||||
pRes->Arg[i].fVal = pCurrent->iVal;
|
||||
}
|
||||
else if(pCurrent->Type == eFloat)
|
||||
{
|
||||
pRes->Arg[i].fVal = pCurrent->fVal;
|
||||
}
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* now text */
|
||||
if(pTemplate[iRet].pArgs[i] == FUPATEXT) /* text is simple */
|
||||
{
|
||||
strcpy(pRes->Arg[i].text,pCurrent->text);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* check integer */
|
||||
if(pTemplate[iRet].pArgs[i] == FUPAINT)
|
||||
{
|
||||
if(pCurrent->Type == eInt)
|
||||
{
|
||||
pRes->Arg[i].iVal = pCurrent->iVal;
|
||||
continue;
|
||||
}
|
||||
else if(pCurrent->Type == eFloat)
|
||||
{
|
||||
pRes->Arg[i].iVal = (int)pCurrent->fVal;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(pRes->pError,"ERROR: expected integer parameter, got %s",
|
||||
pCurrent->text);
|
||||
iRet = -1;
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
/* first one must be name, try locate that one first */
|
||||
pCurrent = pList;
|
||||
for (i = 0; i < iFunc; i++) {
|
||||
if (strcmp(pCurrent->text, pTemplate[i].name) == 0) {
|
||||
iRet = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (iRet == -1) {
|
||||
sprintf(pRes->pError, "ERROR: function %s not available",
|
||||
pCurrent->text);
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* check float */
|
||||
if(pTemplate[iRet].pArgs[i] == FUPAFLOAT)
|
||||
{
|
||||
if(pCurrent->Type == eInt)
|
||||
{
|
||||
pRes->Arg[i].fVal = (float)pCurrent->iVal;
|
||||
continue;
|
||||
}
|
||||
else if(pCurrent->Type == eFloat)
|
||||
{
|
||||
pRes->Arg[i].fVal = pCurrent->fVal;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(pRes->pError,"ERROR: expected float parameter, got %s",
|
||||
pCurrent->text);
|
||||
iRet = -1;
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* now try to find arguments */
|
||||
pRes->iArgs = pTemplate[iRet].iArgs;
|
||||
for (i = 0; i < pRes->iArgs; i++) {
|
||||
pCurrent = pCurrent->pNext;
|
||||
/* check presence */
|
||||
if (!pCurrent) {
|
||||
if (pTemplate[iRet].pArgs[i] == FUPAOPT) {
|
||||
pRes->Arg[i].iVal = 0;
|
||||
goto end;
|
||||
} else {
|
||||
sprintf(pRes->pError,
|
||||
"ERROR: Insufficient number of arguments to %s",
|
||||
pTemplate[iRet].name);
|
||||
iRet = -1;
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
/* check type, optional first */
|
||||
if (pTemplate[iRet].pArgs[i] == FUPAOPT) {
|
||||
pRes->Arg[i].iVal = 1;
|
||||
strcpy(pRes->Arg[i].text, pCurrent->text);
|
||||
if (pCurrent->Type == eInt) {
|
||||
pRes->Arg[i].fVal = pCurrent->iVal;
|
||||
} else if (pCurrent->Type == eFloat) {
|
||||
pRes->Arg[i].fVal = pCurrent->fVal;
|
||||
}
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* now text */
|
||||
if (pTemplate[iRet].pArgs[i] == FUPATEXT) { /* text is simple */
|
||||
strcpy(pRes->Arg[i].text, pCurrent->text);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* check integer */
|
||||
if (pTemplate[iRet].pArgs[i] == FUPAINT) {
|
||||
if (pCurrent->Type == eInt) {
|
||||
pRes->Arg[i].iVal = pCurrent->iVal;
|
||||
continue;
|
||||
} else if (pCurrent->Type == eFloat) {
|
||||
pRes->Arg[i].iVal = (int) pCurrent->fVal;
|
||||
continue;
|
||||
} else {
|
||||
sprintf(pRes->pError, "ERROR: expected integer parameter, got %s",
|
||||
pCurrent->text);
|
||||
iRet = -1;
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
|
||||
/* check float */
|
||||
if (pTemplate[iRet].pArgs[i] == FUPAFLOAT) {
|
||||
if (pCurrent->Type == eInt) {
|
||||
pRes->Arg[i].fVal = (float) pCurrent->iVal;
|
||||
continue;
|
||||
} else if (pCurrent->Type == eFloat) {
|
||||
pRes->Arg[i].fVal = pCurrent->fVal;
|
||||
continue;
|
||||
} else {
|
||||
sprintf(pRes->pError, "ERROR: expected float parameter, got %s",
|
||||
pCurrent->text);
|
||||
iRet = -1;
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
}
|
||||
end:
|
||||
DeleteTokenList(pList);
|
||||
return iRet;
|
||||
}
|
||||
|
||||
DeleteTokenList(pList);
|
||||
return iRet;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user