2 * Copyright (c) Meta Platforms, Inc. and affiliates.
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).
8 * You may select, at your option, one of the above-listed licenses.
11 /*-************************************
13 **************************************/
14 #include <stdio.h> /* fprintf, stderr */
15 #include "datagen.h" /* RDG_generate */
16 #include "loremOut.h" /* LOREM_genOut */
17 #include "util.h" /* Compiler options */
19 /*-************************************
21 **************************************/
24 #define GB *(1U << 30)
26 #define SIZE_DEFAULT ((64 KB) + 1)
27 #define SEED_DEFAULT 0
28 #define COMPRESSIBILITY_DEFAULT 9999
30 /*-************************************
32 **************************************/
33 #define DISPLAY(...) fprintf(stderr, __VA_ARGS__)
34 #define DISPLAYLEVEL(l, ...) \
35 if (displayLevel >= l) { \
36 DISPLAY(__VA_ARGS__); \
38 static unsigned displayLevel = 2;
40 /*-*******************************************************
42 *********************************************************/
43 static int usage(const char* programName)
45 DISPLAY("Compressible data generator\n");
47 DISPLAY(" %s [args]\n", programName);
49 DISPLAY("Arguments :\n");
50 DISPLAY(" -g# : generate # data (default:%i)\n", SIZE_DEFAULT);
51 DISPLAY(" -s# : Select seed (default:%i)\n", SEED_DEFAULT);
52 DISPLAY(" -P# : Select compressibility in %% (range [0-100])\n");
53 DISPLAY(" -h : display help and exit\n");
57 int main(int argc, const char** argv)
59 unsigned probaU32 = COMPRESSIBILITY_DEFAULT;
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];
70 continue; /* Protection if argument empty */
72 /* Handle commands. Aggregated commands are allowed */
73 if (*argument == '-') {
75 while (*argument != 0) {
78 return usage(programName);
82 while ((*argument >= '0') && (*argument <= '9'))
83 size *= 10, size += (U64)(*argument++ - '0');
84 if (*argument == 'K') {
88 if (*argument == 'M') {
92 if (*argument == 'G') {
96 if (*argument == 'B') {
103 while ((*argument >= '0') && (*argument <= '9'))
104 seed *= 10, seed += (U32)(*argument++ - '0');
109 while ((*argument >= '0') && (*argument <= '9'))
111 probaU32 += (U32)(*argument++ - '0');
115 case 'L': /* hidden argument : Literal distribution
119 while ((*argument >= '0') && (*argument <= '9'))
120 litProba *= 10, litProba += *argument++ - '0';
130 return usage(programName);
134 } /* for(argNb=1; argNb<argc; argNb++) */
136 DISPLAYLEVEL(4, "Compressible data Generator \n");
137 DISPLAYLEVEL(3, "Seed = %u \n", (unsigned)seed);
139 if (probaU32 != COMPRESSIBILITY_DEFAULT) {
140 DISPLAYLEVEL(3, "Compressibility : %i%%\n", probaU32);
141 RDG_genStdout(size, (double)probaU32 / 100, litProba, seed);
143 LOREM_genOut(size, seed);
146 DISPLAYLEVEL(3, "\n");