From 51657e10769faa2617d546a06c42e4c62a19bb50 Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 30 Jan 2022 17:41:24 +0100 Subject: Removed trailing whitespace all over the place --- Datafile/Archive.cpp | 76 ++++++++++++++++++++++++++-------------------------- Datafile/Archive.h | 8 +++--- Datafile/Main.cpp | 6 ++--- 3 files changed, 45 insertions(+), 45 deletions(-) (limited to 'Datafile') diff --git a/Datafile/Archive.cpp b/Datafile/Archive.cpp index a33422c..4ae0673 100644 --- a/Datafile/Archive.cpp +++ b/Datafile/Archive.cpp @@ -63,7 +63,7 @@ int err; DataArchive::DataArchive(const char* name) { ZeroMemory(this, sizeof(DataArchive)); - + if (name) LoadDatafile(name); } @@ -83,7 +83,7 @@ void DataArchive::WriteEntry(int index, BYTE* buf) header.dir_size_comp = DirBlocks() * BLOCK_SIZE; dirbuf = new BYTE[header.dir_size_comp]; - err = compress(dirbuf, &header.dir_size_comp, + err = compress(dirbuf, &header.dir_size_comp, (BYTE*) directory, header.nfiles * sizeof(DataEntry)); CHECK_ERR(err, "compress"); @@ -93,9 +93,9 @@ void DataArchive::WriteEntry(int index, BYTE* buf) _write(f, &header, sizeof(DataHeader)); _lseek(f, sizeof(DataHeader) + header.dir_offset, SEEK_SET); _write(f, dirbuf, header.dir_blocks); - + delete [] dirbuf; - + if (buf && directory[index].size_comp) { _lseek(f, sizeof(DataHeader) + directory[index].offset, SEEK_SET); _write(f, buf, directory[index].size_comp); @@ -112,7 +112,7 @@ DWORD DataArchive::Blocks(DWORD raw_size) { int full_blocks = raw_size / BLOCK_SIZE; int part_blocks = (raw_size % BLOCK_SIZE) > 0; - + return full_blocks + part_blocks; } @@ -134,7 +134,7 @@ void DataArchive::CreateBlockMap() { delete [] block_map; block_map = 0; - + if (header.nfiles == 0) return; DWORD i,j; @@ -151,16 +151,16 @@ void DataArchive::CreateBlockMap() block_map = new DWORD[nblocks]; ZeroMemory(block_map, nblocks*sizeof(DWORD)); - DWORD first_block = header.dir_offset/BLOCK_SIZE + + DWORD first_block = header.dir_offset/BLOCK_SIZE + (header.dir_offset%BLOCK_SIZE > 0); - + for (j = 0; j < DirBlocks(); j++) block_map[first_block+j] = 1; for (i = 0; i < header.nfiles; i++) { - DWORD first_block = directory[i].offset/BLOCK_SIZE + + DWORD first_block = directory[i].offset/BLOCK_SIZE + (directory[i].offset%BLOCK_SIZE > 0); - + for (j = 0; j < FileBlocks(i); j++) block_map[first_block+j] = i+2; } @@ -176,9 +176,9 @@ int DataArchive::FindDataBlocks(int need) for (start = 0; start < nblocks-need; start++) { for (i = 0; block_map[start+i] == 0 && i < need; i++); - + if (i == need) return start*BLOCK_SIZE; - + start += i; } } @@ -196,7 +196,7 @@ void DataArchive::LoadDatafile(const char* name) FILE* f = fopen(datafile, "rb"); if (f) { fread(&header, sizeof(DataHeader), 1, f); - + if (header.version != VERSION) { printf("ERROR: datafile '%s' invalid version '%d'\n", //-V576 datafile, header.version); @@ -205,7 +205,7 @@ void DataArchive::LoadDatafile(const char* name) } DWORD len = DirBlocks() * BLOCK_SIZE; - + dirbuf = new BYTE[len]; fseek(f, sizeof(DataHeader) + header.dir_offset, SEEK_SET); fread(dirbuf, header.dir_size_comp, 1, f); @@ -214,21 +214,21 @@ void DataArchive::LoadDatafile(const char* name) dirbuf, header.dir_size_comp); if (err != Z_OK) ZeroMemory(directory, sizeof(directory)); - + delete [] dirbuf; CreateBlockMap(); } else { printf("Creating Archive '%s'...\n", datafile); - + header.version = VERSION; header.nfiles = 0; header.dir_blocks = 0; header.dir_size_comp = 0; header.dir_offset = 0; - + nblocks = DirBlocks(); - + delete [] block_map; block_map = 0; } @@ -243,7 +243,7 @@ int DataArchive::FindEntry(const char* req_name) for (DWORD i = 0; i < header.nfiles; i++) if (!_stricmp(directory[i].name, req_name)) return i; - + return entry; } @@ -259,24 +259,24 @@ BYTE* DataArchive::CompressEntry(int i) fseek(f, 0, SEEK_END); DWORD len = ftell(f); fseek(f, 0, SEEK_SET); - + BYTE* buf = new BYTE[len]; - + fread(buf, len, 1, f); fclose(f); directory[i].size_orig = len; - + directory[i].size_comp = (int) (len * 1.1); BYTE* cbuf = new BYTE[directory[i].size_comp]; err = compress(cbuf, &directory[i].size_comp, buf, len); CHECK_ERR(err, "compress"); - + delete [] buf; return cbuf; } - + return 0; } @@ -291,7 +291,7 @@ int DataArchive::ExpandEntry(int i, BYTE*& buf) if (f) { DWORD clen = directory[i].size_comp; BYTE* cbuf = new BYTE[clen]; - + fseek(f, sizeof(DataHeader) + directory[i].offset, SEEK_SET); fread(cbuf, clen, 1, f); @@ -324,7 +324,7 @@ int DataArchive::InsertEntry(const char* name) strncpy(directory[i].name, name, NAMELEN); directory[i].name[NAMELEN-1] = '\0'; directory[i].size_orig = 1; - + return i; } } @@ -348,20 +348,20 @@ void DataArchive::Insert(const char* name) int added = 0; int index = FindEntry(name); - + if (index < 0) { old_dir_blocks = DirBlocks(); old_dir_offset = header.dir_offset; - + index = InsertEntry(name); - + if (index >= (int) header.nfiles) { header.nfiles = index+1; added = 1; } new_dir_blocks = DirBlocks(); - + if (new_dir_blocks > old_dir_blocks) { header.dir_offset = FindDataBlocks(new_dir_blocks); CreateBlockMap(); @@ -371,14 +371,14 @@ void DataArchive::Insert(const char* name) old_blocks = FileBlocks(index); old_offset = directory[index].offset; } - + if (index >= 0) { DataEntry& e = directory[index]; - + if (verbose) printf(" Inserting: %-48s ", e.name); BYTE* buf = CompressEntry(index); - + if (!buf) { // this is (almost) unrecoverable, // so we quit before screwing things up: @@ -387,7 +387,7 @@ void DataArchive::Insert(const char* name) } new_blocks = FileBlocks(index); - + // the file is new, or got bigger, // need to find room for the data: if (new_blocks > old_blocks) { @@ -397,7 +397,7 @@ void DataArchive::Insert(const char* name) WriteEntry(index, buf); delete [] buf; - + if (verbose) { int ratio = (int) (100.0 * (double) e.size_comp / (double) e.size_orig); printf("%9d => %9d (%2d%%)\n", e.size_orig, e.size_comp, ratio); //-V576 @@ -428,7 +428,7 @@ void DataArchive::Extract(const char* name) BYTE* buf; ExpandEntry(index, buf); - + std::string dirname = directory[index].name; bool create_subdir = (dirname.find_first_of('/', 0) != std::string::npos); std::wstring wdirname = ToWideString(dirname.substr(0, dirname.find_first_of('/'))); @@ -488,9 +488,9 @@ void DataArchive::List() for (DWORD i = 0; i < header.nfiles; i++) { DataEntry& e = directory[i]; int ratio = (int) (100.0 * (double) e.size_comp / (double) e.size_orig); - + printf("%5d %9d %9d %2d%% %s\n", i+1, e.size_orig, e.size_comp, ratio, e.name); //-V576 - + total_orig += e.size_orig; total_comp += e.size_comp; } diff --git a/Datafile/Archive.h b/Datafile/Archive.h index 7b3982d..dabdf21 100644 --- a/Datafile/Archive.h +++ b/Datafile/Archive.h @@ -59,7 +59,7 @@ struct DataEntry char name[NAMELEN]; DWORD size_orig; DWORD size_comp; - DWORD offset; + DWORD offset; }; class DataArchive @@ -75,7 +75,7 @@ public: void Extract(const char* name); void Remove(const char* name); void List(); - + void WriteEntry(int index, BYTE* buf); int FindEntry(const char* req_name); int ExpandEntry(int index, BYTE*& buf); @@ -87,7 +87,7 @@ public: DWORD FileBlocks(int index); int FindDataBlocks(int blocks_needed); void CreateBlockMap(); - + DWORD NumFiles() { return header.nfiles; } DataEntry* GetFile(int i) { if (i>=0 && i<(int)header.nfiles) return &directory[i]; return 0; } @@ -99,7 +99,7 @@ private: // transient members: char datafile[NAMELEN]; - + DWORD* block_map; DWORD nblocks; }; diff --git a/Datafile/Main.cpp b/Datafile/Main.cpp index 8b37e27..c09295b 100644 --- a/Datafile/Main.cpp +++ b/Datafile/Main.cpp @@ -242,7 +242,7 @@ int match(const char* sFile, const char* sPattern) default: file_matches_pattern = (_stricmp(sFile, sPattern) == 0); break; - + case PATTERN_STAR: case PATTERN_STAR_DOT_STAR: file_matches_pattern = 1; @@ -341,7 +341,7 @@ void del(DataArchive& a, int argc, char* argv[]) for (int i = 0; i < argc; i++) { if (strchr(argv[i], '*')) { strcpy(sPath, argv[i]); - + if ((pDirSep = strrchr(sPath, '\\')) != 0) { strcpy(sPatt, pDirSep+1); *pDirSep = 0; @@ -403,7 +403,7 @@ void Usage() printf(" -del (delete files from datafile)\n"); printf(" -mak (insert all files in current directory and all subdirectories)\n"); printf(" -list (display list of entries in datafile)\n"); - + exit(-1); } -- cgit v1.1