mirror of
https://github.com/lz4/lz4.git
synced 2024-12-03 06:43:43 +08:00
Added support for continuation of file compression and decompression if input files are missing. Should more closely match gzip/bzip2/xz and so forth. Also removed a debug print accidentally left in.
This commit is contained in:
parent
0169502b49
commit
7f2f1fcd55
@ -265,7 +265,8 @@ int main(int argc, char** argv)
|
||||
forceStdout=0,
|
||||
forceCompress=0,
|
||||
main_pause=0,
|
||||
multiple_inputs=0;
|
||||
multiple_inputs=0,
|
||||
multiple_rv=0;
|
||||
const char* input_filename=0;
|
||||
const char* output_filename=0;
|
||||
char* dynNameSpace=0;
|
||||
@ -518,7 +519,7 @@ int main(int argc, char** argv)
|
||||
if (decode)
|
||||
{
|
||||
if (multiple_inputs)
|
||||
LZ4IO_decompressMultipleFilenames(inFileNames, ifnIdx, LZ4_EXTENSION);
|
||||
multiple_rv = LZ4IO_decompressMultipleFilenames(inFileNames, ifnIdx, LZ4_EXTENSION);
|
||||
else
|
||||
DEFAULT_DECOMPRESSOR(input_filename, output_filename);
|
||||
}
|
||||
@ -533,7 +534,7 @@ int main(int argc, char** argv)
|
||||
else
|
||||
{
|
||||
if (multiple_inputs)
|
||||
LZ4IO_compressMultipleFilenames(inFileNames, ifnIdx, LZ4_EXTENSION, cLevel);
|
||||
multiple_rv = LZ4IO_compressMultipleFilenames(inFileNames, ifnIdx, LZ4_EXTENSION, cLevel);
|
||||
else
|
||||
DEFAULT_COMPRESSOR(input_filename, output_filename, cLevel);
|
||||
}
|
||||
@ -542,5 +543,6 @@ int main(int argc, char** argv)
|
||||
if (main_pause) waitEnter();
|
||||
free(dynNameSpace);
|
||||
free((void*)inFileNames);
|
||||
if (multiple_rv != 0) return multiple_rv;
|
||||
return 0;
|
||||
}
|
||||
|
@ -501,12 +501,21 @@ int LZ4IO_compressFilename(const char* input_filename, const char* output_filena
|
||||
int LZ4IO_compressMultipleFilenames(const char** inFileNamesTable, int ifntSize, const char* suffix, int compressionlevel)
|
||||
{
|
||||
int i;
|
||||
int missing_files = 0;
|
||||
FILE *ifp;
|
||||
char* outFileName = (char*)malloc(FNSPACE);
|
||||
size_t ofnSize = FNSPACE;
|
||||
const size_t suffixSize = strlen(suffix);
|
||||
|
||||
for (i=0; i<ifntSize; i++)
|
||||
{
|
||||
ifp = fopen(inFileNamesTable[i], "r");
|
||||
if (ifp == NULL) {
|
||||
DISPLAYLEVEL(2, "Unable to access file for processing: %s\n", inFileNamesTable[i]);
|
||||
missing_files++;
|
||||
continue;
|
||||
}
|
||||
fclose(ifp);
|
||||
size_t ifnSize = strlen(inFileNamesTable[i]);
|
||||
if (ofnSize <= ifnSize+suffixSize+1) { free(outFileName); ofnSize = ifnSize + 20; outFileName = (char*)malloc(ofnSize); }
|
||||
strcpy(outFileName, inFileNamesTable[i]);
|
||||
@ -514,6 +523,7 @@ int LZ4IO_compressMultipleFilenames(const char** inFileNamesTable, int ifntSize,
|
||||
LZ4IO_compressFilename(inFileNamesTable[i], outFileName, compressionlevel);
|
||||
}
|
||||
free(outFileName);
|
||||
if (missing_files > 0) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -521,6 +531,8 @@ int LZ4IO_decompressMultipleFilenames(const char** inFileNamesTable, int ifntSiz
|
||||
{
|
||||
int i;
|
||||
int skipped_files = 0;
|
||||
int missing_files = 0;
|
||||
FILE *ifp;
|
||||
char* outFileName = (char*)malloc(FNSPACE);
|
||||
size_t ofnSize = FNSPACE;
|
||||
size_t suffixSize = strlen(suffix);
|
||||
@ -528,13 +540,19 @@ int LZ4IO_decompressMultipleFilenames(const char** inFileNamesTable, int ifntSiz
|
||||
|
||||
for (i=0; i<ifntSize; i++)
|
||||
{
|
||||
ifp = fopen(inFileNamesTable[i], "r");
|
||||
if (ifp == NULL) {
|
||||
DISPLAYLEVEL(2, "Unable to access file for processing: %s\n", inFileNamesTable[i]);
|
||||
missing_files++;
|
||||
continue;
|
||||
}
|
||||
fclose(ifp);
|
||||
size_t ifnSize = strlen(inFileNamesTable[i]);
|
||||
strcpy(ifnSuffix, inFileNamesTable[i] + ifnSize - suffixSize);
|
||||
DISPLAYLEVEL(2, "ifnSuffix is %s\n", ifnSuffix);
|
||||
if (ofnSize <= ifnSize-suffixSize+1) { free(outFileName); ofnSize = ifnSize + 20; outFileName = (char*)malloc(ofnSize); }
|
||||
if (ifnSize <= suffixSize || strcmp(ifnSuffix, suffix) != 0) {
|
||||
DISPLAYLEVEL(2, "File extension doesn't match expected LZ4_EXTENSION (%4s); will not process file: %s\n", suffix, inFileNamesTable[i]);
|
||||
skipped_files = 1;
|
||||
skipped_files++;
|
||||
continue;
|
||||
}
|
||||
memcpy(outFileName, inFileNamesTable[i], ifnSize - suffixSize);
|
||||
@ -542,7 +560,8 @@ int LZ4IO_decompressMultipleFilenames(const char** inFileNamesTable, int ifntSiz
|
||||
LZ4IO_decompressFilename(inFileNamesTable[i], outFileName);
|
||||
}
|
||||
free(outFileName);
|
||||
if (skipped_files) return 1;
|
||||
if (skipped_files > 0) return 1;
|
||||
if (missing_files > 0) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user