77#include < string>
88#include < time.h> /* time */
99#include " argumentparser.h"
10+ #include " logger.h"
1011#include " ..\version_info.h"
1112
1213const char * getVersionString ()
1314{
1415 return BINCPP_VERSION;
1516}
1617
17- bool generateSequentialBinaryFile (size_t size, const char * iFilename)
18- {
19- FILE * f = fopen (iFilename, " wb" );
20- if (f == NULL )
21- return false ;
22- for (size_t i=0 ; i<size; i++)
23- {
24- unsigned int byteInt = i*i + i*3593 + 244 ;
25- unsigned char byte = byteInt%256 ;
26- fwrite (&byte, 1 , 1 , f);
27- }
28- fclose (f);
29- return true ;
30- }
31-
3218void usage ()
3319{
3420 printf (" Usage:\n " );
@@ -55,7 +41,7 @@ enum RETURN_CODE
5541
5642int main (int argc, char **argv)
5743{
58- printf ( " Test file generator v%s\n " , getVersionString ());
44+ bin2cpp::log (bin2cpp::LOG_INFO, " Test file generator v%s" , getVersionString ());
5945
6046 // parse arguments
6147 std::string file;
@@ -66,7 +52,7 @@ int main(int argc, char **argv)
6652
6753 if (!bin2cpp::parseArgument (" file" , file, argc, argv))
6854 {
69- printf ( " Error: Missing 'file' argument!\n " );
55+ bin2cpp::log (bin2cpp::LOG_ERROR, " Missing 'file' argument!\n " );
7056 usage ();
7157 return MISSING_FILE;
7258 }
@@ -77,7 +63,7 @@ int main(int argc, char **argv)
7763 size = tmpSize;
7864 if (size <= 0 )
7965 {
80- printf ( " Error: Invalid file size!\n " );
66+ bin2cpp::log (bin2cpp::LOG_ERROR, " Invalid file size!\n " );
8167 return INVALID_FILE_SIZE;
8268 }
8369 }
@@ -88,7 +74,7 @@ int main(int argc, char **argv)
8874 seed = tmpSeed;
8975 if (seed < 0 )
9076 {
91- printf ( " Error: Invalid seed value!\n " );
77+ bin2cpp::log (bin2cpp::LOG_ERROR, " Invalid seed value!\n " );
9278 return INVALID_SEED;
9379 }
9480 }
@@ -99,7 +85,7 @@ int main(int argc, char **argv)
9985 skip = tmpSkip;
10086 if (skip < 0 )
10187 {
102- printf ( " Error: Invalid skip value!\n " );
88+ bin2cpp::log (bin2cpp::LOG_ERROR, " Invalid skip value!\n " );
10389 return INVALID_SKIP;
10490 }
10591 }
@@ -116,25 +102,25 @@ int main(int argc, char **argv)
116102 }
117103 else
118104 {
119- printf ( " Error: Invalid fill parameter!\n " );
105+ bin2cpp::log (bin2cpp::LOG_ERROR, " Invalid fill parameter!\n " );
120106 return INVALID_FILL_PARAMETER;
121107 }
122108 }
123109
124110 static const size_t ONE_MIB = 1024 *1024 ;
125- printf ( " Generating the following file:\n " );
126- printf ( " path: %s\n " , file.c_str ());
111+ bin2cpp::log (bin2cpp::LOG_INFO, " Generating the following file:\n " );
112+ bin2cpp::log (bin2cpp::LOG_INFO, " path: %s\n " , file.c_str ());
127113 if (size >= ONE_MIB)
128- printf ( " size: %d bytes (%.2f MiB)\n " , size, size/float (ONE_MIB));
114+ bin2cpp::log (bin2cpp::LOG_INFO, " size: %d bytes (%.2f MiB)\n " , size, size/float (ONE_MIB));
129115 else
130- printf ( " size: %d bytes\n " , size);
131- printf ( " fill: %s\n " , fill.c_str ());
116+ bin2cpp::log (bin2cpp::LOG_INFO, " size: %d bytes\n " , size);
117+ bin2cpp::log (bin2cpp::LOG_INFO, " fill: %s\n " , fill.c_str ());
132118
133119 // process with file generation
134120 FILE * f = fopen (file.c_str (), " wb" );
135121 if (!f)
136122 {
137- printf ( " Error: Cannot create file '%s'!\n " , file.c_str ());
123+ bin2cpp::log (bin2cpp::LOG_ERROR, " Cannot create file '%s'!\n " , file.c_str ());
138124 return 4 ;
139125 }
140126
@@ -211,7 +197,7 @@ int main(int argc, char **argv)
211197
212198 fclose (f);
213199
214- printf ( " done!\n " );
200+ bin2cpp::log (bin2cpp::LOG_INFO, " done!\n " );
215201
216202 return EXIT_NO_ERROR;
217203}
0 commit comments