* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
* Copyright (C) 2009 - DIGITEO - Antoine ELIAS
* Copyright (C) 2009-2011 - DIGITEO - Allan CORNET
+ * Copyright (C) 2015 - Scilab Enterprises - Anais AUBERT
*
* This file must be used under the terms of the CeCILL.
* This source file is licensed as described in the file COPYING, which
int allocSingleString(void* _pvCtx, int _iVar, int _iLen, const char** _pstStrings)
{
SciErr sciErr = sciErrInit();
-#if 0
- int iNewPos = Top - Rhs + _iVar;
- int iAddr = *Lstk(iNewPos);
- int* piAddr = NULL;
- int* piOffset = NULL;
- char* pstString = NULL;
- int iFreeSpace = iadr(*Lstk(Bot)) - (iadr(*Lstk(Top)));
+ GatewayStruct* pGstr = (GatewayStruct*)_pvCtx;
+ typed_list in = *pGstr->m_pIn;
+ InternalType** out = pGstr->m_pOut;
+ String *pStr = NULL;
- if (_iLen + 2 > iFreeSpace)
+
+ char* pstStrings = new char[_iLen];
+
+ memset(pstStrings, ' ', _iLen);
+ _pstStrings[0] = pstStrings;
+ if (_pstStrings == NULL)
{
- addStackSizeError(&sciErr, ((StrCtx*)_pvCtx)->pstName, _iLen + 2);
+ addErrorMessage(&sciErr, API_ERROR_NO_MORE_MEMORY, _("%s: No more memory to allocate variable"), "allocSingleString");
return sciErr.iErr;
}
- getNewVarAddressFromPosition(_pvCtx, iNewPos, &piAddr);
+ pStr = new String(pstStrings);
- piAddr[0] = sci_strings;
- piAddr[1] = 1;
- piAddr[2] = 1;
- piAddr[3] = 0;
+ if (pStr == NULL)
+ {
+ addErrorMessage(&sciErr, API_ERROR_NO_MORE_MEMORY, _("%s: No more memory to allocate variable"), "allocSingleString");
+ return sciErr.iErr;
+ }
- piOffset = piAddr + 4;
- piOffset[0] = 1; //Always 1
- piOffset[1] = _iLen + 1;
- pstString = (char*)(piOffset + 2); //2 offsets
-#endif
- return 0;
+ int rhs = _iVar - *getNbInputArgument(_pvCtx);
+ out[rhs - 1] = pStr;
+
+
+ return sciErr.iErr;
}
/*--------------------------------------------------------------------------*/
if (nbOutputArgument(pvApiCtx) >= 5)
{
- char* strRep = NULL;
+ char *strRep = NULL;
AssignOutputVariable(pvApiCtx, 5) = nbInputArgument(pvApiCtx) + 5;
istr = (int)strlen(menuCallback);
- if (allocSingleString(pvApiCtx, nbInputArgument(pvApiCtx) + 5, istr * one, (const char**)&strRep))
+ if (allocSingleString(pvApiCtx, nbInputArgument(pvApiCtx) + 5, istr * one, &strRep))
{
Scierror(999, _("%s: Memory allocation error.\n"), fname);
return 1;
}
-
strncpy(strRep, menuCallback, istr);
}