int ScilabGateway::exists(char * fname, const int envId, void * pvApiCtx) { SciErr err; int * addr = 0; int * id = 0; int row = 0; int col = 0; bool exists = false; CheckInputArgument(pvApiCtx, 1, 1); CheckOutputArgument(pvApiCtx, 1, 1); ScilabAbstractEnvironment & env = ScilabEnvironments::getEnvironment(envId); ScilabGatewayOptions & options = env.getGatewayOptions(); OptionsHelper::setCopyOccured(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); return 0; } 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")); } try { exists = env.isvalidobject(*id); } catch (std::exception & e) { throw; } createScalarBoolean(pvApiCtx, 1, exists ? 1 : 0); LhsVar(1) = 1; PutLhsVar(); return 0; }
/*--------------------------------------------------------------------------*/ static int setStacksizeMax(char *fname) { /* we backup previous size */ unsigned long backupSize = getCurrentStacksize(); /* Bug 5495 on Windows 2000 -- WONT FIX GetLargestFreeMemoryRegion */ /* it works on XP, Vista, S7ven */ /* GetLargestFreeMemoryRegion() returns a superior size to real value */ unsigned long maxmemfree = (GetLargestFreeMemoryRegion()) / sizeof(double); /* We have already max */ if (maxmemfree <= backupSize) { LhsVar(1) = 0; C2F(putlhsvar) (); return 0; } /* we do a stacksize('min') */ if (setStacksizeMin(fname) == 0) { unsigned long memmaxavailablebyscilab = get_max_memory_for_scilab_stack(); unsigned long newMemSizeMax = maxmemfree; int errCode; if (memmaxavailablebyscilab < newMemSizeMax) { newMemSizeMax = memmaxavailablebyscilab; } if (newMemSizeMax < MIN_STACKSIZE) { newMemSizeMax = MIN_STACKSIZE; } errCode = setStacksize(newMemSizeMax); if (errCode != 0) { setStacksize(backupSize); Scierror(10001, _("%s: Cannot allocate memory.\n%s\n"), fname, getStackCreationErrorMessage(errCode)); } return 0; } else { /* stacksize('min') fails */ /* restore previous size */ setStacksize(backupSize); Scierror(10001, _("%s: Cannot allocate memory.\n"), fname); } return 0; }
/*--------------------------------------------------------------------------*/ static int sci_stacksizeMin(char *fname) { if (setStacksizeMin(fname) == 0) { LhsVar(1) = 0; PutLhsVar(); } else { Scierror(10001, _("%s: Cannot allocate memory.\n"), fname); } return 0; }
/*--------------------------------------------------------------------------*/ int C2F(sci_banner)(char *fname,unsigned long fname_len) { Rhs=Max(Rhs,0); CheckRhs(0,0) ; CheckLhs(0,1) ; banner(); LhsVar(1) = 0; PutLhsVar(); return 0; }
/*--------------------------------------------------------------------------*/ int C2F(sci_what)(char *fname, unsigned long fname_len) { int sizecommandwords = 0; char **commandwords = getcommandkeywords(&sizecommandwords); Rhs = Max(0, Rhs); CheckRhs(0, 0); CheckLhs(1, 2); CreateLocalFunctionsTab(); qsort( LocalFunctionsTab , SizeLocalFunctionsTab , sizeof (char *) , cmpfunctionnames); if (Lhs == 1) { DispInternalFunctions(); DispCommands(); LhsVar(1) = 0; } else /* Lhs == 2 */ { int ncol = 1; int nrowFunctions = SizeLocalFunctionsTab; int nrowCommands = sizecommandwords; CreateVarFromPtr(Rhs + 1, MATRIX_OF_STRING_DATATYPE, &nrowFunctions, &ncol, LocalFunctionsTab); LhsVar(1) = Rhs + 1; CreateVarFromPtr(Rhs + 2, MATRIX_OF_STRING_DATATYPE, &nrowCommands, &ncol, commandwords); LhsVar(2) = Rhs + 2; freeArrayOfString(LocalFunctionsTab, nrowFunctions); freeArrayOfString(commandwords, nrowCommands); } PutLhsVar(); return 0; }
/*--------------------------------------------------------------------------*/ int sci_oemtochar(char *fname, unsigned long l) { int l1 = 0, n1 = 0, m1 = 0; char *Output = NULL; if (getWarningMode()) { sciprint(_("%s: Feature %s is obsolete.\n"), _("Warning"), fname); sciprint(_("%s: This feature will be permanently removed in Scilab %s\n\n"), _("Warning"), "5.4.1"); } CheckRhs(1, 1); CheckLhs(0, 1); if (GetType(1) == sci_strings) { char *OEMstring = NULL; GetRhsVar(1, STRING_DATATYPE, &m1, &n1, &l1); OEMstring = cstk(l1); Output = (char*)MALLOC((strlen(OEMstring) + 1) * sizeof(char)); if (getScilabMode() == SCILAB_STD) { OemToChar(OEMstring, Output); } else { wsprintf(Output, "%s", OEMstring); } } else { Scierror(999, _("%s: Wrong type for input argument #%d: String expected.\n"), fname, 1); return 0; } n1 = 1; m1 = (int)strlen(Output); CreateVarFromPtr(Rhs + 1, STRING_DATATYPE, &m1, &n1, &Output); if (Output) { FREE(Output); Output = NULL; } LhsVar(1) = Rhs + 1; PutLhsVar(); return 0; }
int ScilabGateway::remove(char * fname, const int envId, void * pvApiCtx) { SciErr err; int * addr = 0; ScilabAbstractEnvironment & env = ScilabEnvironments::getEnvironment(envId); ScilabGatewayOptions & options = env.getGatewayOptions(); OptionsHelper::setCopyOccured(false); ScilabObjects::initialization(env, pvApiCtx); options.setIsNew(false); if (Rhs == 0) { env.garbagecollect(); LhsVar(1) = 0; PutLhsVar(); return 0; } 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")); } ScilabObjects::removeVar(addr, pvApiCtx); } LhsVar(1) = 0; PutLhsVar(); return 0; }
/*--------------------------------------------------------------------------*/ int sci_xinit(char * fname, void *pvApiCtx) { SciErr err; int * addr = 0; char * path = 0; char * realPath = 0; CheckInputArgument(pvApiCtx, 1, 1); err = getVarAddressFromPosition(pvApiCtx, 1, &addr); if (err.iErr) { printError(&err, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1); return 0; } if (!isStringType(pvApiCtx, addr) || !checkVarDimension(pvApiCtx, addr, 1, 1)) { Scierror(999, gettext("%s: Wrong type for input argument #%d: string expected.\n"), fname, 1); return 0; } if (getAllocatedSingleString(pvApiCtx, addr, &path) != 0) { Scierror(999, _("%s: No more memory.\n"), fname); return 0; } realPath = expandPathVariable(path); if (realPath) { org_scilab_modules_graphic_export::Driver::setPath(getScilabJavaVM(), realPath); FREE(realPath); } else { Scierror(999, _("%s: Invalid path: %s.\n"), fname, path); return 0; } freeAllocatedSingleString(path); LhsVar(1) = 0; PutLhsVar(); return 0; }
/*--------------------------------------------------------------------------*/ int sci_mtell(char *fname, unsigned long fname_len) { int m1 = 0, n1 = 0, l1 = 0; int one = 1; int l2 = 0, err = 0; int fd = ALL_FILES_DESCRIPTOR; Nbvars = 0; CheckRhs(0, 1); CheckLhs(1, 1); /* checking variable file */ if ( Rhs >= 1) { if (GetType(1) == sci_matrix) { GetRhsVar(1, MATRIX_OF_INTEGER_DATATYPE, &m1, &n1, &l1); if (m1*n1 == 1) { fd = *istk(l1); } else { Scierror(999, _("%s: Wrong size for input argument #%d: An integer expected.\n"), fname, 1); return 0; } } else { Scierror(999, _("%s: Wrong type for input argument #%d: An integer expected.\n"), fname, 1); return 0; } } CreateVar(Rhs + 1, MATRIX_OF_DOUBLE_DATATYPE, &one, &one, &l2); C2F(mtell)(&fd, stk(l2), &err); if (err > 0) { SciError(10000); return 0; } LhsVar(1) = Rhs + 1; PutLhsVar(); return 0; }
/*--------------------------------------------------------------------------*/ 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; }
int sci_view(char *fname) { static int l1, m1, n1, l2, m2, n2, m3, n3, l3; static int minlhs=1, maxlhs=3, minrhs=3, maxrhs=3; /* Check number of inputs (rhs=3) and outputs (lhs=3) */ CheckRhs(minrhs,maxrhs) ; CheckLhs(minlhs,maxlhs) ; /* Get X (1 ,double), Y (2, int) and C (3, string) */ GetRhsVar(1,MATRIX_OF_DOUBLE_DATATYPE, &m1, &n1, &l1); GetRhsVar(2,MATRIX_OF_INTEGER_DATATYPE, &m2, &n2, &l2); GetRhsVar(3,STRING_DATATYPE, &m3, &n3, &l3); /* Call display function stk(l1)->X (double), istk(l2)->Y (int), cstk(l3)->Z (char) */ displ(stk(l1), m1, n1, istk(l2), m2, n2, cstk(l3), m3, n3); /* Return variables */ LhsVar(1) = 1; LhsVar(2) = 2; LhsVar(3) = 3; return 0; }
/*--------------------------------------------------------------------------*/ int sci_xpause(char *fname, unsigned long fname_len) { int m1 = 0, n1 = 0, l1 = 0, sec = 0; CheckLhs(0, 1); CheckRhs(1, 1); if (Rhs == 1) { GetRhsVar(1, MATRIX_OF_DOUBLE_DATATYPE, &m1, &n1, &l1); CheckScalar(1, m1, n1); sec = (int) * stk(l1); if (sec <= 0) { Scierror(999, _("%s: Wrong values for input argument #%d: Non-negative integers expected.\n"), fname, 1); return 0; } #ifdef _MSC_VER { int ms = (sec) / 1000; /** time is specified in milliseconds in scilab**/ if (ms > 0) { Sleep(ms); /* Number of milliseconds to sleep. */ } } #else { unsigned useconds; useconds = (unsigned) sec; if (useconds != 0) #ifdef HAVE_USLEEP { usleep(useconds); } #else #ifdef HAVE_SLEEP { sleep(useconds); } #endif #endif } #endif } LhsVar(1) = 0; PutLhsVar(); return 0; }
/*--------------------------------------------------------------------------*/ int sci_tohome(char *fname, void* pvApiCtx) { CheckRhs(0, 0); CheckLhs(0, 1); if (!tohome()) { sciprint(_("%s: This feature has not been implemented in this mode.\n"), fname); } LhsVar(1) = 0; PutLhsVar(); return 0 ; }
// // FIXME: Remove GW after Scilab 5.4.0 // int sci_clear_pixmap(char *fname, unsigned long fname_len ) { CheckRhs(0, 0); CheckLhs(0, 1); if (getWarningMode()) { sciprint(_("%s: Function %s is obsolete.\n"), _("Warning"), fname); sciprint(_("%s: Please use %s instead.\n"), _("Warning"), "drawlater/drawnow"); sciprint(_("%s: This function will be permanently removed in Scilab %s\n\n"), _("Warning"), "5.4.1"); } LhsVar(1) = 0; PutLhsVar(); return 0; }
int sci_bug_9708(char *fname) { SciErr sciErr; const char varname[] = "iputhereavariabletoolongforscilabandthereisnoerror"; sciErr = createNamedMatrixOfString(pvApiCtx, varname, 1, 1, &varname); if(sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Invalid variable name.\n"), fname); return 0; } LhsVar(1) = 1; return 0; }
/*--------------------------------------------------------------------------*/ int sci_getfilepartlevel(char *fname, unsigned long fname_len) { CheckRhs(1, 1); CheckLhs(1, 1); if (GetType(1) == sci_strings) { int m = 0, n = 0; char **InputString = NULL; GetRhsVar(1, MATRIX_OF_STRING_DATATYPE, &m, &n, &InputString); if ( (m == 1) && (n == 1) ) { char *result = NULL; result = getFilePartLevel(InputString[0]); if (result == NULL) { int l = 0; m = 0, n = 0; CreateVar(Rhs + 1, STRING_DATATYPE, &m, &n, &l); } else { n = 1; CreateVarFromPtr(Rhs + 1, STRING_DATATYPE, (m = (int)strlen(result), &m), &n, &result); if (result) { FREE(result); result = NULL; } } LhsVar(1) = Rhs + 1; } else { freeArrayOfString(InputString, m * n); Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), fname, 1); } } else { Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 1); } return 0; }
/*--------------------------------------------------------------------------*/ int C2F(sci_getlanguagestable)(char *fname,unsigned long fname_len) { static int n1,m1; char **Output=NULL; int i=0; CheckRhs(0,0); CheckLhs(0,1); Output=(char**)MALLOC(sizeof(char*)*2* NumberLanguages); for (i=0;i<NumberLanguages;i++) { char *alphacode=NULL; char *language=NULL; alphacode=(char*)MALLOC((strlen(LANGUAGE_COUNTRY_TAB[i].alphacode)+1)*sizeof(char)); strcpy(alphacode,LANGUAGE_COUNTRY_TAB[i].alphacode); language=(char*)MALLOC((strlen(LANGUAGE_COUNTRY_TAB[i].languagedescription)+1)*sizeof(char)); strcpy(language,LANGUAGE_COUNTRY_TAB[i].languagedescription); Output[i]=alphacode; Output[NumberLanguages+i]=language; } m1=NumberLanguages; n1=2; CreateVarFromPtr( Rhs+1,MATRIX_OF_STRING_DATATYPE,&m1,&n1,Output); LhsVar(1) = Rhs+1; PutLhsVar();; if (Output) { for (i=0;i<NumberLanguages;i++) { FREE(Output[i]); Output[i]=NULL; FREE(Output[NumberLanguages+i]); Output[NumberLanguages+i]=NULL; } } return 0; }
int ScilabGateway::getClasspath(char * fname, const int envId, void * pvApiCtx) { CheckInputArgument(pvApiCtx, 0, 0); ScilabAbstractEnvironment & env = ScilabEnvironments::getEnvironment(envId); ScilabGatewayOptions & options = env.getGatewayOptions(); OptionsHelper::setCopyOccurred(false); ScilabObjects::initialization(env, pvApiCtx); options.setIsNew(false); env.getclasspath(ScilabStringStackAllocator(pvApiCtx, Rhs + 1)); LhsVar(1) = Rhs + 1; PutLhsVar(); return 0; }
/* * sets SIP verbosity level * TODO * - even in quiet mode, all function should output useful * info/debug/error codes in a global variable (sip_ans_msg) */ SipExport int sip_set_verbose_int(char *fname) { int rname,cname,pname, rout,cout, minlhs=1, maxlhs=1, minrhs=0, maxrhs=1; char *prev; CheckRhs(minrhs,maxrhs); CheckLhs(minlhs,maxlhs); /* print previous value */ switch (sip_verbose) { case SIP_WORDY: prev = "wordy"; break; case SIP_QUIET: prev = "quiet"; break; default: sip_error("BUG: internal variable has invalid value (please report)"); break; } cout = 1; rout = strlen(prev); CreateVarFromPtr(2, "c", &rout, &cout, &prev); if (Rhs == 0) /* toggle previous value */ sip_verbose = (sip_verbose == SIP_QUIET) ? SIP_WORDY : SIP_QUIET; else { /* set new value */ GetRhsVar(1, "c", &rname, &cname, &pname); if (cname == 1 && *cstk(pname) == 'q') sip_verbose = SIP_QUIET; else sip_verbose = SIP_WORDY; } LhsVar(1)=2; return true; }
/*--------------------------------------------------------------------------*/ int sci_getpid(char *fname, unsigned long fname_len) { int one = 1; int l1 = 0; int pid = 0; CheckRhs(0, 0); CheckLhs(0, 1); C2F(getpidc)(&pid); CreateVar(Rhs + 1, MATRIX_OF_INTEGER_DATATYPE, &one, &one, &l1); *istk(l1) = (int) pid; LhsVar(1) = Rhs + 1; PutLhsVar(); return 0; }
int NdofInterface(char *fname) { static int un = 1, nddl; /* Define minls=1, maxlhs */ static int minlhs = 1, maxlhs = 1; /* Check lhs */ CheckLhs(minlhs, maxlhs) ; CreateVar(1, "d", &un, &un, &nddl); Ndof(istk(nddl)); LhsVar(1) = 1; return 0; }
int introundmode (char *fname) { int direct; int t, u, v; CheckRhs (1, 1); CheckLhs (1, 1); GetRhsVar (1, "i", &t, &u, &direct); CreateVar (2, "i", &t, &u, &v); *istk (v) = roundmode(istk (direct)); LhsVar (1) = 2; return 0; }
/*--------------------------------------------------------------------------*/ static int sci_format_norhs(char *fname) { SciErr sciErr; double dParamout[2]; getFormat(&dParamout[0], &dParamout[1]); sciErr = createMatrixOfDouble(pvApiCtx, Rhs + 1, 1, 2, dParamout); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 0; } LhsVar(1) = Rhs + 1; PutLhsVar(); return 0; }
/*--------------------------------------------------------------------------*/ int sci_system_setproperty(char *fname,unsigned long fname_len) { Rhs = Max(Rhs,0); CheckRhs(2,2); CheckLhs(1,1); if ( (GetType(1) == sci_strings) && (GetType(2) == sci_strings) ) { static int m1,n1=0,l1=0; static int m2,n2=0,l2=0; char *propertyName = NULL; char *propertyValue = NULL; char *previousValue = NULL; GetRhsVar(1,STRING_DATATYPE,&m1,&n1,&l1); propertyName = cstk(l1); GetRhsVar(2,STRING_DATATYPE,&m2,&n2,&l2); propertyValue = cstk(l2); previousValue = system_setproperty(propertyName,propertyValue); if (previousValue) { n1=1; CreateVarFromPtr(Rhs+1,STRING_DATATYPE,(m1=(int)strlen(propertyValue), &m1),&n1,&previousValue); } else { n1 = 0; m1 = 0; l1 = 0; CreateVar(Rhs+1,MATRIX_OF_DOUBLE_DATATYPE,&n1,&m1,&l1); } LhsVar(1)=Rhs+1; if (previousValue) {FREE(previousValue); previousValue = NULL;} PutLhsVar(); } else { Scierror(999,_("%s: Wrong type for input argument #%d or #%d: String expected.\n"),fname, 1, 2); } return 0; }
/*--------------------------------------------------------------------------*/ int sci_opentk(char *fname, unsigned long l) { Tcl_Interp *TCLinterpLocal = NULL; CheckRhs(0, 0); CheckLhs(1, 1); TCLinterpLocal = Tcl_CreateInterp(); Tcl_Init(TCLinterpLocal); Tk_Init(TCLinterpLocal); TKmainWindow = Tk_MainWindow(TCLinterpLocal); Tk_GeometryRequest(TKmainWindow, 200, 200); Tk_SetWindowBackground(TKmainWindow, WhitePixelOfScreen(Tk_Screen(TKmainWindow))); LhsVar(1) = 0; PutLhsVar(); return 0; }
/*--------------------------------------------------------------------------*/ int sci_filesep(char *fname, unsigned long fname_len) { int n1, m1; char *separator; CheckRhs(0, 0); CheckLhs(1, 1); /* Pass as reference as it will always be copied into the stack */ separator = DIR_SEPARATOR; n1 = 1; m1 = (int) strlen(separator); CreateVarFromPtr(Rhs + 1, STRING_DATATYPE, &m1, &n1, &separator); LhsVar(1) = Rhs + 1; PutLhsVar(); return 0; }
SipExport int imvariance_int(char *fname) { static int l1, m1, n1, l2; static int minlhs=1, maxlhs=1, minrhs=1, maxrhs=1; /* Check number of inputs and outputs */ CheckRhs(minrhs,maxrhs); CheckLhs(minlhs,maxlhs); /*Input parameters: */ GetRhsVar(1, "d", &m1, &n1, &l1); CreateVar(2, "d", &m1, &n1, &l2); imvariance(stk(l1), stk(l2), m1, n1); LhsVar(1) = 2; return 0; }
/*--------------------------------------------------------------------------*/ int sci_is_handle_valid(char *fname, unsigned long fname_len) { /* Call isValid = is_handle_valid(h) with h a matrix of handle */ /* and isValid a matrix of boolean */ int nbCol = 0; int nbRow = 0; int nbHandle = 0; int handleStackPointer = 0; int resultStackPointer = 0; int i = 0; CheckRhs(1, 1); CheckLhs(0, 1); /* Get handles matrix */ if (VarType(1) != sci_handles) { Scierror(999, _("%s: Wrong type for input argument #%d: Matrix of handle expected.\n"), fname, 1); return -1; } GetRhsVar(1, (char *)GRAPHICAL_HANDLE_DATATYPE, &nbRow, &nbCol, &handleStackPointer); nbHandle = nbRow * nbCol; /* create output matrix */ CreateVar(Rhs + 1, (char *)MATRIX_OF_BOOLEAN_DATATYPE, &nbRow, &nbCol, &resultStackPointer); /* Check each handle */ for (i = 0; i < nbHandle; i++) { *istk(resultStackPointer + i) = ((getObjectFromHandle((long)getHandleFromStack((size_t)(handleStackPointer + i))) != NULL) ? TRUE : FALSE); } LhsVar(1) = Rhs + 1; PutLhsVar(); return 0; }
/*--------------------------------------------------------------------------*/ int sci_win64(char *fname,unsigned long l) { BOOL Status = FALSE; CheckRhs(0,0); CheckLhs(0,1); #ifdef _WIN64 Status = TRUE; #endif if(createScalarBoolean(pvApiCtx, Rhs + 1, Status) != 0) { return 1; } LhsVar(1) = Rhs + 1; PutLhsVar(); return 0; }
/*--------------------------------------------------------------------------*/ int sci_winopen(char *fname, unsigned long l) { int m1 = 0, n1 = 0, l1 = 0; CheckRhs(1, 1); GetRhsVar(1, STRING_DATATYPE, &m1, &n1, &l1); if (winopen(cstk(l1))) { LhsVar(1) = 0; } else { Scierror(999, _("%s: Cannot open file %s.\n"), fname, cstk(l1)); return 0; } PutLhsVar(); return 0; }