From: David ‘Bombe’ Roden Date: Sun, 6 Jul 2008 09:50:48 +0000 (+0200) Subject: parse header only on first link X-Git-Tag: 0.1~7 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=88a6c6019c9364a9cf0df4af1760b3be44b9052e;p=ecparse.git parse header only on first link --- diff --git a/CollectionReader.cpp b/CollectionReader.cpp index 2f4a3cd..e33d6b8 100644 --- a/CollectionReader.cpp +++ b/CollectionReader.cpp @@ -4,7 +4,6 @@ #include #include -#include #include "CollectionReader.h" #include "GlobalSettings.h" @@ -95,7 +94,6 @@ ED2KLink* CollectionReader::getNextLink() { GlobalSettings::isVerbose() && fprintf(stderr, "[%s:%d] readInput EOF reached.\n", __FILE__, __LINE__); return NULL; } - firstLink = false; } if (isTextCollection) { while (!readerInput->isEOF() && !isLineBreakPresent()) { @@ -128,7 +126,8 @@ ED2KLink* CollectionReader::getNextLink() { ED2KLink* ed2kLink = ED2KLink::parseED2KLink(line); free(line); return ed2kLink; - } else { + } + if (firstLink) { /* read header */ if (!ensureBufferCapacity(4)) { return NULL; @@ -163,6 +162,18 @@ ED2KLink* CollectionReader::getNextLink() { GlobalSettings::isVerbose() && fprintf(stderr, "[%s:%d] unknown tag type: %02x.\n", __FILE__, __LINE__, tagType); } } + fileCollectionCount = 0; + if (!ensureBufferCapacity(4)) { + return NULL; + } + growingBuffer.read(&fileCollectionCount, 4); + GlobalSettings::isVerbose() && fprintf(stderr, "[%s:%d] will read %d file tags.\n", __FILE__, __LINE__, fileCollectionCount); + collectionFileIndex = 0; + firstLink = false; + } + if (collectionFileIndex < fileCollectionCount) { + } else { + GlobalSettings::isVerbose() && fprintf(stderr, "[%s:%d] reached end of collection.\n", __FILE__, __LINE__); } return NULL; } @@ -188,7 +199,6 @@ void CollectionReader::readMoreBytes() { } void CollectionReader::identifyCollectionType() { - int version; size_t readBytes; readBytes = readerInput->read(&version, 4); @@ -206,6 +216,7 @@ void CollectionReader::identifyCollectionType() { } else if (!strncmp("ed2k", (char*) &version, 4)) { isTextCollection = true; growingBuffer.write(&version, 4); + version = 0; GlobalSettings::isVerbose() && fprintf(stderr, "[%s:%d] identified text collection\n", __FILE__, __LINE__); } else { GlobalSettings::isVerbose() && fprintf(stderr, "[%s:%d] could not identify collection!\n", __FILE__, __LINE__); diff --git a/CollectionReader.h b/CollectionReader.h index 6e8f373..770c2a8 100644 --- a/CollectionReader.h +++ b/CollectionReader.h @@ -4,6 +4,7 @@ #pragma once +#include #include "ReaderInput.h" #include "ED2KLink.h" #include "GrowingBuffer.h" @@ -30,9 +31,11 @@ private: private: ReaderInput* readerInput; GrowingBuffer growingBuffer; - int version; + uint32_t version; bool firstLink; bool isTextCollection; + uint32_t fileCollectionCount; + uint32_t collectionFileIndex; };