2 * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
5 * This source code is licensed under the BSD-style license found in the
6 * LICENSE file in the root directory of this source tree. An additional grant
7 * of patent rights can be found in the PATENTS file in the same directory.
11 /*-************************************
13 **************************************/
14 #include "util.h" /* Compiler options */
15 #include <stdio.h> /* fprintf, stderr */
16 #include "datagen.h" /* RDG_generate */
19 /*-************************************
21 **************************************/
26 #define SIZE_DEFAULT ((64 KB) + 1)
27 #define SEED_DEFAULT 0
28 #define COMPRESSIBILITY_DEFAULT 50
31 /*-************************************
33 **************************************/
34 #define DISPLAY(...) fprintf(stderr, __VA_ARGS__)
35 #define DISPLAYLEVEL(l, ...) if (displayLevel>=l) { DISPLAY(__VA_ARGS__); }
36 static unsigned displayLevel = 2;
39 /*-*******************************************************
41 *********************************************************/
42 static int usage(const char* programName)
44 DISPLAY( "Compressible data generator\n");
45 DISPLAY( "Usage :\n");
46 DISPLAY( " %s [args]\n", programName);
48 DISPLAY( "Arguments :\n");
49 DISPLAY( " -g# : generate # data (default:%i)\n", SIZE_DEFAULT);
50 DISPLAY( " -s# : Select seed (default:%i)\n", SEED_DEFAULT);
51 DISPLAY( " -P# : Select compressibility in %% (default:%i%%)\n", COMPRESSIBILITY_DEFAULT);
52 DISPLAY( " -h : display help and exit\n");
57 int main(int argc, const char** argv)
59 double proba = (double)COMPRESSIBILITY_DEFAULT / 100;
60 double litProba = 0.0;
61 U64 size = SIZE_DEFAULT;
62 U32 seed = SEED_DEFAULT;
63 const char* const programName = argv[0];
66 for(argNb=1; argNb<argc; argNb++) {
67 const char* argument = argv[argNb];
69 if(!argument) continue; /* Protection if argument empty */
71 /* Handle commands. Aggregated commands are allowed */
74 while (*argument!=0) {
78 return usage(programName);
82 while ((*argument>='0') && (*argument<='9'))
83 size *= 10, size += *argument++ - '0';
84 if (*argument=='K') { size <<= 10; argument++; }
85 if (*argument=='M') { size <<= 20; argument++; }
86 if (*argument=='G') { size <<= 30; argument++; }
87 if (*argument=='B') { argument++; }
92 while ((*argument>='0') && (*argument<='9'))
93 seed *= 10, seed += *argument++ - '0';
98 while ((*argument>='0') && (*argument<='9'))
99 proba *= 10, proba += *argument++ - '0';
100 if (proba>100.) proba=100.;
103 case 'L': /* hidden argument : Literal distribution probability */
106 while ((*argument>='0') && (*argument<='9'))
107 litProba *= 10, litProba += *argument++ - '0';
108 if (litProba>100.) litProba=100.;
116 return usage(programName);
118 } } } /* for(argNb=1; argNb<argc; argNb++) */
120 DISPLAYLEVEL(4, "Data Generator \n");
121 DISPLAYLEVEL(3, "Seed = %u \n", seed);
122 if (proba!=COMPRESSIBILITY_DEFAULT) DISPLAYLEVEL(3, "Compressibility : %i%%\n", (U32)(proba*100));
124 RDG_genStdout(size, proba, litProba, seed);
125 DISPLAYLEVEL(1, "\n");