diff options
-rw-r--r-- | programs/lz4cli.c | 36 | ||||
-rw-r--r-- | programs/lz4io.c | 47 | ||||
-rw-r--r-- | programs/lz4io.h | 3 |
3 files changed, 71 insertions, 15 deletions
diff --git a/programs/lz4cli.c b/programs/lz4cli.c index 7ed0f30..ffc54c0 100644 --- a/programs/lz4cli.c +++ b/programs/lz4cli.c @@ -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; @@ -524,26 +525,33 @@ int main(int argc, char** argv) /* IO Stream/File */ LZ4IO_setNotificationLevel(displayLevel); - if (decode) DEFAULT_DECOMPRESSOR(input_filename, output_filename); + if (decode) + { + if (multiple_inputs) + multiple_rv = LZ4IO_decompressMultipleFilenames(inFileNames, ifnIdx, LZ4_EXTENSION); + else + DEFAULT_DECOMPRESSOR(input_filename, output_filename); + } else { - /* compression is default action */ - if (legacy_format) - { - DISPLAYLEVEL(3, "! Generating compressed LZ4 using Legacy format (deprecated) ! \n"); - LZ4IO_compressFilename_Legacy(input_filename, output_filename, cLevel); - } + /* compression is default action */ + if (legacy_format) + { + DISPLAYLEVEL(3, "! Generating compressed LZ4 using Legacy format (deprecated) ! \n"); + LZ4IO_compressFilename_Legacy(input_filename, output_filename, cLevel); + } + else + { + if (multiple_inputs) + multiple_rv = LZ4IO_compressMultipleFilenames(inFileNames, ifnIdx, LZ4_EXTENSION, cLevel); else - { - if (multiple_inputs) - LZ4IO_compressMultipleFilenames(inFileNames, ifnIdx, LZ4_EXTENSION, cLevel); - else - DEFAULT_COMPRESSOR(input_filename, output_filename, cLevel); - } + DEFAULT_COMPRESSOR(input_filename, output_filename, cLevel); + } } if (main_pause) waitEnter(); free(dynNameSpace); free((void*)inFileNames); + if (multiple_rv != 0) return multiple_rv; return 0; } diff --git a/programs/lz4io.c b/programs/lz4io.c index 1595a0d..c510f1d 100644 --- a/programs/lz4io.c +++ b/programs/lz4io.c @@ -508,12 +508,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]); @@ -521,9 +530,47 @@ int LZ4IO_compressMultipleFilenames(const char** inFileNamesTable, int ifntSize, LZ4IO_compressFilename(inFileNamesTable[i], outFileName, compressionlevel); } free(outFileName); + if (missing_files > 0) return 1; return 0; } +int LZ4IO_decompressMultipleFilenames(const char** inFileNamesTable, int ifntSize, const char* suffix) +{ + 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); + char* ifnSuffix = (char*)malloc(suffixSize + 1); + + 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); + 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++; + continue; + } + memcpy(outFileName, inFileNamesTable[i], ifnSize - suffixSize); + outFileName[ifnSize-suffixSize] = '\0'; + LZ4IO_decompressFilename(inFileNamesTable[i], outFileName); + } + free(outFileName); + if (skipped_files > 0) return 1; + if (missing_files > 0) return 1; + return 0; +} /* ********************************************************************* */ /* ********************** LZ4 file-stream Decompression **************** */ diff --git a/programs/lz4io.h b/programs/lz4io.h index 75a36e1..11c8fdb 100644 --- a/programs/lz4io.h +++ b/programs/lz4io.h @@ -51,8 +51,9 @@ static char const nulmark[] = "/dev/null"; int LZ4IO_compressFilename (const char* input_filename, const char* output_filename, int compressionlevel); int LZ4IO_decompressFilename(const char* input_filename, const char* output_filename); -int LZ4IO_compressMultipleFilenames(const char** inFileNamesTable, int ifntSize, const char* suffix, int compressionlevel); +int LZ4IO_compressMultipleFilenames(const char** inFileNamesTable, int ifntSize, const char* suffix, int compressionlevel); +int LZ4IO_decompressMultipleFilenames(const char** inFileNamesTable, int ifntSize, const char* suffix); /* ************************************************** */ /* ****************** Parameters ******************** */ |