/*--------------------------------------------------------------------------*/ static int sci_emptystr_no_rhs(void) { /* With no input argument returns a zero length character string */ createSingleString(pvApiCtx, Rhs + 1, ""); LhsVar(1) = Rhs + 1; PutLhsVar(); return 0; }
/*--------------------------------------------------------------------------*/ int sci_getlookandfeel(char *fname, void* pvApiCtx) { CheckInputArgument(pvApiCtx, 0, 0); CheckOutputArgument(pvApiCtx, 1, 1); org_scilab_modules_gui_utils::LookAndFeelManager * lnf = 0; try { lnf = new org_scilab_modules_gui_utils::LookAndFeelManager(getScilabJavaVM()); } catch (const GiwsException::JniException & e) { Scierror(999, _("%s: A Java exception arisen:\n%s"), fname, e.whatStr().c_str()); return 1; } if (lnf) { static int n1 = 0, m1 = 0; char *look = lnf->getCurrentLookAndFeel(); if (look) { m1 = (int)strlen(look); n1 = 1; if (createSingleString(pvApiCtx, nbInputArgument(pvApiCtx) + 1, look)) { Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } if (look) { delete[]look; look = NULL; } delete lnf; AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); } else { delete lnf; Scierror(999, _("%s: An error occurred: %s.\n"), fname, _("Impossible to get current look and feel")); return 1; } } else { Scierror(999, _("%s: No more memory.\n"), fname); return 1; } return 0; }
/* ========================================================================== */ int sci_bug_11106(char *fname) { int* piAddr = NULL; char pstRet[64]; getVarAddressFromPosition(pvApiCtx, 1, &piAddr); if (isStringType(pvApiCtx, piAddr)) { //named check char* pstVar = NULL; getAllocatedSingleString(pvApiCtx, piAddr, &pstVar); if (isNamedListType(pvApiCtx, pstVar)) { sprintf(pstRet, "%s", "isNamedList"); } else if (isNamedTListType(pvApiCtx, pstVar)) { sprintf(pstRet, "%s", "isNamedTList"); } else if (isNamedMListType(pvApiCtx, pstVar)) { sprintf(pstRet, "%s", "isNamedMList"); } else { sprintf(pstRet, "%s", "unmanaged named type"); } FREE(pstVar); } else { if (isListType(pvApiCtx, piAddr)) { sprintf(pstRet, "%s", "isList"); } else if (isTListType(pvApiCtx, piAddr)) { sprintf(pstRet, "%s", "isTList"); } else if (isMListType(pvApiCtx, piAddr)) { sprintf(pstRet, "%s", "isMList"); } else { sprintf(pstRet, "%s", "unmanaged type"); } } createSingleString(pvApiCtx, Rhs + 1, pstRet); LhsVar(1) = Rhs + 1; return 0; }
// usage: str = fann_get_errstr(ann_error); int sci_fann_get_errstr(char * fname) { int res; char * ErrStr = NULL; struct fann_error * result_error = NULL; if ((Rhs!=1)&&(Lhs!=1)) { Scierror(999,"%s: usage result = %(error_fann_in).\n", fname, fname); return 0; } // Get the fann structure res = detect_fannerrorlist(1); if (res==-1) return 0; result_error = createCFannErrorStructFromScilabFannErrorStruct(1,&res); if (res==-1) return 0; if (result_error) { if (fann_get_errno(result_error)!=FANN_E_NO_ERROR) { ErrStr = strdup(fann_get_errstr(result_error)); createSingleString(pvApiCtx, Rhs + 1, ErrStr); FREE(ErrStr); } } else { ErrStr = strdup("no error"); createSingleString(pvApiCtx, Rhs + 1, ErrStr); FREE(ErrStr); } LhsVar(1) = Rhs + 1; return 0; }
/*--------------------------------------------------------------------------*/ int C2F(sci_getscilabmode)(char *fname, unsigned long fname_len) { int n1 = 0, m1 = 0; char *output = NULL ; int iRet = 0; SciErr sciErr; CheckInputArgument(pvApiCtx, 0, 0) ; CheckOutputArgument(pvApiCtx, 1, 1) ; switch (getScilabMode()) { case SCILAB_API: default : output = strdup("API"); break; case SCILAB_STD: output = strdup("STD"); break; case SCILAB_NW: output = strdup("NW"); break; case SCILAB_NWNI: output = strdup("NWNI"); break; } /* Create the string matrix as return of the function */ iRet = createSingleString(pvApiCtx, nbInputArgument(pvApiCtx) + 1, output); free(output); // Data have been copied into Scilab memory if (iRet) { freeAllocatedSingleString(output); return 1; } AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); return 0; }
int sci_matfile_varreadnext(char *fname, void* pvApiCtx) { mat_t *matfile = NULL; matvar_t *matvar = NULL; int fileIndex = 0; int returnedClass = 0, var_type; int * fd_addr = NULL; double tmp_dbl; SciErr sciErr; CheckRhs(1, 1); CheckLhs(1, 3); /* Input argument is the index of the file to read */ sciErr = getVarAddressFromPosition(pvApiCtx, 1, &fd_addr); if (sciErr.iErr) { printError(&sciErr, 0); return 0; } sciErr = getVarType(pvApiCtx, fd_addr, &var_type); if (sciErr.iErr) { printError(&sciErr, 0); return 0; } if (var_type == sci_matrix) { getScalarDouble(pvApiCtx, fd_addr, &tmp_dbl); if (!isScalar(pvApiCtx, fd_addr)) { Scierror(999, _("%s: Wrong size for first input argument: Single double expected.\n"), fname); return FALSE; } fileIndex = (int)tmp_dbl; } else { Scierror(999, _("%s: Wrong type for first input argument: Double expected.\n"), fname); return FALSE; } /* Gets the corresponding matfile */ matfile_manager(MATFILEMANAGER_GETFILE, &fileIndex, &matfile); if (matfile == NULL) { Scierror(999, _("%s: Invalid file identifier.\n"), fname); return FALSE; } matvar = Mat_VarReadNext(matfile); if ((matvar == NULL) || (matvar->name == NULL)) { /* Return empty name */ createSingleString(pvApiCtx, Rhs + 1, "\0"); LhsVar(1) = Rhs + 1; if (Lhs >= 2) { /* Return empty value */ createEmptyMatrix(pvApiCtx, Rhs + 2); LhsVar(2) = Rhs + 2; } if (Lhs == 3) { /* Return error flag instead of variable class */ createScalarDouble(pvApiCtx, Rhs + 3, NO_MORE_VARIABLES); LhsVar(3) = Rhs + 3; } PutLhsVar(); return TRUE; } /* To be sure isComplex is 0 or 1 */ matvar->isComplex = matvar->isComplex != 0; /* Return the variable name */ createSingleString(pvApiCtx, Rhs + 1, matvar->name); LhsVar(1) = Rhs + 1; returnedClass = matvar->class_type; if (Lhs >= 2) { /* Return the values */ if (!CreateMatlabVariable(pvApiCtx, Rhs + 2, matvar, NULL, -1)) /* Could not Create Variable */ { sciprint("Do not know how to read a variable of class %d.\n", matvar->class_type); returnedClass = UNKNOWN_VARIABLE_TYPE; } LhsVar(2) = Rhs + 2; } if (Lhs == 3) { /* Create class return value */ createScalarDouble(pvApiCtx, Rhs + 3, returnedClass); LhsVar(3) = Rhs + 3; } Mat_VarFree(matvar); PutLhsVar(); return TRUE; }
/*--------------------------------------------------------------------------*/ int sci_fscanfMat(char *fname, void* pvApiCtx) { SciErr sciErr; int *piAddressVarOne = NULL; int m1 = 0, n1 = 0; int iType1 = 0; char *filename = NULL; char *expandedFilename = NULL; char *Format = NULL; char *separator = NULL; BOOL bIsDefaultSeparator = TRUE; fscanfMatResult *results = NULL; CheckRhs(1, 3); CheckLhs(1, 2); if (Rhs == 3) { int *piAddressVarThree = NULL; int m3 = 0, n3 = 0; int iType3 = 0; sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddressVarThree); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 3); return 0; } if (isStringType(pvApiCtx, piAddressVarThree) == 0 || isScalar(pvApiCtx, piAddressVarThree) == 0) { Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 3); return 0; } if (getAllocatedSingleString(pvApiCtx, piAddressVarThree, &separator)) { freeVar(&filename, &expandedFilename, &Format, &separator); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 0; } bIsDefaultSeparator = FALSE; } if (Rhs >= 2) { int *piAddressVarTwo = NULL; int m2 = 0, n2 = 0; int iType2 = 0; sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddressVarTwo); if (sciErr.iErr) { freeVar(&filename, &expandedFilename, &Format, &separator); printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2); return 0; } sciErr = getVarType(pvApiCtx, piAddressVarTwo, &iType2); if (sciErr.iErr) { freeVar(&filename, &expandedFilename, &Format, &separator); printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2); return 0; } if (isStringType(pvApiCtx, piAddressVarTwo) == 0 || isScalar(pvApiCtx, piAddressVarTwo) == 0) { freeVar(&filename, &expandedFilename, &Format, &separator); Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 2); return 0; } if (getAllocatedSingleString(pvApiCtx, piAddressVarTwo, &Format)) { freeVar(&filename, &expandedFilename, &Format, &separator); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 0; } } else { Format = os_strdup(DEFAULT_FSCANFMAT_FORMAT); } sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddressVarOne); if (sciErr.iErr) { freeVar(&filename, &expandedFilename, &Format, &separator); printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1); return 0; } if (isStringType(pvApiCtx, piAddressVarOne) == 0 || isScalar(pvApiCtx, piAddressVarOne) == 0) { freeVar(&filename, &expandedFilename, &Format, &separator); Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 1); return 0; } if (getAllocatedSingleString(pvApiCtx, piAddressVarOne, &filename)) { freeVar(&filename, &expandedFilename, &Format, &separator); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 0; } expandedFilename = expandPathVariable(filename); if (bIsDefaultSeparator) { #define NB_DEFAULT_SUPPORTED_SEPARATORS 2 /* bug 8148 */ /* default separator can be a space or a tabulation */ char *supportedSeparators[NB_DEFAULT_SUPPORTED_SEPARATORS] = {DEFAULT_FSCANFMAT_SEPARATOR, "\t"}; int i = 0; for (i = 0; i < NB_DEFAULT_SUPPORTED_SEPARATORS; i++) { results = fscanfMat(expandedFilename, Format, supportedSeparators[i]); if (results && results->err == FSCANFMAT_NO_ERROR) { break; } freeFscanfMatResult(results); } } else { results = fscanfMat(expandedFilename, Format, separator); } if (results == NULL) { freeVar(&filename, &expandedFilename, &Format, &separator); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 0; } freeVar(NULL, &expandedFilename, &Format, &separator); switch (results->err) { case FSCANFMAT_NO_ERROR: { if ( (results->values) && (results->m > 0) && (results->n > 0)) { sciErr = createMatrixOfDouble(pvApiCtx, Rhs + 1, results->m, results->n, results->values); if (sciErr.iErr) { FREE(filename); freeFscanfMatResult(results); printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 0; } } else { if (createEmptyMatrix(pvApiCtx, Rhs + 1)) { FREE(filename); freeFscanfMatResult(results); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 0; } } LhsVar(1) = Rhs + 1; if (Lhs == 2) { if (results->text) { sciErr = createMatrixOfString(pvApiCtx, Rhs + 2, results->sizeText, 1, (char const * const*) results->text); if (sciErr.iErr) { FREE(filename); freeFscanfMatResult(results); printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 0; } } else { if (createSingleString(pvApiCtx, Rhs + 2, "")) { FREE(filename); freeFscanfMatResult(results); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 0; } } LhsVar(2) = Rhs + 2; } freeFscanfMatResult(results); FREE(filename); PutLhsVar(); return 0; } case FSCANFMAT_MOPEN_ERROR: { Scierror(999, _("%s: can not open file %s.\n"), fname, filename); FREE(filename); return 0; } case FSCANFMAT_READLINES_ERROR: { Scierror(999, _("%s: can not read file %s.\n"), fname, filename); FREE(filename); return 0; } case FSCANFMAT_FORMAT_ERROR: { Scierror(999, _("%s: Invalid format.\n"), fname); FREE(filename); return 0; } case FSCANFMAT_MEMORY_ALLOCATION: { Scierror(999, _("%s: Memory allocation error.\n"), fname); FREE(filename); return 0; } default: case FSCANFMAT_ERROR: { Scierror(999, _("%s: error.\n"), fname); FREE(filename); return 0; } } FREE(filename); freeFscanfMatResult(results); return 0; }
int sci_optional_args(char* fname, void *pvApiCtx) { char* pstName = NULL; int iAge = 0; int iDrivingLicense = 0; char stOutput[100]; static rhs_opts opts[] = { { -1, "name", -1, 0, 0, NULL}, { -1, "age", -1, 0, 0, NULL}, { -1, "driving_license", -1, 0, 0, NULL}, { -1, NULL, -1, 0, 0, NULL} }; CheckInputArgument(pvApiCtx, 0, 3); CheckOutputArgument(pvApiCtx, 0, 1); if (getOptionals(pvApiCtx, fname, opts) == 0) { Scierror(999, "foo: error occured in getOptionals()."); return 1; } // name if (opts[0].iPos != -1) { getAllocatedSingleString(pvApiCtx, opts[0].piAddr, &pstName); } else { pstName = strdup("John Doe"); } // age if (opts[1].iPos != -1) { double dblAge = 0; getScalarDouble(pvApiCtx, opts[1].piAddr, &dblAge); iAge = (int)dblAge; } else { iAge = 77; } // driving license if (opts[2].iPos != -1) { getScalarBoolean(pvApiCtx, opts[2].piAddr, &iDrivingLicense); } else { iDrivingLicense = 0; } sprintf(stOutput, "%s, %d years old, %s a driving license.", pstName, iAge, iDrivingLicense ? "has" : "does not have"); if (createSingleString(pvApiCtx, nbInputArgument(pvApiCtx) + 1, stOutput)) { return 1; } AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; return 0; }
/* ==================================================================== */ int sci_getURLcontent(char *fname, int fname_len) { SciErr sciErr; int length = 0; int *piAddr = NULL; char *url = NULL; char *username = NULL; char *password = NULL; int iRows = 0, iCols = 0; int iType = 0; int *piAddressVarOne = NULL; int ret = 0; char *content = NULL; int iRhs = nbInputArgument(pvApiCtx); CheckInputArgument(pvApiCtx, 1, 3); CheckOutputArgument(pvApiCtx, 0, 1); sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddressVarOne); if (sciErr.iErr) { printError(&sciErr, 0); return 0; } ret = getAllocatedSingleString(pvApiCtx, piAddressVarOne, &url); if (ret) { Scierror(999, _("%s: Wrong type for argument %d: A string expected.\n"), fname, 1); freeAllocatedStrings(url, username, password); return 0; } if (iRhs > 1) { /* Specify the username */ int *piAddressVarTwo = NULL; sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddressVarTwo); if (sciErr.iErr) { printError(&sciErr, 0); freeAllocatedStrings(url, username, password); return 0; } ret = getAllocatedSingleString(pvApiCtx, piAddressVarTwo, &username); if (ret) { Scierror(999, _("%s: Wrong type for argument %d: A string expected.\n"), fname, 2); freeAllocatedStrings(url, username, password); return 0; } } if (iRhs > 2) { /* Specify the password */ int *piAddressVarThree = NULL; sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddressVarThree); if (sciErr.iErr) { printError(&sciErr, 0); freeAllocatedStrings(url, username, password); return 0; } ret = getAllocatedSingleString(pvApiCtx, piAddressVarThree, &password); if (ret) { Scierror(999, _("%s: Wrong type for argument %d: A string expected.\n"), fname, 3); freeAllocatedStrings(url, username, password); return 0; } } /* Set to NULL if 0 length strings */ if (url != NULL && strlen(url) == 0) { url = NULL; } if (username != NULL && strlen(username) == 0) { username = NULL; } if (password != NULL && strlen(password) == 0) { password = NULL; } // call function content = downloadContent(url, username, password); if (content != NULL) { //create new variable int res = createSingleString(pvApiCtx, iRhs + 1, content); FREE(content); content = NULL; if (res) { Scierror(999, _("%s: Could not create the output argument.\n")); freeAllocatedStrings(url, username, password); return 0; } } AssignOutputVariable(pvApiCtx, 1) = iRhs + 1; ReturnArguments(pvApiCtx); return 0; }
/*--------------------------------------------------------------------------*/ int sci_ClipBoard(char *fname, void* pvApiCtx) { SciErr sciErr; int* piAddr1 = NULL; int* piAddrl1 = NULL; int* piAddrStr = NULL; double* pdbll1 = NULL; int* pil1 = NULL; static int n1 = 0, m1 = 0; char* param1 = NULL; char* param2 = NULL; nbInputArgument(pvApiCtx) = Max(0, nbInputArgument(pvApiCtx)); CheckInputArgument(pvApiCtx, 0, 2); CheckOutputArgument(pvApiCtx, 0, 1); if ( getScilabMode() != SCILAB_NWNI ) { /*--------------------*/ /* clipboard("paste") */ /*--------------------*/ if (nbInputArgument(pvApiCtx) == 1) { if (checkInputArgumentType(pvApiCtx, 1, sci_strings)) { sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrl1); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 1. if (getAllocatedSingleString(pvApiCtx, piAddrl1, ¶m1)) { Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 1); return 1; } if ( ( strcmp(param1, "paste") == 0 ) || ( strcmp(param1, "pastespecial") == 0 ) ) { /* Use the Java clipboard (CallScilabBridge.java returns "" if clipboard could not be read) */ char *output = getClipboardContents(); m1 = (int)strlen(output); n1 = 1; if (createSingleString(pvApiCtx, nbInputArgument(pvApiCtx) + 1, output)) { freeAllocatedSingleString(param1); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } /* TO DO a delete [] and not a FREE */ FREE(output); AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; freeAllocatedSingleString(param1); ReturnArguments(pvApiCtx); return TRUE; } else { freeAllocatedSingleString(param1); Scierror(999, _("%s: Wrong value for input argument #%d: '%s' or '%s' expected.\n"), fname, 1, "paste", "pastespecial"); return FALSE; } } else { Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 1); return FALSE; } } else if (nbInputArgument(pvApiCtx) == 2) { if (checkInputArgumentType(pvApiCtx, 1, sci_strings)) { /* Get the first argument: should be "copy" or "do" */ sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrl1); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 1. if (getAllocatedSingleString(pvApiCtx, piAddrl1, ¶m1)) { Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 1); return 1; } if (( strcmp(param1, "do") != 0 ) && ( strcmp(param1, "copy") != 0 )) { freeAllocatedSingleString(param1); Scierror(999, _("%s: Wrong value for input argument #%d: '%s' or '%s' expected.\n"), fname, 1, "do", "copy"); return FALSE; } if (checkInputArgumentType(pvApiCtx, 2, sci_strings)) { /*-------------------------------------------*/ /* clipboard("do", {"paste","copy","empty"}) */ /*-------------------------------------------*/ /* @TODO : should be remplaced by an enum */ if ( strcmp(param1, "do") == 0 ) { freeAllocatedSingleString(param1); sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrl1); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 2. if (getAllocatedSingleString(pvApiCtx, piAddrl1, ¶m2)) { Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 2); return 1; } if ( strcmp(param2, "paste") == 0 ) { /* Call Java to do the job */ pasteClipboardIntoConsole(); } else if ( strcmp(param2, "copy") == 0 ) { /* Call Java to do the job */ copyConsoleSelection(); } else if ( strcmp(param2, "empty") == 0 ) { /* Call Java to do the job */ emptyClipboard(); } else { freeAllocatedSingleString(param2); Scierror(999, _("%s: Wrong value for input argument #%d: '%s', '%s' or '%s' expected.\n"), fname, 2, "copy", "paste", "empty"); return FALSE; } m1 = 0; n1 = 0; freeAllocatedSingleString(param2); sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, m1, n1, &pdbll1); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); return TRUE; } /*-------------------------*/ /* clipboard("copy", data) */ /*-------------------------*/ else if ( strcmp(param1, "copy") == 0 ) { char *TextToPutInClipboard = NULL; char **Str = NULL; int m2 = 0, n2 = 0; freeAllocatedSingleString(param1); sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrStr); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of string at position 2. if (getAllocatedMatrixOfString(pvApiCtx, piAddrStr, &m2, &n2, &Str)) { Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 2); return 1; } if (m2 * n2 == 1) /* Single line copy */ { TextToPutInClipboard = Str[0]; /* Call Java to do the job */ setClipboardContents(TextToPutInClipboard); } else /* Multi-line copy */ { int i = 0, j = 0, l2 = 0; char *TextToSendInClipboard = NULL; int SizeofTextToSendInClipboard = 0; char **buffer = (char**)MALLOC( (m2 * n2) * sizeof(char *) ); if (buffer == NULL) { freeAllocatedMatrixOfString(m2, n2, Str); Scierror(999, _("%s: No more memory.\n"), fname); return FALSE; } for (i = 0; i < m2; i++) { for (j = 0; j < n2; j++) { SizeofTextToSendInClipboard = SizeofTextToSendInClipboard + (int)strlen(Str[j * m2 + i]) + (int)strlen("\n") + (int)strlen(" "); buffer[i * n2 + j] = os_strdup(Str[j * m2 + i]); } } TextToSendInClipboard = (char*)MALLOC( (SizeofTextToSendInClipboard) * sizeof(char) ); if (TextToSendInClipboard == NULL) { freeAllocatedMatrixOfString(m2, n2, Str); Scierror(999, _("%s: No more memory.\n"), fname); freeArrayOfString(buffer, m2 * n2); return FALSE; } strcpy(TextToSendInClipboard, ""); for (i = 0; i < m2; i++) { for (j = 0; j < n2; j++) { strcat(TextToSendInClipboard, buffer[l2++]); strcat(TextToSendInClipboard, " "); } if ( i != (m2 - 1) ) { strcat(TextToSendInClipboard, "\n"); } } /* Call Java to do the job */ setClipboardContents(TextToSendInClipboard); FREE(buffer); buffer = NULL; freeArrayOfString(buffer, m2 * n2); FREE(TextToSendInClipboard); TextToSendInClipboard = NULL; } freeAllocatedMatrixOfString(m2, n2, Str); m1 = 0; n1 = 0; sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, m1, n1, &pdbll1); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); return TRUE; } } else { freeAllocatedSingleString(param1); Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 2); return FALSE; } } /*----------------------------------*/ /* clipboard(fignum, {"EMF","DIB"}) */ /*----------------------------------*/ else if (checkInputArgumentType(pvApiCtx, 1, sci_matrix)) { int num_win = -2; sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr1); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 1. sciErr = getMatrixOfDoubleAsInteger(pvApiCtx, piAddr1, &m1, &n1, &pil1); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 1); return 1; } num_win = pil1[0]; if (m1 * n1 != 1) { Scierror(999, _("%s: Wrong size for input argument #%d: A real expected.\n"), fname, 1); return FALSE; } if (checkInputArgumentType(pvApiCtx, 2, sci_strings)) { sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrl1); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 2. if (getAllocatedSingleString(pvApiCtx, piAddrl1, ¶m2)) { Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 2); return 1; } if ( ( strcmp(param2, "EMF") == 0 ) || ( strcmp(param2, "DIB") == 0 ) ) { if (num_win >= 0) { /* Call Java */ if ( strcmp(param2, "EMF") == 0) { /* @TODO create EMF */ copyFigureToClipBoard(getFigureFromIndex(num_win)); } else { /* @TODO create DIB */ copyFigureToClipBoard(getFigureFromIndex(num_win)); } m1 = 0; n1 = 0; freeAllocatedSingleString(param2); sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, m1, n1, &pdbll1); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); return TRUE; } else { freeAllocatedSingleString(param2); Scierror(999, _("%s: Wrong value for input argument #%d: Must be >= %d expected.\n"), fname, 1, 0); return FALSE; } } else { freeAllocatedSingleString(param2); Scierror(999, _("%s: Wrong value for input argument #%d: '%s' or '%s' expected.\n"), fname, 2, "EMF", "DIB"); return FALSE; } } else { Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 2); return FALSE; } } else { Scierror(999, _("%s: Wrong type for input argument #%d: string or real expected.\n"), fname, 1); return FALSE; } } } else { Scierror(999, _("%s: Function not available in NWNI mode.\n"), fname); return FALSE; } return FALSE; }
/*--------------------------------------------------------------------------*/ int sci_winqueryreg(char *fname, unsigned long l) { SciErr sciErr; int *piAddressVarOne = NULL; int *piAddressVarTwo = NULL; int *piAddressVarThree = NULL; char *pStrParamOne = NULL; char *pStrParamTwo = NULL; char *pStrParamThree = NULL; char *pStrOutput = NULL; int iOutput = 0; Rhs = Max(0, Rhs); CheckRhs(2, 3); CheckLhs(0, 1); if (Rhs == 3) { sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddressVarThree); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 3); return 0; } if (!isStringType(pvApiCtx, piAddressVarThree)) { Scierror(999, _("%s: Wrong type for input argument #%d: String expected.\n"), fname, 3); return 0; } if (!isScalar(pvApiCtx, piAddressVarThree)) { Scierror(999, _("%s: Wrong size for input argument #%d: String expected.\n"), fname, 3); return 0; } if (getAllocatedSingleString(pvApiCtx, piAddressVarThree, &pStrParamThree) != 0) { Scierror(999, _("%s: Memory allocation error.\n"), fname); return 0; } } sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddressVarOne); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1); return 0; } if (!isStringType(pvApiCtx, piAddressVarOne)) { Scierror(999, _("%s: Wrong type for input argument #%d: String expected.\n"), fname, 1); return 0; } if (!isScalar(pvApiCtx, piAddressVarOne)) { Scierror(999, _("%s: Wrong size for input argument #%d: String expected.\n"), fname, 1); return 0; } sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddressVarTwo); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2); return 0; } if (!isStringType(pvApiCtx, piAddressVarTwo)) { Scierror(999, _("%s: Wrong type for input argument #%d: String expected.\n"), fname, 2); return 0; } if (!isScalar(pvApiCtx, piAddressVarTwo)) { Scierror(999, _("%s: Wrong size for input argument #%d: String expected.\n"), fname, 2); return 0; } if (getAllocatedSingleString(pvApiCtx, piAddressVarTwo, &pStrParamTwo) != 0) { if (pStrParamThree) { freeAllocatedSingleString(pStrParamThree); pStrParamThree = NULL; } Scierror(999, _("%s: Memory allocation error.\n"), fname); return 0; } if (getAllocatedSingleString(pvApiCtx, piAddressVarOne, &pStrParamOne) != 0) { if (pStrParamThree) { freeAllocatedSingleString(pStrParamThree); pStrParamThree = NULL; } if (pStrParamTwo) { freeAllocatedSingleString(pStrParamTwo); pStrParamTwo = NULL; } Scierror(999, _("%s: Memory allocation error.\n"), fname); return 0; } if (Rhs == 3) { BOOL bKey = strcmp(pStrParamOne, "key") == 0; BOOL bValue = strcmp(pStrParamOne, "name") == 0; if (bValue || bKey) { int NumbersElm = 0; if (bValue) { WindowsQueryRegistryNumberOfValuesInList(pStrParamTwo, pStrParamThree, &NumbersElm); } else { WindowsQueryRegistryNumberOfKeysInList(pStrParamTwo, pStrParamThree, &NumbersElm); } if (NumbersElm) { BOOL bResult = FALSE; #define MAX_ELMT_REGLIST 255 char **ListKeysName = NULL; int i = 0; if (NumbersElm > MAX_ELMT_REGLIST) { NumbersElm = MAX_ELMT_REGLIST; } ListKeysName = (char **)MALLOC(sizeof(char*) * NumbersElm); for (i = 0; i < NumbersElm; i++) { ListKeysName[i] = NULL; } if (bValue) { bResult = WindowsQueryRegistryValuesList(pStrParamTwo, pStrParamThree, NumbersElm, ListKeysName); } else { bResult = WindowsQueryRegistryKeysList(pStrParamTwo, pStrParamThree, NumbersElm, ListKeysName); } if (bResult) { int nOne = 1; sciErr = createMatrixOfString(pvApiCtx, Rhs + 1, NumbersElm, nOne, ListKeysName); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); } else { LhsVar(1) = Rhs + 1; PutLhsVar(); } } else { Scierror(999, _("%s: Cannot open Windows registry.\n"), fname); } freeArrayOfString(ListKeysName, NumbersElm); } else { createEmptyMatrix(pvApiCtx, Rhs + 1); LhsVar(1) = Rhs + 1; PutLhsVar(); } if (pStrParamThree) { freeAllocatedSingleString(pStrParamThree); pStrParamThree = NULL; } if (pStrParamTwo) { freeAllocatedSingleString(pStrParamTwo); pStrParamTwo = NULL; } if (pStrParamOne) { freeAllocatedSingleString(pStrParamOne); pStrParamOne = NULL; } return 0; } } pStrOutput = (char*)MALLOC(PATH_MAX * sizeof(char)); if (pStrOutput) { BOOL OuputIsREG_SZ = FALSE; BOOL TestWinQuery = WindowsQueryRegistry(pStrParamOne, pStrParamTwo, pStrParamThree, pStrOutput, &iOutput, &OuputIsREG_SZ); if ( TestWinQuery ) { if (OuputIsREG_SZ) { createSingleString(pvApiCtx, Rhs + 1, pStrOutput); } else { createScalarDouble(pvApiCtx, Rhs + 1, (double)iOutput); } LhsVar(1) = Rhs + 1; PutLhsVar(); } else { Scierror(999, _("%s: Cannot query value of this type.\n"), fname); } FREE( pStrOutput); pStrOutput = NULL; } else { Scierror(999, _("%s: Memory allocation error.\n"), fname); } if (pStrParamThree) { freeAllocatedSingleString(pStrParamThree); pStrParamThree = NULL; } if (pStrParamTwo) { freeAllocatedSingleString(pStrParamTwo); pStrParamTwo = NULL; } if (pStrParamOne) { freeAllocatedSingleString(pStrParamOne); pStrParamOne = NULL; } return 0; }
int stringExample(char *fname, unsigned long fname_len) { SciErr sciErr; int* piAddr = NULL; int iType = 0; int iRet = 0; CheckInputArgument(pvApiCtx, 1, 1); CheckOutputArgument(pvApiCtx, 0, 1); sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr); if (sciErr.iErr) { printError(&sciErr, 0); return 0; } if (isStringType(pvApiCtx, piAddr)) { if (isScalar(pvApiCtx, piAddr)) { char* pstData = NULL; iRet = getAllocatedSingleString(pvApiCtx, piAddr, &pstData); if (iRet) { freeAllocatedSingleString(pstData); return iRet; } iRet = createSingleString(pvApiCtx, nbInputArgument(pvApiCtx) + 1, pstData); if (iRet) { freeAllocatedSingleString(pstData); return iRet; } freeAllocatedSingleString(pstData); } else { int iRows = 0; int iCols = 0; char** pstData = NULL; iRet = getAllocatedMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, &pstData); if (iRet) { freeAllocatedMatrixOfString(iRows, iCols, pstData); return iRet; } sciErr = createMatrixOfString(pvApiCtx, nbInputArgument(pvApiCtx) + 1, iRows, iCols, pstData); if (sciErr.iErr) { freeAllocatedMatrixOfString(iRows, iCols, pstData); printError(&sciErr, 0); return sciErr.iErr; } freeAllocatedMatrixOfString(iRows, iCols, pstData); } AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; } else { AssignOutputVariable(pvApiCtx, 1) = 0; } return 0; }
int CreateCharVariable(void *pvApiCtx, int iVar, matvar_t *matVariable, int * parent, int item_position) { int nbRow = 0, nbCol = 0; char **charData = NULL; int K = 0, L = 0; SciErr sciErr; if (matVariable->rank == 2) /* 2-D array */ { nbRow = (int)matVariable->dims[0]; nbCol = nbRow == 0 ? 0 : 1; /* In Scilab empty string has size 0x0 */ if (nbRow != 0) { charData = (char**) MALLOC(sizeof(char*) * nbRow); if (charData == NULL) { Scierror(999, _("%s: No more memory.\n"), "CreateCharVariable"); return FALSE; } } for (K = 0; K < nbRow; K++) { charData[K] = (char*) MALLOC(sizeof(char*) * (matVariable->dims[1] + 1)); if (charData[K] == NULL) { Scierror(999, _("%s: No more memory.\n"), "CreateCharVariable"); return FALSE; } } /* Fill items: data in Matlab file is stored columnwise */ for (K = 0; K < (int)matVariable->dims[0]; K++) /* Loop over items */ { for (L = 0; L < (int)matVariable->dims[1]; L++) /* Loop over chars */ { charData[K][L] = ((char *)matVariable->data)[L * matVariable->dims[0] + K]; } charData[K][L] = '\0'; } if (nbRow * nbCol != 0) { if (parent == NULL) { sciErr = createMatrixOfString(pvApiCtx, iVar, nbRow, nbCol, charData); if (sciErr.iErr) { printError(&sciErr, 0); return 0; } } else { sciErr = createMatrixOfStringInList(pvApiCtx, iVar, parent, item_position, nbRow, nbCol, charData); if (sciErr.iErr) { printError(&sciErr, 0); return 0; } } } else /* Empty character string */ { if (parent == NULL) { createSingleString(pvApiCtx, iVar, "\0"); } else { char ** tmp_char = (char **)MALLOC(sizeof(char *)); tmp_char[0] = os_strdup("\0"); sciErr = createMatrixOfStringInList(pvApiCtx, iVar, parent, item_position, 1, 1, tmp_char); if (sciErr.iErr) { printError(&sciErr, 0); return 0; } freeArrayOfString(tmp_char, 1); } } freeArrayOfString(charData, nbRow * nbCol); } else /* Multi-dimension array -> Scilab HyperMatrix */ { Scierror(999, _("%s: N-D arrays of chars not implemented.\n"), "CreateCharVariable"); return FALSE; } return TRUE; }
/*--------------------------------------------------------------------------*/ int C2F(sci_lasterror)(char *fname,unsigned long fname_len) { SciErr sciErr; BOOL bClearLastError = TRUE; int NbLines = 0; const char **errorMessage = NULL; Rhs = Max(0, Rhs); CheckRhs(0,1); CheckLhs(1,4); if (Rhs == 1) { int *piAddressVarOne = NULL; /* get Address of inputs */ sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddressVarOne); if(sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1); return 0; } if (isBooleanType(pvApiCtx, piAddressVarOne)) { if (isScalar(pvApiCtx, piAddressVarOne)) { getScalarBoolean(pvApiCtx, piAddressVarOne, &bClearLastError); } else { Scierror(999,_("%s: Wrong size for input argument #%d: A boolean expected.\n"), fname, 1); } } else { Scierror(999,_("%s: Wrong type for input argument #%d: A boolean expected.\n"), fname, 1); } } errorMessage = getLastErrorMessage(&NbLines); if ((NbLines <= 0) || (errorMessage == NULL)) { createEmptyMatrix(pvApiCtx, Rhs + 1); } else { sciErr = createMatrixOfString(pvApiCtx, Rhs + 1, NbLines, 1, (char**)errorMessage); if(sciErr.iErr) { printError(&sciErr, 0); Scierror(999,_("%s: Memory allocation error.\n"), fname); return 0; } } LhsVar(1) = Rhs + 1; if (Lhs >= 2) { double dLastErrorValue = (double) getLastErrorValue(); createScalarDouble(pvApiCtx, Rhs + 2, dLastErrorValue); LhsVar(2) = Rhs + 2; } if (Lhs >= 3) { double dLinePosition = (double) getLastErrorLinePosition(); createScalarDouble(pvApiCtx, Rhs + 3, dLinePosition); LhsVar(3) = Rhs + 3; } if (Lhs == 4) { createSingleString(pvApiCtx, Rhs + 4, (char*)getLastErrorFunctionName()); LhsVar(4) = Rhs + 4; } if (bClearLastError) { clearLastError(); } PutLhsVar(); return 0; }
/*--------------------------------------------------------------------------*/ int sci_get(char *fname, void *pvApiCtx) { SciErr sciErr; int* piAddrl1 = NULL; long long* l1 = NULL; int* piAddrl2 = NULL; char* l2 = NULL; int m1 = 0, n1 = 0; long hdl = 0; int lw = 0; int iObjUID = 0; int status = SET_PROPERTY_ERROR; CheckInputArgument(pvApiCtx, 1, 2); CheckOutputArgument(pvApiCtx, 0, 1); sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrl1); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } if (isMListType(pvApiCtx, piAddrl1) || isTListType(pvApiCtx, piAddrl1)) { OverLoad(1); return 0; } /* * The first input argument can be an ID or a marker (in this case, get returns the value of the current object */ switch (getInputArgumentType(pvApiCtx, 1)) { case sci_matrix: //console handle { double dbll1 = 0; if (isScalar(pvApiCtx, piAddrl1) == 0) { Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 1); return 1; } // Retrieve a matrix of double at position 1. if (getScalarDouble(pvApiCtx, piAddrl1, &dbll1)) { Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 1); return 1; } if ((int)dbll1 == 0) /* Console property */ { int* piAddrstkAdr = NULL; char *stkAdr = NULL; if (nbInputArgument(pvApiCtx) == 1) { if (sciReturnHandle(getHandle(getConsoleIdentifier())) != 0) /* Get Console handle */ { ReturnArguments(pvApiCtx); return 0; } AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); return 0; } CheckInputArgument(pvApiCtx, 2, 2); sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrstkAdr); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of string at position 2. if (getAllocatedSingleString(pvApiCtx, piAddrstkAdr, &stkAdr)) { Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 2); return 1; } if (GetScreenProperty(pvApiCtx, stkAdr) != SET_PROPERTY_SUCCEED) { Scierror(999, _("%s: Could not read property '%s' for console object.\n"), "get", stkAdr[0]); freeAllocatedSingleString(stkAdr); return 1; } freeAllocatedSingleString(stkAdr); AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); } return 0; break; } case sci_handles: /* scalar argument (hdl + string) */ CheckInputArgument(pvApiCtx, 1, 2); // Retrieve a matrix of handle at position 1. sciErr = getMatrixOfHandle(pvApiCtx, piAddrl1, &m1, &n1, &l1); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for input argument #%d: Handle matrix expected.\n"), fname, 1); return 1; } if (m1 != 1 || n1 != 1) { //lw = 1 + nbArgumentOnStack(pvApiCtx) - nbInputArgument(pvApiCtx); OverLoad(1); return 0; } if (nbInputArgument(pvApiCtx) == 1) { //get path from handle int uic = getObjectFromHandle((long) * l1); char* path = get_path(uic); if (path[0] == '\0') { Scierror(999, _("%s: Unable to get useful path from this handle.\n"), fname); return 1; } createSingleString(pvApiCtx, nbInputArgument(pvApiCtx) + 1, path); FREE(path); AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); return 0; } sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrl2); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } if (isScalar(pvApiCtx, piAddrl2) == 0 || isStringType(pvApiCtx, piAddrl2) == 0) { Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 2); return 1; } // Retrieve a matrix of double at position 2. if (getAllocatedSingleString(pvApiCtx, piAddrl2, &l2)) { Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 2); return 1; } hdl = (long) * l1; /* on recupere le pointeur d'objet par le handle */ break; case sci_strings: /* string argument (string) */ { char* pstFirst = NULL; CheckInputArgument(pvApiCtx, 1, 2); if (isScalar(pvApiCtx, piAddrl1) == 0) { Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 1); return 1; } // Retrieve a matrix of double at position 1. if (getAllocatedSingleString(pvApiCtx, piAddrl1, &pstFirst)) { Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 1); return 1; } if (strcmp(pstFirst, "default_figure") == 0 || strcmp(pstFirst, "default_axes") == 0 || strcmp(pstFirst, "current_figure") == 0 || strcmp(pstFirst, "current_axes") == 0 || strcmp(pstFirst, "current_entity") == 0 || strcmp(pstFirst, "hdl") == 0 || strcmp(pstFirst, "figures_id") == 0) { hdl = 0; l2 = pstFirst; } else { int uid = search_path(pstFirst); if (uid != 0) { freeAllocatedSingleString(pstFirst); hdl = getHandle(uid); if (nbInputArgument(pvApiCtx) == 1) { createScalarHandle(pvApiCtx, nbInputArgument(pvApiCtx) + 1, hdl); AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); return 0; } sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrl2); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } if (isScalar(pvApiCtx, piAddrl2) == 0 || isStringType(pvApiCtx, piAddrl2) == 0) { Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 2); return 1; } if (getAllocatedSingleString(pvApiCtx, piAddrl2, &l2)) { Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 2); return 1; } } else { createEmptyMatrix(pvApiCtx, nbInputArgument(pvApiCtx) + 1); AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); return 0; } } break; } default: //lw = 1 + nbArgumentOnStack(pvApiCtx) - nbInputArgument(pvApiCtx); OverLoad(1); return 0; break; } /* (l2) est la commande, l3 l'indice sur les parametres de la commande */ CheckOutputArgument(pvApiCtx, 0, 1); if (hdl == 0) { /* No handle specified */ if (callGetProperty(pvApiCtx, 0, (l2)) != 0) { /* An error has occurred */ freeAllocatedSingleString(l2); ReturnArguments(pvApiCtx); return 0; } } else { iObjUID = getObjectFromHandle(hdl); if (iObjUID != 0) { if (callGetProperty(pvApiCtx, iObjUID, (l2)) != 0) { /* An error has occurred */ freeAllocatedSingleString(l2); ReturnArguments(pvApiCtx); return 0; } } else { Scierror(999, _("%s: The handle is not or no more valid.\n"), fname); freeAllocatedSingleString(l2); return 0; } } AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); freeAllocatedSingleString(l2); return 0; }
/*--------------------------------------------------------------------------*/ int sci_toolbar(char *fname, unsigned long l) { SciErr sciErr; int* piAddr1 = NULL; int* piStkAdr = NULL; int* piAddrstkAdr = NULL; long long* stkAdr = NULL; int* piAddrparam = NULL; int nbCol = 0; int nbRow = 0; char *Output = NULL; char **param = NULL; int figNum = -2; int iIsVisible = 0; int *piIsVisible = NULL; int iParentUID = 0; int iParentType = -1; int *piParentType = &iParentType; CheckInputArgument(pvApiCtx, 1, 2); CheckOutputArgument(pvApiCtx, 0, 1); /* Figure number */ if (checkInputArgumentType(pvApiCtx, 1, sci_matrix)) { sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr1); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 1. sciErr = getMatrixOfDoubleAsInteger(pvApiCtx, piAddr1, &nbRow, &nbCol, &piStkAdr); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for input argument #%d: A real expected.\n"), fname, 1); return 1; } if (nbRow * nbCol != 1) { Scierror(999, _("%s: Wrong size for input argument #%d: A real expected.\n"), fname, 1); return FALSE; } figNum = *piStkAdr; if (figNum < -1) { Scierror(999, _("%s: Wrong value for input argument #%d: Must be > %d expected.\n"), fname, 1, -1); return FALSE; } if (figNum != -1) /* Check that the figure exists */ { if (getFigureFromIndex(figNum) == 0) { Scierror(999, _("%s: Wrong value for input argument #%d: 'Graphic Window Number %d' does not exist.\n"), fname, 1, figNum); return FALSE; } } if (figNum == -1) { iParentUID = getConsoleIdentifier(); } else { iParentUID = getFigureFromIndex(figNum); } } else if (checkInputArgumentType(pvApiCtx, 1, sci_handles)) { sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrstkAdr); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of handle at position 1. sciErr = getMatrixOfHandle(pvApiCtx, piAddrstkAdr, &nbRow, &nbCol, &stkAdr); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for input argument #%d: Handle matrix expected.\n"), fname, 1); return 1; } if (nbRow * nbCol != 1) { Scierror(999, _("%s: Wrong size for input argument #%d: A graphic handle expected.\n"), fname, 1); return FALSE; } iParentUID = getObjectFromHandle((long) * stkAdr); if (iParentUID == 0) { Scierror(999, _("%s: Wrong value for input argument #%d: this handle does not exist.\n"), fname, 1); return FALSE; } getGraphicObjectProperty(iParentUID, __GO_TYPE__, jni_int, (void **)&piParentType); if (iParentType != __GO_FIGURE__) { Scierror(999, _("%s: Wrong type for input argument #%d: A real or a Figure handle expected.\n"), fname, 1); return FALSE; } } else { Scierror(999, _("%s: Wrong type for input argument #%d: A real or a Figure handle expected.\n"), fname, 1); return FALSE; } if (nbInputArgument(pvApiCtx) == 2) /* New status */ { if ((checkInputArgumentType(pvApiCtx, 2, sci_strings))) { sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrparam); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of string at position 2. if (getAllocatedMatrixOfString(pvApiCtx, piAddrparam, &nbRow, &nbCol, ¶m)) { Scierror(202, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 2); return 1; } if (nbRow * nbCol != 1) { freeAllocatedMatrixOfString(nbRow, nbCol, param); Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), fname, 2); return FALSE; } if ((strcmp(param[0], "off") == 0) || (strcmp(param[0], "on") == 0)) { iIsVisible = strcmp(param[0], "on") == 0; if (iParentUID != getConsoleIdentifier() || getScilabMode() == SCILAB_STD) { setGraphicObjectProperty(iParentUID, __GO_TOOLBAR_VISIBLE__, &iIsVisible, jni_bool, 1); } freeAllocatedMatrixOfString(nbRow, nbCol, param); } else { freeAllocatedMatrixOfString(nbRow, nbCol, param); Scierror(999, _("%s: Wrong value for input argument #%d: '%s' or '%s' expected.\n"), fname, 2, "on", "off"); return FALSE; } } else { Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 2); return FALSE; } } /* Returned value */ piIsVisible = &iIsVisible; getGraphicObjectProperty(iParentUID, __GO_TOOLBAR_VISIBLE__, jni_bool, (void **)&piIsVisible); if (iIsVisible) { Output = strdup("on"); } else { Output = strdup("off"); } nbCol = 1; nbRow = (int)strlen(Output); if (createSingleString(pvApiCtx, nbInputArgument(pvApiCtx) + 1, Output)) { Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; if (Output) { FREE(Output); Output = NULL; } ReturnArguments(pvApiCtx); return TRUE; }
/*--------------------------------------------------------------------------*/ int sci_libraryinfo(char *fname,unsigned long fname_len) { SciErr sciErr; int *piAddressVarOne = NULL; CheckRhs(1,1); CheckLhs(1,2); sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddressVarOne); if(sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1); return 0; } if (isStringType(pvApiCtx, piAddressVarOne)) { char *libraryname = NULL; if (!isScalar(pvApiCtx, piAddressVarOne)) { Scierror(999,_("%s: Wrong size for input argument #%d: String expected.\n"), fname, 1); return 0; } if (getAllocatedSingleString(pvApiCtx, piAddressVarOne, &libraryname) == 0) { if (libraryname) { char *pathlibrary = getlibrarypath(libraryname); if (pathlibrary) { int sizemacrosarray = 0; char **macros = getlistmacrosfromlibrary(libraryname, &sizemacrosarray); if (macros) { int m = sizemacrosarray; int n = 1; sciErr = createMatrixOfString(pvApiCtx, Rhs + 1, m, n, macros); if(sciErr.iErr) { freeArrayOfString(macros, sizemacrosarray); if (pathlibrary) { FREE(pathlibrary); pathlibrary = NULL; } if (libraryname) { freeAllocatedSingleString(libraryname); libraryname = NULL; } printError(&sciErr, 0); Scierror(999,_("%s: Memory allocation error.\n"), fname); return 0; } } else { createEmptyMatrix(pvApiCtx, Rhs + 1); } LhsVar(1) = Rhs+1; freeArrayOfString(macros, sizemacrosarray); if (Lhs == 2) { createSingleString(pvApiCtx, Rhs + 2, pathlibrary); LhsVar(2) = Rhs+2; } if (pathlibrary) {FREE(pathlibrary);pathlibrary=NULL;} PutLhsVar(); } else { Scierror(999,_("%s: Invalid library %s.\n"),fname, libraryname); } if (libraryname) { freeAllocatedSingleString(libraryname); libraryname = NULL; } } else { Scierror(999,_("%s: Memory allocation error.\n"), fname); } } else { Scierror(999,_("%s: Memory allocation error.\n"), fname); } } else { Scierror(999,_("%s: Wrong type of input argument #%d: String expected.\n"),fname,1); } return 0; }
// ============================================================================= static int sci_csvDefault_one_rhs(char *fname, void* pvApiCtx) { int iErr = 0; char *fieldname = NULL; char *fieldvalue = NULL; fieldname = csv_getArgumentAsString(pvApiCtx, 1, fname, &iErr); if (iErr) { freeVar(&fieldname, &fieldvalue); return 0; } if (strcmp(fieldname, SEPARATOR_FIELDNAME) == 0) { fieldvalue = os_strdup(getCsvDefaultSeparator()); } else if (strcmp(fieldname, DECIMAL_FIELDNAME) == 0) { fieldvalue = os_strdup(getCsvDefaultDecimal()); } else if (strcmp(fieldname, CONVERSION_FIELDNAME) == 0) { fieldvalue = os_strdup(getCsvDefaultConversion()); } else if (strcmp(fieldname, PRECISION_FIELDNAME) == 0) { fieldvalue = os_strdup(getCsvDefaultPrecision()); } else if (strcmp(fieldname, COMMENTSREGEXP_FIELDNAME) == 0) { fieldvalue = os_strdup(getCsvDefaultCommentsRegExp()); } else if (strcmp(fieldname, EOL_FIELDNAME) == 0) { const char *currentEol = getCsvDefaultEOL(); if (currentEol) { if (strcmp(currentEol, MACOS9_EOL) == 0) { fieldvalue = os_strdup(MACOS9_EOL_STRING); } else if (strcmp(currentEol, WINDOWS_EOL) == 0) { fieldvalue = os_strdup(WINDOWS_EOL_STRING); } else if (strcmp(currentEol, LINUX_EOL) == 0) { fieldvalue = os_strdup(LINUX_EOL_STRING); } else { fieldvalue = os_strdup("ERROR"); } } else { fieldvalue = os_strdup("ERROR"); } } else if (strcmp(fieldname, ENCODING_FIELDNAME) == 0) { fieldvalue = os_strdup(getCsvDefaultEncoding()); } else if (strcmp(fieldname, BLANK_FIELDNAME) == 0) { fieldvalue = os_strdup(getCsvDefaultCsvIgnoreBlankLine()); } else if (strcmp(fieldname, RESET_PARAMATERS) == 0) { freeVar(&fieldname, &fieldvalue); setCsvDefaultReset(); createEmptyMatrix(pvApiCtx, Rhs + 1); LhsVar(1) = Rhs + 1; PutLhsVar(); return 0; } else { Scierror(999, _("%s: Wrong value for input argument #%d: '%s', '%s', '%s', '%s', '%s' or '%s' expected.\n"), fname, 1, SEPARATOR_FIELDNAME, DECIMAL_FIELDNAME, CONVERSION_FIELDNAME, COMMENTSREGEXP_FIELDNAME, EOL_FIELDNAME, BLANK_FIELDNAME); freeVar(&fieldname, &fieldvalue); return 0; } createSingleString(pvApiCtx, Rhs + 1, fieldvalue); freeVar(&fieldname, &fieldvalue); LhsVar(1) = Rhs + 1; PutLhsVar(); return 0; }