/*--------------------------------------------------------------------------*/ int C2F(sci_getlanguagealias)(char *fname,unsigned long fname_len) { static int l1,n1,m1; char *Output=NULL; CheckRhs(0,0); CheckLhs(0,1); Output=getlanguagealias(); if (Output) { n1=1; CreateVarFromPtr( Rhs+1,STRING_DATATYPE,(m1=(int)strlen(Output), &m1),&n1,&Output); LhsVar(1) = Rhs+1; PutLhsVar();; if (Output) {FREE(Output);Output=NULL;} } else { m1=0; n1=0; l1=0; CreateVar(Rhs+1,MATRIX_OF_DOUBLE_DATATYPE, &m1, &n1, &l1); LhsVar(1)=Rhs+1; PutLhsVar();; return 0; } return 0; }

/*--------------------------------------------------------------------------*/ static int sci_emptystr_one_rhs(char *fname) { int m1 = 0, n1 = 0; /* m1 is the number of row ; n1 is the number of col*/ /*With a matrix for input argument returns a zero length character strings matrix of the same size */ int Type = VarType(1); if (Type == sci_matrix) { char **Input_StringMatrix_One = NULL; GetRhsVar(1, MATRIX_OF_DOUBLE_DATATYPE, &m1, &n1, &Input_StringMatrix_One); if ((m1 == 0) && (n1 == 0)) /* emptystr([]) */ { int l = 0; CreateVar(Rhs + 1, MATRIX_OF_DOUBLE_DATATYPE, &m1, &n1, &l); LhsVar(1) = Rhs + 1 ; PutLhsVar(); return 0; } } else { if ((Type == sci_mlist) || (Type == sci_tlist)) { /* compatibility with 4.1.2 */ int lw = 1 + Top - Rhs; C2F(overload)(&lw, fname, (int)strlen(fname)); return 0; } else { int RHSPOS = 1; int l1 = 0; int il = 0; int lw = RHSPOS + Top - Rhs; l1 = *Lstk(lw); il = iadr(l1); if (*istk(il ) < 0) { il = iadr(*istk(il + 1)); } /* get dimensions */ m1 = getNumberOfLines(il); /* row */ n1 = getNumberOfColumns(il); /* col */ } } /* m1 is the number of row ; n1 is the number of col*/ CreateVarFromPtr(Rhs + 1, MATRIX_OF_STRING_DATATYPE, &m1, &n1, NULL); LhsVar(1) = Rhs + 1; PutLhsVar(); return 0; }

