From 781417a36997548c54c445c0e2e9634e69b0e0c6 Mon Sep 17 00:00:00 2001 From: Filipe Calasans Date: Fri, 7 Feb 2020 14:52:25 -0800 Subject: [PATCH] Implement -m option with legacy format on cli --- programs/lz4cli.c | 11 +++++++++-- programs/lz4io.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 58 insertions(+), 4 deletions(-) diff --git a/programs/lz4cli.c b/programs/lz4cli.c index aadccab..67dcaa1 100644 --- a/programs/lz4cli.c +++ b/programs/lz4cli.c @@ -94,7 +94,10 @@ static unsigned displayLevel = 2; /* 0 : no display ; 1: errors only ; 2 : dow #define DEFAULT_COMPRESSOR LZ4IO_compressFilename #define DEFAULT_DECOMPRESSOR LZ4IO_decompressFilename int LZ4IO_compressFilename_Legacy(LZ4IO_prefs_t* const prefs, const char* input_filename, const char* output_filename, int compressionlevel); /* hidden function */ - +int LZ4IO_compressMultipleFilenames_Legacy(LZ4IO_prefs_t* const prefs, + const char** inFileNamesTable, int ifntSize, + const char* suffix, + int compressionLevel); /*-*************************** * Functions @@ -754,7 +757,11 @@ int main(int argc, const char** argv) } else { /* compression is default action */ if (legacy_format) { DISPLAYLEVEL(3, "! Generating LZ4 Legacy format (deprecated) ! \n"); - LZ4IO_compressFilename_Legacy(prefs, input_filename, output_filename, cLevel); + if(multiple_inputs){ + LZ4IO_compressMultipleFilenames_Legacy(prefs, inFileNames, (int)ifnIdx, !strcmp(output_filename,stdoutmark) ? stdoutmark : LZ4_EXTENSION, cLevel); + } else { + LZ4IO_compressFilename_Legacy(prefs, input_filename, output_filename, cLevel); + } } else { if (multiple_inputs) { assert(ifnIdx <= INT_MAX); diff --git a/programs/lz4io.c b/programs/lz4io.c index ec6dc7f..7926b20 100644 --- a/programs/lz4io.c +++ b/programs/lz4io.c @@ -470,11 +470,59 @@ int LZ4IO_compressFilename_Legacy(LZ4IO_prefs_t* const prefs, const char* input_ free(in_buff); free(out_buff); fclose(finput); - fclose(foutput); + if (strcmp(output_filename,stdoutmark)) fclose(foutput); /* do not close stdout */ return 0; } +#define FNSPACE 30 +/* LZ4IO_compressMultipleFilenames_Legacy : + * This function is intentionally "hidden" (not published in .h) + * It generates multiple compressed streams using the old 'legacy' format */ +int LZ4IO_compressMultipleFilenames_Legacy(LZ4IO_prefs_t* const prefs, + const char** inFileNamesTable, int ifntSize, + const char* suffix, + int compressionLevel) +{ + int i; + int missed_files = 0; + char* dstFileName = (char*)malloc(FNSPACE); + size_t ofnSize = FNSPACE; + const size_t suffixSize = strlen(suffix); + + if (dstFileName == NULL) return ifntSize; /* not enough memory */ + + /* loop on each file */ + for (i=0; i