datagen generates lorem ipsum by default

This commit is contained in:
Yann Collet
2024-02-20 15:24:25 -08:00
parent 7003c9905e
commit 83598aa106
5 changed files with 177 additions and 92 deletions
+106 -86
View File
@@ -8,122 +8,142 @@
* You may select, at your option, one of the above-listed licenses.
*/
/*-************************************
* Dependencies
**************************************/
#include <stdio.h> /* fprintf, stderr */
#include "datagen.h" /* RDG_generate */
#include "loremOut.h" /* LOREM_genOut */
#include "util.h" /* Compiler options */
/*-************************************
* Dependencies
**************************************/
#include "util.h" /* Compiler options */
#include <stdio.h> /* fprintf, stderr */
#include "datagen.h" /* RDG_generate */
/*-************************************
* Constants
**************************************/
#define KB *(1 <<10)
#define MB *(1 <<20)
#define GB *(1U<<30)
* Constants
**************************************/
#define KB *(1 << 10)
#define MB *(1 << 20)
#define GB *(1U << 30)
#define SIZE_DEFAULT ((64 KB) + 1)
#define SEED_DEFAULT 0
#define COMPRESSIBILITY_DEFAULT 50
#define COMPRESSIBILITY_DEFAULT 9999
/*-************************************
* Macros
**************************************/
#define DISPLAY(...) fprintf(stderr, __VA_ARGS__)
#define DISPLAYLEVEL(l, ...) if (displayLevel>=l) { DISPLAY(__VA_ARGS__); }
* Macros
**************************************/
#define DISPLAY(...) fprintf(stderr, __VA_ARGS__)
#define DISPLAYLEVEL(l, ...) \
if (displayLevel >= l) { \
DISPLAY(__VA_ARGS__); \
}
static unsigned displayLevel = 2;
/*-*******************************************************
* Command line
*********************************************************/
* Command line
*********************************************************/
static int usage(const char* programName)
{
DISPLAY( "Compressible data generator\n");
DISPLAY( "Usage :\n");
DISPLAY( " %s [args]\n", programName);
DISPLAY( "\n");
DISPLAY( "Arguments :\n");
DISPLAY( " -g# : generate # data (default:%i)\n", SIZE_DEFAULT);
DISPLAY( " -s# : Select seed (default:%i)\n", SEED_DEFAULT);
DISPLAY( " -P# : Select compressibility in %% (default:%i%%)\n",
COMPRESSIBILITY_DEFAULT);
DISPLAY( " -h : display help and exit\n");
DISPLAY("Compressible data generator\n");
DISPLAY("Usage :\n");
DISPLAY(" %s [args]\n", programName);
DISPLAY("\n");
DISPLAY("Arguments :\n");
DISPLAY(" -g# : generate # data (default:%i)\n", SIZE_DEFAULT);
DISPLAY(" -s# : Select seed (default:%i)\n", SEED_DEFAULT);
DISPLAY(" -P# : Select compressibility in %% (range [0-100])\n");
DISPLAY(" -h : display help and exit\n");
return 0;
}
int main(int argc, const char** argv)
{
unsigned probaU32 = COMPRESSIBILITY_DEFAULT;
double litProba = 0.0;
U64 size = SIZE_DEFAULT;
U32 seed = SEED_DEFAULT;
unsigned probaU32 = COMPRESSIBILITY_DEFAULT;
double litProba = 0.0;
U64 size = SIZE_DEFAULT;
U32 seed = SEED_DEFAULT;
const char* const programName = argv[0];
int argNb;
for(argNb=1; argNb<argc; argNb++) {
for (argNb = 1; argNb < argc; argNb++) {
const char* argument = argv[argNb];
if(!argument) continue; /* Protection if argument empty */
if (!argument)
continue; /* Protection if argument empty */
/* Handle commands. Aggregated commands are allowed */
if (*argument=='-') {
if (*argument == '-') {
argument++;
while (*argument!=0) {
switch(*argument)
{
case 'h':
return usage(programName);
case 'g':
argument++;
size=0;
while ((*argument>='0') && (*argument<='9'))
size *= 10, size += *argument++ - '0';
if (*argument=='K') { size <<= 10; argument++; }
if (*argument=='M') { size <<= 20; argument++; }
if (*argument=='G') { size <<= 30; argument++; }
if (*argument=='B') { argument++; }
break;
case 's':
argument++;
seed=0;
while ((*argument>='0') && (*argument<='9'))
seed *= 10, seed += *argument++ - '0';
break;
case 'P':
argument++;
probaU32 = 0;
while ((*argument>='0') && (*argument<='9'))
probaU32 *= 10, probaU32 += *argument++ - '0';
if (probaU32>100) probaU32 = 100;
break;
case 'L': /* hidden argument : Literal distribution probability */
argument++;
litProba=0.;
while ((*argument>='0') && (*argument<='9'))
litProba *= 10, litProba += *argument++ - '0';
if (litProba>100.) litProba=100.;
litProba /= 100.;
break;
case 'v':
displayLevel = 4;
argument++;
break;
default:
return usage(programName);
while (*argument != 0) {
switch (*argument) {
case 'h':
return usage(programName);
case 'g':
argument++;
size = 0;
while ((*argument >= '0') && (*argument <= '9'))
size *= 10, size += (U64)(*argument++ - '0');
if (*argument == 'K') {
size <<= 10;
argument++;
}
if (*argument == 'M') {
size <<= 20;
argument++;
}
if (*argument == 'G') {
size <<= 30;
argument++;
}
if (*argument == 'B') {
argument++;
}
break;
case 's':
argument++;
seed = 0;
while ((*argument >= '0') && (*argument <= '9'))
seed *= 10, seed += (U32)(*argument++ - '0');
break;
case 'P':
argument++;
probaU32 = 0;
while ((*argument >= '0') && (*argument <= '9'))
probaU32 *= 10,
probaU32 += (U32)(*argument++ - '0');
if (probaU32 > 100)
probaU32 = 100;
break;
case 'L': /* hidden argument : Literal distribution
probability */
argument++;
litProba = 0.;
while ((*argument >= '0') && (*argument <= '9'))
litProba *= 10, litProba += *argument++ - '0';
if (litProba > 100.)
litProba = 100.;
litProba /= 100.;
break;
case 'v':
displayLevel = 4;
argument++;
break;
default:
return usage(programName);
}
} } } /* for(argNb=1; argNb<argc; argNb++) */
}
}
} /* for(argNb=1; argNb<argc; argNb++) */
DISPLAYLEVEL(4, "Compressible data Generator \n");
if (probaU32!=COMPRESSIBILITY_DEFAULT)
DISPLAYLEVEL(3, "Compressibility : %i%%\n", probaU32);
DISPLAYLEVEL(3, "Seed = %u \n", (unsigned)seed);
RDG_genStdout(size, (double)probaU32/100, litProba, seed);
if (probaU32 != COMPRESSIBILITY_DEFAULT) {
DISPLAYLEVEL(3, "Compressibility : %i%%\n", probaU32);
RDG_genStdout(size, (double)probaU32 / 100, litProba, seed);
} else {
LOREM_genOut(size, seed);
}
RDG_genStdout(size, (double)probaU32 / 100, litProba, seed);
DISPLAYLEVEL(3, "\n");
return 0;