Beispiel #1
0
void C2F(mclose) (int *fd, double *res)
{
    int fd1 = -1;
    *res = 0.0;

    switch (*fd)
    {
        case ALL_FILES_DESCRIPTOR :
        {
            /* closing all opened files */
            mcloseAll();
        }
        break;
        default :
        {
            if (mclose(*fd))
            {
                *res = -1.0;
            }
        }
    }
}
Beispiel #2
0
types::Function::ReturnValue sci_mclose(types::typed_list &in, int _iRetCount, types::typed_list &out)
{
    int iRet = 0;
    if (in.size() == 0)
    {
        //close current file
        iRet = mcloseCurrentFile();
    }
    else if (in.size() == 1)
    {
        if (in[0]->isString())
        {
            types::String *pS = in[0]->getAs<types::String>();
            if (pS->getSize() != 1)
            {
                Scierror(999, _("%s: Wrong type for input argument #%d: A String expected.\n"), "mclose", 1);
                return types::Function::Error;
            }

            if (FileManager::isOpened(pS->get(0)))
            {
                int iFileID = FileManager::getFileID(pS->get(0));
                if (iFileID == -1)
                {
                    char* pst = wide_string_to_UTF8(pS->get(0));
                    Scierror(999, _("%s: File not found: '%s'.\n"), "mclose", pst);
                    FREE(pst);
                    return types::Function::Error;
                }
                iRet = mclose(iFileID);
            }
            else if (os_wcsicmp(pS->get(0), L"all") == 0)
            {
                iRet = mcloseAll();
            }
            else
            {
                Scierror(999, _("%s: Wrong input arguments: '%s' expected.\n"), "mclose", "all");
                return types::Function::Error;
            }
        }
        else if (in[0]->isDouble())
        {
            types::Double* pD = in[0]->getAs<types::Double>();
            if (pD->getSize() != 1 || pD->isComplex())
            {
                Scierror(999, _("%s: Wrong type for input argument #%d: A real expected.\n"), "mclose", 1);
                return types::Function::Error;
            }

            int iVal = static_cast<int>(pD->get(0));
            switch (iVal)
            {
                case 0: // stderr
                case 5: // stdin
                case 6: // stdout
                    Scierror(999, _("%s: Wrong file descriptor: %d.\n"), "mclose", iVal);
                    return types::Function::Error;
            }
            iRet = mclose(iVal);
        }
        else
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: A integer or string expected.\n"), "mclose", 1);
            return types::Function::Error;
        }
    }
    else
    {
        Scierror(999, _("%s: Wrong number of input arguments: %d or %d expected.\n"), "mclose", 0, 1);
        return types::Function::Error;
    }

    types::Double* pD = new types::Double(static_cast<double>(iRet));
    out.push_back(pD);
    return types::Function::OK;
}