diff options
| author | Markus Mittendrein <git@maxmitti.tk> | 2019-03-15 17:28:57 +0100 |
|---|---|---|
| committer | Markus Mittendrein <git@maxmitti.tk> | 2019-03-15 17:28:57 +0100 |
| commit | b627615a50df6fdbf9bf574f600a5f2b6cc8eb8d (patch) | |
| tree | 71f3bac650bd0ba45cf51df3784fb6aba3873b0c /src | |
| parent | 4f04d45a0eebe2618e88163d6a8765d180d7c866 (diff) | |
| download | cc4group-b627615a50df6fdbf9bf574f600a5f2b6cc8eb8d.tar.gz cc4group-b627615a50df6fdbf9bf574f600a5f2b6cc8eb8d.zip | |
Refactoring for upcoming lazy mode
Diffstat (limited to 'src')
| -rw-r--r-- | src/cc4group.c | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/src/cc4group.c b/src/cc4group.c index dd926f3..29fe0d5 100644 --- a/src/cc4group.c +++ b/src/cc4group.c @@ -99,6 +99,7 @@ typedef enum { } CC4Group_MemoryManagement; +static const uint8_t* cc4group_getOnlyEntryData(CC4Group* const this, const C4GroupEntryData* entry); static const C4GroupEntryData* cc4group_getEntryByPath(const CC4Group* const this, const char* const entryPath); static const C4GroupEntryData* cc4group_getDirectoryByPath(CC4Group* const this, const char* const entryPath); static const C4GroupEntryData* cc4group_getFileByPath(CC4Group* const this, const char* const entryPath); @@ -825,7 +826,7 @@ static bool cc4group_extractEntry(CC4Group* const this, const C4GroupEntryData* SET_ERRNO_ERROR("open: Creating target file"); return false; } - write(file, root->data, root->core.Size); + write(file, cc4group_getOnlyEntryData(this, root), root->core.Size); if(close(file) == -1) { @@ -933,6 +934,7 @@ static const C4GroupEntryData* cc4group_getEntryByPath(const CC4Group* const thi break; } + // TODO: lazy bool found = false; ForeachGroupEntry(currentParent->children) { @@ -1025,6 +1027,14 @@ static bool cc4group_extractSingle(CC4Group* const this, const char* const entry return cc4group_extractChildren(this, entry, targetPath); } +static const uint8_t* cc4group_getOnlyEntryData(CC4Group* const this, const C4GroupEntryData* entry) +{ + // TODO: lazy + (void)this; + + return entry->data; +} + static bool cc4group_getEntryData(CC4Group* const this, const char* const entryPath, const void** const data, size_t* size) { assert(this); @@ -1038,7 +1048,7 @@ static bool cc4group_getEntryData(CC4Group* const this, const char* const entryP return false; } - *data = entry->data; + *data = cc4group_getOnlyEntryData(this, entry); *size = entry->core.Size; return true; } @@ -1100,14 +1110,14 @@ static size_t cc4group_calculateEntrySizes(C4GroupEntryData* const entryData) } } -static void cc4group_calculateEntryCRC(C4GroupEntryData* const groupEntry) +static void cc4group_calculateEntryCRC(CC4Group* const this, C4GroupEntryData* const groupEntry) { if(groupEntry->core.Directory) { uint32_t crc = 0; ForeachGroupEntry(groupEntry->children) { - cc4group_calculateEntryCRC(&entry->value); + cc4group_calculateEntryCRC(this, &entry->value); crc ^= entry->value.core.CRC; } groupEntry->core.HasCRC = C4GroupEntryCore_ContentsFileNameCRC; @@ -1115,7 +1125,7 @@ static void cc4group_calculateEntryCRC(C4GroupEntryData* const groupEntry) } else if(groupEntry->core.HasCRC != C4GroupEntryCore_ContentsFileNameCRC) { - uint32_t crc = crc32(0, groupEntry->data, groupEntry->core.Size); + uint32_t crc = crc32(0, cc4group_getOnlyEntryData(this, groupEntry), groupEntry->core.Size); crc = crc32(crc, (uint8_t*)groupEntry->core.FileName, strlen(groupEntry->core.FileName)); groupEntry->core.HasCRC = C4GroupEntryCore_ContentsFileNameCRC; @@ -1125,7 +1135,7 @@ static void cc4group_calculateEntryCRC(C4GroupEntryData* const groupEntry) static bool cc4group_writeEntriesToGzFile(CC4Group* const this, C4GroupEntryData* const entryData, gzFile file) { - C4GroupHeader header = *(C4GroupHeader*)entryData->data; + C4GroupHeader header = *(C4GroupHeader*)cc4group_getOnlyEntryData(this, entryData); header.Entries = GroupEntryListSize(entryData->children); header.Ver1 = 1; header.Ver2 = 2; @@ -1171,7 +1181,7 @@ static bool cc4group_writeEntriesToGzFile(CC4Group* const this, C4GroupEntryData } else if(entry->value.core.Size > 0) { - if(gzwrite(file, entry->value.data, entry->value.core.Size) == 0) + if(gzwrite(file, cc4group_getOnlyEntryData(this, &entry->value), entry->value.core.Size) == 0) { int code; gzerror(file, &code); @@ -1213,7 +1223,7 @@ static bool cc4group_saveIt(CC4Group* const this, const char* const path, bool c file = -1; cc4group_calculateEntrySizes(&this->root); - cc4group_calculateEntryCRC(&this->root); + cc4group_calculateEntryCRC(this, &this->root); success = cc4group_writeEntriesToGzFile(this, &this->root, gzfile); ret: |
