/*
*
* ProLinga-Run
*
* Copyright (C) 2002-2008 Xobas Software.
* All rights reserved.
*
* This file is part of ProLinga-Run.
*
* ProLinga-Run is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ProLinga-Run is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ProLinga-Run. If not, see .
*
* More information is available at the following addresses:
*
* Website : http://www.prolinga.org
*
* Email : prolinga-list@prolinga.org
*
*
*/
#include "RunCommon.h"
#include
#include
#include
//#include "RepositoryCommand.hpp"
#include "DataRef.hpp"
/* Command : IF */
/* Syntax : IF condition [AND/OR condition ... ] THEN */
short CmdIf(char **argList, int argHits, bool isMainThread)
{
char cond1[255], cond2[255], *oper;
short retValue = 0;
int dateFormatLeft, dateFormatRight;
/* left */
getDataRef(argList[1], isMainThread, cond1, false);
dateFormatLeft = getDateFormatDataRef(argList[1]);
if (dateFormatLeft > 1)
FormatDate(cond1, dateFormatLeft, cond1, XB_DT_FORMAT_1);
/* operator */
oper = argList[2];
/* right */
getDataRef(argList[3], isMainThread, cond2, false);
dateFormatRight = getDateFormatDataRef(argList[3]);
if (dateFormatRight > 1)
FormatDate(cond2, dateFormatRight, cond2, XB_DT_FORMAT_1);
//printf("COND1 ~%s~ OPER ~%s~ COND2 ~%s~\n", cond1, oper, cond2);
if (strcmp(oper,"=") == 0)
{
if (strcmp(cond1, cond2) == 0)
retValue = 0;
else
retValue = 1;
}
else if (strcmp(oper,"EQ") == 0)
{
if (strcmp(cond1, cond2) == 0)
retValue = 0;
else
retValue = 1;
}
else if (strcmp(oper,"NEQ") == 0)
{
if (strcmp(cond1, cond2) == 0)
retValue = 1;
else
retValue = 0;
}
else if (strcmp(oper,"<>") == 0)
{
if (strcmp(cond1, cond2) == 0)
retValue = 1;
else
retValue = 0;
}
else if (strcmp(oper,"<") == 0)
{
if (atof(cond1) < atof(cond2))
retValue = 0;
else
retValue = 1;
}
else if (strcmp(oper,">") == 0)
{
if (atof(cond1) > atof(cond2))
retValue = 0;
else
retValue = 1;
}
else if (strcmp(oper,"<=") == 0)
{
if (atof(cond1) <= atof(cond2))
retValue = 0;
else
retValue = 1;
}
else if (strcmp(oper,">=") == 0)
{
if (atof(cond1) >= atof(cond2))
retValue = 0;
else
retValue = 1;
}
//printf("RET %d\n", retValue);
return retValue;
}