2015-01-24 00:58:16 +00:00
|
|
|
/*
|
|
|
|
zstdcli - Command Line Interface (cli) for zstd
|
2016-02-11 03:17:50 +00:00
|
|
|
Copyright (C) Yann Collet 2014-2016
|
2015-01-24 00:58:16 +00:00
|
|
|
|
|
|
|
GPL v2 License
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along
|
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
|
|
|
You can contact the author at :
|
2016-02-11 03:17:50 +00:00
|
|
|
- zstd homepage : http://www.zstd.net/
|
2015-01-24 00:58:16 +00:00
|
|
|
*/
|
|
|
|
/*
|
2016-02-12 01:31:57 +00:00
|
|
|
Note : this is user program, not part of libzstd.
|
|
|
|
The license of this command line program is GPLv2.
|
|
|
|
The license of libzstd is BSD.
|
2015-01-24 00:58:16 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2016-02-11 03:17:50 +00:00
|
|
|
/*-************************************
|
2015-01-24 00:58:16 +00:00
|
|
|
* Compiler Options
|
|
|
|
**************************************/
|
|
|
|
#define _CRT_SECURE_NO_WARNINGS /* Visual : removes warning from strcpy */
|
|
|
|
#define _POSIX_SOURCE 1 /* triggers fileno() within <stdio.h> on unix */
|
|
|
|
|
|
|
|
|
2016-02-11 03:17:50 +00:00
|
|
|
/*-************************************
|
2015-01-24 00:58:16 +00:00
|
|
|
* Includes
|
|
|
|
**************************************/
|
|
|
|
#include <stdio.h> /* fprintf, getchar */
|
|
|
|
#include <stdlib.h> /* exit, calloc, free */
|
|
|
|
#include <string.h> /* strcmp, strlen */
|
|
|
|
#include "fileio.h"
|
2015-12-15 10:25:12 +00:00
|
|
|
#ifndef ZSTD_NOBENCH
|
|
|
|
# include "bench.h" /* BMK_benchFiles, BMK_SetNbIterations */
|
|
|
|
#endif
|
2016-02-12 01:31:57 +00:00
|
|
|
#include "zstd_static.h" /* ZSTD_maxCLevel, ZSTD version numbers */
|
|
|
|
#ifndef ZSTD_NODICT
|
|
|
|
# include "dibio.h" /* BMK_benchFiles, BMK_SetNbIterations */
|
|
|
|
#endif
|
2015-01-24 00:58:16 +00:00
|
|
|
|
|
|
|
|
2016-02-11 03:17:50 +00:00
|
|
|
/*-************************************
|
2015-01-24 00:58:16 +00:00
|
|
|
* OS-specific Includes
|
|
|
|
**************************************/
|
|
|
|
#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__)
|
2015-12-15 10:25:12 +00:00
|
|
|
# include <fcntl.h> /* _O_BINARY */
|
|
|
|
# include <io.h> /* _setmode, _isatty */
|
2015-01-24 00:58:16 +00:00
|
|
|
# define SET_BINARY_MODE(file) _setmode(_fileno(file), _O_BINARY)
|
|
|
|
# define IS_CONSOLE(stdStream) _isatty(_fileno(stdStream))
|
|
|
|
#else
|
2015-12-15 10:25:12 +00:00
|
|
|
# include <unistd.h> /* isatty */
|
2015-01-24 00:58:16 +00:00
|
|
|
# define SET_BINARY_MODE(file)
|
|
|
|
# define IS_CONSOLE(stdStream) isatty(fileno(stdStream))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2016-02-11 03:17:50 +00:00
|
|
|
/*-************************************
|
2015-01-25 14:50:24 +00:00
|
|
|
* Constants
|
|
|
|
**************************************/
|
2015-01-24 00:58:16 +00:00
|
|
|
#define COMPRESSOR_NAME "zstd command line interface"
|
|
|
|
#ifndef ZSTD_VERSION
|
2015-12-17 19:30:14 +00:00
|
|
|
# define QUOTE(str) #str
|
|
|
|
# define EXPAND_AND_QUOTE(str) QUOTE(str)
|
|
|
|
# define ZSTD_VERSION "v" EXPAND_AND_QUOTE(ZSTD_VERSION_MAJOR) "." EXPAND_AND_QUOTE(ZSTD_VERSION_MINOR) "." EXPAND_AND_QUOTE(ZSTD_VERSION_RELEASE)
|
2015-01-24 00:58:16 +00:00
|
|
|
#endif
|
|
|
|
#define AUTHOR "Yann Collet"
|
2016-02-08 00:27:59 +00:00
|
|
|
#define WELCOME_MESSAGE "*** %s %i-bits %s, by %s ***\n", COMPRESSOR_NAME, (int)(sizeof(void*)*8), ZSTD_VERSION, AUTHOR
|
2016-02-12 01:31:57 +00:00
|
|
|
|
2015-01-24 00:58:16 +00:00
|
|
|
#define ZSTD_EXTENSION ".zst"
|
|
|
|
#define ZSTD_CAT "zstdcat"
|
2015-03-24 19:15:56 +00:00
|
|
|
#define ZSTD_UNZSTD "unzstd"
|
2015-01-24 00:58:16 +00:00
|
|
|
|
|
|
|
#define KB *(1 <<10)
|
|
|
|
#define MB *(1 <<20)
|
|
|
|
#define GB *(1U<<30)
|
|
|
|
|
2016-02-12 01:31:57 +00:00
|
|
|
static const char* g_defaultDictName = "dictionary";
|
|
|
|
static const unsigned g_defaultMaxDictSize = 110 KB;
|
|
|
|
static const unsigned g_defaultDictCLevel = 5;
|
|
|
|
static const unsigned g_defaultSelectivityLevel = 9;
|
|
|
|
|
2015-01-24 00:58:16 +00:00
|
|
|
|
2016-02-11 03:17:50 +00:00
|
|
|
/*-************************************
|
2015-01-24 00:58:16 +00:00
|
|
|
* Display Macros
|
|
|
|
**************************************/
|
2015-08-25 22:32:45 +00:00
|
|
|
#define DISPLAY(...) fprintf(displayOut, __VA_ARGS__)
|
2015-01-24 00:58:16 +00:00
|
|
|
#define DISPLAYLEVEL(l, ...) if (displayLevel>=l) { DISPLAY(__VA_ARGS__); }
|
2015-08-25 22:32:45 +00:00
|
|
|
static FILE* displayOut;
|
2016-02-11 03:17:50 +00:00
|
|
|
static unsigned displayLevel = 2; /* 0 : no display, 1: errors, 2 : + result + interaction + warnings, 3 : + progression, 4 : + information */
|
2015-01-24 00:58:16 +00:00
|
|
|
|
|
|
|
|
2016-02-11 03:17:50 +00:00
|
|
|
/*-************************************
|
2015-01-24 00:58:16 +00:00
|
|
|
* Command Line
|
|
|
|
**************************************/
|
|
|
|
static int usage(const char* programName)
|
|
|
|
{
|
|
|
|
DISPLAY( "Usage :\n");
|
2016-02-12 01:31:57 +00:00
|
|
|
DISPLAY( " %s [args] [FILE(s)] [-o file]\n", programName);
|
2015-01-24 00:58:16 +00:00
|
|
|
DISPLAY( "\n");
|
2016-02-12 01:31:57 +00:00
|
|
|
DISPLAY( "FILE : a filename\n");
|
2015-01-24 00:58:16 +00:00
|
|
|
DISPLAY( " with no FILE, or when FILE is - , read standard input\n");
|
|
|
|
DISPLAY( "Arguments :\n");
|
2016-02-12 01:31:57 +00:00
|
|
|
DISPLAY( " -# : # compression level (1-%u, default:1) \n", ZSTD_maxCLevel());
|
2016-02-05 14:24:57 +00:00
|
|
|
DISPLAY( " -d : decompression \n");
|
|
|
|
DISPLAY( " -D file: use `file` as Dictionary \n");
|
2016-02-15 18:33:16 +00:00
|
|
|
DISPLAY( " -o file: result stored into `file` (only if 1 input file) \n");
|
2015-01-24 00:58:16 +00:00
|
|
|
DISPLAY( " -f : overwrite output without prompting \n");
|
|
|
|
DISPLAY( " -h/-H : display help/long help and exit\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int usage_advanced(const char* programName)
|
|
|
|
{
|
|
|
|
DISPLAY(WELCOME_MESSAGE);
|
|
|
|
usage(programName);
|
|
|
|
DISPLAY( "\n");
|
|
|
|
DISPLAY( "Advanced arguments :\n");
|
|
|
|
DISPLAY( " -V : display Version number and exit\n");
|
2016-02-15 18:33:16 +00:00
|
|
|
DISPLAY( " -t : test compressed file integrity \n");
|
2015-01-24 00:58:16 +00:00
|
|
|
DISPLAY( " -v : verbose mode\n");
|
|
|
|
DISPLAY( " -q : suppress warnings; specify twice to suppress errors too\n");
|
|
|
|
DISPLAY( " -c : force write to standard output, even if it is the console\n");
|
2016-03-10 20:02:25 +00:00
|
|
|
DISPLAY( "--ultra : enable ultra modes (requires more memory to decompress)\n");
|
2016-02-12 01:31:57 +00:00
|
|
|
#ifndef ZSTD_NODICT
|
|
|
|
DISPLAY( "Dictionary builder :\n");
|
2016-02-12 19:19:48 +00:00
|
|
|
DISPLAY( "--train : create a dictionary from a training set of files \n");
|
2016-02-12 01:31:57 +00:00
|
|
|
DISPLAY( " -o file: `file` is dictionary name (default: %s) \n", g_defaultDictName);
|
|
|
|
DISPLAY( "--maxdict:limit dictionary to specified size (default : %u) \n", g_defaultMaxDictSize);
|
|
|
|
DISPLAY( " -s# : dictionary selectivity level (default: %u)\n", g_defaultSelectivityLevel);
|
|
|
|
#endif
|
2015-12-03 11:11:30 +00:00
|
|
|
#ifndef ZSTD_NOBENCH
|
2015-01-24 00:58:16 +00:00
|
|
|
DISPLAY( "Benchmark arguments :\n");
|
2015-10-29 18:10:54 +00:00
|
|
|
DISPLAY( " -b# : benchmark file(s), using # compression level (default : 1) \n");
|
2015-08-25 22:32:45 +00:00
|
|
|
DISPLAY( " -i# : iteration loops [1-9](default : 3)\n");
|
2016-02-16 13:42:08 +00:00
|
|
|
DISPLAY( " -B# : cut file into independent blocks of size # (default: no block)\n");
|
2016-02-12 01:31:57 +00:00
|
|
|
DISPLAY( " -r# : test all compression levels from 1 to # (default: disabled)\n");
|
2015-12-03 11:11:30 +00:00
|
|
|
#endif
|
2015-01-24 00:58:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int badusage(const char* programName)
|
|
|
|
{
|
|
|
|
DISPLAYLEVEL(1, "Incorrect parameters\n");
|
|
|
|
if (displayLevel >= 1) usage(programName);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void waitEnter(void)
|
|
|
|
{
|
2015-07-05 07:20:56 +00:00
|
|
|
int unused;
|
2015-01-24 00:58:16 +00:00
|
|
|
DISPLAY("Press enter to continue...\n");
|
2015-07-05 07:20:56 +00:00
|
|
|
unused = getchar();
|
|
|
|
(void)unused;
|
2015-01-24 00:58:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-03-21 23:22:50 +00:00
|
|
|
#define CLEAN_RETURN(i) { operationResult = (i); goto _end; }
|
|
|
|
|
2015-11-11 13:39:50 +00:00
|
|
|
int main(int argCount, const char** argv)
|
2015-01-24 00:58:16 +00:00
|
|
|
{
|
|
|
|
int i,
|
|
|
|
bench=0,
|
|
|
|
decode=0,
|
|
|
|
forceStdout=0,
|
2015-12-13 12:35:21 +00:00
|
|
|
main_pause=0,
|
2015-12-17 01:23:58 +00:00
|
|
|
nextEntryIsDictionary=0,
|
2016-02-12 01:31:57 +00:00
|
|
|
operationResult=0,
|
|
|
|
dictBuild=0,
|
|
|
|
nextArgumentIsOutFileName=0,
|
|
|
|
nextArgumentIsMaxDict=0;
|
2015-10-29 21:02:40 +00:00
|
|
|
unsigned cLevel = 1;
|
2015-12-18 02:19:27 +00:00
|
|
|
const char** filenameTable = (const char**)malloc(argCount * sizeof(const char*)); /* argCount >= 1 */
|
2015-12-18 01:14:46 +00:00
|
|
|
unsigned filenameIdx = 0;
|
2015-01-24 00:58:16 +00:00
|
|
|
const char* programName = argv[0];
|
|
|
|
const char* outFileName = NULL;
|
2015-12-13 12:35:21 +00:00
|
|
|
const char* dictFileName = NULL;
|
2015-01-24 00:58:16 +00:00
|
|
|
char* dynNameSpace = NULL;
|
2015-12-03 11:11:30 +00:00
|
|
|
int rangeBench = 1;
|
2016-02-12 01:31:57 +00:00
|
|
|
unsigned maxDictSize = g_defaultMaxDictSize;
|
|
|
|
unsigned dictCLevel = g_defaultDictCLevel;
|
|
|
|
unsigned dictSelect = g_defaultSelectivityLevel;
|
2015-01-24 00:58:16 +00:00
|
|
|
|
2015-12-03 11:11:30 +00:00
|
|
|
/* init */
|
2016-02-12 01:31:57 +00:00
|
|
|
(void)rangeBench; (void)dictCLevel; /* not used when ZSTD_NOBENCH / ZSTD_NODICT set */
|
2015-12-18 01:14:46 +00:00
|
|
|
if (filenameTable==NULL) { DISPLAY("not enough memory\n"); exit(1); }
|
2015-08-25 22:32:45 +00:00
|
|
|
displayOut = stderr;
|
2015-12-18 01:14:46 +00:00
|
|
|
/* Pick out program name from path. Don't rely on stdlib because of conflicting behavior */
|
2015-12-01 00:31:17 +00:00
|
|
|
for (i = (int)strlen(programName); i > 0; i--) { if (programName[i] == '/') { i++; break; } }
|
2015-03-24 19:15:56 +00:00
|
|
|
programName += i;
|
|
|
|
|
2015-12-01 00:31:17 +00:00
|
|
|
/* preset behaviors */
|
|
|
|
if (!strcmp(programName, ZSTD_UNZSTD)) decode=1;
|
2015-01-24 00:58:16 +00:00
|
|
|
if (!strcmp(programName, ZSTD_CAT)) { decode=1; forceStdout=1; displayLevel=1; outFileName=stdoutmark; }
|
|
|
|
|
2015-08-25 22:32:45 +00:00
|
|
|
/* command switches */
|
2016-02-11 03:17:50 +00:00
|
|
|
for(i=1; i<argCount; i++) {
|
2015-11-11 13:39:50 +00:00
|
|
|
const char* argument = argv[i];
|
2015-08-25 22:32:45 +00:00
|
|
|
if(!argument) continue; /* Protection if argument empty */
|
|
|
|
|
|
|
|
/* long commands (--long-word) */
|
2016-02-16 13:42:08 +00:00
|
|
|
if (!strcmp(argument, "--decompress")) { decode=1; continue; }
|
|
|
|
if (!strcmp(argument, "--force")) { FIO_overwriteMode(); continue; }
|
2016-03-21 23:22:50 +00:00
|
|
|
if (!strcmp(argument, "--version")) { displayOut=stdout; DISPLAY(WELCOME_MESSAGE); CLEAN_RETURN(0); }
|
|
|
|
if (!strcmp(argument, "--help")) { displayOut=stdout; CLEAN_RETURN(usage_advanced(programName)); }
|
2015-08-26 09:32:17 +00:00
|
|
|
if (!strcmp(argument, "--verbose")) { displayLevel=4; continue; }
|
2015-12-17 19:30:14 +00:00
|
|
|
if (!strcmp(argument, "--quiet")) { displayLevel--; continue; }
|
2016-02-16 13:42:08 +00:00
|
|
|
if (!strcmp(argument, "--stdout")) { forceStdout=1; outFileName=stdoutmark; displayLevel=1; continue; }
|
|
|
|
if (!strcmp(argument, "--test")) { decode=1; outFileName=nulmark; FIO_overwriteMode(); continue; }
|
2016-02-12 01:31:57 +00:00
|
|
|
if (!strcmp(argument, "--train")) { dictBuild=1; outFileName=g_defaultDictName; continue; }
|
|
|
|
if (!strcmp(argument, "--maxdict")) { nextArgumentIsMaxDict=1; continue; }
|
2016-02-16 13:42:08 +00:00
|
|
|
if (!strcmp(argument, "--keep")) { continue; } /* does nothing, since preserving input is default; for gzip/xz compatibility */
|
2016-03-10 20:02:25 +00:00
|
|
|
if (!strcmp(argument, "--ultra")) { FIO_setMaxWLog(0); continue; }
|
2016-02-12 01:31:57 +00:00
|
|
|
|
|
|
|
/* '-' means stdin/stdout */
|
|
|
|
if (!strcmp(argument, "-")){
|
|
|
|
if (!filenameIdx) { filenameIdx=1, filenameTable[0]=stdinmark; continue; }
|
|
|
|
outFileName=stdoutmark; continue;
|
|
|
|
}
|
2015-01-24 00:58:16 +00:00
|
|
|
|
|
|
|
/* Decode commands (note : aggregated commands are allowed) */
|
2016-02-11 03:17:50 +00:00
|
|
|
if (argument[0]=='-') {
|
2015-01-24 00:58:16 +00:00
|
|
|
argument++;
|
|
|
|
|
2016-02-12 01:31:57 +00:00
|
|
|
while (argument[0]!=0) {
|
|
|
|
|
2015-10-22 14:31:46 +00:00
|
|
|
/* compression Level */
|
2016-02-12 01:31:57 +00:00
|
|
|
if ((*argument>='0') && (*argument<='9')) {
|
2015-10-22 14:31:46 +00:00
|
|
|
cLevel = 0;
|
2016-02-12 01:31:57 +00:00
|
|
|
while ((*argument >= '0') && (*argument <= '9')) {
|
2015-10-22 14:31:46 +00:00
|
|
|
cLevel *= 10;
|
|
|
|
cLevel += *argument - '0';
|
|
|
|
argument++;
|
|
|
|
}
|
2016-02-12 01:31:57 +00:00
|
|
|
dictCLevel = cLevel;
|
2016-02-16 15:33:48 +00:00
|
|
|
if (dictCLevel > ZSTD_maxCLevel())
|
2016-03-21 23:22:50 +00:00
|
|
|
CLEAN_RETURN(badusage(programName));
|
2015-10-22 14:31:46 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-01-24 00:58:16 +00:00
|
|
|
switch(argument[0])
|
|
|
|
{
|
|
|
|
/* Display help */
|
2016-03-21 23:22:50 +00:00
|
|
|
case 'V': displayOut=stdout; DISPLAY(WELCOME_MESSAGE); CLEAN_RETURN(0); /* Version Only */
|
2015-01-24 00:58:16 +00:00
|
|
|
case 'H':
|
2016-03-21 23:22:50 +00:00
|
|
|
case 'h': displayOut=stdout; CLEAN_RETURN(usage_advanced(programName));
|
2015-01-24 00:58:16 +00:00
|
|
|
|
2016-02-11 03:17:50 +00:00
|
|
|
/* Decoding */
|
2015-01-24 00:58:16 +00:00
|
|
|
case 'd': decode=1; argument++; break;
|
|
|
|
|
2015-10-21 07:22:25 +00:00
|
|
|
/* Force stdout, even if stdout==console */
|
2015-01-24 00:58:16 +00:00
|
|
|
case 'c': forceStdout=1; outFileName=stdoutmark; displayLevel=1; argument++; break;
|
|
|
|
|
2015-12-13 12:35:21 +00:00
|
|
|
/* Use file content as dictionary */
|
|
|
|
case 'D': nextEntryIsDictionary = 1; argument++; break;
|
|
|
|
|
2015-01-24 00:58:16 +00:00
|
|
|
/* Overwrite */
|
|
|
|
case 'f': FIO_overwriteMode(); argument++; break;
|
|
|
|
|
|
|
|
/* Verbose mode */
|
|
|
|
case 'v': displayLevel=4; argument++; break;
|
|
|
|
|
|
|
|
/* Quiet mode */
|
|
|
|
case 'q': displayLevel--; argument++; break;
|
|
|
|
|
2015-12-13 12:35:21 +00:00
|
|
|
/* keep source file (default anyway, so useless; for gzip/xz compatibility) */
|
2015-01-24 00:58:16 +00:00
|
|
|
case 'k': argument++; break;
|
|
|
|
|
2016-02-15 18:33:16 +00:00
|
|
|
/* test compressed file */
|
|
|
|
case 't': decode=1; outFileName=nulmark; FIO_overwriteMode(); argument++; break;
|
|
|
|
|
2016-02-12 01:31:57 +00:00
|
|
|
/* dictionary name */
|
|
|
|
case 'o': nextArgumentIsOutFileName=1; argument++; break;
|
|
|
|
|
2015-12-03 11:11:30 +00:00
|
|
|
#ifndef ZSTD_NOBENCH
|
2015-01-24 00:58:16 +00:00
|
|
|
/* Benchmark */
|
|
|
|
case 'b': bench=1; argument++; break;
|
|
|
|
|
|
|
|
/* Modify Nb Iterations (benchmark only) */
|
|
|
|
case 'i':
|
2016-03-21 23:22:50 +00:00
|
|
|
{ U32 iters= 0;
|
2015-01-24 00:58:16 +00:00
|
|
|
argument++;
|
|
|
|
while ((*argument >='0') && (*argument <='9'))
|
|
|
|
iters *= 10, iters += *argument++ - '0';
|
|
|
|
BMK_SetNbIterations(iters);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2015-10-21 07:22:25 +00:00
|
|
|
/* cut input into blocks (benchmark only) */
|
|
|
|
case 'B':
|
2016-03-21 23:22:50 +00:00
|
|
|
{ size_t bSize = 0;
|
2015-10-21 07:22:25 +00:00
|
|
|
argument++;
|
|
|
|
while ((*argument >='0') && (*argument <='9'))
|
|
|
|
bSize *= 10, bSize += *argument++ - '0';
|
|
|
|
if (*argument=='K') bSize<<=10, argument++; /* allows using KB notation */
|
|
|
|
if (*argument=='M') bSize<<=20, argument++;
|
|
|
|
if (*argument=='B') argument++;
|
|
|
|
BMK_SetBlockSize(bSize);
|
|
|
|
}
|
|
|
|
break;
|
2015-10-29 18:10:54 +00:00
|
|
|
|
|
|
|
/* range bench (benchmark only) */
|
|
|
|
case 'r':
|
|
|
|
rangeBench = -1;
|
|
|
|
argument++;
|
|
|
|
break;
|
2015-12-03 11:11:30 +00:00
|
|
|
#endif /* ZSTD_NOBENCH */
|
2015-10-29 18:10:54 +00:00
|
|
|
|
2016-02-12 01:31:57 +00:00
|
|
|
/* Selection level */
|
|
|
|
case 's': argument++;
|
|
|
|
dictSelect = 0;
|
|
|
|
while ((*argument >= '0') && (*argument <= '9'))
|
|
|
|
dictSelect *= 10, dictSelect += *argument++ - '0';
|
|
|
|
break;
|
|
|
|
|
2015-10-29 18:10:54 +00:00
|
|
|
/* Pause at the end (hidden option) */
|
2015-01-24 00:58:16 +00:00
|
|
|
case 'p': main_pause=1; argument++; break;
|
|
|
|
|
|
|
|
/* unknown command */
|
2016-03-21 23:22:50 +00:00
|
|
|
default : CLEAN_RETURN(badusage(programName));
|
2015-01-24 00:58:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
continue;
|
2016-03-21 23:22:50 +00:00
|
|
|
} /* if (argument[0]=='-') */
|
2015-01-24 00:58:16 +00:00
|
|
|
|
2016-02-11 03:17:50 +00:00
|
|
|
if (nextEntryIsDictionary) {
|
2015-12-13 12:35:21 +00:00
|
|
|
nextEntryIsDictionary = 0;
|
|
|
|
dictFileName = argument;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-02-12 01:31:57 +00:00
|
|
|
if (nextArgumentIsOutFileName) {
|
|
|
|
nextArgumentIsOutFileName = 0;
|
|
|
|
outFileName = argument;
|
|
|
|
if (!strcmp(outFileName, "-")) outFileName = stdoutmark;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nextArgumentIsMaxDict) {
|
|
|
|
nextArgumentIsMaxDict = 0;
|
|
|
|
maxDictSize = 0;
|
|
|
|
while ((*argument>='0') && (*argument<='9'))
|
|
|
|
maxDictSize = maxDictSize * 10 + (*argument - '0'), argument++;
|
|
|
|
if (*argument=='k' || *argument=='K')
|
|
|
|
maxDictSize <<= 10;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-12-18 01:14:46 +00:00
|
|
|
/* add filename to list */
|
|
|
|
filenameTable[filenameIdx++] = argument;
|
2015-01-24 00:58:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Welcome message (if verbose) */
|
|
|
|
DISPLAYLEVEL(3, WELCOME_MESSAGE);
|
|
|
|
|
2015-12-01 00:31:17 +00:00
|
|
|
/* Check if benchmark is selected */
|
2016-02-11 03:17:50 +00:00
|
|
|
if (bench) {
|
2015-12-03 11:11:30 +00:00
|
|
|
#ifndef ZSTD_NOBENCH
|
2015-12-18 01:14:46 +00:00
|
|
|
BMK_benchFiles(filenameTable, filenameIdx, dictFileName, cLevel*rangeBench);
|
2015-12-03 11:11:30 +00:00
|
|
|
#endif
|
|
|
|
goto _end;
|
|
|
|
}
|
2015-12-01 00:31:17 +00:00
|
|
|
|
2016-02-12 01:31:57 +00:00
|
|
|
/* Check if dictionary builder is selected */
|
|
|
|
if (dictBuild) {
|
|
|
|
#ifndef ZSTD_NODICT
|
|
|
|
ZDICT_params_t dictParams;
|
|
|
|
dictParams.compressionLevel = dictCLevel;
|
|
|
|
dictParams.selectivityLevel = dictSelect;
|
2016-02-12 19:19:48 +00:00
|
|
|
dictParams.notificationLevel = displayLevel;
|
2016-02-12 01:31:57 +00:00
|
|
|
DiB_trainFromFiles(outFileName, maxDictSize, filenameTable, filenameIdx, dictParams);
|
|
|
|
#endif
|
|
|
|
goto _end;
|
|
|
|
}
|
|
|
|
|
2016-02-12 01:56:27 +00:00
|
|
|
/* No input filename ==> use stdin and stdout */
|
|
|
|
if(!filenameIdx) filenameIdx=1, filenameTable[0]=stdinmark, outFileName=stdoutmark;
|
2015-01-24 00:58:16 +00:00
|
|
|
|
2016-02-12 01:31:57 +00:00
|
|
|
/* Check if input/output defined as console; trigger an error in this case */
|
2016-03-21 23:22:50 +00:00
|
|
|
if (!strcmp(filenameTable[0], stdinmark) && IS_CONSOLE(stdin) ) CLEAN_RETURN(badusage(programName));
|
|
|
|
if (outFileName && !strcmp(outFileName, stdoutmark) && IS_CONSOLE(stdout) && !forceStdout) CLEAN_RETURN(badusage(programName));
|
2015-01-24 00:58:16 +00:00
|
|
|
|
2016-02-12 14:56:46 +00:00
|
|
|
/* user-selected output filename, only possible with a single file */
|
2016-02-15 18:33:16 +00:00
|
|
|
if (outFileName && strcmp(outFileName,stdoutmark) && strcmp(outFileName,nulmark) && (filenameIdx>1)) {
|
2016-02-12 01:31:57 +00:00
|
|
|
DISPLAY("Too many files (%u) on the command line. \n", filenameIdx);
|
2016-03-21 23:22:50 +00:00
|
|
|
CLEAN_RETURN(filenameIdx);
|
2015-12-17 19:30:14 +00:00
|
|
|
}
|
|
|
|
|
2016-02-12 14:56:46 +00:00
|
|
|
/* No warning message in pipe mode (stdin + stdout) or multiple mode */
|
2016-03-21 23:22:50 +00:00
|
|
|
if (!strcmp(filenameTable[0], stdinmark) && outFileName && !strcmp(outFileName,stdoutmark) && (displayLevel==2)) displayLevel=1;
|
2016-02-12 14:56:46 +00:00
|
|
|
if ((filenameIdx>1) && (displayLevel==2)) displayLevel=1;
|
|
|
|
|
2015-01-24 00:58:16 +00:00
|
|
|
/* IO Stream/File */
|
|
|
|
FIO_setNotificationLevel(displayLevel);
|
2016-02-11 03:17:50 +00:00
|
|
|
if (decode) {
|
2016-02-13 02:09:48 +00:00
|
|
|
if (filenameIdx==1 && outFileName)
|
2015-12-18 01:14:46 +00:00
|
|
|
operationResult = FIO_decompressFilename(outFileName, filenameTable[0], dictFileName);
|
2016-02-12 01:31:57 +00:00
|
|
|
else
|
2016-02-15 18:33:16 +00:00
|
|
|
operationResult = FIO_decompressMultipleFilenames(filenameTable, filenameIdx, outFileName ? outFileName : ZSTD_EXTENSION, dictFileName);
|
2016-02-11 03:17:50 +00:00
|
|
|
} else { /* compression */
|
2016-02-13 02:09:48 +00:00
|
|
|
if (filenameIdx==1 && outFileName)
|
2015-12-18 01:14:46 +00:00
|
|
|
operationResult = FIO_compressFilename(outFileName, filenameTable[0], dictFileName, cLevel);
|
2016-02-12 01:31:57 +00:00
|
|
|
else
|
2016-02-15 18:33:16 +00:00
|
|
|
operationResult = FIO_compressMultipleFilenames(filenameTable, filenameIdx, outFileName ? outFileName : ZSTD_EXTENSION, dictFileName, cLevel);
|
2015-12-17 01:23:58 +00:00
|
|
|
}
|
2015-01-24 00:58:16 +00:00
|
|
|
|
|
|
|
_end:
|
|
|
|
if (main_pause) waitEnter();
|
|
|
|
free(dynNameSpace);
|
2015-12-18 02:19:27 +00:00
|
|
|
free((void*)filenameTable);
|
2015-12-17 01:23:58 +00:00
|
|
|
return operationResult;
|
2015-01-24 00:58:16 +00:00
|
|
|
}
|