ostr << L"???" << L" = " << std::endl;
}
ostr << std::endl;
- ostr << pOut->toString(ConfigVariable::getFormat(), ConfigVariable::getConsoleWidth()) << std::endl;
+ ostr << pOut->toString(ConfigVariable::getFormat(), ConfigVariable::getConsoleWidth());
YaspWriteW(ostr.str().c_str());
}
}
{
if(pIT->isRef(1) == true)
{
- pIT = pIT->clone();
+ InternalType* pITTemp = pIT->clone();
+ pIT = pITTemp;
bNew = true;
}
}
{
if(bNew)
{
- symbol::Context::getInstance()->put(pVar->name_get(), *((GenericType*)pOut));
+ if(pVar == NULL)
+ {
+ //is not a(x) = y but something like a.b(x) = y
+ //so we have to retrieve struct and children to assign new value
+ InternalType *pHead = NULL;
+ Struct* pMain = NULL;
+ Struct* pCurrent = NULL;
+ bool bOK = getStructFromExp(&pCall->name_get(), &pMain, &pCurrent, NULL, pOut);
+ //change pOut only to toString call
+ pOut = pMain;
+ }
+ else
+ {
+ symbol::Context::getInstance()->put(pVar->name_get(), *((GenericType*)pOut));
+ }
}
if(e.is_verbose())
}
else
{
- ostr << L"???" << L" = " << std::endl;
+ ostr << *getStructNameFromExp(&pCall->name_get()) << L" = " << std::endl;
}
ostr << std::endl;
- ostr << pOut->toString(ConfigVariable::getFormat(), ConfigVariable::getConsoleWidth()) << std::endl;
+ ostr << pOut->toString(ConfigVariable::getFormat(), ConfigVariable::getConsoleWidth());
YaspWriteW(ostr.str().c_str());
}
}
{
std::wostringstream ostr;
ostr << pVar->name_get().name_get() << L" = " << std::endl << std::endl;
- ostr << pIT->toString(ConfigVariable::getFormat(), ConfigVariable::getConsoleWidth()) << std::endl;
+ ostr << pIT->toString(ConfigVariable::getFormat(), ConfigVariable::getConsoleWidth());
YaspWriteW(ostr.str().c_str());
}
}
std::wostringstream ostr;
ostr << pListVar->name_get().name_get() << L" = " << std::endl;
ostr << std::endl;
- ostr << execMeR.result_get(i)->toString(ConfigVariable::getFormat(), ConfigVariable::getConsoleWidth()) << std::endl;
+ ostr << execMeR.result_get(i)->toString(ConfigVariable::getFormat(), ConfigVariable::getConsoleWidth());
YaspWriteW(ostr.str().c_str());
}
i--;
std::wostringstream ostr;
ostr << *pstName << L" = " << std::endl << std::endl;
- ostr << symbol::Context::getInstance()->get(symbol::Symbol(*pstName))->toString(ConfigVariable::getFormat(), ConfigVariable::getConsoleWidth()) << std::endl;
+ ostr << symbol::Context::getInstance()->get(symbol::Symbol(*pstName))->toString(ConfigVariable::getFormat(), ConfigVariable::getConsoleWidth());
YaspWriteW(ostr.str().c_str());
}
}
std::wostringstream ostr;
ostr << e.name_get().name_get() << L" = " << L"(" << pI->getRef() << L")"<< std::endl;
ostr << std::endl;
- ostr << pI->toString(ConfigVariable::getFormat(), ConfigVariable::getConsoleWidth()) << std::endl;
+ ostr << pI->toString(ConfigVariable::getFormat(), ConfigVariable::getConsoleWidth());
YaspWriteW(ostr.str().c_str());
}
}
//TODO manage multiple returns
std::wostringstream ostr;
ostr << L"ans = " << std::endl << std::endl;
- ostr << execMe.result_get()->toString(ConfigVariable::getFormat(), ConfigVariable::getConsoleWidth()) << std::endl;
+ ostr << execMe.result_get()->toString(ConfigVariable::getFormat(), ConfigVariable::getConsoleWidth());
YaspWriteW(ostr.str().c_str());
}
}
* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
* Copyright (C) 2007 - DIGITEO - Sylvestre LEDRU
* Copyright (C) 2010 - DIGITEO - Bruno JOFRET
+ * Copyright (C) 2011 - DIGITEO - Antoine ELIAS
*
* This file must be used under the terms of the CeCILL.
* This source file is licensed as described in the file COPYING, which
int initMacOSXEnv(int argc, char *argv[], int iFileIndex);
-int StartScilabEngine(int argc, char *argv[], int iFileIndex);
+int StartScilabEngine(int argc, char *argv[], int iFileIndex, int iLangIndex);
#endif /* !__INITMACOSXENV_H__ */
if (ret==0) {
/* Call the actual startup script of Scilab */
- ret=StartScilabEngine(p->argc, p->argv, p->iFileIndex);
+ ret=StartScilabEngine(p->argc, p->argv, p->iFileIndex, 0);
free(p);
exit(ret);
}
#include "PATH_MAX.h"
#include "sci_tmpdir.h"
#include "deleteafile.h"
+#include "setgetlanguage.h"
#ifdef __APPLE__
#include "initMacOSXEnv.h"
int InitializeEnvironnement(void);
bool execScilabStart(void);
-int StartScilabEngine(int argc, char*argv[], int iFileIndex);
+int StartScilabEngine(int argc, char*argv[], int iFileIndex, int iLangIndex);
static Parser::ControlStatus processCommand(char* _pstCommand);
/*
FREE(command);
command = NULL;
}
- //before calling YaspReader, try to call %onprompt function
- callOnPrompt();
-
+ YaspWriteW(L"\n");
command = YaspRead();
}
else
*/
if(execAst == true)
{
+ //before calling YaspReader, try to call %onprompt function
+ callOnPrompt();
execAstTask(parser->getTree(), timed, ASTtimed);
}
}
else if(parser->getExitStatus() == Parser::Failed && parser->getControlStatus() == Parser::AllControlClosed)
{
+ if(execAst == true)
+ {
+ //before calling YaspReader, try to call %onprompt function
+ callOnPrompt();
+ }
+
YaspWriteW(parser->getErrorMessage());
}
FREE(pwstCommand);
}
+ else
+ {
+ if(execAst == true)
+ {
+ //before calling YaspReader, try to call %onprompt function
+ callOnPrompt();
+ }
+ }
return parser->getControlStatus();
}
return initMacOSXEnv(argc, argv, iFileIndex);
}
#endif // !defined(__APPLE__)
- return StartScilabEngine(argc, argv, iFileIndex);
+ return StartScilabEngine(argc, argv, iFileIndex, iLangIndex);
}
else
{
#if defined(__APPLE__)
return initMacOSXEnv(argc, argv, iFileIndex);
#else
- return StartScilabEngine(argc, argv, iFileIndex);
+ return StartScilabEngine(argc, argv, iFileIndex, iLangIndex);
#endif // !defined(__APPLE__)
}
#else
setYaspInputMethod(&TermReadAndProcess);
setYaspOutputMethod(&TermPrintf);
- return StartScilabEngine(argc, argv, iFileIndex);
+ return StartScilabEngine(argc, argv, iFileIndex, iLangIndex);
#endif // defined(WITHOUT_GUI)
}
}
-int StartScilabEngine(int argc, char*argv[], int iFileIndex)
+int StartScilabEngine(int argc, char*argv[], int iFileIndex, int iLangIndex)
{
int iMainRet = 0;
Runner::init();
/* Scilab Startup */
InitializeEnvironnement();
+ if(iLangIndex)
+ {
+ wchar_t* pwstLang = to_wide_string(argv[iLangIndex]);
+ setlanguage(pwstLang);
+ FREE(pwstLang);
+ }
+
+
InitializeString();
#ifdef _MSC_VER
#include "mclose.h"
#include "os_wcsicmp.h"
}
+#include "stdio.h"
-using namespace types;
-
-Function::ReturnValue sci_mclose(typed_list &in, int _iRetCount, typed_list &out)
+types::Function::ReturnValue sci_mclose(types::typed_list &in, int _iRetCount, types::typed_list &out)
{
int iRet = 0;
if(in.size() == 0)
{
if(in[0]->isString())
{
- String *pS = in[0]->getAs<types::String>();
+ types::String *pS = in[0]->getAs<types::String>();
if(pS->getSize() != 1)
{
ScierrorW(999,_W("%ls: Wrong type for input argument #%d: A String expected.\n"), L"mclose", 1);
- return Function::Error;
+ return types::Function::Error;
}
- if(os_wcsicmp(pS->get(0), L"all") != 0)
+ if(FileManager::isOpened(pS->get(0)))
+ {
+ int iFileID = FileManager::getFileID(pS->get(0));
+ if(iFileID == -1)
+ {
+ ScierrorW(999, _W("%ls: File not found: '%ls'.\n"), L"mclose", pS->get(0));
+ return types::Function::Error;
+ }
+ iRet = mclose(iFileID);
+ }
+ else if(os_wcsicmp(pS->get(0), L"all") == 0)
+ {
+ iRet = mcloseAll();
+ }
+ else
{
ScierrorW(999, _W("%ls: Wrong input arguments: '%ls' expected.\n"), L"mclose", L"all");
- return Function::Error;
+ return types::Function::Error;
}
-
- iRet = mcloseAll();
}
else if(in[0]->isDouble())
{
- Double* pD = in[0]->getAs<Double>();
+ types::Double* pD = in[0]->getAs<types::Double>();
if(pD->getSize() != 1 || pD->isComplex())
{
ScierrorW(999,_W("%ls: Wrong type for input argument #%d: A real expected.\n"), L"mclose", 1);
- return Function::Error;
+ return types::Function::Error;
}
- int iVal = static_cast<int>(pD->getReal()[0]);
+ int iVal = static_cast<int>(pD->get(0));
+ switch (iVal)
+ {
+ case 0: // stderr
+ case 5: // stdin
+ case 6: // stdout
+ ScierrorW(999, _W("%ls: Wrong file descriptor: %d.\n"), L"mclose", iVal);
+ return types::Function::Error;
+ }
iRet = mclose(iVal);
}
else
{
ScierrorW(999, _W("%ls: Wrong type for input argument #%d: A integer or string expected.\n"), L"mclose", 1);
- return Function::Error;
+ return types::Function::Error;
}
}
else
{
ScierrorW(999, _W("%ls: Wrong number of input arguments: %d or %d expected.\n"), L"mclose", 0, 1);
- return Function::Error;
+ return types::Function::Error;
}
- Double* pD = new Double(static_cast<double>(iRet));
+ types::Double* pD = new types::Double(static_cast<double>(iRet));
out.push_back(pD);
- return Function::OK;
+ return types::Function::OK;
}
/*--------------------------------------------------------------------------*/
*
*/
/*--------------------------------------------------------------------------*/
-#include "funcmanager.hxx"
#include "fileio_gw.hxx"
-#include "function.hxx"
#include "string.hxx"
#include "filemanager.hxx"
extern "C"
{
#include <stdio.h>
-#include <string.h>
-#include "MALLOC.h"
-#include "removedir.h"
-#include "isdir.h"
#include "expandPathVariable.h"
#include "sci_warning.h"
#include "sciprint.h"
}
iFile = (int)in[0]->getAs<types::Double>()->get(0);
+ switch (iFile)
+ {
+ case 0: // stderr
+ case 5: // stdin
+ case 6: // stdout
+ ScierrorW(999, _W("%ls: Wrong file descriptor: %d.\n"), L"meof", iFile);
+ return types::Function::Error;
+ }
}
File* pF = FileManager::getFile(iFile);
}
// checking ID of file
- iFile = static_cast<int>(in[0]->getAs<types::Double>()->getReal()[0]);
+ iFile = static_cast<int>(in[0]->getAs<types::Double>()->get(0));
if(FileManager::getFile(iFile) == NULL)
{
}
}
- wcsStringToWrite = scilab_sprintf(L"mfprintf", wcsInput, in, pArgs, iNumberPercent, &nbrOfLines);
+ wcsStringToWrite = scilab_sprintf(L"mfprintf", wcsInput, in, pArgs, false, iNumberPercent, &nbrOfLines);
if(isSTD)
{
#include "fileio_gw.hxx"
#include "string.hxx"
#include "cell.hxx"
+#include "filemanager.hxx"
extern "C"
{
int iFile = -1; //default file : last opened file
int size = (int)in.size();
int iNiter = 1;
- int iLinesRead = 0;
+ //int iLinesRead = 0;
int iErr = 0;
wchar_t* wcsFormat = NULL;
- wchar_t** wcsRead = NULL;
int dimsArray[2] = {1,1};
std::vector<types::InternalType*>* pIT = new std::vector<types::InternalType*>();
ScierrorW(999, _W("%ls: Wrong type for input argument #%d: A Real expected.\n"), L"mfscanf", 1);
return types::Function::Error;
}
- iNiter = static_cast<int>(in[0]->getAs<types::Double>()->getReal()[0]);
+ iNiter = static_cast<int>(in[0]->getAs<types::Double>()->get(0));
}
if(in[size-2]->isDouble() == false || in[size-2]->getAs<types::Double>()->isScalar() == false || in[size-2]->getAs<types::Double>()->isComplex())
return types::Function::Error;
}
- iFile = static_cast<int>(in[size-2]->getAs<types::Double>()->getReal()[0]);
+ iFile = static_cast<int>(in[size-2]->getAs<types::Double>()->get(0));
switch (iFile)
{
case 0:
wcsFormat = in[size-1]->getAs<types::String>()->get(0);
-// get data
-
- wcsRead = mgetl(iFile, iNiter, &iLinesRead, &iErr);
- switch(iErr)
+ types::File* pFile = FileManager::getFile(iFile);
+ if(pFile == NULL)
{
- case MGETL_NO_ERROR :
- break;
- case MGETL_EOF :
- sciprintW(_W("Warning: Only %d line(s) read.\n"), iLinesRead);
- break;
- case MGETL_MEMORY_ALLOCATION_ERROR :
- ScierrorW(999, _W("%ls: Memory allocation error in %ls function.\n"), L"mfscanf", L"mgetl");
- return types::Function::Error;
- case MGETL_ERROR :
- ScierrorW(999, _W("%ls: Cannot read file %d.\n"), L"mfscanf", iFile);
+ ScierrorW(999, _W("%ls: Cannot read file %d.\n"), L"mfscanf", iFile);
return types::Function::Error;
}
- nrow = iLinesRead;
- while(++rowcount < iLinesRead)
+ FILE* fDesc = pFile->getFiledesc();
+ nrow = iNiter;
+ //nrow = iLinesRead;
+ while(++rowcount < iNiter)
{
- if ((iLinesRead >= 0) && (rowcount >= iLinesRead)) break;
+ if((iNiter >= 0) && (rowcount >= iNiter)) break;
// get data
- int err = do_xxscanf(L"sscanf",(FILE *)0,wcsFormat,&args,wcsRead[rowcount],&retval,buf,type);
- if(err < 0) return types::Function::Error;
- err=Store_Scan(&nrow,&ncol,type_s,type,&retval,&retval_s,buf,&data,rowcount,args);
+ int err = do_xxscanf(L"mfscanf", fDesc, wcsFormat, &args, NULL, &retval, buf, type);
+ if(err < 0)
+ {
+ return types::Function::Error;
+ }
+
+ err = Store_Scan(&nrow,&ncol,type_s,type,&retval,&retval_s,buf,&data,rowcount,args);
if(err < 0)
{
- switch (err)
+ switch(err)
{
case DO_XXPRINTF_MISMATCH:
- if (iLinesRead >= 0)
+ if(iNiter >= 0)
{
Free_Scan(rowcount,ncol,type_s,&data);
ScierrorW(999,_W("%ls: Data mismatch.\n"),L"mfscanf");
return types::Function::Error;
break;
}
- if (err==DO_XXPRINTF_MISMATCH) break;
+ if(err==DO_XXPRINTF_MISMATCH) break;
}
- FREE(wcsRead[rowcount]);
}
- FREE(wcsRead);
+
unsigned int uiFormatUsed = 0;
- for(int i=0; i<ncol; i++)
+ for(int i = 0 ; i < ncol ; i++)
{
- switch ( type_s[i] )
+ switch(type_s[i])
{
case SF_C:
case SF_S:
{
- types::String* ps = new types::String(iLinesRead,1);
- for(int j=0; j<iLinesRead; j++)
+ types::String* ps = new types::String(iNiter,1);
+ for(int j = 0 ; j < iNiter ; j++)
{
- ps->set(j, data[i+ncol*j].s);
+ ps->set(j, data[i + ncol * j].s);
}
pIT->push_back(ps);
uiFormatUsed |= (1 << 1);
case SF_LF:
case SF_F:
{
- types::Double* p = new types::Double(iLinesRead,1);
- for(int j=0; j<iLinesRead; j++)
+ types::Double* p = new types::Double(iNiter,1);
+ for(int j=0; j<iNiter; j++)
{
p->set(j, data[i+ncol*j].d);
}
int sizeOfDouble = (*pIT)[0]->getAs<types::Double>()->getRows();
int dimsArrayOfRes[2] = {sizeOfDouble, sizeOfVector};
types::Double* pDouble = new types::Double(2, dimsArrayOfRes);
- for(int i = 0; i < sizeOfVector; i++)
+ for(int i = 0 ; i < sizeOfVector; i++)
{
- for(int j = 0; j < sizeOfDouble; j++)
+ for(int j = 0 ; j < sizeOfDouble; j++)
{
pDouble->set(i*sizeOfDouble+j, (*pIT)[i]->getAs<types::Double>()->get(j));
}
pITTemp->push_back((*pIT)[0]);
// sizeOfVector always > 1
- for(int i = 1; i < sizeOfVector; i++) // concatenates the Cells. ex : [String 4x1] [String 4x1] = [String 4x2]
+ for(int i = 1 ; i < sizeOfVector ; i++) // concatenates the Cells. ex : [String 4x1] [String 4x1] = [String 4x2]
{
if(pITTemp->back()->getType() == (*pIT)[i]->getType())
{
int arrayOfType[2] = {iRows, iCols + 1};
types::String* pType = new types::String(2, arrayOfType);
- for(int k=0; k<pITTemp->back()->getAs<types::String>()->getSize(); k++)
+ for(int k = 0 ; k < pITTemp->back()->getAs<types::String>()->getSize() ; k++)
{
pType->set(k, pITTemp->back()->getAs<types::String>()->get(k));
}
- for(int k=0; k<(*pIT)[i]->getAs<types::String>()->getSize(); k++)
+
+ for(int k = 0; k < (*pIT)[i]->getAs<types::String>()->getSize() ; k++)
{
pType->set(iRows * iCols + k, (*pIT)[i]->getAs<types::String>()->get(k));
}
types::Double* pType = new types::Double(2, arrayOfType);
pType->set(pITTemp->back()->getAs<types::Double>()->get());
- for(int k=0; k<(*pIT)[i]->getAs<types::Double>()->getSize(); k++)
+ for(int k = 0; k < (*pIT)[i]->getAs<types::Double>()->getSize() ; k++)
{
pType->set(iRows * iCols + k, (*pIT)[i]->getAs<types::Double>()->get(k));
}
int dimsArrayOfCell[2] = {1, (int)pITTemp->size()};
types::Cell* pCell = new types::Cell(2, dimsArrayOfCell);
- for(int i = 0; i < pITTemp->size(); i++)
+ for(int i = 0 ; i < pITTemp->size() ; i++)
{
pCell->set(i, (*pITTemp)[i]);
}
*
*/
/*--------------------------------------------------------------------------*/
-#include "funcmanager.hxx"
#include "filemanager.hxx"
#include "fileio_gw.hxx"
#include "string.hxx"
#include "file.hxx"
-#include "function.hxx"
extern "C"
{
return Function::Error;
}
- iSize = static_cast<int>(in[0]->getAs<Double>()->getReal()[0]);
+ iSize = static_cast<int>(in[0]->getAs<Double>()->get(0));
if(in.size() >= 2)
{//export format
if(in[1]->isString() == false || in[1]->getAs<types::String>()->getSize() != 1)
{
- ScierrorW(999, _W("%ls: Wrong type for input argument #%d: A string expected.\n"), L"mput", 2);
+ ScierrorW(999, _W("%ls: Wrong type for input argument #%d: A string expected.\n"), L"mget", 2);
return Function::Error;
}
pstType = wide_string_to_UTF8(in[1]->getAs<types::String>()->get(0));
-
}
if(in.size() == 3)
{
if(in[2]->isDouble() == false || in[2]->getAs<Double>()->getSize() != 1)
{
- ScierrorW(999, _W("%ls: Wrong type for input argument #%d: A integer expected.\n"), L"mput", 3);
+ ScierrorW(999, _W("%ls: Wrong type for input argument #%d: A integer expected.\n"), L"mget", 3);
return Function::Error;
}
-
- iFile = static_cast<int>(in[2]->getAs<Double>()->getReal()[0]);
+ iFile = static_cast<int>(in[2]->getAs<Double>()->get(0));
}
Double* pD = new Double(1, iSize);
pData = pD->getReal();
+ switch (iFile)
+ {
+ case 0: // stderr
+ case 6: // stdout
+ ScierrorW(999, _W("%ls: Wrong file descriptor: %d.\n"), L"mget", iFile);
+ return types::Function::Error;
+ }
+
C2F(mget)(&iFile, pData, &iSize, pstType, &iErr);
- File* pFile = FileManager::getFile(iFile);
if(iErr > 0)
{
return Function::Error;
*
*/
/*--------------------------------------------------------------------------*/
-#include "funcmanager.hxx"
#include "filemanager.hxx"
#include "fileio_gw.hxx"
-#include "function.hxx"
#include "string.hxx"
extern "C"
/*--------------------------------------------------------------------------*/
Function::ReturnValue sci_mgetl(typed_list &in, int _iRetCount, typed_list &out)
{
- int iFileID = 0;
- int iErr = 0;
- bool bCloseFile = false;
- int iLinesExcepted = -1;
- int iLinesRead = -1;
+ int iFileID = 0;
+ int iErr = 0;
+ bool bCloseFile = false;
+ int iLinesExcepted = -1;
+ int iLinesRead = -1;
+ wchar_t** wcReadedStrings = NULL;
if(in.size() < 1 || in.size() > 2)
{
- Scierror(999, _("%s: Wrong number of input arguments: %d to %d expected.\n"), "mgetl" , 1, 2);
+ Scierror(77, _("%s: Wrong number of input arguments: %d to %d expected.\n"), "mgetl" , 1, 2);
return Function::OK;
}
Scierror(999,_("%s: Wrong type for input argument #%d: A scalar expected.\n"), "mgetl", 2);
return Function::Error;
}
-
- iLinesExcepted = static_cast<int>(in[1]->getAs<Double>()->getReal()[0]);
+ iLinesExcepted = static_cast<int>(in[1]->getAs<Double>()->get(0));
}
if(in[0]->isDouble() && in[0]->getAs<Double>()->getSize() == 1)
{
- iFileID = static_cast<int>(in[0]->getAs<Double>()->getReal()[0]);
+ iFileID = static_cast<int>(in[0]->getAs<Double>()->get(0));
}
else if(in[0]->isString() && in[0]->getAs<types::String>()->getSize() == 1)
{
return Function::Error;
}
FREE(expandedFileName);
- bCloseFile = true;
+ bCloseFile = true;
}
else
{//Error
return Function::Error;
}
- wchar_t** wcReadedStrings = mgetl(iFileID, iLinesExcepted, &iLinesRead, &iErr);
-
- switch(iErr)
+ switch (iFileID)
{
- case MGETL_MEMORY_ALLOCATION_ERROR :
- break;
+ case 0: // stderr
+ case 6: // stdout
+ ScierrorW(999, _W("%ls: Wrong file descriptor: %d.\n"), L"mgetl", iFileID);
+ return types::Function::Error;
+ default :
+ {
+ wcReadedStrings = mgetl(iFileID, iLinesExcepted, &iLinesRead, &iErr);
+
+ switch(iErr)
+ {
+ case MGETL_MEMORY_ALLOCATION_ERROR :
+ break;
+ }
+ }
+ }
+
+ if(wcReadedStrings && iLinesRead > 0)
+ {
+ String *pS = new String(iLinesRead, 1);
+ pS->set(wcReadedStrings);
+ out.push_back(pS);
+ }
+ else
+ {
+ out.push_back(types::Double::Empty());
}
- String *pS = new String(iLinesRead, 1);
- pS->set(wcReadedStrings);
- out.push_back(pS);
if(bCloseFile)
{
*
*/
/*--------------------------------------------------------------------------*/
-#include "funcmanager.hxx"
#include "filemanager.hxx"
#include "fileio_gw.hxx"
-#include "function.hxx"
#include "string.hxx"
extern "C"
{
-#include <stdio.h>
#include "localization.h"
#include "Scierror.h"
#include "charEncoding.h"
int iFile = -1; //default file : last opened file
types::String* pOutString = NULL;
int iSizeToRead = 0;
- types::Double* pdFileId = NULL;
-
+ wchar_t* pwstOut = NULL;
+
if(in.size() < 1 || in.size() > 2)
{
ScierrorW(77, _W("%ls: Wrong number of input argument(s): %d to %d expected.\n"), L"mgetstr", 1, 2);
ScierrorW(999, _W("%ls: Wrong type for input argument #%d: A real expected.\n"), L"mgetstr", 1);
return types::Function::Error;
}
-
- iSizeToRead = static_cast<int>(in[0]->getAs<types::Double>()->getReal()[0]);
-
+
+ iSizeToRead = static_cast<int>(in[0]->getAs<types::Double>()->get(0));
+
if(in.size() == 2)
{
if(in[1]->isDouble() == false || in[1]->getAs<types::Double>()->isScalar() == false || in[1]->getAs<types::Double>()->isComplex())
ScierrorW(999, _W("%ls: Wrong type for input argument #%d: A real expected.\n"), L"mgetstr", 2);
return types::Function::Error;
}
- pdFileId = in[1]->getAs<types::Double>();
+ iFile = static_cast<int>(in[1]->getAs<types::Double>()->get(0));
}
-
- pOutString = new types::String(iDims,iDimsArray);
-
- if(pdFileId != NULL)
+ switch (iFile)
{
- iFile = static_cast<int>(pdFileId->getReal()[0]);
+ case 0: // stderr
+ case 6: // stdout
+ ScierrorW(999, _W("%ls: Wrong file descriptor: %d.\n"), L"mgetstr", iFile);
+ return types::Function::Error;
+ default :
+ pwstOut = mgetstr(iFile, iSizeToRead);
}
-
- wchar_t* pwstOut = mgetstr(iFile, iSizeToRead);
+ pOutString = new types::String(iDims,iDimsArray);
+
if(pwstOut == NULL)
{
- // ScierrorW(999, _W("%ls: Unable to read file %d.\n"), L"mgetstr", iFile);
-// return types::Function::Error;
+ ScierrorW(999, _W("%ls: Unable to read file %d.\n"), L"mgetstr", iFile);
+ return types::Function::Error;
}
else
{
pOutString->set(0, pwstOut);
}
-
+
FREE(pwstOut);
out.push_back(pOutString);
return Function::OK;
*
*/
-#include "function.hxx"
#include "string.hxx"
-#include "funcmanager.hxx"
#include "filemanager.hxx"
#include "fileio_gw.hxx"
+
extern "C"
{
#include <PATH_MAX.h>
*
*/
/*--------------------------------------------------------------------------*/
-#include "funcmanager.hxx"
#include "filemanager.hxx"
#include "fileio_gw.hxx"
-#include "function.hxx"
#include "string.hxx"
extern "C"
iFile = static_cast<int>(in[2]->getAs<Double>()->get(0));
}
+ switch (iFile)
+ {
+ case 5: // stdin
+ ScierrorW(999, _W("%ls: Wrong file descriptor: %d.\n"), L"mput", iFile);
+ return types::Function::Error;
+ }
+
C2F(mput)(&iFile, pData, &iSize, pstType, &iErr);
FREE(pstType);
*
*/
/*--------------------------------------------------------------------------*/
-#include "funcmanager.hxx"
#include "filemanager.hxx"
#include "fileio_gw.hxx"
-#include "function.hxx"
#include "string.hxx"
extern "C"
if(in.size() != 2)
{
- Scierror(77,_("%s: Wrong number of input argument(s): %d expected.\n"),"mputl", 2);
+ ScierrorW(999,_W("%ls: Wrong number of input argument(s): %d expected.\n"),L"mputl", 2);
return Function::Error;
}
if(_iRetCount != 1)
{
- Scierror(78,_("%s: Wrong number of output argument(s): %d expected.\n"), "mputl", 1);
+ ScierrorW(999,_W("%ls: Wrong number of output argument(s): %d expected.\n"), L"mputl", 1);
return Function::Error;
}
if(in[1]->isDouble() && in[1]->getAs<Double>()->getSize() == 1)
{
- iFileID = static_cast<int>(in[1]->getAs<Double>()->getReal()[0]);
+ iFileID = static_cast<int>(in[1]->getAs<Double>()->get(0));
}
else if(in[1]->isString() && in[1]->getAs<types::String>()->getSize() == 1)
{
//String vextor, row or col
if(in[0]->isString() == false || (in[0]->getAs<types::String>()->getRows() != 1 && in[0]->getAs<types::String>()->getCols() != 1))
{
- Scierror(999,_("%s: Wrong size for input argument #%d: A 1-by-n or m-by-1 array expected.\n"), "mputl", 1);
+ ScierrorW(999,_W("%ls: Wrong size for input argument #%d: A 1-by-n or m-by-1 array expected.\n"), L"mputl", 1);
return Function::Error;
}
String* pS = in[0]->getAs<types::String>();
- iErr = mputl(iFileID, pS->get(), pS->getSize());
+ switch (iFileID)
+ {
+ case 5: // stdin
+ ScierrorW(999, _W("%ls: Wrong file descriptor: %d.\n"), L"mputl", iFileID);
+ return types::Function::Error;
+ default : iErr = mputl(iFileID, pS->get(), pS->getSize());
+ }
out.push_back(new Bool(!iErr));
*
*/
/*--------------------------------------------------------------------------*/
-#include "funcmanager.hxx"
#include "filemanager.hxx"
#include "fileio_gw.hxx"
-#include "function.hxx"
#include "string.hxx"
extern "C"
#include "localization.h"
#include "Scierror.h"
#include "charEncoding.h"
-#include "sci_warning.h"
}
/*--------------------------------------------------------------------------*/
Function::ReturnValue sci_mputstr(types::typed_list &in, int _iRetCount, types::typed_list &out)
{
int iFile = -1; //default file : last opened file
- int iRet = 0;
types::String* pString = NULL;
- types::Double* pdFileId = NULL;
- File* pF = NULL;
+ int iErr = 1;
if(in.size() < 1 || in.size() > 2)
{
ScierrorW(999, _W("%ls: Wrong type for input argument #%d: A string expected.\n"), L"mputstr", 1);
return types::Function::Error;
}
-
+
pString = in[0]->getAs<types::String>();
if(in.size() == 2)
ScierrorW(999, _W("%ls: Wrong type for input argument #%d: A real expected.\n"), L"mputstr", 2);
return types::Function::Error;
}
- pdFileId = in[1]->getAs<types::Double>();
+ iFile = static_cast<int>(in[1]->getAs<types::Double>()->get(0));
+ }
+
+ switch (iFile)
+ {
+ case 5: // stdin
+ ScierrorW(999, _W("%ls: Wrong file descriptor: %d.\n"), L"mputstr", iFile);
+ return types::Function::Error;
+ default :
+ iErr = mputl(iFile, pString->get(), 1);
}
- int iErr = mputl(iFile, pString->get(), 1, FALSE); // FALSE = don't add the "\n" at the end.
out.push_back(new Bool(!iErr));
return Function::OK;
ScierrorW(999, _W("%ls: Wrong type for input argument #%d: A Real expected.\n"), L"mscanf", 1);
return types::Function::Error;
}
- iNiter = static_cast<int>(in[0]->getAs<types::Double>()->getReal()[0]);
+ iNiter = static_cast<int>(in[0]->getAs<types::Double>()->get(0));
if(iNiter < 0)
iNiter = 1;
}
*
*/
/*--------------------------------------------------------------------------*/
-#include "funcmanager.hxx"
#include "filemanager.hxx"
#include "fileio_gw.hxx"
-#include "function.hxx"
#include "string.hxx"
extern "C"
{
-#include <stdio.h>
#include "localization.h"
#include "Scierror.h"
#include "mseek.h"
return types::Function::Error;
}
- iWhere = static_cast<int>(in[0]->getAs<types::Double>()->getReal()[0]);
+ iWhere = static_cast<int>(in[0]->getAs<types::Double>()->get(0));
if(in.size() == 2)
{
if(in[1]->isDouble() && in[1]->getAs<types::Double>()->isScalar() && in[1]->getAs<types::Double>()->isComplex() == false)
{
- iFile = static_cast<int>(in[1]->getAs<types::Double>()->getReal()[0]);
+ iFile = static_cast<int>(in[1]->getAs<types::Double>()->get(0));
}
else if(in[1]->isString() && in[1]->getAs<types::String>()->isScalar())
{
return types::Function::Error;
}
- iFile = static_cast<int>(in[1]->getAs<types::Double>()->getReal()[0]);
+ iFile = static_cast<int>(in[1]->getAs<types::Double>()->get(0));
wcsFlag = in[2]->getAs<types::String>()->get(0);
}
+ switch (iFile)
+ {
+ case 0: // stderr
+ case 5: // stdin
+ case 6: // stdout
+ ScierrorW(999, _W("%ls: Wrong file descriptor: %d.\n"), L"mseek", iFile);
+ return types::Function::Error;
+ }
+
if(wcsFlag != NULL)
{
if(wcsncmp(wcsFlag, L"set",3) == 0)
}
else if(wcsncmp(wcsFlag, L"end",3) == 0)
{
- iFlag = SEEK_END;
+ iFlag = SEEK_END;
}
else
{
ScierrorW(999, _W("%ls: Wrong type for input argument #%d: A Real expected.\n"), L"msscanf", 1);
return types::Function::Error;
}
- iNiter = static_cast<int>(in[0]->getAs<types::Double>()->getReal()[0]);
+ iNiter = static_cast<int>(in[0]->getAs<types::Double>()->get(0));
}
if(in[size-2]->isString() == false)
*
*/
/*--------------------------------------------------------------------------*/
-#include "funcmanager.hxx"
#include "filemanager.hxx"
#include "fileio_gw.hxx"
-#include "function.hxx"
#include "string.hxx"
extern "C"
{
-#include <stdio.h>
#include "localization.h"
#include "Scierror.h"
#include "mtell.h"
return types::Function::Error;
}
- iFile = static_cast<int>(in[0]->getAs<types::Double>()->getReal()[0]);
+ iFile = static_cast<int>(in[0]->getAs<types::Double>()->get(0));
+ }
+
+ switch (iFile)
+ {
+ case 0: // stderr
+ case 5: // stdin
+ case 6: // stdout
+ ScierrorW(999, _W("%ls: Wrong file descriptor: %d.\n"), L"mtell", iFile);
+ return types::Function::Error;
}
long int offset = mtell(iFile);
if(offset < 0)
{
- ScierrorW(999, _W("%ls: Unable to read file %d.\n"), L"mtell", iFile);
+ ScierrorW(999, _W("%ls: Error while opening, reading or writing.\n"), L"mtell", iFile);
return types::Function::Error;
}
{
if(m_fileList[i] != NULL && m_fileList[i]->getFilename() == _stFilename)
{
- return i + 1;
+ return i;
}
}
return -1;
{
if(_iID == -1 && m_iCurrentFile != -1)
{
- return m_fileList[m_iCurrentFile - 1];
+ return m_fileList[m_iCurrentFile];
}
if(_iID <= m_fileList.size())
{//1-indexed
- return m_fileList[_iID - 1];
+ return m_fileList[_iID];
}
return NULL;
if(m_fileList[i] == NULL)
{
m_fileList[i] = _file;
- int iNewId = i + 1;
- m_iCurrentFile = iNewId;
- return iNewId;
+ m_iCurrentFile = i;
+ return i;
}
}
{//1-indexed
//do not delete File object !!!
//delete m_fileList[_iID - 1];
- m_fileList[_iID - 1] = NULL;
+ m_fileList[_iID] = NULL;
if(m_iCurrentFile == _iID)
{
m_iCurrentFile = -1;
{
if(m_fileList[i] != NULL)
{
- piIds[iFileIndex++] = i + 1;
+ piIds[iFileIndex++] = i;
}
}
void FileManager::initialize()
{
+ File* pErr = new File();
+ pErr->setFileMode(L"wb");
+ pErr->setFileDesc(stderr);
+ pErr->setFileSwap(0);
+ pErr->setFileType(1);
+ pErr->setFilename(L"stderr");
+
File* pIn = new File();
pIn->setFileMode(L"rb");
pIn->setFileDesc(stdin);
pOut->setFileType(1);
pOut->setFilename(L"stdout");
+ //put pErr at position 0
+ m_fileList.push_back(pErr);
+
//insert free space
m_fileList.push_back(NULL);
m_fileList.push_back(NULL);
int mcloseAll()
{
- while(FileManager::getFileMaxID() != 0)
- {
- int iRet = mclose(FileManager::getFileMaxID());
- if(iRet)
- {
- return iRet;
- }
- }
-
- return 0;
+ int iFileCount = FileManager::getFileMaxID();
+ for(int i = iFileCount ; i > 0 ; i--)
+ {
+ //stdin and stdout
+ if(i != 0 && i != 5 && i != 6 && FileManager::getFile(i) != NULL)
+ {
+ int iRet = mclose(i);
+ if(iRet)
+ {
+ return iRet;
+ }
+ FileManager::deleteFile(i);
+ }
+ }
+
+ return 0;
}
int mclose(int _iID)
if(pF != NULL)
{
int iRet = fclose(pF->getFiledesc());
-
+
// this function previously called ferror on a just before fclosed FILE* that could lead to crash at exit, depending on libc implementation.
if(iRet != 0)
{
- iRet = 1;
+ return 1;
}
FileManager::deleteFile(_iID);
static wchar_t *removeEOL(wchar_t *_inString);
static char *convertAnsiToUtf(char *_inString);
static wchar_t* getLine(wchar_t* _pstLine, int _iLineSize, File* _pFile);
+/*--------------------------------------------------------------------------*/
+#define UTF_16BE_BOM 0xFEFF // 0xFEFF = to_wide_string(0xEFBBBF)
/*--------------------------------------------------------------------------*/
wchar_t **mgetl(int fd, int nbLinesIn, int *nbLinesOut, int *ierr)
{
pFile = FileManager::getFile(fd);
+ if(nbLinesIn < 0 && fd == 5)
+ {
+ nbLinesIn = 1;
+ }
+
if (pFile)
{
wchar_t Line[LINE_MAX * 2];
while ( getLine ( Line, sizeof(Line), pFile ) != NULL )
{
+ /* UTF-16 BOM */
+ if ((nbLines == 0) && (Line[0] == UTF_16BE_BOM))
+ {
+ wchar_t* tmpLine = os_wcsdup(Line);
+ memset(Line, 0x00, LINE_MAX * 2);
+ wcscpy(Line, &tmpLine[1]);
+ }
+
nbLines++;
strLines = (wchar_t **)REALLOC(strLines, nbLines * sizeof(wchar_t *));
if (strLines == NULL)
{
if (nbLines < nbLinesIn)
{
+ bool header = false;
+ /* UTF-16 BOM */
+ if ((ftell(pFile->getFiledesc()) == 0) && (nbLines == 0))
+ {
+ header = true;
+ }
+
if ( getLine ( Line, sizeof(Line), pFile) != NULL)
{
+ if(header && (Line[0] == UTF_16BE_BOM))
+ {
+ wchar_t* tmpLine = os_wcsdup(Line);
+ memset(Line, 0x00, LINE_MAX * 2);
+ wcscpy(Line, &tmpLine[1]);
+ }
nbLines++;
strLines[nbLines - 1] = os_wcsdup(removeEOL(Line));
if (strLines[nbLines - 1] == NULL)
}
else
{
- char* pstTemp = (char*)MALLOC(sizeof(char*) * _iLineSize);
+ char* pstTemp = (char*)MALLOC(sizeof(char) * _iLineSize);
if(fgets(pstTemp, _iLineSize, _pFile->getFiledesc()) == NULL)
{
FREE(pstTemp);
unsigned char inAnsiChar = 0;
if (_inString[i] < 0)
- {
- inAnsiChar = 256 + _inString[i];
- }
+ {
+ inAnsiChar = 256 + _inString[i];
+ }
else
- {
- inAnsiChar = _inString[i];
- }
+ {
+ inAnsiChar = _inString[i];
+ }
if(inAnsiChar < 128)
{
{
wchar_t* pwstOut = NULL;
File* pF = FileManager::getFile(_iFileId);
- int iSizeToRead = _iSizeToRead + 1; //fgetws and fgets need length to read + 1
-
+
if(pF != NULL)
{
- if(static_cast<int>(pF->getFileModeAsDouble()) % 2 == 1)
+ if(static_cast<int>(pF->getFileModeAsDouble()) % 2 == 1)//to determine if the file have been opened with binary or text mode
{
- pwstOut = (wchar_t*)MALLOC(iSizeToRead * sizeof(wchar_t));
- memset(pwstOut, 0x00, iSizeToRead * sizeof(wchar_t));
- wchar_t* pwstRes = fgetws(pwstOut, iSizeToRead, pF->getFiledesc());
- if(pwstRes == NULL)
+ int iSizeRead = 0;
+ pwstOut = (wchar_t*)MALLOC((_iSizeToRead + 1) * sizeof(wchar_t));
+ memset(pwstOut, 0x00, (_iSizeToRead + 1) * sizeof(wchar_t));
+
+ while(_iSizeToRead > iSizeRead)
{
- FREE(pwstOut);
- return NULL;
+ wchar_t* pwstRes = fgetws(&pwstOut[iSizeRead], _iSizeToRead - iSizeRead + 1, pF->getFiledesc());//fgetws need length to read + 1
+ if(feof(pF->getFiledesc()))
+ {
+ return pwstOut;
+ }
+ if(pwstRes == NULL)
+ {
+ FREE(pwstOut);
+ return NULL;
+ }
+ iSizeRead += (int)wcslen(pwstRes);
}
}
else
{
- char* buffer = (char*)MALLOC(iSizeToRead * sizeof(char));
- memset(buffer, 0x00, iSizeToRead * sizeof(char));
+ int iSizeRead = 0;
+ char* buffer = (char*)MALLOC((_iSizeToRead + 1) * sizeof(char));
+ memset(buffer, 0x00, (_iSizeToRead + 1) * sizeof(char));
- char* pstRes = fgets(buffer, iSizeToRead, pF->getFiledesc());
- if(pstRes == NULL)
+ while(_iSizeToRead > iSizeRead)
{
- FREE(buffer);
- return NULL;
+ char* pstRes = fgets(&buffer[iSizeRead], _iSizeToRead - iSizeRead + 1, pF->getFiledesc());//fgets need length to read + 1
+ if(feof(pF->getFiledesc()))
+ {
+ pwstOut = to_wide_string(buffer);
+ return pwstOut;
+ }
+ if(pstRes == NULL)
+ {
+ FREE(buffer);
+ return NULL;
+ }
+ iSizeRead += (int)strlen(pstRes);
}
pwstOut = to_wide_string(buffer);
offset = ftell(pF->getFiledesc()) ;
#endif
#else
- offset = ftell(pF->getFiledesc()) ;
+ offset = ftell(pF->getFiledesc()) ;
#endif
return offset;
//
// This file is distributed under the same license as the Scilab package.
// =============================================================================
-w=1;
+// <-- JVM NOT MANDATORY -->
+w=1;
//ouvrir le fichier
-// =============================================================================
-// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) 2009 - DIGITEO - Allan CORNET
-//
-// This file is distributed under the same license as the Scilab package.
-// =============================================================================
FLN = 'SCI/modules/fileio/tests/unit_tests/text.txt';
-fd = mopen(FLN,'rt');
-i = 0;
+fd = mopen(FLN,'rt');i = 0;
while ~meof(fd) do
mfscanf(1, fd, "%c");
i = i + 1;
if ierr <> 77 then bugmes();quit;end
ierr = execstr('mgetstr(NB_CHARS,textfile,1)','errcatch');
if ierr <> 77 then bugmes();quit;end
-fd = mopen(textfile,'rb');
+fd = mopen(textfile,'r');
str = mgetstr(NB_CHARS,fd);
mclose(fd);
ref1 = 'Scilab is a numerical computational package';
if length(str) <> NB_CHARS then bugmes();quit;end
if str <> ref1 then bugmes();quit;end;
-fd = mopen(textfile,'rb');
+fd = mopen(textfile,'r');
str = mgetstr(NB_CHARS*2,fd);
mclose(fd);
fd = mopen(textfile,'rb');
if ierr <> 77 then pause,end
-fd = mopen(textfile,'rb');
+fd = mopen(textfile,'r');
str = mgetstr(NB_CHARS,fd);
mclose(fd);
ref1 = 'Scilab is a numerical computational package';
if str <> ref1 then pause,end;
-fd = mopen(textfile,'rb');
+fd = mopen(textfile,'r');
str = mgetstr(NB_CHARS*2,fd);
mclose(fd);
"프로그램",
"×ª×•×›× ×™×ª"];
+disp("toto")
+
lang_name = ["Simplified Chinese",
"Cyrillic",
"Japanese",
// This file is distributed under the same license as the Scilab package.
// =============================================================================
file3=TMPDIR + '/test3.bin';
-fd1= mopen(file3,'wb');
+fd1= mopen(file3, 'wb');
for i=1:10
- mput(i,'d');
+ mput(i, 'd');
end
mseek(0);
-mput(678,'d');
-mseek(0,fd1,'end');
-mput(932,'d');
-mclose(fd1)
- ans =
-
- 0.
-fd1= mopen(file3,'rb');
-res=mget(11,'d')
- res =
-
-
- column 1 to 10
-
- 678. 2. 3. 4. 5. 6. 7. 8. 9. 10.
-
- column 11
-
- 932.
-res1=[1:11];
-res1(1)=678;
-res1($)=932;
-if res1<>res then bugmes();quit;end;
-mseek(0,fd1,'set');
-res1 = mget(100,'d',fd1);
-if res1<>res then bugmes();quit;end;
+mput(678, 'd');
+mseek(0, fd1, 'end');
+mput(932, 'd');
+mclose(fd1);
+fd1 = mopen(file3, 'rb');
+res = mget(11, 'd');
+res1 = [1:11];
+res1(1) = 678;
+res1($) = 932;
+if res1 <> res then bugmes();quit;end;
+mseek(0, fd1, 'set');
+res1 = mget(100, 'd', fd1);
+if res1 <> res then bugmes();quit;end;
meof(fd1);
mclearerr(fd1);
mclose(fd1);
// =============================================================================
file3=TMPDIR + '/test3.bin';
-fd1= mopen(file3,'wb');
+fd1= mopen(file3, 'wb');
for i=1:10
- mput(i,'d');
+ mput(i, 'd');
end
mseek(0);
-mput(678,'d');
-mseek(0,fd1,'end');
-mput(932,'d');
-mclose(fd1)
-fd1= mopen(file3,'rb');
-res=mget(11,'d')
-res1=[1:11];
-res1(1)=678;
-res1($)=932;
-if res1<>res then pause,end;
-mseek(0,fd1,'set');
-res1 = mget(100,'d',fd1);
-if res1<>res then pause,end;
+mput(678, 'd');
+mseek(0, fd1, 'end');
+mput(932, 'd');
+mclose(fd1);
+fd1 = mopen(file3, 'rb');
+res = mget(11, 'd');
+res1 = [1:11];
+res1(1) = 678;
+res1($) = 932;
+if res1 <> res then pause,end;
+
+mseek(0, fd1, 'set');
+res1 = mget(100, 'd', fd1);
+if res1 <> res then pause,end;
meof(fd1);
mclearerr(fd1);
mclose(fd1);
//
// This file is distributed under the same license as the Scilab package.
// =============================================================================
+// <-- ENGLISH IMPOSED -->
testFile=TMPDIR + '/testFile.bin';
fd = mopen(testFile,'wb');
// file should be empty
if mtell(fd) <> 0 then bugmes();quit;end
for j=1:100
- for i=1:j
- mput(i,'d');
- end
- if mtell(fd) <> 8 * j then bugmes();quit;end
- mseek(0);
+ for i=1:j
+ mput(i,'d');
+ end
+ if mtell(fd) <> 8 * j then bugmes();quit;end
+ mseek(0);
end
mclose(fd);
try
- mtell(fd);
-mtell: Error while opening, reading or writing.
+ mtell(fd);
catch
- [message, ierr]=lasterror();
- if ierr <> 10000 then bugmes();quit;end
+ errorMessage = sprintf(gettext("%s: Error while opening, reading or writing.\n"), "mtell");
+ [message, ierr]=lasterror();
+ if message <> errorMessage then disp(errorMessage);disp(message);bugmes();quit;end
end
+Error: mtell: Error while opening, reading or writing.
+
fd = mopen(testFile,'wb');
// file should be empty
if mtell(fd) <> 0 then bugmes();quit;end
for j=1:100
- for i=1:j
- mput(i,'ul');
- end
- if mtell(fd) <> 4 * j then bugmes();quit;end
- mseek(0);
+ for i=1:j
+ mput(i,'ul');
+ end
+ if mtell(fd) <> 4 * j then bugmes();quit;end
+ mseek(0);
end
mclose(fd);
//
// This file is distributed under the same license as the Scilab package.
// =============================================================================
+// <-- ENGLISH IMPOSED -->
testFile=TMPDIR + '/testFile.bin';
fd = mopen(testFile,'wb');
// file should be empty
if mtell(fd) <> 0 then pause, end
for j=1:100
- for i=1:j
- mput(i,'d');
- end
- if mtell(fd) <> 8 * j then pause, end
- mseek(0);
+ for i=1:j
+ mput(i,'d');
+ end
+ if mtell(fd) <> 8 * j then pause, end
+ mseek(0);
end
mclose(fd);
try
- mtell(fd);
+ mtell(fd);
catch
- [message, ierr]=lasterror();
- if ierr <> 10000 then pause,end
+ errorMessage = sprintf(gettext("%s: Error while opening, reading or writing.\n"), "mtell");
+ [message, ierr]=lasterror();
+ if message <> errorMessage then disp(errorMessage);disp(message);bugmes();quit;end
end
-
-
fd = mopen(testFile,'wb');
// file should be empty
if mtell(fd) <> 0 then pause, end
for j=1:100
- for i=1:j
- mput(i,'ul');
- end
- if mtell(fd) <> 4 * j then pause, end
- mseek(0);
+ for i=1:j
+ mput(i,'ul');
+ end
+ if mtell(fd) <> 4 * j then pause, end
+ mseek(0);
end
mclose(fd);
}
}
- //if( !checkPrompt(iMode, EXEC_MODE_MUTE) &&
- // bErrCatch == false)
+ //if( !checkPrompt(iMode, EXEC_MODE_MUTE) && bErrCatch == false)
//{
// YaspWriteW(L"\n");
//}
strncpy(strLastLine, _pstPreviousBuffer + (loc.first_column - 1), loc.last_column - (loc.first_column - 1));
strLastLine[loc.last_column - (loc.first_column - 1)] = 0;
int iExpLen = (int)strlen(strLastLine);
- int iLineLen = (int)strlen(_pstPreviousBuffer) - (loc.first_column - 1);
- if(iExpLen == iLineLen)
- {
- if(loc.first_column == 1)
- {
- printLine(_pstPrompt, strLastLine, true);
- }
- else
- {
- printLine("", strLastLine, true);
- }
+ int iLineLen = (int)strlen(_pstPreviousBuffer);
+//printLine(_pstPrompt, strLastLine, true, false);
+
+
+ if(loc.first_column == 1 && iExpLen == iLineLen)
+ {//entire line
+ printLine("", "", true);
+ printLine(_pstPrompt, strLastLine, true);
}
else
{
if(loc.first_column == 1)
- {
+ {//begin of line
+ printLine("", "", true);
printLine(_pstPrompt, strLastLine, false);
}
else
{
- printLine("", strLastLine, false);
+ if(loc.last_column == iLineLen)
+ {
+ printLine("", strLastLine, true);
+ }
+ else
+ {
+ printLine("", strLastLine, false);
+ }
}
}
- }
- else
- {//multiline
- printLine(_pstPrompt, _pstPreviousBuffer + (loc.first_column - 1), true);
+ }
+ else
+ {//multiline
- //print other full lines
- for(int i = loc.first_line; i < (loc.last_line - 1) ; i++)
- {
- (*_piLine)++;
- _pFile->getline(_pstPreviousBuffer, 1024);
- printLine(_pstPrompt, _pstPreviousBuffer, true);
- }
+ if(loc.first_column == 1)
+ {
+ printLine("", "", true);
+ printLine(_pstPrompt, _pstPreviousBuffer + (loc.first_column - 1), true);
+ }
+ else
+ {
+ printLine("", _pstPreviousBuffer + (loc.first_column - 1), true);
+ }
- //last line
- _pFile->getline(_pstPreviousBuffer, 1024);
- (*_piLine)++;
- strncpy(strLastLine, _pstPreviousBuffer, loc.last_column);
- strLastLine[loc.last_column] = 0;
- printLine(_pstPrompt, strLastLine, true);
- }
+ //print other full lines
+ for(int i = loc.first_line; i < (loc.last_line - 1) ; i++)
+ {
+ (*_piLine)++;
+ _pFile->getline(_pstPreviousBuffer, 1024);
+ printLine(_pstPrompt, _pstPreviousBuffer, true);
+ }
+
+ //last line
+ _pFile->getline(_pstPreviousBuffer, 1024);
+ (*_piLine)++;
+
+ strncpy(strLastLine, _pstPreviousBuffer, loc.last_column);
+ strLastLine[loc.last_column] = 0;
+ int iLineLen = (int)strlen(_pstPreviousBuffer);
+ if(iLineLen == loc.last_column)
+ {
+ printLine(_pstPrompt, strLastLine, true);
+ }
+ else
+ {
+ printLine(_pstPrompt, strLastLine, false);
+ }
+ }
}
void printLine(char* _stPrompt, char* _stLine, bool _bLF)
{
char* sz = (char*)MALLOC(sizeof(char) * (strlen(_stPrompt) + strlen(_stLine) + 2));
memset(sz, 0x00, sizeof(char) * (strlen(_stPrompt) + strlen(_stLine) + 2));
+
if(strlen(_stPrompt) != 0)
{
strcat(sz, _stPrompt);
#ifndef __SCILAB_SPRINTF_HXX__
#define __SCILAB_SPRINTF_HXX__
-#include "dynlib_output_stream.h"
+#include "dynlib_output_stream_gw.h"
#include "internal.hxx"
typedef struct
types::InternalType::RealType type;
}ArgumentPosition;
-OUTPUT_STREAM_IMPEXP wchar_t** scilab_sprintf(wchar_t* _pwstName, wchar_t* _pwstInput, types::typed_list &in, ArgumentPosition* _pArgs, int _iArgsCount, int* _piOutputRows);
+OUTPUT_STREAM_IMPEXP_GW wchar_t** scilab_sprintf(wchar_t* _pwstName, wchar_t* _pwstInput, types::typed_list &in, ArgumentPosition* _pArgs, bool _bKeepEOL, int _iArgsCount, int* _piOutputRows);
#endif /* !__SCILAB_SPRINTF_HXX__ */
}
int iOutputRows = 0;
- wchar_t** pwstOutput = scilab_sprintf(L"mprintf", pwstInput, in, pArgs, iNumberPercent, &iOutputRows);
+ wchar_t** pwstOutput = scilab_sprintf(L"mprintf", pwstInput, in, pArgs, true, iNumberPercent, &iOutputRows);
for(int i = 0 ; i < iOutputRows ; i++)
{
YaspWriteW(pwstOutput[i]);
+ if(iOutputRows != 1)
+ {
+ //YaspWriteW(L"\n");
+ }
fflush(NULL);
FREE(pwstOutput[i]);
}
#include "scilab_sprintf.hxx"
#include "function.hxx"
#include "string.hxx"
+#include "overload.hxx"
+#include "execvisitor.hxx"
extern "C"
{
}
/*--------------------------------------------------------------------------*/
-types::Callable::ReturnValue sci_msprintf(types::typed_list &in, int _piRetCount, types::typed_list &out)
+types::Callable::ReturnValue sci_msprintf(types::typed_list &in, int _iRetCount, types::typed_list &out)
{
//Structure to store, link between % and input value
ArgumentPosition* pArgs = NULL;
{
if(in[i]->isDouble() == false && in[i]->isString() == false)
{
- //TODO: Overload
- ScierrorW(999, _W("%ls: Wrong type for input argument #%d: Real matrix or matrix of strings expected.\n"), L"msprintf", i + 1);
- return types::Function::Error;
+ std::wstring wstFuncName = L"%" + in[i]->getShortTypeStr() + L"_msprintf";
+ return Overload::call(wstFuncName, in, _iRetCount, out, new ExecVisitor());
}
}
}
int iOutputRows = 0;
- wchar_t** pwstOutput = scilab_sprintf(L"msprintf", pwstInput, in, pArgs, iNumberPercent, &iOutputRows);
+ wchar_t** pwstOutput = scilab_sprintf(L"msprintf", pwstInput, in, pArgs, false, iNumberPercent, &iOutputRows);
types::String* pOut = new types::String(iOutputRows, 1);
pOut->set(pwstOutput);
#include <stdio.h>
-wchar_t** scilab_sprintf(wchar_t* _pwstName, wchar_t* _pwstInput, typed_list &in, ArgumentPosition* _pArgs, int _iArgsCount, int* _piOutputRows)
+wchar_t** scilab_sprintf(wchar_t* _pwstName, wchar_t* _pwstInput, typed_list &in, ArgumentPosition* _pArgs, bool _bKeepEOL, int _iArgsCount, int* _piOutputRows)
{
wchar_t** pwstOutput = NULL;
wchar_t* pwstFirstOutput = NULL;
iToken++;
}
- int iLoop = in[1]->getAsGenericType()->getRows();
+ int iLoop = 1;
+ if(in.size() > 1)
+ {
+ iLoop = in[1]->getAsGenericType()->getRows();
+ for(int i = 2 ; i < in.size() ; i++)
+ {
+ iLoop = Min(iLoop, in[i]->getAsGenericType()->getRows());
+ }
+ }
+
pwstFirstOutput = (wchar_t*)MALLOC(sizeof(wchar_t*) * iLoop * bsiz);
memset(pwstFirstOutput, 0x00, sizeof(wchar_t*) * iLoop * bsiz);
for(int j = 0 ; j < iLoop ; j++)
void* pvVal = NULL;
if(_pArgs[i - 1].type == InternalType::RealDouble)
{
- double dblVal = in[_pArgs[i - 1].iArg]->getAs<Double>()->getReal(j, _pArgs[i - 1].iPos);
+ double dblVal = in[_pArgs[i - 1].iArg]->getAs<Double>()->get(j, _pArgs[i - 1].iPos);
if(pToken[i].outputType == InternalType::RealDouble)
{
swprintf(pwstTemp, bsiz, pToken[i].pwstToken, dblVal);
else if(_pArgs[i - 1].type == InternalType::RealString)
{
wchar_t* pwstStr = in[_pArgs[i - 1].iArg]->getAs<types::String>()->get(j, _pArgs[i - 1].iPos);
- int posC = wcscspn(pToken[i].pwstToken,L"c");
- int posS = wcscspn(pToken[i].pwstToken,L"s");
+ int posC = (int)wcscspn(pToken[i].pwstToken,L"c");
+ int posS = (int)wcscspn(pToken[i].pwstToken,L"s");
if(!posS || !posC)
{
return NULL;
if(pToken[i].bLengthFlag == false)
{
//replace %c by %lc to wide char compatibility
- int sizeTotal = wcslen(pToken[i].pwstToken);
+ int sizeTotal = (int)wcslen(pToken[i].pwstToken);
wchar_t* pwstToken = (wchar_t*)MALLOC(sizeof(wchar_t) * (sizeTotal + 2));
wcsncpy(pwstToken, pToken[i].pwstToken, posC);
pwstToken[posC] = L'l';
if(pToken[i].bLengthFlag == false)
{
//replace %s by %ls to wide char compatibility
- int sizeTotal = wcslen(pToken[i].pwstToken);
+ int sizeTotal = (int)wcslen(pToken[i].pwstToken);
wchar_t* pwstToken = (wchar_t*)MALLOC(sizeof(wchar_t) * (sizeTotal + 2));
wcsncpy(pwstToken, pToken[i].pwstToken, posS);
pwstToken[posS] = L'l';
wchar_t* pwstTemp = NULL;
while(pwstSlash != NULL)
{
- if((pwstTemp = wcsstr(pwstSlash, L"\\r\\n")) != NULL && pwstTemp[4] != '\0')
+ if((pwstTemp = wcsstr(pwstSlash, L"\\r\\n")) != NULL)
{
- (*_piOutputRows)++;
- pwstSlash = pwstTemp + 4;
+ if(pwstTemp[4] != '\0')
+ {
+ (*_piOutputRows)++;
+ pwstSlash = pwstTemp + 4;
+ }
+ else
+ {//end of string, so don't need to increament nulber of lines
+ pwstSlash = NULL;
+ }
}
- else if((pwstTemp = wcsstr(pwstSlash, L"\\r")) != NULL && pwstTemp[2] != '\0')
+ else if((pwstTemp = wcsstr(pwstSlash, L"\\r")) != NULL)
{
- (*_piOutputRows)++;
- pwstSlash = pwstTemp + 2;
+ if(pwstTemp[2] != '\0')
+ {
+ (*_piOutputRows)++;
+ pwstSlash = pwstTemp + 2;
+ }
+ else
+ {//end of string, so don't need to increament nulber of lines
+ pwstSlash = NULL;
+ }
}
- else if((pwstTemp = wcsstr(pwstSlash, L"\\n")) != NULL && pwstTemp[2] != '\0')
+ else if((pwstTemp = wcsstr(pwstSlash, L"\\n")) != NULL)
{
- (*_piOutputRows)++;
- pwstSlash = pwstTemp + 2;
+ if(pwstTemp[2] != '\0')
+ {
+ (*_piOutputRows)++;
+ pwstSlash = pwstTemp + 2;
+ }
+ else
+ {//end of string, so don't need to increament nulber of lines
+ pwstSlash = NULL;
+ }
}
else
{
pwstTemp = NULL;
}
- if(bNewLine)
- {//to insert '\0'
+ if(bNewLine && _bKeepEOL)
+ {//to insert '\n'
idx++;
}
pwstOutput[iRows] = (wchar_t*)MALLOC(sizeof(wchar_t) * (idx + 1));
wcsncpy(pwstOutput[iRows], pwstSlash, idx);
- if(bNewLine)
+ if(bNewLine && _bKeepEOL)
{
pwstOutput[iRows][idx - 1] = L'\n';
}
+
// =============================================================================
+
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+
// Copyright (C) 2008 - INRIA
+
//
+
// This file is distributed under the same license as the Scilab package.
+
// =============================================================================
+
// <-- JVM NOT MANDATORY -->
+
// unit tests for msprintf function
+
// =============================================================================
+
// format '%f'
+
// =============================================================================
+
if msprintf("%f",-35) <> "-35.000000" then bugmes();quit;end
+
if msprintf("%f",35.55) <> "35.550000" then bugmes();quit;end
+
if msprintf("%f",0.00433) <> "0.004330" then bugmes();quit;end
+
if msprintf("%f",0.0000000345456) <> "0.000000" then bugmes();quit;end
+
if msprintf("%f",1112423453) <> "1112423453.000000" then bugmes();quit;end
+
if msprintf("%15f",-35) <> " -35.000000" then bugmes();quit;end
+
if msprintf("%15f",0.00433) <> " 0.004330" then bugmes();quit;end
+
if msprintf("%15f",0.0000000345456) <> " 0.000000" then bugmes();quit;end
+
if msprintf("%15f",1112423453) <> "1112423453.000000" then bugmes();quit;end
+
if msprintf("%.1f" ,-35) <> "-35.0" then bugmes();quit;end
+
if msprintf("%.0f" ,-35) <> "-35" then bugmes();quit;end
+
if msprintf("%#.0f",-35) <> "-35." then bugmes();quit;end
+
if msprintf("%.1f" ,0.00433) <> "0.0" then bugmes();quit;end
+
if msprintf("%.15f",0.0000000345456) <> "0.000000034545600" then bugmes();quit;end
+
if msprintf("%.1f" ,11124234534545) <> "11124234534545.0" then bugmes();quit;end
+
// format '%g'
+
// =============================================================================
+
if msprintf("%g" ,-35) <> "-35" then bugmes();quit;end
+
if msprintf("%g" ,35.55) <> "35.55" then bugmes();quit;end
+
if msprintf("%g" ,35.551234567890) <> "35.5512" then bugmes();quit;end
+
if msprintf("%+g",35.551234567890) <> "+35.5512" then bugmes();quit;end
+
if msprintf("%g" ,0.00433) <> "0.00433" then bugmes();quit;end
+
if getos() == 'Windows' then
+
if msprintf("%g" ,0.0000000345456) <> "3.45456e-008" then bugmes();quit;end
+
else
+
if msprintf("%g" ,0.0000000345456) <> "3.45456e-08" then bugmes();quit;end
+
end
+
if getos() == 'Windows' then
+
if msprintf("%g" ,11124234534545) <> "1.11242e+013" then bugmes();quit;end
+
else
+
if msprintf("%g" ,11124234534545) <> "1.11242e+13" then bugmes();quit;end
+
end
+
if msprintf("%15g",-35) <> " -35" then bugmes();quit;end
+
if msprintf("%15g",0.00433) <> " 0.00433" then bugmes();quit;end
+
if getos() == 'Windows' then
+
if msprintf("%15g",0.0000000345456) <> " 3.45456e-008" then bugmes();quit;end
+
else
+
if msprintf("%15g",0.0000000345456) <> " 3.45456e-08" then bugmes();quit;end
+
end
+
if getos() == 'Windows' then
+
if msprintf("%15g",11124234534545) <> " 1.11242e+013" then bugmes();quit;end
+
else
+
if msprintf("%15g",11124234534545) <> " 1.11242e+13" then bugmes();quit;end
+
end
+
if getos() == 'Windows' then
+
if msprintf("%.1g",-35.1) <> "-4e+001" then bugmes();quit;end
+
else
+
if msprintf("%.1g",-35.1) <> "-4e+01" then bugmes();quit;end
+
end
+
if getos() == 'Windows' then
+
if msprintf("%.0g",-35.1) <> "-4e+001" then bugmes();quit;end
+
else
+
if msprintf("%.0g",-35.1) <> "-4e+01" then bugmes();quit;end
+
end
+
if getos() == 'Windows' then
+
if msprintf("%#.0g",-35.1) <> "-4.e+001" then bugmes();quit;end
+
else
+
if msprintf("%#.0g",-35.1) <> "-4.e+01" then bugmes();quit;end
+
end
+
if getos() == 'Windows' then
+
if msprintf("%#.0G",-35.1) <> "-4.E+001" then bugmes();quit;end
+
else
+
if msprintf("%#.0G",-35.1) <> "-4.E+01" then bugmes();quit;end
+
end
+
if msprintf("%.1g",0.00433) <> "0.004" then bugmes();quit;end
+
if getos() == 'Windows' then
+
if msprintf("%.15g",0.0000000345456) <> "3.45456e-008" then bugmes();quit;end
+
else
+
if msprintf("%.15g",0.0000000345456) <> "3.45456e-08" then bugmes();quit;end
+
end
+
if getos() == 'Windows' then
+
if msprintf("%.1g",11124234534545) <> "1e+013" then bugmes();quit;end
+
else
+
if msprintf("%.1g",11124234534545) <> "1e+13" then bugmes();quit;end
+
end
+
// format '%e'
+
// =============================================================================
+
if getos() == 'Windows' then
+
if msprintf("%e",-35) <> "-3.500000e+001" then bugmes();quit;end
+
else
+
if msprintf("%e",-35) <> "-3.500000e+01" then bugmes();quit;end
+
end
+
if getos() == 'Windows' then
+
if msprintf("%e",35.55) <> "3.555000e+001" then bugmes();quit;end
+
else
+
if msprintf("%e",35.55) <> "3.555000e+01" then bugmes();quit;end
+
end
+
if getos() == 'Windows' then
+
if msprintf("%+e",35.55) <> "+3.555000e+001" then bugmes();quit;end
+
else
+
if msprintf("%+e",35.55) <> "+3.555000e+01" then bugmes();quit;end
+
end
+
if getos() == 'Windows' then
+
if msprintf("%e",35.551234567890) <> "3.555123e+001" then bugmes();quit;end
+
else
+
if msprintf("%e",35.551234567890) <> "3.555123e+01" then bugmes();quit;end
+
end
+
if getos() == 'Windows' then
+
if msprintf("%e",0.00433) <> "4.330000e-003" then bugmes();quit;end
+
else
+
if msprintf("%e",0.00433) <> "4.330000e-03" then bugmes();quit;end
+
end
+
if getos() == 'Windows' then
+
if msprintf("%e",0.0000000345456) <> "3.454560e-008" then bugmes();quit;end
+
else
+
if msprintf("%e",0.0000000345456) <> "3.454560e-08" then bugmes();quit;end
+
end
+
if getos() == 'Windows' then
+
if msprintf("%e",11124234534545) <> "1.112423e+013" then bugmes();quit;end
+
else
+
if msprintf("%e",11124234534545) <> "1.112423e+13" then bugmes();quit;end
+
end
+
if getos() == 'Windows' then
+
if msprintf("%E",11124234534545) <> "1.112423E+013" then bugmes();quit;end
+
else
+
if msprintf("%E",11124234534545) <> "1.112423E+13" then bugmes();quit;end
+
end
+
if getos() == 'Windows' then
+
if msprintf("%15e",-35) <> " -3.500000e+001" then bugmes();quit;end
+
else
+
if msprintf("%15e",-35) <> " -3.500000e+01" then bugmes();quit;end
+
end
+
if getos() == 'Windows' then
+
if msprintf("%15e",0.00433) <> " 4.330000e-003" then bugmes();quit;end
+
else
+
if msprintf("%15e",0.00433) <> " 4.330000e-03" then bugmes();quit;end
+
end
+
if getos() == 'Windows' then
+
if msprintf("%15e",0.0000000345456) <> " 3.454560e-008" then bugmes();quit;end
+
else
+
if msprintf("%15e",0.0000000345456) <> " 3.454560e-08" then bugmes();quit;end
+
end
+
if getos() == 'Windows' then
+
if msprintf("%+15e",0.0000000345456) <> " +3.454560e-008" then bugmes();quit;end
+
else
+
if msprintf("%+15e",0.0000000345456) <> " +3.454560e-08" then bugmes();quit;end
+
end
+
if getos() == 'Windows' then
+
if msprintf("%15e",11124234534545) <> " 1.112423e+013" then bugmes();quit;end
+
else
+
if msprintf("%15e",11124234534545) <> " 1.112423e+13" then bugmes();quit;end
+
end
+
if getos() == 'Windows' then
+
if msprintf("%.1e",-35) <> "-3.5e+001" then bugmes();quit;end
+
else
+
if msprintf("%.1e",-35) <> "-3.5e+01" then bugmes();quit;end
+
end
+
if getos() == 'Windows' then
+
if msprintf("%.0e",-35.1) <> "-4e+001" then bugmes();quit;end
+
else
+
if msprintf("%.0e",-35.1) <> "-4e+01" then bugmes();quit;end
+
end
+
if getos() == 'Windows' then
+
if msprintf("%.1e",0.00433) <> "4.3e-003" then bugmes();quit;end
+
else
+
if msprintf("%.1e",0.00433) <> "4.3e-03" then bugmes();quit;end
+
end
+
if getos() == 'Windows' then
+
if msprintf("%.15e",0.0000000345456) <> "3.454560000000000e-008" then bugmes();quit;end
+
else
+
if msprintf("%.15e",0.0000000345456) <> "3.454560000000000e-08" then bugmes();quit;end
+
end
+
if getos() == 'Windows' then
+
if msprintf("%.1e",11124234534545) <> "1.1e+013" then bugmes();quit;end
+
else
+
if msprintf("%.1e",11124234534545) <> "1.1e+13" then bugmes();quit;end
+
end
+
// format '%c'
+
// =============================================================================
+
if msprintf("%c","t") <> "t" then bugmes();quit;end
+
if msprintf("%10c","t") <> " t" then bugmes();quit;end
+
if msprintf("%10.3c","t") <> " t" then bugmes();quit;end
+
if msprintf("%-10c","t") <> "t " then bugmes();quit;end
+
// format '%s'
+
// =============================================================================
+
if msprintf("%s","text") <> "text" then bugmes();quit;end
+
if msprintf("%10s","text") <> " text" then bugmes();quit;end
+
if msprintf("%10.3s","text") <> " tex" then bugmes();quit;end
+
if msprintf("%-10s","text") <> "text " then bugmes();quit;end
+
if msprintf("%s","t") <> "t" then bugmes();quit;end
+
// format '%x'
+
// =============================================================================
+
if msprintf("%x",123) <> "7b" then bugmes();quit;end
+
if msprintf("%.10x",123) <> "000000007b" then bugmes();quit;end
+
if msprintf("%x",-123) <> "ffffff85" then bugmes();quit;end
+
if msprintf("%X",-123) <> "FFFFFF85" then bugmes();quit;end
+
if msprintf("%#.3X",12) <> "0X00C" then bugmes();quit;end
+
// format '%o'
+
// =============================================================================
+
if msprintf("%015o",-12)<>"000037777777764" then bugmes();quit;end
+
// Vectorisation
+
// =============================================================================
+
nb_row = 10000;
+
// test 1
+
A = "row "+string(1:nb_row)';
+
B = 100*rand(nb_row,3);
+
C = msprintf("%10s => %08.4f %08.4f %08.4f\n",A,B);
+
if or(size(C) <> [nb_row,1]) then bugmes();quit;end
+
for i=1:nb_row
+
if length(C(i))<>40 then bugmes();quit;end
+
end
+
// test 2
+
B = 100*rand(nb_row,2);
+
C = 100*rand(nb_row,1);
+
D = msprintf("%10s => %08.4f %08.4f %08.4f\n",A,B,C);
+
if or(size(D) <> [nb_row,1]) then bugmes();quit;end
+
for i=1:nb_row
+
if length(D(i))<>40 then bugmes();quit;end
+
end
+
// test 3
+
B = 100*rand(nb_row,1);
+
C = 100*rand(nb_row,1);
+
D = 100*rand(nb_row,1);
+
E = msprintf("%10s => %08.4f %08.4f %08.4f\n",A,B,C,D);
+
if or(size(E) <> [nb_row,1]) then bugmes();quit;end
+
for i=1:nb_row
+
if length(E(i))<>40 then bugmes();quit;end
+
end
+
// test 4
+
B = 100*rand(nb_row,1);
+
if execstr("msprintf(""%10s => %08.4f %08.4f %08.4f\n"",A,B,B);","errcatch") == 0 then, pause end
+
if execstr("msprintf(""%10s => %08.4f %08.4f %08.4f\n"",A,B,B,B,B);","errcatch") == 0 then, pause end
+
// No arg
+
if execstr("msprintf();","errcatch") == 0 then, bugmes();quit;end
+
// overload: Arg not managed
-s=poly(0,"s");
-p=1+s+2*s^2;
-if execstr("msprintf(""plop"",p);","errcatch") <> 246 then, bugmes();quit;end
-if execstr("msprintf(""%s %s"",""plop"");","errcatch") <> 999 then, bugmes();quit;end
+
+p=1+%s+2*%s*%s;
+
+if execstr("msprintf(""plop"",p);","errcatch") == 0 then, bugmes();quit;end
+
+if execstr("msprintf(""%s %s"",""plop"");","errcatch") == 0 then, bugmes();quit;end
+
if execstr("msprintf();","errcatch") == 0 then, pause, end
// overload: Arg not managed
-s=poly(0,"s");
-p=1+s+2*s^2;
-if execstr("msprintf(""plop"",p);","errcatch") <> 246 then, pause, end
+p=1+%s+2*%s*%s;
+if execstr("msprintf(""plop"",p);","errcatch") == 0 then, pause, end
-if execstr("msprintf(""%s %s"",""plop"");","errcatch") <> 999 then, pause, end
+if execstr("msprintf(""%s %s"",""plop"");","errcatch") == 0 then, pause, end
// double / char / short / int / long long / unsigned ...
template<typename T>
void extractFullMatrix(T *_pT);
+ void extractFullMatrix(double *_pdbl);
};
}
virtual InternalType* clone(void) = 0;
- void IncreaseRef()
+ virtual void IncreaseRef()
{
m_iRef++;
}
** \}
*/
- private :
+ protected :
int m_iRef;
//use to know if we can delete this variables or if it's link to a scilab variable.
bool m_bAllowDelete;
/* return type as short string ( s, i, ce, l, ... )*/
virtual std::wstring getShortTypeStr() {return L"";}
+ virtual void IncreaseRef();
+ virtual void DecreaseRef();
+
private :
std::map<std::wstring, InternalType *>* m_pData;
};
virtual std::wstring toString(int _iPrecision, int _iLineLen);
std::vector<InternalType*> extractFields(std::list<std::wstring> _wstFields);
+ virtual void IncreaseRef();
+ virtual void DecreaseRef();
+
private :
virtual SingleStruct* getNullValue();
virtual Struct* createEmpty(int _iDims, int* _piDims, bool _bComplex = false);
bool bFP = false; // FloatingPoint
getDoubleFormat((m_pRealData[iPos]), _iPrecision, &iWidth, &iPrec, &bFP);
addDoubleValue(&ostr, (m_pRealData[iPos]), iWidth, iPrec);
+ ostr << endl;
}
else
{//complex value
return pIT;
}
+ void ImplicitList::extractFullMatrix(double *_pdbl)
+ {
+ double dblStart = m_poStart->getAs<Double>()->get(0);
+ double dblStep = m_poStep->getAs<Double>()->get(0);
+
+ _pdbl[0] = dblStart;
+ for(int i = 1 ; i < m_iSize ; i++)
+ {
+ _pdbl[i] = _pdbl[i - 1] + dblStep;
+ }
+ }
+
template<typename T>
void ImplicitList::extractFullMatrix(T *_pT)
{
T tStart = static_cast<T>(convert_input(m_poStart));
T tStep = static_cast<T>(convert_input(m_poStep));
- for(int i = 0 ; i < m_iSize ; i++)
+ _pT[0] = tStart;
+ for(int i = 1 ; i < m_iSize ; i++)
{
- _pT[i] = tStart + tStep * i;
+ _pT[i] = _pT[i - 1] + tStep;
}
}
}
try
{
-
m_body->mute();
MuteVisitor mute;
m_body->accept(mute);
(*m_pData)[_sKey] = Double::Empty();
return true;
}
+
+ void SingleStruct::IncreaseRef()
+ {
+ std::map<std::wstring, InternalType *>::iterator it;
+
+ for (it = m_pData->begin() ; it != m_pData->end() ; it++)
+ {
+ it->second->IncreaseRef();
+ }
+ }
+
+ void SingleStruct::DecreaseRef()
+ {
+ std::map<std::wstring, InternalType *>::iterator it;
+
+ for (it = m_pData->begin() ; it != m_pData->end() ; it++)
+ {
+ it->second->DecreaseRef();
+ if(it->second->isDeletable())
+ {
+ delete it->second;
+ }
+ }
+ }
}
std::wstring wstField(pwstFields->get(i));
InternalType* pIT = pSS->get(wstField);
- ostr << L" " << wstField << ": ";
+// ostr << L" " << wstField << ": ";
+ ostr << L" " << wstField << "[" << pIT->getRef() << "]: ";
ostr << pIT->toStringInLine(_iPrecision, _iLineLen);
ostr << std::endl;
}
}
return ResultList;
}
+
+ void Struct::IncreaseRef()
+ {
+ m_iRef++;
+ //increaseRef of children too
+ for(int i = 0 ; i < getSize() ; i++)
+ {
+ get(i)->IncreaseRef();
+ }
+ }
+
+ void Struct::DecreaseRef()
+ {
+ m_iRef--;
+ //increaseRef of children too
+ for(int i = 0 ; i < getSize() ; i++)
+ {
+ get(i)->DecreaseRef();
+ }
+ }
}