33
44#include " targetver.h"
55
6- #include " errorcodes.h"
76#include " SegmentGenerator.h"
87#include " StringGenerator.h"
98#include " ArrayGenerator.h"
2524
2625using namespace bin2cpp ;
2726
27+ enum APP_ERROR_CODES
28+ {
29+ APP_ERROR_SUCCESS,
30+ APP_ERROR_MISSINGARGUMENTS,
31+ APP_ERROR_INPUTFILENOTFOUND,
32+ APP_ERROR_UNABLETOCREATEOUTPUTFILES,
33+ };
34+
35+ enum FILE_UPDATE_MODE
36+ {
37+ WRITING,
38+ UPDATING,
39+ OVERWRITING,
40+ SKIPPING,
41+ };
42+
43+ const char * getErrorCodeDescription (const APP_ERROR_CODES & iErrorCode)
44+ {
45+ switch (iErrorCode)
46+ {
47+ case APP_ERROR_SUCCESS:
48+ return " Success" ;
49+ break ;
50+ case APP_ERROR_MISSINGARGUMENTS:
51+ return " Missing arguments" ;
52+ break ;
53+ case APP_ERROR_INPUTFILENOTFOUND:
54+ return " Unable to open input file" ;
55+ break ;
56+ case APP_ERROR_UNABLETOCREATEOUTPUTFILES:
57+ return " Unable to create output files" ;
58+ break ;
59+ default :
60+ return " Unknown error" ;
61+ };
62+ }
63+
64+ const char * getUpdateModeText (const FILE_UPDATE_MODE & iMode)
65+ {
66+ switch (iMode)
67+ {
68+ case WRITING:
69+ return " Writing" ;
70+ case UPDATING:
71+ return " Updating" ;
72+ case OVERWRITING:
73+ return " Overwriting" ;
74+ case SKIPPING:
75+ return " Skipping" ;
76+ default :
77+ return " Unknown" ;
78+ };
79+ }
80+
2881// pre-declarations
2982bool processFile (const std::string & inputFile, bin2cpp::IGenerator * generator, const std::string & functionIdentifier, const size_t & chunkSize, bool overrideExisting, const std::string & iOutputFilePath);
3083
@@ -72,7 +125,7 @@ int main(int argc, char* argv[])
72125 {
73126 printHeader ();
74127 printUsage ();
75- return bin2cpp::ErrorCodes::Success ;
128+ return APP_ERROR_SUCCESS ;
76129 }
77130
78131 // noheader
@@ -100,7 +153,7 @@ int main(int argc, char* argv[])
100153 {
101154 if (!noheader)
102155 printHeader ();
103- return bin2cpp::ErrorCodes::Success ;
156+ return APP_ERROR_SUCCESS ;
104157 }
105158
106159 if (!noheader && !quiet)
@@ -114,31 +167,31 @@ int main(int argc, char* argv[])
114167
115168 if (!bin2cpp::parseArgument (" file" , inputFile, argc, argv))
116169 {
117- bin2cpp::ErrorCodes error = bin2cpp::ErrorCodes::MissingArguments ;
170+ APP_ERROR_CODES error = APP_ERROR_MISSINGARGUMENTS ;
118171 bin2cpp::log (bin2cpp::LOG_ERROR, " %s (file)" , getErrorCodeDescription (error));
119172 printUsage ();
120173 return error;
121174 }
122175
123176 if (!bin2cpp::parseArgument (" output" , outputFolder, argc, argv))
124177 {
125- bin2cpp::ErrorCodes error = bin2cpp::ErrorCodes::MissingArguments ;
178+ APP_ERROR_CODES error = APP_ERROR_MISSINGARGUMENTS ;
126179 bin2cpp::log (bin2cpp::LOG_ERROR, " %s (output)" , getErrorCodeDescription (error));
127180 printUsage ();
128181 return error;
129182 }
130183
131184 if (!bin2cpp::parseArgument (" headerfile" , headerFilename, argc, argv))
132185 {
133- bin2cpp::ErrorCodes error = bin2cpp::ErrorCodes::MissingArguments ;
186+ APP_ERROR_CODES error = APP_ERROR_MISSINGARGUMENTS ;
134187 bin2cpp::log (bin2cpp::LOG_ERROR, " %s (headerfile)" , getErrorCodeDescription (error));
135188 printUsage ();
136189 return error;
137190 }
138191
139192 if (!bin2cpp::parseArgument (" identifier" , functionIdentifier, argc, argv))
140193 {
141- bin2cpp::ErrorCodes error = bin2cpp::ErrorCodes::MissingArguments ;
194+ APP_ERROR_CODES error = APP_ERROR_MISSINGARGUMENTS ;
142195 bin2cpp::log (bin2cpp::LOG_ERROR, " %s (identifier)" , getErrorCodeDescription (error));
143196 printUsage ();
144197 return error;
@@ -185,7 +238,7 @@ int main(int argc, char* argv[])
185238 // validate generator selection
186239 if (generator == NULL )
187240 {
188- bin2cpp::ErrorCodes error = bin2cpp::ErrorCodes::MissingArguments ;
241+ APP_ERROR_CODES error = APP_ERROR_MISSINGARGUMENTS ;
189242 bin2cpp::log (bin2cpp::LOG_ERROR, " %s, unknown values for 'generator' argument!" , getErrorCodeDescription (error));
190243 printUsage ();
191244 return error;
@@ -219,29 +272,21 @@ int main(int argc, char* argv[])
219272
220273 // check if input file exists
221274 if (!bin2cpp::fileExists (inputFile.c_str ()))
222- return bin2cpp::ErrorCodes::InputFileNotFound ;
275+ return APP_ERROR_INPUTFILENOTFOUND ;
223276
224277 // process files
225278 bool headerResult = processFile (inputFile, generator, functionIdentifier, chunkSize, overrideExisting, outputHeaderPath);
226279 if (!headerResult)
227- return bin2cpp::ErrorCodes::UnableToCreateOutputFiles ;
280+ return APP_ERROR_UNABLETOCREATEOUTPUTFILES ;
228281
229282 bool cppResult = processFile (inputFile, generator, functionIdentifier, chunkSize, overrideExisting, outputCppPath);
230283 if (!cppResult)
231- return bin2cpp::ErrorCodes::UnableToCreateOutputFiles ;
284+ return APP_ERROR_UNABLETOCREATEOUTPUTFILES ;
232285
233286 // success
234- return bin2cpp::ErrorCodes::Success ;
287+ return APP_ERROR_SUCCESS ;
235288}
236289
237- enum FILE_UPDATE_MODE
238- {
239- WRITING,
240- UPDATING,
241- OVERWRITING,
242- SKIPPING,
243- };
244-
245290FILE_UPDATE_MODE getFileUpdateMode (const std::string & inputFile, const std::string & iOutputFilePath, bool overrideExisting)
246291{
247292 if (!bin2cpp::fileExists (iOutputFilePath.c_str ()))
@@ -263,23 +308,6 @@ FILE_UPDATE_MODE getFileUpdateMode(const std::string & inputFile, const std::str
263308 return UPDATING;
264309}
265310
266- const char * getUpdateModeText (const FILE_UPDATE_MODE & iMode)
267- {
268- switch (iMode)
269- {
270- case WRITING:
271- return " Writing" ;
272- case UPDATING:
273- return " Updating" ;
274- case OVERWRITING:
275- return " Overwriting" ;
276- case SKIPPING:
277- return " Skipping" ;
278- default :
279- return " Unknown" ;
280- };
281- }
282-
283311bool processFile (const std::string & inputFile, bin2cpp::IGenerator * generator, const std::string & functionIdentifier, const size_t & chunkSize, bool overrideExisting, const std::string & iOutputFilePath)
284312{
285313 FILE_UPDATE_MODE mode = getFileUpdateMode (inputFile, iOutputFilePath, overrideExisting);
@@ -305,7 +333,7 @@ bool processFile(const std::string & inputFile, bin2cpp::IGenerator * generator,
305333 if (!result)
306334 {
307335 // there was an error generating file
308- bin2cpp::log (bin2cpp::LOG_ERROR, " %s" , getErrorCodeDescription (result ));
336+ bin2cpp::log (bin2cpp::LOG_ERROR, " %s" , getErrorCodeDescription (APP_ERROR_UNABLETOCREATEOUTPUTFILES ));
309337 bin2cpp::log (bin2cpp::LOG_ERROR, " Embedding failed!" );
310338 }
311339 return result;
0 commit comments