int ScilabGateway::getsetOptions(char * fname, const int envId, ScilabAbstractOptionsSetter & setter, void * pvApiCtx) { SciErr sciErr; int * addr = 0; int val = 0; CheckInputArgument(pvApiCtx, 0, 1); CheckOutputArgument(pvApiCtx, 1, 1); ScilabAbstractEnvironment & env = ScilabEnvironments::getEnvironment(envId); ScilabGatewayOptions & options = env.getGatewayOptions(); OptionsHelper::setCopyOccured(false); ScilabObjects::initialization(env, pvApiCtx); options.setIsNew(false); if (Rhs == 0) { createScalarBoolean(pvApiCtx, 1, (int)setter.get()); LhsVar(1) = 1; PutLhsVar(); return 0; } sciErr = getVarAddressFromPosition(pvApiCtx, 1, &addr); if (sciErr.iErr) { throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data")); } if (!isBooleanType(pvApiCtx, addr)) { throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Wrong type for input argument #%d: A boolean expected."), 1); } if (!isScalar(pvApiCtx, addr)) { throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Wrong type for input argument #%d: A single boolean expected."), 1); } getScalarBoolean(pvApiCtx, addr, &val); setter.set(val == 1); LhsVar(1) = 0; PutLhsVar(); return 0; }

/*--------------------------------------------------------------------------*/ int sci_fromjava(char *fname, unsigned long fname_len) { static int n1; int *paramoutINT = (int*)MALLOC(sizeof(int) + 1); Rhs = Max(0, Rhs); CheckRhs(0, 0); CheckLhs(1, 1); if ( IsFromJava() ) { *paramoutINT = (int)(TRUE); } else { *paramoutINT = (int)(FALSE); } n1 = 1; CreateVarFromPtr(Rhs + 1, MATRIX_OF_BOOLEAN_DATATYPE, &n1, &n1, ¶moutINT); if (paramoutINT) { FREE(paramoutINT); paramoutINT = NULL; } LhsVar(1) = Rhs + 1; PutLhsVar(); return 0; }

/* ========================================================================== */ int sci_gpuDeviceMemInfo(char *fname) { #ifdef WITH_CUDA if(isGpuInit()) { if (useCuda()) { size_t free = 0, total = 0; cuMemGetInfo(&free,&total); double freeMem = (double)free; createScalarDouble(pvApiCtx, Rhs + 1, freeMem); } else { double zero = 0.; createScalarDouble(pvApiCtx, Rhs + 1, zero); sciprint("not implemented with OpenCL.\n"); } LhsVar(1) = Rhs + 1; PutLhsVar(); } else { Scierror(999,"%s","gpu is not initialised. Please launch gpuInit() before use this function.\n"); } #else sciprint("not implemented with OpenCL.\n"); #endif return 0; }

/*--------------------------------------------------------------------------*/ int sci_type(char *fname, void* pvApiCtx) { SciErr sciErr; int* piAddr = NULL; int iType = 0; int iRet = 0; CheckRhs(1, 1); CheckLhs(1, 1); sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr); if (sciErr.iErr) { printError(&sciErr, 0); return 0; } sciErr = getVarType(pvApiCtx, piAddr, &iType); if (sciErr.iErr) { printError(&sciErr, 0); return 0; } iRet = createMatrixOfDoubleFromInteger(pvApiCtx, Rhs + 1, 1, 1, &iType); if (iRet) { return 0; } LhsVar(1) = Rhs + 1; PutLhsVar(); return 0; }

/* ========================================================================== */ int sci_gpuLoadDynLib(char* fname) { int row = 0; int col = 0; int* piLen = NULL; char** pstData = NULL; int* pstrA = NULL; int inputType_A = 0; int i = 0; CheckRhs(1, 1); CheckLhs(0, 1); // get lib getVarAddressFromPosition(pvApiCtx,1,&pstrA); getVarType(pvApiCtx, pstrA, &inputType_A); getMatrixOfString(pvApiCtx, pstrA, &row, &col, NULL, NULL); piLen = (int*)malloc(sizeof(int) * row * col); getMatrixOfString(pvApiCtx, pstrA, &row, &col, piLen, NULL); pstData = (char**)malloc(sizeof(char*) * row * col); for(i = 0 ; i < row * col ; i++) { pstData[i] = (char*)malloc(sizeof(char) * (piLen[i] + 1)); } getMatrixOfString(pvApiCtx, pstrA, &row, &col, piLen, pstData); // open lib printf("%s\n", *pstData); Sci_dlopen(*pstData); LhsVar(1) = Rhs + 1; PutLhsVar(); return 0; }

int ScilabGateway::getRepresentation(char * fname, const int envId, void * pvApiCtx) { SciErr err; int * addr = 0; int tmpvar[2] = {0, 0}; int idObj = 0; CheckInputArgument(pvApiCtx, 1, 1); ScilabAbstractEnvironment & env = ScilabEnvironments::getEnvironment(envId); ScilabGatewayOptions & options = env.getGatewayOptions(); OptionsHelper::setCopyOccurred(false); ScilabObjects::initialization(env, pvApiCtx); options.setIsNew(false); err = getVarAddressFromPosition(pvApiCtx, 1, &addr); if (err.iErr) { throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data")); } if (!ScilabObjects::isExternalObjOrClass(addr, pvApiCtx)) { throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Wrong type for input argument #%d: An External Object expected."), 1); } idObj = ScilabObjects::getArgumentId(addr, tmpvar, false, false, envId, pvApiCtx); env.getrepresentation(idObj, ScilabStringStackAllocator(pvApiCtx, Rhs + 1)); LhsVar(1) = Rhs + 1; PutLhsVar(); return 0; }

/*--------------------------------------------------------------------------*/ static int sci_stacksizeNoRhs(char *fname) { int n1 = 0, m1 = 0; int *paramoutINT = NULL; int total = 0; int used = 0; paramoutINT = (int *)MALLOC(sizeof(int) * 2); C2F(getstackinfo) (&total, &used); paramoutINT[0] = total; paramoutINT[1] = used; n1 = 1; m1 = 2; CreateVarFromPtr(Rhs + 1, MATRIX_OF_INTEGER_DATATYPE, &n1, &m1, (int *)¶moutINT); LhsVar(1) = Rhs + 1; if (paramoutINT) { FREE(paramoutINT); paramoutINT = NULL; } PutLhsVar(); return 0; }

