Yann Collet | 4ded9e5 | 2016-08-30 10:04:33 -0700 | [diff] [blame] | 1 | /** |
| 2 | * Copyright (c) 2016-present, Yann Collet, Facebook, Inc. |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * This source code is licensed under the BSD-style license found in the |
| 6 | * LICENSE file in the root directory of this source tree. An additional grant |
| 7 | * of patent rights can be found in the PATENTS file in the same directory. |
| 8 | */ |
Yann Collet | 5f53b03 | 2016-08-28 10:00:49 -0700 | [diff] [blame] | 9 | |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 10 | |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 11 | /*-************************************ |
Yann Collet | 2cac5b3 | 2016-07-13 14:15:08 +0200 | [diff] [blame] | 12 | * Tuning parameters |
| 13 | **************************************/ |
Yann Collet | 2b1a363 | 2016-07-13 15:16:00 +0200 | [diff] [blame] | 14 | #ifndef ZSTDCLI_CLEVEL_DEFAULT |
| 15 | # define ZSTDCLI_CLEVEL_DEFAULT 3 |
Yann Collet | 2cac5b3 | 2016-07-13 14:15:08 +0200 | [diff] [blame] | 16 | #endif |
| 17 | |
Yann Collet | fe0590f | 2016-08-12 18:04:15 +0200 | [diff] [blame] | 18 | #ifndef ZSTDCLI_CLEVEL_MAX |
Yann Collet | 0977f7e | 2016-09-21 12:24:43 +0200 | [diff] [blame] | 19 | # define ZSTDCLI_CLEVEL_MAX 19 /* when not using --ultra */ |
Yann Collet | fe0590f | 2016-08-12 18:04:15 +0200 | [diff] [blame] | 20 | #endif |
| 21 | |
Yann Collet | 2cac5b3 | 2016-07-13 14:15:08 +0200 | [diff] [blame] | 22 | |
| 23 | /*-************************************ |
Yann Collet | 52afb39 | 2016-11-16 08:50:54 -0800 | [diff] [blame] | 24 | * Dependencies |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 25 | **************************************/ |
Yann Collet | 92c986b | 2016-07-04 01:37:30 +0200 | [diff] [blame] | 26 | #include "util.h" /* Compiler options, UTIL_HAS_CREATEFILELIST */ |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 27 | #include <string.h> /* strcmp, strlen */ |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 28 | #include <errno.h> /* errno */ |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 29 | #include "fileio.h" |
| 30 | #ifndef ZSTD_NOBENCH |
Przemyslaw Skibinski | 26306fc | 2016-11-03 11:38:01 +0100 | [diff] [blame] | 31 | # include "bench.h" /* BMK_benchFiles, BMK_SetNbSeconds */ |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 32 | #endif |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 33 | #ifndef ZSTD_NODICT |
| 34 | # include "dibio.h" |
| 35 | #endif |
Yann Collet | d3b7f8d | 2016-06-04 19:47:02 +0200 | [diff] [blame] | 36 | #define ZSTD_STATIC_LINKING_ONLY /* ZSTD_maxCLevel */ |
| 37 | #include "zstd.h" /* ZSTD_VERSION_STRING */ |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 38 | |
| 39 | |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 40 | /*-************************************ |
| 41 | * OS-specific Includes |
| 42 | **************************************/ |
| 43 | #if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__) |
| 44 | # include <io.h> /* _isatty */ |
| 45 | # define IS_CONSOLE(stdStream) _isatty(_fileno(stdStream)) |
Yann Collet | 0977f7e | 2016-09-21 12:24:43 +0200 | [diff] [blame] | 46 | #elif defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) || defined(_POSIX_SOURCE) || (defined(__APPLE__) && defined(__MACH__)) /* https://sourceforge.net/p/predef/wiki/OperatingSystems/ */ |
| 47 | # include <unistd.h> /* isatty */ |
| 48 | # define IS_CONSOLE(stdStream) isatty(fileno(stdStream)) |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 49 | #else |
Yann Collet | 0977f7e | 2016-09-21 12:24:43 +0200 | [diff] [blame] | 50 | # define IS_CONSOLE(stdStream) 0 |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 51 | #endif |
| 52 | |
| 53 | |
| 54 | /*-************************************ |
| 55 | * Constants |
| 56 | **************************************/ |
| 57 | #define COMPRESSOR_NAME "zstd command line interface" |
| 58 | #ifndef ZSTD_VERSION |
| 59 | # define ZSTD_VERSION "v" ZSTD_VERSION_STRING |
| 60 | #endif |
| 61 | #define AUTHOR "Yann Collet" |
| 62 | #define WELCOME_MESSAGE "*** %s %i-bits %s, by %s ***\n", COMPRESSOR_NAME, (int)(sizeof(size_t)*8), ZSTD_VERSION, AUTHOR |
| 63 | |
| 64 | #define ZSTD_EXTENSION ".zst" |
| 65 | #define ZSTD_CAT "zstdcat" |
| 66 | #define ZSTD_UNZSTD "unzstd" |
| 67 | |
| 68 | #define KB *(1 <<10) |
| 69 | #define MB *(1 <<20) |
| 70 | #define GB *(1U<<30) |
| 71 | |
David Lam | ac43e95 | 2016-08-12 14:49:05 -0700 | [diff] [blame] | 72 | #define DEFAULT_DISPLAY_LEVEL 2 |
| 73 | |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 74 | static const char* g_defaultDictName = "dictionary"; |
| 75 | static const unsigned g_defaultMaxDictSize = 110 KB; |
Yann Collet | c843142 | 2016-09-01 15:05:57 -0700 | [diff] [blame] | 76 | static const int g_defaultDictCLevel = 3; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 77 | static const unsigned g_defaultSelectivityLevel = 9; |
| 78 | |
| 79 | |
| 80 | /*-************************************ |
| 81 | * Display Macros |
| 82 | **************************************/ |
| 83 | #define DISPLAY(...) fprintf(displayOut, __VA_ARGS__) |
| 84 | #define DISPLAYLEVEL(l, ...) if (displayLevel>=l) { DISPLAY(__VA_ARGS__); } |
| 85 | static FILE* displayOut; |
David Lam | ac43e95 | 2016-08-12 14:49:05 -0700 | [diff] [blame] | 86 | static unsigned displayLevel = DEFAULT_DISPLAY_LEVEL; /* 0 : no display, 1: errors, 2 : + result + interaction + warnings, 3 : + progression, 4 : + information */ |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 87 | |
| 88 | |
| 89 | /*-************************************ |
| 90 | * Command Line |
| 91 | **************************************/ |
| 92 | static int usage(const char* programName) |
| 93 | { |
| 94 | DISPLAY( "Usage :\n"); |
| 95 | DISPLAY( " %s [args] [FILE(s)] [-o file]\n", programName); |
| 96 | DISPLAY( "\n"); |
| 97 | DISPLAY( "FILE : a filename\n"); |
| 98 | DISPLAY( " with no FILE, or when FILE is - , read standard input\n"); |
| 99 | DISPLAY( "Arguments :\n"); |
| 100 | #ifndef ZSTD_NOCOMPRESS |
inikep | 5a54870 | 2016-08-18 09:00:25 +0200 | [diff] [blame] | 101 | DISPLAY( " -# : # compression level (1-%d, default:%d) \n", ZSTDCLI_CLEVEL_MAX, ZSTDCLI_CLEVEL_DEFAULT); |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 102 | #endif |
| 103 | #ifndef ZSTD_NODECOMPRESS |
| 104 | DISPLAY( " -d : decompression \n"); |
| 105 | #endif |
| 106 | DISPLAY( " -D file: use `file` as Dictionary \n"); |
| 107 | DISPLAY( " -o file: result stored into `file` (only if 1 input file) \n"); |
| 108 | DISPLAY( " -f : overwrite output without prompting \n"); |
Yann Collet | a7a5d77 | 2016-07-02 00:37:32 +0200 | [diff] [blame] | 109 | DISPLAY( "--rm : remove source file(s) after successful de/compression \n"); |
Yann Collet | d916c90 | 2016-07-04 00:42:58 +0200 | [diff] [blame] | 110 | DISPLAY( " -k : preserve source file(s) (default) \n"); |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 111 | DISPLAY( " -h/-H : display help/long help and exit\n"); |
| 112 | return 0; |
| 113 | } |
| 114 | |
| 115 | static int usage_advanced(const char* programName) |
| 116 | { |
| 117 | DISPLAY(WELCOME_MESSAGE); |
| 118 | usage(programName); |
| 119 | DISPLAY( "\n"); |
| 120 | DISPLAY( "Advanced arguments :\n"); |
| 121 | DISPLAY( " -V : display Version number and exit\n"); |
David Lam | ac43e95 | 2016-08-12 14:49:05 -0700 | [diff] [blame] | 122 | DISPLAY( " -v : verbose mode; specify multiple times to increase log level (default:%d)\n", DEFAULT_DISPLAY_LEVEL); |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 123 | DISPLAY( " -q : suppress warnings; specify twice to suppress errors too\n"); |
| 124 | DISPLAY( " -c : force write to standard output, even if it is the console\n"); |
| 125 | #ifdef UTIL_HAS_CREATEFILELIST |
| 126 | DISPLAY( " -r : operate recursively on directories\n"); |
| 127 | #endif |
| 128 | #ifndef ZSTD_NOCOMPRESS |
Yann Collet | fe0590f | 2016-08-12 18:04:15 +0200 | [diff] [blame] | 129 | DISPLAY( "--ultra : enable levels beyond %i, up to %i (requires more memory)\n", ZSTDCLI_CLEVEL_MAX, ZSTD_maxCLevel()); |
Yann Collet | b09b12c | 2016-06-09 22:59:51 +0200 | [diff] [blame] | 130 | DISPLAY( "--no-dictID : don't write dictID into header (dictionary compression)\n"); |
Yann Collet | c98f8e7 | 2016-06-20 16:31:24 +0200 | [diff] [blame] | 131 | DISPLAY( "--[no-]check : integrity check (default:enabled)\n"); |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 132 | #endif |
Yann Collet | 6381e99 | 2016-05-31 02:29:45 +0200 | [diff] [blame] | 133 | #ifndef ZSTD_NODECOMPRESS |
Yann Collet | 2c4acda | 2016-06-02 17:05:50 +0200 | [diff] [blame] | 134 | DISPLAY( "--test : test compressed file integrity \n"); |
Yann Collet | b09b12c | 2016-06-09 22:59:51 +0200 | [diff] [blame] | 135 | DISPLAY( "--[no-]sparse : sparse mode (default:enabled on file, disabled on stdout)\n"); |
Yann Collet | 6381e99 | 2016-05-31 02:29:45 +0200 | [diff] [blame] | 136 | #endif |
Yann Collet | d4cda27 | 2016-10-14 13:13:13 -0700 | [diff] [blame] | 137 | DISPLAY( " -M# : Set a memory usage limit for decompression \n"); |
Yann Collet | 6003894 | 2016-09-16 18:52:52 +0200 | [diff] [blame] | 138 | DISPLAY( "-- : All arguments after \"--\" are treated as files \n"); |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 139 | #ifndef ZSTD_NODICT |
| 140 | DISPLAY( "\n"); |
| 141 | DISPLAY( "Dictionary builder :\n"); |
Yann Collet | b09b12c | 2016-06-09 22:59:51 +0200 | [diff] [blame] | 142 | DISPLAY( "--train ## : create a dictionary from a training set of files \n"); |
| 143 | DISPLAY( " -o file : `file` is dictionary name (default: %s) \n", g_defaultDictName); |
| 144 | DISPLAY( "--maxdict ## : limit dictionary to specified size (default : %u) \n", g_defaultMaxDictSize); |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 145 | DISPLAY( " -s# : dictionary selectivity level (default: %u)\n", g_defaultSelectivityLevel); |
Yann Collet | b09b12c | 2016-06-09 22:59:51 +0200 | [diff] [blame] | 146 | DISPLAY( "--dictID ## : force dictionary ID to specified value (default: random)\n"); |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 147 | #endif |
| 148 | #ifndef ZSTD_NOBENCH |
| 149 | DISPLAY( "\n"); |
| 150 | DISPLAY( "Benchmark arguments :\n"); |
| 151 | DISPLAY( " -b# : benchmark file(s), using # compression level (default : 1) \n"); |
| 152 | DISPLAY( " -e# : test all compression levels from -bX to # (default: 1)\n"); |
Yann Collet | a9febe8 | 2016-08-01 13:37:17 +0200 | [diff] [blame] | 153 | DISPLAY( " -i# : minimum evaluation time in seconds (default : 3s)\n"); |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 154 | DISPLAY( " -B# : cut file into independent blocks of size # (default: no block)\n"); |
| 155 | #endif |
| 156 | return 0; |
| 157 | } |
| 158 | |
| 159 | static int badusage(const char* programName) |
| 160 | { |
| 161 | DISPLAYLEVEL(1, "Incorrect parameters\n"); |
| 162 | if (displayLevel >= 1) usage(programName); |
| 163 | return 1; |
| 164 | } |
| 165 | |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 166 | static void waitEnter(void) |
| 167 | { |
| 168 | int unused; |
| 169 | DISPLAY("Press enter to continue...\n"); |
| 170 | unused = getchar(); |
| 171 | (void)unused; |
| 172 | } |
| 173 | |
Yann Collet | 1dd7961 | 2016-06-03 15:14:09 +0200 | [diff] [blame] | 174 | /*! readU32FromChar() : |
Yann Collet | d4cda27 | 2016-10-14 13:13:13 -0700 | [diff] [blame] | 175 | @return : unsigned integer value read from input in `char` format |
| 176 | allows and interprets K, KB, KiB, M, MB and MiB suffix. |
Yann Collet | 1dd7961 | 2016-06-03 15:14:09 +0200 | [diff] [blame] | 177 | Will also modify `*stringPtr`, advancing it to position where it stopped reading. |
Yann Collet | d4cda27 | 2016-10-14 13:13:13 -0700 | [diff] [blame] | 178 | Note : function result can overflow if digit string > MAX_UINT */ |
Yann Collet | 1dd7961 | 2016-06-03 15:14:09 +0200 | [diff] [blame] | 179 | static unsigned readU32FromChar(const char** stringPtr) |
| 180 | { |
| 181 | unsigned result = 0; |
| 182 | while ((**stringPtr >='0') && (**stringPtr <='9')) |
| 183 | result *= 10, result += **stringPtr - '0', (*stringPtr)++ ; |
Yann Collet | 33fdd09 | 2016-10-17 17:48:48 -0700 | [diff] [blame] | 184 | if ((**stringPtr=='K') || (**stringPtr=='M')) { |
| 185 | result <<= 10; |
| 186 | if (**stringPtr=='M') result <<= 10; |
| 187 | (*stringPtr)++ ; |
| 188 | if (**stringPtr=='i') (*stringPtr)++; |
| 189 | if (**stringPtr=='B') (*stringPtr)++; |
| 190 | } |
Yann Collet | 1dd7961 | 2016-06-03 15:14:09 +0200 | [diff] [blame] | 191 | return result; |
| 192 | } |
| 193 | |
Yann Collet | 743b33f | 2016-12-02 15:18:57 -0800 | [diff] [blame] | 194 | /** longCommandWArg() : |
| 195 | * check is *stringPtr is the same as longCommand. |
| 196 | * If yes, @return 1 and advances *stringPtr to the position which immediately follows longCommand. |
| 197 | * @return 0 and doesn't modify *stringPtr otherwise. |
| 198 | */ |
Yann Collet | 70077bc | 2016-10-14 14:41:17 -0700 | [diff] [blame] | 199 | static unsigned longCommandWArg(const char** stringPtr, const char* longCommand) |
| 200 | { |
| 201 | size_t const comSize = strlen(longCommand); |
Yann Collet | 743b33f | 2016-12-02 15:18:57 -0800 | [diff] [blame] | 202 | int const result = !strncmp(*stringPtr, longCommand, comSize); |
Yann Collet | 70077bc | 2016-10-14 14:41:17 -0700 | [diff] [blame] | 203 | if (result) *stringPtr += comSize; |
| 204 | return result; |
| 205 | } |
| 206 | |
Yann Collet | 22de81e | 2016-10-28 13:58:31 -0700 | [diff] [blame] | 207 | typedef enum { zom_compress, zom_decompress, zom_test, zom_bench, zom_train } zstd_operation_mode; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 208 | |
| 209 | #define CLEAN_RETURN(i) { operationResult = (i); goto _end; } |
| 210 | |
Yann Collet | 0977f7e | 2016-09-21 12:24:43 +0200 | [diff] [blame] | 211 | int main(int argCount, const char* argv[]) |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 212 | { |
| 213 | int argNb, |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 214 | forceStdout=0, |
| 215 | main_pause=0, |
| 216 | nextEntryIsDictionary=0, |
| 217 | operationResult=0, |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 218 | nextArgumentIsOutFileName=0, |
Yann Collet | 290aaa7 | 2016-05-30 21:18:52 +0200 | [diff] [blame] | 219 | nextArgumentIsMaxDict=0, |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 220 | nextArgumentIsDictID=0, |
Yann Collet | 743b33f | 2016-12-02 15:18:57 -0800 | [diff] [blame] | 221 | nextArgumentsAreFiles=0, |
Yann Collet | 27b5ac6 | 2016-09-21 14:20:56 +0200 | [diff] [blame] | 222 | ultra=0, |
| 223 | lastCommand = 0; |
Yann Collet | 22de81e | 2016-10-28 13:58:31 -0700 | [diff] [blame] | 224 | zstd_operation_mode operation = zom_compress; |
Yann Collet | 4110534 | 2016-07-27 15:09:11 +0200 | [diff] [blame] | 225 | int cLevel = ZSTDCLI_CLEVEL_DEFAULT; |
| 226 | int cLevelLast = 1; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 227 | unsigned recursive = 0; |
Yann Collet | d4cda27 | 2016-10-14 13:13:13 -0700 | [diff] [blame] | 228 | unsigned memLimit = 0; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 229 | const char** filenameTable = (const char**)malloc(argCount * sizeof(const char*)); /* argCount >= 1 */ |
| 230 | unsigned filenameIdx = 0; |
| 231 | const char* programName = argv[0]; |
| 232 | const char* outFileName = NULL; |
| 233 | const char* dictFileName = NULL; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 234 | unsigned maxDictSize = g_defaultMaxDictSize; |
Yann Collet | 290aaa7 | 2016-05-30 21:18:52 +0200 | [diff] [blame] | 235 | unsigned dictID = 0; |
Yann Collet | 4110534 | 2016-07-27 15:09:11 +0200 | [diff] [blame] | 236 | int dictCLevel = g_defaultDictCLevel; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 237 | unsigned dictSelect = g_defaultSelectivityLevel; |
| 238 | #ifdef UTIL_HAS_CREATEFILELIST |
Yann Collet | 0977f7e | 2016-09-21 12:24:43 +0200 | [diff] [blame] | 239 | const char** extendedFileList = NULL; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 240 | char* fileNamesBuf = NULL; |
| 241 | unsigned fileNamesNb; |
| 242 | #endif |
| 243 | |
| 244 | /* init */ |
Yann Collet | f3a1a84 | 2016-06-05 01:05:01 +0200 | [diff] [blame] | 245 | (void)recursive; (void)cLevelLast; /* not used when ZSTD_NOBENCH set */ |
Yann Collet | 407a11f | 2016-11-03 15:52:01 -0700 | [diff] [blame] | 246 | (void)dictCLevel; (void)dictSelect; (void)dictID; (void)maxDictSize; /* not used when ZSTD_NODICT set */ |
| 247 | (void)ultra; (void)cLevel; /* not used when ZSTD_NOCOMPRESS set */ |
| 248 | (void)memLimit; /* not used when ZSTD_NODECOMPRESS set */ |
Yann Collet | d916c90 | 2016-07-04 00:42:58 +0200 | [diff] [blame] | 249 | if (filenameTable==NULL) { DISPLAY("zstd: %s \n", strerror(errno)); exit(1); } |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 250 | filenameTable[0] = stdinmark; |
| 251 | displayOut = stderr; |
| 252 | /* Pick out program name from path. Don't rely on stdlib because of conflicting behavior */ |
| 253 | { size_t pos; |
| 254 | for (pos = (int)strlen(programName); pos > 0; pos--) { if (programName[pos] == '/') { pos++; break; } } |
| 255 | programName += pos; |
| 256 | } |
| 257 | |
| 258 | /* preset behaviors */ |
Yann Collet | 22de81e | 2016-10-28 13:58:31 -0700 | [diff] [blame] | 259 | if (!strcmp(programName, ZSTD_UNZSTD)) operation=zom_decompress; |
Yann Collet | 743b33f | 2016-12-02 15:18:57 -0800 | [diff] [blame] | 260 | if (!strcmp(programName, ZSTD_CAT)) { operation=zom_decompress; forceStdout=1; FIO_overwriteMode(); outFileName=stdoutmark; displayLevel=1; } |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 261 | |
| 262 | /* command switches */ |
Yann Collet | 1122349 | 2016-10-14 14:07:11 -0700 | [diff] [blame] | 263 | for (argNb=1; argNb<argCount; argNb++) { |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 264 | const char* argument = argv[argNb]; |
| 265 | if(!argument) continue; /* Protection if argument empty */ |
| 266 | |
Yann Collet | 743b33f | 2016-12-02 15:18:57 -0800 | [diff] [blame] | 267 | if (nextArgumentsAreFiles==0) { |
| 268 | /* "-" means stdin/stdout */ |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 269 | if (!strcmp(argument, "-")){ |
| 270 | if (!filenameIdx) { |
| 271 | filenameIdx=1, filenameTable[0]=stdinmark; |
| 272 | outFileName=stdoutmark; |
| 273 | displayLevel-=(displayLevel==2); |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 274 | continue; |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 275 | } } |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 276 | |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 277 | /* Decode commands (note : aggregated commands are allowed) */ |
| 278 | if (argument[0]=='-') { |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 279 | |
Yann Collet | 743b33f | 2016-12-02 15:18:57 -0800 | [diff] [blame] | 280 | if (argument[1]=='-') { |
| 281 | /* long commands (--long-word) */ |
| 282 | if (!strcmp(argument, "--")) { nextArgumentsAreFiles=1; continue; } /* only file names allowed from now on */ |
| 283 | if (!strcmp(argument, "--compress")) { operation=zom_compress; continue; } |
| 284 | if (!strcmp(argument, "--decompress")) { operation=zom_decompress; continue; } |
| 285 | if (!strcmp(argument, "--uncompress")) { operation=zom_decompress; continue; } |
| 286 | if (!strcmp(argument, "--force")) { FIO_overwriteMode(); continue; } |
| 287 | if (!strcmp(argument, "--version")) { displayOut=stdout; DISPLAY(WELCOME_MESSAGE); CLEAN_RETURN(0); } |
| 288 | if (!strcmp(argument, "--help")) { displayOut=stdout; CLEAN_RETURN(usage_advanced(programName)); } |
| 289 | if (!strcmp(argument, "--verbose")) { displayLevel++; continue; } |
| 290 | if (!strcmp(argument, "--quiet")) { displayLevel--; continue; } |
| 291 | if (!strcmp(argument, "--stdout")) { forceStdout=1; outFileName=stdoutmark; displayLevel-=(displayLevel==2); continue; } |
| 292 | if (!strcmp(argument, "--ultra")) { ultra=1; continue; } |
| 293 | if (!strcmp(argument, "--check")) { FIO_setChecksumFlag(2); continue; } |
| 294 | if (!strcmp(argument, "--no-check")) { FIO_setChecksumFlag(0); continue; } |
| 295 | if (!strcmp(argument, "--sparse")) { FIO_setSparseWrite(2); continue; } |
| 296 | if (!strcmp(argument, "--no-sparse")) { FIO_setSparseWrite(0); continue; } |
| 297 | if (!strcmp(argument, "--test")) { operation=zom_test; continue; } |
| 298 | if (!strcmp(argument, "--train")) { operation=zom_train; outFileName=g_defaultDictName; continue; } |
| 299 | if (!strcmp(argument, "--maxdict")) { nextArgumentIsMaxDict=1; lastCommand=1; continue; } |
| 300 | if (!strcmp(argument, "--dictID")) { nextArgumentIsDictID=1; lastCommand=1; continue; } |
| 301 | if (!strcmp(argument, "--no-dictID")) { FIO_setDictIDFlag(0); continue; } |
| 302 | if (!strcmp(argument, "--keep")) { FIO_setRemoveSrcFile(0); continue; } |
| 303 | if (!strcmp(argument, "--rm")) { FIO_setRemoveSrcFile(1); continue; } |
| 304 | |
| 305 | /* long commands with arguments */ |
| 306 | if (longCommandWArg(&argument, "--memlimit=")) { memLimit = readU32FromChar(&argument); continue; } |
| 307 | if (longCommandWArg(&argument, "--memory=")) { memLimit = readU32FromChar(&argument); continue; } |
| 308 | if (longCommandWArg(&argument, "--memlimit-decompress=")) { memLimit = readU32FromChar(&argument); continue; } |
| 309 | /* fall-through, will trigger bad_usage() later on */ |
| 310 | } |
| 311 | |
| 312 | argument++; |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 313 | while (argument[0]!=0) { |
Yann Collet | 27b5ac6 | 2016-09-21 14:20:56 +0200 | [diff] [blame] | 314 | if (lastCommand) { |
| 315 | DISPLAY("error : command must be followed by argument \n"); |
| 316 | return 1; |
| 317 | } |
Yann Collet | c843142 | 2016-09-01 15:05:57 -0700 | [diff] [blame] | 318 | #ifndef ZSTD_NOCOMPRESS |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 319 | /* compression Level */ |
| 320 | if ((*argument>='0') && (*argument<='9')) { |
Yann Collet | fe0590f | 2016-08-12 18:04:15 +0200 | [diff] [blame] | 321 | dictCLevel = cLevel = readU32FromChar(&argument); |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 322 | continue; |
| 323 | } |
Yann Collet | c843142 | 2016-09-01 15:05:57 -0700 | [diff] [blame] | 324 | #endif |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 325 | |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 326 | switch(argument[0]) |
| 327 | { |
| 328 | /* Display help */ |
| 329 | case 'V': displayOut=stdout; DISPLAY(WELCOME_MESSAGE); CLEAN_RETURN(0); /* Version Only */ |
| 330 | case 'H': |
| 331 | case 'h': displayOut=stdout; CLEAN_RETURN(usage_advanced(programName)); |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 332 | |
Yann Collet | 22de81e | 2016-10-28 13:58:31 -0700 | [diff] [blame] | 333 | /* Compress */ |
| 334 | case 'z': operation=zom_compress; argument++; break; |
| 335 | |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 336 | /* Decoding */ |
Yann Collet | 22de81e | 2016-10-28 13:58:31 -0700 | [diff] [blame] | 337 | case 'd': operation=zom_decompress; argument++; break; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 338 | |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 339 | /* Force stdout, even if stdout==console */ |
Yann Collet | fe0590f | 2016-08-12 18:04:15 +0200 | [diff] [blame] | 340 | case 'c': forceStdout=1; outFileName=stdoutmark; argument++; break; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 341 | |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 342 | /* Use file content as dictionary */ |
Yann Collet | 27b5ac6 | 2016-09-21 14:20:56 +0200 | [diff] [blame] | 343 | case 'D': nextEntryIsDictionary = 1; lastCommand = 1; argument++; break; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 344 | |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 345 | /* Overwrite */ |
| 346 | case 'f': FIO_overwriteMode(); forceStdout=1; argument++; break; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 347 | |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 348 | /* Verbose mode */ |
Yann Collet | 988bcf3 | 2016-07-15 19:43:30 +0200 | [diff] [blame] | 349 | case 'v': displayLevel++; argument++; break; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 350 | |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 351 | /* Quiet mode */ |
| 352 | case 'q': displayLevel--; argument++; break; |
Yann Collet | 2c4acda | 2016-06-02 17:05:50 +0200 | [diff] [blame] | 353 | |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 354 | /* keep source file (default); for gzip/xz compatibility */ |
| 355 | case 'k': FIO_setRemoveSrcFile(0); argument++; break; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 356 | |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 357 | /* Checksum */ |
| 358 | case 'C': argument++; FIO_setChecksumFlag(2); break; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 359 | |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 360 | /* test compressed file */ |
Yann Collet | 22de81e | 2016-10-28 13:58:31 -0700 | [diff] [blame] | 361 | case 't': operation=zom_test; argument++; break; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 362 | |
Yann Collet | 2cac5b3 | 2016-07-13 14:15:08 +0200 | [diff] [blame] | 363 | /* destination file name */ |
Yann Collet | 27b5ac6 | 2016-09-21 14:20:56 +0200 | [diff] [blame] | 364 | case 'o': nextArgumentIsOutFileName=1; lastCommand=1; argument++; break; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 365 | |
Yann Collet | d4cda27 | 2016-10-14 13:13:13 -0700 | [diff] [blame] | 366 | /* limit decompression memory */ |
| 367 | case 'M': |
| 368 | argument++; |
| 369 | memLimit = readU32FromChar(&argument); |
| 370 | break; |
| 371 | |
Yann Collet | c4cc9bf | 2016-09-13 17:50:08 +0200 | [diff] [blame] | 372 | #ifdef UTIL_HAS_CREATEFILELIST |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 373 | /* recursive */ |
| 374 | case 'r': recursive=1; argument++; break; |
Yann Collet | c4cc9bf | 2016-09-13 17:50:08 +0200 | [diff] [blame] | 375 | #endif |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 376 | |
Yann Collet | c843142 | 2016-09-01 15:05:57 -0700 | [diff] [blame] | 377 | #ifndef ZSTD_NOBENCH |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 378 | /* Benchmark */ |
Yann Collet | b9550d6 | 2016-10-28 14:43:24 -0700 | [diff] [blame] | 379 | case 'b': operation=zom_bench; argument++; break; |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 380 | |
| 381 | /* range bench (benchmark only) */ |
| 382 | case 'e': |
| 383 | /* compression Level */ |
| 384 | argument++; |
| 385 | cLevelLast = readU32FromChar(&argument); |
| 386 | break; |
| 387 | |
| 388 | /* Modify Nb Iterations (benchmark only) */ |
| 389 | case 'i': |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 390 | argument++; |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 391 | { U32 const iters = readU32FromChar(&argument); |
| 392 | BMK_setNotificationLevel(displayLevel); |
Przemyslaw Skibinski | 26306fc | 2016-11-03 11:38:01 +0100 | [diff] [blame] | 393 | BMK_SetNbSeconds(iters); |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 394 | } |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 395 | break; |
| 396 | |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 397 | /* cut input into blocks (benchmark only) */ |
| 398 | case 'B': |
| 399 | argument++; |
Yann Collet | d4cda27 | 2016-10-14 13:13:13 -0700 | [diff] [blame] | 400 | { size_t const bSize = readU32FromChar(&argument); |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 401 | BMK_setNotificationLevel(displayLevel); |
| 402 | BMK_SetBlockSize(bSize); |
| 403 | } |
| 404 | break; |
Yann Collet | c843142 | 2016-09-01 15:05:57 -0700 | [diff] [blame] | 405 | #endif /* ZSTD_NOBENCH */ |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 406 | |
| 407 | /* Dictionary Selection level */ |
| 408 | case 's': |
| 409 | argument++; |
| 410 | dictSelect = readU32FromChar(&argument); |
| 411 | break; |
| 412 | |
| 413 | /* Pause at the end (-p) or set an additional param (-p#) (hidden option) */ |
| 414 | case 'p': argument++; |
Yann Collet | c843142 | 2016-09-01 15:05:57 -0700 | [diff] [blame] | 415 | #ifndef ZSTD_NOBENCH |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 416 | if ((*argument>='0') && (*argument<='9')) { |
| 417 | BMK_setAdditionalParam(readU32FromChar(&argument)); |
| 418 | } else |
Yann Collet | c843142 | 2016-09-01 15:05:57 -0700 | [diff] [blame] | 419 | #endif |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 420 | main_pause=1; |
| 421 | break; |
| 422 | /* unknown command */ |
| 423 | default : CLEAN_RETURN(badusage(programName)); |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 424 | } |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 425 | } |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 426 | continue; |
| 427 | } /* if (argument[0]=='-') */ |
| 428 | |
| 429 | if (nextArgumentIsMaxDict) { |
| 430 | nextArgumentIsMaxDict = 0; |
Yann Collet | 27b5ac6 | 2016-09-21 14:20:56 +0200 | [diff] [blame] | 431 | lastCommand = 0; |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 432 | maxDictSize = readU32FromChar(&argument); |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 433 | continue; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 434 | } |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 435 | |
| 436 | if (nextArgumentIsDictID) { |
| 437 | nextArgumentIsDictID = 0; |
Yann Collet | 27b5ac6 | 2016-09-21 14:20:56 +0200 | [diff] [blame] | 438 | lastCommand = 0; |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 439 | dictID = readU32FromChar(&argument); |
| 440 | continue; |
| 441 | } |
| 442 | |
| 443 | } /* if (nextArgumentIsAFile==0) */ |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 444 | |
| 445 | if (nextEntryIsDictionary) { |
| 446 | nextEntryIsDictionary = 0; |
Yann Collet | 27b5ac6 | 2016-09-21 14:20:56 +0200 | [diff] [blame] | 447 | lastCommand = 0; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 448 | dictFileName = argument; |
| 449 | continue; |
| 450 | } |
| 451 | |
| 452 | if (nextArgumentIsOutFileName) { |
| 453 | nextArgumentIsOutFileName = 0; |
Yann Collet | 27b5ac6 | 2016-09-21 14:20:56 +0200 | [diff] [blame] | 454 | lastCommand = 0; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 455 | outFileName = argument; |
| 456 | if (!strcmp(outFileName, "-")) outFileName = stdoutmark; |
| 457 | continue; |
| 458 | } |
| 459 | |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 460 | /* add filename to list */ |
| 461 | filenameTable[filenameIdx++] = argument; |
| 462 | } |
| 463 | |
Yann Collet | 714464f | 2016-09-21 16:05:03 +0200 | [diff] [blame] | 464 | if (lastCommand) { DISPLAY("error : command must be followed by argument \n"); return 1; } /* forgotten argument */ |
| 465 | |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 466 | /* Welcome message (if verbose) */ |
| 467 | DISPLAYLEVEL(3, WELCOME_MESSAGE); |
| 468 | |
| 469 | #ifdef UTIL_HAS_CREATEFILELIST |
Yann Collet | 0977f7e | 2016-09-21 12:24:43 +0200 | [diff] [blame] | 470 | if (recursive) { /* at this stage, filenameTable is a list of paths, which can contain both files and directories */ |
| 471 | extendedFileList = UTIL_createFileList(filenameTable, filenameIdx, &fileNamesBuf, &fileNamesNb); |
| 472 | if (extendedFileList) { |
Yann Collet | 415251c | 2016-08-01 14:26:49 +0200 | [diff] [blame] | 473 | unsigned u; |
Yann Collet | 0977f7e | 2016-09-21 12:24:43 +0200 | [diff] [blame] | 474 | for (u=0; u<fileNamesNb; u++) DISPLAYLEVEL(4, "%u %s\n", u, extendedFileList[u]); |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 475 | free((void*)filenameTable); |
Yann Collet | 0977f7e | 2016-09-21 12:24:43 +0200 | [diff] [blame] | 476 | filenameTable = extendedFileList; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 477 | filenameIdx = fileNamesNb; |
| 478 | } |
| 479 | } |
| 480 | #endif |
| 481 | |
| 482 | /* Check if benchmark is selected */ |
Yann Collet | 22de81e | 2016-10-28 13:58:31 -0700 | [diff] [blame] | 483 | if (operation==zom_bench) { |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 484 | #ifndef ZSTD_NOBENCH |
| 485 | BMK_setNotificationLevel(displayLevel); |
| 486 | BMK_benchFiles(filenameTable, filenameIdx, dictFileName, cLevel, cLevelLast); |
| 487 | #endif |
| 488 | goto _end; |
| 489 | } |
| 490 | |
| 491 | /* Check if dictionary builder is selected */ |
Yann Collet | 22de81e | 2016-10-28 13:58:31 -0700 | [diff] [blame] | 492 | if (operation==zom_train) { |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 493 | #ifndef ZSTD_NODICT |
| 494 | ZDICT_params_t dictParams; |
Yann Collet | 5e80dd3 | 2016-07-13 17:38:39 +0200 | [diff] [blame] | 495 | memset(&dictParams, 0, sizeof(dictParams)); |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 496 | dictParams.compressionLevel = dictCLevel; |
| 497 | dictParams.selectivityLevel = dictSelect; |
| 498 | dictParams.notificationLevel = displayLevel; |
Yann Collet | 290aaa7 | 2016-05-30 21:18:52 +0200 | [diff] [blame] | 499 | dictParams.dictID = dictID; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 500 | DiB_trainFromFiles(outFileName, maxDictSize, filenameTable, filenameIdx, dictParams); |
| 501 | #endif |
| 502 | goto _end; |
| 503 | } |
| 504 | |
| 505 | /* No input filename ==> use stdin and stdout */ |
Yann Collet | 87c18b2 | 2016-08-26 01:43:47 +0200 | [diff] [blame] | 506 | filenameIdx += !filenameIdx; /* filenameTable[0] is stdin by default */ |
| 507 | if (!strcmp(filenameTable[0], stdinmark) && !outFileName) outFileName = stdoutmark; /* when input is stdin, default output is stdout */ |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 508 | |
| 509 | /* Check if input/output defined as console; trigger an error in this case */ |
| 510 | if (!strcmp(filenameTable[0], stdinmark) && IS_CONSOLE(stdin) ) CLEAN_RETURN(badusage(programName)); |
Yann Collet | 22de81e | 2016-10-28 13:58:31 -0700 | [diff] [blame] | 511 | if (outFileName && !strcmp(outFileName, stdoutmark) && IS_CONSOLE(stdout) && strcmp(filenameTable[0], stdinmark) && !(forceStdout && (operation==zom_decompress))) |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 512 | CLEAN_RETURN(badusage(programName)); |
| 513 | |
| 514 | /* user-selected output filename, only possible with a single file */ |
| 515 | if (outFileName && strcmp(outFileName,stdoutmark) && strcmp(outFileName,nulmark) && (filenameIdx>1)) { |
| 516 | DISPLAY("Too many files (%u) on the command line. \n", filenameIdx); |
| 517 | CLEAN_RETURN(filenameIdx); |
| 518 | } |
| 519 | |
inikep | 23cec87 | 2016-10-05 11:56:22 +0200 | [diff] [blame] | 520 | #ifndef ZSTD_NOCOMPRESS |
Yann Collet | fe0590f | 2016-08-12 18:04:15 +0200 | [diff] [blame] | 521 | /* check compression level limits */ |
| 522 | { int const maxCLevel = ultra ? ZSTD_maxCLevel() : ZSTDCLI_CLEVEL_MAX; |
| 523 | if (cLevel > maxCLevel) { |
| 524 | DISPLAYLEVEL(2, "Warning : compression level higher than max, reduced to %i \n", maxCLevel); |
| 525 | cLevel = maxCLevel; |
| 526 | } } |
inikep | 23cec87 | 2016-10-05 11:56:22 +0200 | [diff] [blame] | 527 | #endif |
Yann Collet | fe0590f | 2016-08-12 18:04:15 +0200 | [diff] [blame] | 528 | |
| 529 | /* No warning message in pipe mode (stdin + stdout) or multi-files mode */ |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 530 | if (!strcmp(filenameTable[0], stdinmark) && outFileName && !strcmp(outFileName,stdoutmark) && (displayLevel==2)) displayLevel=1; |
Yann Collet | 06dd741 | 2016-07-18 04:06:43 +0200 | [diff] [blame] | 531 | if ((filenameIdx>1) & (displayLevel==2)) displayLevel=1; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 532 | |
| 533 | /* IO Stream/File */ |
| 534 | FIO_setNotificationLevel(displayLevel); |
Yann Collet | 22de81e | 2016-10-28 13:58:31 -0700 | [diff] [blame] | 535 | if (operation==zom_compress) { |
Yann Collet | 0977f7e | 2016-09-21 12:24:43 +0200 | [diff] [blame] | 536 | #ifndef ZSTD_NOCOMPRESS |
Yann Collet | 993060e | 2016-09-21 16:46:08 +0200 | [diff] [blame] | 537 | if ((filenameIdx==1) && outFileName) |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 538 | operationResult = FIO_compressFilename(outFileName, filenameTable[0], dictFileName, cLevel); |
| 539 | else |
| 540 | operationResult = FIO_compressMultipleFilenames(filenameTable, filenameIdx, outFileName ? outFileName : ZSTD_EXTENSION, dictFileName, cLevel); |
Yann Collet | 0977f7e | 2016-09-21 12:24:43 +0200 | [diff] [blame] | 541 | #else |
| 542 | DISPLAY("Compression not supported\n"); |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 543 | #endif |
Yann Collet | 22de81e | 2016-10-28 13:58:31 -0700 | [diff] [blame] | 544 | } else { /* decompression or test */ |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 545 | #ifndef ZSTD_NODECOMPRESS |
Yann Collet | 22de81e | 2016-10-28 13:58:31 -0700 | [diff] [blame] | 546 | if (operation==zom_test) { outFileName=nulmark; FIO_setRemoveSrcFile(0); } /* test mode */ |
Yann Collet | d4cda27 | 2016-10-14 13:13:13 -0700 | [diff] [blame] | 547 | FIO_setMemLimit(memLimit); |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 548 | if (filenameIdx==1 && outFileName) |
| 549 | operationResult = FIO_decompressFilename(outFileName, filenameTable[0], dictFileName); |
| 550 | else |
| 551 | operationResult = FIO_decompressMultipleFilenames(filenameTable, filenameIdx, outFileName ? outFileName : ZSTD_EXTENSION, dictFileName); |
| 552 | #else |
| 553 | DISPLAY("Decompression not supported\n"); |
| 554 | #endif |
| 555 | } |
| 556 | |
| 557 | _end: |
| 558 | if (main_pause) waitEnter(); |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 559 | #ifdef UTIL_HAS_CREATEFILELIST |
Yann Collet | 0977f7e | 2016-09-21 12:24:43 +0200 | [diff] [blame] | 560 | if (extendedFileList) |
| 561 | UTIL_freeFileList(extendedFileList, fileNamesBuf); |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 562 | else |
| 563 | #endif |
| 564 | free((void*)filenameTable); |
| 565 | return operationResult; |
| 566 | } |