bool CDecoder::ReadTables(void) { Byte newLevels[kMaxTableSize]; { if (_skipByte) m_InBitStream.DirectReadByte(); m_InBitStream.Normalize(); int blockType = (int)ReadBits(kNumBlockTypeBits); if (blockType > kBlockTypeUncompressed) return false; if (_wimMode) if (ReadBits(1) == 1) m_UnCompressedBlockSize = (1 << 15); else m_UnCompressedBlockSize = ReadBits(16); else m_UnCompressedBlockSize = m_InBitStream.ReadBitsBig(kUncompressedBlockSizeNumBits); m_IsUncompressedBlock = (blockType == kBlockTypeUncompressed); _skipByte = (m_IsUncompressedBlock && ((m_UnCompressedBlockSize & 1) != 0)); if (m_IsUncompressedBlock) { ReadBits(16 - m_InBitStream.GetBitPosition()); if (!m_InBitStream.ReadUInt32(m_RepDistances[0])) return false; m_RepDistances[0]--; for (int i = 1; i < kNumRepDistances; i++) { UInt32 rep = 0; for (int j = 0; j < 4; j++) rep |= (UInt32)m_InBitStream.DirectReadByte() << (8 * j); m_RepDistances[i] = rep - 1; } return true; } m_AlignIsUsed = (blockType == kBlockTypeAligned); if (m_AlignIsUsed) { for(int i = 0; i < kAlignTableSize; i++) newLevels[i] = (Byte)ReadBits(kNumBitsForAlignLevel); RIF(m_AlignDecoder.SetCodeLengths(newLevels)); } } RIF(ReadTable(m_LastMainLevels, newLevels, 256)); RIF(ReadTable(m_LastMainLevels + 256, newLevels + 256, m_NumPosLenSlots)); for (UInt32 i = 256 + m_NumPosLenSlots; i < kMainTableSize; i++) newLevels[i] = 0; RIF(m_MainDecoder.SetCodeLengths(newLevels)); RIF(ReadTable(m_LastLenLevels, newLevels, kNumLenSymbols)); return m_LenDecoder.SetCodeLengths(newLevels); }
int main(int argc, char *argv[]){ if(argc<2){ printf("Specify the file name\n"); exit(-1); } char*table_txt=argv[1]; node*root=Init_tree(); if(root==NULL)printf("Table successfully initialized\n"); ReadTable(&root, table_txt); int option; int hop; char prefix[128]; while(1){ printf("Choose from the following options:\n1: Add Prefix\n2: Delete Prefix\n3: Print Table\n4: Convert Tree to Two Tree\n5: Address Look Up\n6: Exit\n\n"); bzero(prefix, 128); if(scanf("%d",&option)==1)printf("deu\n"); if(option==1){ printf("\nPlease specify the prefix and next hop to add.\n"); fscanf(stdin,"%s %d", prefix, &hop); AddPrefix(&root, prefix, hop); printf("\nAdded the prefix: %s with next hop: %d\n",prefix, hop); } if(option==2){ printf("\nPlease specify the prefix to delete.\n"); fscanf(stdin,"%s", prefix); printf("\n%s\t%d\n",prefix, hop); DeletePrefix(&root, prefix); printf("\nDeleted the prefix: %s\n",prefix); } if(option==3){ PrintTable(root); printf("\nTable successfully printed\n"); } if(option==4){ convert_tree(&root, root->next_hop); printf("\nTable successfully converted\n"); } if(option==5){ printf("\nPlease specify the prefix to scan.\n"); fscanf(stdin,"%s", prefix); int result=AddressLookUp(root, prefix); printf("\nNext hop is: %d\n", result); } if(option==6){ printf("The program will now exit.\n"); exit(1); } } exit(0); }
bool GlueFile::OpenGlueFile(const std::string gluefilename, bool read) { AMJU_CALL_STACK; if (!SimpleOpen(gluefilename, read)) { return false; } return ReadTable(); }
bool CG3DBinaryLoader::InitFile(const char* filename) { m_CurrFile = new BinaryFile(filename); OpenFile(m_CurrFile, 0); if (!m_CurrFP->IsLoaded()) return Error("Cannot find file"); if (m_CurrFP->m_Ident == IDENT('W','D','3','G')) return Error("This platform is big endian, contact the developers!"); else if (m_CurrFP->m_Ident != IDENT('G','3','D','W')) return Error("File does not have the correct header"); m_CurrFile->m_Header.m_Version = m_CurrFP->ReadUInt16(); m_CurrFile->m_Header.m_Num = m_CurrFP->ReadUInt16(); m_CurrFile->m_Header.m_Table = m_CurrFP->ReadUInt32(); m_CurrFile->m_Header.m_Import = m_CurrFP->ReadUInt32(); m_CurrFile->m_Header.m_Reloc = m_CurrFP->ReadUInt32(); if (m_CurrFile->m_Header.m_Import != 0) if (!ReadImport()) return false; OpenFile(m_CurrFile, m_CurrFile->m_Header.m_Table); for (int i=0; i<m_CurrFile->m_Header.m_Num; i++) { if (!ReadTable()) return false; if (!NextFile()) return Error("failed to find all tables"); } CloseFile(); m_CurrFile->Release(); return true; }
CMassCalibDoc::CMassCalibDoc() { ReadTable(); }
int ILI1Reader::ReadFeatures() { char **tokens = NULL; const char *firsttok = NULL; const char *pszLine; char *topic = NULL; int ret = TRUE; while (ret && (tokens = ReadParseLine())) { firsttok = tokens[0]; if (EQUAL(firsttok, "SCNT")) { //read description do { pszLine = CPLReadLine( fpItf ); } while (pszLine && !EQUALN(pszLine, "////", 4)); ret = (pszLine != NULL); } else if (EQUAL(firsttok, "MOTR")) { //read model do { pszLine = CPLReadLine( fpItf ); } while (pszLine && !EQUALN(pszLine, "////", 4)); ret = (pszLine != NULL); } else if (EQUAL(firsttok, "MTID")) { } else if (EQUAL(firsttok, "MODL")) { } else if (EQUAL(firsttok, "TOPI")) { CPLFree(topic); topic = CPLStrdup(CSLGetField(tokens, 1)); } else if (EQUAL(firsttok, "TABL")) { CPLDebug( "OGR_ILI", "Reading table '%s'", GetLayerNameString(topic, CSLGetField(tokens, 1)) ); const char *layername = GetLayerNameString(topic, CSLGetField(tokens, 1)); curLayer = GetLayerByName(layername); int multiple = HasMultiplePointGeom(layername); // create only a new layer if there is no curLayer AND // if there are more than one point geometry columns if (curLayer == NULL && multiple < 1) { //create one CPLDebug( "OGR_ILI", "No model found, using default field names." ); OGRSpatialReference *poSRSIn = NULL; int bWriterIn = 0; OGRwkbGeometryType eReqType = wkbUnknown; OGRILI1DataSource *poDSIn = NULL; curLayer = new OGRILI1Layer(GetLayerNameString(topic, CSLGetField(tokens, 1)), poSRSIn, bWriterIn, eReqType, poDSIn); AddLayer(curLayer); } if(curLayer != NULL) { for (int i=0; i < curLayer->GetLayerDefn()->GetFieldCount(); i++) { CPLDebug( "OGR_ILI", "Field %d: %s", i, curLayer->GetLayerDefn()->GetFieldDefn(i)->GetNameRef()); } } ret = ReadTable(layername); } else if (EQUAL(firsttok, "ETOP")) { } else if (EQUAL(firsttok, "EMOD")) { } else if (EQUAL(firsttok, "ENDE")) { CSLDestroy(tokens); CPLFree(topic); return TRUE; } else { CPLDebug( "OGR_ILI", "Unexpected token: %s", firsttok ); } CSLDestroy(tokens); tokens = NULL; } CSLDestroy(tokens); CPLFree(topic); return ret; }
int ILI1Reader::ReadFeatures() { char **tokens = NULL; const char *pszLine = NULL; char *topic = CPLStrdup("(null)"); int ret = TRUE; while (ret && (tokens = ReadParseLine()) != NULL) { const char *firsttok = tokens[0]; if (EQUAL(firsttok, "SCNT")) { //read description do { pszLine = CPLReadLine( fpItf ); } while (pszLine && !STARTS_WITH_CI(pszLine, "////")); ret = (pszLine != NULL); } else if (EQUAL(firsttok, "MOTR")) { //read model do { pszLine = CPLReadLine( fpItf ); } while (pszLine && !STARTS_WITH_CI(pszLine, "////")); ret = (pszLine != NULL); } else if (EQUAL(firsttok, "MTID")) { } else if (EQUAL(firsttok, "MODL")) { } else if (EQUAL(firsttok, "TOPI") && CSLCount(tokens) >= 2) { CPLFree(topic); topic = CPLStrdup(CSLGetField(tokens, 1)); } else if (EQUAL(firsttok, "TABL") && CSLCount(tokens) >= 2) { const char *layername = GetLayerNameString(topic, CSLGetField(tokens, 1)); CPLDebug( "OGR_ILI", "Reading table '%s'", layername ); curLayer = GetLayerByName(layername); if (curLayer == NULL) { //create one CPLError( CE_Warning, CPLE_AppDefined, "No model definition for table '%s' found, " "using default field names.", layername ); OGRFeatureDefn* poFeatureDefn = new OGRFeatureDefn( GetLayerNameString(topic, CSLGetField(tokens, 1))); poFeatureDefn->SetGeomType( wkbUnknown ); GeomFieldInfos oGeomFieldInfos; curLayer = new OGRILI1Layer(poFeatureDefn, oGeomFieldInfos, NULL); AddLayer(curLayer); } if(curLayer != NULL) { for (int i=0; i < curLayer->GetLayerDefn()->GetFieldCount(); i++) { CPLDebug( "OGR_ILI", "Field %d: %s", i, curLayer->GetLayerDefn()->GetFieldDefn(i)->GetNameRef()); } } ret = ReadTable(layername); } else if (EQUAL(firsttok, "ETOP")) { } else if (EQUAL(firsttok, "EMOD")) { } else if (EQUAL(firsttok, "ENDE")) { CSLDestroy(tokens); CPLFree(topic); return TRUE; } else { CPLError( CE_Warning, CPLE_AppDefined, "Unexpected token: %s", firsttok ); } CSLDestroy(tokens); tokens = NULL; } CSLDestroy(tokens); CPLFree(topic); return ret; }
void IO_UncertSimResults::ReadTableArray(DC_TableArray& tableArray) { tableArray.AllocAndSetSize(ReadInt()); for (int i = 0; i < tableArray.Size(); i++) ReadTable(tableArray[i]); }
/*---------------------------------------------------------------------------------------------- Call after object constructed. Does most of the real initialization of the object such as reading the needed TTF tables and scanning the cmap for collisions. Needed so an error code can be returned. Must be called ONLY once BEFORE any other methods are called. Returns 0 if successful. Otherwise non-zero (see below for error numbers) ----------------------------------------------------------------------------------------------*/ int GrcFont::Init(GrcManager * pcman) { Assert(!m_fDebug); Assert(m_pFile == NULL); // should only call once if (!OpenFile()) // open the TTF file passed in the ctor { g_errorList.AddError(107, NULL, "Could not open font file"); return 1; } // read the offset table long lnOffset, lnSize; byte * pHdr, * pTableDir; if (!TtfUtil::GetHeaderInfo(lnOffset, lnSize)) return 2; if (!ReadData(&pHdr, lnOffset, lnSize)) { g_errorList.AddError(108, NULL, "Error reading font offset table."); return 3; } if (!TtfUtil::CheckHeader(pHdr)) { g_errorList.AddError(109, NULL, "Font file has bad offset table"); return 4; } if (!TtfUtil::GetTableDirInfo(pHdr, lnOffset, lnSize)) return 5; if (!ReadData(&pTableDir, lnOffset, lnSize)) { g_errorList.AddError(110, NULL, "Error reading font Table Directory."); return 6; } if (IsGraphiteFont(pHdr, pTableDir)) { g_errorList.AddError(111, NULL, "Font already has Graphite table(s) present."); return 7; } // cmap if (!ReadTable(ktiCmap, pHdr, pTableDir, &m_pCmap, &m_cCmap)) return 10; // Find cmap subtable we need. // Start with UTF-32 table platform 3 encoding 10 m_pCmap_3_10 = TtfUtil::FindCmapSubtable(m_pCmap, 3, 10); // Regardless, we should also have a UTF-16 table. First try platform 3 encoding 1. m_pCmap_3_1 = TtfUtil::FindCmapSubtable(m_pCmap, 3, 1); if (m_pCmap_3_1 == NULL) { // try the platform 3 encoding 0 table instead m_pCmap_3_1 = TtfUtil::FindCmapSubtable(m_pCmap, 3, 0); } if (m_pCmap_3_10 == NULL && m_pCmap_3_1 == NULL) { g_errorList.AddError(112, NULL, "Microsoft Unicode cmap could not be found."); return 11; } if (m_pCmap_3_10) { if (!TtfUtil::CheckCmap310Subtable(m_pCmap_3_10)) { g_errorList.AddError(113, NULL, "cmap platform 3 encoding 10 subtable is invalid."); return 12; } } if (m_pCmap_3_1) { if (!TtfUtil::CheckCmap31Subtable(m_pCmap_3_1)) { if (m_pCmap_3_10) // we can survive g_errorList.AddWarning(506, NULL, "cmap platform 3 encoding 1 subtable is invalid."); else g_errorList.AddError(114, NULL, "cmap platform 3 encoding 1 subtable is invalid."); return 13; } } else if (m_pCmap_3_10) { // All fonts are supposed to have a 16-bit table. g_errorList.AddWarning(507, NULL, "cmap platform 3 encoding 1 subtable not found"); } // glyf if (!ReadTable(ktiGlyf, pHdr, pTableDir, &m_pGlyf, &m_cGlyf)) return 20; // head if (!ReadTable(ktiHead, pHdr, pTableDir, &m_pHead, &m_cHead)) return 21; // hhea if (!ReadTable(ktiHhea, pHdr, pTableDir, &m_pHhea, &m_cHhea)) return 2; // hmtx if (!ReadTable(ktiHmtx, pHdr, pTableDir, &m_pHmtx, &m_cHmtx)) return 23; // loca if (!ReadTable(ktiLoca, pHdr, pTableDir, &m_pLoca, &m_cLoca)) return 24; // maxp if (!ReadTable(ktiMaxp, pHdr, pTableDir, &m_pMaxp, &m_cMaxp)) return 25; // OS/2 if (!ReadTable(ktiOs2, pHdr, pTableDir, &m_pOs2, &m_cOs2)) return 26; // post if (!ReadTable(ktiPost, pHdr, pTableDir, &m_pPost, &m_cPost)) return 27; // name if (!ReadTable(ktiName, pHdr, pTableDir, &m_pName, &m_cName)) return 28; delete [] pTableDir; delete [] pHdr; // scan the cmap for colliding Unicode values & find largest glyph id if (!ScanGlyfIds()) return 30; if (AnySupplementaryPlaneChars() && pcman->FontTableVersion() <= 0x00010000) { g_errorList.AddError(115, NULL, "Supplementary plane characters are not supported in version 1.0"); } return 0; }