int sci_deleteNamedVariable(char *fname, unsigned long fname_len) { SciErr sciErr; int iRet = 0; int* piAddr = NULL; char* pstVarName = NULL; CheckRhs(1, 1); CheckLhs(1, 1); sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } if (getAllocatedSingleString(pvApiCtx, piAddr, &pstVarName)) { //error return 1; } if (isNamedVarExist(pvApiCtx, pstVarName)) { iRet = deleteNamedVariable(pvApiCtx, pstVarName); } createScalarBoolean(pvApiCtx, Rhs + 1, iRet); AssignOutputVariable(pvApiCtx, 1) = Rhs + 1; return 0; }
/*Function that closes symphony environment * Returns 1 on success , 0 on failure */ int sci_sym_close(char *fname, unsigned long fname_len){ // Error management variable SciErr sciErr; double status=0; int output;//output parameter for closing the environment //check whether we have no input and one output argument or not CheckInputArgument(pvApiCtx, 0, 0) ;//no input argument CheckOutputArgument(pvApiCtx, 1, 1) ;//one output argument if (global_sym_env==NULL){//check for environment sciprint("Error: symphony environment is not initialized.\n"); }else{ output=sym_close_environment(global_sym_env);//close environment if(output==ERROR__USER){ status=0;//User error detected in user_free_master() function or when function invoked unsuccessfully sciprint("Error in user_free_master()\n"); }else if(output==FUNCTION_TERMINATED_ABNORMALLY){ status=0;//function invoked unsuccessfully sciprint("Symphony environment could not be closed.\n"); }else if(output==FUNCTION_TERMINATED_NORMALLY){ status=1;//function invoked successfully and no error global_sym_env=NULL;//important to set to NULL, so that other functions can detect that environment is not open. //sciprint("Symphony environement closed successfully. Please run 'sym_open()' to restart.\n"); //delete the sym_ variables deleteNamedVariable(pvApiCtx,"sym_minimize"); deleteNamedVariable(pvApiCtx,"sym_maximize"); } } /*write satus of function (success-1 or failure-0) as output argument to scilab*/ if(returnDoubleToScilab(status)) return 1; return 0; }
void ScilabObjects::removeVar(int * addr, void * pvApiCtx) { SciErr err; int type, row, col, * id; err = getVarType(pvApiCtx, addr, &type); if (err.iErr) { throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data")); } if (type == sci_mlist && (isExternalObjOrClass(addr, pvApiCtx))) { 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")); } int envId = getEnvironmentId(addr, pvApiCtx); ScilabAbstractEnvironment & env = ScilabEnvironments::getEnvironment(envId); env.removeobject(*id); } else if (type == sci_strings) { char * varName = 0; if (getAllocatedSingleString(pvApiCtx, addr, &varName)) { throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data")); } err = getVarAddressFromName(pvApiCtx, varName, &addr); if (err.iErr) { freeAllocatedSingleString(varName); return; } err = getVarType(pvApiCtx, addr, &type); if (err.iErr) { freeAllocatedSingleString(varName); throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data")); } if (type == sci_mlist && isExternalObjOrClass(addr, pvApiCtx)) { err = getMatrixOfInteger32InList(pvApiCtx, addr, EXTERNAL_OBJ_ID_POSITION, &row, &col, &id); if (err.iErr) { freeAllocatedSingleString(varName); throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data")); } int envId = getEnvironmentId(addr, pvApiCtx); ScilabAbstractEnvironment & env = ScilabEnvironments::getEnvironment(envId); env.removeobject(*id); deleteNamedVariable(pvApiCtx, varName); freeAllocatedSingleString(varName); } } }