Yann Collet | 32fb407 | 2017-08-18 16:52:05 -0700 | [diff] [blame] | 1 | /* |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
Yann Collet | 4ded9e5 | 2016-08-30 10:04:33 -0700 | [diff] [blame] | 3 | * All rights reserved. |
| 4 | * |
Yann Collet | 32fb407 | 2017-08-18 16:52:05 -0700 | [diff] [blame] | 5 | * This source code is licensed under both the BSD-style license (found in the |
| 6 | * LICENSE file in the root directory of this source tree) and the GPLv2 (found |
| 7 | * in the COPYING file in the root directory of this source tree). |
Yann Collet | 3128e03 | 2017-09-08 00:09:23 -0700 | [diff] [blame] | 8 | * You may select, at your option, one of the above-listed licenses. |
Yann Collet | 4ded9e5 | 2016-08-30 10:04:33 -0700 | [diff] [blame] | 9 | */ |
Yann Collet | 5f53b03 | 2016-08-28 10:00:49 -0700 | [diff] [blame] | 10 | |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 11 | |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 12 | /*-************************************ |
Yann Collet | 2cac5b3 | 2016-07-13 14:15:08 +0200 | [diff] [blame] | 13 | * Tuning parameters |
| 14 | **************************************/ |
Yann Collet | 2b1a363 | 2016-07-13 15:16:00 +0200 | [diff] [blame] | 15 | #ifndef ZSTDCLI_CLEVEL_DEFAULT |
| 16 | # define ZSTDCLI_CLEVEL_DEFAULT 3 |
Yann Collet | 2cac5b3 | 2016-07-13 14:15:08 +0200 | [diff] [blame] | 17 | #endif |
| 18 | |
Yann Collet | fe0590f | 2016-08-12 18:04:15 +0200 | [diff] [blame] | 19 | #ifndef ZSTDCLI_CLEVEL_MAX |
Yann Collet | 1c108c8 | 2017-08-19 13:33:50 -0700 | [diff] [blame] | 20 | # define ZSTDCLI_CLEVEL_MAX 19 /* without using --ultra */ |
Yann Collet | fe0590f | 2016-08-12 18:04:15 +0200 | [diff] [blame] | 21 | #endif |
| 22 | |
senhuang42 | a71963c | 2020-09-09 12:35:40 -0400 | [diff] [blame] | 23 | #ifndef ZSTDCLI_NBTHREADS_DEFAULT |
| 24 | # define ZSTDCLI_NBTHREADS_DEFAULT 1 |
senhuang42 | 888c385 | 2020-09-07 18:11:42 -0400 | [diff] [blame] | 25 | #endif |
Yann Collet | 8dafb1a | 2017-01-25 17:01:13 -0800 | [diff] [blame] | 26 | |
Yann Collet | 2cac5b3 | 2016-07-13 14:15:08 +0200 | [diff] [blame] | 27 | /*-************************************ |
Yann Collet | 52afb39 | 2016-11-16 08:50:54 -0800 | [diff] [blame] | 28 | * Dependencies |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 29 | **************************************/ |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 30 | #include "platform.h" /* PLATFORM_POSIX_VERSION */ |
| 31 | #include "util.h" /* UTIL_HAS_CREATEFILELIST, UTIL_createFileList, UTIL_isConsole */ |
Yi Jin | 5324b1e | 2018-12-19 13:26:27 -0800 | [diff] [blame] | 32 | #include <stdlib.h> /* getenv */ |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 33 | #include <string.h> /* strcmp, strlen */ |
Yann Collet | a49417b | 2019-12-02 14:28:18 -0800 | [diff] [blame] | 34 | #include <stdio.h> /* fprintf(), stdin, stdout, stderr */ |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 35 | #include <errno.h> /* errno */ |
Yann Collet | a49417b | 2019-12-02 14:28:18 -0800 | [diff] [blame] | 36 | #include <assert.h> /* assert */ |
| 37 | |
Yann Collet | 1c108c8 | 2017-08-19 13:33:50 -0700 | [diff] [blame] | 38 | #include "fileio.h" /* stdinmark, stdoutmark, ZSTD_EXTENSION */ |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 39 | #ifndef ZSTD_NOBENCH |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 40 | # include "benchzstd.h" /* BMK_benchFilesAdvanced */ |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 41 | #endif |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 42 | #ifndef ZSTD_NODICT |
Yann Collet | 1c108c8 | 2017-08-19 13:33:50 -0700 | [diff] [blame] | 43 | # include "dibio.h" /* ZDICT_cover_params_t, DiB_trainFromFiles() */ |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 44 | #endif |
Nick Terrell | 54a4998 | 2021-02-03 19:53:00 -0800 | [diff] [blame] | 45 | #ifndef ZSTD_NOTRACE |
| 46 | # include "zstdcli_trace.h" |
| 47 | #endif |
W. Felix Handte | 7dcca6b | 2020-05-01 16:20:40 -0400 | [diff] [blame] | 48 | #include "../lib/zstd.h" /* ZSTD_VERSION_STRING, ZSTD_minCLevel, ZSTD_maxCLevel */ |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 49 | #include "fileio_asyncio.h" |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 50 | |
| 51 | |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 52 | /*-************************************ |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 53 | * Constants |
| 54 | **************************************/ |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 55 | #define COMPRESSOR_NAME "Zstandard CLI" |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 56 | #ifndef ZSTD_VERSION |
| 57 | # define ZSTD_VERSION "v" ZSTD_VERSION_STRING |
| 58 | #endif |
| 59 | #define AUTHOR "Yann Collet" |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 60 | #define WELCOME_MESSAGE "*** %s (%i-bit) %s, by %s ***\n", COMPRESSOR_NAME, (int)(sizeof(size_t)*8), ZSTD_VERSION, AUTHOR |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 61 | |
Sean Purcell | 5a61f36 | 2017-04-14 11:33:04 -0700 | [diff] [blame] | 62 | #define ZSTD_ZSTDMT "zstdmt" |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 63 | #define ZSTD_UNZSTD "unzstd" |
Yann Collet | c09d16b | 2017-02-14 10:45:19 -0800 | [diff] [blame] | 64 | #define ZSTD_CAT "zstdcat" |
Yann Collet | cb5eba8 | 2018-01-19 11:26:35 -0800 | [diff] [blame] | 65 | #define ZSTD_ZCAT "zcat" |
Yann Collet | c09d16b | 2017-02-14 10:45:19 -0800 | [diff] [blame] | 66 | #define ZSTD_GZ "gzip" |
| 67 | #define ZSTD_GUNZIP "gunzip" |
| 68 | #define ZSTD_GZCAT "gzcat" |
Nick Terrell | aa8bcf3 | 2017-03-13 18:11:07 -0700 | [diff] [blame] | 69 | #define ZSTD_LZMA "lzma" |
Nick Terrell | 6aeb50e | 2017-06-26 11:24:36 -0700 | [diff] [blame] | 70 | #define ZSTD_UNLZMA "unlzma" |
Nick Terrell | aa8bcf3 | 2017-03-13 18:11:07 -0700 | [diff] [blame] | 71 | #define ZSTD_XZ "xz" |
Nick Terrell | 6aeb50e | 2017-06-26 11:24:36 -0700 | [diff] [blame] | 72 | #define ZSTD_UNXZ "unxz" |
W. Felix Handte | d0519d4 | 2017-09-28 19:18:15 -0400 | [diff] [blame] | 73 | #define ZSTD_LZ4 "lz4" |
| 74 | #define ZSTD_UNLZ4 "unlz4" |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 75 | |
| 76 | #define KB *(1 <<10) |
| 77 | #define MB *(1 <<20) |
| 78 | #define GB *(1U<<30) |
| 79 | |
Yann Collet | 1c108c8 | 2017-08-19 13:33:50 -0700 | [diff] [blame] | 80 | #define DISPLAY_LEVEL_DEFAULT 2 |
David Lam | ac43e95 | 2016-08-12 14:49:05 -0700 | [diff] [blame] | 81 | |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 82 | static const char* g_defaultDictName = "dictionary"; |
| 83 | static const unsigned g_defaultMaxDictSize = 110 KB; |
Yann Collet | c843142 | 2016-09-01 15:05:57 -0700 | [diff] [blame] | 84 | static const int g_defaultDictCLevel = 3; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 85 | static const unsigned g_defaultSelectivityLevel = 9; |
Nick Terrell | c233bdb | 2017-09-22 14:04:39 -0700 | [diff] [blame] | 86 | static const unsigned g_defaultMaxWindowLog = 27; |
Yann Collet | 8d8513f | 2017-01-30 14:37:08 -0800 | [diff] [blame] | 87 | #define OVERLAP_LOG_DEFAULT 9999 |
Stella Lau | 67d4a61 | 2017-09-02 21:10:36 -0700 | [diff] [blame] | 88 | #define LDM_PARAM_DEFAULT 9999 /* Default for parameters where 0 is valid */ |
Yann Collet | 8d8513f | 2017-01-30 14:37:08 -0800 | [diff] [blame] | 89 | static U32 g_overlapLog = OVERLAP_LOG_DEFAULT; |
Stella Lau | a1f04d5 | 2017-09-01 14:52:51 -0700 | [diff] [blame] | 90 | static U32 g_ldmHashLog = 0; |
| 91 | static U32 g_ldmMinMatch = 0; |
Yann Collet | 41c7d0b | 2018-11-21 14:36:57 -0800 | [diff] [blame] | 92 | static U32 g_ldmHashRateLog = LDM_PARAM_DEFAULT; |
Stella Lau | 67d4a61 | 2017-09-02 21:10:36 -0700 | [diff] [blame] | 93 | static U32 g_ldmBucketSizeLog = LDM_PARAM_DEFAULT; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 94 | |
Jennifer Liu | 9d6ed9d | 2018-08-23 12:06:20 -0700 | [diff] [blame] | 95 | |
| 96 | #define DEFAULT_ACCEL 1 |
| 97 | |
| 98 | typedef enum { cover, fastCover, legacy } dictType; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 99 | |
| 100 | /*-************************************ |
| 101 | * Display Macros |
| 102 | **************************************/ |
Yann Collet | 4b4de74 | 2019-12-02 16:08:08 -0800 | [diff] [blame] | 103 | #define DISPLAY_F(f, ...) fprintf((f), __VA_ARGS__) |
| 104 | #define DISPLAYOUT(...) DISPLAY_F(stdout, __VA_ARGS__) |
| 105 | #define DISPLAY(...) DISPLAY_F(stderr, __VA_ARGS__) |
Sean Purcell | 042ba12 | 2017-03-23 11:13:52 -0700 | [diff] [blame] | 106 | #define DISPLAYLEVEL(l, ...) { if (g_displayLevel>=l) { DISPLAY(__VA_ARGS__); } } |
Yann Collet | 1c108c8 | 2017-08-19 13:33:50 -0700 | [diff] [blame] | 107 | static int g_displayLevel = DISPLAY_LEVEL_DEFAULT; /* 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] | 108 | |
| 109 | |
| 110 | /*-************************************ |
Yann Collet | 3324e87 | 2021-01-07 10:37:27 -0800 | [diff] [blame] | 111 | * Check Version (when CLI linked to dynamic library) |
| 112 | **************************************/ |
| 113 | |
| 114 | /* Due to usage of experimental symbols and capabilities by the CLI, |
| 115 | * the CLI must be linked against a dynamic library of same version */ |
| 116 | static void checkLibVersion(void) |
| 117 | { |
| 118 | if (strcmp(ZSTD_VERSION_STRING, ZSTD_versionString())) { |
| 119 | DISPLAYLEVEL(1, "Error : incorrect library version (expecting : %s ; actual : %s ) \n", |
| 120 | ZSTD_VERSION_STRING, ZSTD_versionString()); |
| 121 | DISPLAYLEVEL(1, "Please update library to version %s, or use stand-alone zstd binary \n", |
| 122 | ZSTD_VERSION_STRING); |
| 123 | exit(1); |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 128 | /*! exeNameMatch() : |
| 129 | @return : a non-zero value if exeName matches test, excluding the extension |
| 130 | */ |
| 131 | static int exeNameMatch(const char* exeName, const char* test) |
| 132 | { |
| 133 | return !strncmp(exeName, test, strlen(test)) && |
| 134 | (exeName[strlen(test)] == '\0' || exeName[strlen(test)] == '.'); |
| 135 | } |
| 136 | |
Yann Collet | 3324e87 | 2021-01-07 10:37:27 -0800 | [diff] [blame] | 137 | /*-************************************ |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 138 | * Command Line |
| 139 | **************************************/ |
Yann Collet | 4b4de74 | 2019-12-02 16:08:08 -0800 | [diff] [blame] | 140 | /* print help either in `stderr` or `stdout` depending on originating request |
| 141 | * error (badusage) => stderr |
| 142 | * help (usage_advanced) => stdout |
| 143 | */ |
| 144 | static void usage(FILE* f, const char* programName) |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 145 | { |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 146 | DISPLAY_F(f, "Compress or decompress the INPUT file(s); reads from STDIN if INPUT is `-` or not provided.\n\n"); |
| 147 | DISPLAY_F(f, "Usage: %s [OPTIONS...] [INPUT... | -] [-o OUTPUT]\n\n", programName); |
| 148 | DISPLAY_F(f, "Options:\n"); |
| 149 | DISPLAY_F(f, " -o OUTPUT Write output to a single file, OUTPUT.\n"); |
| 150 | DISPLAY_F(f, " -k, --keep Preserve INPUT file(s). [Default] \n"); |
| 151 | DISPLAY_F(f, " --rm Remove INPUT file(s) after successful (de)compression.\n"); |
| 152 | #ifdef ZSTD_GZCOMPRESS |
| 153 | if (exeNameMatch(programName, ZSTD_GZ)) { /* behave like gzip */ |
| 154 | DISPLAY_F(f, " -n, --no-name Do not store original filename when compressing.\n\n"); |
| 155 | } |
| 156 | #endif |
Jon Palmisciano | 678335c | 2022-12-20 15:34:02 -0500 | [diff] [blame] | 157 | DISPLAY_F(f, "\n"); |
| 158 | #ifndef ZSTD_NOCOMPRESS |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 159 | DISPLAY_F(f, " -# Desired compression level, where `#` is a number between 1 and %d;\n", ZSTDCLI_CLEVEL_MAX); |
| 160 | DISPLAY_F(f, " lower numbers provide faster compression, higher numbers yield\n"); |
| 161 | DISPLAY_F(f, " better compression ratios. [Default: %d]\n\n", ZSTDCLI_CLEVEL_DEFAULT); |
Jon Palmisciano | 678335c | 2022-12-20 15:34:02 -0500 | [diff] [blame] | 162 | #endif |
| 163 | #ifndef ZSTD_NODECOMPRESS |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 164 | DISPLAY_F(f, " -d, --decompress Perform decompression.\n"); |
Jon Palmisciano | 678335c | 2022-12-20 15:34:02 -0500 | [diff] [blame] | 165 | #endif |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 166 | DISPLAY_F(f, " -D DICT Use DICT as the dictionary for compression or decompression.\n\n"); |
| 167 | DISPLAY_F(f, " -f, --force Disable input and output checks. Allows overwriting existing files,\n"); |
| 168 | DISPLAY_F(f, " receiving input from the console, printing output to STDOUT, and\n"); |
| 169 | DISPLAY_F(f, " operating on links, block devices, etc. Unrecognized formats will be\n"); |
| 170 | DISPLAY_F(f, " passed-through through as-is.\n\n"); |
| 171 | |
| 172 | DISPLAY_F(f, " -h Display short usage and exit.\n"); |
| 173 | DISPLAY_F(f, " -H, --help Display full help and exit.\n"); |
| 174 | DISPLAY_F(f, " -V, --version Display the program version and exit.\n"); |
| 175 | DISPLAY_F(f, "\n"); |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 176 | } |
| 177 | |
Yann Collet | 4b4de74 | 2019-12-02 16:08:08 -0800 | [diff] [blame] | 178 | static void usage_advanced(const char* programName) |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 179 | { |
Yann Collet | 4b4de74 | 2019-12-02 16:08:08 -0800 | [diff] [blame] | 180 | DISPLAYOUT(WELCOME_MESSAGE); |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 181 | DISPLAYOUT("\n"); |
Yann Collet | 4b4de74 | 2019-12-02 16:08:08 -0800 | [diff] [blame] | 182 | usage(stdout, programName); |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 183 | DISPLAYOUT("Advanced options:\n"); |
| 184 | DISPLAYOUT(" -c, --stdout Write to STDOUT (even if it is a console) and keep the INPUT file(s).\n\n"); |
Yann Collet | e5366be | 2020-05-08 14:14:46 -0700 | [diff] [blame] | 185 | |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 186 | DISPLAYOUT(" -v, --verbose Enable verbose output; pass multiple times to increase verbosity.\n"); |
| 187 | DISPLAYOUT(" -q, --quiet Suppress warnings; pass twice to suppress errors.\n"); |
| 188 | #ifndef ZSTD_NOTRACE |
| 189 | DISPLAYOUT(" --trace LOG Log tracing information to LOG.\n"); |
| 190 | #endif |
| 191 | DISPLAYOUT("\n"); |
| 192 | DISPLAYOUT(" --[no-]progress Forcibly show/hide the progress counter. NOTE: Any (de)compressed\n"); |
| 193 | DISPLAYOUT(" output to terminal will mix with progress counter text.\n\n"); |
Yann Collet | e5366be | 2020-05-08 14:14:46 -0700 | [diff] [blame] | 194 | |
| 195 | #ifdef UTIL_HAS_CREATEFILELIST |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 196 | DISPLAYOUT(" -r Operate recursively on directories.\n"); |
| 197 | DISPLAYOUT(" --filelist LIST Read a list of files to operate on from LIST.\n"); |
| 198 | DISPLAYOUT(" --output-dir-flat DIR Store processed files in DIR.\n"); |
Yann Collet | e5366be | 2020-05-08 14:14:46 -0700 | [diff] [blame] | 199 | #endif |
| 200 | |
Xin Xie | 9a8ccd4 | 2020-06-19 19:35:51 -0700 | [diff] [blame] | 201 | #ifdef UTIL_HAS_MIRRORFILELIST |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 202 | DISPLAYOUT(" --output-dir-mirror DIR Store processed files in DIR, respecting original directory structure.\n"); |
Xin Xie | 9a8ccd4 | 2020-06-19 19:35:51 -0700 | [diff] [blame] | 203 | #endif |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 204 | if (AIO_supported()) |
| 205 | DISPLAYOUT(" --[no-]asyncio Use asynchronous IO. [Default: Enabled]\n"); |
senhuang42 | 44c54a3 | 2020-08-24 16:14:19 -0400 | [diff] [blame] | 206 | |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 207 | DISPLAYOUT("\n"); |
senhuang42 | 44c54a3 | 2020-08-24 16:14:19 -0400 | [diff] [blame] | 208 | #ifndef ZSTD_NOCOMPRESS |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 209 | DISPLAYOUT(" --[no-]check Add XXH64 integrity checksums during compression. [Default: Add, Validate]\n"); |
senhuang42 | 44c54a3 | 2020-08-24 16:14:19 -0400 | [diff] [blame] | 210 | #ifndef ZSTD_NODECOMPRESS |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 211 | DISPLAYOUT(" If `-d` is present, ignore/validate checksums during decompression.\n"); |
senhuang42 | 44c54a3 | 2020-08-24 16:14:19 -0400 | [diff] [blame] | 212 | #endif |
senhuang42 | e1e41ad | 2020-08-24 17:36:36 -0400 | [diff] [blame] | 213 | #else |
senhuang42 | 44c54a3 | 2020-08-24 16:14:19 -0400 | [diff] [blame] | 214 | #ifdef ZSTD_NOCOMPRESS |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 215 | DISPLAYOUT(" --[no-]check Ignore/validate checksums during decompression. [Default: Validate]"); |
senhuang42 | 44c54a3 | 2020-08-24 16:14:19 -0400 | [diff] [blame] | 216 | #endif |
senhuang42 | e1e41ad | 2020-08-24 17:36:36 -0400 | [diff] [blame] | 217 | #endif /* ZSTD_NOCOMPRESS */ |
Nick Terrell | 54a4998 | 2021-02-03 19:53:00 -0800 | [diff] [blame] | 218 | |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 219 | DISPLAYOUT("\n"); |
| 220 | DISPLAYOUT(" -- Treat remaining arguments after `--` as files.\n"); |
Yann Collet | e5366be | 2020-05-08 14:14:46 -0700 | [diff] [blame] | 221 | |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 222 | #ifndef ZSTD_NOCOMPRESS |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 223 | DISPLAYOUT("\n"); |
| 224 | DISPLAYOUT("Advanced compression options:\n"); |
| 225 | DISPLAYOUT(" --ultra Enable levels beyond %i, up to %i; requires more memory.\n", ZSTDCLI_CLEVEL_MAX, ZSTD_maxCLevel()); |
| 226 | DISPLAYOUT(" --fast[=#] Use to very fast compression levels. [Default: %u]\n", 1); |
Przemyslaw Skibinski | cfd4dc2 | 2017-02-08 15:17:55 +0100 | [diff] [blame] | 227 | #ifdef ZSTD_GZCOMPRESS |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 228 | if (exeNameMatch(programName, ZSTD_GZ)) { /* behave like gzip */ |
| 229 | DISPLAYOUT(" --best Compatibility alias for `-9`.\n"); |
| 230 | } |
| 231 | #endif |
| 232 | DISPLAYOUT(" --adapt Dynamically adapt compression level to I/O conditions.\n"); |
| 233 | DISPLAYOUT(" --long[=#] Enable long distance matching with window log #. [Default: %u]\n", g_defaultMaxWindowLog); |
| 234 | DISPLAYOUT(" --patch-from=REF Use REF as the reference point for Zstandard's diff engine. \n\n"); |
| 235 | # ifdef ZSTD_MULTITHREAD |
| 236 | DISPLAYOUT(" -T# Spawn # compression threads. [Default: 1; pass 0 for core count.]\n"); |
| 237 | DISPLAYOUT(" --single-thread Share a single thread for I/O and compression (slightly different than `-T1`).\n"); |
| 238 | DISPLAYOUT(" --auto-threads={physical|logical}\n"); |
| 239 | DISPLAYOUT(" Use physical/logical cores when using `-T0`. [Default: Physical]\n\n"); |
| 240 | DISPLAYOUT(" -B# Set job size to #. [Default: 0 (automatic)]\n"); |
| 241 | DISPLAYOUT(" --rsyncable Compress using a rsync-friendly method (`-B` sets block size). \n"); |
| 242 | DISPLAYOUT("\n"); |
| 243 | # endif |
| 244 | DISPLAYOUT(" --exclude-compressed Only compress files that are not already compressed.\n\n"); |
| 245 | |
| 246 | DISPLAYOUT(" --stream-size=# Specify size of streaming input from STDIN.\n"); |
| 247 | DISPLAYOUT(" --size-hint=# Optimize compression parameters for streaming input of approximately size #.\n"); |
| 248 | DISPLAYOUT(" --target-compressed-block-size=#\n"); |
| 249 | DISPLAYOUT(" Generate compressed blocks of approximately # size.\n\n"); |
| 250 | DISPLAYOUT(" --no-dictID Don't write `dictID` into the header (dictionary compression only).\n"); |
| 251 | DISPLAYOUT(" --[no-]compress-literals Force (un)compressed literals.\n"); |
| 252 | DISPLAYOUT(" --[no-]row-match-finder Explicitly enable/disable the fast, row-based matchfinder for\n"); |
| 253 | DISPLAYOUT(" the 'greedy', 'lazy', and 'lazy2' strategies.\n"); |
| 254 | |
| 255 | DISPLAYOUT("\n"); |
| 256 | DISPLAYOUT(" --format=zstd Compress files to the `.zst` format. [Default]\n"); |
| 257 | DISPLAYOUT(" --mmap-dict Memory-map dictionary file rather than mallocing and loading all at once"); |
| 258 | #ifdef ZSTD_GZCOMPRESS |
| 259 | DISPLAYOUT(" --format=gzip Compress files to the `.gz` format.\n"); |
Przemyslaw Skibinski | cfd4dc2 | 2017-02-08 15:17:55 +0100 | [diff] [blame] | 260 | #endif |
Nick Terrell | aa8bcf3 | 2017-03-13 18:11:07 -0700 | [diff] [blame] | 261 | #ifdef ZSTD_LZMACOMPRESS |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 262 | DISPLAYOUT(" --format=xz Compress files to the `.xz` format.\n"); |
| 263 | DISPLAYOUT(" --format=lzma Compress files to the `.lzma` format.\n"); |
Nick Terrell | aa8bcf3 | 2017-03-13 18:11:07 -0700 | [diff] [blame] | 264 | #endif |
Sean Purcell | 4de8632 | 2017-04-24 16:48:25 -0700 | [diff] [blame] | 265 | #ifdef ZSTD_LZ4COMPRESS |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 266 | DISPLAYOUT( " --format=lz4 Compress files to the `.lz4` format.\n"); |
Sean Purcell | 4de8632 | 2017-04-24 16:48:25 -0700 | [diff] [blame] | 267 | #endif |
Yann Collet | e5366be | 2020-05-08 14:14:46 -0700 | [diff] [blame] | 268 | #endif /* !ZSTD_NOCOMPRESS */ |
| 269 | |
Yann Collet | 6381e99 | 2016-05-31 02:29:45 +0200 | [diff] [blame] | 270 | #ifndef ZSTD_NODECOMPRESS |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 271 | DISPLAYOUT("\n"); |
| 272 | DISPLAYOUT("Advanced decompression options:\n"); |
| 273 | DISPLAYOUT(" -l Print information about Zstandard-compressed files.\n"); |
| 274 | DISPLAYOUT(" --test Test compressed file integrity.\n"); |
| 275 | DISPLAYOUT(" -M# Set the memory usage limit to # megabytes.\n"); |
Yann Collet | e5366be | 2020-05-08 14:14:46 -0700 | [diff] [blame] | 276 | # if ZSTD_SPARSE_DEFAULT |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 277 | DISPLAYOUT(" --[no-]sparse Enable sparse mode. [Default: Enabled for files, disabled for STDOUT.]\n"); |
Yann Collet | e5366be | 2020-05-08 14:14:46 -0700 | [diff] [blame] | 278 | # else |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 279 | DISPLAYOUT(" --[no-]sparse Enable sparse mode. [Default: Disabled]\n"); |
Yann Collet | e5366be | 2020-05-08 14:14:46 -0700 | [diff] [blame] | 280 | # endif |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 281 | { |
| 282 | char const* passThroughDefault = "Disabled"; |
| 283 | if (exeNameMatch(programName, ZSTD_CAT) || |
| 284 | exeNameMatch(programName, ZSTD_ZCAT) || |
| 285 | exeNameMatch(programName, ZSTD_GZCAT)) { |
| 286 | passThroughDefault = "Enabled"; |
| 287 | } |
| 288 | DISPLAYOUT(" --[no-]pass-through Pass through uncompressed files as-is. [Default: %s]\n", passThroughDefault); |
| 289 | } |
Yann Collet | e5366be | 2020-05-08 14:14:46 -0700 | [diff] [blame] | 290 | #endif /* ZSTD_NODECOMPRESS */ |
| 291 | |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 292 | #ifndef ZSTD_NODICT |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 293 | DISPLAYOUT("\n"); |
| 294 | DISPLAYOUT("Dictionary builder:\n"); |
| 295 | DISPLAYOUT(" --train Create a dictionary from a training set of files.\n\n"); |
| 296 | DISPLAYOUT(" --train-cover[=k=#,d=#,steps=#,split=#,shrink[=#]]\n"); |
| 297 | DISPLAYOUT(" Use the cover algorithm (with optional arguments).\n"); |
| 298 | DISPLAYOUT(" --train-fastcover[=k=#,d=#,f=#,steps=#,split=#,accel=#,shrink[=#]]\n"); |
| 299 | DISPLAYOUT(" Use the fast cover algorithm (with optional arguments).\n\n"); |
| 300 | DISPLAYOUT(" --train-legacy[=s=#] Use the legacy algorithm with selectivity #. [Default: %u]\n", g_defaultSelectivityLevel); |
| 301 | DISPLAYOUT(" -o NAME Use NAME as dictionary name. [Default: %s]\n", g_defaultDictName); |
| 302 | DISPLAYOUT(" --maxdict=# Limit dictionary to specified size #. [Default: %u]\n", g_defaultMaxDictSize); |
| 303 | DISPLAYOUT(" --dictID=# Force dictionary ID to #. [Default: Random]\n"); |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 304 | #endif |
Yann Collet | e5366be | 2020-05-08 14:14:46 -0700 | [diff] [blame] | 305 | |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 306 | #ifndef ZSTD_NOBENCH |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 307 | DISPLAYOUT("\n"); |
| 308 | DISPLAYOUT("Benchmark options:\n"); |
| 309 | DISPLAYOUT(" -b# Perform benchmarking with compression level #. [Default: %d]\n", ZSTDCLI_CLEVEL_DEFAULT); |
| 310 | DISPLAYOUT(" -e# Test all compression levels up to #; starting level is `-b#`. [Default: 1]\n"); |
| 311 | DISPLAYOUT(" -i# Set the minimum evaluation to time # seconds. [Default: 3]\n"); |
| 312 | DISPLAYOUT(" -B# Cut file into independent chunks of size #. [Default: No chunking]\n"); |
| 313 | DISPLAYOUT(" -S Output one benchmark result per input file. [Default: Consolidated result]\n"); |
| 314 | DISPLAYOUT(" --priority=rt Set process priority to real-time.\n"); |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 315 | #endif |
Yann Collet | e5366be | 2020-05-08 14:14:46 -0700 | [diff] [blame] | 316 | |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 317 | } |
| 318 | |
Yann Collet | 4b4de74 | 2019-12-02 16:08:08 -0800 | [diff] [blame] | 319 | static void badusage(const char* programName) |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 320 | { |
Yann Collet | 4b4de74 | 2019-12-02 16:08:08 -0800 | [diff] [blame] | 321 | DISPLAYLEVEL(1, "Incorrect parameters \n"); |
| 322 | if (g_displayLevel >= 2) usage(stderr, programName); |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 323 | } |
| 324 | |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 325 | static void waitEnter(void) |
| 326 | { |
| 327 | int unused; |
Yann Collet | 4b4de74 | 2019-12-02 16:08:08 -0800 | [diff] [blame] | 328 | DISPLAY("Press enter to continue... \n"); |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 329 | unused = getchar(); |
| 330 | (void)unused; |
| 331 | } |
| 332 | |
Sean Purcell | ef30af8 | 2017-03-24 17:06:09 -0700 | [diff] [blame] | 333 | static const char* lastNameFromPath(const char* path) |
| 334 | { |
| 335 | const char* name = path; |
| 336 | if (strrchr(name, '/')) name = strrchr(name, '/') + 1; |
| 337 | if (strrchr(name, '\\')) name = strrchr(name, '\\') + 1; /* windows */ |
| 338 | return name; |
| 339 | } |
| 340 | |
Yann Collet | 9cd5c63 | 2018-05-12 14:29:33 -0700 | [diff] [blame] | 341 | static void errorOut(const char* msg) |
| 342 | { |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 343 | DISPLAYLEVEL(1, "%s \n", msg); exit(1); |
Yann Collet | 9cd5c63 | 2018-05-12 14:29:33 -0700 | [diff] [blame] | 344 | } |
| 345 | |
Yi Jin | 9b2d708 | 2018-12-19 23:41:18 -0800 | [diff] [blame] | 346 | /*! readU32FromCharChecked() : |
Yi Jin | 26a9ae3 | 2018-12-19 16:45:42 -0800 | [diff] [blame] | 347 | * @return 0 if success, and store the result in *value. |
Yann Collet | 6a9b41b | 2018-03-11 19:56:48 -0700 | [diff] [blame] | 348 | * allows and interprets K, KB, KiB, M, MB and MiB suffix. |
| 349 | * Will also modify `*stringPtr`, advancing it to position where it stopped reading. |
Yi Jin | 26a9ae3 | 2018-12-19 16:45:42 -0800 | [diff] [blame] | 350 | * @return 1 if an overflow error occurs */ |
Yi Jin | 9b2d708 | 2018-12-19 23:41:18 -0800 | [diff] [blame] | 351 | static int readU32FromCharChecked(const char** stringPtr, unsigned* value) |
Yann Collet | 1dd7961 | 2016-06-03 15:14:09 +0200 | [diff] [blame] | 352 | { |
| 353 | unsigned result = 0; |
Yann Collet | 9cd5c63 | 2018-05-12 14:29:33 -0700 | [diff] [blame] | 354 | while ((**stringPtr >='0') && (**stringPtr <='9')) { |
Philip Jones | 4e728e2 | 2020-02-18 15:30:59 -0800 | [diff] [blame] | 355 | unsigned const max = ((unsigned)(-1)) / 10; |
| 356 | unsigned last = result; |
Yann Collet | 90c0462 | 2019-04-10 10:03:06 -0700 | [diff] [blame] | 357 | if (result > max) return 1; /* overflow error */ |
| 358 | result *= 10; |
| 359 | result += (unsigned)(**stringPtr - '0'); |
Philip Jones | 4e728e2 | 2020-02-18 15:30:59 -0800 | [diff] [blame] | 360 | if (result < last) return 1; /* overflow error */ |
Yann Collet | 90c0462 | 2019-04-10 10:03:06 -0700 | [diff] [blame] | 361 | (*stringPtr)++ ; |
Yann Collet | 9cd5c63 | 2018-05-12 14:29:33 -0700 | [diff] [blame] | 362 | } |
Yann Collet | 33fdd09 | 2016-10-17 17:48:48 -0700 | [diff] [blame] | 363 | if ((**stringPtr=='K') || (**stringPtr=='M')) { |
Yann Collet | 9cd5c63 | 2018-05-12 14:29:33 -0700 | [diff] [blame] | 364 | unsigned const maxK = ((unsigned)(-1)) >> 10; |
Yann Collet | 90c0462 | 2019-04-10 10:03:06 -0700 | [diff] [blame] | 365 | if (result > maxK) return 1; /* overflow error */ |
Yann Collet | 33fdd09 | 2016-10-17 17:48:48 -0700 | [diff] [blame] | 366 | result <<= 10; |
Yann Collet | 9cd5c63 | 2018-05-12 14:29:33 -0700 | [diff] [blame] | 367 | if (**stringPtr=='M') { |
Yann Collet | 90c0462 | 2019-04-10 10:03:06 -0700 | [diff] [blame] | 368 | if (result > maxK) return 1; /* overflow error */ |
Yann Collet | 9cd5c63 | 2018-05-12 14:29:33 -0700 | [diff] [blame] | 369 | result <<= 10; |
| 370 | } |
| 371 | (*stringPtr)++; /* skip `K` or `M` */ |
Yann Collet | 33fdd09 | 2016-10-17 17:48:48 -0700 | [diff] [blame] | 372 | if (**stringPtr=='i') (*stringPtr)++; |
| 373 | if (**stringPtr=='B') (*stringPtr)++; |
| 374 | } |
Yi Jin | 26a9ae3 | 2018-12-19 16:45:42 -0800 | [diff] [blame] | 375 | *value = result; |
| 376 | return 0; |
| 377 | } |
| 378 | |
| 379 | /*! readU32FromChar() : |
| 380 | * @return : unsigned integer value read from input in `char` format. |
| 381 | * allows and interprets K, KB, KiB, M, MB and MiB suffix. |
| 382 | * Will also modify `*stringPtr`, advancing it to position where it stopped reading. |
| 383 | * Note : function will exit() program if digit sequence overflows */ |
| 384 | static unsigned readU32FromChar(const char** stringPtr) { |
Lehman Garrison | 834d06b | 2020-02-20 14:29:58 -0500 | [diff] [blame] | 385 | static const char errorMsg[] = "error: numeric value overflows 32-bit unsigned int"; |
Yi Jin | 26a9ae3 | 2018-12-19 16:45:42 -0800 | [diff] [blame] | 386 | unsigned result; |
Yi Jin | 9b2d708 | 2018-12-19 23:41:18 -0800 | [diff] [blame] | 387 | if (readU32FromCharChecked(stringPtr, &result)) { errorOut(errorMsg); } |
Yann Collet | 1dd7961 | 2016-06-03 15:14:09 +0200 | [diff] [blame] | 388 | return result; |
| 389 | } |
| 390 | |
Binh Vo | 6fad35c | 2021-06-09 16:49:36 -0400 | [diff] [blame] | 391 | /*! readIntFromChar() : |
| 392 | * @return : signed integer value read from input in `char` format. |
| 393 | * allows and interprets K, KB, KiB, M, MB and MiB suffix. |
| 394 | * Will also modify `*stringPtr`, advancing it to position where it stopped reading. |
| 395 | * Note : function will exit() program if digit sequence overflows */ |
| 396 | static int readIntFromChar(const char** stringPtr) { |
| 397 | static const char errorMsg[] = "error: numeric value overflows 32-bit int"; |
| 398 | int sign = 1; |
| 399 | unsigned result; |
| 400 | if (**stringPtr=='-') { |
| 401 | (*stringPtr)++; |
| 402 | sign = -1; |
| 403 | } |
| 404 | if (readU32FromCharChecked(stringPtr, &result)) { errorOut(errorMsg); } |
| 405 | return (int) result * sign; |
| 406 | } |
| 407 | |
Lehman Garrison | 834d06b | 2020-02-20 14:29:58 -0500 | [diff] [blame] | 408 | /*! readSizeTFromCharChecked() : |
| 409 | * @return 0 if success, and store the result in *value. |
| 410 | * allows and interprets K, KB, KiB, M, MB and MiB suffix. |
| 411 | * Will also modify `*stringPtr`, advancing it to position where it stopped reading. |
| 412 | * @return 1 if an overflow error occurs */ |
| 413 | static int readSizeTFromCharChecked(const char** stringPtr, size_t* value) |
| 414 | { |
| 415 | size_t result = 0; |
| 416 | while ((**stringPtr >='0') && (**stringPtr <='9')) { |
| 417 | size_t const max = ((size_t)(-1)) / 10; |
| 418 | size_t last = result; |
| 419 | if (result > max) return 1; /* overflow error */ |
| 420 | result *= 10; |
| 421 | result += (size_t)(**stringPtr - '0'); |
| 422 | if (result < last) return 1; /* overflow error */ |
| 423 | (*stringPtr)++ ; |
| 424 | } |
| 425 | if ((**stringPtr=='K') || (**stringPtr=='M')) { |
| 426 | size_t const maxK = ((size_t)(-1)) >> 10; |
| 427 | if (result > maxK) return 1; /* overflow error */ |
| 428 | result <<= 10; |
| 429 | if (**stringPtr=='M') { |
| 430 | if (result > maxK) return 1; /* overflow error */ |
| 431 | result <<= 10; |
| 432 | } |
| 433 | (*stringPtr)++; /* skip `K` or `M` */ |
| 434 | if (**stringPtr=='i') (*stringPtr)++; |
| 435 | if (**stringPtr=='B') (*stringPtr)++; |
| 436 | } |
| 437 | *value = result; |
| 438 | return 0; |
| 439 | } |
| 440 | |
| 441 | /*! readSizeTFromChar() : |
| 442 | * @return : size_t value read from input in `char` format. |
| 443 | * allows and interprets K, KB, KiB, M, MB and MiB suffix. |
| 444 | * Will also modify `*stringPtr`, advancing it to position where it stopped reading. |
| 445 | * Note : function will exit() program if digit sequence overflows */ |
| 446 | static size_t readSizeTFromChar(const char** stringPtr) { |
| 447 | static const char errorMsg[] = "error: numeric value overflows size_t"; |
| 448 | size_t result; |
| 449 | if (readSizeTFromCharChecked(stringPtr, &result)) { errorOut(errorMsg); } |
| 450 | return result; |
| 451 | } |
| 452 | |
Yann Collet | 743b33f | 2016-12-02 15:18:57 -0800 | [diff] [blame] | 453 | /** longCommandWArg() : |
Yann Collet | 6ccd37c | 2017-01-30 13:07:24 -0800 | [diff] [blame] | 454 | * check if *stringPtr is the same as longCommand. |
Yann Collet | 743b33f | 2016-12-02 15:18:57 -0800 | [diff] [blame] | 455 | * If yes, @return 1 and advances *stringPtr to the position which immediately follows longCommand. |
Yann Collet | 6a9b41b | 2018-03-11 19:56:48 -0700 | [diff] [blame] | 456 | * @return 0 and doesn't modify *stringPtr otherwise. |
Yann Collet | 743b33f | 2016-12-02 15:18:57 -0800 | [diff] [blame] | 457 | */ |
Yann Collet | 7f86ae2 | 2019-10-17 15:27:25 -0700 | [diff] [blame] | 458 | static int longCommandWArg(const char** stringPtr, const char* longCommand) |
Yann Collet | 70077bc | 2016-10-14 14:41:17 -0700 | [diff] [blame] | 459 | { |
| 460 | size_t const comSize = strlen(longCommand); |
Yann Collet | 743b33f | 2016-12-02 15:18:57 -0800 | [diff] [blame] | 461 | int const result = !strncmp(*stringPtr, longCommand, comSize); |
Yann Collet | 70077bc | 2016-10-14 14:41:17 -0700 | [diff] [blame] | 462 | if (result) *stringPtr += comSize; |
| 463 | return result; |
| 464 | } |
| 465 | |
Przemyslaw Skibinski | 671f28d | 2016-12-13 12:18:07 +0100 | [diff] [blame] | 466 | |
Nick Terrell | df8415c | 2016-12-31 21:08:24 -0800 | [diff] [blame] | 467 | #ifndef ZSTD_NODICT |
Qin Li | 04a9d6b | 2019-07-18 11:44:59 -0700 | [diff] [blame] | 468 | |
| 469 | static const unsigned kDefaultRegression = 1; |
Nick Terrell | df8415c | 2016-12-31 21:08:24 -0800 | [diff] [blame] | 470 | /** |
| 471 | * parseCoverParameters() : |
Nick Terrell | f376d47 | 2017-05-01 23:40:20 -0700 | [diff] [blame] | 472 | * reads cover parameters from *stringPtr (e.g. "--train-cover=k=48,d=8,steps=32") into *params |
Nick Terrell | df8415c | 2016-12-31 21:08:24 -0800 | [diff] [blame] | 473 | * @return 1 means that cover parameters were correct |
| 474 | * @return 0 in case of malformed parameters |
| 475 | */ |
Nick Terrell | 5b7fd7c | 2017-06-26 21:07:14 -0700 | [diff] [blame] | 476 | static unsigned parseCoverParameters(const char* stringPtr, ZDICT_cover_params_t* params) |
Nick Terrell | df8415c | 2016-12-31 21:08:24 -0800 | [diff] [blame] | 477 | { |
| 478 | memset(params, 0, sizeof(*params)); |
| 479 | for (; ;) { |
Nick Terrell | 3a1fefc | 2017-01-02 12:40:43 -0800 | [diff] [blame] | 480 | 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] | 481 | 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] | 482 | if (longCommandWArg(&stringPtr, "steps=")) { params->steps = readU32FromChar(&stringPtr); if (stringPtr[0]==',') { stringPtr++; continue; } else break; } |
Jennifer Liu | 348e5f7 | 2018-06-29 17:54:41 -0700 | [diff] [blame] | 483 | if (longCommandWArg(&stringPtr, "split=")) { |
Jennifer Liu | 0881184 | 2018-07-03 17:53:27 -0700 | [diff] [blame] | 484 | unsigned splitPercentage = readU32FromChar(&stringPtr); |
Jennifer Liu | 348e5f7 | 2018-06-29 17:54:41 -0700 | [diff] [blame] | 485 | params->splitPoint = (double)splitPercentage / 100.0; |
| 486 | if (stringPtr[0]==',') { stringPtr++; continue; } else break; |
| 487 | } |
Tyler-Tran | c55d2e7 | 2019-06-27 16:26:57 -0700 | [diff] [blame] | 488 | if (longCommandWArg(&stringPtr, "shrink")) { |
| 489 | params->shrinkDictMaxRegression = kDefaultRegression; |
| 490 | params->shrinkDict = 1; |
| 491 | if (stringPtr[0]=='=') { |
| 492 | stringPtr++; |
| 493 | params->shrinkDictMaxRegression = readU32FromChar(&stringPtr); |
| 494 | } |
| 495 | if (stringPtr[0]==',') { |
| 496 | stringPtr++; |
| 497 | continue; |
| 498 | } |
| 499 | else break; |
| 500 | } |
Nick Terrell | df8415c | 2016-12-31 21:08:24 -0800 | [diff] [blame] | 501 | return 0; |
| 502 | } |
| 503 | if (stringPtr[0] != 0) return 0; |
Tyler-Tran | c55d2e7 | 2019-06-27 16:26:57 -0700 | [diff] [blame] | 504 | DISPLAYLEVEL(4, "cover: k=%u\nd=%u\nsteps=%u\nsplit=%u\nshrink%u\n", params->k, params->d, params->steps, (unsigned)(params->splitPoint * 100), params->shrinkDictMaxRegression); |
Nick Terrell | df8415c | 2016-12-31 21:08:24 -0800 | [diff] [blame] | 505 | return 1; |
| 506 | } |
Nick Terrell | f376d47 | 2017-05-01 23:40:20 -0700 | [diff] [blame] | 507 | |
| 508 | /** |
Jennifer Liu | 9d6ed9d | 2018-08-23 12:06:20 -0700 | [diff] [blame] | 509 | * parseFastCoverParameters() : |
| 510 | * reads fastcover parameters from *stringPtr (e.g. "--train-fastcover=k=48,d=8,f=20,steps=32,accel=2") into *params |
| 511 | * @return 1 means that fastcover parameters were correct |
| 512 | * @return 0 in case of malformed parameters |
| 513 | */ |
| 514 | static unsigned parseFastCoverParameters(const char* stringPtr, ZDICT_fastCover_params_t* params) |
| 515 | { |
| 516 | memset(params, 0, sizeof(*params)); |
| 517 | for (; ;) { |
| 518 | if (longCommandWArg(&stringPtr, "k=")) { params->k = readU32FromChar(&stringPtr); if (stringPtr[0]==',') { stringPtr++; continue; } else break; } |
| 519 | if (longCommandWArg(&stringPtr, "d=")) { params->d = readU32FromChar(&stringPtr); if (stringPtr[0]==',') { stringPtr++; continue; } else break; } |
| 520 | if (longCommandWArg(&stringPtr, "f=")) { params->f = readU32FromChar(&stringPtr); if (stringPtr[0]==',') { stringPtr++; continue; } else break; } |
| 521 | if (longCommandWArg(&stringPtr, "steps=")) { params->steps = readU32FromChar(&stringPtr); if (stringPtr[0]==',') { stringPtr++; continue; } else break; } |
| 522 | if (longCommandWArg(&stringPtr, "accel=")) { params->accel = readU32FromChar(&stringPtr); if (stringPtr[0]==',') { stringPtr++; continue; } else break; } |
| 523 | if (longCommandWArg(&stringPtr, "split=")) { |
| 524 | unsigned splitPercentage = readU32FromChar(&stringPtr); |
| 525 | params->splitPoint = (double)splitPercentage / 100.0; |
| 526 | if (stringPtr[0]==',') { stringPtr++; continue; } else break; |
| 527 | } |
Tyler-Tran | c55d2e7 | 2019-06-27 16:26:57 -0700 | [diff] [blame] | 528 | if (longCommandWArg(&stringPtr, "shrink")) { |
| 529 | params->shrinkDictMaxRegression = kDefaultRegression; |
| 530 | params->shrinkDict = 1; |
| 531 | if (stringPtr[0]=='=') { |
| 532 | stringPtr++; |
| 533 | params->shrinkDictMaxRegression = readU32FromChar(&stringPtr); |
| 534 | } |
| 535 | if (stringPtr[0]==',') { |
| 536 | stringPtr++; |
| 537 | continue; |
| 538 | } |
| 539 | else break; |
| 540 | } |
Jennifer Liu | 9d6ed9d | 2018-08-23 12:06:20 -0700 | [diff] [blame] | 541 | return 0; |
| 542 | } |
| 543 | if (stringPtr[0] != 0) return 0; |
Tyler-Tran | c55d2e7 | 2019-06-27 16:26:57 -0700 | [diff] [blame] | 544 | DISPLAYLEVEL(4, "cover: k=%u\nd=%u\nf=%u\nsteps=%u\nsplit=%u\naccel=%u\nshrink=%u\n", params->k, params->d, params->f, params->steps, (unsigned)(params->splitPoint * 100), params->accel, params->shrinkDictMaxRegression); |
Jennifer Liu | 9d6ed9d | 2018-08-23 12:06:20 -0700 | [diff] [blame] | 545 | return 1; |
| 546 | } |
| 547 | |
| 548 | /** |
Nick Terrell | f376d47 | 2017-05-01 23:40:20 -0700 | [diff] [blame] | 549 | * parseLegacyParameters() : |
Josh Soref | a880ca2 | 2019-04-12 14:18:11 -0400 | [diff] [blame] | 550 | * reads legacy dictionary builder parameters from *stringPtr (e.g. "--train-legacy=selectivity=8") into *selectivity |
Nick Terrell | f376d47 | 2017-05-01 23:40:20 -0700 | [diff] [blame] | 551 | * @return 1 means that legacy dictionary builder parameters were correct |
| 552 | * @return 0 in case of malformed parameters |
| 553 | */ |
| 554 | static unsigned parseLegacyParameters(const char* stringPtr, unsigned* selectivity) |
| 555 | { |
| 556 | if (!longCommandWArg(&stringPtr, "s=") && !longCommandWArg(&stringPtr, "selectivity=")) { return 0; } |
| 557 | *selectivity = readU32FromChar(&stringPtr); |
| 558 | if (stringPtr[0] != 0) return 0; |
| 559 | DISPLAYLEVEL(4, "legacy: selectivity=%u\n", *selectivity); |
| 560 | return 1; |
| 561 | } |
| 562 | |
Nick Terrell | 5b7fd7c | 2017-06-26 21:07:14 -0700 | [diff] [blame] | 563 | static ZDICT_cover_params_t defaultCoverParams(void) |
Nick Terrell | f376d47 | 2017-05-01 23:40:20 -0700 | [diff] [blame] | 564 | { |
Nick Terrell | 5b7fd7c | 2017-06-26 21:07:14 -0700 | [diff] [blame] | 565 | ZDICT_cover_params_t params; |
Nick Terrell | f376d47 | 2017-05-01 23:40:20 -0700 | [diff] [blame] | 566 | memset(¶ms, 0, sizeof(params)); |
| 567 | params.d = 8; |
| 568 | params.steps = 4; |
Jennifer Liu | 9d6ed9d | 2018-08-23 12:06:20 -0700 | [diff] [blame] | 569 | params.splitPoint = 1.0; |
Tyler-Tran | c55d2e7 | 2019-06-27 16:26:57 -0700 | [diff] [blame] | 570 | params.shrinkDict = 0; |
| 571 | params.shrinkDictMaxRegression = kDefaultRegression; |
Jennifer Liu | 9d6ed9d | 2018-08-23 12:06:20 -0700 | [diff] [blame] | 572 | return params; |
| 573 | } |
| 574 | |
| 575 | static ZDICT_fastCover_params_t defaultFastCoverParams(void) |
| 576 | { |
| 577 | ZDICT_fastCover_params_t params; |
| 578 | memset(¶ms, 0, sizeof(params)); |
| 579 | params.d = 8; |
Jennifer Liu | 21721b7 | 2018-09-04 17:12:35 -0700 | [diff] [blame] | 580 | params.f = 20; |
Jennifer Liu | 9d6ed9d | 2018-08-23 12:06:20 -0700 | [diff] [blame] | 581 | params.steps = 4; |
| 582 | params.splitPoint = 0.75; /* different from default splitPoint of cover */ |
| 583 | params.accel = DEFAULT_ACCEL; |
Tyler-Tran | c55d2e7 | 2019-06-27 16:26:57 -0700 | [diff] [blame] | 584 | params.shrinkDict = 0; |
| 585 | params.shrinkDictMaxRegression = kDefaultRegression; |
Nick Terrell | f376d47 | 2017-05-01 23:40:20 -0700 | [diff] [blame] | 586 | return params; |
| 587 | } |
Nick Terrell | df8415c | 2016-12-31 21:08:24 -0800 | [diff] [blame] | 588 | #endif |
Yann Collet | 6ccd37c | 2017-01-30 13:07:24 -0800 | [diff] [blame] | 589 | |
| 590 | |
Yann Collet | 6c51bf4 | 2018-09-24 18:16:08 -0700 | [diff] [blame] | 591 | /** parseAdaptParameters() : |
| 592 | * reads adapt parameters from *stringPtr (e.g. "--zstd=min=1,max=19) and store them into adaptMinPtr and adaptMaxPtr. |
| 593 | * Both adaptMinPtr and adaptMaxPtr must be already allocated and correctly initialized. |
| 594 | * There is no guarantee that any of these values will be updated. |
| 595 | * @return 1 means that parsing was successful, |
| 596 | * @return 0 in case of malformed parameters |
| 597 | */ |
| 598 | static unsigned parseAdaptParameters(const char* stringPtr, int* adaptMinPtr, int* adaptMaxPtr) |
| 599 | { |
| 600 | for ( ; ;) { |
Binh Vo | 6fad35c | 2021-06-09 16:49:36 -0400 | [diff] [blame] | 601 | if (longCommandWArg(&stringPtr, "min=")) { *adaptMinPtr = readIntFromChar(&stringPtr); if (stringPtr[0]==',') { stringPtr++; continue; } else break; } |
| 602 | if (longCommandWArg(&stringPtr, "max=")) { *adaptMaxPtr = readIntFromChar(&stringPtr); if (stringPtr[0]==',') { stringPtr++; continue; } else break; } |
Yann Collet | 6c51bf4 | 2018-09-24 18:16:08 -0700 | [diff] [blame] | 603 | DISPLAYLEVEL(4, "invalid compression parameter \n"); |
| 604 | return 0; |
| 605 | } |
| 606 | if (stringPtr[0] != 0) return 0; /* check the end of string */ |
| 607 | if (*adaptMinPtr > *adaptMaxPtr) { |
| 608 | DISPLAYLEVEL(4, "incoherent adaptation limits \n"); |
| 609 | return 0; |
| 610 | } |
| 611 | return 1; |
| 612 | } |
| 613 | |
| 614 | |
Przemyslaw Skibinski | 671f28d | 2016-12-13 12:18:07 +0100 | [diff] [blame] | 615 | /** parseCompressionParameters() : |
Yann Collet | e874dac | 2018-11-20 14:56:07 -0800 | [diff] [blame] | 616 | * reads compression parameters from *stringPtr (e.g. "--zstd=wlog=23,clog=23,hlog=22,slog=6,mml=3,tlen=48,strat=6") into *params |
Przemyslaw Skibinski | 671f28d | 2016-12-13 12:18:07 +0100 | [diff] [blame] | 617 | * @return 1 means that compression parameters were correct |
| 618 | * @return 0 in case of malformed parameters |
| 619 | */ |
| 620 | static unsigned parseCompressionParameters(const char* stringPtr, ZSTD_compressionParameters* params) |
| 621 | { |
| 622 | for ( ; ;) { |
Przemyslaw Skibinski | 671f28d | 2016-12-13 12:18:07 +0100 | [diff] [blame] | 623 | if (longCommandWArg(&stringPtr, "windowLog=") || longCommandWArg(&stringPtr, "wlog=")) { params->windowLog = readU32FromChar(&stringPtr); if (stringPtr[0]==',') { stringPtr++; continue; } else break; } |
| 624 | if (longCommandWArg(&stringPtr, "chainLog=") || longCommandWArg(&stringPtr, "clog=")) { params->chainLog = readU32FromChar(&stringPtr); if (stringPtr[0]==',') { stringPtr++; continue; } else break; } |
| 625 | if (longCommandWArg(&stringPtr, "hashLog=") || longCommandWArg(&stringPtr, "hlog=")) { params->hashLog = readU32FromChar(&stringPtr); if (stringPtr[0]==',') { stringPtr++; continue; } else break; } |
| 626 | if (longCommandWArg(&stringPtr, "searchLog=") || longCommandWArg(&stringPtr, "slog=")) { params->searchLog = readU32FromChar(&stringPtr); if (stringPtr[0]==',') { stringPtr++; continue; } else break; } |
Yann Collet | e874dac | 2018-11-20 14:56:07 -0800 | [diff] [blame] | 627 | if (longCommandWArg(&stringPtr, "minMatch=") || longCommandWArg(&stringPtr, "mml=")) { params->minMatch = readU32FromChar(&stringPtr); if (stringPtr[0]==',') { stringPtr++; continue; } else break; } |
Przemyslaw Skibinski | 671f28d | 2016-12-13 12:18:07 +0100 | [diff] [blame] | 628 | if (longCommandWArg(&stringPtr, "targetLength=") || longCommandWArg(&stringPtr, "tlen=")) { params->targetLength = readU32FromChar(&stringPtr); if (stringPtr[0]==',') { stringPtr++; continue; } else break; } |
Yann Collet | b44ab82 | 2017-06-20 14:11:49 -0700 | [diff] [blame] | 629 | if (longCommandWArg(&stringPtr, "strategy=") || longCommandWArg(&stringPtr, "strat=")) { params->strategy = (ZSTD_strategy)(readU32FromChar(&stringPtr)); if (stringPtr[0]==',') { stringPtr++; continue; } else break; } |
Yann Collet | 6ccd37c | 2017-01-30 13:07:24 -0800 | [diff] [blame] | 630 | if (longCommandWArg(&stringPtr, "overlapLog=") || longCommandWArg(&stringPtr, "ovlog=")) { g_overlapLog = readU32FromChar(&stringPtr); if (stringPtr[0]==',') { stringPtr++; continue; } else break; } |
Yann Collet | e874dac | 2018-11-20 14:56:07 -0800 | [diff] [blame] | 631 | if (longCommandWArg(&stringPtr, "ldmHashLog=") || longCommandWArg(&stringPtr, "lhlog=")) { g_ldmHashLog = readU32FromChar(&stringPtr); if (stringPtr[0]==',') { stringPtr++; continue; } else break; } |
| 632 | if (longCommandWArg(&stringPtr, "ldmMinMatch=") || longCommandWArg(&stringPtr, "lmml=")) { g_ldmMinMatch = readU32FromChar(&stringPtr); if (stringPtr[0]==',') { stringPtr++; continue; } else break; } |
| 633 | if (longCommandWArg(&stringPtr, "ldmBucketSizeLog=") || longCommandWArg(&stringPtr, "lblog=")) { g_ldmBucketSizeLog = readU32FromChar(&stringPtr); if (stringPtr[0]==',') { stringPtr++; continue; } else break; } |
Yann Collet | 41c7d0b | 2018-11-21 14:36:57 -0800 | [diff] [blame] | 634 | if (longCommandWArg(&stringPtr, "ldmHashRateLog=") || longCommandWArg(&stringPtr, "lhrlog=")) { g_ldmHashRateLog = readU32FromChar(&stringPtr); if (stringPtr[0]==',') { stringPtr++; continue; } else break; } |
Yann Collet | c707c6e | 2017-12-27 13:32:05 +0100 | [diff] [blame] | 635 | DISPLAYLEVEL(4, "invalid compression parameter \n"); |
Przemyslaw Skibinski | 671f28d | 2016-12-13 12:18:07 +0100 | [diff] [blame] | 636 | return 0; |
| 637 | } |
| 638 | |
Yann Collet | c707c6e | 2017-12-27 13:32:05 +0100 | [diff] [blame] | 639 | DISPLAYLEVEL(4, "windowLog=%d, chainLog=%d, hashLog=%d, searchLog=%d \n", params->windowLog, params->chainLog, params->hashLog, params->searchLog); |
Yann Collet | e874dac | 2018-11-20 14:56:07 -0800 | [diff] [blame] | 640 | DISPLAYLEVEL(4, "minMatch=%d, targetLength=%d, strategy=%d \n", params->minMatch, params->targetLength, params->strategy); |
Przemyslaw Skibinski | 671f28d | 2016-12-13 12:18:07 +0100 | [diff] [blame] | 641 | if (stringPtr[0] != 0) return 0; /* check the end of string */ |
Przemyslaw Skibinski | 671f28d | 2016-12-13 12:18:07 +0100 | [diff] [blame] | 642 | return 1; |
| 643 | } |
| 644 | |
Yann Collet | 1c108c8 | 2017-08-19 13:33:50 -0700 | [diff] [blame] | 645 | static void printVersion(void) |
| 646 | { |
Tobias Hieta | b1cce9a | 2020-06-08 14:06:37 +0200 | [diff] [blame] | 647 | if (g_displayLevel < DISPLAY_LEVEL_DEFAULT) { |
| 648 | DISPLAYOUT("%s\n", ZSTD_VERSION_STRING); |
| 649 | return; |
| 650 | } |
| 651 | |
Yann Collet | 4b4de74 | 2019-12-02 16:08:08 -0800 | [diff] [blame] | 652 | DISPLAYOUT(WELCOME_MESSAGE); |
| 653 | if (g_displayLevel >= 3) { |
Yann Collet | 1c108c8 | 2017-08-19 13:33:50 -0700 | [diff] [blame] | 654 | /* format support */ |
Yann Collet | 4b4de74 | 2019-12-02 16:08:08 -0800 | [diff] [blame] | 655 | DISPLAYOUT("*** supports: zstd"); |
| 656 | #if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT>0) && (ZSTD_LEGACY_SUPPORT<8) |
| 657 | DISPLAYOUT(", zstd legacy v0.%d+", ZSTD_LEGACY_SUPPORT); |
| 658 | #endif |
| 659 | #ifdef ZSTD_GZCOMPRESS |
| 660 | DISPLAYOUT(", gzip"); |
| 661 | #endif |
| 662 | #ifdef ZSTD_LZ4COMPRESS |
| 663 | DISPLAYOUT(", lz4"); |
| 664 | #endif |
| 665 | #ifdef ZSTD_LZMACOMPRESS |
| 666 | DISPLAYOUT(", lzma, xz "); |
| 667 | #endif |
| 668 | DISPLAYOUT("\n"); |
| 669 | if (g_displayLevel >= 4) { |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 670 | /* library versions */ |
| 671 | DISPLAYOUT("zlib version %s\n", FIO_zlibVersion()); |
| 672 | DISPLAYOUT("lz4 version %s\n", FIO_lz4Version()); |
| 673 | DISPLAYOUT("lzma version %s\n", FIO_lzmaVersion()); |
| 674 | |
Yann Collet | 4b4de74 | 2019-12-02 16:08:08 -0800 | [diff] [blame] | 675 | /* posix support */ |
| 676 | #ifdef _POSIX_C_SOURCE |
| 677 | DISPLAYOUT("_POSIX_C_SOURCE defined: %ldL\n", (long) _POSIX_C_SOURCE); |
| 678 | #endif |
| 679 | #ifdef _POSIX_VERSION |
| 680 | DISPLAYOUT("_POSIX_VERSION defined: %ldL \n", (long) _POSIX_VERSION); |
| 681 | #endif |
| 682 | #ifdef PLATFORM_POSIX_VERSION |
| 683 | DISPLAYOUT("PLATFORM_POSIX_VERSION defined: %ldL\n", (long) PLATFORM_POSIX_VERSION); |
| 684 | #endif |
| 685 | } } |
Yann Collet | 1c108c8 | 2017-08-19 13:33:50 -0700 | [diff] [blame] | 686 | } |
Przemyslaw Skibinski | 671f28d | 2016-12-13 12:18:07 +0100 | [diff] [blame] | 687 | |
Kevin Svetlitski | 63fe619 | 2021-11-05 12:48:13 -0700 | [diff] [blame] | 688 | #define ZSTD_NB_STRATEGIES 9 |
| 689 | static const char* ZSTD_strategyMap[ZSTD_NB_STRATEGIES + 1] = { "", "ZSTD_fast", |
| 690 | "ZSTD_dfast", "ZSTD_greedy", "ZSTD_lazy", "ZSTD_lazy2", "ZSTD_btlazy2", |
| 691 | "ZSTD_btopt", "ZSTD_btultra", "ZSTD_btultra2"}; |
| 692 | |
Kevin Svetlitski | 365c911 | 2021-11-11 12:14:56 -0800 | [diff] [blame] | 693 | #ifndef ZSTD_NOCOMPRESS |
| 694 | |
Kevin Svetlitski | 63fe619 | 2021-11-05 12:48:13 -0700 | [diff] [blame] | 695 | static void printDefaultCParams(const char* filename, const char* dictFileName, int cLevel) { |
| 696 | unsigned long long fileSize = UTIL_getFileSize(filename); |
| 697 | const size_t dictSize = dictFileName != NULL ? (size_t)UTIL_getFileSize(dictFileName) : 0; |
| 698 | const ZSTD_compressionParameters cParams = ZSTD_getCParams(cLevel, fileSize, dictSize); |
| 699 | if (fileSize != UTIL_FILESIZE_UNKNOWN) DISPLAY("%s (%u bytes)\n", filename, (unsigned)fileSize); |
| 700 | else DISPLAY("%s (src size unknown)\n", filename); |
| 701 | DISPLAY(" - windowLog : %u\n", cParams.windowLog); |
| 702 | DISPLAY(" - chainLog : %u\n", cParams.chainLog); |
| 703 | DISPLAY(" - hashLog : %u\n", cParams.hashLog); |
| 704 | DISPLAY(" - searchLog : %u\n", cParams.searchLog); |
| 705 | DISPLAY(" - minMatch : %u\n", cParams.minMatch); |
| 706 | DISPLAY(" - targetLength : %u\n", cParams.targetLength); |
| 707 | assert(cParams.strategy < ZSTD_NB_STRATEGIES + 1); |
| 708 | DISPLAY(" - strategy : %s (%u)\n", ZSTD_strategyMap[(int)cParams.strategy], (unsigned)cParams.strategy); |
| 709 | } |
| 710 | |
| 711 | static void printActualCParams(const char* filename, const char* dictFileName, int cLevel, const ZSTD_compressionParameters* cParams) { |
| 712 | unsigned long long fileSize = UTIL_getFileSize(filename); |
| 713 | const size_t dictSize = dictFileName != NULL ? (size_t)UTIL_getFileSize(dictFileName) : 0; |
| 714 | ZSTD_compressionParameters actualCParams = ZSTD_getCParams(cLevel, fileSize, dictSize); |
| 715 | assert(g_displayLevel >= 4); |
| 716 | actualCParams.windowLog = cParams->windowLog == 0 ? actualCParams.windowLog : cParams->windowLog; |
| 717 | actualCParams.chainLog = cParams->chainLog == 0 ? actualCParams.chainLog : cParams->chainLog; |
| 718 | actualCParams.hashLog = cParams->hashLog == 0 ? actualCParams.hashLog : cParams->hashLog; |
| 719 | actualCParams.searchLog = cParams->searchLog == 0 ? actualCParams.searchLog : cParams->searchLog; |
| 720 | actualCParams.minMatch = cParams->minMatch == 0 ? actualCParams.minMatch : cParams->minMatch; |
| 721 | actualCParams.targetLength = cParams->targetLength == 0 ? actualCParams.targetLength : cParams->targetLength; |
| 722 | actualCParams.strategy = cParams->strategy == 0 ? actualCParams.strategy : cParams->strategy; |
| 723 | DISPLAY("--zstd=wlog=%d,clog=%d,hlog=%d,slog=%d,mml=%d,tlen=%d,strat=%d\n", |
| 724 | actualCParams.windowLog, actualCParams.chainLog, actualCParams.hashLog, actualCParams.searchLog, |
| 725 | actualCParams.minMatch, actualCParams.targetLength, actualCParams.strategy); |
| 726 | } |
| 727 | |
Kevin Svetlitski | 365c911 | 2021-11-11 12:14:56 -0800 | [diff] [blame] | 728 | #endif |
| 729 | |
Yi Jin | 5324b1e | 2018-12-19 13:26:27 -0800 | [diff] [blame] | 730 | /* Environment variables for parameter setting */ |
| 731 | #define ENV_CLEVEL "ZSTD_CLEVEL" |
senhuang42 | a71963c | 2020-09-09 12:35:40 -0400 | [diff] [blame] | 732 | #define ENV_NBTHREADS "ZSTD_NBTHREADS" /* takes lower precedence than directly specifying -T# in the CLI */ |
Yi Jin | 5324b1e | 2018-12-19 13:26:27 -0800 | [diff] [blame] | 733 | |
Yann Collet | 4b4de74 | 2019-12-02 16:08:08 -0800 | [diff] [blame] | 734 | /* pick up environment variable */ |
Yi Jin | f7b1841 | 2018-12-19 17:56:45 -0800 | [diff] [blame] | 735 | static int init_cLevel(void) { |
Yi Jin | 26a9ae3 | 2018-12-19 16:45:42 -0800 | [diff] [blame] | 736 | const char* const env = getenv(ENV_CLEVEL); |
Yann Collet | a49417b | 2019-12-02 14:28:18 -0800 | [diff] [blame] | 737 | if (env != NULL) { |
| 738 | const char* ptr = env; |
Yi Jin | 5324b1e | 2018-12-19 13:26:27 -0800 | [diff] [blame] | 739 | int sign = 1; |
Yi Jin | 26a9ae3 | 2018-12-19 16:45:42 -0800 | [diff] [blame] | 740 | if (*ptr == '-') { |
Yi Jin | 5324b1e | 2018-12-19 13:26:27 -0800 | [diff] [blame] | 741 | sign = -1; |
Yi Jin | 26a9ae3 | 2018-12-19 16:45:42 -0800 | [diff] [blame] | 742 | ptr++; |
| 743 | } else if (*ptr == '+') { |
| 744 | ptr++; |
Yi Jin | 5324b1e | 2018-12-19 13:26:27 -0800 | [diff] [blame] | 745 | } |
| 746 | |
Yi Jin | 26a9ae3 | 2018-12-19 16:45:42 -0800 | [diff] [blame] | 747 | if ((*ptr>='0') && (*ptr<='9')) { |
| 748 | unsigned absLevel; |
Yann Collet | 90c0462 | 2019-04-10 10:03:06 -0700 | [diff] [blame] | 749 | if (readU32FromCharChecked(&ptr, &absLevel)) { |
Yann Collet | a49417b | 2019-12-02 14:28:18 -0800 | [diff] [blame] | 750 | DISPLAYLEVEL(2, "Ignore environment variable setting %s=%s: numeric value too large \n", ENV_CLEVEL, env); |
Yi Jin | 26a9ae3 | 2018-12-19 16:45:42 -0800 | [diff] [blame] | 751 | return ZSTDCLI_CLEVEL_DEFAULT; |
| 752 | } else if (*ptr == 0) { |
Yann Collet | 7f86ae2 | 2019-10-17 15:27:25 -0700 | [diff] [blame] | 753 | return sign * (int)absLevel; |
Yann Collet | a49417b | 2019-12-02 14:28:18 -0800 | [diff] [blame] | 754 | } } |
Yi Jin | 26a9ae3 | 2018-12-19 16:45:42 -0800 | [diff] [blame] | 755 | |
Yann Collet | a49417b | 2019-12-02 14:28:18 -0800 | [diff] [blame] | 756 | DISPLAYLEVEL(2, "Ignore environment variable setting %s=%s: not a valid integer value \n", ENV_CLEVEL, env); |
Yi Jin | 5324b1e | 2018-12-19 13:26:27 -0800 | [diff] [blame] | 757 | } |
| 758 | |
| 759 | return ZSTDCLI_CLEVEL_DEFAULT; |
| 760 | } |
| 761 | |
senhuang42 | 243c8df | 2020-09-08 09:26:16 -0400 | [diff] [blame] | 762 | #ifdef ZSTD_MULTITHREAD |
senhuang42 | a71963c | 2020-09-09 12:35:40 -0400 | [diff] [blame] | 763 | static unsigned init_nbThreads(void) { |
| 764 | const char* const env = getenv(ENV_NBTHREADS); |
senhuang42 | 70fa7b3 | 2020-08-25 18:49:52 -0400 | [diff] [blame] | 765 | if (env != NULL) { |
| 766 | const char* ptr = env; |
| 767 | if ((*ptr>='0') && (*ptr<='9')) { |
senhuang42 | a71963c | 2020-09-09 12:35:40 -0400 | [diff] [blame] | 768 | unsigned nbThreads; |
| 769 | if (readU32FromCharChecked(&ptr, &nbThreads)) { |
| 770 | DISPLAYLEVEL(2, "Ignore environment variable setting %s=%s: numeric value too large \n", ENV_NBTHREADS, env); |
| 771 | return ZSTDCLI_NBTHREADS_DEFAULT; |
senhuang42 | 70fa7b3 | 2020-08-25 18:49:52 -0400 | [diff] [blame] | 772 | } else if (*ptr == 0) { |
senhuang42 | a71963c | 2020-09-09 12:35:40 -0400 | [diff] [blame] | 773 | return nbThreads; |
senhuang42 | 70fa7b3 | 2020-08-25 18:49:52 -0400 | [diff] [blame] | 774 | } |
| 775 | } |
senhuang42 | a71963c | 2020-09-09 12:35:40 -0400 | [diff] [blame] | 776 | DISPLAYLEVEL(2, "Ignore environment variable setting %s=%s: not a valid unsigned value \n", ENV_NBTHREADS, env); |
senhuang42 | 70fa7b3 | 2020-08-25 18:49:52 -0400 | [diff] [blame] | 777 | } |
| 778 | |
senhuang42 | a71963c | 2020-09-09 12:35:40 -0400 | [diff] [blame] | 779 | return ZSTDCLI_NBTHREADS_DEFAULT; |
senhuang42 | 70fa7b3 | 2020-08-25 18:49:52 -0400 | [diff] [blame] | 780 | } |
senhuang42 | 243c8df | 2020-09-08 09:26:16 -0400 | [diff] [blame] | 781 | #endif |
senhuang42 | 70fa7b3 | 2020-08-25 18:49:52 -0400 | [diff] [blame] | 782 | |
Yann Collet | 610c41f | 2020-07-20 17:41:32 -0700 | [diff] [blame] | 783 | #define NEXT_FIELD(ptr) { \ |
| 784 | if (*argument == '=') { \ |
| 785 | ptr = ++argument; \ |
| 786 | argument += strlen(ptr); \ |
| 787 | } else { \ |
| 788 | argNb++; \ |
| 789 | if (argNb >= argCount) { \ |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 790 | DISPLAYLEVEL(1, "error: missing command argument \n"); \ |
Yann Collet | 610c41f | 2020-07-20 17:41:32 -0700 | [diff] [blame] | 791 | CLEAN_RETURN(1); \ |
| 792 | } \ |
| 793 | ptr = argv[argNb]; \ |
| 794 | assert(ptr != NULL); \ |
| 795 | if (ptr[0]=='-') { \ |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 796 | DISPLAYLEVEL(1, "error: command cannot be separated from its argument by another command \n"); \ |
Yann Collet | 610c41f | 2020-07-20 17:41:32 -0700 | [diff] [blame] | 797 | CLEAN_RETURN(1); \ |
| 798 | } } } |
| 799 | |
| 800 | #define NEXT_UINT32(val32) { \ |
| 801 | const char* __nb; \ |
| 802 | NEXT_FIELD(__nb); \ |
| 803 | val32 = readU32FromChar(&__nb); \ |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 804 | if(*__nb != 0) { \ |
| 805 | errorOut("error: only numeric values with optional suffixes K, KB, KiB, M, MB, MiB are allowed"); \ |
| 806 | } \ |
| 807 | } |
| 808 | |
| 809 | #define NEXT_TSIZE(valTsize) { \ |
| 810 | const char* __nb; \ |
| 811 | NEXT_FIELD(__nb); \ |
| 812 | valTsize = readSizeTFromChar(&__nb); \ |
| 813 | if(*__nb != 0) { \ |
| 814 | errorOut("error: only numeric values with optional suffixes K, KB, KiB, M, MB, MiB are allowed"); \ |
| 815 | } \ |
Yann Collet | a7e5652 | 2020-07-17 12:46:36 -0700 | [diff] [blame] | 816 | } |
Bimba Shrestha | 38d010e | 2020-01-31 10:47:17 -0800 | [diff] [blame] | 817 | |
Paul Cruz | 901435e | 2017-06-05 14:45:31 -0700 | [diff] [blame] | 818 | typedef enum { zom_compress, zom_decompress, zom_test, zom_bench, zom_train, zom_list } zstd_operation_mode; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 819 | |
| 820 | #define CLEAN_RETURN(i) { operationResult = (i); goto _end; } |
| 821 | |
Yann Collet | 6c51bf4 | 2018-09-24 18:16:08 -0700 | [diff] [blame] | 822 | #ifdef ZSTD_NOCOMPRESS |
| 823 | /* symbols from compression library are not defined and should not be invoked */ |
Yann Collet | a49417b | 2019-12-02 14:28:18 -0800 | [diff] [blame] | 824 | # define MINCLEVEL -99 |
Yann Collet | 6c51bf4 | 2018-09-24 18:16:08 -0700 | [diff] [blame] | 825 | # define MAXCLEVEL 22 |
| 826 | #else |
| 827 | # define MINCLEVEL ZSTD_minCLevel() |
| 828 | # define MAXCLEVEL ZSTD_maxCLevel() |
| 829 | #endif |
| 830 | |
makise-homura | a5f518a | 2021-07-14 19:55:47 +0300 | [diff] [blame] | 831 | int main(int argCount, const char* argv[]) |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 832 | { |
| 833 | int argNb, |
Yann Collet | 5cb1144 | 2018-02-13 14:56:35 -0800 | [diff] [blame] | 834 | followLinks = 0, |
W. Felix Handte | 33f3e29 | 2021-05-04 16:24:46 -0400 | [diff] [blame] | 835 | allowBlockDevices = 0, |
W. Felix Handte | 8b6a4b5 | 2021-01-11 17:53:20 -0500 | [diff] [blame] | 836 | forceStdin = 0, |
Yann Collet | 5cb1144 | 2018-02-13 14:56:35 -0800 | [diff] [blame] | 837 | forceStdout = 0, |
senhuang42 | 7259b25 | 2020-10-07 13:47:38 -0400 | [diff] [blame] | 838 | hasStdout = 0, |
Yann Collet | 7568983 | 2018-02-09 15:53:27 -0800 | [diff] [blame] | 839 | ldmFlag = 0, |
Yann Collet | 5cb1144 | 2018-02-13 14:56:35 -0800 | [diff] [blame] | 840 | main_pause = 0, |
Yann Collet | e7a49c6 | 2018-08-11 20:48:06 -0700 | [diff] [blame] | 841 | adapt = 0, |
Yann Collet | 6c51bf4 | 2018-09-24 18:16:08 -0700 | [diff] [blame] | 842 | adaptMin = MINCLEVEL, |
| 843 | adaptMax = MAXCLEVEL, |
Nick Terrell | f9a671a | 2018-11-12 19:59:42 -0800 | [diff] [blame] | 844 | rsyncable = 0, |
Yann Collet | 5cb1144 | 2018-02-13 14:56:35 -0800 | [diff] [blame] | 845 | nextArgumentsAreFiles = 0, |
Yann Collet | 5cb1144 | 2018-02-13 14:56:35 -0800 | [diff] [blame] | 846 | operationResult = 0, |
Yann Collet | d898fb7 | 2017-11-17 00:22:55 -0800 | [diff] [blame] | 847 | separateFiles = 0, |
Yann Collet | 7568983 | 2018-02-09 15:53:27 -0800 | [diff] [blame] | 848 | setRealTimePrio = 0, |
Yann Collet | 5cb1144 | 2018-02-13 14:56:35 -0800 | [diff] [blame] | 849 | singleThread = 0, |
Binh Vo | 6a46e38 | 2021-06-16 09:38:43 -0400 | [diff] [blame] | 850 | defaultLogicalCores = 0, |
Bimba Shrestha | 2f10019 | 2020-01-30 14:12:03 -0800 | [diff] [blame] | 851 | showDefaultCParams = 0, |
Bimba Shrestha | 167244a | 2020-03-09 13:07:29 -0500 | [diff] [blame] | 852 | ultra=0, |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 853 | contentSize=1, |
| 854 | removeSrcFile=0; |
| 855 | ZSTD_paramSwitch_e mmapDict=ZSTD_ps_auto; |
| 856 | ZSTD_paramSwitch_e useRowMatchFinder = ZSTD_ps_auto; |
| 857 | FIO_compressionType_t cType = FIO_zstdCompression; |
| 858 | unsigned nbWorkers = 0; |
George Lu | a8eea99 | 2018-06-19 10:58:22 -0700 | [diff] [blame] | 859 | double compressibility = 0.5; |
Yann Collet | 500014a | 2017-01-19 16:59:56 -0800 | [diff] [blame] | 860 | unsigned bench_nbSeconds = 3; /* would be better if this value was synchronized from bench */ |
| 861 | size_t blockSize = 0; |
Karl Ostmo | 5e220bf | 2019-01-22 17:31:13 -0800 | [diff] [blame] | 862 | |
| 863 | FIO_prefs_t* const prefs = FIO_createPreferences(); |
senhuang42 | d54566f | 2020-08-28 11:01:04 -0400 | [diff] [blame] | 864 | FIO_ctx_t* const fCtx = FIO_createContext(); |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 865 | FIO_progressSetting_e progress = FIO_ps_auto; |
Yann Collet | 22de81e | 2016-10-28 13:58:31 -0700 | [diff] [blame] | 866 | zstd_operation_mode operation = zom_compress; |
Przemyslaw Skibinski | 671f28d | 2016-12-13 12:18:07 +0100 | [diff] [blame] | 867 | ZSTD_compressionParameters compressionParams; |
Yann Collet | 4b4de74 | 2019-12-02 16:08:08 -0800 | [diff] [blame] | 868 | int cLevel = init_cLevel(); |
Yann Collet | a49417b | 2019-12-02 14:28:18 -0800 | [diff] [blame] | 869 | int cLevelLast = MINCLEVEL - 1; /* lower than minimum */ |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 870 | unsigned recursive = 0; |
Yann Collet | d4cda27 | 2016-10-14 13:13:13 -0700 | [diff] [blame] | 871 | unsigned memLimit = 0; |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 872 | FileNamesTable* filenames = UTIL_allocateFileNamesTable((size_t)argCount); /* argCount >= 1 */ |
| 873 | FileNamesTable* file_of_names = UTIL_allocateFileNamesTable((size_t)argCount); /* argCount >= 1 */ |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 874 | const char* programName = argv[0]; |
| 875 | const char* outFileName = NULL; |
Sen Huang | 7f98b46 | 2019-09-05 16:03:35 -0700 | [diff] [blame] | 876 | const char* outDirName = NULL; |
Xin Xie | 9a8ccd4 | 2020-06-19 19:35:51 -0700 | [diff] [blame] | 877 | const char* outMirroredDirName = NULL; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 878 | const char* dictFileName = NULL; |
Bimba Shrestha | f25a6e9 | 2020-01-10 14:25:24 -0800 | [diff] [blame] | 879 | const char* patchFromDictFileName = NULL; |
Przemyslaw Skibinski | cb56306 | 2017-02-08 17:37:14 +0100 | [diff] [blame] | 880 | const char* suffix = ZSTD_EXTENSION; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 881 | unsigned maxDictSize = g_defaultMaxDictSize; |
Yann Collet | 290aaa7 | 2016-05-30 21:18:52 +0200 | [diff] [blame] | 882 | unsigned dictID = 0; |
Nick Magerko | af0c950 | 2019-08-15 23:57:55 -0700 | [diff] [blame] | 883 | size_t streamSrcSize = 0; |
Ephraim Park | 9007701 | 2019-06-24 13:40:52 -0700 | [diff] [blame] | 884 | size_t targetCBlockSize = 0; |
Nick Magerko | dffbac5 | 2019-08-19 08:52:08 -0700 | [diff] [blame] | 885 | size_t srcSizeHint = 0; |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 886 | size_t nbInputFileNames = 0; |
Yann Collet | 4110534 | 2016-07-27 15:09:11 +0200 | [diff] [blame] | 887 | int dictCLevel = g_defaultDictCLevel; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 888 | unsigned dictSelect = g_defaultSelectivityLevel; |
Nick Terrell | df8415c | 2016-12-31 21:08:24 -0800 | [diff] [blame] | 889 | #ifndef ZSTD_NODICT |
Nick Terrell | 5b7fd7c | 2017-06-26 21:07:14 -0700 | [diff] [blame] | 890 | ZDICT_cover_params_t coverParams = defaultCoverParams(); |
Jennifer Liu | 9d6ed9d | 2018-08-23 12:06:20 -0700 | [diff] [blame] | 891 | ZDICT_fastCover_params_t fastCoverParams = defaultFastCoverParams(); |
| 892 | dictType dict = fastCover; |
Nick Terrell | df8415c | 2016-12-31 21:08:24 -0800 | [diff] [blame] | 893 | #endif |
Yann Collet | 5203f01 | 2018-08-03 07:54:29 -0700 | [diff] [blame] | 894 | #ifndef ZSTD_NOBENCH |
| 895 | BMK_advancedParams_t benchParams = BMK_initAdvancedParams(); |
| 896 | #endif |
senhuang42 | b5c35d7 | 2021-09-20 09:04:07 -0400 | [diff] [blame] | 897 | ZSTD_paramSwitch_e literalCompressionMode = ZSTD_ps_auto; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 898 | |
Yann Collet | 00fc1ba | 2017-10-01 12:10:26 -0700 | [diff] [blame] | 899 | |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 900 | /* init */ |
Yann Collet | 3324e87 | 2021-01-07 10:37:27 -0800 | [diff] [blame] | 901 | checkLibVersion(); |
Yann Collet | f3a1a84 | 2016-06-05 01:05:01 +0200 | [diff] [blame] | 902 | (void)recursive; (void)cLevelLast; /* not used when ZSTD_NOBENCH set */ |
Bimba Shrestha | f25a6e9 | 2020-01-10 14:25:24 -0800 | [diff] [blame] | 903 | (void)memLimit; |
Yann Collet | a49417b | 2019-12-02 14:28:18 -0800 | [diff] [blame] | 904 | assert(argCount >= 1); |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 905 | if ((filenames==NULL) || (file_of_names==NULL)) { DISPLAYLEVEL(1, "zstd: allocation error \n"); exit(1); } |
Sean Purcell | ef30af8 | 2017-03-24 17:06:09 -0700 | [diff] [blame] | 906 | programName = lastNameFromPath(programName); |
Yann Collet | 5cb1144 | 2018-02-13 14:56:35 -0800 | [diff] [blame] | 907 | #ifdef ZSTD_MULTITHREAD |
senhuang42 | a71963c | 2020-09-09 12:35:40 -0400 | [diff] [blame] | 908 | nbWorkers = init_nbThreads(); |
Yann Collet | 5cb1144 | 2018-02-13 14:56:35 -0800 | [diff] [blame] | 909 | #endif |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 910 | |
| 911 | /* preset behaviors */ |
Yann Collet | b5207aa | 2018-06-29 17:10:56 -0700 | [diff] [blame] | 912 | if (exeNameMatch(programName, ZSTD_ZSTDMT)) nbWorkers=0, singleThread=0; |
Sean Purcell | ef30af8 | 2017-03-24 17:06:09 -0700 | [diff] [blame] | 913 | if (exeNameMatch(programName, ZSTD_UNZSTD)) operation=zom_decompress; |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 914 | if (exeNameMatch(programName, ZSTD_CAT)) { operation=zom_decompress; FIO_overwriteMode(prefs); forceStdout=1; followLinks=1; FIO_setPassThroughFlag(prefs, 1); outFileName=stdoutmark; g_displayLevel=1; } /* supports multiple formats */ |
| 915 | if (exeNameMatch(programName, ZSTD_ZCAT)) { operation=zom_decompress; FIO_overwriteMode(prefs); forceStdout=1; followLinks=1; FIO_setPassThroughFlag(prefs, 1); outFileName=stdoutmark; g_displayLevel=1; } /* behave like zcat, also supports multiple formats */ |
| 916 | if (exeNameMatch(programName, ZSTD_GZ)) { /* behave like gzip */ |
| 917 | suffix = GZ_EXTENSION; cType = FIO_gzipCompression; removeSrcFile=1; |
| 918 | dictCLevel = cLevel = 6; /* gzip default is -6 */ |
| 919 | } |
| 920 | if (exeNameMatch(programName, ZSTD_GUNZIP)) { operation=zom_decompress; removeSrcFile=1; } /* behave like gunzip, also supports multiple formats */ |
| 921 | if (exeNameMatch(programName, ZSTD_GZCAT)) { operation=zom_decompress; FIO_overwriteMode(prefs); forceStdout=1; followLinks=1; FIO_setPassThroughFlag(prefs, 1); outFileName=stdoutmark; g_displayLevel=1; } /* behave like gzcat, also supports multiple formats */ |
| 922 | if (exeNameMatch(programName, ZSTD_LZMA)) { suffix = LZMA_EXTENSION; cType = FIO_lzmaCompression; removeSrcFile=1; } /* behave like lzma */ |
| 923 | if (exeNameMatch(programName, ZSTD_UNLZMA)) { operation=zom_decompress; cType = FIO_lzmaCompression; removeSrcFile=1; } /* behave like unlzma, also supports multiple formats */ |
| 924 | if (exeNameMatch(programName, ZSTD_XZ)) { suffix = XZ_EXTENSION; cType = FIO_xzCompression; removeSrcFile=1; } /* behave like xz */ |
| 925 | if (exeNameMatch(programName, ZSTD_UNXZ)) { operation=zom_decompress; cType = FIO_xzCompression; removeSrcFile=1; } /* behave like unxz, also supports multiple formats */ |
| 926 | if (exeNameMatch(programName, ZSTD_LZ4)) { suffix = LZ4_EXTENSION; cType = FIO_lz4Compression; } /* behave like lz4 */ |
| 927 | if (exeNameMatch(programName, ZSTD_UNLZ4)) { operation=zom_decompress; cType = FIO_lz4Compression; } /* behave like unlz4, also supports multiple formats */ |
Przemyslaw Skibinski | 671f28d | 2016-12-13 12:18:07 +0100 | [diff] [blame] | 928 | memset(&compressionParams, 0, sizeof(compressionParams)); |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 929 | |
Casey McGinty | a06574f | 2018-09-06 18:46:52 -0700 | [diff] [blame] | 930 | /* init crash handler */ |
Casey McGinty | 2224ecd | 2018-09-11 11:56:50 -0700 | [diff] [blame] | 931 | FIO_addAbortHandler(); |
Casey McGinty | a06574f | 2018-09-06 18:46:52 -0700 | [diff] [blame] | 932 | |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 933 | /* command switches */ |
Yann Collet | 1122349 | 2016-10-14 14:07:11 -0700 | [diff] [blame] | 934 | for (argNb=1; argNb<argCount; argNb++) { |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 935 | const char* argument = argv[argNb]; |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 936 | if (!argument) continue; /* Protection if argument empty */ |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 937 | |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 938 | if (nextArgumentsAreFiles) { |
| 939 | UTIL_refFilename(filenames, argument); |
| 940 | continue; |
| 941 | } |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 942 | |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 943 | /* "-" means stdin/stdout */ |
| 944 | if (!strcmp(argument, "-")){ |
| 945 | UTIL_refFilename(filenames, stdinmark); |
| 946 | continue; |
| 947 | } |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 948 | |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 949 | /* Decode commands (note : aggregated commands are allowed) */ |
| 950 | if (argument[0]=='-') { |
| 951 | |
| 952 | if (argument[1]=='-') { |
| 953 | /* long commands (--long-word) */ |
| 954 | if (!strcmp(argument, "--")) { nextArgumentsAreFiles=1; continue; } /* only file names allowed from now on */ |
| 955 | if (!strcmp(argument, "--list")) { operation=zom_list; continue; } |
| 956 | if (!strcmp(argument, "--compress")) { operation=zom_compress; continue; } |
| 957 | if (!strcmp(argument, "--decompress")) { operation=zom_decompress; continue; } |
| 958 | if (!strcmp(argument, "--uncompress")) { operation=zom_decompress; continue; } |
W. Felix Handte | 33f3e29 | 2021-05-04 16:24:46 -0400 | [diff] [blame] | 959 | if (!strcmp(argument, "--force")) { FIO_overwriteMode(prefs); forceStdin=1; forceStdout=1; followLinks=1; allowBlockDevices=1; continue; } |
Yann Collet | 4b4de74 | 2019-12-02 16:08:08 -0800 | [diff] [blame] | 960 | if (!strcmp(argument, "--version")) { printVersion(); CLEAN_RETURN(0); } |
| 961 | if (!strcmp(argument, "--help")) { usage_advanced(programName); CLEAN_RETURN(0); } |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 962 | if (!strcmp(argument, "--verbose")) { g_displayLevel++; continue; } |
| 963 | if (!strcmp(argument, "--quiet")) { g_displayLevel--; continue; } |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 964 | if (!strcmp(argument, "--stdout")) { forceStdout=1; outFileName=stdoutmark; removeSrcFile=0; continue; } |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 965 | if (!strcmp(argument, "--ultra")) { ultra=1; continue; } |
| 966 | if (!strcmp(argument, "--check")) { FIO_setChecksumFlag(prefs, 2); continue; } |
| 967 | if (!strcmp(argument, "--no-check")) { FIO_setChecksumFlag(prefs, 0); continue; } |
| 968 | if (!strcmp(argument, "--sparse")) { FIO_setSparseWrite(prefs, 2); continue; } |
| 969 | if (!strcmp(argument, "--no-sparse")) { FIO_setSparseWrite(prefs, 0); continue; } |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 970 | if (!strcmp(argument, "--pass-through")) { FIO_setPassThroughFlag(prefs, 1); continue; } |
| 971 | if (!strcmp(argument, "--no-pass-through")) { FIO_setPassThroughFlag(prefs, 0); continue; } |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 972 | if (!strcmp(argument, "--test")) { operation=zom_test; continue; } |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 973 | if (!strcmp(argument, "--asyncio")) { FIO_setAsyncIOFlag(prefs, 1); continue;} |
| 974 | if (!strcmp(argument, "--no-asyncio")) { FIO_setAsyncIOFlag(prefs, 0); continue;} |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 975 | if (!strcmp(argument, "--train")) { operation=zom_train; if (outFileName==NULL) outFileName=g_defaultDictName; continue; } |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 976 | if (!strcmp(argument, "--no-dictID")) { FIO_setDictIDFlag(prefs, 0); continue; } |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 977 | if (!strcmp(argument, "--keep")) { removeSrcFile=0; continue; } |
| 978 | if (!strcmp(argument, "--rm")) { removeSrcFile=1; continue; } |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 979 | if (!strcmp(argument, "--priority=rt")) { setRealTimePrio = 1; continue; } |
Bimba Shrestha | 2f10019 | 2020-01-30 14:12:03 -0800 | [diff] [blame] | 980 | if (!strcmp(argument, "--show-default-cparams")) { showDefaultCParams = 1; continue; } |
Bimba Shrestha | 4387473 | 2020-03-09 14:19:05 -0500 | [diff] [blame] | 981 | if (!strcmp(argument, "--content-size")) { contentSize = 1; continue; } |
Bimba Shrestha | 6d8e761 | 2020-03-09 14:12:52 -0500 | [diff] [blame] | 982 | if (!strcmp(argument, "--no-content-size")) { contentSize = 0; continue; } |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 983 | if (!strcmp(argument, "--adapt")) { adapt = 1; continue; } |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 984 | if (!strcmp(argument, "--no-row-match-finder")) { useRowMatchFinder = ZSTD_ps_disable; continue; } |
| 985 | if (!strcmp(argument, "--row-match-finder")) { useRowMatchFinder = ZSTD_ps_enable; continue; } |
Yann Collet | 4b4de74 | 2019-12-02 16:08:08 -0800 | [diff] [blame] | 986 | if (longCommandWArg(&argument, "--adapt=")) { adapt = 1; if (!parseAdaptParameters(argument, &adaptMin, &adaptMax)) { badusage(programName); CLEAN_RETURN(1); } continue; } |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 987 | if (!strcmp(argument, "--single-thread")) { nbWorkers = 0; singleThread = 1; continue; } |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 988 | if (!strcmp(argument, "--format=zstd")) { suffix = ZSTD_EXTENSION; cType = FIO_zstdCompression; continue; } |
| 989 | if (!strcmp(argument, "--mmap-dict")) { mmapDict = ZSTD_ps_enable; continue; } |
| 990 | if (!strcmp(argument, "--no-mmap-dict")) { mmapDict = ZSTD_ps_disable; continue; } |
Yann Collet | c1c040e | 2017-03-01 16:49:20 -0800 | [diff] [blame] | 991 | #ifdef ZSTD_GZCOMPRESS |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 992 | if (!strcmp(argument, "--format=gzip")) { suffix = GZ_EXTENSION; cType = FIO_gzipCompression; continue; } |
| 993 | if (exeNameMatch(programName, ZSTD_GZ)) { /* behave like gzip */ |
| 994 | if (!strcmp(argument, "--best")) { dictCLevel = cLevel = 9; continue; } |
| 995 | if (!strcmp(argument, "--no-name")) { /* ignore for now */; continue; } |
| 996 | } |
Yann Collet | c1c040e | 2017-03-01 16:49:20 -0800 | [diff] [blame] | 997 | #endif |
Nick Terrell | aa8bcf3 | 2017-03-13 18:11:07 -0700 | [diff] [blame] | 998 | #ifdef ZSTD_LZMACOMPRESS |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 999 | if (!strcmp(argument, "--format=lzma")) { suffix = LZMA_EXTENSION; cType = FIO_lzmaCompression; continue; } |
| 1000 | if (!strcmp(argument, "--format=xz")) { suffix = XZ_EXTENSION; cType = FIO_xzCompression; continue; } |
Nick Terrell | aa8bcf3 | 2017-03-13 18:11:07 -0700 | [diff] [blame] | 1001 | #endif |
Sean Purcell | 4de8632 | 2017-04-24 16:48:25 -0700 | [diff] [blame] | 1002 | #ifdef ZSTD_LZ4COMPRESS |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 1003 | if (!strcmp(argument, "--format=lz4")) { suffix = LZ4_EXTENSION; cType = FIO_lz4Compression; continue; } |
Sean Purcell | 4de8632 | 2017-04-24 16:48:25 -0700 | [diff] [blame] | 1004 | #endif |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 1005 | if (!strcmp(argument, "--rsyncable")) { rsyncable = 1; continue; } |
senhuang42 | b5c35d7 | 2021-09-20 09:04:07 -0400 | [diff] [blame] | 1006 | if (!strcmp(argument, "--compress-literals")) { literalCompressionMode = ZSTD_ps_enable; continue; } |
| 1007 | if (!strcmp(argument, "--no-compress-literals")) { literalCompressionMode = ZSTD_ps_disable; continue; } |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 1008 | if (!strcmp(argument, "--no-progress")) { progress = FIO_ps_never; continue; } |
| 1009 | if (!strcmp(argument, "--progress")) { progress = FIO_ps_always; continue; } |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 1010 | if (!strcmp(argument, "--exclude-compressed")) { FIO_setExcludeCompressedFile(prefs, 1); continue; } |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 1011 | if (!strcmp(argument, "--fake-stdin-is-console")) { UTIL_fakeStdinIsConsole(); continue; } |
| 1012 | if (!strcmp(argument, "--fake-stdout-is-console")) { UTIL_fakeStdoutIsConsole(); continue; } |
| 1013 | if (!strcmp(argument, "--fake-stderr-is-console")) { UTIL_fakeStderrIsConsole(); continue; } |
| 1014 | if (!strcmp(argument, "--trace-file-stat")) { UTIL_traceFileStat(); continue; } |
Yann Collet | 610c41f | 2020-07-20 17:41:32 -0700 | [diff] [blame] | 1015 | |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 1016 | /* long commands with arguments */ |
Yann Collet | c1c040e | 2017-03-01 16:49:20 -0800 | [diff] [blame] | 1017 | #ifndef ZSTD_NODICT |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 1018 | if (longCommandWArg(&argument, "--train-cover")) { |
| 1019 | operation = zom_train; |
| 1020 | if (outFileName == NULL) |
| 1021 | outFileName = g_defaultDictName; |
| 1022 | dict = cover; |
| 1023 | /* Allow optional arguments following an = */ |
| 1024 | if (*argument == 0) { memset(&coverParams, 0, sizeof(coverParams)); } |
Yann Collet | 4b4de74 | 2019-12-02 16:08:08 -0800 | [diff] [blame] | 1025 | else if (*argument++ != '=') { badusage(programName); CLEAN_RETURN(1); } |
| 1026 | else if (!parseCoverParameters(argument, &coverParams)) { badusage(programName); CLEAN_RETURN(1); } |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 1027 | continue; |
| 1028 | } |
| 1029 | if (longCommandWArg(&argument, "--train-fastcover")) { |
| 1030 | operation = zom_train; |
| 1031 | if (outFileName == NULL) |
| 1032 | outFileName = g_defaultDictName; |
| 1033 | dict = fastCover; |
| 1034 | /* Allow optional arguments following an = */ |
| 1035 | if (*argument == 0) { memset(&fastCoverParams, 0, sizeof(fastCoverParams)); } |
Yann Collet | 4b4de74 | 2019-12-02 16:08:08 -0800 | [diff] [blame] | 1036 | else if (*argument++ != '=') { badusage(programName); CLEAN_RETURN(1); } |
| 1037 | else if (!parseFastCoverParameters(argument, &fastCoverParams)) { badusage(programName); CLEAN_RETURN(1); } |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 1038 | continue; |
| 1039 | } |
| 1040 | if (longCommandWArg(&argument, "--train-legacy")) { |
| 1041 | operation = zom_train; |
| 1042 | if (outFileName == NULL) |
| 1043 | outFileName = g_defaultDictName; |
| 1044 | dict = legacy; |
| 1045 | /* Allow optional arguments following an = */ |
| 1046 | if (*argument == 0) { continue; } |
Yann Collet | 4b4de74 | 2019-12-02 16:08:08 -0800 | [diff] [blame] | 1047 | else if (*argument++ != '=') { badusage(programName); CLEAN_RETURN(1); } |
| 1048 | else if (!parseLegacyParameters(argument, &dictSelect)) { badusage(programName); CLEAN_RETURN(1); } |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 1049 | continue; |
| 1050 | } |
Nick Terrell | df8415c | 2016-12-31 21:08:24 -0800 | [diff] [blame] | 1051 | #endif |
Yann Collet | 610c41f | 2020-07-20 17:41:32 -0700 | [diff] [blame] | 1052 | if (longCommandWArg(&argument, "--threads")) { NEXT_UINT32(nbWorkers); continue; } |
| 1053 | if (longCommandWArg(&argument, "--memlimit")) { NEXT_UINT32(memLimit); continue; } |
| 1054 | if (longCommandWArg(&argument, "--memory")) { NEXT_UINT32(memLimit); continue; } |
| 1055 | if (longCommandWArg(&argument, "--memlimit-decompress")) { NEXT_UINT32(memLimit); continue; } |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 1056 | if (longCommandWArg(&argument, "--block-size")) { NEXT_TSIZE(blockSize); continue; } |
Yann Collet | 610c41f | 2020-07-20 17:41:32 -0700 | [diff] [blame] | 1057 | if (longCommandWArg(&argument, "--maxdict")) { NEXT_UINT32(maxDictSize); continue; } |
| 1058 | if (longCommandWArg(&argument, "--dictID")) { NEXT_UINT32(dictID); continue; } |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 1059 | if (longCommandWArg(&argument, "--zstd=")) { if (!parseCompressionParameters(argument, &compressionParams)) { badusage(programName); CLEAN_RETURN(1); } ; cType = FIO_zstdCompression; continue; } |
| 1060 | if (longCommandWArg(&argument, "--stream-size")) { NEXT_TSIZE(streamSrcSize); continue; } |
| 1061 | if (longCommandWArg(&argument, "--target-compressed-block-size")) { NEXT_TSIZE(targetCBlockSize); continue; } |
| 1062 | if (longCommandWArg(&argument, "--size-hint")) { NEXT_TSIZE(srcSizeHint); continue; } |
| 1063 | if (longCommandWArg(&argument, "--output-dir-flat")) { |
| 1064 | NEXT_FIELD(outDirName); |
| 1065 | if (strlen(outDirName) == 0) { |
| 1066 | DISPLAYLEVEL(1, "error: output dir cannot be empty string (did you mean to pass '.' instead?)\n"); |
| 1067 | CLEAN_RETURN(1); |
| 1068 | } |
| 1069 | continue; |
| 1070 | } |
Binh Vo | 6a46e38 | 2021-06-16 09:38:43 -0400 | [diff] [blame] | 1071 | if (longCommandWArg(&argument, "--auto-threads")) { |
| 1072 | const char* threadDefault = NULL; |
| 1073 | NEXT_FIELD(threadDefault); |
| 1074 | if (strcmp(threadDefault, "logical") == 0) |
| 1075 | defaultLogicalCores = 1; |
| 1076 | continue; |
| 1077 | } |
Yann Collet | 610c41f | 2020-07-20 17:41:32 -0700 | [diff] [blame] | 1078 | #ifdef UTIL_HAS_MIRRORFILELIST |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 1079 | if (longCommandWArg(&argument, "--output-dir-mirror")) { |
| 1080 | NEXT_FIELD(outMirroredDirName); |
| 1081 | if (strlen(outMirroredDirName) == 0) { |
| 1082 | DISPLAYLEVEL(1, "error: output dir cannot be empty string (did you mean to pass '.' instead?)\n"); |
| 1083 | CLEAN_RETURN(1); |
| 1084 | } |
| 1085 | continue; |
| 1086 | } |
Yann Collet | 610c41f | 2020-07-20 17:41:32 -0700 | [diff] [blame] | 1087 | #endif |
Nick Terrell | 54a4998 | 2021-02-03 19:53:00 -0800 | [diff] [blame] | 1088 | #ifndef ZSTD_NOTRACE |
| 1089 | if (longCommandWArg(&argument, "--trace")) { char const* traceFile; NEXT_FIELD(traceFile); TRACE_enable(traceFile); continue; } |
| 1090 | #endif |
Yann Collet | 610c41f | 2020-07-20 17:41:32 -0700 | [diff] [blame] | 1091 | if (longCommandWArg(&argument, "--patch-from")) { NEXT_FIELD(patchFromDictFileName); continue; } |
binhdvo | 325952f | 2021-06-09 15:35:43 -0400 | [diff] [blame] | 1092 | if (longCommandWArg(&argument, "--long")) { |
| 1093 | unsigned ldmWindowLog = 0; |
| 1094 | ldmFlag = 1; |
| 1095 | /* Parse optional window log */ |
| 1096 | if (*argument == '=') { |
| 1097 | ++argument; |
| 1098 | ldmWindowLog = readU32FromChar(&argument); |
| 1099 | } else if (*argument != 0) { |
| 1100 | /* Invalid character following --long */ |
| 1101 | badusage(programName); |
| 1102 | CLEAN_RETURN(1); |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 1103 | } else { |
| 1104 | ldmWindowLog = g_defaultMaxWindowLog; |
binhdvo | 325952f | 2021-06-09 15:35:43 -0400 | [diff] [blame] | 1105 | } |
| 1106 | /* Only set windowLog if not already set by --zstd */ |
| 1107 | if (compressionParams.windowLog == 0) |
| 1108 | compressionParams.windowLog = ldmWindowLog; |
| 1109 | continue; |
| 1110 | } |
Yann Collet | 0fc07eb | 2018-09-22 17:21:39 -0700 | [diff] [blame] | 1111 | #ifndef ZSTD_NOCOMPRESS /* linking ZSTD_minCLevel() requires compression support */ |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 1112 | if (longCommandWArg(&argument, "--fast")) { |
| 1113 | /* Parse optional acceleration factor */ |
| 1114 | if (*argument == '=') { |
| 1115 | U32 const maxFast = (U32)-ZSTD_minCLevel(); |
| 1116 | U32 fastLevel; |
| 1117 | ++argument; |
| 1118 | fastLevel = readU32FromChar(&argument); |
| 1119 | if (fastLevel > maxFast) fastLevel = maxFast; |
| 1120 | if (fastLevel) { |
Yann Collet | 4b4de74 | 2019-12-02 16:08:08 -0800 | [diff] [blame] | 1121 | dictCLevel = cLevel = -(int)fastLevel; |
Yann Collet | 6a9b41b | 2018-03-11 19:56:48 -0700 | [diff] [blame] | 1122 | } else { |
Yann Collet | 4b4de74 | 2019-12-02 16:08:08 -0800 | [diff] [blame] | 1123 | badusage(programName); |
| 1124 | CLEAN_RETURN(1); |
Yann Collet | 6a9b41b | 2018-03-11 19:56:48 -0700 | [diff] [blame] | 1125 | } |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 1126 | } else if (*argument != 0) { |
| 1127 | /* Invalid character following --fast */ |
Yann Collet | 4b4de74 | 2019-12-02 16:08:08 -0800 | [diff] [blame] | 1128 | badusage(programName); |
| 1129 | CLEAN_RETURN(1); |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 1130 | } else { |
| 1131 | cLevel = -1; /* default for --fast */ |
Yann Collet | 6a9b41b | 2018-03-11 19:56:48 -0700 | [diff] [blame] | 1132 | } |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 1133 | continue; |
| 1134 | } |
Yann Collet | 0fc07eb | 2018-09-22 17:21:39 -0700 | [diff] [blame] | 1135 | #endif |
Ahmed Abdellah | 779ea72 | 2019-10-15 07:49:13 +0100 | [diff] [blame] | 1136 | |
Yann Collet | 610c41f | 2020-07-20 17:41:32 -0700 | [diff] [blame] | 1137 | if (longCommandWArg(&argument, "--filelist")) { |
| 1138 | const char* listName; |
| 1139 | NEXT_FIELD(listName); |
| 1140 | UTIL_refFilename(file_of_names, listName); |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 1141 | continue; |
Yann Collet | 743b33f | 2016-12-02 15:18:57 -0800 | [diff] [blame] | 1142 | } |
| 1143 | |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 1144 | /* fall-through, will trigger bad_usage() later on */ |
| 1145 | } |
| 1146 | |
| 1147 | argument++; |
| 1148 | while (argument[0]!=0) { |
Yann Collet | 7280c1d | 2020-07-17 13:09:23 -0700 | [diff] [blame] | 1149 | |
Yann Collet | c843142 | 2016-09-01 15:05:57 -0700 | [diff] [blame] | 1150 | #ifndef ZSTD_NOCOMPRESS |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 1151 | /* compression Level */ |
| 1152 | if ((*argument>='0') && (*argument<='9')) { |
| 1153 | dictCLevel = cLevel = (int)readU32FromChar(&argument); |
| 1154 | continue; |
| 1155 | } |
Yann Collet | c843142 | 2016-09-01 15:05:57 -0700 | [diff] [blame] | 1156 | #endif |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 1157 | |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 1158 | switch(argument[0]) |
| 1159 | { |
| 1160 | /* Display help */ |
Yann Collet | 4b4de74 | 2019-12-02 16:08:08 -0800 | [diff] [blame] | 1161 | case 'V': printVersion(); CLEAN_RETURN(0); /* Version Only */ |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 1162 | case 'H': usage_advanced(programName); CLEAN_RETURN(0); |
| 1163 | case 'h': usage(stdout, programName); CLEAN_RETURN(0); |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 1164 | |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 1165 | /* Compress */ |
| 1166 | case 'z': operation=zom_compress; argument++; break; |
Yann Collet | 22de81e | 2016-10-28 13:58:31 -0700 | [diff] [blame] | 1167 | |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 1168 | /* Decoding */ |
| 1169 | case 'd': |
Yann Collet | 2a826e5 | 2016-12-06 17:56:20 -0800 | [diff] [blame] | 1170 | #ifndef ZSTD_NOBENCH |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 1171 | benchParams.mode = BMK_decodeOnly; |
| 1172 | if (operation==zom_bench) { argument++; break; } /* benchmark decode (hidden option) */ |
Yann Collet | 2a826e5 | 2016-12-06 17:56:20 -0800 | [diff] [blame] | 1173 | #endif |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 1174 | operation=zom_decompress; argument++; break; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 1175 | |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 1176 | /* Force stdout, even if stdout==console */ |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 1177 | case 'c': forceStdout=1; outFileName=stdoutmark; removeSrcFile=0; argument++; break; |
| 1178 | |
| 1179 | /* do not store filename - gzip compatibility - nothing to do */ |
| 1180 | case 'n': argument++; break; |
Dirk Müller | e653e97 | 2022-02-08 21:32:42 +0100 | [diff] [blame] | 1181 | |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 1182 | /* Use file content as dictionary */ |
Yann Collet | 610c41f | 2020-07-20 17:41:32 -0700 | [diff] [blame] | 1183 | case 'D': argument++; NEXT_FIELD(dictFileName); break; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 1184 | |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 1185 | /* Overwrite */ |
W. Felix Handte | 33f3e29 | 2021-05-04 16:24:46 -0400 | [diff] [blame] | 1186 | case 'f': FIO_overwriteMode(prefs); forceStdin=1; forceStdout=1; followLinks=1; allowBlockDevices=1; argument++; break; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 1187 | |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 1188 | /* Verbose mode */ |
| 1189 | case 'v': g_displayLevel++; argument++; break; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 1190 | |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 1191 | /* Quiet mode */ |
| 1192 | case 'q': g_displayLevel--; argument++; break; |
Yann Collet | 2c4acda | 2016-06-02 17:05:50 +0200 | [diff] [blame] | 1193 | |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 1194 | /* keep source file (default) */ |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 1195 | case 'k': removeSrcFile=0; argument++; break; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 1196 | |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 1197 | /* Checksum */ |
| 1198 | case 'C': FIO_setChecksumFlag(prefs, 2); argument++; break; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 1199 | |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 1200 | /* test compressed file */ |
| 1201 | case 't': operation=zom_test; argument++; break; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 1202 | |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 1203 | /* destination file name */ |
Yann Collet | 610c41f | 2020-07-20 17:41:32 -0700 | [diff] [blame] | 1204 | case 'o': argument++; NEXT_FIELD(outFileName); break; |
Yann Collet | 7f86ae2 | 2019-10-17 15:27:25 -0700 | [diff] [blame] | 1205 | |
Bimba Shrestha | f25a6e9 | 2020-01-10 14:25:24 -0800 | [diff] [blame] | 1206 | /* limit memory */ |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 1207 | case 'M': |
| 1208 | argument++; |
| 1209 | memLimit = readU32FromChar(&argument); |
| 1210 | break; |
| 1211 | case 'l': operation=zom_list; argument++; break; |
Yann Collet | c4cc9bf | 2016-09-13 17:50:08 +0200 | [diff] [blame] | 1212 | #ifdef UTIL_HAS_CREATEFILELIST |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 1213 | /* recursive */ |
| 1214 | case 'r': recursive=1; argument++; break; |
Yann Collet | c4cc9bf | 2016-09-13 17:50:08 +0200 | [diff] [blame] | 1215 | #endif |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 1216 | |
Yann Collet | c843142 | 2016-09-01 15:05:57 -0700 | [diff] [blame] | 1217 | #ifndef ZSTD_NOBENCH |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 1218 | /* Benchmark */ |
| 1219 | case 'b': |
| 1220 | operation=zom_bench; |
| 1221 | argument++; |
| 1222 | break; |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 1223 | |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 1224 | /* range bench (benchmark only) */ |
| 1225 | case 'e': |
| 1226 | /* compression Level */ |
| 1227 | argument++; |
| 1228 | cLevelLast = (int)readU32FromChar(&argument); |
| 1229 | break; |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 1230 | |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 1231 | /* Modify Nb Iterations (benchmark only) */ |
| 1232 | case 'i': |
| 1233 | argument++; |
| 1234 | bench_nbSeconds = readU32FromChar(&argument); |
| 1235 | break; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 1236 | |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 1237 | /* cut input into blocks (benchmark only) */ |
| 1238 | case 'B': |
| 1239 | argument++; |
| 1240 | blockSize = readU32FromChar(&argument); |
| 1241 | break; |
Yann Collet | 7474526 | 2017-01-02 02:05:45 +0100 | [diff] [blame] | 1242 | |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 1243 | /* benchmark files separately (hidden option) */ |
| 1244 | case 'S': |
| 1245 | argument++; |
| 1246 | separateFiles = 1; |
| 1247 | break; |
Yann Collet | d898fb7 | 2017-11-17 00:22:55 -0800 | [diff] [blame] | 1248 | |
Yann Collet | 500014a | 2017-01-19 16:59:56 -0800 | [diff] [blame] | 1249 | #endif /* ZSTD_NOBENCH */ |
| 1250 | |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 1251 | /* nb of threads (hidden option) */ |
| 1252 | case 'T': |
| 1253 | argument++; |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 1254 | nbWorkers = readU32FromChar(&argument); |
George Lu | a8eea99 | 2018-06-19 10:58:22 -0700 | [diff] [blame] | 1255 | break; |
| 1256 | |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 1257 | /* Dictionary Selection level */ |
| 1258 | case 's': |
| 1259 | argument++; |
| 1260 | dictSelect = readU32FromChar(&argument); |
| 1261 | break; |
| 1262 | |
| 1263 | /* Pause at the end (-p) or set an additional param (-p#) (hidden option) */ |
| 1264 | case 'p': argument++; |
| 1265 | #ifndef ZSTD_NOBENCH |
| 1266 | if ((*argument>='0') && (*argument<='9')) { |
| 1267 | benchParams.additionalParam = (int)readU32FromChar(&argument); |
| 1268 | } else |
| 1269 | #endif |
| 1270 | main_pause=1; |
| 1271 | break; |
| 1272 | |
| 1273 | /* Select compressibility of synthetic sample */ |
| 1274 | case 'P': |
Yann Collet | 610c41f | 2020-07-20 17:41:32 -0700 | [diff] [blame] | 1275 | argument++; |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 1276 | compressibility = (double)readU32FromChar(&argument) / 100; |
Yann Collet | 610c41f | 2020-07-20 17:41:32 -0700 | [diff] [blame] | 1277 | break; |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 1278 | |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 1279 | /* unknown command */ |
Yann Collet | 4b4de74 | 2019-12-02 16:08:08 -0800 | [diff] [blame] | 1280 | default : badusage(programName); CLEAN_RETURN(1); |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 1281 | } |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 1282 | } |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 1283 | continue; |
| 1284 | } /* if (argument[0]=='-') */ |
Yann Collet | f9cac7a | 2016-07-04 18:16:16 +0200 | [diff] [blame] | 1285 | |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 1286 | /* none of the above : add filename to list */ |
| 1287 | UTIL_refFilename(filenames, argument); |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 1288 | } |
| 1289 | |
| 1290 | /* Welcome message (if verbose) */ |
| 1291 | DISPLAYLEVEL(3, WELCOME_MESSAGE); |
| 1292 | |
Yann Collet | 5cb1144 | 2018-02-13 14:56:35 -0800 | [diff] [blame] | 1293 | #ifdef ZSTD_MULTITHREAD |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 1294 | if ((operation==zom_decompress) && (!singleThread) && (nbWorkers > 1)) { |
| 1295 | DISPLAYLEVEL(2, "Warning : decompression does not support multi-threading\n"); |
| 1296 | } |
Yann Collet | 5cb1144 | 2018-02-13 14:56:35 -0800 | [diff] [blame] | 1297 | if ((nbWorkers==0) && (!singleThread)) { |
Yann Collet | 209df52 | 2018-02-01 19:29:30 -0800 | [diff] [blame] | 1298 | /* automatically set # workers based on # of reported cpus */ |
Binh Vo | 6a46e38 | 2021-06-16 09:38:43 -0400 | [diff] [blame] | 1299 | if (defaultLogicalCores) { |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 1300 | nbWorkers = (unsigned)UTIL_countLogicalCores(); |
Binh Vo | 6a46e38 | 2021-06-16 09:38:43 -0400 | [diff] [blame] | 1301 | DISPLAYLEVEL(3, "Note: %d logical core(s) detected \n", nbWorkers); |
| 1302 | } else { |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 1303 | nbWorkers = (unsigned)UTIL_countPhysicalCores(); |
Binh Vo | 6a46e38 | 2021-06-16 09:38:43 -0400 | [diff] [blame] | 1304 | DISPLAYLEVEL(3, "Note: %d physical core(s) detected \n", nbWorkers); |
| 1305 | } |
Sean Purcell | afa4851 | 2017-04-13 12:28:28 -0700 | [diff] [blame] | 1306 | } |
cyan4973 | f741fb8 | 2018-06-26 01:22:45 -0700 | [diff] [blame] | 1307 | #else |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 1308 | (void)singleThread; (void)nbWorkers; (void)defaultLogicalCores; |
Yann Collet | 5cb1144 | 2018-02-13 14:56:35 -0800 | [diff] [blame] | 1309 | #endif |
Sean Purcell | 680e4e0 | 2017-03-23 11:52:09 -0700 | [diff] [blame] | 1310 | |
Sean Purcell | dee08ca | 2017-03-23 12:09:35 -0700 | [diff] [blame] | 1311 | g_utilDisplayLevel = g_displayLevel; |
W. Felix Handte | 464bfb0 | 2021-06-09 15:22:59 -0400 | [diff] [blame] | 1312 | |
| 1313 | #ifdef UTIL_HAS_CREATEFILELIST |
Sean Purcell | 680e4e0 | 2017-03-23 11:52:09 -0700 | [diff] [blame] | 1314 | if (!followLinks) { |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 1315 | unsigned u, fileNamesNb; |
| 1316 | unsigned const nbFilenames = (unsigned)filenames->tableSize; |
| 1317 | for (u=0, fileNamesNb=0; u<nbFilenames; u++) { |
Yann Collet | c71bd45 | 2019-11-26 11:20:26 -0800 | [diff] [blame] | 1318 | if ( UTIL_isLink(filenames->fileNames[u]) |
| 1319 | && !UTIL_isFIFO(filenames->fileNames[u]) |
Bimba Shrestha | 0b52d87 | 2019-10-25 14:06:50 -0700 | [diff] [blame] | 1320 | ) { |
Yann Collet | c71bd45 | 2019-11-26 11:20:26 -0800 | [diff] [blame] | 1321 | DISPLAYLEVEL(2, "Warning : %s is a symbolic link, ignoring \n", filenames->fileNames[u]); |
Sean Purcell | 680e4e0 | 2017-03-23 11:52:09 -0700 | [diff] [blame] | 1322 | } else { |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 1323 | filenames->fileNames[fileNamesNb++] = filenames->fileNames[u]; |
Yann Collet | b40eace | 2019-10-25 18:16:45 -0700 | [diff] [blame] | 1324 | } } |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 1325 | if (fileNamesNb == 0 && nbFilenames > 0) /* all names are eliminated */ |
Björn Ketelaars | 482b84f | 2019-02-12 00:07:32 +0100 | [diff] [blame] | 1326 | CLEAN_RETURN(1); |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 1327 | filenames->tableSize = fileNamesNb; |
| 1328 | } /* if (!followLinks) */ |
| 1329 | |
| 1330 | /* read names from a file */ |
| 1331 | if (file_of_names->tableSize) { |
| 1332 | size_t const nbFileLists = file_of_names->tableSize; |
| 1333 | size_t flNb; |
| 1334 | for (flNb=0; flNb < nbFileLists; flNb++) { |
| 1335 | FileNamesTable* const fnt = UTIL_createFileNamesTable_fromFileName(file_of_names->fileNames[flNb]); |
| 1336 | if (fnt==NULL) { |
| 1337 | DISPLAYLEVEL(1, "zstd: error reading %s \n", file_of_names->fileNames[flNb]); |
| 1338 | CLEAN_RETURN(1); |
| 1339 | } |
Yann Collet | 31a0abb | 2019-11-06 09:10:05 -0800 | [diff] [blame] | 1340 | filenames = UTIL_mergeFileNamesTable(filenames, fnt); |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 1341 | } |
Sean Purcell | 680e4e0 | 2017-03-23 11:52:09 -0700 | [diff] [blame] | 1342 | } |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 1343 | |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 1344 | nbInputFileNames = filenames->tableSize; /* saving number of input files */ |
| 1345 | |
Yann Collet | 0977f7e | 2016-09-21 12:24:43 +0200 | [diff] [blame] | 1346 | if (recursive) { /* at this stage, filenameTable is a list of paths, which can contain both files and directories */ |
Yann Collet | 31a0abb | 2019-11-06 09:10:05 -0800 | [diff] [blame] | 1347 | UTIL_expandFNT(&filenames, followLinks); |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 1348 | } |
cyan4973 | f741fb8 | 2018-06-26 01:22:45 -0700 | [diff] [blame] | 1349 | #else |
| 1350 | (void)followLinks; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 1351 | #endif |
Yann Collet | 166645e | 2017-08-18 18:30:41 -0700 | [diff] [blame] | 1352 | |
Paul Cruz | b3e6244 | 2017-06-15 17:46:49 -0700 | [diff] [blame] | 1353 | if (operation == zom_list) { |
Yann Collet | 166645e | 2017-08-18 18:30:41 -0700 | [diff] [blame] | 1354 | #ifndef ZSTD_NODECOMPRESS |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 1355 | int const ret = FIO_listMultipleFiles((unsigned)filenames->tableSize, filenames->fileNames, g_displayLevel); |
Paul Cruz | bda5775 | 2017-06-20 12:43:10 -0700 | [diff] [blame] | 1356 | CLEAN_RETURN(ret); |
Yann Collet | 166645e | 2017-08-18 18:30:41 -0700 | [diff] [blame] | 1357 | #else |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 1358 | DISPLAYLEVEL(1, "file information is not supported \n"); |
Yann Collet | 166645e | 2017-08-18 18:30:41 -0700 | [diff] [blame] | 1359 | CLEAN_RETURN(1); |
| 1360 | #endif |
Paul Cruz | 901435e | 2017-06-05 14:45:31 -0700 | [diff] [blame] | 1361 | } |
Yann Collet | 166645e | 2017-08-18 18:30:41 -0700 | [diff] [blame] | 1362 | |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 1363 | /* Check if benchmark is selected */ |
Yann Collet | 22de81e | 2016-10-28 13:58:31 -0700 | [diff] [blame] | 1364 | if (operation==zom_bench) { |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 1365 | #ifndef ZSTD_NOBENCH |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 1366 | if (cType != FIO_zstdCompression) { |
| 1367 | DISPLAYLEVEL(1, "benchmark mode is only compatible with zstd format \n"); |
| 1368 | CLEAN_RETURN(1); |
| 1369 | } |
Yann Collet | 5203f01 | 2018-08-03 07:54:29 -0700 | [diff] [blame] | 1370 | benchParams.blockSize = blockSize; |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 1371 | benchParams.nbWorkers = (int)nbWorkers; |
Yann Collet | 7f86ae2 | 2019-10-17 15:27:25 -0700 | [diff] [blame] | 1372 | benchParams.realTime = (unsigned)setRealTimePrio; |
Yann Collet | 5203f01 | 2018-08-03 07:54:29 -0700 | [diff] [blame] | 1373 | benchParams.nbSeconds = bench_nbSeconds; |
| 1374 | benchParams.ldmFlag = ldmFlag; |
Yann Collet | 7f86ae2 | 2019-10-17 15:27:25 -0700 | [diff] [blame] | 1375 | benchParams.ldmMinMatch = (int)g_ldmMinMatch; |
| 1376 | benchParams.ldmHashLog = (int)g_ldmHashLog; |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 1377 | benchParams.useRowMatchFinder = (int)useRowMatchFinder; |
Stella Lau | 67d4a61 | 2017-09-02 21:10:36 -0700 | [diff] [blame] | 1378 | if (g_ldmBucketSizeLog != LDM_PARAM_DEFAULT) { |
Yann Collet | 7f86ae2 | 2019-10-17 15:27:25 -0700 | [diff] [blame] | 1379 | benchParams.ldmBucketSizeLog = (int)g_ldmBucketSizeLog; |
Stella Lau | 67d4a61 | 2017-09-02 21:10:36 -0700 | [diff] [blame] | 1380 | } |
Yann Collet | 41c7d0b | 2018-11-21 14:36:57 -0800 | [diff] [blame] | 1381 | if (g_ldmHashRateLog != LDM_PARAM_DEFAULT) { |
Yann Collet | 7f86ae2 | 2019-10-17 15:27:25 -0700 | [diff] [blame] | 1382 | benchParams.ldmHashRateLog = (int)g_ldmHashRateLog; |
Stella Lau | 67d4a61 | 2017-09-02 21:10:36 -0700 | [diff] [blame] | 1383 | } |
Nick Terrell | 19ca3fb | 2019-02-15 15:24:55 -0800 | [diff] [blame] | 1384 | benchParams.literalCompressionMode = literalCompressionMode; |
George Lu | 0d1ee22 | 2018-06-15 16:21:08 -0400 | [diff] [blame] | 1385 | |
George Lu | a3c8b59 | 2018-06-18 15:06:31 -0700 | [diff] [blame] | 1386 | if (cLevel > ZSTD_maxCLevel()) cLevel = ZSTD_maxCLevel(); |
| 1387 | if (cLevelLast > ZSTD_maxCLevel()) cLevelLast = ZSTD_maxCLevel(); |
| 1388 | if (cLevelLast < cLevel) cLevelLast = cLevel; |
Nick Terrell | 58b8219 | 2018-07-09 18:24:07 -0700 | [diff] [blame] | 1389 | if (cLevelLast > cLevel) |
Yann Collet | 55affc0 | 2018-08-28 11:21:09 -0700 | [diff] [blame] | 1390 | DISPLAYLEVEL(3, "Benchmarking levels from %d to %d\n", cLevel, cLevelLast); |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 1391 | if (filenames->tableSize > 0) { |
George Lu | a8eea99 | 2018-06-19 10:58:22 -0700 | [diff] [blame] | 1392 | if(separateFiles) { |
| 1393 | unsigned i; |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 1394 | for(i = 0; i < filenames->tableSize; i++) { |
George Lu | a8eea99 | 2018-06-19 10:58:22 -0700 | [diff] [blame] | 1395 | int c; |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 1396 | DISPLAYLEVEL(3, "Benchmarking %s \n", filenames->fileNames[i]); |
George Lu | a8eea99 | 2018-06-19 10:58:22 -0700 | [diff] [blame] | 1397 | for(c = cLevel; c <= cLevelLast; c++) { |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 1398 | operationResult = BMK_benchFilesAdvanced(&filenames->fileNames[i], 1, dictFileName, c, &compressionParams, g_displayLevel, &benchParams); |
Yann Collet | 1ead0c5 | 2019-10-25 16:36:59 -0700 | [diff] [blame] | 1399 | } } |
George Lu | a8eea99 | 2018-06-19 10:58:22 -0700 | [diff] [blame] | 1400 | } else { |
| 1401 | for(; cLevel <= cLevelLast; cLevel++) { |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 1402 | operationResult = BMK_benchFilesAdvanced(filenames->fileNames, (unsigned)filenames->tableSize, dictFileName, cLevel, &compressionParams, g_displayLevel, &benchParams); |
Yann Collet | 1ead0c5 | 2019-10-25 16:36:59 -0700 | [diff] [blame] | 1403 | } } |
George Lu | a3c8b59 | 2018-06-18 15:06:31 -0700 | [diff] [blame] | 1404 | } else { |
| 1405 | for(; cLevel <= cLevelLast; cLevel++) { |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 1406 | operationResult = BMK_syntheticTest(cLevel, compressibility, &compressionParams, g_displayLevel, &benchParams); |
Yann Collet | 1ead0c5 | 2019-10-25 16:36:59 -0700 | [diff] [blame] | 1407 | } } |
George Lu | 0d1ee22 | 2018-06-15 16:21:08 -0400 | [diff] [blame] | 1408 | |
Yann Collet | 71f012e | 2017-12-01 17:42:46 -0800 | [diff] [blame] | 1409 | #else |
Yann Collet | 2fdab16 | 2018-08-03 08:30:01 -0700 | [diff] [blame] | 1410 | (void)bench_nbSeconds; (void)blockSize; (void)setRealTimePrio; (void)separateFiles; (void)compressibility; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 1411 | #endif |
| 1412 | goto _end; |
| 1413 | } |
| 1414 | |
| 1415 | /* Check if dictionary builder is selected */ |
Yann Collet | 22de81e | 2016-10-28 13:58:31 -0700 | [diff] [blame] | 1416 | if (operation==zom_train) { |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 1417 | #ifndef ZSTD_NODICT |
Nick Terrell | 5b7fd7c | 2017-06-26 21:07:14 -0700 | [diff] [blame] | 1418 | ZDICT_params_t zParams; |
| 1419 | zParams.compressionLevel = dictCLevel; |
Yann Collet | 7f86ae2 | 2019-10-17 15:27:25 -0700 | [diff] [blame] | 1420 | zParams.notificationLevel = (unsigned)g_displayLevel; |
Nick Terrell | 5b7fd7c | 2017-06-26 21:07:14 -0700 | [diff] [blame] | 1421 | zParams.dictID = dictID; |
Jennifer Liu | 9d6ed9d | 2018-08-23 12:06:20 -0700 | [diff] [blame] | 1422 | if (dict == cover) { |
Nick Terrell | f376d47 | 2017-05-01 23:40:20 -0700 | [diff] [blame] | 1423 | int const optimize = !coverParams.k || !coverParams.d; |
Yann Collet | 7f86ae2 | 2019-10-17 15:27:25 -0700 | [diff] [blame] | 1424 | coverParams.nbThreads = (unsigned)nbWorkers; |
Nick Terrell | 5b7fd7c | 2017-06-26 21:07:14 -0700 | [diff] [blame] | 1425 | coverParams.zParams = zParams; |
Elliot Gorokhovsky | 71c0c07 | 2021-12-10 16:19:40 -0500 | [diff] [blame] | 1426 | operationResult = DiB_trainFromFiles(outFileName, maxDictSize, filenames->fileNames, (int)filenames->tableSize, blockSize, NULL, &coverParams, NULL, optimize, memLimit); |
Jennifer Liu | 9d6ed9d | 2018-08-23 12:06:20 -0700 | [diff] [blame] | 1427 | } else if (dict == fastCover) { |
| 1428 | int const optimize = !fastCoverParams.k || !fastCoverParams.d; |
Yann Collet | 7f86ae2 | 2019-10-17 15:27:25 -0700 | [diff] [blame] | 1429 | fastCoverParams.nbThreads = (unsigned)nbWorkers; |
Jennifer Liu | 9d6ed9d | 2018-08-23 12:06:20 -0700 | [diff] [blame] | 1430 | fastCoverParams.zParams = zParams; |
Elliot Gorokhovsky | 71c0c07 | 2021-12-10 16:19:40 -0500 | [diff] [blame] | 1431 | operationResult = DiB_trainFromFiles(outFileName, maxDictSize, filenames->fileNames, (int)filenames->tableSize, blockSize, NULL, NULL, &fastCoverParams, optimize, memLimit); |
Nick Terrell | df8415c | 2016-12-31 21:08:24 -0800 | [diff] [blame] | 1432 | } else { |
Nick Terrell | 5b7fd7c | 2017-06-26 21:07:14 -0700 | [diff] [blame] | 1433 | ZDICT_legacy_params_t dictParams; |
Nick Terrell | df8415c | 2016-12-31 21:08:24 -0800 | [diff] [blame] | 1434 | memset(&dictParams, 0, sizeof(dictParams)); |
Nick Terrell | df8415c | 2016-12-31 21:08:24 -0800 | [diff] [blame] | 1435 | dictParams.selectivityLevel = dictSelect; |
Nick Terrell | 5b7fd7c | 2017-06-26 21:07:14 -0700 | [diff] [blame] | 1436 | dictParams.zParams = zParams; |
Elliot Gorokhovsky | 71c0c07 | 2021-12-10 16:19:40 -0500 | [diff] [blame] | 1437 | operationResult = DiB_trainFromFiles(outFileName, maxDictSize, filenames->fileNames, (int)filenames->tableSize, blockSize, &dictParams, NULL, NULL, 0, memLimit); |
Nick Terrell | df8415c | 2016-12-31 21:08:24 -0800 | [diff] [blame] | 1438 | } |
Yann Collet | 0250ac7 | 2018-09-24 00:52:19 -0700 | [diff] [blame] | 1439 | #else |
| 1440 | (void)dictCLevel; (void)dictSelect; (void)dictID; (void)maxDictSize; /* not used when ZSTD_NODICT set */ |
| 1441 | DISPLAYLEVEL(1, "training mode not available \n"); |
| 1442 | operationResult = 1; |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 1443 | #endif |
| 1444 | goto _end; |
| 1445 | } |
| 1446 | |
Nick Terrell | d0b2748 | 2017-07-18 14:45:49 -0700 | [diff] [blame] | 1447 | #ifndef ZSTD_NODECOMPRESS |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 1448 | if (operation==zom_test) { FIO_setTestMode(prefs, 1); outFileName=nulmark; removeSrcFile=0; } /* test mode */ |
Nick Terrell | d0b2748 | 2017-07-18 14:45:49 -0700 | [diff] [blame] | 1449 | #endif |
| 1450 | |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 1451 | /* No input filename ==> use stdin and stdout */ |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 1452 | if (filenames->tableSize == 0) { |
| 1453 | /* It is possible that the input |
| 1454 | was a number of empty directories. In this case |
| 1455 | stdin and stdout should not be used */ |
| 1456 | if (nbInputFileNames > 0 ){ |
| 1457 | DISPLAYLEVEL(1, "please provide correct input file(s) or non-empty directories -- ignored \n"); |
| 1458 | CLEAN_RETURN(0); |
| 1459 | } |
| 1460 | UTIL_refFilename(filenames, stdinmark); |
| 1461 | } |
| 1462 | |
| 1463 | if (filenames->tableSize == 1 && !strcmp(filenames->fileNames[0], stdinmark) && !outFileName) |
Yann Collet | 6a9b41b | 2018-03-11 19:56:48 -0700 | [diff] [blame] | 1464 | outFileName = stdoutmark; /* when input is stdin, default output is stdout */ |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 1465 | |
| 1466 | /* Check if input/output defined as console; trigger an error in this case */ |
W. Felix Handte | 8b6a4b5 | 2021-01-11 17:53:20 -0500 | [diff] [blame] | 1467 | if (!forceStdin |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 1468 | && (UTIL_searchFileNamesTable(filenames, stdinmark) != -1) |
| 1469 | && UTIL_isConsole(stdin) ) { |
senhuang42 | ce56810 | 2020-09-28 12:15:18 -0400 | [diff] [blame] | 1470 | DISPLAYLEVEL(1, "stdin is a console, aborting\n"); |
Yann Collet | 4b4de74 | 2019-12-02 16:08:08 -0800 | [diff] [blame] | 1471 | CLEAN_RETURN(1); |
| 1472 | } |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 1473 | if ( (!outFileName || !strcmp(outFileName, stdoutmark)) |
| 1474 | && UTIL_isConsole(stdout) |
| 1475 | && (UTIL_searchFileNamesTable(filenames, stdinmark) != -1) |
Yann Collet | 6a9b41b | 2018-03-11 19:56:48 -0700 | [diff] [blame] | 1476 | && !forceStdout |
Yann Collet | 4b4de74 | 2019-12-02 16:08:08 -0800 | [diff] [blame] | 1477 | && operation!=zom_decompress ) { |
senhuang42 | ce56810 | 2020-09-28 12:15:18 -0400 | [diff] [blame] | 1478 | DISPLAYLEVEL(1, "stdout is a console, aborting\n"); |
Yann Collet | 4b4de74 | 2019-12-02 16:08:08 -0800 | [diff] [blame] | 1479 | CLEAN_RETURN(1); |
| 1480 | } |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 1481 | |
inikep | 23cec87 | 2016-10-05 11:56:22 +0200 | [diff] [blame] | 1482 | #ifndef ZSTD_NOCOMPRESS |
Yann Collet | fe0590f | 2016-08-12 18:04:15 +0200 | [diff] [blame] | 1483 | /* check compression level limits */ |
| 1484 | { int const maxCLevel = ultra ? ZSTD_maxCLevel() : ZSTDCLI_CLEVEL_MAX; |
| 1485 | if (cLevel > maxCLevel) { |
| 1486 | DISPLAYLEVEL(2, "Warning : compression level higher than max, reduced to %i \n", maxCLevel); |
| 1487 | cLevel = maxCLevel; |
| 1488 | } } |
inikep | 23cec87 | 2016-10-05 11:56:22 +0200 | [diff] [blame] | 1489 | #endif |
Yann Collet | fe0590f | 2016-08-12 18:04:15 +0200 | [diff] [blame] | 1490 | |
Bimba Shrestha | 2f10019 | 2020-01-30 14:12:03 -0800 | [diff] [blame] | 1491 | if (showDefaultCParams) { |
| 1492 | if (operation == zom_decompress) { |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 1493 | DISPLAYLEVEL(1, "error : can't use --show-default-cparams in decompression mode \n"); |
Bimba Shrestha | 2f10019 | 2020-01-30 14:12:03 -0800 | [diff] [blame] | 1494 | CLEAN_RETURN(1); |
| 1495 | } |
Bimba Shrestha | 2f10019 | 2020-01-30 14:12:03 -0800 | [diff] [blame] | 1496 | } |
| 1497 | |
Bimba Shrestha | f25a6e9 | 2020-01-10 14:25:24 -0800 | [diff] [blame] | 1498 | if (dictFileName != NULL && patchFromDictFileName != NULL) { |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 1499 | DISPLAYLEVEL(1, "error : can't use -D and --patch-from=# at the same time \n"); |
Bimba Shrestha | f25a6e9 | 2020-01-10 14:25:24 -0800 | [diff] [blame] | 1500 | CLEAN_RETURN(1); |
| 1501 | } |
| 1502 | |
Bimba Shrestha | 5b0a452 | 2020-04-17 15:58:53 -0500 | [diff] [blame] | 1503 | if (patchFromDictFileName != NULL && filenames->tableSize > 1) { |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 1504 | DISPLAYLEVEL(1, "error : can't use --patch-from=# on multiple files \n"); |
Bimba Shrestha | 5b0a452 | 2020-04-17 15:58:53 -0500 | [diff] [blame] | 1505 | CLEAN_RETURN(1); |
| 1506 | } |
Yann Collet | 3324e87 | 2021-01-07 10:37:27 -0800 | [diff] [blame] | 1507 | |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 1508 | /* No status message by default when output is stdout */ |
senhuang42 | 7259b25 | 2020-10-07 13:47:38 -0400 | [diff] [blame] | 1509 | hasStdout = outFileName && !strcmp(outFileName,stdoutmark); |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 1510 | if (hasStdout && (g_displayLevel==2)) g_displayLevel=1; |
Yann Collet | 8c85b29 | 2023-01-23 18:55:51 -0800 | [diff] [blame] | 1511 | |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 1512 | /* when stderr is not the console, do not pollute it with progress updates (unless requested) */ |
| 1513 | if (!UTIL_isConsole(stderr) && (progress!=FIO_ps_always)) progress=FIO_ps_never; |
| 1514 | FIO_setProgressSetting(progress); |
| 1515 | |
| 1516 | /* don't remove source files when output is stdout */; |
| 1517 | if (hasStdout && removeSrcFile) { |
| 1518 | DISPLAYLEVEL(3, "Note: src files are not removed when output is stdout \n"); |
| 1519 | removeSrcFile = 0; |
| 1520 | } |
| 1521 | FIO_setRemoveSrcFile(prefs, removeSrcFile); |
Yann Collet | cee6bec | 2023-01-20 17:53:05 -0800 | [diff] [blame] | 1522 | |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 1523 | /* IO Stream/File */ |
senhuang42 | 7259b25 | 2020-10-07 13:47:38 -0400 | [diff] [blame] | 1524 | FIO_setHasStdoutOutput(fCtx, hasStdout); |
Yann Collet | 3324e87 | 2021-01-07 10:37:27 -0800 | [diff] [blame] | 1525 | FIO_setNbFilesTotal(fCtx, (int)filenames->tableSize); |
senhuang42 | 432186c | 2020-09-24 15:55:30 -0400 | [diff] [blame] | 1526 | FIO_determineHasStdinInput(fCtx, filenames); |
Sean Purcell | 042ba12 | 2017-03-23 11:13:52 -0700 | [diff] [blame] | 1527 | FIO_setNotificationLevel(g_displayLevel); |
W. Felix Handte | 33f3e29 | 2021-05-04 16:24:46 -0400 | [diff] [blame] | 1528 | FIO_setAllowBlockDevices(prefs, allowBlockDevices); |
Bimba Shrestha | f25a6e9 | 2020-01-10 14:25:24 -0800 | [diff] [blame] | 1529 | FIO_setPatchFromMode(prefs, patchFromDictFileName != NULL); |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 1530 | FIO_setMMapDict(prefs, mmapDict); |
Bimba Shrestha | f25a6e9 | 2020-01-10 14:25:24 -0800 | [diff] [blame] | 1531 | if (memLimit == 0) { |
| 1532 | if (compressionParams.windowLog == 0) { |
| 1533 | memLimit = (U32)1 << g_defaultMaxWindowLog; |
| 1534 | } else { |
| 1535 | memLimit = (U32)1 << (compressionParams.windowLog & 31); |
| 1536 | } } |
Bimba Shrestha | 5b0a452 | 2020-04-17 15:58:53 -0500 | [diff] [blame] | 1537 | if (patchFromDictFileName != NULL) |
| 1538 | dictFileName = patchFromDictFileName; |
Bimba Shrestha | f25a6e9 | 2020-01-10 14:25:24 -0800 | [diff] [blame] | 1539 | FIO_setMemLimit(prefs, memLimit); |
Yann Collet | 22de81e | 2016-10-28 13:58:31 -0700 | [diff] [blame] | 1540 | if (operation==zom_compress) { |
Yann Collet | 0977f7e | 2016-09-21 12:24:43 +0200 | [diff] [blame] | 1541 | #ifndef ZSTD_NOCOMPRESS |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 1542 | FIO_setCompressionType(prefs, cType); |
Bimba Shrestha | 6d8e761 | 2020-03-09 14:12:52 -0500 | [diff] [blame] | 1543 | FIO_setContentSize(prefs, contentSize); |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 1544 | FIO_setNbWorkers(prefs, (int)nbWorkers); |
Yann Collet | 7f86ae2 | 2019-10-17 15:27:25 -0700 | [diff] [blame] | 1545 | FIO_setBlockSize(prefs, (int)blockSize); |
| 1546 | if (g_overlapLog!=OVERLAP_LOG_DEFAULT) FIO_setOverlapLog(prefs, (int)g_overlapLog); |
| 1547 | FIO_setLdmFlag(prefs, (unsigned)ldmFlag); |
| 1548 | FIO_setLdmHashLog(prefs, (int)g_ldmHashLog); |
| 1549 | FIO_setLdmMinMatch(prefs, (int)g_ldmMinMatch); |
| 1550 | if (g_ldmBucketSizeLog != LDM_PARAM_DEFAULT) FIO_setLdmBucketSizeLog(prefs, (int)g_ldmBucketSizeLog); |
| 1551 | if (g_ldmHashRateLog != LDM_PARAM_DEFAULT) FIO_setLdmHashRateLog(prefs, (int)g_ldmHashRateLog); |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 1552 | FIO_setAdaptiveMode(prefs, adapt); |
| 1553 | FIO_setUseRowMatchFinder(prefs, (int)useRowMatchFinder); |
Karl Ostmo | 5e220bf | 2019-01-22 17:31:13 -0800 | [diff] [blame] | 1554 | FIO_setAdaptMin(prefs, adaptMin); |
| 1555 | FIO_setAdaptMax(prefs, adaptMax); |
| 1556 | FIO_setRsyncable(prefs, rsyncable); |
Nick Magerko | af0c950 | 2019-08-15 23:57:55 -0700 | [diff] [blame] | 1557 | FIO_setStreamSrcSize(prefs, streamSrcSize); |
Ephraim Park | 9007701 | 2019-06-24 13:40:52 -0700 | [diff] [blame] | 1558 | FIO_setTargetCBlockSize(prefs, targetCBlockSize); |
Nick Magerko | dffbac5 | 2019-08-19 08:52:08 -0700 | [diff] [blame] | 1559 | FIO_setSrcSizeHint(prefs, srcSizeHint); |
Nick Terrell | 19ca3fb | 2019-02-15 15:24:55 -0800 | [diff] [blame] | 1560 | FIO_setLiteralCompressionMode(prefs, literalCompressionMode); |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 1561 | FIO_setSparseWrite(prefs, 0); |
Yann Collet | 6c51bf4 | 2018-09-24 18:16:08 -0700 | [diff] [blame] | 1562 | if (adaptMin > cLevel) cLevel = adaptMin; |
| 1563 | if (adaptMax < cLevel) cLevel = adaptMax; |
Stella Lau | a1f04d5 | 2017-09-01 14:52:51 -0700 | [diff] [blame] | 1564 | |
Bimba Shrestha | d1389ac | 2020-02-03 09:52:39 -0800 | [diff] [blame] | 1565 | /* Compare strategies constant with the ground truth */ |
| 1566 | { ZSTD_bounds strategyBounds = ZSTD_cParam_getBounds(ZSTD_c_strategy); |
W. Felix Handte | 376c26b | 2020-05-08 16:42:15 -0400 | [diff] [blame] | 1567 | assert(ZSTD_NB_STRATEGIES == strategyBounds.upperBound); |
| 1568 | (void)strategyBounds; } |
Bimba Shrestha | 38d010e | 2020-01-31 10:47:17 -0800 | [diff] [blame] | 1569 | |
Kevin Svetlitski | 63fe619 | 2021-11-05 12:48:13 -0700 | [diff] [blame] | 1570 | if (showDefaultCParams || g_displayLevel >= 4) { |
Bimba Shrestha | 2f10019 | 2020-01-30 14:12:03 -0800 | [diff] [blame] | 1571 | size_t fileNb; |
Bimba Shrestha | 2f10019 | 2020-01-30 14:12:03 -0800 | [diff] [blame] | 1572 | for (fileNb = 0; fileNb < (size_t)filenames->tableSize; fileNb++) { |
Kevin Svetlitski | 63fe619 | 2021-11-05 12:48:13 -0700 | [diff] [blame] | 1573 | if (showDefaultCParams) |
| 1574 | printDefaultCParams(filenames->fileNames[fileNb], dictFileName, cLevel); |
| 1575 | if (g_displayLevel >= 4) |
| 1576 | printActualCParams(filenames->fileNames[fileNb], dictFileName, cLevel, &compressionParams); |
Bimba Shrestha | 2f10019 | 2020-01-30 14:12:03 -0800 | [diff] [blame] | 1577 | } |
| 1578 | } |
| 1579 | |
Kevin Svetlitski | 0665d4c | 2021-11-05 12:01:20 -0700 | [diff] [blame] | 1580 | if (g_displayLevel >= 4) |
| 1581 | FIO_displayCompressionParameters(prefs); |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 1582 | if ((filenames->tableSize==1) && outFileName) |
senhuang42 | 5123496 | 2020-09-07 13:13:05 -0400 | [diff] [blame] | 1583 | operationResult = FIO_compressFilename(fCtx, prefs, outFileName, filenames->fileNames[0], dictFileName, cLevel, compressionParams); |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 1584 | else |
senhuang42 | 5123496 | 2020-09-07 13:13:05 -0400 | [diff] [blame] | 1585 | operationResult = FIO_compressMultipleFilenames(fCtx, prefs, filenames->fileNames, outMirroredDirName, outDirName, outFileName, suffix, dictFileName, cLevel, compressionParams); |
Yann Collet | 0977f7e | 2016-09-21 12:24:43 +0200 | [diff] [blame] | 1586 | #else |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 1587 | /* these variables are only used when compression mode is enabled */ |
| 1588 | (void)contentSize; (void)suffix; (void)adapt; (void)rsyncable; |
| 1589 | (void)ultra; (void)cLevel; (void)ldmFlag; (void)literalCompressionMode; |
| 1590 | (void)targetCBlockSize; (void)streamSrcSize; (void)srcSizeHint; |
| 1591 | (void)ZSTD_strategyMap; (void)useRowMatchFinder; (void)cType; |
| 1592 | DISPLAYLEVEL(1, "Compression not supported \n"); |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 1593 | #endif |
Yann Collet | 22de81e | 2016-10-28 13:58:31 -0700 | [diff] [blame] | 1594 | } else { /* decompression or test */ |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 1595 | #ifndef ZSTD_NODECOMPRESS |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 1596 | if (filenames->tableSize == 1 && outFileName) { |
senhuang42 | 5123496 | 2020-09-07 13:13:05 -0400 | [diff] [blame] | 1597 | operationResult = FIO_decompressFilename(fCtx, prefs, outFileName, filenames->fileNames[0], dictFileName); |
Yann Collet | 1ead0c5 | 2019-10-25 16:36:59 -0700 | [diff] [blame] | 1598 | } else { |
senhuang42 | 5123496 | 2020-09-07 13:13:05 -0400 | [diff] [blame] | 1599 | operationResult = FIO_decompressMultipleFilenames(fCtx, prefs, filenames->fileNames, outMirroredDirName, outDirName, outFileName, dictFileName); |
Yann Collet | 1ead0c5 | 2019-10-25 16:36:59 -0700 | [diff] [blame] | 1600 | } |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 1601 | #else |
Elliott Hughes | 44aba64 | 2023-09-12 20:18:59 +0000 | [diff] [blame] | 1602 | DISPLAYLEVEL(1, "Decompression not supported \n"); |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 1603 | #endif |
| 1604 | } |
| 1605 | |
| 1606 | _end: |
Karl Ostmo | 5e220bf | 2019-01-22 17:31:13 -0800 | [diff] [blame] | 1607 | FIO_freePreferences(prefs); |
senhuang42 | 48bca10 | 2020-09-03 10:14:04 -0400 | [diff] [blame] | 1608 | FIO_freeContext(fCtx); |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 1609 | if (main_pause) waitEnter(); |
Yann Collet | b09f593 | 2019-11-05 17:02:43 -0800 | [diff] [blame] | 1610 | UTIL_freeFileNamesTable(filenames); |
| 1611 | UTIL_freeFileNamesTable(file_of_names); |
Nick Terrell | 54a4998 | 2021-02-03 19:53:00 -0800 | [diff] [blame] | 1612 | #ifndef ZSTD_NOTRACE |
| 1613 | TRACE_finish(); |
| 1614 | #endif |
Yann Collet | b40eace | 2019-10-25 18:16:45 -0700 | [diff] [blame] | 1615 | |
Yann Collet | fcf2087 | 2016-05-29 05:16:05 +0200 | [diff] [blame] | 1616 | return operationResult; |
| 1617 | } |