@@ -16,18 +16,35 @@ const char * getVersionString()
1616 return BINCPP_VERSION;
1717}
1818
19- void usage ()
19+ void printVersion ()
2020{
21- printf (" Usage:\n " );
22- printf (" --file: Path of the generated file\n " );
23- printf (" --size: Size of generated file in bytes. Defaults to 1024\n " );
24- printf (" --seed: Define a seed value to initialze the random number generator. Defaults to local time\n " );
25- printf (" --skip: Define the number of random number to skip before dumping to the file. Defaults to 0\n " );
26- printf (" --fill: Name of the filling strategy. Must be one of the following:\n " );
27- printf (" sequential : Insert values from 0x00 to 0xFF into the file. Default option.\n " );
28- printf (" random : Insert random data into the file\n " );
29- printf (" text : Insert text data into the file.\n " );
30- printf (" html : Insert html data into the file.\n " );
21+ printf (" testfilegenerator v%s\n " , bin2cpp::getVersionString () );
22+ }
23+
24+ void printUsage ()
25+ {
26+ // usage string in docopt format. See http://docopt.org/
27+ static const char usage[] =
28+ " Usage:\n "
29+ " testfilegenerator --file=<path> [--size=<value>] [--quiet] [--fill=<name>] [--seed=<value>] [--skip=<value>]\n "
30+ " testfilegenerator --help\n "
31+ " testfilegenerator --version\n "
32+ " \n "
33+ " Options:\n "
34+ " --help Display this help message.\n "
35+ " --version Display this application version.\n "
36+ " --file=<path> Path of the generated file.\n "
37+ " --size=<value> Size of generated file in bytes. [default: 1024]\n "
38+ " --fill=<name> Name of the filling strategy. Must be one of the following:\n "
39+ " sequential : Insert values from 0x00 to 0xFF into the file. Default option.\n "
40+ " random : Insert random data into the file. See 'seed' and 'skip' options.\n "
41+ " text : Insert text data into the file.\n "
42+ " html : Insert html data into the file.\n "
43+ " --seed=<value> Define a seed value to initialze the random number generator. Defaults to local time.\n "
44+ " --skip=<value> Define the number of random number to skip before dumping to the file. [default: 0]\n "
45+ " --quiet Do not log any message to standard output.\n "
46+ " \n " ;
47+ printf (" %s" , usage);
3148}
3249
3350enum RETURN_CODE
@@ -42,22 +59,45 @@ enum RETURN_CODE
4259
4360int main (int argc, char **argv)
4461{
45- bin2cpp::log (bin2cpp::LOG_INFO, " Test file generator v%s" , getVersionString ());
46-
4762 // parse arguments
4863 std::string file;
4964 int size = 1024 ; // in bytes
5065 unsigned int seed = (unsigned int )time (NULL ); // warning C4244: 'initializing' : conversion from 'time_t' to 'unsigned int', possible loss of data
5166 unsigned int skip = 0 ;
5267 std::string fill = " sequential" ;
5368
69+ // help
70+ std::string tmp;
71+ if (bin2cpp::parseArgument (" help" , tmp, argc, argv))
72+ {
73+ printVersion ();
74+ printUsage ();
75+ return EXIT_NO_ERROR;
76+ }
77+
78+ // version
79+ if (bin2cpp::parseArgument (" version" , tmp, argc, argv))
80+ {
81+ printVersion ();
82+ return EXIT_NO_ERROR;
83+ }
84+
85+ // quiet
86+ std::string tmpQuiet;
87+ if (bin2cpp::parseArgument (" quiet" , tmpQuiet, argc, argv))
88+ {
89+ bin2cpp::setQuietMode (true );
90+ }
91+
92+ // file
5493 if (!bin2cpp::parseArgument (" file" , file, argc, argv))
5594 {
5695 bin2cpp::log (bin2cpp::LOG_ERROR, " Missing 'file' argument!" );
57- usage ();
96+ printUsage ();
5897 return MISSING_FILE;
5998 }
6099
100+ // size
61101 int tmpSize = 0 ;
62102 if (bin2cpp::parseArgument (" size" , tmpSize, argc, argv))
63103 {
@@ -69,6 +109,7 @@ int main(int argc, char **argv)
69109 }
70110 }
71111
112+ // seed
72113 int tmpSeed = 0 ;
73114 if (bin2cpp::parseArgument (" seed" , tmpSeed, argc, argv))
74115 {
@@ -80,6 +121,7 @@ int main(int argc, char **argv)
80121 }
81122 }
82123
124+ // skip
83125 int tmpSkip = 0 ;
84126 if (bin2cpp::parseArgument (" skip" , tmpSkip, argc, argv))
85127 {
@@ -91,6 +133,7 @@ int main(int argc, char **argv)
91133 }
92134 }
93135
136+ // fill
94137 std::string tmpFill;
95138 if (bin2cpp::parseArgument (" fill" , tmpFill, argc, argv))
96139 {
0 commit comments