update gencpp to latest
This commit is contained in:
parent
208cc67a7f
commit
feea8361b5
@ -1,3 +1,7 @@
|
|||||||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||||
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CppCodeStyle/OverridingFunctionStyle/@EntryValue">Override</s:String>
|
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CppCodeStyle/OverridingFunctionStyle/@EntryValue">Override</s:String>
|
||||||
|
<s:String x:Key="/Default/Environment/Hierarchy/Build/BuildTool/CustomBuildToolPath/@EntryValue">C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Current\Bin\MSBuild.exe</s:String>
|
||||||
|
<s:String x:Key="/Default/Environment/Hierarchy/Build/BuildTool/DotNetCliExePath/@EntryValue">C:\projects\Unreal\Surgo\UE\Engine\Binaries\ThirdParty\DotNet\8.0.300\win-x64\dotnet.exe</s:String>
|
||||||
|
<s:Int64 x:Key="/Default/Environment/Hierarchy/Build/BuildTool/MsbuildVersion/@EntryValue">1114112</s:Int64>
|
||||||
|
<s:Boolean x:Key="/Default/Environment/Hierarchy/Build/BuildTool/RecentDotNetCliExePaths/=C_003A_005Cprojects_005CUnreal_005CSurgo_005CUE_005CEngine_005CBinaries_005CThirdParty_005CDotNet_005C8_002E0_002E300_005Cwin_002Dx64_005Cdotnet_002Eexe/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Gasa/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Gasa/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
@ -28,8 +28,8 @@ public class GasaEditor : ModuleRules
|
|||||||
PrivateDependencyModuleNames.Add("Gasa");
|
PrivateDependencyModuleNames.Add("Gasa");
|
||||||
|
|
||||||
bWarningsAsErrors = false;
|
bWarningsAsErrors = false;
|
||||||
ShadowVariableWarningLevel = UnrealBuildTool.WarningLevel.Warning;
|
ShadowVariableWarningLevel = UnrealBuildTool.WarningLevel.Off;
|
||||||
UndefinedIdentifierWarningLevel = UnrealBuildTool.WarningLevel.Warning;
|
UndefinedIdentifierWarningLevel = UnrealBuildTool.WarningLevel.Off;
|
||||||
|
|
||||||
// gencpp related defines
|
// gencpp related defines
|
||||||
PublicDefinitions.Add("Build_Debug=1");
|
PublicDefinitions.Add("Build_Debug=1");
|
||||||
|
@ -1,22 +1,22 @@
|
|||||||
// This file was generated automatially by gencpp's unreal.cpp (See: https://github.com/Ed94/gencpp)
|
// This file was generated automatially by gencpp's unreal.cpp (See: https://github.com/Ed94/gencpp)
|
||||||
|
|
||||||
#ifdef __clang__
|
#ifdef __clang__
|
||||||
#pragma clang diagnostic push
|
# pragma clang diagnostic push
|
||||||
#pragma clang diagnostic ignored "-Wunused-const-variable"
|
# pragma clang diagnostic ignored "-Wunused-const-variable"
|
||||||
#pragma clang diagnostic ignored "-Wunused-but-set-variable"
|
# pragma clang diagnostic ignored "-Wunused-but-set-variable"
|
||||||
#pragma clang diagnostic ignored "-Wswitch"
|
# pragma clang diagnostic ignored "-Wswitch"
|
||||||
#pragma clang diagnostic ignored "-Wunused-variable"
|
# pragma clang diagnostic ignored "-Wunused-variable"
|
||||||
#pragma clang diagnostic ignored "-Wunknown-pragmas"
|
# pragma clang diagnostic ignored "-Wunknown-pragmas"
|
||||||
#pragma clang diagnostic ignored "-Wvarargs"
|
# pragma clang diagnostic ignored "-Wvarargs"
|
||||||
#pragma clang diagnostic ignored "-Wunused-function"
|
# pragma clang diagnostic ignored "-Wunused-function"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
#pragma GCC diagnostic push
|
# pragma GCC diagnostic push
|
||||||
#pragma GCC diagnostic ignored "-Wunknown-pragmas"
|
# pragma GCC diagnostic ignored "-Wunknown-pragmas"
|
||||||
#pragma GCC diagnostic ignored "-Wcomment"
|
# pragma GCC diagnostic ignored "-Wcomment"
|
||||||
#pragma GCC diagnostic ignored "-Wswitch"
|
# pragma GCC diagnostic ignored "-Wswitch"
|
||||||
#pragma GCC diagnostic ignored "-Wunused-variable"
|
# pragma GCC diagnostic ignored "-Wunused-variable"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "gen.builder.hpp"
|
#include "gen.builder.hpp"
|
||||||
@ -27,10 +27,10 @@ Builder Builder::open( char const* path )
|
|||||||
{
|
{
|
||||||
Builder result;
|
Builder result;
|
||||||
|
|
||||||
FileError error = file_open_mode( &result.File, EFileMode_WRITE, path );
|
FileError error = file_open_mode( & result.File, EFileMode_WRITE, path );
|
||||||
if ( error != EFileError_NONE )
|
if ( error != EFileError_NONE )
|
||||||
{
|
{
|
||||||
log_failure( "gen::File::open - Could not open file: %s", path );
|
log_failure( "gen::File::open - Could not open file: %s", path);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,16 +47,16 @@ void Builder::pad_lines( s32 num )
|
|||||||
|
|
||||||
void Builder::print( Code code )
|
void Builder::print( Code code )
|
||||||
{
|
{
|
||||||
String str = code->to_string();
|
String str = code->to_string();
|
||||||
// const sw len = str.length();
|
// const ssize len = str.length();
|
||||||
// log_fmt( "%s - print: %.*s\n", File.filename, len > 80 ? 80 : len, str.Data );
|
// log_fmt( "%s - print: %.*s\n", File.filename, len > 80 ? 80 : len, str.Data );
|
||||||
Buffer.append( str );
|
Buffer.append( str );
|
||||||
}
|
}
|
||||||
|
|
||||||
void Builder::print_fmt( char const* fmt, ... )
|
void Builder::print_fmt( char const* fmt, ... )
|
||||||
{
|
{
|
||||||
sw res;
|
ssize res;
|
||||||
char buf[GEN_PRINTF_MAXLEN] = { 0 };
|
char buf[ GEN_PRINTF_MAXLEN ] = { 0 };
|
||||||
|
|
||||||
va_list va;
|
va_list va;
|
||||||
va_start( va, fmt );
|
va_start( va, fmt );
|
||||||
@ -69,22 +69,22 @@ void Builder::print_fmt( char const* fmt, ... )
|
|||||||
|
|
||||||
void Builder::write()
|
void Builder::write()
|
||||||
{
|
{
|
||||||
b32 result = file_write( &File, Buffer, Buffer.length() );
|
b32 result = file_write( & File, Buffer, Buffer.length() );
|
||||||
|
|
||||||
if ( result == false )
|
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( & File ) );
|
||||||
|
|
||||||
log_fmt( "Generated: %s\n", File.filename );
|
log_fmt( "Generated: %s\n", File.filename );
|
||||||
file_close( &File );
|
file_close( & File );
|
||||||
Buffer.free();
|
Buffer.free();
|
||||||
}
|
}
|
||||||
|
|
||||||
GEN_NS_END
|
GEN_NS_END
|
||||||
|
|
||||||
#ifdef __clang__
|
#ifdef __clang__
|
||||||
#pragma clang diagnostic pop
|
# pragma clang diagnostic pop
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
#pragma GCC diagnostic pop
|
# pragma GCC diagnostic pop
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,22 +1,22 @@
|
|||||||
// This file was generated automatially by gencpp's unreal.cpp (See: https://github.com/Ed94/gencpp)
|
// This file was generated automatially by gencpp's unreal.cpp (See: https://github.com/Ed94/gencpp)
|
||||||
|
|
||||||
#ifdef __clang__
|
#ifdef __clang__
|
||||||
#pragma clang diagnostic push
|
# pragma clang diagnostic push
|
||||||
#pragma clang diagnostic ignored "-Wunused-const-variable"
|
# pragma clang diagnostic ignored "-Wunused-const-variable"
|
||||||
#pragma clang diagnostic ignored "-Wunused-but-set-variable"
|
# pragma clang diagnostic ignored "-Wunused-but-set-variable"
|
||||||
#pragma clang diagnostic ignored "-Wswitch"
|
# pragma clang diagnostic ignored "-Wswitch"
|
||||||
#pragma clang diagnostic ignored "-Wunused-variable"
|
# pragma clang diagnostic ignored "-Wunused-variable"
|
||||||
#pragma clang diagnostic ignored "-Wunknown-pragmas"
|
# pragma clang diagnostic ignored "-Wunknown-pragmas"
|
||||||
#pragma clang diagnostic ignored "-Wvarargs"
|
# pragma clang diagnostic ignored "-Wvarargs"
|
||||||
#pragma clang diagnostic ignored "-Wunused-function"
|
# pragma clang diagnostic ignored "-Wunused-function"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
#pragma GCC diagnostic push
|
# pragma GCC diagnostic push
|
||||||
#pragma GCC diagnostic ignored "-Wunknown-pragmas"
|
# pragma GCC diagnostic ignored "-Wunknown-pragmas"
|
||||||
#pragma GCC diagnostic ignored "-Wcomment"
|
# pragma GCC diagnostic ignored "-Wcomment"
|
||||||
#pragma GCC diagnostic ignored "-Wswitch"
|
# pragma GCC diagnostic ignored "-Wswitch"
|
||||||
#pragma GCC diagnostic ignored "-Wunused-variable"
|
# pragma GCC diagnostic ignored "-Wunused-variable"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
@ -43,9 +43,9 @@ struct Builder
|
|||||||
GEN_NS_END
|
GEN_NS_END
|
||||||
|
|
||||||
#ifdef __clang__
|
#ifdef __clang__
|
||||||
#pragma clang diagnostic pop
|
# pragma clang diagnostic pop
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
#pragma GCC diagnostic pop
|
# pragma GCC diagnostic pop
|
||||||
#endif
|
#endif
|
||||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,22 +1,22 @@
|
|||||||
// This file was generated automatially by gencpp's unreal.cpp (See: https://github.com/Ed94/gencpp)
|
// This file was generated automatially by gencpp's unreal.cpp (See: https://github.com/Ed94/gencpp)
|
||||||
|
|
||||||
#ifdef __clang__
|
#ifdef __clang__
|
||||||
#pragma clang diagnostic push
|
# pragma clang diagnostic push
|
||||||
#pragma clang diagnostic ignored "-Wunused-const-variable"
|
# pragma clang diagnostic ignored "-Wunused-const-variable"
|
||||||
#pragma clang diagnostic ignored "-Wunused-but-set-variable"
|
# pragma clang diagnostic ignored "-Wunused-but-set-variable"
|
||||||
#pragma clang diagnostic ignored "-Wswitch"
|
# pragma clang diagnostic ignored "-Wswitch"
|
||||||
#pragma clang diagnostic ignored "-Wunused-variable"
|
# pragma clang diagnostic ignored "-Wunused-variable"
|
||||||
#pragma clang diagnostic ignored "-Wunknown-pragmas"
|
# pragma clang diagnostic ignored "-Wunknown-pragmas"
|
||||||
#pragma clang diagnostic ignored "-Wvarargs"
|
# pragma clang diagnostic ignored "-Wvarargs"
|
||||||
#pragma clang diagnostic ignored "-Wunused-function"
|
# pragma clang diagnostic ignored "-Wunused-function"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
#pragma GCC diagnostic push
|
# pragma GCC diagnostic push
|
||||||
#pragma GCC diagnostic ignored "-Wunknown-pragmas"
|
# pragma GCC diagnostic ignored "-Wunknown-pragmas"
|
||||||
#pragma GCC diagnostic ignored "-Wcomment"
|
# pragma GCC diagnostic ignored "-Wcomment"
|
||||||
#pragma GCC diagnostic ignored "-Wswitch"
|
# pragma GCC diagnostic ignored "-Wswitch"
|
||||||
#pragma GCC diagnostic ignored "-Wunused-variable"
|
# pragma GCC diagnostic ignored "-Wunused-variable"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "gen.scanner.hpp"
|
#include "gen.scanner.hpp"
|
||||||
@ -57,7 +57,7 @@ u8 adt_destroy_branch( ADT_Node* node )
|
|||||||
GEN_ASSERT_NOT_NULL( node );
|
GEN_ASSERT_NOT_NULL( node );
|
||||||
if ( ( node->type == EADT_TYPE_OBJECT || node->type == EADT_TYPE_ARRAY ) && node->nodes )
|
if ( ( node->type == EADT_TYPE_OBJECT || node->type == EADT_TYPE_ARRAY ) && node->nodes )
|
||||||
{
|
{
|
||||||
for ( sw i = 0; i < scast( sw, node->nodes.num() ); ++i )
|
for ( ssize i = 0; i < scast(ssize, node->nodes.num()); ++i )
|
||||||
{
|
{
|
||||||
adt_destroy_branch( node->nodes + i );
|
adt_destroy_branch( node->nodes + i );
|
||||||
}
|
}
|
||||||
@ -87,9 +87,9 @@ ADT_Node* adt_find( ADT_Node* node, char const* name, b32 deep_search )
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( sw i = 0; i < scast( sw, node->nodes.num() ); i++ )
|
for ( ssize i = 0; i < scast(ssize, node->nodes.num()); i++ )
|
||||||
{
|
{
|
||||||
if ( ! str_compare( node->nodes[i].name, name ) )
|
if ( ! str_compare( node->nodes[ i ].name, name ) )
|
||||||
{
|
{
|
||||||
return ( node->nodes + i );
|
return ( node->nodes + i );
|
||||||
}
|
}
|
||||||
@ -97,7 +97,7 @@ ADT_Node* adt_find( ADT_Node* node, char const* name, b32 deep_search )
|
|||||||
|
|
||||||
if ( deep_search )
|
if ( deep_search )
|
||||||
{
|
{
|
||||||
for ( sw i = 0; i < scast( sw, node->nodes.num() ); i++ )
|
for ( ssize i = 0; i < scast(ssize, node->nodes.num()); i++ )
|
||||||
{
|
{
|
||||||
ADT_Node* res = adt_find( node->nodes + i, name, deep_search );
|
ADT_Node* res = adt_find( node->nodes + i, name, deep_search );
|
||||||
|
|
||||||
@ -115,35 +115,35 @@ internal ADT_Node* _adt_get_value( ADT_Node* node, char const* value )
|
|||||||
{
|
{
|
||||||
case EADT_TYPE_MULTISTRING :
|
case EADT_TYPE_MULTISTRING :
|
||||||
case EADT_TYPE_STRING :
|
case EADT_TYPE_STRING :
|
||||||
{
|
|
||||||
if ( node->string && ! str_compare( node->string, value ) )
|
|
||||||
{
|
{
|
||||||
return node;
|
if ( node->string && ! str_compare( node->string, value ) )
|
||||||
|
{
|
||||||
|
return node;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
break;
|
|
||||||
case EADT_TYPE_INTEGER :
|
case EADT_TYPE_INTEGER :
|
||||||
case EADT_TYPE_REAL :
|
case EADT_TYPE_REAL :
|
||||||
{
|
|
||||||
char back[4096] = { 0 };
|
|
||||||
FileInfo tmp;
|
|
||||||
|
|
||||||
/* allocate a file descriptor for a memory-mapped number to string conversion, input source buffer is not cloned, however. */
|
|
||||||
file_stream_open( &tmp, heap(), (u8*)back, size_of( back ), EFileStream_WRITABLE );
|
|
||||||
adt_print_number( &tmp, node );
|
|
||||||
|
|
||||||
sw fsize = 0;
|
|
||||||
u8* buf = file_stream_buf( &tmp, &fsize );
|
|
||||||
|
|
||||||
if ( ! str_compare( (char const*)buf, value ) )
|
|
||||||
{
|
{
|
||||||
file_close( &tmp );
|
char back[ 4096 ] = { 0 };
|
||||||
return node;
|
FileInfo tmp;
|
||||||
}
|
|
||||||
|
|
||||||
file_close( &tmp );
|
/* allocate a file descriptor for a memory-mapped number to string conversion, input source buffer is not cloned, however. */
|
||||||
}
|
file_stream_open( &tmp, heap(), ( u8* )back, size_of( back ), EFileStream_WRITABLE );
|
||||||
break;
|
adt_print_number( &tmp, node );
|
||||||
|
|
||||||
|
ssize fsize = 0;
|
||||||
|
u8* buf = file_stream_buf( &tmp, &fsize );
|
||||||
|
|
||||||
|
if ( ! str_compare( ( char const* )buf, value ) )
|
||||||
|
{
|
||||||
|
file_close( &tmp );
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
file_close( &tmp );
|
||||||
|
}
|
||||||
|
break;
|
||||||
default :
|
default :
|
||||||
break; /* node doesn't support value based lookup */
|
break; /* node doesn't support value based lookup */
|
||||||
}
|
}
|
||||||
@ -153,11 +153,11 @@ internal ADT_Node* _adt_get_value( ADT_Node* node, char const* value )
|
|||||||
|
|
||||||
internal ADT_Node* _adt_get_field( ADT_Node* node, char* name, char* value )
|
internal ADT_Node* _adt_get_field( ADT_Node* node, char* name, char* value )
|
||||||
{
|
{
|
||||||
for ( sw i = 0; i < scast( sw, node->nodes.num() ); i++ )
|
for ( ssize i = 0; i < scast(ssize, node->nodes.num()); i++ )
|
||||||
{
|
{
|
||||||
if ( ! str_compare( node->nodes[i].name, name ) )
|
if ( ! str_compare( node->nodes[ i ].name, name ) )
|
||||||
{
|
{
|
||||||
ADT_Node* child = &node->nodes[i];
|
ADT_Node* child = &node->nodes[ i ];
|
||||||
if ( _adt_get_value( child, value ) )
|
if ( _adt_get_value( child, value ) )
|
||||||
{
|
{
|
||||||
return node; /* this object does contain a field of a specified value! */
|
return node; /* this object does contain a field of a specified value! */
|
||||||
@ -191,19 +191,19 @@ ADT_Node* adt_query( ADT_Node* node, char const* uri )
|
|||||||
str_fmt_out( "uri: %s\n", uri );
|
str_fmt_out( "uri: %s\n", uri );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
char * p = (char*)uri, *b = p, *e = p;
|
char * p = ( char* )uri, *b = p, *e = p;
|
||||||
ADT_Node* found_node = NULL;
|
ADT_Node* found_node = NULL;
|
||||||
|
|
||||||
b = p;
|
b = p;
|
||||||
p = e = (char*)str_skip( p, '/' );
|
p = e = ( char* )str_skip( p, '/' );
|
||||||
char* buf = str_fmt_buf( "%.*s", (int)( e - b ), b );
|
char* buf = str_fmt_buf( "%.*s", ( int )( e - b ), b );
|
||||||
|
|
||||||
/* handle field value lookup */
|
/* handle field value lookup */
|
||||||
if ( *b == '[' )
|
if ( *b == '[' )
|
||||||
{
|
{
|
||||||
char *l_p = buf + 1, *l_b = l_p, *l_e = l_p, *l_b2 = l_p, *l_e2 = l_p;
|
char *l_p = buf + 1, *l_b = l_p, *l_e = l_p, *l_b2 = l_p, *l_e2 = l_p;
|
||||||
l_e = (char*)str_skip( l_p, '=' );
|
l_e = ( char* )str_skip( l_p, '=' );
|
||||||
l_e2 = (char*)str_skip( l_p, ']' );
|
l_e2 = ( char* )str_skip( l_p, ']' );
|
||||||
|
|
||||||
if ( ( ! *l_e && node->type != EADT_TYPE_ARRAY ) || ! *l_e2 )
|
if ( ( ! *l_e && node->type != EADT_TYPE_ARRAY ) || ! *l_e2 )
|
||||||
{
|
{
|
||||||
@ -228,9 +228,9 @@ ADT_Node* adt_query( ADT_Node* node, char const* uri )
|
|||||||
/* run a value comparison against any child that is an object node */
|
/* run a value comparison against any child that is an object node */
|
||||||
else if ( node->type == EADT_TYPE_ARRAY )
|
else if ( node->type == EADT_TYPE_ARRAY )
|
||||||
{
|
{
|
||||||
for ( sw i = 0; i < scast( sw, node->nodes.num() ); i++ )
|
for ( ssize i = 0; i < scast(ssize, node->nodes.num()); i++ )
|
||||||
{
|
{
|
||||||
ADT_Node* child = &node->nodes[i];
|
ADT_Node* child = &node->nodes[ i ];
|
||||||
if ( child->type != EADT_TYPE_OBJECT )
|
if ( child->type != EADT_TYPE_OBJECT )
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
@ -246,9 +246,9 @@ ADT_Node* adt_query( ADT_Node* node, char const* uri )
|
|||||||
/* [value] */
|
/* [value] */
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for ( sw i = 0; i < scast( sw, node->nodes.num() ); i++ )
|
for ( ssize i = 0; i < scast(ssize, node->nodes.num()); i++ )
|
||||||
{
|
{
|
||||||
ADT_Node* child = &node->nodes[i];
|
ADT_Node* child = &node->nodes[ i ];
|
||||||
if ( _adt_get_value( child, l_b2 ) )
|
if ( _adt_get_value( child, l_b2 ) )
|
||||||
{
|
{
|
||||||
found_node = child;
|
found_node = child;
|
||||||
@ -277,10 +277,10 @@ ADT_Node* adt_query( ADT_Node* node, char const* uri )
|
|||||||
/* handle array index lookup */
|
/* handle array index lookup */
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sw idx = (sw)str_to_i64( buf, NULL, 10 );
|
ssize idx = ( ssize )str_to_i64( buf, NULL, 10 );
|
||||||
if ( idx >= 0 && idx < scast( sw, node->nodes.num() ) )
|
if ( idx >= 0 && idx < scast(ssize, node->nodes.num()) )
|
||||||
{
|
{
|
||||||
found_node = &node->nodes[idx];
|
found_node = &node->nodes[ idx ];
|
||||||
|
|
||||||
/* go deeper if uri continues */
|
/* go deeper if uri continues */
|
||||||
if ( *e )
|
if ( *e )
|
||||||
@ -293,7 +293,7 @@ ADT_Node* adt_query( ADT_Node* node, char const* uri )
|
|||||||
return found_node;
|
return found_node;
|
||||||
}
|
}
|
||||||
|
|
||||||
ADT_Node* adt_alloc_at( ADT_Node* parent, sw index )
|
ADT_Node* adt_alloc_at( ADT_Node* parent, ssize index )
|
||||||
{
|
{
|
||||||
if ( ! parent || ( parent->type != EADT_TYPE_OBJECT && parent->type != EADT_TYPE_ARRAY ) )
|
if ( ! parent || ( parent->type != EADT_TYPE_OBJECT && parent->type != EADT_TYPE_ARRAY ) )
|
||||||
{
|
{
|
||||||
@ -303,7 +303,7 @@ ADT_Node* adt_alloc_at( ADT_Node* parent, sw index )
|
|||||||
if ( ! parent->nodes )
|
if ( ! parent->nodes )
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if ( index < 0 || index > scast( sw, parent->nodes.num() ) )
|
if ( index < 0 || index > scast(ssize, parent->nodes.num()) )
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
ADT_Node o = { 0 };
|
ADT_Node o = { 0 };
|
||||||
@ -358,7 +358,7 @@ b8 adt_set_int( ADT_Node* obj, char const* name, s64 value )
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ADT_Node* adt_move_node_at( ADT_Node* node, ADT_Node* new_parent, sw index )
|
ADT_Node* adt_move_node_at( ADT_Node* node, ADT_Node* new_parent, ssize index )
|
||||||
{
|
{
|
||||||
GEN_ASSERT_NOT_NULL( node );
|
GEN_ASSERT_NOT_NULL( node );
|
||||||
GEN_ASSERT_NOT_NULL( new_parent );
|
GEN_ASSERT_NOT_NULL( new_parent );
|
||||||
@ -385,15 +385,15 @@ void adt_swap_nodes( ADT_Node* node, ADT_Node* other_node )
|
|||||||
{
|
{
|
||||||
GEN_ASSERT_NOT_NULL( node );
|
GEN_ASSERT_NOT_NULL( node );
|
||||||
GEN_ASSERT_NOT_NULL( other_node );
|
GEN_ASSERT_NOT_NULL( other_node );
|
||||||
ADT_Node* parent = node->parent;
|
ADT_Node* parent = node->parent;
|
||||||
ADT_Node* other_parent = other_node->parent;
|
ADT_Node* other_parent = other_node->parent;
|
||||||
sw index = ( pointer_diff( parent->nodes, node ) / size_of( ADT_Node ) );
|
ssize index = ( pointer_diff( parent->nodes, node ) / size_of( ADT_Node ) );
|
||||||
sw index2 = ( pointer_diff( other_parent->nodes, other_node ) / size_of( ADT_Node ) );
|
ssize index2 = ( pointer_diff( other_parent->nodes, other_node ) / size_of( ADT_Node ) );
|
||||||
ADT_Node temp = parent->nodes[index];
|
ADT_Node temp = parent->nodes[ index ];
|
||||||
temp.parent = other_parent;
|
temp.parent = other_parent;
|
||||||
other_parent->nodes[index2].parent = parent;
|
other_parent->nodes[ index2 ].parent = parent;
|
||||||
parent->nodes[index] = other_parent->nodes[index2];
|
parent->nodes[ index ] = other_parent->nodes[ index2 ];
|
||||||
other_parent->nodes[index2] = temp;
|
other_parent->nodes[ index2 ] = temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
void adt_remove_node( ADT_Node* node )
|
void adt_remove_node( ADT_Node* node )
|
||||||
@ -401,7 +401,7 @@ void adt_remove_node( ADT_Node* node )
|
|||||||
GEN_ASSERT_NOT_NULL( node );
|
GEN_ASSERT_NOT_NULL( node );
|
||||||
GEN_ASSERT_NOT_NULL( node->parent );
|
GEN_ASSERT_NOT_NULL( node->parent );
|
||||||
ADT_Node* parent = node->parent;
|
ADT_Node* parent = node->parent;
|
||||||
sw index = ( pointer_diff( parent->nodes, node ) / size_of( ADT_Node ) );
|
ssize index = ( pointer_diff( parent->nodes, node ) / size_of( ADT_Node ) );
|
||||||
parent->nodes.remove_at( index );
|
parent->nodes.remove_at( index );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -487,14 +487,14 @@ char* adt_parse_number( ADT_Node* node, char* base_str )
|
|||||||
GEN_ASSERT_NOT_NULL( base_str );
|
GEN_ASSERT_NOT_NULL( base_str );
|
||||||
char *p = base_str, *e = p;
|
char *p = base_str, *e = p;
|
||||||
|
|
||||||
s32 base = 0;
|
s32 base = 0;
|
||||||
s32 base2 = 0;
|
s32 base2 = 0;
|
||||||
u8 base2_offset = 0;
|
u8 base2_offset = 0;
|
||||||
s8 exp = 0, orig_exp = 0;
|
s8 exp = 0, orig_exp = 0;
|
||||||
u8 neg_zero = 0;
|
u8 neg_zero = 0;
|
||||||
u8 lead_digit = 0;
|
u8 lead_digit = 0;
|
||||||
ADT_Type node_type = EADT_TYPE_UNINITIALISED;
|
ADT_Type node_type = EADT_TYPE_UNINITIALISED;
|
||||||
u8 node_props = 0;
|
u8 node_props = 0;
|
||||||
|
|
||||||
/* skip false positives and special cases */
|
/* skip false positives and special cases */
|
||||||
if ( ! ! str_find( "eE", *p ) || ( ! ! str_find( ".+-", *p ) && ! char_is_hex_digit( *( p + 1 ) ) && *( p + 1 ) != '.' ) )
|
if ( ! ! str_find( "eE", *p ) || ( ! ! str_find( ".+-", *p ) && ! char_is_hex_digit( *( p + 1 ) ) && *( p + 1 ) != '.' ) )
|
||||||
@ -502,28 +502,28 @@ char* adt_parse_number( ADT_Node* node, char* base_str )
|
|||||||
return ++base_str;
|
return ++base_str;
|
||||||
}
|
}
|
||||||
|
|
||||||
node_type = EADT_TYPE_INTEGER;
|
node_type = EADT_TYPE_INTEGER;
|
||||||
neg_zero = false;
|
neg_zero = false;
|
||||||
|
|
||||||
sw ib = 0;
|
ssize ib = 0;
|
||||||
char buf[48] = { 0 };
|
char buf[ 48 ] = { 0 };
|
||||||
|
|
||||||
if ( *e == '+' )
|
if ( *e == '+' )
|
||||||
++e;
|
++e;
|
||||||
else if ( *e == '-' )
|
else if ( *e == '-' )
|
||||||
{
|
{
|
||||||
buf[ib++] = *e++;
|
buf[ ib++ ] = *e++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( *e == '.' )
|
if ( *e == '.' )
|
||||||
{
|
{
|
||||||
node_type = EADT_TYPE_REAL;
|
node_type = EADT_TYPE_REAL;
|
||||||
node_props = EADT_PROPS_IS_PARSED_REAL;
|
node_props = EADT_PROPS_IS_PARSED_REAL;
|
||||||
lead_digit = false;
|
lead_digit = false;
|
||||||
buf[ib++] = '0';
|
buf[ ib++ ] = '0';
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
buf[ib++] = *e;
|
buf[ ib++ ] = *e;
|
||||||
} while ( char_is_digit( *++e ) );
|
} while ( char_is_digit( *++e ) );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -541,7 +541,7 @@ char* adt_parse_number( ADT_Node* node, char* base_str )
|
|||||||
|
|
||||||
while ( char_is_hex_digit( *e ) || char_to_lower( *e ) == 'x' )
|
while ( char_is_hex_digit( *e ) || char_to_lower( *e ) == 'x' )
|
||||||
{
|
{
|
||||||
buf[ib++] = *e++;
|
buf[ ib++ ] = *e++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( *e == '.' )
|
if ( *e == '.' )
|
||||||
@ -552,13 +552,13 @@ char* adt_parse_number( ADT_Node* node, char* base_str )
|
|||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
buf[ib++] = *e;
|
buf[ ib++ ] = *e;
|
||||||
++step;
|
++step;
|
||||||
} while ( char_is_digit( *++e ) );
|
} while ( char_is_digit( *++e ) );
|
||||||
|
|
||||||
if ( step < 2 )
|
if ( step < 2 )
|
||||||
{
|
{
|
||||||
buf[ib++] = '0';
|
buf[ ib++ ] = '0';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -569,9 +569,9 @@ char* adt_parse_number( ADT_Node* node, char* base_str )
|
|||||||
return ++base_str;
|
return ++base_str;
|
||||||
}
|
}
|
||||||
|
|
||||||
f32 eb = 10;
|
f32 eb = 10;
|
||||||
char expbuf[6] = { 0 };
|
char expbuf[ 6 ] = { 0 };
|
||||||
sw expi = 0;
|
ssize expi = 0;
|
||||||
|
|
||||||
if ( *e && ! ! str_find( "eE", *e ) )
|
if ( *e && ! ! str_find( "eE", *e ) )
|
||||||
{
|
{
|
||||||
@ -588,11 +588,11 @@ char* adt_parse_number( ADT_Node* node, char* base_str )
|
|||||||
}
|
}
|
||||||
while ( char_is_digit( *e ) )
|
while ( char_is_digit( *e ) )
|
||||||
{
|
{
|
||||||
expbuf[expi++] = *e++;
|
expbuf[ expi++ ] = *e++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
orig_exp = exp = (u8)str_to_i64( expbuf, NULL, 10 );
|
orig_exp = exp = ( u8 )str_to_i64( expbuf, NULL, 10 );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( node_type == EADT_TYPE_INTEGER )
|
if ( node_type == EADT_TYPE_INTEGER )
|
||||||
@ -600,14 +600,14 @@ char* adt_parse_number( ADT_Node* node, char* base_str )
|
|||||||
node->integer = str_to_i64( buf, 0, 0 );
|
node->integer = str_to_i64( buf, 0, 0 );
|
||||||
#ifndef GEN_PARSER_DISABLE_ANALYSIS
|
#ifndef GEN_PARSER_DISABLE_ANALYSIS
|
||||||
/* special case: negative zero */
|
/* special case: negative zero */
|
||||||
if ( node->integer == 0 && buf[0] == '-' )
|
if ( node->integer == 0 && buf[ 0 ] == '-' )
|
||||||
{
|
{
|
||||||
neg_zero = true;
|
neg_zero = true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
while ( orig_exp-- > 0 )
|
while ( orig_exp-- > 0 )
|
||||||
{
|
{
|
||||||
node->integer *= (s64)eb;
|
node->integer *= ( s64 )eb;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -616,15 +616,15 @@ char* adt_parse_number( ADT_Node* node, char* base_str )
|
|||||||
|
|
||||||
#ifndef GEN_PARSER_DISABLE_ANALYSIS
|
#ifndef GEN_PARSER_DISABLE_ANALYSIS
|
||||||
char *q = buf, *base_string = q, *base_string2 = q;
|
char *q = buf, *base_string = q, *base_string2 = q;
|
||||||
base_string = zpl_cast( char* ) str_skip( base_string, '.' );
|
base_string = ccast( char*, str_skip( base_string, '.' ));
|
||||||
*base_string = '\0';
|
*base_string = '\0';
|
||||||
base_string2 = base_string + 1;
|
base_string2 = base_string + 1;
|
||||||
char* base_string_off = base_string2;
|
char* base_string_off = base_string2;
|
||||||
while ( *base_string_off++ == '0' )
|
while ( *base_string_off++ == '0' )
|
||||||
base2_offset++;
|
base2_offset++;
|
||||||
|
|
||||||
base = (s32)str_to_i64( q, 0, 0 );
|
base = ( s32 )str_to_i64( q, 0, 0 );
|
||||||
base2 = (s32)str_to_i64( base_string2, 0, 0 );
|
base2 = ( s32 )str_to_i64( base_string2, 0, 0 );
|
||||||
if ( exp )
|
if ( exp )
|
||||||
{
|
{
|
||||||
exp = exp * ( ! ( eb == 10.0f ) ? -1 : 1 );
|
exp = exp * ( ! ( eb == 10.0f ) ? -1 : 1 );
|
||||||
@ -632,7 +632,7 @@ char* adt_parse_number( ADT_Node* node, char* base_str )
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* special case: negative zero */
|
/* special case: negative zero */
|
||||||
if ( base == 0 && buf[0] == '-' )
|
if ( base == 0 && buf[ 0 ] == '-' )
|
||||||
{
|
{
|
||||||
neg_zero = true;
|
neg_zero = true;
|
||||||
}
|
}
|
||||||
@ -683,67 +683,67 @@ ADT_Error adt_print_number( FileInfo* file, ADT_Node* node )
|
|||||||
switch ( node->type )
|
switch ( node->type )
|
||||||
{
|
{
|
||||||
case EADT_TYPE_INTEGER :
|
case EADT_TYPE_INTEGER :
|
||||||
{
|
|
||||||
if ( node->props == EADT_PROPS_IS_HEX )
|
|
||||||
{
|
{
|
||||||
_adt_fprintf( file, "0x%llx", (long long)node->integer );
|
if ( node->props == EADT_PROPS_IS_HEX )
|
||||||
|
{
|
||||||
|
_adt_fprintf( file, "0x%llx", ( long long )node->integer );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_adt_fprintf( file, "%lld", ( long long )node->integer );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
break;
|
||||||
{
|
|
||||||
_adt_fprintf( file, "%lld", (long long)node->integer );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case EADT_TYPE_REAL :
|
case EADT_TYPE_REAL :
|
||||||
{
|
|
||||||
if ( node->props == EADT_PROPS_NAN )
|
|
||||||
{
|
{
|
||||||
_adt_fprintf( file, "NaN" );
|
if ( node->props == EADT_PROPS_NAN )
|
||||||
}
|
{
|
||||||
else if ( node->props == EADT_PROPS_NAN_NEG )
|
_adt_fprintf( file, "NaN" );
|
||||||
{
|
}
|
||||||
_adt_fprintf( file, "-NaN" );
|
else if ( node->props == EADT_PROPS_NAN_NEG )
|
||||||
}
|
{
|
||||||
else if ( node->props == EADT_PROPS_INFINITY )
|
_adt_fprintf( file, "-NaN" );
|
||||||
{
|
}
|
||||||
_adt_fprintf( file, "Infinity" );
|
else if ( node->props == EADT_PROPS_INFINITY )
|
||||||
}
|
{
|
||||||
else if ( node->props == EADT_PROPS_INFINITY_NEG )
|
_adt_fprintf( file, "Infinity" );
|
||||||
{
|
}
|
||||||
_adt_fprintf( file, "-Infinity" );
|
else if ( node->props == EADT_PROPS_INFINITY_NEG )
|
||||||
}
|
{
|
||||||
else if ( node->props == EADT_PROPS_TRUE )
|
_adt_fprintf( file, "-Infinity" );
|
||||||
{
|
}
|
||||||
_adt_fprintf( file, "true" );
|
else if ( node->props == EADT_PROPS_TRUE )
|
||||||
}
|
{
|
||||||
else if ( node->props == EADT_PROPS_FALSE )
|
_adt_fprintf( file, "true" );
|
||||||
{
|
}
|
||||||
_adt_fprintf( file, "false" );
|
else if ( node->props == EADT_PROPS_FALSE )
|
||||||
}
|
{
|
||||||
else if ( node->props == EADT_PROPS_NULL )
|
_adt_fprintf( file, "false" );
|
||||||
{
|
}
|
||||||
_adt_fprintf( file, "null" );
|
else if ( node->props == EADT_PROPS_NULL )
|
||||||
|
{
|
||||||
|
_adt_fprintf( file, "null" );
|
||||||
#ifndef GEN_PARSER_DISABLE_ANALYSIS
|
#ifndef GEN_PARSER_DISABLE_ANALYSIS
|
||||||
}
|
}
|
||||||
else if ( node->props == EADT_PROPS_IS_EXP )
|
else if ( node->props == EADT_PROPS_IS_EXP )
|
||||||
{
|
{
|
||||||
_adt_fprintf( file, "%lld.%0*d%llde%lld", (long long)node->base, node->base2_offset, 0, (long long)node->base2, (long long)node->exp );
|
_adt_fprintf( file, "%lld.%0*d%llde%lld", ( long long )node->base, node->base2_offset, 0, ( long long )node->base2, ( long long )node->exp );
|
||||||
}
|
}
|
||||||
else if ( node->props == EADT_PROPS_IS_PARSED_REAL )
|
else if ( node->props == EADT_PROPS_IS_PARSED_REAL )
|
||||||
{
|
{
|
||||||
if ( ! node->lead_digit )
|
if ( ! node->lead_digit )
|
||||||
_adt_fprintf( file, ".%0*d%lld", node->base2_offset, 0, (long long)node->base2 );
|
_adt_fprintf( file, ".%0*d%lld", node->base2_offset, 0, ( long long )node->base2 );
|
||||||
else
|
else
|
||||||
_adt_fprintf( file, "%lld.%0*d%lld", (long long int)node->base2_offset, 0, (int)node->base, (long long)node->base2 );
|
_adt_fprintf( file, "%lld.%0*d%lld", ( long long int )node->base2_offset, 0, ( int )node->base, ( long long )node->base2 );
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_adt_fprintf( file, "%f", node->real );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
break;
|
||||||
{
|
|
||||||
_adt_fprintf( file, "%f", node->real );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return EADT_ERROR_NONE;
|
return EADT_ERROR_NONE;
|
||||||
@ -791,7 +791,7 @@ ADT_Error adt_str_to_number( ADT_Node* node )
|
|||||||
return EADT_ERROR_INVALID_TYPE;
|
return EADT_ERROR_INVALID_TYPE;
|
||||||
}
|
}
|
||||||
|
|
||||||
adt_parse_number( node, (char*)node->string );
|
adt_parse_number( node, ( char* )node->string );
|
||||||
|
|
||||||
return EADT_ERROR_NONE;
|
return EADT_ERROR_NONE;
|
||||||
}
|
}
|
||||||
@ -807,7 +807,7 @@ ADT_Error adt_str_to_number_strict( ADT_Node* node )
|
|||||||
return EADT_ERROR_INVALID_TYPE;
|
return EADT_ERROR_INVALID_TYPE;
|
||||||
}
|
}
|
||||||
|
|
||||||
adt_parse_number_strict( node, (char*)node->string );
|
adt_parse_number_strict( node, ( char* )node->string );
|
||||||
|
|
||||||
return EADT_ERROR_NONE;
|
return EADT_ERROR_NONE;
|
||||||
}
|
}
|
||||||
@ -819,9 +819,9 @@ ADT_Error adt_str_to_number_strict( ADT_Node* node )
|
|||||||
#pragma region CSV
|
#pragma region CSV
|
||||||
|
|
||||||
#ifdef GEN_CSV_DEBUG
|
#ifdef GEN_CSV_DEBUG
|
||||||
#define GEN_CSV_ASSERT( msg ) GEN_PANIC( msg )
|
# define GEN_CSV_ASSERT( msg ) GEN_PANIC( msg )
|
||||||
#else
|
#else
|
||||||
#define GEN_CSV_ASSERT( msg )
|
# define GEN_CSV_ASSERT( msg )
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
u8 csv_parse_delimiter( CSV_Object* root, char* text, AllocatorInfo allocator, b32 has_header, char delim )
|
u8 csv_parse_delimiter( CSV_Object* root, char* text, AllocatorInfo allocator, b32 has_header, char delim )
|
||||||
@ -837,13 +837,13 @@ u8 csv_parse_delimiter( CSV_Object* root, char* text, AllocatorInfo allocator, b
|
|||||||
char* beginChar;
|
char* beginChar;
|
||||||
char* endChar;
|
char* endChar;
|
||||||
|
|
||||||
sw columnIndex = 0;
|
ssize columnIndex = 0;
|
||||||
sw totalColumnIndex = 0;
|
ssize totalColumnIndex = 0;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
char delimiter = 0;
|
char delimiter = 0;
|
||||||
currentChar = zpl_cast( char* ) str_trim( currentChar, false );
|
currentChar = ccast( char*, str_trim( currentChar, false ));
|
||||||
|
|
||||||
if ( *currentChar == 0 )
|
if ( *currentChar == 0 )
|
||||||
break;
|
break;
|
||||||
@ -851,23 +851,23 @@ u8 csv_parse_delimiter( CSV_Object* root, char* text, AllocatorInfo allocator, b
|
|||||||
ADT_Node rowItem = { 0 };
|
ADT_Node rowItem = { 0 };
|
||||||
rowItem.type = EADT_TYPE_STRING;
|
rowItem.type = EADT_TYPE_STRING;
|
||||||
|
|
||||||
#ifndef GEN_PARSER_DISABLE_ANALYSIS
|
#ifndef GEN_PARSER_DISABLE_ANALYSIS
|
||||||
rowItem.name_style = EADT_NAME_STYLE_NO_QUOTES;
|
rowItem.name_style = EADT_NAME_STYLE_NO_QUOTES;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* handle string literals */
|
/* handle string literals */
|
||||||
if ( *currentChar == '"' )
|
if ( *currentChar == '"' )
|
||||||
{
|
{
|
||||||
currentChar += 1;
|
currentChar += 1;
|
||||||
beginChar = currentChar;
|
beginChar = currentChar;
|
||||||
endChar = currentChar;
|
endChar = currentChar;
|
||||||
rowItem.string = beginChar;
|
rowItem.string = beginChar;
|
||||||
#ifndef GEN_PARSER_DISABLE_ANALYSIS
|
#ifndef GEN_PARSER_DISABLE_ANALYSIS
|
||||||
rowItem.name_style = EADT_NAME_STYLE_DOUBLE_QUOTE;
|
rowItem.name_style = EADT_NAME_STYLE_DOUBLE_QUOTE;
|
||||||
#endif
|
#endif
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
endChar = zpl_cast( char* ) str_skip( endChar, '"' );
|
endChar = ccast( char*, str_skip( endChar, '"' ));
|
||||||
|
|
||||||
if ( *endChar && *( endChar + 1 ) == '"' )
|
if ( *endChar && *( endChar + 1 ) == '"' )
|
||||||
{
|
{
|
||||||
@ -875,7 +875,8 @@ u8 csv_parse_delimiter( CSV_Object* root, char* text, AllocatorInfo allocator, b
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
} while ( *endChar );
|
}
|
||||||
|
while ( *endChar );
|
||||||
|
|
||||||
if ( *endChar == 0 )
|
if ( *endChar == 0 )
|
||||||
{
|
{
|
||||||
@ -885,8 +886,8 @@ u8 csv_parse_delimiter( CSV_Object* root, char* text, AllocatorInfo allocator, b
|
|||||||
}
|
}
|
||||||
|
|
||||||
*endChar = 0;
|
*endChar = 0;
|
||||||
currentChar = zpl_cast( char* ) str_trim( endChar + 1, true );
|
currentChar = ccast( char*, str_trim( endChar + 1, true ));
|
||||||
delimiter = *currentChar;
|
delimiter = * currentChar;
|
||||||
|
|
||||||
/* unescape escaped quotes (so that unescaped text escapes :) */
|
/* unescape escaped quotes (so that unescaped text escapes :) */
|
||||||
{
|
{
|
||||||
@ -898,12 +899,13 @@ u8 csv_parse_delimiter( CSV_Object* root, char* text, AllocatorInfo allocator, b
|
|||||||
mem_move( escapedChar, escapedChar + 1, str_len( escapedChar ) );
|
mem_move( escapedChar, escapedChar + 1, str_len( escapedChar ) );
|
||||||
}
|
}
|
||||||
escapedChar++;
|
escapedChar++;
|
||||||
} while ( *escapedChar );
|
}
|
||||||
|
while ( *escapedChar );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( *currentChar == delim )
|
else if ( *currentChar == delim )
|
||||||
{
|
{
|
||||||
delimiter = *currentChar;
|
delimiter = * currentChar;
|
||||||
rowItem.string = "";
|
rowItem.string = "";
|
||||||
}
|
}
|
||||||
else if ( *currentChar )
|
else if ( *currentChar )
|
||||||
@ -916,19 +918,20 @@ u8 csv_parse_delimiter( CSV_Object* root, char* text, AllocatorInfo allocator, b
|
|||||||
do
|
do
|
||||||
{
|
{
|
||||||
endChar++;
|
endChar++;
|
||||||
} while ( *endChar && *endChar != delim && *endChar != '\n' );
|
}
|
||||||
|
while ( * endChar && * endChar != delim && * endChar != '\n' );
|
||||||
|
|
||||||
if ( *endChar )
|
if ( * endChar )
|
||||||
{
|
{
|
||||||
currentChar = zpl_cast( char* ) str_trim( endChar, true );
|
currentChar = ccast( char*, str_trim( endChar, true ));
|
||||||
|
|
||||||
while ( char_is_space( *( endChar - 1 ) ) )
|
while ( char_is_space( *( endChar - 1 ) ) )
|
||||||
{
|
{
|
||||||
endChar--;
|
endChar--;
|
||||||
}
|
}
|
||||||
|
|
||||||
delimiter = *currentChar;
|
delimiter = * currentChar;
|
||||||
*endChar = 0;
|
* endChar = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -941,35 +944,35 @@ u8 csv_parse_delimiter( CSV_Object* root, char* text, AllocatorInfo allocator, b
|
|||||||
char* num_p = beginChar;
|
char* num_p = beginChar;
|
||||||
|
|
||||||
// We only consider hexadecimal values if they start with 0x
|
// We only consider hexadecimal values if they start with 0x
|
||||||
if ( str_len( num_p ) > 2 && num_p[0] == '0' && ( num_p[1] == 'x' || num_p[1] == 'X' ) )
|
if ( str_len(num_p) > 2 && num_p[0] == '0' && (num_p[1] == 'x' || num_p[1] == 'X') )
|
||||||
{
|
{
|
||||||
num_p += 2; // skip '0x' prefix
|
num_p += 2; // skip '0x' prefix
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if ( ! char_is_hex_digit( *num_p ) )
|
if (!char_is_hex_digit(*num_p))
|
||||||
{
|
{
|
||||||
skip_number = true;
|
skip_number = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while ( *num_p++ );
|
} while (*num_p++);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
skip_number = true;
|
skip_number = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! skip_number )
|
if (!skip_number)
|
||||||
{
|
{
|
||||||
adt_str_to_number( &rowItem );
|
adt_str_to_number(&rowItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( columnIndex >= scast( sw, root->nodes.num() ) )
|
if ( columnIndex >= scast(ssize, root->nodes.num()) )
|
||||||
{
|
{
|
||||||
adt_append_arr( root, NULL );
|
adt_append_arr( root, NULL );
|
||||||
}
|
}
|
||||||
|
|
||||||
root->nodes[columnIndex].nodes.append( rowItem );
|
root->nodes[ columnIndex ].nodes.append( rowItem );
|
||||||
|
|
||||||
if ( delimiter == delim )
|
if ( delimiter == delim )
|
||||||
{
|
{
|
||||||
@ -994,7 +997,8 @@ u8 csv_parse_delimiter( CSV_Object* root, char* text, AllocatorInfo allocator, b
|
|||||||
if ( delimiter != 0 )
|
if ( delimiter != 0 )
|
||||||
currentChar++;
|
currentChar++;
|
||||||
}
|
}
|
||||||
} while ( *currentChar );
|
}
|
||||||
|
while ( *currentChar );
|
||||||
|
|
||||||
if ( root->nodes.num() == 0 )
|
if ( root->nodes.num() == 0 )
|
||||||
{
|
{
|
||||||
@ -1006,7 +1010,7 @@ u8 csv_parse_delimiter( CSV_Object* root, char* text, AllocatorInfo allocator, b
|
|||||||
/* consider first row as a header. */
|
/* consider first row as a header. */
|
||||||
if ( has_header )
|
if ( has_header )
|
||||||
{
|
{
|
||||||
for ( sw i = 0; i < scast( sw, root->nodes.num() ); i++ )
|
for ( ssize i = 0; i < scast(ssize, root->nodes.num()); i++ )
|
||||||
{
|
{
|
||||||
CSV_Object* col = root->nodes + i;
|
CSV_Object* col = root->nodes + i;
|
||||||
CSV_Object* hdr = col->nodes;
|
CSV_Object* hdr = col->nodes;
|
||||||
@ -1028,36 +1032,36 @@ void _csv_write_record( FileInfo* file, CSV_Object* node )
|
|||||||
switch ( node->type )
|
switch ( node->type )
|
||||||
{
|
{
|
||||||
case EADT_TYPE_STRING :
|
case EADT_TYPE_STRING :
|
||||||
{
|
|
||||||
#ifndef GEN_PARSER_DISABLE_ANALYSIS
|
|
||||||
switch ( node->name_style )
|
|
||||||
{
|
{
|
||||||
case EADT_NAME_STYLE_DOUBLE_QUOTE :
|
|
||||||
{
|
|
||||||
str_fmt_file( file, "\"" );
|
|
||||||
adt_print_string( file, node, "\"", "\"" );
|
|
||||||
str_fmt_file( file, "\"" );
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case EADT_NAME_STYLE_NO_QUOTES :
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
str_fmt_file( file, "%s", node->string );
|
|
||||||
#ifndef GEN_PARSER_DISABLE_ANALYSIS
|
#ifndef GEN_PARSER_DISABLE_ANALYSIS
|
||||||
}
|
switch ( node->name_style )
|
||||||
break;
|
{
|
||||||
}
|
case EADT_NAME_STYLE_DOUBLE_QUOTE :
|
||||||
|
{
|
||||||
|
str_fmt_file( file, "\"" );
|
||||||
|
adt_print_string( file, node, "\"", "\"" );
|
||||||
|
str_fmt_file( file, "\"" );
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case EADT_NAME_STYLE_NO_QUOTES :
|
||||||
|
{
|
||||||
#endif
|
#endif
|
||||||
}
|
str_fmt_file( file, "%s", node->string );
|
||||||
break;
|
#ifndef GEN_PARSER_DISABLE_ANALYSIS
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case EADT_TYPE_REAL :
|
case EADT_TYPE_REAL :
|
||||||
case EADT_TYPE_INTEGER :
|
case EADT_TYPE_INTEGER :
|
||||||
{
|
{
|
||||||
adt_print_number( file, node );
|
adt_print_number( file, node );
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1074,21 +1078,21 @@ void csv_write_delimiter( FileInfo* file, CSV_Object* obj, char delimiter )
|
|||||||
GEN_ASSERT_NOT_NULL( file );
|
GEN_ASSERT_NOT_NULL( file );
|
||||||
GEN_ASSERT_NOT_NULL( obj );
|
GEN_ASSERT_NOT_NULL( obj );
|
||||||
GEN_ASSERT( obj->nodes );
|
GEN_ASSERT( obj->nodes );
|
||||||
sw cols = obj->nodes.num();
|
ssize cols = obj->nodes.num();
|
||||||
if ( cols == 0 )
|
if ( cols == 0 )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
sw rows = obj->nodes[0].nodes.num();
|
ssize rows = obj->nodes[ 0 ].nodes.num();
|
||||||
if ( rows == 0 )
|
if ( rows == 0 )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
b32 has_headers = obj->nodes[0].name != NULL;
|
b32 has_headers = obj->nodes[ 0 ].name != NULL;
|
||||||
|
|
||||||
if ( has_headers )
|
if ( has_headers )
|
||||||
{
|
{
|
||||||
for ( sw i = 0; i < cols; i++ )
|
for ( ssize i = 0; i < cols; i++ )
|
||||||
{
|
{
|
||||||
_csv_write_header( file, &obj->nodes[i] );
|
_csv_write_header( file, &obj->nodes[ i ] );
|
||||||
if ( i + 1 != cols )
|
if ( i + 1 != cols )
|
||||||
{
|
{
|
||||||
str_fmt_file( file, "%c", delimiter );
|
str_fmt_file( file, "%c", delimiter );
|
||||||
@ -1097,11 +1101,11 @@ void csv_write_delimiter( FileInfo* file, CSV_Object* obj, char delimiter )
|
|||||||
str_fmt_file( file, "\n" );
|
str_fmt_file( file, "\n" );
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( sw r = 0; r < rows; r++ )
|
for ( ssize r = 0; r < rows; r++ )
|
||||||
{
|
{
|
||||||
for ( sw i = 0; i < cols; i++ )
|
for ( ssize i = 0; i < cols; i++ )
|
||||||
{
|
{
|
||||||
_csv_write_record( file, &obj->nodes[i].nodes[r] );
|
_csv_write_record( file, &obj->nodes[ i ].nodes[ r ] );
|
||||||
if ( i + 1 != cols )
|
if ( i + 1 != cols )
|
||||||
{
|
{
|
||||||
str_fmt_file( file, "%c", delimiter );
|
str_fmt_file( file, "%c", delimiter );
|
||||||
@ -1116,9 +1120,10 @@ String csv_write_string_delimiter( AllocatorInfo a, CSV_Object* obj, char delimi
|
|||||||
FileInfo tmp;
|
FileInfo tmp;
|
||||||
file_stream_new( &tmp, a );
|
file_stream_new( &tmp, a );
|
||||||
csv_write_delimiter( &tmp, obj, delimiter );
|
csv_write_delimiter( &tmp, obj, delimiter );
|
||||||
sw fsize;
|
|
||||||
|
ssize fsize;
|
||||||
u8* buf = file_stream_buf( &tmp, &fsize );
|
u8* buf = file_stream_buf( &tmp, &fsize );
|
||||||
String output = String::make_length( a, (char*)buf, fsize );
|
String output = String::make_length( a, ( char* )buf, fsize );
|
||||||
file_close( &tmp );
|
file_close( &tmp );
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
@ -1128,9 +1133,9 @@ String csv_write_string_delimiter( AllocatorInfo a, CSV_Object* obj, char delimi
|
|||||||
GEN_NS_END
|
GEN_NS_END
|
||||||
|
|
||||||
#ifdef __clang__
|
#ifdef __clang__
|
||||||
#pragma clang diagnostic pop
|
# pragma clang diagnostic pop
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
#pragma GCC diagnostic pop
|
# pragma GCC diagnostic pop
|
||||||
#endif
|
#endif
|
||||||
|
@ -3,22 +3,22 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#ifdef __clang__
|
#ifdef __clang__
|
||||||
#pragma clang diagnostic push
|
# pragma clang diagnostic push
|
||||||
#pragma clang diagnostic ignored "-Wunused-const-variable"
|
# pragma clang diagnostic ignored "-Wunused-const-variable"
|
||||||
#pragma clang diagnostic ignored "-Wunused-but-set-variable"
|
# pragma clang diagnostic ignored "-Wunused-but-set-variable"
|
||||||
#pragma clang diagnostic ignored "-Wswitch"
|
# pragma clang diagnostic ignored "-Wswitch"
|
||||||
#pragma clang diagnostic ignored "-Wunused-variable"
|
# pragma clang diagnostic ignored "-Wunused-variable"
|
||||||
#pragma clang diagnostic ignored "-Wunknown-pragmas"
|
# pragma clang diagnostic ignored "-Wunknown-pragmas"
|
||||||
#pragma clang diagnostic ignored "-Wvarargs"
|
# pragma clang diagnostic ignored "-Wvarargs"
|
||||||
#pragma clang diagnostic ignored "-Wunused-function"
|
# pragma clang diagnostic ignored "-Wunused-function"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
#pragma GCC diagnostic push
|
# pragma GCC diagnostic push
|
||||||
#pragma GCC diagnostic ignored "-Wunknown-pragmas"
|
# pragma GCC diagnostic ignored "-Wunknown-pragmas"
|
||||||
#pragma GCC diagnostic ignored "-Wcomment"
|
# pragma GCC diagnostic ignored "-Wcomment"
|
||||||
#pragma GCC diagnostic ignored "-Wswitch"
|
# pragma GCC diagnostic ignored "-Wswitch"
|
||||||
#pragma GCC diagnostic ignored "-Wunused-variable"
|
# pragma GCC diagnostic ignored "-Wunused-variable"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "gen.hpp"
|
#include "gen.hpp"
|
||||||
@ -92,7 +92,7 @@ struct ADT_Node
|
|||||||
|
|
||||||
/* properties */
|
/* properties */
|
||||||
ADT_Type type : 4;
|
ADT_Type type : 4;
|
||||||
u8 props : 4;
|
u8 props : 4;
|
||||||
#ifndef GEN_PARSER_DISABLE_ANALYSIS
|
#ifndef GEN_PARSER_DISABLE_ANALYSIS
|
||||||
u8 cfg_mode : 1;
|
u8 cfg_mode : 1;
|
||||||
u8 name_style : 2;
|
u8 name_style : 2;
|
||||||
@ -130,283 +130,283 @@ struct ADT_Node
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* ADT NODE LIMITS
|
/* ADT NODE LIMITS
|
||||||
* delimiter and assignment segment width is limited to 128 whitespace symbols each.
|
* delimiter and assignment segment width is limited to 128 whitespace symbols each.
|
||||||
* real number limits decimal position to 128 places.
|
* real number limits decimal position to 128 places.
|
||||||
* real number exponent is limited to 64 digits.
|
* real number exponent is limited to 64 digits.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Initialise an ADT object or array
|
* @brief Initialise an ADT object or array
|
||||||
*
|
*
|
||||||
* @param node
|
* @param node
|
||||||
* @param backing Memory allocator used for descendants
|
* @param backing Memory allocator used for descendants
|
||||||
* @param name Node's name
|
* @param name Node's name
|
||||||
* @param is_array
|
* @param is_array
|
||||||
* @return error code
|
* @return error code
|
||||||
*/
|
*/
|
||||||
u8 adt_make_branch( ADT_Node* node, AllocatorInfo backing, char const* name, b32 is_array );
|
u8 adt_make_branch( ADT_Node* node, AllocatorInfo backing, char const* name, b32 is_array );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Destroy an ADT branch and its descendants
|
* @brief Destroy an ADT branch and its descendants
|
||||||
*
|
*
|
||||||
* @param node
|
* @param node
|
||||||
* @return error code
|
* @return error code
|
||||||
*/
|
*/
|
||||||
u8 adt_destroy_branch( ADT_Node* node );
|
u8 adt_destroy_branch( ADT_Node* node );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Initialise an ADT leaf
|
* @brief Initialise an ADT leaf
|
||||||
*
|
*
|
||||||
* @param node
|
* @param node
|
||||||
* @param name Node's name
|
* @param name Node's name
|
||||||
* @param type Node's type (use zpl_adt_make_branch for container nodes)
|
* @param type Node's type (use zpl_adt_make_branch for container nodes)
|
||||||
* @return error code
|
* @return error code
|
||||||
*/
|
*/
|
||||||
u8 adt_make_leaf( ADT_Node* node, char const* name, ADT_Type type );
|
u8 adt_make_leaf( ADT_Node* node, char const* name, ADT_Type type );
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Fetch a node using provided URI string.
|
* @brief Fetch a node using provided URI string.
|
||||||
*
|
*
|
||||||
* This method uses a basic syntax to fetch a node from the ADT. The following features are available
|
* This method uses a basic syntax to fetch a node from the ADT. The following features are available
|
||||||
* to retrieve the data:
|
* to retrieve the data:
|
||||||
*
|
*
|
||||||
* - "a/b/c" navigates through objects "a" and "b" to get to "c"
|
* - "a/b/c" navigates through objects "a" and "b" to get to "c"
|
||||||
* - "arr/[foo=123]/bar" iterates over "arr" to find any object with param "foo" that matches the value "123", then gets its field called "bar"
|
* - "arr/[foo=123]/bar" iterates over "arr" to find any object with param "foo" that matches the value "123", then gets its field called "bar"
|
||||||
* - "arr/3" retrieves the 4th element in "arr"
|
* - "arr/3" retrieves the 4th element in "arr"
|
||||||
* - "arr/[apple]" retrieves the first element of value "apple" in "arr"
|
* - "arr/[apple]" retrieves the first element of value "apple" in "arr"
|
||||||
*
|
*
|
||||||
* @param node ADT node
|
* @param node ADT node
|
||||||
* @param uri Locator string as described above
|
* @param uri Locator string as described above
|
||||||
* @return zpl_adt_node*
|
* @return zpl_adt_node*
|
||||||
*
|
*
|
||||||
* @see code/apps/examples/json_get.c
|
* @see code/apps/examples/json_get.c
|
||||||
*/
|
*/
|
||||||
ADT_Node* adt_query( ADT_Node* node, char const* uri );
|
ADT_Node* adt_query( ADT_Node* node, char const* uri );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Find a field node within an object by the given name.
|
* @brief Find a field node within an object by the given name.
|
||||||
*
|
*
|
||||||
* @param node
|
* @param node
|
||||||
* @param name
|
* @param name
|
||||||
* @param deep_search Perform search recursively
|
* @param deep_search Perform search recursively
|
||||||
* @return zpl_adt_node * node
|
* @return zpl_adt_node * node
|
||||||
*/
|
*/
|
||||||
ADT_Node* adt_find( ADT_Node* node, char const* name, b32 deep_search );
|
ADT_Node* adt_find( ADT_Node* node, char const* name, b32 deep_search );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Allocate an unitialised node within a container at a specified index.
|
* @brief Allocate an unitialised node within a container at a specified index.
|
||||||
*
|
*
|
||||||
* @param parent
|
* @param parent
|
||||||
* @param index
|
* @param index
|
||||||
* @return zpl_adt_node * node
|
* @return zpl_adt_node * node
|
||||||
*/
|
*/
|
||||||
ADT_Node* adt_alloc_at( ADT_Node* parent, sw index );
|
ADT_Node* adt_alloc_at( ADT_Node* parent, ssize index );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Allocate an unitialised node within a container.
|
* @brief Allocate an unitialised node within a container.
|
||||||
*
|
*
|
||||||
* @param parent
|
* @param parent
|
||||||
* @return zpl_adt_node * node
|
* @return zpl_adt_node * node
|
||||||
*/
|
*/
|
||||||
ADT_Node* adt_alloc( ADT_Node* parent );
|
ADT_Node* adt_alloc( ADT_Node* parent );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Move an existing node to a new container at a specified index.
|
* @brief Move an existing node to a new container at a specified index.
|
||||||
*
|
*
|
||||||
* @param node
|
* @param node
|
||||||
* @param new_parent
|
* @param new_parent
|
||||||
* @param index
|
* @param index
|
||||||
* @return zpl_adt_node * node
|
* @return zpl_adt_node * node
|
||||||
*/
|
*/
|
||||||
ADT_Node* adt_move_node_at( ADT_Node* node, ADT_Node* new_parent, sw index );
|
ADT_Node* adt_move_node_at( ADT_Node* node, ADT_Node* new_parent, ssize index );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Move an existing node to a new container.
|
* @brief Move an existing node to a new container.
|
||||||
*
|
*
|
||||||
* @param node
|
* @param node
|
||||||
* @param new_parent
|
* @param new_parent
|
||||||
* @return zpl_adt_node * node
|
* @return zpl_adt_node * node
|
||||||
*/
|
*/
|
||||||
ADT_Node* adt_move_node( ADT_Node* node, ADT_Node* new_parent );
|
ADT_Node* adt_move_node( ADT_Node* node, ADT_Node* new_parent );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Swap two nodes.
|
* @brief Swap two nodes.
|
||||||
*
|
*
|
||||||
* @param node
|
* @param node
|
||||||
* @param other_node
|
* @param other_node
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
void adt_swap_nodes( ADT_Node* node, ADT_Node* other_node );
|
void adt_swap_nodes( ADT_Node* node, ADT_Node* other_node );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Remove node from container.
|
* @brief Remove node from container.
|
||||||
*
|
*
|
||||||
* @param node
|
* @param node
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
void adt_remove_node( ADT_Node* node );
|
void adt_remove_node( ADT_Node* node );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Initialise a node as an object
|
* @brief Initialise a node as an object
|
||||||
*
|
*
|
||||||
* @param obj
|
* @param obj
|
||||||
* @param name
|
* @param name
|
||||||
* @param backing
|
* @param backing
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
b8 adt_set_obj( ADT_Node* obj, char const* name, AllocatorInfo backing );
|
b8 adt_set_obj( ADT_Node* obj, char const* name, AllocatorInfo backing );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Initialise a node as an array
|
* @brief Initialise a node as an array
|
||||||
*
|
*
|
||||||
* @param obj
|
* @param obj
|
||||||
* @param name
|
* @param name
|
||||||
* @param backing
|
* @param backing
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
b8 adt_set_arr( ADT_Node* obj, char const* name, AllocatorInfo backing );
|
b8 adt_set_arr( ADT_Node* obj, char const* name, AllocatorInfo backing );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Initialise a node as a string
|
* @brief Initialise a node as a string
|
||||||
*
|
*
|
||||||
* @param obj
|
* @param obj
|
||||||
* @param name
|
* @param name
|
||||||
* @param value
|
* @param value
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
b8 adt_set_str( ADT_Node* obj, char const* name, char const* value );
|
b8 adt_set_str( ADT_Node* obj, char const* name, char const* value );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Initialise a node as a float
|
* @brief Initialise a node as a float
|
||||||
*
|
*
|
||||||
* @param obj
|
* @param obj
|
||||||
* @param name
|
* @param name
|
||||||
* @param value
|
* @param value
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
b8 adt_set_flt( ADT_Node* obj, char const* name, f64 value );
|
b8 adt_set_flt( ADT_Node* obj, char const* name, f64 value );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Initialise a node as a signed integer
|
* @brief Initialise a node as a signed integer
|
||||||
*
|
*
|
||||||
* @param obj
|
* @param obj
|
||||||
* @param name
|
* @param name
|
||||||
* @param value
|
* @param value
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
b8 adt_set_int( ADT_Node* obj, char const* name, s64 value );
|
b8 adt_set_int( ADT_Node* obj, char const* name, s64 value );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Append a new node to a container as an object
|
* @brief Append a new node to a container as an object
|
||||||
*
|
*
|
||||||
* @param parent
|
* @param parent
|
||||||
* @param name
|
* @param name
|
||||||
* @return*
|
* @return*
|
||||||
*/
|
*/
|
||||||
ADT_Node* adt_append_obj( ADT_Node* parent, char const* name );
|
ADT_Node* adt_append_obj( ADT_Node* parent, char const* name );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Append a new node to a container as an array
|
* @brief Append a new node to a container as an array
|
||||||
*
|
*
|
||||||
* @param parent
|
* @param parent
|
||||||
* @param name
|
* @param name
|
||||||
* @return*
|
* @return*
|
||||||
*/
|
*/
|
||||||
ADT_Node* adt_append_arr( ADT_Node* parent, char const* name );
|
ADT_Node* adt_append_arr( ADT_Node* parent, char const* name );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Append a new node to a container as a string
|
* @brief Append a new node to a container as a string
|
||||||
*
|
*
|
||||||
* @param parent
|
* @param parent
|
||||||
* @param name
|
* @param name
|
||||||
* @param value
|
* @param value
|
||||||
* @return*
|
* @return*
|
||||||
*/
|
*/
|
||||||
ADT_Node* adt_append_str( ADT_Node* parent, char const* name, char const* value );
|
ADT_Node* adt_append_str( ADT_Node* parent, char const* name, char const* value );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Append a new node to a container as a float
|
* @brief Append a new node to a container as a float
|
||||||
*
|
*
|
||||||
* @param parent
|
* @param parent
|
||||||
* @param name
|
* @param name
|
||||||
* @param value
|
* @param value
|
||||||
* @return*
|
* @return*
|
||||||
*/
|
*/
|
||||||
ADT_Node* adt_append_flt( ADT_Node* parent, char const* name, f64 value );
|
ADT_Node* adt_append_flt( ADT_Node* parent, char const* name, f64 value );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Append a new node to a container as a signed integer
|
* @brief Append a new node to a container as a signed integer
|
||||||
*
|
*
|
||||||
* @param parent
|
* @param parent
|
||||||
* @param name
|
* @param name
|
||||||
* @param value
|
* @param value
|
||||||
* @return*
|
* @return*
|
||||||
*/
|
*/
|
||||||
ADT_Node* adt_append_int( ADT_Node* parent, char const* name, s64 value );
|
ADT_Node* adt_append_int( ADT_Node* parent, char const* name, s64 value );
|
||||||
|
|
||||||
/* parser helpers */
|
/* parser helpers */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Parses a text and stores the result into an unitialised node.
|
* @brief Parses a text and stores the result into an unitialised node.
|
||||||
*
|
*
|
||||||
* @param node
|
* @param node
|
||||||
* @param base
|
* @param base
|
||||||
* @return*
|
* @return*
|
||||||
*/
|
*/
|
||||||
char* adt_parse_number( ADT_Node* node, char* base );
|
char* adt_parse_number( ADT_Node* node, char* base );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Parses a text and stores the result into an unitialised node.
|
* @brief Parses a text and stores the result into an unitialised node.
|
||||||
* This function expects the entire input to be a number.
|
* This function expects the entire input to be a number.
|
||||||
*
|
*
|
||||||
* @param node
|
* @param node
|
||||||
* @param base
|
* @param base
|
||||||
* @return*
|
* @return*
|
||||||
*/
|
*/
|
||||||
char* adt_parse_number_strict( ADT_Node* node, char* base_str );
|
char* adt_parse_number_strict( ADT_Node* node, char* base_str );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Parses and converts an existing string node into a number.
|
* @brief Parses and converts an existing string node into a number.
|
||||||
*
|
*
|
||||||
* @param node
|
* @param node
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
ADT_Error adt_str_to_number( ADT_Node* node );
|
ADT_Error adt_str_to_number( ADT_Node* node );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Parses and converts an existing string node into a number.
|
* @brief Parses and converts an existing string node into a number.
|
||||||
* This function expects the entire input to be a number.
|
* This function expects the entire input to be a number.
|
||||||
*
|
*
|
||||||
* @param node
|
* @param node
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
ADT_Error adt_str_to_number_strict( ADT_Node* node );
|
ADT_Error adt_str_to_number_strict( ADT_Node* node );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Prints a number into a file stream.
|
* @brief Prints a number into a file stream.
|
||||||
*
|
*
|
||||||
* The provided file handle can also be a memory mapped stream.
|
* The provided file handle can also be a memory mapped stream.
|
||||||
*
|
*
|
||||||
* @see zpl_file_stream_new
|
* @see zpl_file_stream_new
|
||||||
* @param file
|
* @param file
|
||||||
* @param node
|
* @param node
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
ADT_Error adt_print_number( FileInfo* file, ADT_Node* node );
|
ADT_Error adt_print_number( FileInfo* file, ADT_Node* node );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Prints a string into a file stream.
|
* @brief Prints a string into a file stream.
|
||||||
*
|
*
|
||||||
* The provided file handle can also be a memory mapped stream.
|
* The provided file handle can also be a memory mapped stream.
|
||||||
*
|
*
|
||||||
* @see zpl_file_stream_new
|
* @see zpl_file_stream_new
|
||||||
* @param file
|
* @param file
|
||||||
* @param node
|
* @param node
|
||||||
* @param escaped_chars
|
* @param escaped_chars
|
||||||
* @param escape_symbol
|
* @param escape_symbol
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
ADT_Error adt_print_string( FileInfo* file, ADT_Node* node, char const* escaped_chars, char const* escape_symbol );
|
ADT_Error adt_print_string( FileInfo* file, ADT_Node* node, char const* escaped_chars, char const* escape_symbol );
|
||||||
|
|
||||||
#pragma endregion ADT
|
#pragma endregion ADT
|
||||||
@ -423,28 +423,31 @@ enum CSV_Error : u32
|
|||||||
|
|
||||||
typedef ADT_Node CSV_Object;
|
typedef ADT_Node CSV_Object;
|
||||||
|
|
||||||
GEN_DEF_INLINE u8 csv_parse( CSV_Object* root, char* text, AllocatorInfo allocator, b32 has_header );
|
u8 csv_parse( CSV_Object* root, char* text, AllocatorInfo allocator, b32 has_header );
|
||||||
u8 csv_parse_delimiter( CSV_Object* root, char* text, AllocatorInfo allocator, b32 has_header, char delim );
|
u8 csv_parse_delimiter( CSV_Object* root, char* text, AllocatorInfo allocator, b32 has_header, char delim );
|
||||||
void csv_free( CSV_Object* obj );
|
void csv_free( CSV_Object* obj );
|
||||||
|
|
||||||
GEN_DEF_INLINE void csv_write( FileInfo* file, CSV_Object* obj );
|
void csv_write( FileInfo* file, CSV_Object* obj );
|
||||||
GEN_DEF_INLINE String csv_write_string( AllocatorInfo a, CSV_Object* obj );
|
String csv_write_string( AllocatorInfo a, CSV_Object* obj );
|
||||||
void csv_write_delimiter( FileInfo* file, CSV_Object* obj, char delim );
|
void csv_write_delimiter( FileInfo* file, CSV_Object* obj, char delim );
|
||||||
String csv_write_string_delimiter( AllocatorInfo a, CSV_Object* obj, char delim );
|
String csv_write_string_delimiter( AllocatorInfo a, CSV_Object* obj, char delim );
|
||||||
|
|
||||||
/* inline */
|
/* inline */
|
||||||
|
|
||||||
GEN_IMPL_INLINE u8 csv_parse( CSV_Object* root, char* text, AllocatorInfo allocator, b32 has_header )
|
inline
|
||||||
|
u8 csv_parse( CSV_Object* root, char* text, AllocatorInfo allocator, b32 has_header )
|
||||||
{
|
{
|
||||||
return csv_parse_delimiter( root, text, allocator, has_header, ',' );
|
return csv_parse_delimiter( root, text, allocator, has_header, ',' );
|
||||||
}
|
}
|
||||||
|
|
||||||
GEN_IMPL_INLINE void csv_write( FileInfo* file, CSV_Object* obj )
|
inline
|
||||||
|
void csv_write( FileInfo* file, CSV_Object* obj )
|
||||||
{
|
{
|
||||||
csv_write_delimiter( file, obj, ',' );
|
csv_write_delimiter( file, obj, ',' );
|
||||||
}
|
}
|
||||||
|
|
||||||
GEN_IMPL_INLINE String csv_write_string( AllocatorInfo a, CSV_Object* obj )
|
inline
|
||||||
|
String csv_write_string( AllocatorInfo a, CSV_Object* obj )
|
||||||
{
|
{
|
||||||
return csv_write_string_delimiter( a, obj, ',' );
|
return csv_write_string_delimiter( a, obj, ',' );
|
||||||
}
|
}
|
||||||
@ -454,41 +457,37 @@ GEN_IMPL_INLINE String csv_write_string( AllocatorInfo a, CSV_Object* obj )
|
|||||||
// This is a simple file reader that reads the entire file into memory.
|
// This is a simple file reader that reads the entire file into memory.
|
||||||
// It has an extra option to skip the first few lines for undesired includes.
|
// It has an extra option to skip the first few lines for undesired includes.
|
||||||
// This is done so that includes can be kept in dependency and component files so that intellisense works.
|
// This is done so that includes can be kept in dependency and component files so that intellisense works.
|
||||||
inline Code scan_file( char const* path )
|
inline
|
||||||
|
Code scan_file( char const* path )
|
||||||
{
|
{
|
||||||
FileInfo file;
|
FileInfo file;
|
||||||
|
|
||||||
FileError error = file_open_mode( &file, EFileMode_READ, path );
|
FileError error = file_open_mode( & file, EFileMode_READ, path );
|
||||||
if ( error != EFileError_NONE )
|
if ( error != EFileError_NONE )
|
||||||
{
|
{
|
||||||
GEN_FATAL( "scan_file: Could not open: %s", path );
|
GEN_FATAL( "scan_file: Could not open: %s", path );
|
||||||
}
|
}
|
||||||
|
|
||||||
sw fsize = file_size( &file );
|
ssize fsize = file_size( & file );
|
||||||
if ( fsize <= 0 )
|
if ( fsize <= 0 )
|
||||||
{
|
{
|
||||||
GEN_FATAL( "scan_file: %s is empty", path );
|
GEN_FATAL("scan_file: %s is empty", path );
|
||||||
}
|
}
|
||||||
|
|
||||||
String str = String::make_reserve( GlobalAllocator, fsize );
|
String str = String::make_reserve( GlobalAllocator, fsize );
|
||||||
file_read( &file, str, fsize );
|
file_read( & file, str, fsize );
|
||||||
str.get_header().Length = fsize;
|
str.get_header().Length = fsize;
|
||||||
|
|
||||||
// Skip GEN_INTELLISENSE_DIRECTIVES preprocessor blocks
|
// Skip GEN_INTELLISENSE_DIRECTIVES preprocessor blocks
|
||||||
// Its designed so that the directive should be the first thing in the file.
|
// Its designed so that the directive should be the first thing in the file.
|
||||||
// Anything that comes before it will also be omitted.
|
// Anything that comes before it will also be omitted.
|
||||||
{
|
{
|
||||||
#define current ( *scanner )
|
#define current (*scanner)
|
||||||
#define matched 0
|
#define matched 0
|
||||||
#define move_fwd() \
|
#define move_fwd() do { ++ scanner; -- left; } while (0)
|
||||||
do \
|
const StrC directive_start = txt( "ifdef" );
|
||||||
{ \
|
const StrC directive_end = txt( "endif" );
|
||||||
++scanner; \
|
const StrC def_intellisense = txt("GEN_INTELLISENSE_DIRECTIVES" );
|
||||||
--left; \
|
|
||||||
} while ( 0 )
|
|
||||||
const StrC directive_start = txt( "ifdef" );
|
|
||||||
const StrC directive_end = txt( "endif" );
|
|
||||||
const StrC def_intellisense = txt( "GEN_INTELLISENSE_DIRECTIVES" );
|
|
||||||
|
|
||||||
bool found_directive = false;
|
bool found_directive = false;
|
||||||
char const* scanner = str.Data;
|
char const* scanner = str.Data;
|
||||||
@ -514,10 +513,10 @@ inline Code scan_file( char const* path )
|
|||||||
|
|
||||||
if ( left && str_compare( scanner, def_intellisense.Ptr, def_intellisense.Len ) == matched )
|
if ( left && str_compare( scanner, def_intellisense.Ptr, def_intellisense.Len ) == matched )
|
||||||
{
|
{
|
||||||
scanner += def_intellisense.Len;
|
scanner += def_intellisense.Len;
|
||||||
left -= def_intellisense.Len;
|
left -= def_intellisense.Len;
|
||||||
|
|
||||||
found_directive = true;
|
found_directive = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -546,7 +545,7 @@ inline Code scan_file( char const* path )
|
|||||||
move_fwd();
|
move_fwd();
|
||||||
|
|
||||||
// sptr skip_size = fsize - left;
|
// sptr skip_size = fsize - left;
|
||||||
if ( ( scanner + 2 ) >= ( str.Data + fsize ) )
|
if ( (scanner + 2) >= ( str.Data + fsize ) )
|
||||||
{
|
{
|
||||||
mem_move( str, scanner, left );
|
mem_move( str, scanner, left );
|
||||||
str.get_header().Length = left;
|
str.get_header().Length = left;
|
||||||
@ -558,16 +557,17 @@ inline Code scan_file( char const* path )
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
move_fwd();
|
move_fwd();
|
||||||
}
|
}
|
||||||
#undef move_fwd
|
#undef move_fwd
|
||||||
#undef matched
|
#undef matched
|
||||||
#undef current
|
#undef current
|
||||||
}
|
}
|
||||||
|
|
||||||
file_close( &file );
|
file_close( & file );
|
||||||
return untyped_str( str );
|
return untyped_str( str );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -612,9 +612,9 @@ CodeFile scan_file( char const* path )
|
|||||||
GEN_NS_END
|
GEN_NS_END
|
||||||
|
|
||||||
#ifdef __clang__
|
#ifdef __clang__
|
||||||
#pragma clang diagnostic pop
|
# pragma clang diagnostic pop
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
#pragma GCC diagnostic pop
|
# pragma GCC diagnostic pop
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user