// CIFfile::Read() int CIFfile::Read(FileName const& fnameIn, int debugIn) { if (file_.OpenFileRead( fnameIn )) return 1; const char* ptr = file_.Line(); mode currentMode = UNKNOWN; while (ptr != 0) { /// There are 3 places we can be; a data block, a looped data block, /// or unknown. if ( currentMode == UNKNOWN ) { // Are we at a data block yet? if (ptr[0] == '_') currentMode = SERIAL; else if ( strncmp(ptr, "loop_", 5) == 0 ) currentMode = LOOP; else ptr = file_.Line(); } else if ( currentMode == SERIAL ) { // SERIAL data block DataBlock serial; while ( ptr != 0 && ptr[0] == '_' ) { serial.AddSerialDataRecord(ptr, file_); ptr = file_.Line(); } if (debugIn > 1) serial.ListData(); currentMode = UNKNOWN; if (AddDataBlock( serial )) return 1; } else if ( currentMode == LOOP ) { DataBlock loop; ptr = file_.Line(); if (ptr == 0 || ptr[0] != '_') return LineError("In CIF file, malformed loop.", file_.LineNumber(), ptr); while (ptr != 0 && ptr[0] == '_') { loop.AddLoopColumn(ptr, file_); ptr = file_.Line(); } // Should now be positioned at loop data if (ptr == 0) return LineError("In CIF file, no loop data.", file_.LineNumber(), ptr); while (ptr != 0 && ptr[0] != '_' && ptr[0] != '#') { loop.AddLoopData(ptr, file_); ptr = file_.Line(); } if (debugIn > 1) loop.ListData(); currentMode = UNKNOWN; if (AddDataBlock( loop )) return 1; } } if (debugIn > 0) mprintf("\tCIF file '%s', %i lines.\n", file_.Filename().full(), file_.LineNumber()); return 0; }
void GRIProcessThread::AddDataBlocks(QList<QString> dataBlockNames) { for (QList<QString>::iterator it = dataBlockNames.begin(); it != dataBlockNames.end(); ++it) { QString name = *it; AddDataBlock(name, is_daq_); } }
// Auth2Certificate::UnpackData // Unpacks member data from raw buffer in base class. Returns true on success and // false on failure. Verifies raw data length, reads memeber data, sets mDatalen. bool Auth2Certificate::UnpackData() { WTRACE("Auth2Certificate::UnpackData"); if (! AuthCertificateBase::UnpackData()) return false; // Get data pointer (skip header data) WDBG_LL("Auth2Certificate::UnpackData Unpack fixed fields."); #ifdef macintosh const unsigned char* #else const unsigned char const* #endif // macintosh aDataPStart = mRawBuf.data(); const unsigned char* aDataP = mRawBuf.data() + mDataLen; int aSize = mRawBuf.size() - mDataLen; unsigned short aDataCount; // unpack count if( aSize < sizeof(aDataCount) ) return false; aDataCount = *(reinterpret_cast<const unsigned short*>(aDataP)); aDataP += sizeof(aDataCount); aSize -= sizeof(aDataCount); while( aDataCount-- ) { // unpack a block, advance the data pointer, and adjust the size CertificateDataBlock *aDataBlock = CertificateDataBlock::UnpackDataBlock( aDataP, aSize ); if( ! aDataBlock ) return false; if(aDataBlock->GetContentType()==CTAuthData) { AuthDataBlk *anAuthData = (AuthDataBlk*)aDataBlock; mUserId = anAuthData->GetUserId(); mPubKey = anAuthData->GetPubKey(); mAccessList = anAuthData->GetAccessList(); mUserName = anAuthData->GetUserName(); } AddDataBlock( aDataBlock ); } mDataLen = aDataP - aDataPStart; // save length of data portion of the buffer. return true; }
/*! \brief Get data blocks (&B) Call LoadData() before this function. \return FALSE on error \return TRUE on success */ int VFKReader::LoadDataBlocks() { char *pszChar; char *pszLine; char *pszBlockName; int nRow; VFKDataBlock *poNewDataBlock; if (m_pszWholeText == NULL) return FALSE; poNewDataBlock = NULL; pszBlockName = NULL; nRow = 0; /* read lines */ pszChar = m_pszWholeText; pszLine = m_pszWholeText; while (*pszChar != '\0') { if (*pszChar == '\r' && *(pszChar+1) == '\n') { nRow++; if (*pszLine == '&' && *(pszLine+1) == 'B') { /* add data block */ pszBlockName = GetDataBlockName(pszLine); if (pszBlockName == NULL) break; poNewDataBlock = new VFKDataBlock(pszBlockName, this); CPLFree(pszBlockName); pszBlockName = NULL; poNewDataBlock->SetGeometryType(); poNewDataBlock->SetProperties(pszLine); AddDataBlock(poNewDataBlock); } else if (*pszLine == '&' && *(pszLine+1) == 'D') { /* data row */ pszBlockName = GetDataBlockName(pszLine); if (pszBlockName == NULL) break; poNewDataBlock = GetDataBlock(pszBlockName); if (poNewDataBlock == NULL) { if (!EQUAL(pszBlockName, "KATUZE")) { /* ignore KATUZE block */ CPLError(CE_Warning, CPLE_AppDefined, "Data block '%s' not found.\n", pszBlockName); } } else poNewDataBlock->AddFeature(pszLine); CPLFree(pszBlockName); pszBlockName = NULL; } else if (*pszLine == '&' && *(pszLine+1) == 'H') { /* header - metadata */ AddInfo(pszLine); } else if (*pszLine == '&' && *(pszLine+1) == 'K') { /* end of file */ break; } pszChar++; pszLine = pszChar + 1; } pszChar++; } return TRUE; }
/// \brief /// Helper function that wraps around AddDataBlock with the string length+1 passed as size. Returns -1 for a NULL string inline int AddString(const char *szString) { if (szString!=NULL) return AddDataBlock(szString,(int)strlen(szString)+1); return -1; }