@@ -73,8 +73,10 @@ enum FILE_UPDATE_MODE
7373
7474// default values
7575static const size_t DEFAULT_CHUNK_SIZE = 200 ;
76- static const char * DEFAULT_NAMESPACE = " bin2cpp" ;
77- static const char * DEFAULT_BASECLASSNAME = " File" ;
76+ static const char * DEFAULT_NAMESPACE_CPP = " bin2cpp" ;
77+ static const char * DEFAULT_NAMESPACE_C = " bin2c" ;
78+ static const char * DEFAULT_BASECLASS_NAME_CPP = " File" ;
79+ static const char * DEFAULT_BASECLASS_NAME_C = " Bin2cFile" ;
7880static const CppEncoderEnum DEFAULT_ENCODING = CPP_ENCODER_OCT;
7981static const CodeGenerationEnum DEFAULT_CODE_GENERATION = CODE_GENERATION_CPP;
8082static Dictionary identifiers_dictionary; // unique values for identifiers
@@ -391,12 +393,31 @@ int main(int argc, char* argv[])
391393
392394 if (!ra::cli::ParseArgument (" namespace" , c.codeNamespace , argc, argv))
393395 {
394- c.codeNamespace = DEFAULT_NAMESPACE;
396+ switch ( c.code )
397+ {
398+ default :
399+ case CODE_GENERATION_CPP:
400+ c.codeNamespace = DEFAULT_NAMESPACE_CPP;
401+ break ;
402+ case CODE_GENERATION_C:
403+ c.codeNamespace = DEFAULT_NAMESPACE_C;
404+ break ;
405+ };
406+
395407 }
396408
397409 if (!ra::cli::ParseArgument (" baseclass" , c.baseClass , argc, argv))
398410 {
399- c.baseClass = DEFAULT_BASECLASSNAME;
411+ switch ( c.code )
412+ {
413+ default :
414+ case CODE_GENERATION_CPP:
415+ c.baseClass = DEFAULT_BASECLASS_NAME_CPP;
416+ break ;
417+ case CODE_GENERATION_C:
418+ c.baseClass = DEFAULT_BASECLASS_NAME_C;
419+ break ;
420+ };
400421 }
401422
402423 c.registerFiles = ra::cli::ParseArgument (" registerfile" , dummy, argc, argv);
@@ -567,8 +588,9 @@ APP_ERROR_CODES processInputFile(const Context & c, bin2cpp::IGenerator * genera
567588 return APP_ERROR_INPUTFILENOTFOUND;
568589
569590 // prepare output files path
570- std::string headerExtention = ra::filesystem::GetFileExtention (c.headerFilename );
571- std::string cppFilename = c.headerFilename .substr (0 , c.headerFilename .size () - headerExtention.size ()) + " cpp" ; // strip out header file's extension and add 'cpp'.
591+ const std::string headerExtention = ra::filesystem::GetFileExtention (c.headerFilename );
592+ const std::string & sourceExtension = getDefaultCodeSourceFileExtension (c.code );
593+ std::string sourceFilename = c.headerFilename .substr (0 , c.headerFilename .size () - headerExtention.size ()) + sourceExtension; // strip out header file's extension and add 'cpp'.
572594
573595 // create a copy of the context.
574596 // we may have already generated files from a previous call to processInputFile().
@@ -577,11 +599,11 @@ APP_ERROR_CODES processInputFile(const Context & c, bin2cpp::IGenerator * genera
577599
578600 // build unique output relative file paths
579601 cCopy.headerFilename = bin2cpp::getUniqueFilePath (cCopy.headerFilename , output_files_dictionary);
580- cppFilename = bin2cpp::getUniqueFilePath (cppFilename , output_files_dictionary);
602+ sourceFilename = bin2cpp::getUniqueFilePath (sourceFilename , output_files_dictionary);
581603
582604 // build full absolute paths
583605 std::string outputHeaderPath = cCopy.outputDirPath + ra::filesystem::GetPathSeparatorStr () + cCopy.headerFilename ;
584- std::string outputCppPath = cCopy.outputDirPath + ra::filesystem::GetPathSeparatorStr () + cppFilename ;
606+ std::string outputSourcePath = cCopy.outputDirPath + ra::filesystem::GetPathSeparatorStr () + sourceFilename ;
585607
586608 // configure the generator
587609 generator->setContext (cCopy);
@@ -607,7 +629,7 @@ APP_ERROR_CODES processInputFile(const Context & c, bin2cpp::IGenerator * genera
607629 if (!headerResult)
608630 return APP_ERROR_UNABLETOCREATEOUTPUTFILES;
609631
610- bool cppResult = generateOutputFile (c, outputCppPath , generator);
632+ bool cppResult = generateOutputFile (c, outputSourcePath , generator);
611633 if (!cppResult)
612634 return APP_ERROR_UNABLETOCREATEOUTPUTFILES;
613635
@@ -760,16 +782,26 @@ bool generateOutputFile(const Context & c, const std::string & output_file_path,
760782
761783 // generate file
762784 bool result = false ;
763- if (isCppHeaderFile (output_file_path))
785+ if (c. code == CODE_GENERATION_CPP && isCppHeaderFile (output_file_path))
764786 {
765- // generate header
787+ // generate C++ header
766788 result = generator->createCppHeaderFile (output_file_path.c_str ());
767789 }
768- else
790+ else if ( c. code == CODE_GENERATION_CPP)
769791 {
770- // generate cpp
792+ // generate C++ source
771793 result = generator->createCppSourceFile (output_file_path.c_str ());
772794 }
795+ else if ( c.code == CODE_GENERATION_C && isCHeaderFile (output_file_path) )
796+ {
797+ // generate C header
798+ result = generator->createCHeaderFile (output_file_path.c_str ());
799+ }
800+ else if ( c.code == CODE_GENERATION_C )
801+ {
802+ // generate C source
803+ result = generator->createCSourceFile (output_file_path.c_str ());
804+ }
773805 if (!result)
774806 {
775807 // there was an error generating file
0 commit comments