/*--------------------------------------------------------------------------*/ int C2F(sci_havewindow)(char *fname, unsigned long fname_len) { static int n1, m1; int *Status = NULL; CheckRhs(0, 1); CheckLhs(1, 1); Status = (int*)MALLOC(sizeof(int)); *Status = (int) ( getScilabMode() == SCILAB_STD ); m1 = 1; n1 = 1; CreateVarFromPtr(Rhs + 1, MATRIX_OF_BOOLEAN_DATATYPE, &n1, &n1, &Status); LhsVar(1) = Rhs + 1; if (Status) { FREE(Status); Status = NULL; } PutLhsVar(); return 0; }

int sci_curblockc(char *fname, unsigned long fname_len) { /*********************** * variables declaration ***********************/ /* address of the data of the output parameter */ int l1 = 0; /* local counter variable */ int j = 1, k = 1; /* definition of min/max output argument */ static int minlhs = 1, maxlhs = 1; /************************** * Check number of outputs **************************/ CheckLhs(minlhs, maxlhs); /************************ * Create double variable ************************/ /* Create int32 variable at the top addr. of the stack */ CreateVar(1, MATRIX_OF_DOUBLE_DATATYPE, &j, &k, &l1); /* Store value of C2F(curblk).kfun at the l1 address in istk */ *stk(l1) = (double)C2F(curblk).kfun; /* return the value stored at Top address to lhs variable */ LhsVar(1) = 1; PutLhsVar(); /* return 0 as default value */ return 0; }

/*--------------------------------------------------------------------------*/ int sci_xname(char *fname, unsigned long fname_len) { int m1 = 0, n1 = 0, l1 = 0; char *pstCurrentFigure = NULL; CheckRhs(1, 1); CheckLhs(1, 1); GetRhsVar(1, STRING_DATATYPE, &m1, &n1, &l1); pstCurrentFigure = getCurrentFigure(); if (pstCurrentFigure == NULL) { pstCurrentFigure = createNewFigureWithAxes(); } setGraphicObjectProperty(pstCurrentFigure, __GO_NAME__, cstk(l1), jni_string, 1); LhsVar(1) = 0; PutLhsVar(); return 0; }

/*--------------------------------------------------------------------------*/ int sci_ctree2(char *fname, unsigned long fname_len) { int one = 1, ipvec = 0, nvec = 0, mvec = 0, noin = 0, moin = 0, ipoin = 0, noinr = 0, moinr = 0, ipoinr = 0; int ndep = 0, mdep = 0, ipdep = 0, ndepuptr = 0, mdepuptr = 0, ipdepuptr = 0, ipord = 0, ipok = 0, n = 0, nord = 0; CheckRhs(5, 5); CheckLhs(2, 2); GetRhsVar(1, MATRIX_OF_INTEGER_DATATYPE, &nvec, &mvec, &ipvec); GetRhsVar(2, MATRIX_OF_INTEGER_DATATYPE, &noin, &moin, &ipoin); GetRhsVar(3, MATRIX_OF_INTEGER_DATATYPE, &noinr, &moinr, &ipoinr); GetRhsVar(4, MATRIX_OF_INTEGER_DATATYPE, &ndep, &mdep, &ipdep); GetRhsVar(5, MATRIX_OF_INTEGER_DATATYPE, &ndepuptr, &mdepuptr, &ipdepuptr); n = nvec * mvec; CreateVar(6, MATRIX_OF_INTEGER_DATATYPE, &n, &one, &ipord); CreateVar(7, MATRIX_OF_INTEGER_DATATYPE, &one, &one, &ipok); ctree2(istk(ipvec), n, istk(ipdep), istk(ipdepuptr), istk(ipoin), istk(ipoinr), istk(ipord), &nord, istk(ipok)); *istk(iadr(C2F(intersci).iwhere[5]) + 1) = nord; LhsVar(1) = 6; LhsVar(2) = 7; PutLhsVar(); return 0; }

