summaryrefslogtreecommitdiffstats
path: root/programs/lz4cli.c
diff options
context:
space:
mode:
Diffstat (limited to 'programs/lz4cli.c')
-rw-r--r--programs/lz4cli.c219
1 files changed, 110 insertions, 109 deletions
diff --git a/programs/lz4cli.c b/programs/lz4cli.c
index 6f62095..0da5dce 100644
--- a/programs/lz4cli.c
+++ b/programs/lz4cli.c
@@ -30,62 +30,62 @@
The license of this compression CLI program is GPLv2.
*/
-//**************************************
-// Tuning parameters
-//**************************************
-// ENABLE_LZ4C_LEGACY_OPTIONS :
-// Control the availability of -c0, -c1 and -hc legacy arguments
-// Default : Legacy options are disabled
-// #define ENABLE_LZ4C_LEGACY_OPTIONS
-
-
-//**************************************
-// Compiler Options
-//**************************************
-// Disable some Visual warning messages
-#ifdef _MSC_VER // Visual Studio
+/**************************************
+* Tuning parameters
+***************************************/
+/* ENABLE_LZ4C_LEGACY_OPTIONS :
+ Control the availability of -c0, -c1 and -hc legacy arguments
+ Default : Legacy options are disabled */
+/* #define ENABLE_LZ4C_LEGACY_OPTIONS */
+
+
+/**************************************
+* Compiler Options
+***************************************/
+/* Disable some Visual warning messages */
+#ifdef _MSC_VER
# define _CRT_SECURE_NO_WARNINGS
-# define _CRT_SECURE_NO_DEPRECATE // VS2005
-# pragma warning(disable : 4127) // disable: C4127: conditional expression is constant
+# define _CRT_SECURE_NO_DEPRECATE /* VS2005 */
+# pragma warning(disable : 4127) /* disable: C4127: conditional expression is constant */
#endif
-#define _POSIX_SOURCE 1 // for fileno() within <stdio.h> on unix
+#define _POSIX_SOURCE 1 /* for fileno() within <stdio.h> on unix */
-//****************************
-// Includes
-//****************************
-#include <stdio.h> // fprintf, fopen, fread, _fileno, stdin, stdout
-#include <stdlib.h> // exit, calloc, free
-#include <string.h> // strcmp, strlen
-#include "bench.h" // BMK_benchFile, BMK_SetNbIterations, BMK_SetBlocksize, BMK_SetPause
+/****************************
+* Includes
+*****************************/
+#include <stdio.h> /* fprintf, getchar */
+#include <stdlib.h> /* exit, calloc, free */
+#include <string.h> /* strcmp, strlen */
+#include "bench.h" /* BMK_benchFile, BMK_SetNbIterations, BMK_SetBlocksize, BMK_SetPause */
#include "lz4io.h"
-//****************************
-// OS-specific Includes
-//****************************
+/****************************
+* OS-specific Includes
+*****************************/
#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__)
-# include <fcntl.h> // _O_BINARY
-# include <io.h> // _setmode, _isatty
+# include <fcntl.h> /* _O_BINARY */
+# include <io.h> /* _setmode, _isatty */
# ifdef __MINGW32__
- int _fileno(FILE *stream); // MINGW somehow forgets to include this windows declaration into <stdio.h>
+ int _fileno(FILE *stream); /* MINGW somehow forgets to include this prototype into <stdio.h> */
# endif
# define SET_BINARY_MODE(file) _setmode(_fileno(file), _O_BINARY)
# define IS_CONSOLE(stdStream) _isatty(_fileno(stdStream))
#else
-# include <unistd.h> // isatty
+# include <unistd.h> /* isatty */
# define SET_BINARY_MODE(file)
# define IS_CONSOLE(stdStream) isatty(fileno(stdStream))
#endif
-//****************************
-// Constants
-//****************************
+/*****************************
+* Constants
+******************************/
#define COMPRESSOR_NAME "LZ4 command line interface"
#ifndef LZ4_VERSION
-# define LZ4_VERSION "r125"
+# define LZ4_VERSION "r126"
#endif
#define AUTHOR "Yann Collet"
#define WELCOME_MESSAGE "*** %s %i-bits %s, by %s (%s) ***\n", COMPRESSOR_NAME, (int)(sizeof(void*)*8), LZ4_VERSION, AUTHOR, __DATE__
@@ -99,23 +99,23 @@
#define LZ4_BLOCKSIZEID_DEFAULT 7
-//**************************************
-// Macros
-//**************************************
+/**************************************
+* Macros
+***************************************/
#define DISPLAY(...) fprintf(stderr, __VA_ARGS__)
#define DISPLAYLEVEL(l, ...) if (displayLevel>=l) { DISPLAY(__VA_ARGS__); }
-static unsigned displayLevel = 2; // 0 : no display // 1: errors // 2 : + result + interaction + warnings ; // 3 : + progression; // 4 : + information
+static unsigned displayLevel = 2; /* 0 : no display ; 1: errors ; 2 : + result + interaction + warnings ; 3 : + progression; 4 : + information */
-//**************************************
-// Local Variables
-//**************************************
+/**************************************
+* Local Variables
+***************************************/
static char* programName;
-//**************************************
-// Exceptions
-//**************************************
+/**************************************
+* Exceptions
+***************************************/
#define DEBUG 0
#define DEBUGOUTPUT(...) if (DEBUG) DISPLAY(__VA_ARGS__);
#define EXM_THROW(error, ...) \
@@ -128,21 +128,21 @@ static char* programName;
}
-//**************************************
-// Version modifiers
-//**************************************
+/**************************************
+* Version modifiers
+***************************************/
#define EXTENDED_ARGUMENTS
#define EXTENDED_HELP
#define EXTENDED_FORMAT
#define DEFAULT_COMPRESSOR LZ4IO_compressFilename
#define DEFAULT_DECOMPRESSOR LZ4IO_decompressFilename
-int LZ4IO_compressFilename_Legacy(char* input_filename, char* output_filename, int compressionlevel);
+int LZ4IO_compressFilename_Legacy(char* input_filename, char* output_filename, int compressionlevel); /* hidden function */
-//****************************
-// Functions
-//****************************
-int usage(void)
+/****************************
+* Functions
+*****************************/
+static int usage(void)
{
DISPLAY( "Usage :\n");
DISPLAY( " %s [arg] [input] [output]\n", programName);
@@ -159,7 +159,7 @@ int usage(void)
return 0;
}
-int usage_advanced(void)
+static int usage_advanced(void)
{
DISPLAY(WELCOME_MESSAGE);
usage();
@@ -173,7 +173,7 @@ int usage_advanced(void)
DISPLAY( " -l : compress using Legacy format (Linux kernel compression)\n");
DISPLAY( " -B# : Block size [4-7](default : 7)\n");
DISPLAY( " -BD : Block dependency (improve compression ratio)\n");
- //DISPLAY( " -BX : enable block checksum (default:disabled)\n"); // Option currently inactive
+ /* DISPLAY( " -BX : enable block checksum (default:disabled)\n"); *//* Option currently inactive */
DISPLAY( " -Sx : disable stream checksum (default:enabled)\n");
DISPLAY( "Benchmark arguments :\n");
DISPLAY( " -b : benchmark file(s)\n");
@@ -185,12 +185,12 @@ int usage_advanced(void)
DISPLAY( " -hc : high compression\n");
DISPLAY( " -y : overwrite output without prompting \n");
DISPLAY( " -s : suppress warnings \n");
-#endif // ENABLE_LZ4C_LEGACY_OPTIONS
+#endif /* ENABLE_LZ4C_LEGACY_OPTIONS */
EXTENDED_HELP;
return 0;
}
-int usage_longhelp(void)
+static int usage_longhelp(void)
{
DISPLAY( "\n");
DISPLAY( "Which values can get [output] ? \n");
@@ -236,11 +236,11 @@ int usage_longhelp(void)
DISPLAY( "It is not equivalent to :\n");
DISPLAY( " %s -h -c filename\n", programName);
DISPLAY( "which would display help text and exit\n");
-#endif // ENABLE_LZ4C_LEGACY_OPTIONS
+#endif /* ENABLE_LZ4C_LEGACY_OPTIONS */
return 0;
}
-int badusage(void)
+static int badusage(void)
{
DISPLAYLEVEL(1, "Incorrect parameters\n");
if (displayLevel >= 1) usage();
@@ -248,7 +248,7 @@ int badusage(void)
}
-void waitEnter(void)
+static void waitEnter(void)
{
DISPLAY("Press enter to continue...\n");
getchar();
@@ -273,25 +273,25 @@ int main(int argc, char** argv)
char extension[] = LZ4_EXTENSION;
int blockSize;
- // Init
+ /* Init */
programName = argv[0];
LZ4IO_setOverwrite(0);
blockSize = LZ4IO_setBlockSizeID(LZ4_BLOCKSIZEID_DEFAULT);
- // lz4cat behavior
+ /* lz4cat behavior */
if (!strcmp(programName, LZ4_CAT)) { decode=1; forceStdout=1; output_filename=stdoutmark; displayLevel=1; }
- // command switches
+ /* command switches */
for(i=1; i<argc; i++)
{
char* argument = argv[i];
- if(!argument) continue; // Protection if argument empty
+ if(!argument) continue; /* Protection if argument empty */
- // Decode command (note : aggregated commands are allowed)
+ /* Decode command (note : aggregated commands are allowed) */
if (argument[0]=='-')
{
- // '-' means stdin/stdout
+ /* '-' means stdin/stdout */
if (argument[1]==0)
{
if (!input_filename) input_filename=stdinmark;
@@ -303,13 +303,13 @@ int main(int argc, char** argv)
argument ++;
#if defined(ENABLE_LZ4C_LEGACY_OPTIONS)
- // Legacy options (-c0, -c1, -hc, -y, -s)
- if ((argument[0]=='c') && (argument[1]=='0')) { cLevel=0; argument++; continue; } // -c0 (fast compression)
- if ((argument[0]=='c') && (argument[1]=='1')) { cLevel=9; argument++; continue; } // -c1 (high compression)
- if ((argument[0]=='h') && (argument[1]=='c')) { cLevel=9; argument++; continue; } // -hc (high compression)
- if (*argument=='y') { LZ4IO_setOverwrite(1); continue; } // -y (answer 'yes' to overwrite permission)
- if (*argument=='s') { displayLevel=1; continue; } // -s (silent mode)
-#endif // ENABLE_LZ4C_LEGACY_OPTIONS
+ /* Legacy arguments (-c0, -c1, -hc, -y, -s) */
+ if ((argument[0]=='c') && (argument[1]=='0')) { cLevel=0; argument++; continue; } /* -c0 (fast compression) */
+ if ((argument[0]=='c') && (argument[1]=='1')) { cLevel=9; argument++; continue; } /* -c1 (high compression) */
+ if ((argument[0]=='h') && (argument[1]=='c')) { cLevel=9; argument++; continue; } /* -hc (high compression) */
+ if (*argument=='y') { LZ4IO_setOverwrite(1); continue; } /* -y (answer 'yes' to overwrite permission) */
+ if (*argument=='s') { displayLevel=1; continue; } /* -s (silent mode) */
+#endif /* ENABLE_LZ4C_LEGACY_OPTIONS */
if ((*argument>='0') && (*argument<='9'))
{
@@ -326,39 +326,39 @@ int main(int argc, char** argv)
switch(argument[0])
{
- // Display help
- case 'V': DISPLAY(WELCOME_MESSAGE); return 0; // Version
+ /* Display help */
+ case 'V': DISPLAY(WELCOME_MESSAGE); return 0; /* Version */
case 'h': usage_advanced(); return 0;
case 'H': usage_advanced(); usage_longhelp(); return 0;
- // Compression (default)
+ /* Compression (default) */
case 'z': forceCompress = 1; break;
- // Use Legacy format (for Linux kernel compression)
- case 'l': legacy_format=1; break;
+ /* Use Legacy format (ex : Linux kernel compression) */
+ case 'l': legacy_format = 1; blockSize = 8 MB; break;
- // Decoding
+ /* Decoding */
case 'd': decode=1; break;
- // Force stdout, even if stdout==console
+ /* Force stdout, even if stdout==console */
case 'c': forceStdout=1; output_filename=stdoutmark; displayLevel=1; break;
- // Test
+ /* Test integrity */
case 't': decode=1; LZ4IO_setOverwrite(1); output_filename=nulmark; break;
- // Overwrite
+ /* Overwrite */
case 'f': LZ4IO_setOverwrite(1); break;
- // Verbose mode
+ /* Verbose mode */
case 'v': displayLevel=4; break;
- // Quiet mode
+ /* Quiet mode */
case 'q': displayLevel--; break;
- // keep source file (default anyway, so useless) (for xz/lzma compatibility)
+ /* keep source file (default anyway, so useless) (for xz/lzma compatibility) */
case 'k': break;
- // Modify Block Properties
+ /* Modify Block Properties */
case 'B':
while (argument[1]!=0)
{
@@ -377,20 +377,20 @@ int main(int argc, char** argv)
break;
}
case 'D': LZ4IO_setBlockMode(LZ4IO_blockLinked); argument++; break;
- case 'X': LZ4IO_setBlockChecksumMode(1); argument ++; break;
+ case 'X': LZ4IO_setBlockChecksumMode(1); argument ++; break; /* currently disables */
default : exitBlockProperties=1;
}
if (exitBlockProperties) break;
}
break;
- // Modify Stream properties
+ /* Modify Stream properties */
case 'S': if (argument[1]=='x') { LZ4IO_setStreamChecksumMode(0); argument++; break; } else { badusage(); }
- // Benchmark
+ /* Benchmark */
case 'b': bench=1; break;
- // Modify Nb Iterations (benchmark only)
+ /* Modify Nb Iterations (benchmark only) */
case 'i':
if ((argument[1] >='1') && (argument[1] <='9'))
{
@@ -400,22 +400,23 @@ int main(int argc, char** argv)
}
break;
- // Pause at the end (hidden option)
+ /* Pause at the end (hidden option) */
case 'p': main_pause=1; BMK_SetPause(); break;
+ /* Specific commands for customized versions */
EXTENDED_ARGUMENTS;
- // Unrecognised command
+ /* Unrecognised command */
default : badusage();
}
}
continue;
}
- // first provided filename is input
+ /* first provided filename is input */
if (!input_filename) { input_filename=argument; filenamesStart=i; continue; }
- // second provided filename is output
+ /* second provided filename is output */
if (!output_filename)
{
output_filename=argument;
@@ -427,25 +428,25 @@ int main(int argc, char** argv)
DISPLAYLEVEL(3, WELCOME_MESSAGE);
if (!decode) DISPLAYLEVEL(4, "Blocks size : %i KB\n", blockSize>>10);
- // No input filename ==> use stdin
+ /* No input filename ==> use stdin */
if(!input_filename) { input_filename=stdinmark; }
- // Check if input or output are defined as console; trigger an error in this case
- if (!strcmp(input_filename, stdinmark) && IS_CONSOLE(stdin) ) badusage();
+ /* Check if input or output are defined as console; trigger an error in this case */
+ if (!strcmp(input_filename, stdinmark) && IS_CONSOLE(stdin) ) badusage();
- // Check if benchmark is selected
+ /* Check if benchmark is selected */
if (bench) return BMK_benchFile(argv+filenamesStart, argc-filenamesStart, cLevel);
- // No output filename ==> try to select one automatically (when possible)
+ /* No output filename ==> try to select one automatically (when possible) */
while (!output_filename)
{
- if (!IS_CONSOLE(stdout)) { output_filename=stdoutmark; break; } // Default to stdout whenever possible (i.e. not a console)
- if ((!decode) && !(forceCompress)) // auto-determine compression or decompression, based on file extension
+ if (!IS_CONSOLE(stdout)) { output_filename=stdoutmark; break; } /* Default to stdout whenever possible (i.e. not a console) */
+ if ((!decode) && !(forceCompress)) /* auto-determine compression or decompression, based on file extension */
{
size_t l = strlen(input_filename);
if (!strcmp(input_filename+(l-4), LZ4_EXTENSION)) decode=1;
}
- if (!decode) // compression to file
+ if (!decode) /* compression to file */
{
size_t l = strlen(input_filename);
dynNameSpace = (char*)calloc(1,l+5);
@@ -455,7 +456,7 @@ int main(int argc, char** argv)
DISPLAYLEVEL(2, "Compressed filename will be : %s \n", output_filename);
break;
}
- // decompression to file (automatic name will work only if input filename has correct format extension)
+ /* decompression to file (automatic name will work only if input filename has correct format extension) */
{
size_t outl;
size_t inl = strlen(input_filename);
@@ -470,19 +471,19 @@ int main(int argc, char** argv)
}
}
- // No warning message in pure pipe mode (stdin + stdout)
+ /* Check if output is defined as console; trigger an error in this case */
+ if (!strcmp(output_filename,stdoutmark) && IS_CONSOLE(stdout) && !forceStdout) badusage();
+
+ /* No warning message in pure pipe mode (stdin + stdout) */
if (!strcmp(input_filename, stdinmark) && !strcmp(output_filename,stdoutmark) && (displayLevel==2)) displayLevel=1;
- // Check if input or output are defined as console; trigger an error in this case
- if (!strcmp(input_filename, stdinmark) && IS_CONSOLE(stdin) ) badusage();
- if (!strcmp(output_filename,stdoutmark) && IS_CONSOLE(stdout) && !forceStdout) badusage();
- // IO Stream/File
+ /* IO Stream/File */
LZ4IO_setNotificationLevel(displayLevel);
if (decode) DEFAULT_DECOMPRESSOR(input_filename, output_filename);
else
- // compression is default action
{
+ /* compression is default action */
if (legacy_format)
{
DISPLAYLEVEL(3, "! Generating compressed LZ4 using Legacy format (deprecated) ! \n");