Esempio n. 1
0
void UCIParser<NumType, LabelType>::ParseInit(LPCWSTR/*TODO: change to C++ type*/ fileName, size_t startFeatures, size_t dimFeatures, size_t startLabels, size_t dimLabels, size_t bufferSize, size_t startPosition)
{
    assert(fileName != NULL);
    m_startLabels = startLabels;
    m_dimLabels = dimLabels;
    m_startFeatures = startFeatures;
    m_dimFeatures = dimFeatures;
    m_parseMode = ParseNormal;
    m_traceLevel = 0;
    m_bufferSize = bufferSize;
    m_bufferStart = startPosition;

    // if we have a file already open, cleanup
    if (m_pFile != NULL)
        UCIParser<NumType, LabelType>::~UCIParser();

    errno_t err = _wfopen_s(&m_pFile, fileName, L"rb");
    if (err)
        RuntimeError("UCIParser::ParseInit - error opening file %ls", fileName);
    int rc = _fseeki64(m_pFile, 0, SEEK_END);
    if (rc)
        RuntimeError("UCIParser::ParseInit - error seeking in file %ls", fileName);

    m_fileSize = GetFilePosition();
    m_fileBuffer = new BYTE[m_bufferSize];
    SetFilePosition(startPosition);
}
int AG_GetFileFormat( filehandle refNum, int *fileFormat )
{
    *fileFormat = 0;

    // Read the file header
    int posn = 0;
    int result = SetFilePosition( refNum, posn );		// Position the mark at start
    if ( result )
        return result;

    // Read the 4-byte prefix present in all AxoGraph file formats
    unsigned char AxoGraphFileID[4];
    AXGLONG bytes = 4;	// 4 byte identifier
    result = ReadFromFile( refNum, &bytes, AxoGraphFileID );
    if ( result )
        return result;

    // Check the prefix
    if ( memcmp( AxoGraphFileID, kAxoGraph4DocType, 4 ) == 0 )
    {
        // Got an AxoGraph version 4 format file. Read the file type.
        short version;
        bytes = sizeof( short );
        result = ReadFromFile( refNum, &bytes, &version );
        if ( result )
            return result;

#ifdef __LITTLE_ENDIAN__
        ByteSwapShort( &version );
#endif

        if ( version != kAxoGraph_Graph_Format &&
             version != kAxoGraph_Digitized_Format  )
            return kAG_VersionErr;

        // Return the file format
        *fileFormat = version;
    }
    else if ( memcmp( AxoGraphFileID, kAxoGraphXDocType, 4 ) == 0 )
    {
        // Got an AxoGraph X format file. Check the file version.
        AXGLONG version = 0;
        bytes = sizeof( AXGLONG );
        result = ReadFromFile( refNum, &bytes, &version );
        if ( result )
            return result;

#ifdef __LITTLE_ENDIAN__
        ByteSwapLong( &version );
#endif

        if ( version < 3 || version > kAxoGraph_X_Format )
        {
            return kAG_VersionErr;
        }

        // update to latest version number
        version = kAxoGraph_X_Format;

        // Return the file format
        *fileFormat = version;
    }
    else
    {
        result = kAG_FormatErr;
    }

    // pass back the result ( = 0 if all went well)
    return result;
}
Esempio n. 3
0
/**
Reads a directory entry from the specified position in the core image file.
This method moves the position of the file to the specified value and then
uses the other ReadDirEntry method to read the directory entry

@param aDir memory where the directory entry is read from the file. This is only valid if KErrNone is returned.
@param aFilePos position in the core image file where the directory
entry is located
@return KErrNone for successful read or error number if failed 
@see RCoreImageReader::ReadDirEntry(TRofsDir* aDir)
*/
TInt RCoreImageReader::ReadDirEntry(TRofsDir& aDir, long aFilePos)
	{
	SetFilePosition(aFilePos);
	return ReadDirEntry(aDir);
	}