/*--------------------------------------------------------------------------*/ int sci_loadfftwlibrary(char *fname,unsigned long fname_len) { static int l1,n1,m1; char *FFTWLibname=NULL; CheckRhs(1,1); if (GetType(1) == sci_strings) { GetRhsVar(1,STRING_DATATYPE,&m1,&n1,&l1); FFTWLibname=cstk(l1); setfftwlibname(FFTWLibname); n1=1; if ( LoadFFTWLibrary(FFTWLibname) ) { CreateVar(Rhs+1,MATRIX_OF_BOOLEAN_DATATYPE, &n1,&n1,&l1); *istk(l1)=(int)(TRUE); } else { CreateVar(Rhs+1,MATRIX_OF_BOOLEAN_DATATYPE, &n1,&n1,&l1); *istk(l1)=(int)(FALSE); } LhsVar(1)=Rhs+1; PutLhsVar(); } else { Scierror(999,_("%s: Wrong type for input argument #%d: A string expected.\n"),fname,1); } return(0); }

/*--------------------------------------------------------------------------*/ int sci_gethistoryfile(char *fname, unsigned long fname_len) { char *filename = NULL; int m1 = 0, n1 = 0; CheckRhs(0, 0) ; CheckLhs(0, 1) ; filename = getFilenameScilabHistory(); if (filename) { n1 = 1; m1 = (int)strlen(filename); CreateVarFromPtr(Rhs + 1, STRING_DATATYPE, &m1, &n1, &filename); if (filename) { FREE(filename); filename = NULL; } LhsVar(1) = Rhs + 1; PutLhsVar(); } else { Scierror(999, _("%s: An error occurred: %s\n"), fname, _("filename not defined.")); } return 0; }

/*--------------------------------------------------------------------------*/ static int OneLhs(struct VariableStruct* Vstruct,int lenStructArray,BOOL Sorted) { int i=0; int m=0; int n=0; char **LocalTab = NULL; if (Sorted) SortVarsStructByStrings(Vstruct,lenStructArray); LocalTab=(char **)MALLOC(sizeof(char*)*(lenStructArray)); for (i=0;i<lenStructArray;i++) { if (strlen(Vstruct[i].NameVariable)>0) { LocalTab[i] = strdup(Vstruct[i].NameVariable); } } m=lenStructArray; n=1; CreateVarFromPtr(Rhs+1,MATRIX_OF_STRING_DATATYPE, &m, &n,LocalTab); LhsVar(1)=Rhs+1; freeArrayOfString(LocalTab, lenStructArray); PutLhsVar(); return 0; }

/*--------------------------------------------------------------------------*/ static int TwoLhs(struct VariableStruct* Vstruct,int lenStructArray,BOOL Sorted) { char **Tab=NULL; int *Size=NULL; int i=0; int m=0; int n=0; if (Sorted) SortVarsStructByStrings(Vstruct,lenStructArray); Tab=(char **)MALLOC(sizeof(char*)*lenStructArray); Size=(int *)MALLOC(sizeof(int)*lenStructArray); for (i=0;i<lenStructArray;i++) { Tab[i] = strdup(Vstruct[i].NameVariable); Size[i]=Vstruct[i].SizeVariable; } m=lenStructArray; n=1; CreateVarFromPtr(Rhs+1,MATRIX_OF_STRING_DATATYPE, &m, &n, Tab); LhsVar(1) = Rhs+1; CreateVarFromPtr(Rhs+2,MATRIX_OF_INTEGER_DATATYPE, &m, &n, &Size); LhsVar(2) = Rhs+2; freeArrayOfString(Tab, lenStructArray); if (Size) {FREE(Size);Size=NULL;} PutLhsVar(); return 0; }

/*--------------------------------------------------------------------------*/ static int NoRhs(struct VariableStruct* GVstruct,int GlenStructArray,struct VariableStruct* LVstruct,int LlenStructArray,BOOL Sorted) { int memtotal=0; int memused=0; int vartotal=0; int varused=0; int gmemtotal=0; int gmemused=0; int gvartotal=0; int gvarused=0; C2F(getstackinfo)(&memtotal,&memused); C2F(getvariablesinfo)(&vartotal,&varused); if (Sorted) SortVarsStructByStrings(LVstruct,LlenStructArray); DispVariables(LVstruct,_("Your variables are:"),LlenStructArray,memused,memtotal,varused,vartotal); C2F(getgstackinfo)(&gmemtotal,&gmemused); C2F(getgvariablesinfo)(&gvartotal,&gvarused); if (Sorted) SortVarsStructByStrings(GVstruct,GlenStructArray); DispVariables(GVstruct,_("Your global variables are:"),GlenStructArray,gmemused,gmemtotal,gvarused,gvartotal); LhsVar(1) = 0; PutLhsVar(); return 0; }

