mirror of
				https://github.com/Ed94/gencpp.git
				synced 2025-11-03 23:36:12 -08:00 
			
		
		
		
	prepare c_library meta-program a bit
This commit is contained in:
		@@ -18,4 +18,49 @@ GEN_NS_END
 | 
			
		||||
 | 
			
		||||
using namespace gen;
 | 
			
		||||
 | 
			
		||||
void format_file( char const* path )
 | 
			
		||||
{
 | 
			
		||||
	String resolved_path = String::make(GlobalAllocator, to_str(path));
 | 
			
		||||
 | 
			
		||||
	String style_arg = String::make(GlobalAllocator, txt("-style=file:"));
 | 
			
		||||
	style_arg.append("../scripts/.clang-format ");
 | 
			
		||||
 | 
			
		||||
	// Need to execute clang format on the generated file to get it to match the original.
 | 
			
		||||
	#define clang_format      "clang-format "
 | 
			
		||||
	#define cf_format_inplace "-i "
 | 
			
		||||
	#define cf_verbose        "-verbose "
 | 
			
		||||
	String command = String::make( GlobalAllocator, clang_format );
 | 
			
		||||
	command.append( cf_format_inplace );
 | 
			
		||||
	command.append( cf_verbose );
 | 
			
		||||
	command.append( style_arg );
 | 
			
		||||
	command.append( resolved_path );
 | 
			
		||||
		log_fmt("\tRunning clang-format on file:\n");
 | 
			
		||||
		system( command );
 | 
			
		||||
		log_fmt("\tclang-format finished reformatting.\n");
 | 
			
		||||
	#undef cf_cmd
 | 
			
		||||
	#undef cf_format_inplace
 | 
			
		||||
	#undef cf_style
 | 
			
		||||
	#undef cf_verbse
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Code dump_to_scratch_and_retireve( Code code )
 | 
			
		||||
{
 | 
			
		||||
	Builder ecode_file_temp = Builder::open("gen/scratch.hpp");
 | 
			
		||||
	ecode_file_temp.print(code);
 | 
			
		||||
	ecode_file_temp.write();
 | 
			
		||||
	format_file("gen/scratch.hpp");
 | 
			
		||||
	Code result = scan_file( "gen/scratch.hpp" );
 | 
			
		||||
	remove("gen/scratch.hpp");
 | 
			
		||||
	return result;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int gen_main()
 | 
			
		||||
{
 | 
			
		||||
#define project_dir "../project/"
 | 
			
		||||
	gen::init();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	gen::deinit();
 | 
			
		||||
	return 0;
 | 
			
		||||
#undef project_dir
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user