Rizin
unix-like reverse engineering framework and cli tools
datagencli.c File Reference
#include "util.h"
#include <stdio.h>
#include "datagen.h"
#include "lz4.h"

Go to the source code of this file.

Macros

#define KB   *(1 <<10)
 
#define MB   *(1 <<20)
 
#define GB   *(1U<<30)
 
#define SIZE_DEFAULT   (64 KB)
 
#define SEED_DEFAULT   0
 
#define COMPRESSIBILITY_DEFAULT   50
 
#define DISPLAY(...)   fprintf(stderr, __VA_ARGS__)
 
#define DISPLAYLEVEL(l, ...)   if (displayLevel>=l) { DISPLAY(__VA_ARGS__); }
 

Functions

static int usage (char *programName)
 
int main (int argc, char **argv)
 

Variables

static unsigned displayLevel = 2
 

Macro Definition Documentation

◆ COMPRESSIBILITY_DEFAULT

#define COMPRESSIBILITY_DEFAULT   50

Definition at line 45 of file datagencli.c.

◆ DISPLAY

#define DISPLAY (   ...)    fprintf(stderr, __VA_ARGS__)

Definition at line 51 of file datagencli.c.

◆ DISPLAYLEVEL

#define DISPLAYLEVEL (   l,
  ... 
)    if (displayLevel>=l) { DISPLAY(__VA_ARGS__); }

Definition at line 52 of file datagencli.c.

◆ GB

#define GB   *(1U<<30)

Definition at line 41 of file datagencli.c.

◆ KB

#define KB   *(1 <<10)

Definition at line 39 of file datagencli.c.

◆ MB

#define MB   *(1 <<20)

Definition at line 40 of file datagencli.c.

◆ SEED_DEFAULT

#define SEED_DEFAULT   0

Definition at line 44 of file datagencli.c.

◆ SIZE_DEFAULT

#define SIZE_DEFAULT   (64 KB)

Definition at line 43 of file datagencli.c.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 77 of file datagencli.c.

78 {
79  int argNb;
80  double proba = (double)COMPRESSIBILITY_DEFAULT / 100;
81  double litProba = 0.0;
83  U32 seed = SEED_DEFAULT;
84  char* programName;
85 
86  /* Check command line */
87  programName = argv[0];
88  for(argNb=1; argNb<argc; argNb++)
89  {
90  char* argument = argv[argNb];
91 
92  if(!argument) continue; /* Protection if argument empty */
93 
94  /* Handle commands. Aggregated commands are allowed */
95  if (*argument=='-')
96  {
97  argument++;
98  while (*argument!=0)
99  {
100  switch(*argument)
101  {
102  case 'h':
103  return usage(programName);
104  case 'g':
105  argument++;
106  size=0;
107  while ((*argument>='0') && (*argument<='9'))
108  {
109  size *= 10;
110  size += *argument - '0';
111  argument++;
112  }
113  if (*argument=='K') { size <<= 10; argument++; }
114  if (*argument=='M') { size <<= 20; argument++; }
115  if (*argument=='G') { size <<= 30; argument++; }
116  if (*argument=='B') { argument++; }
117  break;
118  case 's':
119  argument++;
120  seed=0;
121  while ((*argument>='0') && (*argument<='9'))
122  {
123  seed *= 10;
124  seed += *argument - '0';
125  argument++;
126  }
127  break;
128  case 'P':
129  argument++;
130  proba=0.0;
131  while ((*argument>='0') && (*argument<='9'))
132  {
133  proba *= 10;
134  proba += *argument - '0';
135  argument++;
136  }
137  if (proba>100.) proba=100.;
138  proba /= 100.;
139  break;
140  case 'L': /* hidden argument : Literal distribution probability */
141  argument++;
142  litProba=0.;
143  while ((*argument>='0') && (*argument<='9'))
144  {
145  litProba *= 10;
146  litProba += *argument - '0';
147  argument++;
148  }
149  if (litProba>100.) litProba=100.;
150  litProba /= 100.;
151  break;
152  case 'v':
153  displayLevel = 4;
154  argument++;
155  break;
156  default:
157  return usage(programName);
158  }
159  }
160 
161  }
162  }
163 
164  DISPLAYLEVEL(4, "Data Generator %s \n", LZ4_VERSION_STRING);
165  DISPLAYLEVEL(3, "Seed = %u \n", seed);
166  if (proba!=COMPRESSIBILITY_DEFAULT) DISPLAYLEVEL(3, "Compressibility : %i%%\n", (U32)(proba*100));
167 
168  RDG_genOut(size, proba, litProba, seed);
169  DISPLAYLEVEL(1, "\n");
170 
171  return 0;
172 }
void RDG_genOut(unsigned long long size, double matchProba, double litProba, unsigned seed)
Definition: datagen.c:165
#define SIZE_DEFAULT
Definition: datagencli.c:43
static unsigned displayLevel
Definition: datagencli.c:53
static int usage(char *programName)
Definition: datagencli.c:59
#define DISPLAYLEVEL(l,...)
Definition: datagencli.c:52
#define COMPRESSIBILITY_DEFAULT
Definition: datagencli.c:45
#define SEED_DEFAULT
Definition: datagencli.c:44
voidpf void uLong size
Definition: ioapi.h:138
static static fork const void static count static fd const char const char static newpath char char argv
Definition: sflib.h:40
unsigned long long U64
Definition: lz4.c:290
unsigned int U32
Definition: lz4.c:288
#define LZ4_VERSION_STRING
Definition: lz4.h:110

References argv, COMPRESSIBILITY_DEFAULT, DISPLAYLEVEL, displayLevel, LZ4_VERSION_STRING, RDG_genOut(), SEED_DEFAULT, SIZE_DEFAULT, and usage().

◆ usage()

static int usage ( char *  programName)
static

Definition at line 59 of file datagencli.c.

60 {
61  DISPLAY( "Compressible data generator\n");
62  DISPLAY( "Usage :\n");
63  DISPLAY( " %s [size] [args]\n", programName);
64  DISPLAY( "\n");
65  DISPLAY( "Arguments :\n");
66  DISPLAY( " -g# : generate # data (default:%i)\n", SIZE_DEFAULT);
67  DISPLAY( " -s# : Select seed (default:%i)\n", SEED_DEFAULT);
68  DISPLAY( " -P# : Select compressibility in %% (default:%i%%)\n", COMPRESSIBILITY_DEFAULT);
69  DISPLAY( " -h : display help and exit\n");
70  DISPLAY( "Special values :\n");
71  DISPLAY( " -P0 : generate incompressible noise\n");
72  DISPLAY( " -P100 : generate sparse files\n");
73  return 0;
74 }
#define DISPLAY(...)
Definition: datagencli.c:51

References COMPRESSIBILITY_DEFAULT, DISPLAY, SEED_DEFAULT, and SIZE_DEFAULT.

Referenced by main().

Variable Documentation

◆ displayLevel

unsigned displayLevel = 2
static

Definition at line 53 of file datagencli.c.

Referenced by main().