/* * * 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 "Main.hpp" #include "RunConfig.hpp" #include #include #include "DataRef.hpp" #include "ScreenRef.hpp" #include "Logic.hpp" #include "LogicCommands.hpp" #include "RepositoryCommand.hpp" #include extern GtkWidget *activeScreen; /* Built-In Functions */ extern BiAppnPtr biAppnPtr; extern BiAppnDevPtr biAppnDevPtr; extern BiValidateStatusPtr biValidateStatusPtr; extern BiDataModelStatusPtr biDataModelStatusPtr; extern BiErrorReturnPtr biErrorReturnPtr; extern BiSqlInfoPtr biSqlInfoPtr; extern BiSqlReturnPtr biSqlReturnPtr; extern BiSqlStatusPtr biSqlStatusPtr; extern BiRepositoryStatusPtr biRepositoryStatusPtr; extern BiTableStatusPtr biTableStatusPtr; extern BiThreadStatusPtr biThreadStatusPtr; extern BiThreadExitPtr biThreadExitPtr; extern BiListColCountPtr biListColCountPtr; extern BiListRowCountPtr biListRowCountPtr; extern BiFalsePtr biFalsePtr; extern BiTextStatusPtr biTextStatusPtr; extern BiUserPtr biUserPtr; extern BiXmlStatusPtr biXmlStatusPtr; extern BiTruePtr biTruePtr; extern BiQuitLastScreenPtr biQuitLastScreenPtr; /* Local variable (L-) */ extern DataDictionaryPtr dicPtr; /* Data Model (M-) */ extern DataModelPtr dmPtr; /* Constant (C-) */ extern ConstantPtr consPtr; /* Global variable (V-) */ extern VariablePtr varPtr; /* VariableGroup (G-) */ extern VariableGroupPtr vgrpPtr; /* Table.Record (F-) */ extern TablePtr tablePtr; /* PickList (P-) */ extern PickListPtr pickPtr; /* Web Parameter */ extern BiWebParameterPtr biWebPtr; char *exitLogicValue = NULL; /* Logic Data Return */ extern DataReturnPtr dataPtr; char *triml(char *str) { if (str != NULL) { while (*str != '\0' && isspace(*str)) str++; } return str; } char *trimr(char *str) { if (str != NULL) { while ((strlen(str) > 0) && (isspace(str[strlen(str)-1]))) str[strlen(str)-1] = '\0'; } return str; } char *UnstringDataRefValue(char *dataRefIn, char *dataRefOut) { int strLen; if (dataRefIn == NULL) { strcpy(dataRefOut,""); return dataRefOut; } strcpy(dataRefOut,dataRefIn); strLen = strlen(dataRefIn); if ( (strLen > 1) && (dataRefIn[0] == '\"') && (dataRefIn[(strLen-1)] == '\"')) { /* DataRef is string */ strcpy(dataRefOut, (dataRefIn+1)); dataRefOut[(strLen-2)] = '\0'; } return dataRefOut; } char *stringRaw(char *dataRefValue, int length, char padChar, char justification) { char *start, *value; /* Get value */ value = new char[(strlen(dataRefValue)+1)]; strcpy(value, dataRefValue); /* Populate with pad character */ memset(dataRefValue, padChar, length); dataRefValue[length] = '\0'; /* Calculate starting point */ if (justification == XB_JTF_LEFT_CHAR) start = dataRefValue; else if (justification == XB_JTF_CENTER_CHAR) start = dataRefValue + (length - strlen(value))/2; else start = dataRefValue + length - strlen(value); /* Insert data */ memcpy(start, value, strlen(value)); /* Clean up */ delete value; /* Return */ return dataRefValue; } char *getDataRefData(char *dataRef, bool isMainThread, char *dataRefValue, int &retLength, char &retPadChar, char &retJustification, bool allocate_mem) { int strLen, i, j; char *token, *listName = NULL, *paramName = NULL, *paramValue, retValue[255], tmpValue[1024]; char *string, *substrExt; struct tm s; time_t t; time(&t); bool isSubString = false; int ssPos = 0, ssLen = 0, tmpLen; /* Init */ retLength = 0; retPadChar = ' '; retJustification = XB_JTF_LEFT_CHAR; /* If no match, return nothing */ if (allocate_mem == true) dataRefValue = NULL; else strcpy(dataRefValue, ""); /* Set original length */ strLen = strlen(dataRef); /* If substring, split */ if (dataRef[strLen-1] == ']') { isSubString = true; strcpy(tmpValue, dataRef); token = strtok((char *)tmpValue, "["); i = 1; while (token != NULL) { if (i == 1) string = token; else if (i == 2) substrExt = token; token = strtok(NULL, "["); i++; } strcpy(dataRef, string); /* Split position and range */ substrExt[(strlen(substrExt)-1)] = '\0'; strcpy(tmpValue, substrExt); token = strtok((char *)tmpValue, ","); i = 1; while (token != NULL) { if (i == 1) ssPos = atoi(token); else if (i == 2) ssLen = atoi(token); token = strtok(NULL, ","); i++; } } /* Set original length */ strLen = strlen(dataRef); /* Determine which dataref */ if ((dataRef[0] == 'V') && (dataRef[1] == '-')) { if (varPtr->getValueData(&varPtr, dataRef+2, retLength, retPadChar, retJustification) == NULL) { if (allocate_mem == true) dataRefValue = NULL; else dataRefValue[0] = '\0'; } else if (allocate_mem == true) dataRefValue = new char[strlen(varPtr->getValueData(&varPtr, dataRef+2, retLength, retPadChar, retJustification))+1]; strcpy(dataRefValue, varPtr->getValueData(&varPtr, dataRef+2, retLength, retPadChar, retJustification)); } else if ((dataRef[0] == 'C') && (dataRef[1] == '-')) { if (consPtr->getValueData(&consPtr, dataRef+2, retLength, retPadChar, retJustification) == NULL) { if (allocate_mem == true) dataRefValue = NULL; else dataRefValue[0] = '\0'; } else if (allocate_mem == true) dataRefValue = new char[strlen(consPtr->getValueData(&consPtr, dataRef+2, retLength, retPadChar, retJustification))+1]; strcpy(dataRefValue, consPtr->getValueData(&consPtr, dataRef+2, retLength, retPadChar, retJustification)); } else if ((dataRef[0] == 'L') && (dataRef[1] == '-')) { if (dicPtr->getValueData(&dicPtr, dataRef+2, retLength, retPadChar, retJustification) == NULL) { if (allocate_mem == true) dataRefValue = NULL; else dataRefValue[0] = '\0'; } else if (allocate_mem == true) dataRefValue = new char[strlen(dicPtr->getValueData(&dicPtr, dataRef+2, retLength, retPadChar, retJustification))+1]; strcpy(dataRefValue, dicPtr->getValueData(&dicPtr, dataRef+2, retLength, retPadChar, retJustification)); } else if ((dataRef[0] == 'G') && (dataRef[1] == '-')) { if (vgrpPtr->getValueData(&vgrpPtr, dataRef+2, retLength, retPadChar, retJustification) == NULL) { if (allocate_mem == true) dataRefValue = NULL; else dataRefValue[0] = '\0'; } else if (allocate_mem == true) dataRefValue = new char[strlen(vgrpPtr->getValueData(&vgrpPtr, dataRef+2, retLength, retPadChar, retJustification))+1]; strcpy(dataRefValue, vgrpPtr->getValueData(&vgrpPtr, dataRef+2, retLength, retPadChar, retJustification)); } else if ((dataRef[0] == 'F') && (dataRef[1] == '-')) { if (tablePtr->getValueData(&tablePtr, dataRef+2, retLength, retPadChar, retJustification) == NULL) { if (allocate_mem == true) dataRefValue = NULL; else dataRefValue[0] = '\0'; } else if (allocate_mem == true) dataRefValue = new char[strlen(tablePtr->getValueData(&tablePtr, dataRef+2, retLength, retPadChar, retJustification))+1]; strcpy(dataRefValue, tablePtr->getValueData(&tablePtr, dataRef+2, retLength, retPadChar, retJustification)); } else if ((dataRef[0] == 'M') && (dataRef[1] == '-')) { if (dmPtr->getValue(dmPtr, dataRef+2) == NULL) { if (allocate_mem == true) dataRefValue = NULL; else dataRefValue[0] = '\0'; } else if (allocate_mem == true) dataRefValue = new char[strlen(dmPtr->getValue(dmPtr, dataRef+2))+1]; strcpy(dataRefValue, dmPtr->getValue(dmPtr, dataRef+2)); } else if ((dataRef[0] == 'P') && (dataRef[1] == '-')) { if (pickPtr->getValue(&pickPtr, dataRef+2) == NULL) { if (allocate_mem == true) dataRefValue = NULL; else dataRefValue[0] = '\0'; } else if (allocate_mem == true) dataRefValue = new char[strlen(pickPtr->getValue(&pickPtr, dataRef+2))+1]; strcpy(dataRefValue, pickPtr->getValue(&pickPtr, dataRef+2)); } else if ((dataRef[0] == 'S') && (dataRef[1] == '-')) { if (allocate_mem == true) dataRefValue = new char[strlen(getScreenWidgetData(dataRef+2, isMainThread, activeScreen, dataRefValue, allocate_mem))+1]; getScreenWidgetData(dataRef+2, isMainThread, activeScreen, dataRefValue, allocate_mem); } else if ((dataRef[0] == 'T') && (dataRef[1] == '-')) { if (tablePtr->getExternalName(&tablePtr, dataRef+2) == NULL) { if (allocate_mem == true) dataRefValue = NULL; else dataRefValue[0] = '\0'; } else if (allocate_mem == true) dataRefValue = new char[strlen(tablePtr->getExternalName(&tablePtr, dataRef+2))+1]; strcpy(dataRefValue, tablePtr->getExternalName(&tablePtr, dataRef+2)); } else if ((dataRef[0] == 'X') && (dataRef[1] == '-')) getContentsTextDocument(dataRef+2, dataRefValue); else if ((dataRef[0] == '"') && (dataRef[(strLen-1)] == '"')) { if (dataRef == NULL) { if (allocate_mem == true) dataRefValue = NULL; else dataRefValue[0] = '\0'; } else { if (allocate_mem == true) dataRefValue = new char[strlen((dataRef+1))+1]; strcpy(dataRefValue, (dataRef+1)); dataRefValue[(strLen-2)] = '\0'; } } /* Built-In commands */ else if ( strcmp(dataRef, "APPN()") == 0) { if (allocate_mem == true) dataRefValue = new char[strlen(biAppnPtr->getAppn())+1]; sprintf(dataRefValue, "%s", biAppnPtr->getAppn()); } else if ( strcmp(dataRef, "APPNDEV()") == 0) { if (allocate_mem == true) dataRefValue = new char[strlen(biAppnDevPtr->getAppnDev())+1]; sprintf(dataRefValue, "%s", biAppnDevPtr->getAppnDev()); } else if ( strncmp(dataRef, "CLIP", 4) == 0) { token = strtok(dataRef, "("); i = 1; while (token != NULL) { if (i == 2) paramName = token; token = strtok(NULL, ")"); i++; } if (paramName == NULL) { if (allocate_mem == true) dataRefValue = NULL; else strcpy(dataRefValue, ""); } else { //sprintf(dataRefValue, "%s", getDataRef(paramName, isMainThread, retValue, false)); getDataRef(paramName, isMainThread, retValue, false); triml(retValue); trimr(retValue); if (allocate_mem == true) dataRefValue = new char[strlen(retValue)+1]; sprintf(dataRefValue, "%s", retValue); } } else if ( strcmp(dataRef, "COMPILEINFO()") == 0) { if (allocate_mem == true) dataRefValue = new char[1024]; strcpy(dataRefValue,"- GNOME/GTK+ GUI \n- 4GL Interpreter"); #ifdef BUILD_REPOSITORY strcat(dataRefValue, "\n- Repository"); #endif #ifdef BUILD_VALIDATE strcat(dataRefValue, "\n- Validate Engine"); #endif #ifdef BUILD_DATA strcat(dataRefValue, "\n- Data Engine"); #endif } else if ( strcmp(dataRef, "CONFIGFILE()") == 0) { if (allocate_mem == true) dataRefValue = new char[strlen(DEF_CONFIG_FILE)+1]; sprintf(dataRefValue, "%s", DEF_CONFIG_FILE); } else if ( strcmp(dataRef, "DATAMODELSTATUS()") == 0) { if (allocate_mem == true) dataRefValue = new char[32]; sprintf(dataRefValue, "%d", biDataModelStatusPtr->getDataModelStatus()); } else if ( strcmp(dataRef, "DATE()") == 0) { if (allocate_mem == true) dataRefValue = new char[11]; s = *localtime(&t); sprintf(dataRefValue, "%d-%02d-%02d", s.tm_year + 1900, s.tm_mon + 1, s.tm_mday); } else if ( strcmp(dataRef, "ERRORRETURN()") == 0) { if (allocate_mem == true) dataRefValue = new char[32]; sprintf(dataRefValue, "%d", biErrorReturnPtr->getErrorReturn()); } else if ( strncmp(dataRef, "LENGTH", 6) == 0) { token = strtok(dataRef, "("); i = 1; while (token != NULL) { if (i == 2) paramName = token; token = strtok(NULL, ")"); i++; } if (paramName == NULL) { if (allocate_mem == true) dataRefValue = new char[2]; strcpy(dataRefValue, "0"); } else { if (allocate_mem == true) dataRefValue = new char[32]; sprintf(dataRefValue, "%ld", strlen(getDataRef(paramName, isMainThread, retValue, false))); } } else if ( strncmp(dataRef, "LISTCOLCOUNT", 12) == 0) { token = strtok(dataRef, "("); i = 1; while (token != NULL) { if (i == 2) listName = token; token = strtok(NULL, ")"); i++; } if (listName == NULL) { if (allocate_mem == true) dataRefValue = new char[2]; sprintf(dataRefValue, "0"); } else { if (allocate_mem == true) dataRefValue = new char[32]; sprintf(dataRefValue, "%d", biListColCountPtr->getListColCount(getDataRef(listName, isMainThread, retValue, false))); //printf("!!!!!!!!!!!!!%d\n", biListColCountPtr->getListColCount(getDataRef(listName, isMainThread, retValue, false))); } } else if ( strncmp(dataRef, "LISTROWCOUNT", 12) == 0) { token = strtok(dataRef, "("); i = 1; while (token != NULL) { if (i == 2) listName = token; token = strtok(NULL, ")"); i++; } if (listName == NULL) { if (allocate_mem == true) dataRefValue = new char[2]; sprintf(dataRefValue, "0"); } else { if (allocate_mem == true) dataRefValue = new char[32]; sprintf(dataRefValue, "%d", biListRowCountPtr->getListRowCount(getDataRef(listName, isMainThread, retValue, false), isMainThread)); } } else if ( strcmp(dataRef, "FALSE()") == 0) { /* Load class if not already loaded */ if (biFalsePtr == NULL) biFalsePtr = new class BiFalse; if (allocate_mem == true) dataRefValue = new char[strlen(biFalsePtr->getFalse())+1]; sprintf(dataRefValue, "%s", biFalsePtr->getFalse()); } else if ( strcmp(dataRef, "TRUE()") == 0) { /* Load class if not already loaded */ if (biTruePtr == NULL) biTruePtr = new class BiTrue; if (allocate_mem == true) dataRefValue = new char[strlen(biTruePtr->getTrue())+1]; sprintf(dataRefValue, "%s", biTruePtr->getTrue()); } else if ( strcmp(dataRef, "NEWLINE()") == 0) { if (allocate_mem == true) dataRefValue = new char[2]; strcpy(dataRefValue, "\n"); } else if ( strncmp(dataRef, "REPOSITORYINFO", 14) == 0) { token = strtok(dataRef, "("); i = 1; while (token != NULL) { if (i == 2) paramName = token; token = strtok(NULL, ")"); i++; } if (paramName == NULL) { if (allocate_mem == true) dataRefValue = NULL; else strcpy(dataRefValue, ""); } else if (strlen(paramName) == 0) { if (allocate_mem == true) dataRefValue = NULL; else strcpy(dataRefValue, ""); } else { if (repSysInfoSetting(getDataRef(paramName, isMainThread, retValue, false),tmpValue) == 0) { if (allocate_mem == true) dataRefValue = new char[strlen(tmpValue)+1]; strcpy(dataRefValue, tmpValue); } else { if (allocate_mem == true) dataRefValue = NULL; else strcpy(dataRefValue, ""); } } } else if ( strcmp(dataRef, "QUITLASTSCREEN()") == 0) { if (allocate_mem == true) dataRefValue = new char[32]; sprintf(dataRefValue, "%d", biQuitLastScreenPtr->getQuitLastScreen()); } else if ( strcmp(dataRef, "SQLINFO()") == 0) { if (allocate_mem == true) dataRefValue = new char[strlen(biSqlInfoPtr->getSqlInfo())+1]; sprintf(dataRefValue, "%s", biSqlInfoPtr->getSqlInfo()); } else if ( strcmp(dataRef, "SQLRETURN()") == 0) { if (allocate_mem == true) dataRefValue = new char[32]; sprintf(dataRefValue, "%d", biSqlReturnPtr->getSqlReturn()); } else if ( strcmp(dataRef, "SQLSTATUS()") == 0) { if (allocate_mem == true) dataRefValue = new char[32]; sprintf(dataRefValue, "%d", biSqlStatusPtr->getSqlStatus()); } else if ( strcmp(dataRef, "REPOSITORYSTATUS()") == 0) { if (allocate_mem == true) dataRefValue = new char[32]; sprintf(dataRefValue, "%d", biRepositoryStatusPtr->getRepositoryStatus()); } else if ( strcmp(dataRef, "TABLESTATUS()") == 0) { if (allocate_mem == true) dataRefValue = new char[32]; sprintf(dataRefValue, "%d", biTableStatusPtr->getTableStatus()); } else if ( strcmp(dataRef, "THREADSTATUS()") == 0) { if (allocate_mem == true) dataRefValue = new char[32]; sprintf(dataRefValue, "%d", biThreadStatusPtr->getThreadStatus()); } else if ( strcmp(dataRef, "THREADEXIT()") == 0) { /* Load class if not already loaded */ if (biFalsePtr == NULL) biFalsePtr = new class BiFalse; if (biTruePtr == NULL) biTruePtr = new class BiTrue; //printf("Thread id from THREADEXIT %ld\n", pthread_self()); if (biThreadExitPtr->getThreadExit(pthread_self()) == true) { if (allocate_mem == true) dataRefValue = new char[strlen(biTruePtr->getTrue())+1]; sprintf(dataRefValue, "%s", biTruePtr->getTrue()); } else { if (allocate_mem == true) dataRefValue = new char[strlen(biFalsePtr->getFalse())+1]; sprintf(dataRefValue, "%s", biFalsePtr->getFalse()); } } else if ( strcmp(dataRef, "TIME()") == 0) { s = *localtime(&t); if (allocate_mem == true) dataRefValue = new char[10]; sprintf(dataRefValue, "%02d:%02d:%02d", s.tm_hour, s.tm_min, s.tm_sec); } else if ( strcmp(dataRef, "TEXTSTATUS()") == 0) { if (allocate_mem == true) dataRefValue = new char[32]; sprintf(dataRefValue, "%d", biTextStatusPtr->getTextStatus()); } else if ( strcmp(dataRef, "UTCSTAMP()") == 0) { if (allocate_mem == true) dataRefValue = new char[30]; s = *gmtime(&t); sprintf(dataRefValue, "%d-%02d-%02dT%02d:%02d:%02dZ", s.tm_year + 1900, s.tm_mon + 1, s.tm_mday, s.tm_hour, s.tm_min, s.tm_sec); } else if ( strcmp(dataRef, "USER()") == 0) { if (allocate_mem == true) dataRefValue = new char[strlen(biUserPtr->getUser())+1]; sprintf(dataRefValue, "%s", biUserPtr->getUser()); } else if ( strcmp((dataRef), "VALIDATESTATUS()") == 0) { if (allocate_mem == true) dataRefValue = new char[32]; sprintf(dataRefValue, "%d", biValidateStatusPtr->getValidateStatus()); } else if ( strcmp(dataRef, "VERSION()") == 0) { if (allocate_mem == true) dataRefValue = new char[strlen(VERSION)+1]; sprintf(dataRefValue, "%s", VERSION); } else if ( strncmp(dataRef, "WEBPARAMETER", 12) == 0) { token = strtok(dataRef, "("); i = 1; while (token != NULL) { if (i == 2) paramName = token; token = strtok(NULL, ")"); i++; } if (paramName == NULL) { if (allocate_mem == true) dataRefValue = NULL; else strcpy(dataRefValue, ""); } else { paramValue = biWebPtr->getValue(biWebPtr, getDataRef(paramName, isMainThread, retValue, false)); if (paramValue == NULL) { if (allocate_mem == true) dataRefValue = NULL; else strcpy(dataRefValue, ""); } else { if (allocate_mem == true) dataRefValue = new char[strlen(paramValue)+1]; sprintf(dataRefValue, "%s", paramValue); } } } else if ( strcmp(dataRef, "XMLSTATUS()") == 0) { if (allocate_mem == true) dataRefValue = new char[32]; sprintf(dataRefValue, "%d", biXmlStatusPtr->getXmlStatus()); } else if ( strncmp(dataRef, "TOLOWER", 7) == 0) { token = strtok(dataRef, "("); i = 1; while (token != NULL) { if (i == 2) paramName = token; token = strtok(NULL, ")"); i++; } if (paramName == NULL) { if (allocate_mem == true) dataRefValue = NULL; else strcpy(dataRefValue, ""); } else { if (allocate_mem == true) dataRefValue = new char[strlen(getDataRef(paramName, isMainThread, retValue, false))+1]; strcpy(dataRefValue, getDataRef(paramName, isMainThread, retValue, false)); tmpLen = strlen(dataRefValue); for (i=0; i= ssLen) tmpLen = ssLen; else tmpLen = tmpLen - ssPos + 1; j=0; for (i=0; igetColumns(dmPtr, dataRefDest+2); /* Check if source is VariableGroup(H) or Record(R) */ if (dataRefSource[0] == 'H') { for (i=1; i<=numEntries; i++) { /* Get Date Format Source (if applicable) */ dateFormat = vgrpPtr->getDateFormatSeqNo(vgrpPtr, dataRefSource+2, i); value = vgrpPtr->getValueSeqNo(&vgrpPtr, dataRefSource+2, i); if (dateFormat > 0) { if (value == NULL) value = XB_INVALID_DATE; else { FormatDate(value, dateFormat, valueDate, XB_DT_FORMAT_1); value = valueDate; } } if (value != NULL) dmPtr->updateDataValue(&dmPtr, dataRefDest+2, i, value); else dmPtr->updateDataValue(&dmPtr, dataRefDest+2, i, ""); } } else if (dataRefSource[0] == 'R') { for (i=1; i<=numEntries; i++) { /* Get Date Format Source (if applicable) */ dateFormat = tablePtr->getDateFormatSeqNo(tablePtr, dataRefSource+2, i); value = tablePtr->getValueSeqNo(&tablePtr, dataRefSource+2, i); if (dateFormat > 0) { if (value == NULL) value = XB_INVALID_DATE; else { FormatDate(value, dateFormat, valueDate, XB_DT_FORMAT_1); value = valueDate; } } if (value != NULL) dmPtr->updateDataValue(&dmPtr, dataRefDest+2, i, value); else dmPtr->updateDataValue(&dmPtr, dataRefDest+2, i, ""); } } } void GroupAssignRecord(char *dataRefDest, char *dataRefSource) { int i, numEntries = 0, dateFormat; char *value, valueDate[11]; /* Get number of DataDictionaries Record */ numEntries = tablePtr->getNumEntries(&tablePtr, dataRefDest+2); /* Check if source is VariableGroup(H) or DataModel(O) */ if (dataRefSource[0] == 'H') { for (i=1; i<=numEntries; i++) { value = vgrpPtr->getValueSeqNo(&vgrpPtr, dataRefSource+2, i); if (value != NULL) tablePtr->putValueSeqNo(&tablePtr, dataRefDest+2, i, value); else tablePtr->putValueSeqNo(&tablePtr, dataRefDest+2, i, ""); } } else if (dataRefSource[0] == 'O') { for (i=1; i<=numEntries; i++) { /* Get Date Format Target (if applicable) */ dateFormat = tablePtr->getDateFormatSeqNo(tablePtr, dataRefDest+2, i); value = dmPtr->getDataValueColNo(dmPtr, dataRefSource+2, i); if (dateFormat > 0) { if (value == NULL) value = XB_INVALID_DATE; FormatDate(value, XB_DT_FORMAT_1, valueDate, dateFormat); value = valueDate; } if (value != NULL) tablePtr->putValueSeqNo(&tablePtr, dataRefDest+2, i, value); else tablePtr->putValueSeqNo(&tablePtr, dataRefDest+2, i, ""); } } } void GroupAssignVariableGroup(char *dataRefDest, char *dataRefSource) { int i, numEntries = 0, dateFormat; char *value, valueDate[11]; /* Get number of DataDictionaries Var group */ numEntries = vgrpPtr->getNumEntries(&vgrpPtr, dataRefDest+2); /* Check if source is Record(R) or DataModel(O) */ if (dataRefSource[0] == 'R') { for (i=1; i<=numEntries; i++) { value = tablePtr->getValueSeqNo(&tablePtr, dataRefSource+2, i); if (value != NULL) vgrpPtr->putValueSeqNo(&vgrpPtr, dataRefDest+2, i, value); else vgrpPtr->putValueSeqNo(&vgrpPtr, dataRefDest+2, i, ""); } } else if (dataRefSource[0] == 'O') { for (i=1; i<=numEntries; i++) { /* Get Date Format Target (if applicable) */ dateFormat = tablePtr->getDateFormatSeqNo(tablePtr, dataRefDest+2, i); value = dmPtr->getDataValueColNo(dmPtr, dataRefSource+2, i); if (dateFormat > 0) { if (value == NULL) value = XB_INVALID_DATE; FormatDate(value, XB_DT_FORMAT_1, valueDate, dateFormat); value = valueDate; } if (value != NULL) vgrpPtr->putValueSeqNo(&vgrpPtr, dataRefDest+2, i, value); else vgrpPtr->putValueSeqNo(&vgrpPtr, dataRefDest+2, i, ""); } } else printf("Group assign not implemented (yet).\n"); } /* Put DataRef */ void putDataRef(char *dataRef, char *dataRefValue, int dateFormat, bool isMainThread) { char *tmpValue; int dateFormatTarget; if (dataRefValue == NULL) { tmpValue = new char[2]; strcpy(tmpValue, ""); } else tmpValue = new char[(strlen(dataRefValue)+2)]; /* Simple Assignment */ if ((dataRef[0] == 'V') && (dataRef[1] == '-')) { UnstringDataRefValue(dataRefValue, tmpValue); /* Get Date Format (if applicable) */ dateFormatTarget = getDateFormatDataRef(dataRef); if (dateFormatTarget > 0) { if (dateFormat < 1) dateFormat = dateFormatTarget; // dateFormat = XB_DT_FORMAT_1; if ( (dateFormat > 0) && (dateFormatTarget > 0) && (dateFormat != dateFormatTarget) ) FormatDate(tmpValue, dateFormat, tmpValue, dateFormatTarget); } varPtr->putValue(&varPtr, dataRef+2, tmpValue); } else if ((dataRef[0] == 'L') && (dataRef[1] == '-')) { UnstringDataRefValue(dataRefValue, tmpValue); /* Get Date Format (if applicable) */ dateFormatTarget = getDateFormatDataRef(dataRef); if (dateFormatTarget > 0) { if (dateFormat < 1) dateFormat = dateFormatTarget; if ( (dateFormat > 0) && (dateFormatTarget > 0) && (dateFormat != dateFormatTarget) ) FormatDate(tmpValue, dateFormat, tmpValue, dateFormatTarget); } dicPtr->putValue(&dicPtr, dataRef+2, 1, tmpValue); } else if ((dataRef[0] == 'G') && (dataRef[1] == '-')) { UnstringDataRefValue(dataRefValue, tmpValue); /* Get Date Format (if applicable) */ dateFormatTarget = getDateFormatDataRef(dataRef); if (dateFormatTarget > 0) { if (dateFormat < 1) dateFormat = dateFormatTarget; if ( (dateFormat > 0) && (dateFormatTarget > 0) && (dateFormat != dateFormatTarget) ) FormatDate(tmpValue, dateFormat, tmpValue, dateFormatTarget); } vgrpPtr->putValue(&vgrpPtr, dataRef+2, tmpValue); } else if ((dataRef[0] == 'F') && (dataRef[1] == '-')) { UnstringDataRefValue(dataRefValue, tmpValue); /* Get Date Format (if applicable) */ dateFormatTarget = getDateFormatDataRef(dataRef); if (dateFormatTarget > 0) { if (dateFormat < 1) dateFormat = dateFormatTarget; if ( (dateFormat > 0) && (dateFormatTarget > 0) && (dateFormat != dateFormatTarget) ) FormatDate(tmpValue, dateFormat, tmpValue, dateFormatTarget); } tablePtr->putValue(&tablePtr, dataRef+2, tmpValue); } else if ((dataRef[0] == 'P') && (dataRef[1] == '-')) { pickPtr->putValue(&pickPtr, dataRef+2, UnstringDataRefValue(dataRefValue, tmpValue)); //pickPtr->putValue(&pickPtr, dataRef+2, getDataRef(dataRefValue, isMainThread, tmpValue, false)); } else if ((dataRef[0] == 'S') && (dataRef[1] == '-')) putScreenWidgetData(dataRef+2, UnstringDataRefValue(dataRefValue, tmpValue), isMainThread, activeScreen); else if ((dataRef[0] == 'H') && (dataRef[1] == '-')) GroupAssignVariableGroup(dataRef, dataRefValue); else if ((dataRef[0] == 'R') && (dataRef[1] == '-')) GroupAssignRecord(dataRef, dataRefValue); else if ((dataRef[0] == 'O') && (dataRef[1] == '-')) GroupAssignDataModel(dataRef, dataRefValue); else if ((dataRef[0] == 'M') && (dataRef[1] == '-')) { UnstringDataRefValue(dataRefValue, tmpValue); /* Force date format into CCYY-MM-DD for database compatibility */ if (dateFormat > 0) FormatDate(tmpValue, dateFormat, tmpValue, XB_DT_FORMAT_1); dmPtr->updateDataValueCol(&dmPtr, dataRef+2, tmpValue); } // else if (dataRef[0] == '*') // { // if ( strcmp((dataRef+1), "VALSTATUS") == 0) // caValStatusPtr->setValStatus(atoi(dataRefValue)); // // else if ( strcmp((dataRef+1), "TABLESTATUS") == 0) // biTableStatusPtr->setTableStatus(atoi(dataRefValue)); // } else if ( strcmp((dataRef), "QUITLASTSCREEN()") == 0) biQuitLastScreenPtr->setQuitLastScreen(atoi(dataRefValue)); else if ( strcmp((dataRef), "SQLINFO()") == 0) biSqlInfoPtr->setSqlInfo(dataRefValue); else if ( strcmp((dataRef), "SQLRETURN()") == 0) biSqlReturnPtr->setSqlReturn(atoi(dataRefValue)); else if ( strcmp((dataRef), "SQLSTATUS()") == 0) biSqlStatusPtr->setSqlStatus(atoi(dataRefValue)); else if ( strcmp((dataRef), "REPOSITORYSTATUS()") == 0) biRepositoryStatusPtr->setRepositoryStatus(atoi(dataRefValue)); else if ( strcmp((dataRef), "TABLESTATUS()") == 0) biTableStatusPtr->setTableStatus(atoi(dataRefValue)); else if ( strcmp((dataRef), "THREADSTATUS()") == 0) biThreadStatusPtr->setThreadStatus(atoi(dataRefValue)); else if ( strcmp((dataRef), "VALIDATESTATUS()") == 0) biValidateStatusPtr->setValidateStatus(atoi(dataRefValue)); delete tmpValue; // vgrpPtr->printList(vgrpPtr); } /* Command : LET */ /* Syntax : LET dest_data_ref = src_data_ref [ calculation operator/function src_data_ref ...] */ /* LET dest_data_ref = CALL logic_name [argument ... ] */ void CmdLet(char **argList, int argHits, bool isMainThread, bool idleEvent) { char *calcResult, result[255], expr[255], valueExpand[5120]; char *logicCommand[255], tmpString[255]; char workDate[11]; int i, j, logicArgument, dateFormat; int wDay, wMonth, wYear, dow, calcNum; struct tm calcDate, tmDate1, tmDate2; time_t date1, date2; double diff; PlCalc *calcExpr; //printf("ASSIGN!!!%s - %s\n", argList[1], argList[2]); if (argHits == 3) { /* Simple Assignment */ getDataRef(argList[3], isMainThread, valueExpand, false); /* Get Date Format (if applicable) */ dateFormat = getDateFormatDataRef(argList[3]); /* Store value */ putDataRef(argList[1], valueExpand, dateFormat, isMainThread); } else if (strcmp(argList[3], "CALL") == 0) { /* Assign Return value from logic */ logicArgument = argHits - 3; logicCommand[1] = argList[4]; for (j=1;jgetDataRefValue(dataPtr, 0, retValue); //putDataRef(argList[1], retValue, isMainThread); putDataRef(argList[1], exitLogicValue, 0, isMainThread); //delete exitLogicValue; //exitLogicValue = NULL; } else if (strcmp(argList[3], "CALCDATE") == 0) { /* Get Date Format (if applicable) */ dateFormat = getDateFormatDataRef(argList[4]); getDataRef(argList[4], isMainThread, valueExpand, false); /* Get date into CCYY-MM-DD format */ if (dateFormat > 0) { FormatDate(valueExpand, dateFormat, workDate, XB_DT_FORMAT_1); } else strcpy(workDate, valueExpand); /* Get year */ strncpy(tmpString, workDate, 4); tmpString[4] = '\0'; wYear = atoi(tmpString); /* Get month */ strncpy(tmpString, workDate+5, 2); tmpString[2] = '\0'; wMonth = atoi(tmpString); /* Get day */ strncpy(tmpString, workDate+8, 2); tmpString[2] = '\0'; wDay = atoi(tmpString); if (strcmp(argList[5], "DIFF") == 0) { /* Set values date 1 */ tmDate1.tm_sec = 0; tmDate1.tm_min = 0; tmDate1.tm_hour = 0; tmDate1.tm_mday = wDay; tmDate1.tm_mon = wMonth-1; tmDate1.tm_year = wYear-1900; date1 = mktime(&tmDate1); /* Get Date Format (if applicable) */ dateFormat = getDateFormatDataRef(argList[6]); getDataRef(argList[6], isMainThread, valueExpand, false); /* Get date into CCYY-MM-DD format */ if (dateFormat > 0) { FormatDate(valueExpand, dateFormat, workDate, XB_DT_FORMAT_1); } else strcpy(workDate, valueExpand); /* Get year */ strncpy(tmpString, workDate, 4); tmpString[4] = '\0'; wYear = atoi(tmpString); /* Get month */ strncpy(tmpString, workDate+5, 2); tmpString[2] = '\0'; wMonth = atoi(tmpString); /* Get day */ strncpy(tmpString, workDate+8, 2); tmpString[2] = '\0'; wDay = atoi(tmpString); /* Set values date 2 */ tmDate2.tm_sec = 0; tmDate2.tm_min = 0; tmDate2.tm_hour = 0; tmDate2.tm_mday = wDay; tmDate2.tm_mon = wMonth-1; tmDate2.tm_year = wYear-1900; date2 = mktime(&tmDate2); if ( (date1 != (time_t)-1) || (date2 != (time_t)-1)) { /* Get difference */ diff = difftime(date1, date2)/86400; sprintf(tmpString, "%0.0f", diff); } else { /* Set error if calendar time not available */ strcpy(tmpString, "0"); } /* Store value */ putDataRef(argList[1], tmpString, 0, isMainThread); } else if ((strcmp(argList[5], "+") == 0) || (strcmp(argList[5], "-") == 0)) { /* Get number to calculate with */ getDataRef(argList[7], isMainThread, tmpString, false); calcNum = atoi(tmpString); /* Set date values */ calcDate.tm_sec = 0; calcDate.tm_min = 0; calcDate.tm_hour = 0; calcDate.tm_mday = wDay; calcDate.tm_mon = wMonth-1; calcDate.tm_year = wYear-1900; /* Calc Days */ if (strcmp(argList[6], "DAYS") == 0) { if (strcmp(argList[5], "+") == 0) calcDate.tm_mday = calcDate.tm_mday + calcNum; else calcDate.tm_mday = calcDate.tm_mday - calcNum; } /* Calc Weeks */ else if (strcmp(argList[6], "WEEKS") == 0) { wDay = calcNum * 7; if (strcmp(argList[5], "+") == 0) calcDate.tm_mday = calcDate.tm_mday + wDay; else calcDate.tm_mday = calcDate.tm_mday - wDay; } /* Calc Months */ else if (strcmp(argList[6], "MONTHS") == 0) { if (strcmp(argList[5], "+") == 0) calcDate.tm_mon = calcDate.tm_mon + calcNum; else calcDate.tm_mon = calcDate.tm_mon - calcNum; } /* Get the new date */ if (mktime(&calcDate) != (time_t)-1) { wYear = calcDate.tm_year + 1900; wMonth = calcDate.tm_mon + 1; wDay = calcDate.tm_mday; sprintf(workDate, "%d-%02d-%02d", wYear, wMonth, wDay); /* Store value */ putDataRef(argList[1], workDate, XB_DT_FORMAT_1, isMainThread); } else { /* Set error if calendar time not available */ putDataRef(argList[1], XB_INVALID_DATE, XB_DT_FORMAT_1, isMainThread); } } else if (strcmp(argList[5], "DOW") == 0) { /* Get Day Of Week */ dow = (wDay+=wMonth<3?wYear--:wYear-2,23*wMonth/9+wDay+4+wYear/4-wYear/100+wYear/400)%7; sprintf(tmpString, "%d", dow); /* Store value */ putDataRef(argList[1], tmpString, 0, isMainThread); } else if (strcmp(argList[5], "WEEKNUM") == 0) { /* Set date values */ calcDate.tm_sec = 0; calcDate.tm_min = 0; calcDate.tm_hour = 0; calcDate.tm_mday = wDay; calcDate.tm_mon = wMonth-1; calcDate.tm_year = wYear-1900; if (mktime(&calcDate) != (time_t)-1) { /* Get Week Number */ strftime(tmpString, 255, "%U", &calcDate ); } else { /* Set error if calendar time not available */ strcpy(tmpString, "-1"); } /* Store value */ putDataRef(argList[1], tmpString, 0, isMainThread); } } else if ( (strlen(argList[4]) == 1) && ( isdigit(atoi(argList[4])) == 0 )) { /* Init expr string */ strcpy(expr, ""); /* Get value of Dataref */ for (i=3; i<=argHits; i++) { getDataRef(argList[i], isMainThread, valueExpand, false); if (strcmp(valueExpand, "") == 0) strcat(expr, argList[i]); else strcat(expr, valueExpand); } /* Calculate value */ calcExpr = new PlCalc; calcResult = calcExpr->getCalc(expr); strcpy(result, calcResult); delete calcExpr; /* Assignment */ if (argList[1][0] == 'V') varPtr->putValue(&varPtr, argList[1]+2, result); else if (argList[1][0] == 'L') dicPtr->putValue(&dicPtr, argList[1]+2, 1, result); else if (argList[1][0] == 'G') vgrpPtr->putValue(&vgrpPtr, argList[1]+2, result); else if (argList[1][0] == 'F') tablePtr->putValue(&tablePtr, argList[1]+2, result); else if (argList[1][0] == 'P') pickPtr->putValue(&pickPtr, argList[1]+2, result); } else { strcpy(result, ""); for (i=3; i<=argHits; i++) { getDataRef(argList[i], isMainThread, valueExpand, false); if (strcmp(valueExpand, "") == 0) strcat(result, argList[i]); else strcat(result, valueExpand); } /* Assignment */ if (argList[1][0] == 'V') varPtr->putValue(&varPtr, argList[1]+2, result); else if (argList[1][0] == 'L') dicPtr->putValue(&dicPtr, argList[1]+2, 1, result); else if (argList[1][0] == 'G') vgrpPtr->putValue(&vgrpPtr, argList[1]+2, result); else if (argList[1][0] == 'F') tablePtr->putValue(&tablePtr, argList[1]+2, result); else if (argList[1][0] == 'P') pickPtr->putValue(&pickPtr, argList[1]+2, result); } /* Print List */ // varPtr->printList(varPtr); /* printf("=== VARGRP ===\n"); vgrpPtr->printList(vgrpPtr); printf("=== === ===\n"); printf("=== VAR ===\n"); varPtr->printList(varPtr); printf("=== === ===\n"); */ //printf("END ASSIGN\n"); }