/*--------------------------------------------------------------------------*/
int *GetTypesUsed(int *sizeArrayReturned)
{
    int *ArrayTypeUsed = NULL;
    int i = 0, j = 0;

    *sizeArrayReturned = GetNumberOfIdsUsed();

    ArrayTypeUsed = (int*)MALLOC(sizeof(int)*(*sizeArrayReturned));
    if (ArrayTypeUsed == NULL)
    {
        *sizeArrayReturned = 0;
        return NULL;
    }

    j = 0;
    for (i = 0; i < GetMaximumFileOpenedInScilab(); i++)
    {
        if (GetFileTypeOpenedInScilab(i) != 0)
        {
            ArrayTypeUsed[j] = GetFileTypeOpenedInScilab(i);
            j++;
        }
    }
    return ArrayTypeUsed;
}
/*--------------------------------------------------------------------------*/
int GetSwapStatus(int Id)
{
    int fd1;
    fd1 = (Id != -1) ?  Min(Max(Id,0),GetMaximumFileOpenedInScilab()-1) : GetCurrentFileId() ;
    if ( fd1 != -1 ) return(ScilabFileList[fd1].ftswap);
    return(0);
}
/*--------------------------------------------------------------------------*/
double *GetSwapsUsed(int *sizeArrayReturned)
{
    double *ArraySwapUsed = NULL;
    int i = 0, j = 0;

    *sizeArrayReturned = GetNumberOfIdsUsed();

    ArraySwapUsed = (double*)MALLOC(sizeof(double)*(*sizeArrayReturned));
    if (ArraySwapUsed == NULL)
    {
        *sizeArrayReturned = 0;
        return NULL;
    }

    j = 0;
    for (i = 0; i < GetMaximumFileOpenedInScilab(); i++)
    {
        if (GetFileTypeOpenedInScilab(i) != 0)
        {
            ArraySwapUsed[j] = (double)GetSwapStatus(i);
            j++;
        }
    }
    return ArraySwapUsed;
}
/*--------------------------------------------------------------------------*/
void C2F(getfileinfo)(int *fd, FILE *fa, int *swap2, int *type, int *mode, char *filename, int *lf, int *ierr)
{
	char *filenamefromfd = NULL;
	if (*fd<0 || *fd>=GetMaximumFileOpenedInScilab() ) 
	{
		*ierr=1;
		return;
	}
	if ( GetFileTypeOpenedInScilab(*fd) == 0 ) 
	{
		*ierr=2;
		return;
	}
	fa = GetFileOpenedInScilab(*fd);

	*swap2 = GetSwapStatus(*fd);
	*type = GetFileTypeOpenedInScilab(*fd);
	*mode = GetFileModeOpenedInScilab(*fd);
	filenamefromfd = GetFileNameOpenedInScilab(*fd);
	if (filenamefromfd) strcpy(filename,GetFileNameOpenedInScilab(*fd));
	else strcpy(filename,"");

	*lf=(int)strlen(filename);
	*ierr=0;
}
/*--------------------------------------------------------------------------*/
int GetFileTypeOpenedInScilab(int Id)
{
    if ( (Id > 0) && (Id < GetMaximumFileOpenedInScilab()) )
    {
        return ScilabFileList[Id].fttype;
    }
    else
    {
        return 0;
    }
}
/*--------------------------------------------------------------------------*/
FILE *GetFileOpenedInScilab(int Id)
{
    int fd1 = 0;

    fd1 = (Id != -1) ?  Min(Max(Id,0),GetMaximumFileOpenedInScilab()-1) : CurFile ;

    if ( fd1 != -1 )
    {
        return  ScilabFileList[fd1].ftformat;
    }
    return NULL;
}
/*--------------------------------------------------------------------------*/
int GetNumberOfIdsUsed(void)
{
    int i = 0;
    int numberOfIds = 0;

    for (i = 0; i < GetMaximumFileOpenedInScilab(); i++)
    {
        if (GetFileTypeOpenedInScilab(i) != 0)
        {
            numberOfIds++;
        }
    }
    return numberOfIds;
}
Exemple #8
0
/*--------------------------------------------------------------------------*/
void C2F(getfiletype)(int *fd, int *type, int *ierr)
{
	if (*fd<0 || *fd>=GetMaximumFileOpenedInScilab() ) 
	{
		*ierr=1;
		return;
	}
	if ( GetFileTypeOpenedInScilab(*fd) == 0 ) 
	{
		*ierr=2;
		return;
	}
	*type = GetFileTypeOpenedInScilab(*fd);
	*ierr=0;
}
Exemple #9
0
/*--------------------------------------------------------------------------*/
void C2F(mclose) (int *fd, double *res)
{
    int fd1 = -1;
    *res = 0.0;

    switch ( *fd )
    {
        case ALL_FILES_DESCRIPTOR :
            /* closing all opened files */
            for ( fd1 = 0; fd1 < GetMaximumFileOpenedInScilab(); fd1++)
            {
                FILE* stream = GetFileOpenedInScilab(fd1) ;
                if ( stream )
                {
                    int res1 = 1;
                    res1 = fclose( stream );
                    // this function previously called ferror on a just before fclosed FILE* that could lead to crash at exit, depending on libc implementation.
                    if (res1 != 0)
                    {
                        *res = 1;
                    }
                    C2F(delfile)(&fd1);
                    /* bug 3897 */
                    /* initialize file ID */
                    SetCurrentFileId(-1);
                }
            }
            break;

        default :
        {
            fd1 = (*fd == -1 ) ? GetCurrentFileId() : Min(Max(*fd, 0), GetMaximumFileOpenedInScilab() - 1);
            if ( fd1 != -1 )
            {
                if ( GetFileOpenedInScilab(fd1) )
                {
                    int prevId = -1;

                    if (fclose(GetFileOpenedInScilab(fd1)))
                    {
                        *res = (double)ferror(GetFileOpenedInScilab(fd1));
                    }
                    C2F(delfile)(&fd1);

                    /* bug 3897 */
                    /* set as current file previous opened file if exists */
                    prevId = GetPreviousFileId();

                    if ( GetFileOpenedInScilab(prevId) )
                    {
                        SetCurrentFileId(prevId);
                    }
                }
                else
                {
                    *res = 0.0;
                    if (getWarningMode())
                    {
                        sciprint(_("%s: Cannot close file whose descriptor is %d: File is not active.\n"), "mclose", fd1);
                    }
                }
            }
            else
            {
                *res = -1.0;
                if (getWarningMode())
                {
                    sciprint(_("%s: Cannot close file whose descriptor is %d: No file to close.\n"), "mclose", fd1);
                }
            }
        }
    }
}