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 | |
Yann Collet | 8dafb1a | 2017-01-25 17:01:13 -0800 | [diff] [blame] | 23 | |
Yann Collet | 2cac5b3 | 2016-07-13 14:15:08 +0200 | [diff] [blame] | 24 | /*-************************************ |
Yann Collet | 52afb39 | 2016-11-16 08:50:54 -0800 | [diff] [blame] | 25 | * Dependencies |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 26 | **************************************/ |
Przemyslaw Skibinski | 7a8a03c | 2016-12-21 15:08:44 +0100 | [diff] [blame] | 27 | #include "platform.h" /* IS_CONSOLE, PLATFORM_POSIX_VERSION */ |
| 28 | #include "util.h" /* UTIL_HAS_CREATEFILELIST, UTIL_createFileList */ |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 29 | #include <string.h> /* strcmp, strlen */ |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 30 | #include <errno.h> /* errno */ |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 31 | #include "fileio.h" |
| 32 | #ifndef ZSTD_NOBENCH |
Przemyslaw Skibinski | 26306fc | 2016-11-03 11:38:01 +0100 | [diff] [blame] | 33 | # include "bench.h" /* BMK_benchFiles, BMK_SetNbSeconds */ |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 34 | #endif |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 35 | #ifndef ZSTD_NODICT |
| 36 | # include "dibio.h" |
| 37 | #endif |
Yann Collet | d3b7f8d | 2016-06-04 19:47:02 +0200 | [diff] [blame] | 38 | #define ZSTD_STATIC_LINKING_ONLY /* ZSTD_maxCLevel */ |
| 39 | #include "zstd.h" /* ZSTD_VERSION_STRING */ |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 40 | |
| 41 | |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 42 | /*-************************************ |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 43 | * Constants |
| 44 | **************************************/ |
| 45 | #define COMPRESSOR_NAME "zstd command line interface" |
| 46 | #ifndef ZSTD_VERSION |
| 47 | # define ZSTD_VERSION "v" ZSTD_VERSION_STRING |
| 48 | #endif |
| 49 | #define AUTHOR "Yann Collet" |
| 50 | #define WELCOME_MESSAGE "*** %s %i-bits %s, by %s ***\n", COMPRESSOR_NAME, (int)(sizeof(size_t)*8), ZSTD_VERSION, AUTHOR |
| 51 | |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 52 | #define ZSTD_UNZSTD "unzstd" |
Yann Collet | c09d16b | 2017-02-14 10:45:19 -0800 | [diff] [blame] | 53 | #define ZSTD_CAT "zstdcat" |
| 54 | #define ZSTD_GZ "gzip" |
| 55 | #define ZSTD_GUNZIP "gunzip" |
| 56 | #define ZSTD_GZCAT "gzcat" |
Nick Terrell | aa8bcf3 | 2017-03-13 18:11:07 -0700 | [diff] [blame] | 57 | #define ZSTD_LZMA "lzma" |
| 58 | #define ZSTD_XZ "xz" |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 59 | |
| 60 | #define KB *(1 <<10) |
| 61 | #define MB *(1 <<20) |
| 62 | #define GB *(1U<<30) |
| 63 | |
David Lam | ac43e95 | 2016-08-12 14:49:05 -0700 | [diff] [blame] | 64 | #define DEFAULT_DISPLAY_LEVEL 2 |
| 65 | |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 66 | static const char* g_defaultDictName = "dictionary"; |
| 67 | static const unsigned g_defaultMaxDictSize = 110 KB; |
Yann Collet | c843142 | 2016-09-01 15:05:57 -0700 | [diff] [blame] | 68 | static const int g_defaultDictCLevel = 3; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 69 | static const unsigned g_defaultSelectivityLevel = 9; |
Yann Collet | 8d8513f | 2017-01-30 14:37:08 -0800 | [diff] [blame] | 70 | #define OVERLAP_LOG_DEFAULT 9999 |
| 71 | static U32 g_overlapLog = OVERLAP_LOG_DEFAULT; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 72 | |
| 73 | |
| 74 | /*-************************************ |
| 75 | * Display Macros |
| 76 | **************************************/ |
Sean Purcell | 042ba12 | 2017-03-23 11:13:52 -0700 | [diff] [blame] | 77 | #define DISPLAY(...) fprintf(g_displayOut, __VA_ARGS__) |
| 78 | #define DISPLAYLEVEL(l, ...) { if (g_displayLevel>=l) { DISPLAY(__VA_ARGS__); } } |
| 79 | static int g_displayLevel = DEFAULT_DISPLAY_LEVEL; /* 0 : no display, 1: errors, 2 : + result + interaction + warnings, 3 : + progression, 4 : + information */ |
| 80 | static FILE* g_displayOut; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 81 | |
| 82 | |
| 83 | /*-************************************ |
| 84 | * Command Line |
| 85 | **************************************/ |
| 86 | static int usage(const char* programName) |
| 87 | { |
| 88 | DISPLAY( "Usage :\n"); |
| 89 | DISPLAY( " %s [args] [FILE(s)] [-o file]\n", programName); |
| 90 | DISPLAY( "\n"); |
| 91 | DISPLAY( "FILE : a filename\n"); |
| 92 | DISPLAY( " with no FILE, or when FILE is - , read standard input\n"); |
| 93 | DISPLAY( "Arguments :\n"); |
| 94 | #ifndef ZSTD_NOCOMPRESS |
inikep | 5a54870 | 2016-08-18 09:00:25 +0200 | [diff] [blame] | 95 | 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] | 96 | #endif |
| 97 | #ifndef ZSTD_NODECOMPRESS |
| 98 | DISPLAY( " -d : decompression \n"); |
| 99 | #endif |
| 100 | DISPLAY( " -D file: use `file` as Dictionary \n"); |
| 101 | DISPLAY( " -o file: result stored into `file` (only if 1 input file) \n"); |
Sean Purcell | 680e4e0 | 2017-03-23 11:52:09 -0700 | [diff] [blame] | 102 | DISPLAY( " -f : overwrite output without prompting and (de)compress links \n"); |
Yann Collet | a7a5d77 | 2016-07-02 00:37:32 +0200 | [diff] [blame] | 103 | DISPLAY( "--rm : remove source file(s) after successful de/compression \n"); |
Yann Collet | d916c90 | 2016-07-04 00:42:58 +0200 | [diff] [blame] | 104 | DISPLAY( " -k : preserve source file(s) (default) \n"); |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 105 | DISPLAY( " -h/-H : display help/long help and exit\n"); |
| 106 | return 0; |
| 107 | } |
| 108 | |
| 109 | static int usage_advanced(const char* programName) |
| 110 | { |
| 111 | DISPLAY(WELCOME_MESSAGE); |
| 112 | usage(programName); |
| 113 | DISPLAY( "\n"); |
| 114 | DISPLAY( "Advanced arguments :\n"); |
| 115 | DISPLAY( " -V : display Version number and exit\n"); |
David Lam | ac43e95 | 2016-08-12 14:49:05 -0700 | [diff] [blame] | 116 | 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] | 117 | DISPLAY( " -q : suppress warnings; specify twice to suppress errors too\n"); |
| 118 | DISPLAY( " -c : force write to standard output, even if it is the console\n"); |
| 119 | #ifdef UTIL_HAS_CREATEFILELIST |
Yann Collet | 500014a | 2017-01-19 16:59:56 -0800 | [diff] [blame] | 120 | DISPLAY( " -r : operate recursively on directories \n"); |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 121 | #endif |
| 122 | #ifndef ZSTD_NOCOMPRESS |
Yann Collet | fe0590f | 2016-08-12 18:04:15 +0200 | [diff] [blame] | 123 | 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] | 124 | DISPLAY( "--no-dictID : don't write dictID into header (dictionary compression)\n"); |
Yann Collet | 500014a | 2017-01-19 16:59:56 -0800 | [diff] [blame] | 125 | DISPLAY( "--[no-]check : integrity check (default:enabled) \n"); |
| 126 | #ifdef ZSTD_MULTITHREAD |
| 127 | DISPLAY( " -T# : use # threads for compression (default:1) \n"); |
Yann Collet | 512cbe8 | 2017-01-24 17:02:26 -0800 | [diff] [blame] | 128 | DISPLAY( " -B# : select size of independent sections (default:0==automatic) \n"); |
Yann Collet | 500014a | 2017-01-19 16:59:56 -0800 | [diff] [blame] | 129 | #endif |
Przemyslaw Skibinski | cfd4dc2 | 2017-02-08 15:17:55 +0100 | [diff] [blame] | 130 | #ifdef ZSTD_GZCOMPRESS |
Przemyslaw Skibinski | 4f9eaa7 | 2017-02-08 18:08:09 +0100 | [diff] [blame] | 131 | DISPLAY( "--format=gzip : compress files to the .gz format \n"); |
Przemyslaw Skibinski | cfd4dc2 | 2017-02-08 15:17:55 +0100 | [diff] [blame] | 132 | #endif |
Nick Terrell | aa8bcf3 | 2017-03-13 18:11:07 -0700 | [diff] [blame] | 133 | #ifdef ZSTD_LZMACOMPRESS |
| 134 | DISPLAY( "--format=xz : compress files to the .xz format \n"); |
| 135 | DISPLAY( "--format=lzma : compress files to the .lzma format \n"); |
| 136 | #endif |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 137 | #endif |
Yann Collet | 6381e99 | 2016-05-31 02:29:45 +0200 | [diff] [blame] | 138 | #ifndef ZSTD_NODECOMPRESS |
Yann Collet | 2c4acda | 2016-06-02 17:05:50 +0200 | [diff] [blame] | 139 | DISPLAY( "--test : test compressed file integrity \n"); |
Yann Collet | b09b12c | 2016-06-09 22:59:51 +0200 | [diff] [blame] | 140 | 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] | 141 | #endif |
Yann Collet | d4cda27 | 2016-10-14 13:13:13 -0700 | [diff] [blame] | 142 | DISPLAY( " -M# : Set a memory usage limit for decompression \n"); |
Yann Collet | 6003894 | 2016-09-16 18:52:52 +0200 | [diff] [blame] | 143 | DISPLAY( "-- : All arguments after \"--\" are treated as files \n"); |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 144 | #ifndef ZSTD_NODICT |
| 145 | DISPLAY( "\n"); |
| 146 | DISPLAY( "Dictionary builder :\n"); |
Yann Collet | b09b12c | 2016-06-09 22:59:51 +0200 | [diff] [blame] | 147 | DISPLAY( "--train ## : create a dictionary from a training set of files \n"); |
Nick Terrell | df8415c | 2016-12-31 21:08:24 -0800 | [diff] [blame] | 148 | DISPLAY( "--cover=k=#,d=# : use the cover algorithm with parameters k and d \n"); |
| 149 | DISPLAY( "--optimize-cover[=steps=#,k=#,d=#] : optimize cover parameters with optional parameters\n"); |
Yann Collet | b09b12c | 2016-06-09 22:59:51 +0200 | [diff] [blame] | 150 | DISPLAY( " -o file : `file` is dictionary name (default: %s) \n", g_defaultDictName); |
| 151 | DISPLAY( "--maxdict ## : limit dictionary to specified size (default : %u) \n", g_defaultMaxDictSize); |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 152 | DISPLAY( " -s# : dictionary selectivity level (default: %u)\n", g_defaultSelectivityLevel); |
Yann Collet | b09b12c | 2016-06-09 22:59:51 +0200 | [diff] [blame] | 153 | DISPLAY( "--dictID ## : force dictionary ID to specified value (default: random)\n"); |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 154 | #endif |
| 155 | #ifndef ZSTD_NOBENCH |
| 156 | DISPLAY( "\n"); |
| 157 | DISPLAY( "Benchmark arguments :\n"); |
| 158 | DISPLAY( " -b# : benchmark file(s), using # compression level (default : 1) \n"); |
| 159 | DISPLAY( " -e# : test all compression levels from -bX to # (default: 1)\n"); |
Yann Collet | a9febe8 | 2016-08-01 13:37:17 +0200 | [diff] [blame] | 160 | DISPLAY( " -i# : minimum evaluation time in seconds (default : 3s)\n"); |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 161 | DISPLAY( " -B# : cut file into independent blocks of size # (default: no block)\n"); |
Przemyslaw Skibinski | 40580ff | 2017-02-08 13:49:06 +0100 | [diff] [blame] | 162 | DISPLAY( "--priority=rt : set process priority to real-time\n"); |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 163 | #endif |
| 164 | return 0; |
| 165 | } |
| 166 | |
| 167 | static int badusage(const char* programName) |
| 168 | { |
| 169 | DISPLAYLEVEL(1, "Incorrect parameters\n"); |
Sean Purcell | 042ba12 | 2017-03-23 11:13:52 -0700 | [diff] [blame] | 170 | if (g_displayLevel >= 2) usage(programName); |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 171 | return 1; |
| 172 | } |
| 173 | |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 174 | static void waitEnter(void) |
| 175 | { |
| 176 | int unused; |
| 177 | DISPLAY("Press enter to continue...\n"); |
| 178 | unused = getchar(); |
| 179 | (void)unused; |
| 180 | } |
| 181 | |
Yann Collet | 1dd7961 | 2016-06-03 15:14:09 +0200 | [diff] [blame] | 182 | /*! readU32FromChar() : |
Yann Collet | d4cda27 | 2016-10-14 13:13:13 -0700 | [diff] [blame] | 183 | @return : unsigned integer value read from input in `char` format |
| 184 | allows and interprets K, KB, KiB, M, MB and MiB suffix. |
Yann Collet | 1dd7961 | 2016-06-03 15:14:09 +0200 | [diff] [blame] | 185 | Will also modify `*stringPtr`, advancing it to position where it stopped reading. |
Yann Collet | d4cda27 | 2016-10-14 13:13:13 -0700 | [diff] [blame] | 186 | Note : function result can overflow if digit string > MAX_UINT */ |
Yann Collet | 1dd7961 | 2016-06-03 15:14:09 +0200 | [diff] [blame] | 187 | static unsigned readU32FromChar(const char** stringPtr) |
| 188 | { |
| 189 | unsigned result = 0; |
| 190 | while ((**stringPtr >='0') && (**stringPtr <='9')) |
| 191 | result *= 10, result += **stringPtr - '0', (*stringPtr)++ ; |
Yann Collet | 33fdd09 | 2016-10-17 17:48:48 -0700 | [diff] [blame] | 192 | if ((**stringPtr=='K') || (**stringPtr=='M')) { |
| 193 | result <<= 10; |
| 194 | if (**stringPtr=='M') result <<= 10; |
| 195 | (*stringPtr)++ ; |
| 196 | if (**stringPtr=='i') (*stringPtr)++; |
| 197 | if (**stringPtr=='B') (*stringPtr)++; |
| 198 | } |
Yann Collet | 1dd7961 | 2016-06-03 15:14:09 +0200 | [diff] [blame] | 199 | return result; |
| 200 | } |
| 201 | |
Yann Collet | 743b33f | 2016-12-02 15:18:57 -0800 | [diff] [blame] | 202 | /** longCommandWArg() : |
Yann Collet | 6ccd37c | 2017-01-30 13:07:24 -0800 | [diff] [blame] | 203 | * check if *stringPtr is the same as longCommand. |
Yann Collet | 743b33f | 2016-12-02 15:18:57 -0800 | [diff] [blame] | 204 | * If yes, @return 1 and advances *stringPtr to the position which immediately follows longCommand. |
| 205 | * @return 0 and doesn't modify *stringPtr otherwise. |
| 206 | */ |
Yann Collet | 70077bc | 2016-10-14 14:41:17 -0700 | [diff] [blame] | 207 | static unsigned longCommandWArg(const char** stringPtr, const char* longCommand) |
| 208 | { |
| 209 | size_t const comSize = strlen(longCommand); |
Yann Collet | 743b33f | 2016-12-02 15:18:57 -0800 | [diff] [blame] | 210 | int const result = !strncmp(*stringPtr, longCommand, comSize); |
Yann Collet | 70077bc | 2016-10-14 14:41:17 -0700 | [diff] [blame] | 211 | if (result) *stringPtr += comSize; |
| 212 | return result; |
| 213 | } |
| 214 | |
Przemyslaw Skibinski | 671f28d | 2016-12-13 12:18:07 +0100 | [diff] [blame] | 215 | |
Nick Terrell | df8415c | 2016-12-31 21:08:24 -0800 | [diff] [blame] | 216 | #ifndef ZSTD_NODICT |
| 217 | /** |
| 218 | * parseCoverParameters() : |
| 219 | * reads cover parameters from *stringPtr (e.g. "--cover=smoothing=100,kmin=48,kstep=4,kmax=64,d=8") into *params |
| 220 | * @return 1 means that cover parameters were correct |
| 221 | * @return 0 in case of malformed parameters |
| 222 | */ |
| 223 | static unsigned parseCoverParameters(const char* stringPtr, COVER_params_t *params) |
| 224 | { |
| 225 | memset(params, 0, sizeof(*params)); |
| 226 | for (; ;) { |
Nick Terrell | 3a1fefc | 2017-01-02 12:40:43 -0800 | [diff] [blame] | 227 | if (longCommandWArg(&stringPtr, "k=")) { params->k = readU32FromChar(&stringPtr); if (stringPtr[0]==',') { stringPtr++; continue; } else break; } |
Nick Terrell | df8415c | 2016-12-31 21:08:24 -0800 | [diff] [blame] | 228 | if (longCommandWArg(&stringPtr, "d=")) { params->d = readU32FromChar(&stringPtr); if (stringPtr[0]==',') { stringPtr++; continue; } else break; } |
Nick Terrell | 3a1fefc | 2017-01-02 12:40:43 -0800 | [diff] [blame] | 229 | if (longCommandWArg(&stringPtr, "steps=")) { params->steps = readU32FromChar(&stringPtr); if (stringPtr[0]==',') { stringPtr++; continue; } else break; } |
Nick Terrell | df8415c | 2016-12-31 21:08:24 -0800 | [diff] [blame] | 230 | return 0; |
| 231 | } |
| 232 | if (stringPtr[0] != 0) return 0; |
Nick Terrell | 3a1fefc | 2017-01-02 12:40:43 -0800 | [diff] [blame] | 233 | DISPLAYLEVEL(4, "k=%u\nd=%u\nsteps=%u\n", params->k, params->d, params->steps); |
Nick Terrell | df8415c | 2016-12-31 21:08:24 -0800 | [diff] [blame] | 234 | return 1; |
| 235 | } |
| 236 | #endif |
Yann Collet | 6ccd37c | 2017-01-30 13:07:24 -0800 | [diff] [blame] | 237 | |
| 238 | |
Przemyslaw Skibinski | 671f28d | 2016-12-13 12:18:07 +0100 | [diff] [blame] | 239 | /** parseCompressionParameters() : |
| 240 | * reads compression parameters from *stringPtr (e.g. "--zstd=wlog=23,clog=23,hlog=22,slog=6,slen=3,tlen=48,strat=6") into *params |
| 241 | * @return 1 means that compression parameters were correct |
| 242 | * @return 0 in case of malformed parameters |
| 243 | */ |
| 244 | static unsigned parseCompressionParameters(const char* stringPtr, ZSTD_compressionParameters* params) |
| 245 | { |
| 246 | for ( ; ;) { |
Przemyslaw Skibinski | 671f28d | 2016-12-13 12:18:07 +0100 | [diff] [blame] | 247 | if (longCommandWArg(&stringPtr, "windowLog=") || longCommandWArg(&stringPtr, "wlog=")) { params->windowLog = readU32FromChar(&stringPtr); if (stringPtr[0]==',') { stringPtr++; continue; } else break; } |
| 248 | if (longCommandWArg(&stringPtr, "chainLog=") || longCommandWArg(&stringPtr, "clog=")) { params->chainLog = readU32FromChar(&stringPtr); if (stringPtr[0]==',') { stringPtr++; continue; } else break; } |
| 249 | if (longCommandWArg(&stringPtr, "hashLog=") || longCommandWArg(&stringPtr, "hlog=")) { params->hashLog = readU32FromChar(&stringPtr); if (stringPtr[0]==',') { stringPtr++; continue; } else break; } |
| 250 | if (longCommandWArg(&stringPtr, "searchLog=") || longCommandWArg(&stringPtr, "slog=")) { params->searchLog = readU32FromChar(&stringPtr); if (stringPtr[0]==',') { stringPtr++; continue; } else break; } |
| 251 | if (longCommandWArg(&stringPtr, "searchLength=") || longCommandWArg(&stringPtr, "slen=")) { params->searchLength = readU32FromChar(&stringPtr); if (stringPtr[0]==',') { stringPtr++; continue; } else break; } |
| 252 | if (longCommandWArg(&stringPtr, "targetLength=") || longCommandWArg(&stringPtr, "tlen=")) { params->targetLength = readU32FromChar(&stringPtr); if (stringPtr[0]==',') { stringPtr++; continue; } else break; } |
Przemyslaw Skibinski | c71e552 | 2016-12-13 20:04:32 +0100 | [diff] [blame] | 253 | if (longCommandWArg(&stringPtr, "strategy=") || longCommandWArg(&stringPtr, "strat=")) { params->strategy = (ZSTD_strategy)(1 + readU32FromChar(&stringPtr)); if (stringPtr[0]==',') { stringPtr++; continue; } else break; } |
Yann Collet | 6ccd37c | 2017-01-30 13:07:24 -0800 | [diff] [blame] | 254 | if (longCommandWArg(&stringPtr, "overlapLog=") || longCommandWArg(&stringPtr, "ovlog=")) { g_overlapLog = readU32FromChar(&stringPtr); if (stringPtr[0]==',') { stringPtr++; continue; } else break; } |
Przemyslaw Skibinski | 671f28d | 2016-12-13 12:18:07 +0100 | [diff] [blame] | 255 | return 0; |
| 256 | } |
| 257 | |
| 258 | if (stringPtr[0] != 0) return 0; /* check the end of string */ |
Przemyslaw Skibinski | 897b8bb | 2016-12-13 13:03:41 +0100 | [diff] [blame] | 259 | DISPLAYLEVEL(4, "windowLog=%d\nchainLog=%d\nhashLog=%d\nsearchLog=%d\n", params->windowLog, params->chainLog, params->hashLog, params->searchLog); |
| 260 | DISPLAYLEVEL(4, "searchLength=%d\ntargetLength=%d\nstrategy=%d\n", params->searchLength, params->targetLength, params->strategy); |
Przemyslaw Skibinski | 671f28d | 2016-12-13 12:18:07 +0100 | [diff] [blame] | 261 | return 1; |
| 262 | } |
| 263 | |
| 264 | |
Yann Collet | 22de81e | 2016-10-28 13:58:31 -0700 | [diff] [blame] | 265 | 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] | 266 | |
| 267 | #define CLEAN_RETURN(i) { operationResult = (i); goto _end; } |
| 268 | |
Yann Collet | 0977f7e | 2016-09-21 12:24:43 +0200 | [diff] [blame] | 269 | int main(int argCount, const char* argv[]) |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 270 | { |
| 271 | int argNb, |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 272 | forceStdout=0, |
Sean Purcell | 680e4e0 | 2017-03-23 11:52:09 -0700 | [diff] [blame] | 273 | followLinks=0, |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 274 | main_pause=0, |
| 275 | nextEntryIsDictionary=0, |
| 276 | operationResult=0, |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 277 | nextArgumentIsOutFileName=0, |
Yann Collet | 290aaa7 | 2016-05-30 21:18:52 +0200 | [diff] [blame] | 278 | nextArgumentIsMaxDict=0, |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 279 | nextArgumentIsDictID=0, |
Yann Collet | 743b33f | 2016-12-02 15:18:57 -0800 | [diff] [blame] | 280 | nextArgumentsAreFiles=0, |
Yann Collet | 27b5ac6 | 2016-09-21 14:20:56 +0200 | [diff] [blame] | 281 | ultra=0, |
Yann Collet | 500014a | 2017-01-19 16:59:56 -0800 | [diff] [blame] | 282 | lastCommand = 0, |
Przemyslaw Skibinski | d05014c | 2017-02-07 16:48:01 +0100 | [diff] [blame] | 283 | nbThreads = 1, |
| 284 | setRealTimePrio = 0; |
Yann Collet | 500014a | 2017-01-19 16:59:56 -0800 | [diff] [blame] | 285 | unsigned bench_nbSeconds = 3; /* would be better if this value was synchronized from bench */ |
| 286 | size_t blockSize = 0; |
Yann Collet | 22de81e | 2016-10-28 13:58:31 -0700 | [diff] [blame] | 287 | zstd_operation_mode operation = zom_compress; |
Przemyslaw Skibinski | 671f28d | 2016-12-13 12:18:07 +0100 | [diff] [blame] | 288 | ZSTD_compressionParameters compressionParams; |
Yann Collet | 4110534 | 2016-07-27 15:09:11 +0200 | [diff] [blame] | 289 | int cLevel = ZSTDCLI_CLEVEL_DEFAULT; |
| 290 | int cLevelLast = 1; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 291 | unsigned recursive = 0; |
Yann Collet | d4cda27 | 2016-10-14 13:13:13 -0700 | [diff] [blame] | 292 | unsigned memLimit = 0; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 293 | const char** filenameTable = (const char**)malloc(argCount * sizeof(const char*)); /* argCount >= 1 */ |
| 294 | unsigned filenameIdx = 0; |
| 295 | const char* programName = argv[0]; |
| 296 | const char* outFileName = NULL; |
| 297 | const char* dictFileName = NULL; |
Przemyslaw Skibinski | cb56306 | 2017-02-08 17:37:14 +0100 | [diff] [blame] | 298 | const char* suffix = ZSTD_EXTENSION; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 299 | unsigned maxDictSize = g_defaultMaxDictSize; |
Yann Collet | 290aaa7 | 2016-05-30 21:18:52 +0200 | [diff] [blame] | 300 | unsigned dictID = 0; |
Yann Collet | 4110534 | 2016-07-27 15:09:11 +0200 | [diff] [blame] | 301 | int dictCLevel = g_defaultDictCLevel; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 302 | unsigned dictSelect = g_defaultSelectivityLevel; |
| 303 | #ifdef UTIL_HAS_CREATEFILELIST |
Yann Collet | 0977f7e | 2016-09-21 12:24:43 +0200 | [diff] [blame] | 304 | const char** extendedFileList = NULL; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 305 | char* fileNamesBuf = NULL; |
| 306 | unsigned fileNamesNb; |
| 307 | #endif |
Nick Terrell | df8415c | 2016-12-31 21:08:24 -0800 | [diff] [blame] | 308 | #ifndef ZSTD_NODICT |
| 309 | COVER_params_t coverParams; |
| 310 | int cover = 0; |
| 311 | #endif |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 312 | |
| 313 | /* init */ |
Yann Collet | f3a1a84 | 2016-06-05 01:05:01 +0200 | [diff] [blame] | 314 | (void)recursive; (void)cLevelLast; /* not used when ZSTD_NOBENCH set */ |
Yann Collet | 407a11f | 2016-11-03 15:52:01 -0700 | [diff] [blame] | 315 | (void)dictCLevel; (void)dictSelect; (void)dictID; (void)maxDictSize; /* not used when ZSTD_NODICT set */ |
| 316 | (void)ultra; (void)cLevel; /* not used when ZSTD_NOCOMPRESS set */ |
| 317 | (void)memLimit; /* not used when ZSTD_NODECOMPRESS set */ |
Yann Collet | d916c90 | 2016-07-04 00:42:58 +0200 | [diff] [blame] | 318 | if (filenameTable==NULL) { DISPLAY("zstd: %s \n", strerror(errno)); exit(1); } |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 319 | filenameTable[0] = stdinmark; |
Sean Purcell | 042ba12 | 2017-03-23 11:13:52 -0700 | [diff] [blame] | 320 | g_displayOut = stderr; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 321 | /* Pick out program name from path. Don't rely on stdlib because of conflicting behavior */ |
| 322 | { size_t pos; |
| 323 | for (pos = (int)strlen(programName); pos > 0; pos--) { if (programName[pos] == '/') { pos++; break; } } |
| 324 | programName += pos; |
| 325 | } |
| 326 | |
| 327 | /* preset behaviors */ |
Yann Collet | 22de81e | 2016-10-28 13:58:31 -0700 | [diff] [blame] | 328 | if (!strcmp(programName, ZSTD_UNZSTD)) operation=zom_decompress; |
Sean Purcell | 042ba12 | 2017-03-23 11:13:52 -0700 | [diff] [blame] | 329 | if (!strcmp(programName, ZSTD_CAT)) { operation=zom_decompress; forceStdout=1; FIO_overwriteMode(); outFileName=stdoutmark; g_displayLevel=1; } |
Yann Collet | c09d16b | 2017-02-14 10:45:19 -0800 | [diff] [blame] | 330 | if (!strcmp(programName, ZSTD_GZ)) { suffix = GZ_EXTENSION; FIO_setCompressionType(FIO_gzipCompression); FIO_setRemoveSrcFile(1); } /* behave like gzip */ |
| 331 | if (!strcmp(programName, ZSTD_GUNZIP)) { operation=zom_decompress; FIO_setRemoveSrcFile(1); } /* behave like gunzip */ |
Sean Purcell | 042ba12 | 2017-03-23 11:13:52 -0700 | [diff] [blame] | 332 | if (!strcmp(programName, ZSTD_GZCAT)) { operation=zom_decompress; forceStdout=1; FIO_overwriteMode(); outFileName=stdoutmark; g_displayLevel=1; } /* behave like gzcat */ |
Nick Terrell | aa8bcf3 | 2017-03-13 18:11:07 -0700 | [diff] [blame] | 333 | if (!strcmp(programName, ZSTD_LZMA)) { suffix = LZMA_EXTENSION; FIO_setCompressionType(FIO_lzmaCompression); FIO_setRemoveSrcFile(1); } /* behave like lzma */ |
| 334 | if (!strcmp(programName, ZSTD_XZ)) { suffix = XZ_EXTENSION; FIO_setCompressionType(FIO_xzCompression); FIO_setRemoveSrcFile(1); } /* behave like xz */ |
Przemyslaw Skibinski | 671f28d | 2016-12-13 12:18:07 +0100 | [diff] [blame] | 335 | memset(&compressionParams, 0, sizeof(compressionParams)); |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 336 | |
| 337 | /* command switches */ |
Yann Collet | 1122349 | 2016-10-14 14:07:11 -0700 | [diff] [blame] | 338 | for (argNb=1; argNb<argCount; argNb++) { |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 339 | const char* argument = argv[argNb]; |
| 340 | if(!argument) continue; /* Protection if argument empty */ |
| 341 | |
Yann Collet | 743b33f | 2016-12-02 15:18:57 -0800 | [diff] [blame] | 342 | if (nextArgumentsAreFiles==0) { |
| 343 | /* "-" means stdin/stdout */ |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 344 | if (!strcmp(argument, "-")){ |
| 345 | if (!filenameIdx) { |
| 346 | filenameIdx=1, filenameTable[0]=stdinmark; |
| 347 | outFileName=stdoutmark; |
Sean Purcell | 042ba12 | 2017-03-23 11:13:52 -0700 | [diff] [blame] | 348 | g_displayLevel-=(g_displayLevel==2); |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 349 | continue; |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 350 | } } |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 351 | |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 352 | /* Decode commands (note : aggregated commands are allowed) */ |
| 353 | if (argument[0]=='-') { |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 354 | |
Yann Collet | 743b33f | 2016-12-02 15:18:57 -0800 | [diff] [blame] | 355 | if (argument[1]=='-') { |
| 356 | /* long commands (--long-word) */ |
| 357 | if (!strcmp(argument, "--")) { nextArgumentsAreFiles=1; continue; } /* only file names allowed from now on */ |
| 358 | if (!strcmp(argument, "--compress")) { operation=zom_compress; continue; } |
| 359 | if (!strcmp(argument, "--decompress")) { operation=zom_decompress; continue; } |
| 360 | if (!strcmp(argument, "--uncompress")) { operation=zom_decompress; continue; } |
Sean Purcell | 680e4e0 | 2017-03-23 11:52:09 -0700 | [diff] [blame] | 361 | if (!strcmp(argument, "--force")) { FIO_overwriteMode(); forceStdout=1; followLinks=1; continue; } |
Sean Purcell | 042ba12 | 2017-03-23 11:13:52 -0700 | [diff] [blame] | 362 | if (!strcmp(argument, "--version")) { g_displayOut=stdout; DISPLAY(WELCOME_MESSAGE); CLEAN_RETURN(0); } |
| 363 | if (!strcmp(argument, "--help")) { g_displayOut=stdout; CLEAN_RETURN(usage_advanced(programName)); } |
| 364 | if (!strcmp(argument, "--verbose")) { g_displayLevel++; continue; } |
| 365 | if (!strcmp(argument, "--quiet")) { g_displayLevel--; continue; } |
| 366 | if (!strcmp(argument, "--stdout")) { forceStdout=1; outFileName=stdoutmark; g_displayLevel-=(g_displayLevel==2); continue; } |
Yann Collet | 743b33f | 2016-12-02 15:18:57 -0800 | [diff] [blame] | 367 | if (!strcmp(argument, "--ultra")) { ultra=1; continue; } |
| 368 | if (!strcmp(argument, "--check")) { FIO_setChecksumFlag(2); continue; } |
| 369 | if (!strcmp(argument, "--no-check")) { FIO_setChecksumFlag(0); continue; } |
| 370 | if (!strcmp(argument, "--sparse")) { FIO_setSparseWrite(2); continue; } |
| 371 | if (!strcmp(argument, "--no-sparse")) { FIO_setSparseWrite(0); continue; } |
| 372 | if (!strcmp(argument, "--test")) { operation=zom_test; continue; } |
| 373 | if (!strcmp(argument, "--train")) { operation=zom_train; outFileName=g_defaultDictName; continue; } |
| 374 | if (!strcmp(argument, "--maxdict")) { nextArgumentIsMaxDict=1; lastCommand=1; continue; } |
| 375 | if (!strcmp(argument, "--dictID")) { nextArgumentIsDictID=1; lastCommand=1; continue; } |
| 376 | if (!strcmp(argument, "--no-dictID")) { FIO_setDictIDFlag(0); continue; } |
| 377 | if (!strcmp(argument, "--keep")) { FIO_setRemoveSrcFile(0); continue; } |
| 378 | if (!strcmp(argument, "--rm")) { FIO_setRemoveSrcFile(1); continue; } |
Przemyslaw Skibinski | 0665a35 | 2017-02-07 20:12:59 +0100 | [diff] [blame] | 379 | if (!strcmp(argument, "--priority=rt")) { setRealTimePrio = 1; continue; } |
Yann Collet | c1c040e | 2017-03-01 16:49:20 -0800 | [diff] [blame] | 380 | #ifdef ZSTD_GZCOMPRESS |
Przemyslaw Skibinski | 9704195 | 2017-02-14 09:47:29 +0100 | [diff] [blame] | 381 | if (!strcmp(argument, "--format=gzip")) { suffix = GZ_EXTENSION; FIO_setCompressionType(FIO_gzipCompression); continue; } |
Yann Collet | c1c040e | 2017-03-01 16:49:20 -0800 | [diff] [blame] | 382 | #endif |
Nick Terrell | aa8bcf3 | 2017-03-13 18:11:07 -0700 | [diff] [blame] | 383 | #ifdef ZSTD_LZMACOMPRESS |
| 384 | if (!strcmp(argument, "--format=lzma")) { suffix = LZMA_EXTENSION; FIO_setCompressionType(FIO_lzmaCompression); continue; } |
| 385 | if (!strcmp(argument, "--format=xz")) { suffix = XZ_EXTENSION; FIO_setCompressionType(FIO_xzCompression); continue; } |
| 386 | #endif |
Yann Collet | 743b33f | 2016-12-02 15:18:57 -0800 | [diff] [blame] | 387 | |
| 388 | /* long commands with arguments */ |
Yann Collet | c1c040e | 2017-03-01 16:49:20 -0800 | [diff] [blame] | 389 | #ifndef ZSTD_NODICT |
Nick Terrell | df8415c | 2016-12-31 21:08:24 -0800 | [diff] [blame] | 390 | if (longCommandWArg(&argument, "--cover=")) { |
| 391 | cover=1; if (!parseCoverParameters(argument, &coverParams)) CLEAN_RETURN(badusage(programName)); |
| 392 | continue; |
| 393 | } |
| 394 | if (longCommandWArg(&argument, "--optimize-cover")) { |
| 395 | cover=2; |
| 396 | /* Allow optional arguments following an = */ |
| 397 | if (*argument == 0) { memset(&coverParams, 0, sizeof(coverParams)); } |
| 398 | else if (*argument++ != '=') { CLEAN_RETURN(badusage(programName)); } |
| 399 | else if (!parseCoverParameters(argument, &coverParams)) { CLEAN_RETURN(badusage(programName)); } |
| 400 | continue; |
| 401 | } |
| 402 | #endif |
Yann Collet | 743b33f | 2016-12-02 15:18:57 -0800 | [diff] [blame] | 403 | if (longCommandWArg(&argument, "--memlimit=")) { memLimit = readU32FromChar(&argument); continue; } |
| 404 | if (longCommandWArg(&argument, "--memory=")) { memLimit = readU32FromChar(&argument); continue; } |
| 405 | if (longCommandWArg(&argument, "--memlimit-decompress=")) { memLimit = readU32FromChar(&argument); continue; } |
Yann Collet | 6be2337 | 2017-01-30 11:17:26 -0800 | [diff] [blame] | 406 | if (longCommandWArg(&argument, "--block-size=")) { blockSize = readU32FromChar(&argument); continue; } |
Przemyslaw Skibinski | 671f28d | 2016-12-13 12:18:07 +0100 | [diff] [blame] | 407 | if (longCommandWArg(&argument, "--zstd=")) { if (!parseCompressionParameters(argument, &compressionParams)) CLEAN_RETURN(badusage(programName)); continue; } |
Yann Collet | 743b33f | 2016-12-02 15:18:57 -0800 | [diff] [blame] | 408 | /* fall-through, will trigger bad_usage() later on */ |
| 409 | } |
| 410 | |
| 411 | argument++; |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 412 | while (argument[0]!=0) { |
Yann Collet | 27b5ac6 | 2016-09-21 14:20:56 +0200 | [diff] [blame] | 413 | if (lastCommand) { |
| 414 | DISPLAY("error : command must be followed by argument \n"); |
Przemyslaw Skibinski | 684858e | 2017-02-21 18:17:24 +0100 | [diff] [blame] | 415 | CLEAN_RETURN(1); |
Yann Collet | 27b5ac6 | 2016-09-21 14:20:56 +0200 | [diff] [blame] | 416 | } |
Yann Collet | c843142 | 2016-09-01 15:05:57 -0700 | [diff] [blame] | 417 | #ifndef ZSTD_NOCOMPRESS |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 418 | /* compression Level */ |
| 419 | if ((*argument>='0') && (*argument<='9')) { |
Yann Collet | fe0590f | 2016-08-12 18:04:15 +0200 | [diff] [blame] | 420 | dictCLevel = cLevel = readU32FromChar(&argument); |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 421 | continue; |
| 422 | } |
Yann Collet | c843142 | 2016-09-01 15:05:57 -0700 | [diff] [blame] | 423 | #endif |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 424 | |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 425 | switch(argument[0]) |
| 426 | { |
| 427 | /* Display help */ |
Sean Purcell | 042ba12 | 2017-03-23 11:13:52 -0700 | [diff] [blame] | 428 | case 'V': g_displayOut=stdout; DISPLAY(WELCOME_MESSAGE); CLEAN_RETURN(0); /* Version Only */ |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 429 | case 'H': |
Sean Purcell | 042ba12 | 2017-03-23 11:13:52 -0700 | [diff] [blame] | 430 | case 'h': g_displayOut=stdout; CLEAN_RETURN(usage_advanced(programName)); |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 431 | |
Yann Collet | 22de81e | 2016-10-28 13:58:31 -0700 | [diff] [blame] | 432 | /* Compress */ |
| 433 | case 'z': operation=zom_compress; argument++; break; |
| 434 | |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 435 | /* Decoding */ |
Yann Collet | 2a826e5 | 2016-12-06 17:56:20 -0800 | [diff] [blame] | 436 | case 'd': |
| 437 | #ifndef ZSTD_NOBENCH |
Yann Collet | ab7a579 | 2016-12-28 16:11:09 +0100 | [diff] [blame] | 438 | if (operation==zom_bench) { BMK_setDecodeOnlyMode(1); argument++; break; } /* benchmark decode (hidden option) */ |
Yann Collet | 2a826e5 | 2016-12-06 17:56:20 -0800 | [diff] [blame] | 439 | #endif |
Yann Collet | d946501 | 2016-12-06 16:49:23 -0800 | [diff] [blame] | 440 | operation=zom_decompress; argument++; break; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 441 | |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 442 | /* Force stdout, even if stdout==console */ |
Yann Collet | fe0590f | 2016-08-12 18:04:15 +0200 | [diff] [blame] | 443 | case 'c': forceStdout=1; outFileName=stdoutmark; argument++; break; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 444 | |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 445 | /* Use file content as dictionary */ |
Yann Collet | 27b5ac6 | 2016-09-21 14:20:56 +0200 | [diff] [blame] | 446 | case 'D': nextEntryIsDictionary = 1; lastCommand = 1; argument++; break; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 447 | |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 448 | /* Overwrite */ |
Sean Purcell | 680e4e0 | 2017-03-23 11:52:09 -0700 | [diff] [blame] | 449 | case 'f': FIO_overwriteMode(); forceStdout=1; followLinks=1; argument++; break; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 450 | |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 451 | /* Verbose mode */ |
Sean Purcell | 042ba12 | 2017-03-23 11:13:52 -0700 | [diff] [blame] | 452 | case 'v': g_displayLevel++; argument++; break; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 453 | |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 454 | /* Quiet mode */ |
Sean Purcell | 042ba12 | 2017-03-23 11:13:52 -0700 | [diff] [blame] | 455 | case 'q': g_displayLevel--; argument++; break; |
Yann Collet | 2c4acda | 2016-06-02 17:05:50 +0200 | [diff] [blame] | 456 | |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 457 | /* keep source file (default); for gzip/xz compatibility */ |
| 458 | case 'k': FIO_setRemoveSrcFile(0); argument++; break; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 459 | |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 460 | /* Checksum */ |
| 461 | case 'C': argument++; FIO_setChecksumFlag(2); break; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 462 | |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 463 | /* test compressed file */ |
Yann Collet | 22de81e | 2016-10-28 13:58:31 -0700 | [diff] [blame] | 464 | case 't': operation=zom_test; argument++; break; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 465 | |
Yann Collet | 2cac5b3 | 2016-07-13 14:15:08 +0200 | [diff] [blame] | 466 | /* destination file name */ |
Yann Collet | 27b5ac6 | 2016-09-21 14:20:56 +0200 | [diff] [blame] | 467 | case 'o': nextArgumentIsOutFileName=1; lastCommand=1; argument++; break; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 468 | |
Yann Collet | d4cda27 | 2016-10-14 13:13:13 -0700 | [diff] [blame] | 469 | /* limit decompression memory */ |
| 470 | case 'M': |
| 471 | argument++; |
| 472 | memLimit = readU32FromChar(&argument); |
| 473 | break; |
| 474 | |
Yann Collet | c4cc9bf | 2016-09-13 17:50:08 +0200 | [diff] [blame] | 475 | #ifdef UTIL_HAS_CREATEFILELIST |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 476 | /* recursive */ |
| 477 | case 'r': recursive=1; argument++; break; |
Yann Collet | c4cc9bf | 2016-09-13 17:50:08 +0200 | [diff] [blame] | 478 | #endif |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 479 | |
Yann Collet | c843142 | 2016-09-01 15:05:57 -0700 | [diff] [blame] | 480 | #ifndef ZSTD_NOBENCH |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 481 | /* Benchmark */ |
Yann Collet | 500014a | 2017-01-19 16:59:56 -0800 | [diff] [blame] | 482 | case 'b': |
| 483 | operation=zom_bench; |
| 484 | argument++; |
| 485 | break; |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 486 | |
| 487 | /* range bench (benchmark only) */ |
| 488 | case 'e': |
Yann Collet | 500014a | 2017-01-19 16:59:56 -0800 | [diff] [blame] | 489 | /* compression Level */ |
| 490 | argument++; |
| 491 | cLevelLast = readU32FromChar(&argument); |
| 492 | break; |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 493 | |
| 494 | /* Modify Nb Iterations (benchmark only) */ |
| 495 | case 'i': |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 496 | argument++; |
Yann Collet | 500014a | 2017-01-19 16:59:56 -0800 | [diff] [blame] | 497 | bench_nbSeconds = readU32FromChar(&argument); |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 498 | break; |
| 499 | |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 500 | /* cut input into blocks (benchmark only) */ |
| 501 | case 'B': |
| 502 | argument++; |
Yann Collet | 500014a | 2017-01-19 16:59:56 -0800 | [diff] [blame] | 503 | blockSize = readU32FromChar(&argument); |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 504 | break; |
Yann Collet | 7474526 | 2017-01-02 02:05:45 +0100 | [diff] [blame] | 505 | |
Yann Collet | 500014a | 2017-01-19 16:59:56 -0800 | [diff] [blame] | 506 | #endif /* ZSTD_NOBENCH */ |
| 507 | |
Yann Collet | 7474526 | 2017-01-02 02:05:45 +0100 | [diff] [blame] | 508 | /* nb of threads (hidden option) */ |
| 509 | case 'T': |
| 510 | argument++; |
Yann Collet | 500014a | 2017-01-19 16:59:56 -0800 | [diff] [blame] | 511 | nbThreads = readU32FromChar(&argument); |
Yann Collet | 7474526 | 2017-01-02 02:05:45 +0100 | [diff] [blame] | 512 | break; |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 513 | |
| 514 | /* Dictionary Selection level */ |
| 515 | case 's': |
| 516 | argument++; |
| 517 | dictSelect = readU32FromChar(&argument); |
| 518 | break; |
| 519 | |
| 520 | /* Pause at the end (-p) or set an additional param (-p#) (hidden option) */ |
| 521 | case 'p': argument++; |
Yann Collet | c843142 | 2016-09-01 15:05:57 -0700 | [diff] [blame] | 522 | #ifndef ZSTD_NOBENCH |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 523 | if ((*argument>='0') && (*argument<='9')) { |
| 524 | BMK_setAdditionalParam(readU32FromChar(&argument)); |
| 525 | } else |
Yann Collet | c843142 | 2016-09-01 15:05:57 -0700 | [diff] [blame] | 526 | #endif |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 527 | main_pause=1; |
| 528 | break; |
| 529 | /* unknown command */ |
| 530 | default : CLEAN_RETURN(badusage(programName)); |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 531 | } |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 532 | } |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 533 | continue; |
| 534 | } /* if (argument[0]=='-') */ |
| 535 | |
| 536 | if (nextArgumentIsMaxDict) { |
| 537 | nextArgumentIsMaxDict = 0; |
Yann Collet | 27b5ac6 | 2016-09-21 14:20:56 +0200 | [diff] [blame] | 538 | lastCommand = 0; |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 539 | maxDictSize = readU32FromChar(&argument); |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 540 | continue; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 541 | } |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 542 | |
| 543 | if (nextArgumentIsDictID) { |
| 544 | nextArgumentIsDictID = 0; |
Yann Collet | 27b5ac6 | 2016-09-21 14:20:56 +0200 | [diff] [blame] | 545 | lastCommand = 0; |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 546 | dictID = readU32FromChar(&argument); |
| 547 | continue; |
| 548 | } |
| 549 | |
| 550 | } /* if (nextArgumentIsAFile==0) */ |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 551 | |
| 552 | if (nextEntryIsDictionary) { |
| 553 | nextEntryIsDictionary = 0; |
Yann Collet | 27b5ac6 | 2016-09-21 14:20:56 +0200 | [diff] [blame] | 554 | lastCommand = 0; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 555 | dictFileName = argument; |
| 556 | continue; |
| 557 | } |
| 558 | |
| 559 | if (nextArgumentIsOutFileName) { |
| 560 | nextArgumentIsOutFileName = 0; |
Yann Collet | 27b5ac6 | 2016-09-21 14:20:56 +0200 | [diff] [blame] | 561 | lastCommand = 0; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 562 | outFileName = argument; |
| 563 | if (!strcmp(outFileName, "-")) outFileName = stdoutmark; |
| 564 | continue; |
| 565 | } |
| 566 | |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 567 | /* add filename to list */ |
| 568 | filenameTable[filenameIdx++] = argument; |
| 569 | } |
| 570 | |
Przemyslaw Skibinski | 684858e | 2017-02-21 18:17:24 +0100 | [diff] [blame] | 571 | if (lastCommand) { DISPLAY("error : command must be followed by argument \n"); CLEAN_RETURN(1); } /* forgotten argument */ |
Yann Collet | 714464f | 2016-09-21 16:05:03 +0200 | [diff] [blame] | 572 | |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 573 | /* Welcome message (if verbose) */ |
| 574 | DISPLAYLEVEL(3, WELCOME_MESSAGE); |
Przemyslaw Skibinski | b0f3663 | 2016-12-16 15:41:18 +0100 | [diff] [blame] | 575 | #ifdef _POSIX_C_SOURCE |
| 576 | DISPLAYLEVEL(4, "_POSIX_C_SOURCE defined: %ldL\n", (long) _POSIX_C_SOURCE); |
| 577 | #endif |
| 578 | #ifdef _POSIX_VERSION |
| 579 | DISPLAYLEVEL(4, "_POSIX_VERSION defined: %ldL\n", (long) _POSIX_VERSION); |
| 580 | #endif |
| 581 | #ifdef PLATFORM_POSIX_VERSION |
| 582 | DISPLAYLEVEL(4, "PLATFORM_POSIX_VERSION defined: %ldL\n", (long) PLATFORM_POSIX_VERSION); |
| 583 | #endif |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 584 | |
Sean Purcell | 680e4e0 | 2017-03-23 11:52:09 -0700 | [diff] [blame] | 585 | |
Sean Purcell | dee08ca | 2017-03-23 12:09:35 -0700 | [diff] [blame] | 586 | g_utilDisplayLevel = g_displayLevel; |
Sean Purcell | 680e4e0 | 2017-03-23 11:52:09 -0700 | [diff] [blame] | 587 | if (!followLinks) { |
| 588 | unsigned u; |
| 589 | for (u=0, fileNamesNb=0; u<filenameIdx; u++) { |
| 590 | if (UTIL_isLink(filenameTable[u])) { |
| 591 | DISPLAYLEVEL(2, "Warning : %s is a symbolic link, ignoring\n", filenameTable[u]); |
| 592 | } else { |
| 593 | filenameTable[fileNamesNb++] = filenameTable[u]; |
| 594 | } |
| 595 | } |
| 596 | filenameIdx = fileNamesNb; |
| 597 | } |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 598 | #ifdef UTIL_HAS_CREATEFILELIST |
Yann Collet | 0977f7e | 2016-09-21 12:24:43 +0200 | [diff] [blame] | 599 | if (recursive) { /* at this stage, filenameTable is a list of paths, which can contain both files and directories */ |
Sean Purcell | 680e4e0 | 2017-03-23 11:52:09 -0700 | [diff] [blame] | 600 | extendedFileList = UTIL_createFileList(filenameTable, filenameIdx, &fileNamesBuf, &fileNamesNb, followLinks); |
Yann Collet | 0977f7e | 2016-09-21 12:24:43 +0200 | [diff] [blame] | 601 | if (extendedFileList) { |
Yann Collet | 415251c | 2016-08-01 14:26:49 +0200 | [diff] [blame] | 602 | unsigned u; |
Yann Collet | 0977f7e | 2016-09-21 12:24:43 +0200 | [diff] [blame] | 603 | 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] | 604 | free((void*)filenameTable); |
Yann Collet | 0977f7e | 2016-09-21 12:24:43 +0200 | [diff] [blame] | 605 | filenameTable = extendedFileList; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 606 | filenameIdx = fileNamesNb; |
| 607 | } |
| 608 | } |
| 609 | #endif |
| 610 | |
| 611 | /* Check if benchmark is selected */ |
Yann Collet | 22de81e | 2016-10-28 13:58:31 -0700 | [diff] [blame] | 612 | if (operation==zom_bench) { |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 613 | #ifndef ZSTD_NOBENCH |
Sean Purcell | 042ba12 | 2017-03-23 11:13:52 -0700 | [diff] [blame] | 614 | BMK_setNotificationLevel(g_displayLevel); |
Yann Collet | 500014a | 2017-01-19 16:59:56 -0800 | [diff] [blame] | 615 | BMK_setBlockSize(blockSize); |
| 616 | BMK_setNbThreads(nbThreads); |
| 617 | BMK_setNbSeconds(bench_nbSeconds); |
Przemyslaw Skibinski | d05014c | 2017-02-07 16:48:01 +0100 | [diff] [blame] | 618 | BMK_benchFiles(filenameTable, filenameIdx, dictFileName, cLevel, cLevelLast, &compressionParams, setRealTimePrio); |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 619 | #endif |
Yann Collet | 3dc85ba | 2017-02-02 16:19:09 -0800 | [diff] [blame] | 620 | (void)bench_nbSeconds; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 621 | goto _end; |
| 622 | } |
| 623 | |
| 624 | /* Check if dictionary builder is selected */ |
Yann Collet | 22de81e | 2016-10-28 13:58:31 -0700 | [diff] [blame] | 625 | if (operation==zom_train) { |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 626 | #ifndef ZSTD_NODICT |
Nick Terrell | df8415c | 2016-12-31 21:08:24 -0800 | [diff] [blame] | 627 | if (cover) { |
Nick Terrell | 2fe9126 | 2017-01-27 11:56:02 -0800 | [diff] [blame] | 628 | coverParams.nbThreads = nbThreads; |
Nick Terrell | df8415c | 2016-12-31 21:08:24 -0800 | [diff] [blame] | 629 | coverParams.compressionLevel = dictCLevel; |
Sean Purcell | 042ba12 | 2017-03-23 11:13:52 -0700 | [diff] [blame] | 630 | coverParams.notificationLevel = g_displayLevel; |
Nick Terrell | df8415c | 2016-12-31 21:08:24 -0800 | [diff] [blame] | 631 | coverParams.dictID = dictID; |
Yann Collet | f332ece | 2017-03-23 16:24:02 -0700 | [diff] [blame] | 632 | operationResult = DiB_trainFromFiles(outFileName, maxDictSize, filenameTable, filenameIdx, NULL, &coverParams, cover - 1); |
Nick Terrell | df8415c | 2016-12-31 21:08:24 -0800 | [diff] [blame] | 633 | } else { |
| 634 | ZDICT_params_t dictParams; |
| 635 | memset(&dictParams, 0, sizeof(dictParams)); |
| 636 | dictParams.compressionLevel = dictCLevel; |
| 637 | dictParams.selectivityLevel = dictSelect; |
Sean Purcell | 042ba12 | 2017-03-23 11:13:52 -0700 | [diff] [blame] | 638 | dictParams.notificationLevel = g_displayLevel; |
Nick Terrell | df8415c | 2016-12-31 21:08:24 -0800 | [diff] [blame] | 639 | dictParams.dictID = dictID; |
Yann Collet | f332ece | 2017-03-23 16:24:02 -0700 | [diff] [blame] | 640 | operationResult = DiB_trainFromFiles(outFileName, maxDictSize, filenameTable, filenameIdx, &dictParams, NULL, 0); |
Nick Terrell | df8415c | 2016-12-31 21:08:24 -0800 | [diff] [blame] | 641 | } |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 642 | #endif |
| 643 | goto _end; |
| 644 | } |
| 645 | |
| 646 | /* No input filename ==> use stdin and stdout */ |
Yann Collet | 87c18b2 | 2016-08-26 01:43:47 +0200 | [diff] [blame] | 647 | filenameIdx += !filenameIdx; /* filenameTable[0] is stdin by default */ |
| 648 | 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] | 649 | |
| 650 | /* Check if input/output defined as console; trigger an error in this case */ |
| 651 | if (!strcmp(filenameTable[0], stdinmark) && IS_CONSOLE(stdin) ) CLEAN_RETURN(badusage(programName)); |
Sean Purcell | b8e52d3 | 2017-03-16 16:06:03 -0700 | [diff] [blame] | 652 | 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] | 653 | CLEAN_RETURN(badusage(programName)); |
| 654 | |
| 655 | /* user-selected output filename, only possible with a single file */ |
| 656 | if (outFileName && strcmp(outFileName,stdoutmark) && strcmp(outFileName,nulmark) && (filenameIdx>1)) { |
| 657 | DISPLAY("Too many files (%u) on the command line. \n", filenameIdx); |
| 658 | CLEAN_RETURN(filenameIdx); |
| 659 | } |
| 660 | |
inikep | 23cec87 | 2016-10-05 11:56:22 +0200 | [diff] [blame] | 661 | #ifndef ZSTD_NOCOMPRESS |
Yann Collet | fe0590f | 2016-08-12 18:04:15 +0200 | [diff] [blame] | 662 | /* check compression level limits */ |
| 663 | { int const maxCLevel = ultra ? ZSTD_maxCLevel() : ZSTDCLI_CLEVEL_MAX; |
| 664 | if (cLevel > maxCLevel) { |
| 665 | DISPLAYLEVEL(2, "Warning : compression level higher than max, reduced to %i \n", maxCLevel); |
| 666 | cLevel = maxCLevel; |
| 667 | } } |
inikep | 23cec87 | 2016-10-05 11:56:22 +0200 | [diff] [blame] | 668 | #endif |
Yann Collet | fe0590f | 2016-08-12 18:04:15 +0200 | [diff] [blame] | 669 | |
Yann Collet | f22adae | 2017-01-19 13:46:30 -0800 | [diff] [blame] | 670 | /* No status message in pipe mode (stdin - stdout) or multi-files mode */ |
Sean Purcell | 042ba12 | 2017-03-23 11:13:52 -0700 | [diff] [blame] | 671 | if (!strcmp(filenameTable[0], stdinmark) && outFileName && !strcmp(outFileName,stdoutmark) && (g_displayLevel==2)) g_displayLevel=1; |
| 672 | if ((filenameIdx>1) & (g_displayLevel==2)) g_displayLevel=1; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 673 | |
| 674 | /* IO Stream/File */ |
Sean Purcell | 042ba12 | 2017-03-23 11:13:52 -0700 | [diff] [blame] | 675 | FIO_setNotificationLevel(g_displayLevel); |
Yann Collet | 22de81e | 2016-10-28 13:58:31 -0700 | [diff] [blame] | 676 | if (operation==zom_compress) { |
Yann Collet | 0977f7e | 2016-09-21 12:24:43 +0200 | [diff] [blame] | 677 | #ifndef ZSTD_NOCOMPRESS |
Yann Collet | 500014a | 2017-01-19 16:59:56 -0800 | [diff] [blame] | 678 | FIO_setNbThreads(nbThreads); |
Yann Collet | 512cbe8 | 2017-01-24 17:02:26 -0800 | [diff] [blame] | 679 | FIO_setBlockSize((U32)blockSize); |
Yann Collet | 8d8513f | 2017-01-30 14:37:08 -0800 | [diff] [blame] | 680 | if (g_overlapLog!=OVERLAP_LOG_DEFAULT) FIO_setOverlapLog(g_overlapLog); |
Yann Collet | 993060e | 2016-09-21 16:46:08 +0200 | [diff] [blame] | 681 | if ((filenameIdx==1) && outFileName) |
Przemyslaw Skibinski | 8349d67 | 2016-12-13 13:24:59 +0100 | [diff] [blame] | 682 | operationResult = FIO_compressFilename(outFileName, filenameTable[0], dictFileName, cLevel, &compressionParams); |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 683 | else |
Przemyslaw Skibinski | cb56306 | 2017-02-08 17:37:14 +0100 | [diff] [blame] | 684 | operationResult = FIO_compressMultipleFilenames(filenameTable, filenameIdx, outFileName ? outFileName : suffix, dictFileName, cLevel, &compressionParams); |
Yann Collet | 0977f7e | 2016-09-21 12:24:43 +0200 | [diff] [blame] | 685 | #else |
| 686 | DISPLAY("Compression not supported\n"); |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 687 | #endif |
Yann Collet | 22de81e | 2016-10-28 13:58:31 -0700 | [diff] [blame] | 688 | } else { /* decompression or test */ |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 689 | #ifndef ZSTD_NODECOMPRESS |
Yann Collet | 22de81e | 2016-10-28 13:58:31 -0700 | [diff] [blame] | 690 | if (operation==zom_test) { outFileName=nulmark; FIO_setRemoveSrcFile(0); } /* test mode */ |
Yann Collet | d4cda27 | 2016-10-14 13:13:13 -0700 | [diff] [blame] | 691 | FIO_setMemLimit(memLimit); |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 692 | if (filenameIdx==1 && outFileName) |
| 693 | operationResult = FIO_decompressFilename(outFileName, filenameTable[0], dictFileName); |
| 694 | else |
| 695 | operationResult = FIO_decompressMultipleFilenames(filenameTable, filenameIdx, outFileName ? outFileName : ZSTD_EXTENSION, dictFileName); |
| 696 | #else |
| 697 | DISPLAY("Decompression not supported\n"); |
| 698 | #endif |
| 699 | } |
| 700 | |
| 701 | _end: |
| 702 | if (main_pause) waitEnter(); |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 703 | #ifdef UTIL_HAS_CREATEFILELIST |
Yann Collet | 0977f7e | 2016-09-21 12:24:43 +0200 | [diff] [blame] | 704 | if (extendedFileList) |
| 705 | UTIL_freeFileList(extendedFileList, fileNamesBuf); |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 706 | else |
| 707 | #endif |
| 708 | free((void*)filenameTable); |
| 709 | return operationResult; |
| 710 | } |