summaryrefslogtreecommitdiff
path: root/programs
diff options
context:
space:
mode:
authorFilipe Calasans <filipe.calasans@gmail.com>2020-02-07 14:52:25 -0800
committerFilipe Calasans <filipe.calasans@gmail.com>2020-02-07 17:03:13 -0800
commit781417a36997548c54c445c0e2e9634e69b0e0c6 (patch)
tree254a238d43dc87efec79f9b328d3f1831371b95a /programs
parent8372862e0f7e072cb206e96c70f6e1a796b66fe6 (diff)
downloadlz4-781417a36997548c54c445c0e2e9634e69b0e0c6.tar.gz
lz4-781417a36997548c54c445c0e2e9634e69b0e0c6.tar.bz2
lz4-781417a36997548c54c445c0e2e9634e69b0e0c6.zip
Implement -m option with legacy format on cli
Diffstat (limited to 'programs')
-rw-r--r--programs/lz4cli.c11
-rw-r--r--programs/lz4io.c51
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<ifntSize; i++) {
+ size_t const ifnSize = strlen(inFileNamesTable[i]);
+ if (!strcmp(suffix, stdoutmark)) {
+ missed_files += LZ4IO_compressFilename_Legacy(prefs,
+ inFileNamesTable[i], stdoutmark,
+ compressionLevel);
+ continue;
+ }
+
+ if (ofnSize <= ifnSize+suffixSize+1) {
+ free(dstFileName);
+ ofnSize = ifnSize + 20;
+ dstFileName = (char*)malloc(ofnSize);
+ if (dstFileName==NULL) {
+ return ifntSize;
+ } }
+ strcpy(dstFileName, inFileNamesTable[i]);
+ strcat(dstFileName, suffix);
+
+ missed_files += LZ4IO_compressFilename_Legacy(prefs,
+ inFileNamesTable[i], dstFileName,
+ compressionLevel);
+ }
+
+ /* Close & Free */
+ free(dstFileName);
+
+ return missed_files;
+}
+
/*********************************************
* Compression using Frame format
@@ -749,7 +797,6 @@ int LZ4IO_compressFilename(LZ4IO_prefs_t* const prefs, const char* srcFileName,
}
-#define FNSPACE 30
int LZ4IO_compressMultipleFilenames(LZ4IO_prefs_t* const prefs,
const char** inFileNamesTable, int ifntSize,
const char* suffix,