Exemplo n.º 1
0
/**********************************************************************
 *                          AVCRawBinEOF()
 *
 * Return TRUE if there is no more data to read from the file or
 * FALSE otherwise.
 **********************************************************************/
GBool AVCRawBinEOF(AVCRawBinFile *psFile)
{
    if (psFile == NULL || psFile->fp == NULL)
        return TRUE;

    /* In write access mode, always return TRUE, since we always write
     * at EOF for now.
     */
    if (psFile->eAccess != AVCRead && psFile->eAccess != AVCReadWrite)
        return TRUE;

    /* If file data size was specified, then check that we have not
     * passed that point yet...
     */
    if (psFile->nFileDataSize > 0 &&
        (psFile->nOffset+psFile->nCurPos) >= psFile->nFileDataSize)
        return TRUE;

    /* If the file pointer has been moved by AVCRawBinFSeek(), then
     * we may be at a position past EOF, but VSIFeof() would still
     * return FALSE. It also returns false if we have read just up to
     * the end of the file. EOF marker would not have been set unless
     * we try to read past that.
     *
     * To prevent this situation, if the memory buffer is empty,
     * we will try to read 1 byte from the file to force the next
     * chunk of data to be loaded (and we'll move the read pointer
     * back by 1 char after of course!).
     * If we are at the end of the file, this will trigger the EOF flag.
     */
    if ((psFile->nCurPos == 0 && psFile->nCurSize == 0) ||
        (psFile->nCurPos == AVCRAWBIN_READBUFSIZE &&
         psFile->nCurSize == AVCRAWBIN_READBUFSIZE))
    {
        GByte c;
        /* Set bDisableReadBytesEOFError=TRUE to temporarily disable
         * the EOF error message from AVCRawBinReadBytes().
         */
        bDisableReadBytesEOFError = TRUE;
        AVCRawBinReadBytes(psFile, 1, &c);
        bDisableReadBytesEOFError = FALSE;

        if (psFile->nCurPos > 0)
            AVCRawBinFSeek(psFile, -1, SEEK_CUR);
    }

    return (psFile->nCurPos == psFile->nCurSize &&
            VSIFEof(psFile->fp));
}
Exemplo n.º 2
0
/*
It returns the table names and something more:
- Arc file
- Number of fields
- Register Size
- Number of registers
- External/Internal Table Identifier
*/
SEXP get_table_names(SEXP directory)
{
	SEXP *table, aux;
	AVCRawBinFile *arcfile;
	AVCTableDef tabledefaux;
	char arcdir[PATH], *dirname;
	int i,n, **idata;

	dirname= (char *) CHAR(STRING_ELT(directory,0));/*FIXME*/
	strcpy(arcdir,dirname);

	complete_path(arcdir,"arc.dir", 0);

	if(!(arcfile=AVCRawBinOpen(arcdir,"r")))
	{
		error("Error opening arc.dir");
	}

	n=0;
	while(!AVCRawBinEOF(arcfile))
	{
		if(!_AVCBinReadNextArcDir(arcfile, &tabledefaux))
			n++;
	}

	AVCRawBinFSeek(arcfile, 0,SEEK_SET);

	table=calloc(6, sizeof(SEXP));

	PROTECT(table[0]=NEW_STRING(n));
	PROTECT(table[1]=NEW_STRING(n));

	idata=calloc(4, sizeof(char *));
	PROTECT(table[2]=NEW_INTEGER(n));
	idata[0]=INTEGER(table[2]);
	PROTECT(table[3]=NEW_INTEGER(n));
	idata[1]=INTEGER(table[3]);
	PROTECT(table[4]=NEW_INTEGER(n));
	idata[2]=INTEGER(table[4]);
	PROTECT(table[5]=NEW_LOGICAL(n));
	idata[3]=LOGICAL(table[5]);


	i=0;
	while(!AVCRawBinEOF(arcfile))
	{
		if(_AVCBinReadNextArcDir(arcfile, &tabledefaux))
			break;


		SET_STRING_ELT(table[0],i,COPY_TO_USER_STRING(tabledefaux.szTableName));
		SET_STRING_ELT(table[1],i,COPY_TO_USER_STRING(tabledefaux.szInfoFile));

		idata[0][i]=tabledefaux.numFields;
		idata[1][i]=tabledefaux.nRecSize;
		idata[2][i]=tabledefaux.numRecords;
		if(!strcmp(tabledefaux.szExternal,"XX"))
			idata[3][i]=1;
		else
			idata[3][i]=0;

		i++;
	}

	PROTECT(aux=NEW_LIST(6));

	for(i=0;i<6;i++)
		SET_VECTOR_ELT(aux,i,table[i]);

	UNPROTECT(7);

	free(table);
	free(idata);

	return aux;
}