/* * * ProLinga-Run * * Copyright (C) 2002-2009 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" extern BiTextStatusPtr biTextStatusPtr; extern TextDocumentPtr textPtr; /* Command : TEXT */ /* Syntax : */ void CmdText(const char **argList, int argHits, bool isMainThread) { int i, ch, lineNo; char shellCmd[255], tmpValue[255], tmpValue2[255], chString[1], *token, *textContents; FILE *fpText; /* Init */ biTextStatusPtr->setTextStatus(0); /* Get option */ if (strcmp(argList[1], "APPEND") == 0) { for (i = 4; i <= argHits; i++) { /* Append Value */ textPtr->appendStringValue(&textPtr, getDataRef(argList[2], isMainThread, tmpValue, false), getDataRefRaw(argList[i], isMainThread, tmpValue2, false)); } } // else if (strcmp(argList[1], "CLEAR") == 0) // { // textPtr->clearDocument(&textPtr, getDataRef(argList[2], isMainThread, tmpValue, false)); // } else if (strcmp(argList[1], "LOAD") == 0) { if (strcmp(argList[4], "FILE") == 0) { /* Open file */ fpText = fopen(getDataRef(argList[5], isMainThread, tmpValue, false), "r"); if (fpText == NULL) { biTextStatusPtr->setTextStatus(10401); return; } /* Read file */ while ((ch = getc(fpText)) != EOF) { sprintf(chString, "%c", ch); strcat(textPtr->getValue(&textPtr, getDataRef(argList[2], isMainThread, tmpValue, false)),chString); } /* Close file */ fclose(fpText); } else { /* Feature not implemented yet */ biTextStatusPtr->setTextStatus(10498); return; } } else if (strcmp(argList[1], "READ") == 0) { /* Get Line number */ lineNo = atoi(getDataRef(argList[4], isMainThread, tmpValue, false)); /* Copy text contents to temp string */ textContents = new char[(strlen(textPtr->getValue(&textPtr, getDataRef(argList[2], isMainThread, tmpValue, false))) + 1)]; strcpy(textContents, textPtr->getValue(&textPtr, getDataRef(argList[2], isMainThread, tmpValue, false))); token = strtok(textContents, "\n"); i = 1; while (token != NULL) { if (i == lineNo) { putDataRef(argList[6], token, 0, isMainThread); delete textContents; return; } token = strtok(NULL, "\n"); i++; } biTextStatusPtr->setTextStatus(10403); delete textContents; } else if (strcmp(argList[1], "REMOVE") == 0) { for (i = 2; i <= argHits; i++) { sprintf(shellCmd, "rm %s 2>1", getDataRef(argList[i], isMainThread, tmpValue, false)); system (shellCmd); } } else if (strcmp(argList[1], "SAVE") == 0) { /* Open file */ if ((argHits == 7) && (strcmp(argList[7], "OVERWRITE") == 0)) fpText = fopen(getDataRef(argList[5], isMainThread, tmpValue, false), "w"); else fpText = fopen(getDataRef(argList[5], isMainThread, tmpValue, false), "a"); if (fpText == NULL) { biTextStatusPtr->setTextStatus(10402); return; } /* Write text buffer to file */ fprintf(fpText,"%s", textPtr->getValue(&textPtr, getDataRef(argList[2], isMainThread, tmpValue, false))); /* Close file */ fclose(fpText); } }