/*--------------------------------------------------------------------------*/ int sci_timer(char *fname,unsigned long fname_len) { double timerval = 0; Rhs = Max(0, Rhs); CheckLhs(0,1); CheckRhs(0,0); timerval = scilab_timer(); if (timerval >= 0.) { int l1 = 0, n1 = 1; CreateVar(Rhs+1,MATRIX_OF_DOUBLE_DATATYPE, &n1, &n1,&l1); *stk(l1) = (double)timerval; LhsVar(1) = Rhs+1; PutLhsVar(); } else { Scierror(999,_("%s: An error occurred.\n"), fname); } return 0; }

/*--------------------------------------------------------------------------*/ int sci_iswaitingforinput(char *fname, unsigned long fname_len) { BOOL res = FALSE; int un = 1, outIndex = 0; Rhs = Max(Rhs, 0); CheckRhs(0, 1); CheckLhs(0, 1); if (getScilabMode() == SCILAB_STD) { res = ConsoleIsWaitingForInput(); } else { sciprint(_("%s: Not implemented in this mode.\n"), fname); } CreateVar(Rhs + 1, MATRIX_OF_BOOLEAN_DATATYPE, &un, &un, &outIndex); *istk(outIndex) = res; LhsVar(1) = Rhs + 1; PutLhsVar(); return 0; }

