Example #1
0
/*
 * a - name of scan configuration to save or restore
 * b - return value from fdbrestore()
 * c - current state of busy record
 * d - status from callback (0 or -1)
 * e - restore(0) or save(1)
 * f - reqFile
 * g - configMenu name
 * vala - desired state of busy record (used to set)
 * valb - desired state of busy record (used to clear)
 * valc - status value for output: 0=Success, 1=Error
 */
static long configMenu_do(aSubRecord *pasub) {
	char *a = (char *)pasub->a;
	epicsInt32 *b = (epicsInt32 *)pasub->b;
	char *c = (char *)pasub->c;
	epicsInt32 *d = (epicsInt32 *)pasub->d;
	short *e = (short *)pasub->e;
	char *f = (char *)pasub->f;
	char *g = (char *)pasub->g;
	epicsInt32 *vala = (epicsInt32 *)pasub->vala;
	epicsInt32 *valb = (epicsInt32 *)pasub->valb;
	epicsInt32 *valc = (epicsInt32 *)pasub->valc;
	char *macrostring = NULL;
	char filename[100];

	if (configMenuDebug) printf("configMenu_do:c='%s' (%s)\n",
		c, *e?"save":"restore");

	if (*e==0) {
		/* restore */
		if (strcmp(c,"Done") == 0) {
			/* start restore operation */
			if (configMenuDebug)
				printf("configMenu_do:a='%s', c='%s', pasub=%p\n", a, c, pasub);
			if (strlen(a)<1) {
				*d = 1;
				*valc = 1;
				return(0);
			}
			if (f) {
				macrostring = getMacroString(f);
			}
			makeLegal(a);
			epicsSnprintf(filename, 99, "%s_%s.cfg", g, a);
			*b = fdbrestoreX(filename, macrostring, configMenuCallback, (void *)pasub);
			if (configMenuDebug) printf("configMenu_do:fdbrestore returned %d\n", *b);
			*vala = 1;
			*valb = 1;
		} else {
			/* this is a callback from restore operation */
			if (configMenuDebug)
				printf("configMenu_do:callback status=%d\n", *valc);
			*valc = (*d ? 1 : 0);
			*vala = 0;
			*valb = 0;
		}
	} else {
		/* save */
		if (strcmp(c,"Done") == 0) {
			/* start save operation */
			if (configMenuDebug)
				printf("configMenu_do:a='%s', c='%s', pasub=%p\n", a, c, pasub);
			if (strlen(a)<1) {
				*d = 1;
				*valc = 1;
				return(0);
			}
			makeLegal(a);
			epicsSnprintf(filename, 99, "%s_%s.cfg", g, a);
			*b = (epicsInt32)manual_save(f, filename, configMenuCallback, (void *)pasub);
			if (configMenuDebug) printf("configMenu_do:manual_save returned %d\n", *b);
			*vala = 1;
			*valb = 1;
		} else {
			/* this is a callback from a save operation */
			if (configMenuDebug)
				printf("configMenu_do:save callback status=%d\n", *valc);
			*valc = (*d ? 1 : 0);
			*vala = 0;
			*valb = 0;
		}
	}
	return(0);
}
Example #2
0
types::Function::ReturnValue sci_string(types::typed_list &in, int _iRetCount, types::typed_list &out)
{
    if (in.size() != 1)
    {
        Scierror(77, _("%s: Wrong number of input argument(s): %d expected.\n"), "string", 1);
        return types::Function::Error;
    }

    switch (in[0]->getType())
    {
        case types::GenericType::ScilabSparse:
        {
            //C=sparse([0 0 4 0 9;0 0 5 0 0;1 3 0 7 0;0 0 6 0 10;2 0 0 8 0]);string(C)
            types::Sparse* pS = in[0]->getAs<types::Sparse>();
            int iRows = pS->getRows();
            int iCols = pS->getCols();
            bool isComplex = pS->isComplex();
            std::wostringstream ostr;
            std::vector<std::wstring> vect;


            ostr << "(" << iRows << "," << iCols << ") sparse matrix";

            vect.push_back(ostr.str());
            ostr.str(L"");
            ostr.clear();

            for (int i = 0 ; i < iRows ; i++)
            {
                for (int j = 0 ; j < iCols ; j++)
                {
                    std::wostringstream temp;
                    double real = pS->getReal(i, j);
                    double cplx = 0;
                    if (isComplex)
                    {
                        cplx = pS->getImg(i, j).imag();
                    }

                    if (real || cplx )
                    {
                        temp << L"(" << i + 1 << L"," << j + 1 << L")    ";

                        if (real)
                        {
                            temp << pS->getReal(i, j);
                        }

                        if (cplx)
                        {
                            if (real && cplx > 0)
                            {
                                temp << L"+";
                            }
                            else if (cplx < 0)
                            {
                                temp << L"-";
                            }

                            temp << L"%i*" << std::abs(cplx);
                        }

                        ostr << temp.str();
                        vect.push_back(ostr.str());
                        ostr.str(L"");
                        ostr.clear();
                    }
                }
            }

            types::String* pSt = new types::String((int)vect.size(), 1);
            for (int i = 0 ; i < vect.size(); i++)
            {
                pSt->set(i, vect[i].c_str());
            }

            out.push_back(pSt);
            break;
        }

        case types::InternalType::ScilabInt8 :
        {
            return intString(in[0]->getAs<types::Int8>(), out);
        }
        case types::InternalType::ScilabUInt8 :
        {
            return intString(in[0]->getAs<types::UInt8>(), out);
        }
        case types::InternalType::ScilabInt16 :
        {
            return intString(in[0]->getAs<types::Int16>(), out);
        }
        case types::InternalType::ScilabUInt16 :
        {
            return intString(in[0]->getAs<types::UInt16>(), out);
        }
        case types::InternalType::ScilabInt32 :
        {
            return intString(in[0]->getAs<types::Int32>(), out);
        }
        case types::InternalType::ScilabUInt32 :
        {
            return intString(in[0]->getAs<types::UInt32>(), out);
        }
        case types::InternalType::ScilabInt64 :
        {
            return intString(in[0]->getAs<types::Int64>(), out);
        }
        case types::InternalType::ScilabUInt64 :
        {
            return intString(in[0]->getAs<types::UInt64>(), out);
        }
        case types::InternalType::ScilabDouble :
        {
            return doubleString(in[0]->getAs<types::Double>(), out);
        }
        case types::InternalType::ScilabString :
        {
            out.push_back(in[0]);
            break;
        }
        case types::InternalType::ScilabFunction:
        {
            Scierror(999, _("%s: Wrong type for input argument #%d.\n"), "string", 1);
            return types::Function::Error;
        }
        case types::InternalType::ScilabMacroFile :
        {
            if (_iRetCount != 3)
            {
                Scierror(77, _("%s: Wrong number of output argument(s): %d expected.\n"), "string", 3);
                return types::Function::Error;
            }

            types::MacroFile* pMF = in[0]->getAs<types::MacroFile>();
            types::InternalType* pOut = NULL;
            types::InternalType* pIn = NULL;
            types::InternalType* pBody = NULL;

            getMacroString(pMF->getMacro(), &pOut, &pIn, &pBody);

            out.push_back(pOut);
            out.push_back(pIn);
            out.push_back(pBody);
            break;
        }
        case types::InternalType::ScilabMacro :
        {
            if (_iRetCount != 3)
            {
                Scierror(77, _("%s: Wrong number of output argument(s): %d expected.\n"), "string", 3);
                return types::Function::Error;
            }

            types::Macro* pM = in[0]->getAs<types::Macro>();
            types::InternalType* pOut = NULL;
            types::InternalType* pIn = NULL;
            types::InternalType* pBody = NULL;

            getMacroString(pM, &pOut, &pIn, &pBody);

            out.push_back(pOut);
            out.push_back(pIn);
            out.push_back(pBody);
            break;
        }
        case types::InternalType::ScilabTList :
        case types::InternalType::ScilabMList :
        case types::InternalType::ScilabPolynom :
        {
            std::wstring wstFuncName = L"%" + in[0]->getShortTypeStr() + L"_string";
            return Overload::call(wstFuncName, in, _iRetCount, out);
        }
        case types::InternalType::ScilabBool:
        {
            return booleanString(in[0]->getAs<types::Bool>(), out);
        }
        case types::InternalType::ScilabLibrary:
        {
            types::Library* pL = in[0]->getAs<types::Library>();
            std::wstring path = pL->getPath();
            std::list<std::wstring> macros;
            int size = pL->getMacrosName(macros);
            types::String* pS = new types::String(size + 1, 1);
            pS->set(0, path.c_str());
            int i = 1;
            for (auto it : macros)
            {
                pS->set(i++, it.c_str());
            }

            out.push_back(pS);
            break;
        }
        case types::InternalType::ScilabImplicitList:
        {
            return implicitListString(in[0]->getAs<types::ImplicitList>(), out);
        }
        case types::InternalType::ScilabColon:
        {
            out.push_back(new types::String(L""));
            break;
        }
        default:
        {
            std::wostringstream ostr;
            in[0]->toString(ostr);
            out.push_back(new types::String(ostr.str().c_str()));
            break;
        }
    }
    return types::Function::OK;
}