LogMessageData(const char* file, unsigned int line, LogId id, LogSeverity severity, int error) : file_(GetFileBasename(file)), line_number_(line), id_(id), severity_(severity), error_(error) { }
int main ( int argc, const char* argv[] ) { if(argc <= 2) { std::cerr << "You need to specify at least the output file and one input file." << std::endl << "Example: " << argv[0] << " output_file input_file" << std::endl; return 1; } try { std::string headername (argv[1]); std::vector<std::string> input_files; for(int i = 2; i < argc; i++) { input_files.push_back(std::string(argv[i])); } /* Process */ std::ofstream output ( headername, std::ios::out | std::ios::trunc| std::ios::binary ); /* Use buffer */ char outbuffer[BUFFER_SIZE]; output.rdbuf()->pubsetbuf ( outbuffer, BUFFER_SIZE ); if ( !output ) throw std::runtime_error ( "Failed to create output file!" ); /* Show status */ std::cout << "Build : file '" << headername << "'..." << std::endl; /* Get base name of file */ headername = GetFileBasename ( headername ); /* Data string stream */ std::ostringstream data; /* Write header start when wanted */ defineheader_start ( data, headername, /*use macro*/ true, /* const */ true ); /* Write macros */ definemacros ( data ); /* Common input buffer */ char inbuffer[BUFFER_SIZE]; for ( auto iter = input_files.begin(); iter != input_files.end(); iter++ ) { std::string &file = *iter; //std::string fileext = GetFileExtension ( file ); std::ifstream input ( file, std::ios::in | std::ios::binary | std::ios::ate ); input.rdbuf()->pubsetbuf ( inbuffer, BUFFER_SIZE ); if ( input.is_open() ) { /* Show status */ std::cout << "Process: file '" << file << "'..." << std::endl; /* Remove extension */ file = removeExtension(file); std::transform(file.begin(), file.end(), file.begin(), ::tolower); std::transform(file.begin(), file.end(), file.begin(), toUnderscores); /* Process file */ definefile ( data, input, file, true ); } else { /* Only show warning, other files need to be processed */ std::cout << "Warning: input file '" << file << "' failed to open." << std::endl; } } /* Write header end when wanted */ defineheader_end ( data, headername ); /* Write data to output file */ output.seekp ( 0, std::ios::beg ); output << data.str(); } catch ( std::exception& e ) { std::cerr << "Error: " << e.what() << std::endl; } catch ( ... ) { std::cerr << "Error: Exception of unknown type!" << std::endl; } return 0; }