/*--------------------------------------------------------------------------*/ int sci_exportUI(char * fname, unsigned long fname_len) { int iFigureId = 0; // id of the figure to export int iRows = 0; int iCols = 0; size_t stackPointer = 0; CheckLhs(0, 1); CheckRhs(1, 1); if (GetType(1) == sci_handles) // exportUI(figHandle) { const char *pstFigureUID = NULL; int iHandleType = -1; int *piHandleType = &iHandleType; int *piFigureId = &iFigureId; GetRhsVar(1, GRAPHICAL_HANDLE_DATATYPE, &iRows, &iCols, &stackPointer); if (iRows * iCols != 1) { Scierror(999, _("%s: Wrong size for input argument #%d: A Real Scalar or a 'Figure' handle expected.\n"), fname, 1); } pstFigureUID = getObjectFromHandle((unsigned long) * (hstk(stackPointer))); getGraphicObjectProperty(pstFigureUID, __GO_TYPE__, jni_int, (void **)&piHandleType); if (iHandleType == __GO_FIGURE__) { Scierror(999, _("%s: Wrong type for input argument #%d: A Real Scalar or a 'Figure' handle expected.\n"), fname, 1); return FALSE; } getGraphicObjectProperty(pstFigureUID, __GO_ID__, jni_int, (void **)&piFigureId); } else if (GetType(1) == sci_matrix) // exportUI(figId) { GetRhsVar(1, MATRIX_OF_DOUBLE_DATATYPE, &iRows, &iCols, &stackPointer); if (iRows * iCols != 1) { Scierror(999, _("%s: Wrong size for input argument #%d: A Real Scalar or a 'Figure' handle expected.\n"), fname, 1); return FALSE; } iFigureId = (int) * (stk(stackPointer)); } else { Scierror(999, _("%s: Wrong type for input argument #%d: A Real Scalar or a 'Figure' handle expected.\n"), fname, 1); return FALSE; } // call the export function exportUserInterface(iFigureId); LhsVar(1) = 0; PutLhsVar(); return 0; }

/*--------------------------------------------------------------------------*/ int sci_xfarcs(char *fname, unsigned long fname_len) { int m1 = 0, n1 = 0, l1 = 0; int m2 = 0, n2 = 0, l2 = 0; long hdl = 0; int i = 0; double angle1 = 0.0; double angle2 = 0.0; CheckRhs(1, 2); GetRhsVar(1, MATRIX_OF_DOUBLE_DATATYPE, &m1, &n1, &l1); if (m1 != 6) { Scierror(999, _("%s: Wrong size for input argument #%d: %s expected.\n"), fname, 1, "(6,n)"); return 0; } if (Rhs == 2) { GetRhsVar(2, MATRIX_OF_INTEGER_DATATYPE, &m2, &n2, &l2); CheckVector(2, m2, n2); if (n1 != m2 * n2) { Scierror(999, _("%s: Wrong size for input arguments #%d and #%d.\n"), fname, 1, 2); return 0; } } else { m2 = 1; n2 = n1; CreateVar(2, MATRIX_OF_INTEGER_DATATYPE, &m2, &n2, &l2); for (i = 0; i < n2; ++i) { *istk(l2 + i) = i + 1; } } getOrCreateDefaultSubwin(); for (i = 0; i < n1; ++i) { angle1 = DEG2RAD(*stk(l1 + (6 * i) + 4) / 64.0); angle2 = DEG2RAD(*stk(l1 + (6 * i) + 5) / 64.0); Objarc(&angle1, &angle2, stk(l1 + (6 * i)), stk(l1 + (6 * i) + 1), stk(l1 + (6 * i) + 2), stk(l1 + (6 * i) + 3), istk(l2 + i), istk(l2 + i), TRUE, FALSE, &hdl); } /** Construct Compound and make it current object **/ setCurrentObject(ConstructCompoundSeq(n1)); LhsVar(1) = 0; PutLhsVar(); return 0; }

int empty(void) { int m, n; int k; int m1, n1, p1; int m2, n2, p2; int NZMAX = 1; int jc = 5; int ir; int *header; double *value; GetRhsVar(1, MATRIX_OF_DOUBLE_DATATYPE, &m1, &n1, &p1); GetRhsVar(2, MATRIX_OF_DOUBLE_DATATYPE, &m2, &n2, &p2); m = (int) * stk(p1); n = (int) * stk(p2); CreateData(3, (6 + n + 1)*sizeof(int) + sizeof(double)); header = (int *) GetData(3); value = (double *) header; header[0] = 7; header[1] = m; header[2] = n; header[3] = 0; header[4] = NZMAX; header[jc] = 0; ir = jc + n + 1; for (k = 0; k < n; ++k) { header[jc + k + 1] = 0; } header[ir] = 0; value[(5 + header[2] + header[4]) / 2 + 1] = 0.0; LhsVar(1) = 3; PutLhsVar(); return 1; }

/*--------------------------------------------------------------------------*/ int sci_librarieslist(char *fname, unsigned long fname_len) { char **libraries = NULL; int sizelibraries = 0; CheckRhs(0, 0); CheckLhs(0, 1); libraries = getlibrarieslist(&sizelibraries); if (libraries) { int m = 0, n = 0; m = sizelibraries; n = 1; CreateVarFromPtr(Rhs + 1, MATRIX_OF_STRING_DATATYPE, &m, &n, libraries); } else { int m = 0, n = 0, l = 0; CreateVarFromPtr(Rhs + 1, MATRIX_OF_DOUBLE_DATATYPE, &n, &m, &l); } LhsVar(1) = Rhs + 1; freeArrayOfString(libraries, sizelibraries); PutLhsVar(); return 0; }

/*-------------------------------------------------------------------------------------*/ static int sci_strcat_rhs_one_is_a_matrix(char *fname) { /* strcat([],'A') returns an empty string matrix */ double *Input_String_One = NULL; int Row_One = 0, Col_One = 0; GetRhsVar(1, MATRIX_OF_DOUBLE_DATATYPE, &Row_One, &Col_One, &Input_String_One); /* check that we have [] */ if ((Row_One == 0) && (Col_One == 0)) { int one = 1; int len = (int)strlen(EMPTY_CHAR); int outIndex = 0; CreateVar(Rhs + 1, STRING_DATATYPE, &len, &one, &outIndex); strcpy(cstk(outIndex), EMPTY_CHAR); LhsVar(1) = Rhs + 1; PutLhsVar(); } else { Scierror(999, _("%s: Wrong type for input argument #%d: Matrix of strings or empty real matrix expected.\n"), fname, 1); } return 0; }

int ScilabGateway::unwrapremove(char * fname, const int envId, void * pvApiCtx) { SciErr err; int * addr = 0; int row = 0, col = 0; int * id = 0; if (Rhs == 0) { throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Wrong number of arguments : more than 1 argument expected")); } CheckOutputArgument(pvApiCtx, Rhs, Rhs); ScilabAbstractEnvironment & env = ScilabEnvironments::getEnvironment(envId); ScilabGatewayOptions & options = env.getGatewayOptions(); OptionsHelper::setCopyOccurred(false); ScilabObjects::initialization(env, pvApiCtx); options.setIsNew(false); for (int i = 1; i <= Rhs; i++) { err = getVarAddressFromPosition(pvApiCtx, i, &addr); if (err.iErr) { throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data")); } if (!ScilabObjects::isExternalObj(addr, pvApiCtx)) { throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Wrong type for input argument #%d: An External Object expected."), i); } err = getMatrixOfInteger32InList(pvApiCtx, addr, EXTERNAL_OBJ_ID_POSITION, &row, &col, &id); if (err.iErr) { throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data")); } if (!ScilabObjects::unwrap(*id, Rhs + i, envId, pvApiCtx)) { try { ScilabObjects::createEnvironmentObjectAtPos(EXTERNAL_OBJECT, Rhs + i, *id, envId, pvApiCtx); } catch (ScilabAbstractEnvironmentException & /*e*/) { } } LhsVar(i) = Rhs + i; env.removeobject(*id); } PutLhsVar(); return 0; }

/*--------------------------------------------------------------------------*/ int sci_deletefile(char *fname,unsigned long fname_len) { CheckRhs(1,1); CheckLhs(1,1); if (GetType(1) == sci_strings) { int m1,n1,l1; char *VarName=NULL; GetRhsVar(1,STRING_DATATYPE,&m1,&n1,&l1); /* Bug 3089 */ VarName = cstk(l1); n1=1; if ( deleteafile(VarName) ) { CreateVar(Rhs+1,MATRIX_OF_BOOLEAN_DATATYPE, &n1,&n1,&l1); *istk(l1)=(int)(TRUE); } else { CreateVar(Rhs+1,MATRIX_OF_BOOLEAN_DATATYPE, &n1,&n1,&l1); *istk(l1)=(int)(FALSE); } LhsVar(1)=Rhs+1; PutLhsVar(); } else { Scierror(999,_("%s: Wrong type for input argument: A string expected.\n"),fname); } return 0; }

/* * Stub function to load the gateway */ int sci_loadXcos(char *fname, unsigned long fname_len) { CheckRhs(0, 1); LhsVar(1) = 0; PutLhsVar(); return 0; }

/*--------------------------------------------------------------------------*/ int sci_getsystemmetrics(char *fname, unsigned long l) { char *param = NULL; int nIndex = -1; int m1 = 0; int n1 = 0; int l1 = 0; CheckRhs(1, 1); if (GetType(1) != sci_strings) { Scierror(999, _("%s: Wrong type for input argument #%d: String expected.\n"), fname, 1); return 0; } GetRhsVar(1, STRING_DATATYPE, &m1, &n1, &l1); param = cstk(l1); nIndex = getnIndexFromString(param); if ( nIndex > -1 ) { int one = 1; CreateVar(Rhs + 1, MATRIX_OF_INTEGER_DATATYPE, &one, &one, &l1); *istk(l1) = GetSystemMetrics(nIndex); LhsVar(1) = Rhs + 1; PutLhsVar(); } else { Scierror(999, _("%s: Wrong value for input argument: %s.\n"), fname, _("see help")); } return 0; }

/*------------------------------------------------------------------------*/ int sci_grep(char *fname, unsigned long fname_len) { CheckRhs(2, 3); CheckLhs(1, 2); if (VarType(1) == sci_matrix) { int m1 = 0, n1 = 0; char **Str = NULL; GetRhsVar(1, MATRIX_OF_DOUBLE_DATATYPE, &m1, &n1, &Str); if ((m1 == 0) && (n1 == 0)) { int l = 0; CreateVar(Rhs + 1, MATRIX_OF_DOUBLE_DATATYPE, &m1, &n1, &l); LhsVar(1) = Rhs + 1; PutLhsVar(); return 0; } } if (Rhs == 3) { if (VarType(3) == sci_strings) { char typ = 'd'; /*default */ int m3 = 0, n3 = 0, l3 = 0; GetRhsVar(3, STRING_DATATYPE, &m3, &n3, &l3); if (m3 * n3 != 0) { typ = cstk(l3)[0]; } if (typ == 'r') { sci_grep_common(fname, TRUE); } else { Scierror(999, _("%s: Wrong value for input argument #%d: '%s' expected.\n"), fname, 3, "s"); return 0; } } else { Scierror(999, _("%s: Wrong type for input argument #%d: String expected.\n"), fname, 3); return 0; } } else /* Rhs == 2 */ { sci_grep_common(fname, FALSE); } return 0; }