2023-08-28 21:03:08 -07:00
|
|
|
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
|
|
|
# include "builder.hpp"
|
|
|
|
#endif
|
2023-08-21 18:40:23 -07:00
|
|
|
|
2023-08-03 08:01:43 -07:00
|
|
|
Builder Builder::open( char const* path )
|
|
|
|
{
|
|
|
|
Builder result;
|
|
|
|
|
|
|
|
FileError error = file_open_mode( & result.File, EFileMode_WRITE, path );
|
|
|
|
|
|
|
|
if ( error != EFileError_NONE )
|
|
|
|
{
|
|
|
|
log_failure( "gen::File::open - Could not open file: %s", path);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
result.Buffer = String::make_reserve( GlobalAllocator, Builder_StrBufferReserve );
|
|
|
|
|
2023-08-19 05:21:28 -07:00
|
|
|
// log_fmt("$Builder - Opened file: %s\n", result.File.filename );
|
2023-08-03 08:01:43 -07:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Builder::pad_lines( s32 num )
|
|
|
|
{
|
|
|
|
Buffer.append( "\n" );
|
|
|
|
}
|
|
|
|
|
2023-07-24 14:45:27 -07:00
|
|
|
void Builder::print( Code code )
|
|
|
|
{
|
2023-08-19 05:21:28 -07:00
|
|
|
String str = code->to_string();
|
2023-09-07 19:51:15 -07:00
|
|
|
// const sw len = str.length();
|
2023-08-19 05:21:28 -07:00
|
|
|
// log_fmt( "%s - print: %.*s\n", File.filename, len > 80 ? 80 : len, str.Data );
|
|
|
|
Buffer.append( str );
|
2023-07-24 14:45:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void Builder::print_fmt( char const* fmt, ... )
|
|
|
|
{
|
|
|
|
sw 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 );
|
|
|
|
|
2023-08-19 05:21:28 -07:00
|
|
|
// log_fmt( "$%s - print_fmt: %.*s\n", File.filename, res > 80 ? 80 : res, buf );
|
2023-07-24 14:45:27 -07:00
|
|
|
Buffer.append( buf, res );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Builder::write()
|
|
|
|
{
|
|
|
|
bool result = file_write( & File, Buffer, Buffer.length() );
|
|
|
|
|
|
|
|
if ( result == false )
|
2023-08-19 05:21:28 -07:00
|
|
|
log_failure("gen::File::write - Failed to write to file: %s\n", file_name( & File ) );
|
2023-07-24 14:45:27 -07:00
|
|
|
|
2023-08-19 05:21:28 -07:00
|
|
|
log_fmt( "Generated: %s\n", File.filename );
|
2023-07-24 14:45:27 -07:00
|
|
|
file_close( & File );
|
|
|
|
Buffer.free();
|
|
|
|
}
|