builder compiles in c (some issues with filtering out preprocess #if)

This commit is contained in:
2024-12-10 07:24:32 -05:00
parent 0ccffe3f80
commit a4143b537d
5 changed files with 270 additions and 189 deletions

View File

@ -2,7 +2,7 @@
# include "builder.hpp"
#endif
Builder Builder::open( char const* path )
Builder builder_open( char const* path )
{
Builder result;
@ -19,41 +19,38 @@ Builder Builder::open( char const* path )
return result;
}
void Builder::pad_lines( s32 num )
void builder_pad_lines( Builder* builder, s32 num )
{
string_append_strc( & Buffer, txt("\n") );
string_append_strc( & builder->Buffer, txt("\n") );
}
void Builder::print( Code code )
void builder_print( Builder* builder, Code code )
{
String str = code_to_string(code);
// const ssize len = str.length();
// log_fmt( "%s - print: %.*s\n", File.filename, len > 80 ? 80 : len, str.Data );
string_append_string( & Buffer, str );
string_append_string( & builder->Buffer, str );
}
void Builder::print_fmt( char const* fmt, ... )
void builder_print_fmt_va( Builder* builder, char const* fmt, va_list va )
{
ssize res;
char buf[ GEN_PRINTF_MAXLEN ] = { 0 };
va_list va;
va_start( va, fmt );
res = str_fmt_va( buf, count_of( buf ) - 1, fmt, va ) - 1;
va_end( va );
// log_fmt( "$%s - print_fmt: %.*s\n", File.filename, res > 80 ? 80 : res, buf );
string_append_c_str_len( (String*) & Buffer, (char const*)buf, res);
string_append_c_str_len( (String*) & builder->Buffer, (char const*)buf, res);
}
void Builder::write()
void builder_write(Builder* builder)
{
b32 result = file_write( & File, Buffer, string_length(Buffer) );
b32 result = file_write( & builder->File, builder->Buffer, string_length(builder->Buffer) );
if ( result == false )
log_failure("gen::File::write - Failed to write to file: %s\n", file_name( & File ) );
log_failure("gen::File::write - Failed to write to file: %s\n", file_name( & builder->File ) );
log_fmt( "Generated: %s\n", File.filename );
file_close( & File );
string_free(& Buffer);
log_fmt( "Generated: %s\n", builder->File.filename );
file_close( & builder->File );
string_free(& builder->Buffer);
}