/*--------------------------------------------------------------------------*/ types::Function::ReturnValue sci_findfileassociation(types::typed_list &in, int _iRetCount, types::typed_list &out) { types::String* pS = nullptr; std::wstring param1; std::wstring param2(L"open"); int rhs = static_cast<int>(in.size()); if (rhs != 1 && rhs != 2) { Scierror(77, _("%s: Wrong number of input argument(s): %d to %d expected.\n"), fname.data(), 1, 2); return types::Function::Error; } if (_iRetCount != 1) { Scierror(999, _("%s: Wrong number of output arguments: %d expected.\n"), fname.data(), 1); return types::Function::Error; } if (in[0]->isString() == false) { Scierror(999, _("%s: Wrong type for input argument #%d: String expected.\n"), fname.data(), 1); return types::Function::Error; } pS = in[0]->getAs<types::String>(); if (pS->isScalar() == false) { Scierror(999, _("%s: Wrong size for input argument #%d: String expected.\n"), fname.data(), 1); return types::Function::Error; } param1 = pS->get()[0]; if (rhs == 2) { if (in[1]->isString() == false) { Scierror(999, _("%s: Wrong type for input argument #%d: String expected.\n"), fname.data(), 2); return types::Function::Error; } pS = in[1]->getAs<types::String>(); if (pS->isScalar() == false) { Scierror(999, _("%s: Wrong size for input argument #%d: String expected.\n"), fname.data(), 2); return types::Function::Error; } param2 = pS->get()[0]; } wchar_t* output = FindFileAssociation(param1.data(), param2.data()) ; if (output) { out.push_back(new types::String(output)); } else { out.push_back(types::Double::Empty()); } return types::Function::OK; }
/*--------------------------------------------------------------------------*/ int sci_findfileassociation(char *fname,unsigned long l) { static int l1,n1,m1; char *Output=NULL; char ExtraParam[PATH_MAX]; char AssocParam[PATH_MAX]; Rhs=Max(Rhs,0); CheckRhs(1,2); CheckLhs(0,1); if (Rhs == 1) { if (GetType(1) != sci_strings) { Scierror(999,_("%s: Wrong type for input argument #%d: String expected.\n") ,fname,1); return 0; } else { char *param=NULL; GetRhsVar(1,STRING_DATATYPE,&m1,&n1,&l1); param=cstk(l1); strcpy(AssocParam,param); strcpy(ExtraParam,"open"); } } else { if ( (GetType(1) != sci_strings) && (GetType(2) != sci_strings) ) { Scierror(999,_("%s: Wrong type for input arguments: Strings expected.\n"),fname); return 0; } else { char *param=NULL; GetRhsVar(1,STRING_DATATYPE,&m1,&n1,&l1); param=cstk(l1); strcpy(AssocParam,param); GetRhsVar(2,STRING_DATATYPE,&m1,&n1,&l1); param=cstk(l1); strcpy(ExtraParam,param); } } Output=FindFileAssociation(AssocParam,ExtraParam) ; if (Output) { n1=1; CreateVarFromPtr(Rhs+ 1,STRING_DATATYPE,(m1=(int)strlen(Output), &m1),&n1,&Output); } else { n1=0; m1=0; l1=0; CreateVarFromPtr(Rhs+ 1,MATRIX_OF_DOUBLE_DATATYPE,&n1,&m1,&l1); } if (Output) {FREE(Output);Output=NULL;} LhsVar(1) = Rhs+1; PutLhsVar(); return 0; }