Got it to compile (without Incremental, parsing, editor, scanner)

This commit is contained in:
Edward R. Gonzalez 2023-05-07 15:03:24 -04:00
parent 74c5736f59
commit 00b4220333
6 changed files with 203 additions and 253 deletions

View File

@ -80,10 +80,10 @@ using zpl::pool_init;
using zpl::pool_free;
using zpl::process_exit;
using zpl::str_copy;
using zpl::str_fmt_va;
using zpl::str_fmt_out_va;
using zpl::str_fmt_out_err_va;
using zpl::str_compare;
using zpl::str_fmt_va;
using zpl::string_appendc;
using zpl::string_append_fmt;
using zpl::string_append_length;
@ -104,6 +104,7 @@ using zpl::str_len;
# pragma clang diagnostic ignored "-Wunused-variable"
# pragma clang diagnostic ignored "-Wunknown-pragmas"
# pragma clang diagnostic ignored "-Wvarargs"
# pragma clang diagnostic ignored "-Wunused-function"
#endif
@ -264,14 +265,12 @@ char const* Msg_Invalid_Value = "INVALID VALUE PROVIDED";
if ( ! str )
mem_set( allocation, 0, alloc_size );
Header
header = { allocator, length, length };
Header header = { allocator, length, length };
String result = { rcast( char*, allocation) + header_size };
if ( length && str )
mem_copy( allocation + header_size, str, length );
mem_copy( result, str, length );
String
result = { rcast( char*, allocation + header_size) };
result[ length ] = '\0';
return result;
@ -327,8 +326,45 @@ char const* Msg_Invalid_Value = "INVALID VALUE PROVIDED";
return true;
}
bool make_space_for( char const* str, sw add_len )
{
sw available = avail_space();
// NOTE: Return if there is enough space left
if ( available >= add_len )
{
return false;
}
else
{
sw new_len, old_size, new_size;
void* ptr;
void* new_ptr;
AllocatorInfo allocator = get_header().Allocator;
Header* header = nullptr;
new_len = length() + add_len;
ptr = & get_header();
old_size = size_of( Header ) + length() + 1;
new_size = size_of( Header ) + new_len + 1;
new_ptr = resize( allocator, ptr, old_size, new_size );
if ( new_ptr == nullptr )
return false;
header = zpl_cast( Header* ) new_ptr;
header->Allocator = allocator;
header->Capacity = new_len;
Data = rcast( char*, header + 1 );
return str;
}
}
bool make_space_for( char const* str, sw add_len );
bool append( char const* str )
{
@ -339,7 +375,7 @@ char const* Msg_Invalid_Value = "INVALID VALUE PROVIDED";
{
Header& header = get_header();
if ( str > 0 )
if ( sptr(str) > 0 )
{
sw curr_len = header.Length;
@ -428,60 +464,12 @@ char const* Msg_Invalid_Value = "INVALID VALUE PROVIDED";
return header.Length;
}
bool make_space_for( char const* str, sw add_len )
{
sw available = avail_space();
// NOTE: Return if there is enough space left
if ( available >= add_len )
{
return false;
}
else
{
sw new_len, old_size, new_size;
void* ptr;
void* new_ptr;
AllocatorInfo allocator = get_header().Allocator;
Header* header = nullptr;
new_len = length() + add_len;
ptr = & get_header();
old_size = size_of( Header ) + length() + 1;
new_size = size_of( Header ) + new_len + 1;
new_ptr = resize( allocator, ptr, old_size, new_size );
if ( new_ptr == nullptr )
return false;
header = zpl_cast( Header* ) new_ptr;
header->Allocator = allocator;
header->Capacity = new_len;
Data = rcast( char*, header + 1 );
return str;
}
}
void trim( char const* cut_set )
{
char* start;
char* end;
char* start_pos;
char* end_pos;
sw len = 0;
start_pos = Data;
start = Data;
end_pos = Data + length() - 1;
end = Data + length() - 1;
char* start_pos = Data;
char* end_pos = Data + length() - 1;
while ( start_pos <= end_pos && char_first_occurence( cut_set, *start_pos ) )
start_pos++;
@ -606,7 +594,7 @@ sw fatal(char const* fmt, ...)
#if Build_Debug
va_start(va, fmt);
zpl::snprintf_va(buf, ZPL_PRINTF_MAXLEN, fmt, va);
str_fmt_va(buf, ZPL_PRINTF_MAXLEN, fmt, va);
va_end(va);
assert_crash(buf);

View File

@ -28,10 +28,10 @@ namespace gen
#pragma region Constants
#ifdef GEN_DEFINE_LIBRARY_CODE_CONSTANTS
Code type_ns(void);
Code type_ns(int);
Code type_ns(bool);
Code type_ns(char);
Code type_ns(char_wide);
Code type_ns(wchar_t);
Code type_ns(s8);
Code type_ns(s16);
@ -421,7 +421,8 @@ namespace gen
switch ( Type )
{
case Invalid:
break;
log_failure( "AST::duplicate: Cannot duplicate an invalid AST." );
return nullptr;
case Untyped:
case Comment:
@ -484,6 +485,9 @@ namespace gen
}
return result;
}
log_failure( "AST::duplicate: Unknown AST type %s.", type_str() );
return nullptr;
}
String AST::to_string()
@ -606,6 +610,7 @@ namespace gen
break;
case Enum:
{
result.append( indent );
ProcessModuleFlags();
@ -640,6 +645,7 @@ namespace gen
, body()->to_string()
, indent_str
);
}
break;
case Enum_Fwd:
@ -651,6 +657,7 @@ namespace gen
break;
case Enum_Class:
{
result.append( indent );
ProcessModuleFlags();
@ -685,9 +692,11 @@ namespace gen
, body()->to_string()
, indent_str
);
}
break;
case Enum_Class_Fwd:
{
result.append( indent );
ProcessModuleFlags();
@ -703,6 +712,7 @@ namespace gen
}
result.append_fmt( ": %s;\n", Name, Entries[idx]->to_string() );
}
break;
case Execution:
@ -900,7 +910,7 @@ namespace gen
ProcessModuleFlags();
s32 idx;
s32 idx = 0;
if ( Entries[idx]->Type == Specifiers )
{
@ -1022,6 +1032,7 @@ namespace gen
break;
case Typedef:
{
result.append( indent );
ProcessModuleFlags();
@ -1043,6 +1054,7 @@ namespace gen
{
result.append( ";" );
}
}
break;
case Typename:
@ -1057,6 +1069,7 @@ namespace gen
break;
case Union:
{
result.append( indent );
ProcessModuleFlags();
@ -1077,9 +1090,11 @@ namespace gen
, body()->to_string()
, indent_str
);
}
break;
case Using:
{
result.append( indent );
ProcessModuleFlags();
@ -1103,6 +1118,7 @@ namespace gen
result.append_fmt( "using %s", Name );
result.append( ";" );
}
break;
case Using_Namespace:
@ -1195,16 +1211,17 @@ namespace gen
#ifdef GEN_DEFINE_LIBRARY_CODE_CONSTANTS
Code&
t_bool_write = ccast( Code, t_void );
t_bool_write = def_type( name(void) );
t_void_write = ccast( Code, t_void );
t_void_write = def_type( name(void) );
t_void_write->Readonly = true;
# define def_constant_code_type( Type_ ) \
Code& \
t_##Type_ = def_type( name(Type_) ); \
t_##Type_->Readonly = true;
# define def_constant_code_type( Type_ ) \
Code& \
t_##Type_##write = ccast( Code, type_ns(Type_) ); \
t_##Type_##write = def_type( name(Type_) ); \
t_##Type_##write->Readonly = true;
def_constant_code_type( int );
def_constant_code_type( bool );
def_constant_code_type( char );
def_constant_code_type( wchar_t );
@ -1231,10 +1248,11 @@ namespace gen
spec_constexpr_write = ccast( Code, spec_constexpr );
spec_constexpr_write = def_specifiers( 1, ESpecifier::Constexpr );
# define def_constant_spec( Type_, ... ) \
Code& \
spec_##Type_ = def_specifiers( macro_num_args(__VA_ARGS__), __VA_ARGS__); \
spec_##Type_.lock();
# define def_constant_spec( Type_, ... ) \
Code& \
spec_##Type_##write = ccast( Code, spec_##Type_); \
spec_##Type_##write = def_specifiers( macro_num_args(__VA_ARGS__), __VA_ARGS__); \
spec_##Type_##write.lock()
def_constant_spec( const, ESpecifier::Const );
def_constant_spec( inline, ESpecifier::Inline );
@ -1855,7 +1873,7 @@ namespace gen
return Code::Invalid;
}
if ( parent && parent->Type != Class || parent->Type != Struct || parent->Type != Typename || parent->Type != Untyped )
if ( parent && (parent->Type != Class || parent->Type != Struct || parent->Type != Typename || parent->Type != Untyped) )
{
log_failure( "gen::def_class: parent provided is not type 'Class', 'Struct', 'Typeanme', or 'Untyped': %s", parent->debug_str() );
return Code::Invalid;

View File

@ -16,10 +16,10 @@
// #define GEN_DONT_USE_FATAL
#define GEN_ENFORCE_READONLY_AST
#define GEN_FEATURE_INCREMENTAL
#define GEN_FEATURE_PARSING
#define GEN_FEATURE_EDITOR
#define GEN_FEATURE_SCANNER
// #define GEN_FEATURE_INCREMENTAL
// #define GEN_FEATURE_PARSING
// #define GEN_FEATURE_EDITOR
// #define GEN_FEATURE_SCANNER
#ifdef gen_time
@ -188,9 +188,6 @@ namespace gen
inline
char const* to_str( Type op )
{
using something = u8;
typedef u8 another;
local_persist
char const* lookup[ Num_Ops ] = {
# define Entry( Type_, Token_ ) txt(Token_),
@ -312,7 +309,7 @@ namespace gen
};
if ( type > AccessSpec::Public )
return lookup[ (u32)AccessSpec::Invalid ];
return "Invalid";
return lookup[ (u32)type ];
}
@ -482,12 +479,14 @@ namespace gen
bool typename_is_ptr()
{
assert_crash("not implemented");
return false;
}
inline
bool typename_is_ref()
{
assert_crash("not implemented");
return false;
}
inline
@ -572,7 +571,7 @@ namespace gen
struct CodePOD
{
Using_Code_POD
# undef Using_CodePOD;
# undef Using_CodePOD
};
constexpr sw size_AST = sizeof(AST);
@ -667,6 +666,8 @@ namespace gen
return ast;
}
// Cannot be done unfortunately c++ sucks. (Will lose POD by doing so)
#if 0
inline
Code& operator=( Code other )
{
@ -688,6 +689,7 @@ namespace gen
return *this;
}
#endif
inline
AST* operator->()
@ -823,6 +825,7 @@ namespace gen
, ModuleFlag mflags = ModuleFlag::None );
Code def_class_body ( s32 num, ... );
Code def_class_body ( s32 num, Code* codes );
Code def_enum_body ( s32 num, ... );
Code def_enum_body ( s32 num, Code* codes );
Code def_export_body ( s32 num, ... );

View File

@ -7,7 +7,7 @@ foreach ( $arg in $args )
{
$test = $true
}
else
else
{
$type = $arg
}
@ -19,47 +19,6 @@ $path_build = Join-Path $path_root build
$path_scripts = Join-Path $path_root scripts
if ($false)
{
#region Regular Build
write-host "Building project`n"
if ( -not( Test-Path $path_build ) )
{
$args_meson = @()
$args_meson += "setup"
$args_meson += $path_build
# Start-Process meson $args_meson -NoNewWindow -Wait -WorkingDirectory $path_scripts
Push-Location $path_scripts
Invoke-Expression "& meson $args_meson"
Pop-Location
}
if ( $type )
{
$args_meson = @()
$args_meson += "configure"
$args_meson += $path_build
$args_meson += "--buildtype $($type)"
# Start-Process meson $args_meson -NoNewWindow -Wait -WorkingDirectory $path_scripts
Push-Location $path_scripts
Invoke-Expression "& meson $args_meson"
Pop-Location
}
$args_ninja = @()
$args_ninja += "-C"
$args_ninja += $path_build
Push-Location $path_root
ninja $args_ninja
Pop-Location
#endregion Regular Build
}
# if ( $test -eq $true )
# {
#region Test Build
@ -81,7 +40,7 @@ Pop-Location
& meson $args_meson
Pop-Location
}
$args_ninja = @()
$args_ninja += "-C"
$args_ninja += $path_gen_build
@ -98,29 +57,29 @@ Pop-Location
# Build the program depending on generated files.
if ( -not( Test-Path $path_test_build ) )
{
$args_meson = @()
$args_meson += "setup"
$args_meson += $path_test_build
# if ( -not( Test-Path $path_test_build ) )
# {
# $args_meson = @()
# $args_meson += "setup"
# $args_meson += $path_test_build
Push-Location $path_test
& meson $args_meson
Pop-Location
}
# Push-Location $path_test
# & meson $args_meson
# Pop-Location
# }
$args_ninja = @()
$args_ninja += "-C"
$args_ninja += $path_test_build
# $args_ninja = @()
# $args_ninja += "-C"
# $args_ninja += $path_test_build
Push-Location $path_root
ninja $args_ninja
Pop-Location
# Push-Location $path_root
# ninja $args_ninja
# Pop-Location
$testcpp = Join-Path $path_test_build testcpp.exe
# $testcpp = Join-Path $path_test_build testcpp.exe
Push-Location $path_test
& $testcpp
Pop-Location
# Push-Location $path_test
# & $testcpp
# Pop-Location
# endregion Test Build
# }

View File

@ -1,19 +0,0 @@
project( 'refactor', 'c', 'cpp', default_options : ['buildtype=release'] )
# add_global_arguments('-E', language : 'cpp')
includes = include_directories(
[ '../project'
, '../thirdparty'
])
get_sources = files('./get_sources.ps1')
sources = files(run_command('powershell', get_sources, check: true).stdout().strip().split('\n'))
if get_option('buildtype').startswith('debug')
add_project_arguments('-DBuild_Debug', language : ['c', 'cpp'])
endif
executable( 'refactor', sources, include_directories : includes )

177
thirdparty/zpl.h vendored
View File

@ -34,8 +34,9 @@ GitHub:
https://github.com/zpl-c/zpl
Version History:
19.0.1 - Fixed zpl_array_fill ZPL_ASSERT off-by-one error
19.0.0 - Check all results of zpl_alloc() when using JSON parser/writer (rheatley-pervasid)
18.1.5 - set parent to parsed JSON nodes (fixed)
- fix zpl_json/csv_write_string off-by-one issue
18.1.4 - fix zpl_random_gen_isize/zpl_random_range_isize 32bit overflow
@ -51,13 +52,13 @@ Version History:
18.0.0 - removed coroutines module
- removed timer module
- rename zpl_adt_get -> zpl_adt_query
17.0.0 - ADT API changes
zpl_adt_inset_* -> zpl_adt_append_*
zpl_adt_node now holds a parent field, methods no longer require a pointer to the parent
methods are now documented
- add zpl_thread_init_nowait (gaopeng)
16.1.1 - fix scientific notation parsing
16.1.0 - introduce ZPL_PARSER_DISABLE_ANALYSIS that disables extra parsing capabilities to offer better raw performance
at a cost of lack of node metadata.
@ -69,7 +70,7 @@ Version History:
- fix memory leak when parsing a json array (gaopeng)
- add zpl_strntok (gaopeng)
- add zpl_semaphore_trywait (gaopeng)
15.0.3 - fix zpl_sign call in math failing to compile
on macos devices
15.0.2 - zpl_sign0 was introduced
@ -77,7 +78,7 @@ Version History:
- zpl_sign(0) returns 0
15.0.0 - Rework zpl ring buffer
- various code improvements
14.1.7 - fix zpl_random_range_i64
- set thread's is_running before we start a thread
14.1.6 - remove windows.h dependency for header part
@ -87,7 +88,7 @@ Version History:
14.1.0 - add hashtable map_mut method
14.0.1 - fix zpl_array_remove_at boundary bug
14.0.0 - heap memory allocator analysis
13.4.1 - adt optimizations
13.4.0 - new adt manipulation methods
13.3.3 - fix zpl_str_skip_literal bug
@ -102,7 +103,7 @@ Version History:
13.1.1 - fix emscripten support
13.1.0 - abstract data tree naming update
13.0.0 - text parsers refactor
12.8.0 - zpl_opts improvements
12.7.0 - math improvements
12.6.2 - remove register usage (BeastLe9enD)
@ -119,7 +120,7 @@ Version History:
12.1.0 - Add rectangle partitioning
12.0.1 - Optimize zpl_strlen
12.0.0 - JSON API revamp + improvements
11.3.0 - JSON zpl_json_str_to_flt + cleanup
11.2.5 - fix small atomics typo
11.2.4 - JSON rewrite core parser
@ -141,7 +142,7 @@ Version History:
11.0.0 - New jobs system
- Rewrite the timer module
- zpl_ring rework
10.13.0 - Initial ARM threading support
10.12.1 - Fix missing zpL_alloc_str
10.12.0 - Add zpl_crc64
@ -185,7 +186,7 @@ Version History:
10.0.4 - Flush tester output to fix ordering
10.0.3 - Fix ZPL_STATIC_ASSERT under MSVC
10.0.0 - Major overhaul of the library
9.8.10 - JSON fix array-based documents with objects
9.8.9 - JSON document structured as array now properly recognizes the root object as array.
9.8.8 - Fixed an incorrect parsing of empty array nodes.
@ -218,7 +219,7 @@ Version History:
9.1.0 - get_env rework and fixes
9.0.3 - Small fixes and removals
9.0.0 - New documentation format, removed deprecated code, changed styles
8.14.1 - Fix string library
8.14.0 - Added zpl_re_match_all
8.13.0 - Update system command API
@ -237,7 +238,7 @@ Version History:
8.10.0 - Added zpl_strchr
8.9.0 - API improvements for JSON5 parser
8.8.4 - Add support for SJSON formatting http://bitsquid.blogspot.com/2009/10/simplified-json-notation.html
6.8.3 - JSON5 exp fix
6.8.2 - Bugfixes applied from gb
6.8.1 - Performance improvements for JSON5 parser
@ -257,7 +258,7 @@ Version History:
6.0.2 - Fixed warnings for json5 i64 printfs
6.0.1 - Fixed warnings for particual win compiler in dirlist method
6.0.0 - New build, include/ was renamed to code/
5.8.3 - Naming fixes
5.8.2 - Job system now supports prioritized tasks
5.8.1 - Renames zpl_pad to zpl_ring
@ -285,7 +286,7 @@ Version History:
5.0.2 - Fix segfault when using zpl_stack_memory
5.0.1 - Small code improvements
5.0.0 - Project structure changes
4.7.2 - Got rid of size arg for zpl_str_split_lines
4.7.1 - Added an example
4.7.0 - Added zpl_path_dirlist
@ -310,7 +311,7 @@ Version History:
4.0.2 - Warning fix for _LARGEFILE64_SOURCE
4.0.1 - include stdlib.h for getenv (temp)
4.0.0 - ARM support, coding style changes and various improvements
3.4.1 - zpl_memcopy now uses memcpy for ARM arch-family
3.4.0 - Removed obsolete code
3.3.4 - Added Travis CI config
@ -331,7 +332,7 @@ Version History:
3.0.2 - Fixed linux part, and removed trailing spaces
3.0.1 - Small bugfix in zpl_file_open
3.0.0 - Added several fixes and features
2.4.0 - Added remove to hash table
2.3.3 - Removed redundant code
2.3.2 - Eliminated extra warnings
@ -344,7 +345,7 @@ Version History:
2.0.8 - Small adjustments
2.0.7 - MinGW related fixes
2.0.0 - New NPM based version
1.2.2 - Small fix
1.2.1 - Macro fixes
1.2.0 - Added zpl_async macro
@ -354,15 +355,15 @@ Version History:
License:
This Software is dual licensed under the following licenses:
Unlicense
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
@ -370,7 +371,7 @@ License:
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
@ -378,15 +379,15 @@ License:
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <http://unlicense.org/>
BSD 3-Clause
Copyright (c) 2016-2021 Dominik Madarász. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
@ -395,7 +396,7 @@ License:
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
@ -414,7 +415,7 @@ License:
# define ZPL_VERSION_MAJOR 19
# define ZPL_VERSION_MINOR 0
# define ZPL_VERSION_PATCH 0
# define ZPL_VERSION_PATCH 1
# define ZPL_VERSION_PRE ""
// file: zpl_hedley.h
@ -2044,7 +2045,7 @@ ZPL_DIAGNOSTIC_POP
namespace zpl \
{
# define ZPL_END_NAMESPACE }
# define ZPL_NS( Identifier ) zpl::##Identifier // Used in macros, properly exposes symbol anywhere
# define ZPL_NS( Identifier ) zpl::Identifier // Used in macros, properly exposes symbol anywhere
# else
# define ZPL_BEGIN_NAMESPACE
# define ZPL_END_NAMESPACE
@ -3885,15 +3886,15 @@ ZPL_IMPL_INLINE b8 _array_appendv_at( void** x, void* items, sw item_size, sw it
#define array_appendv_at( x, items, item_count, ind ) ZPL_NS( _array_appendv_at )( zpl_cast( void** ) & ( x ), ( items ), size_of( ( items )[ 0 ] ), ( item_count ), ( ind ) )
#define array_fill( x, begin, end, value ) \
do \
{ \
ZPL_ASSERT( ( begin ) >= 0 && ( end ) < array_count( x ) ); \
ZPL_ASSERT( size_of( value ) == size_of( ( x )[ 0 ] ) ); \
for ( ZPL_NS( sw ) i = ( begin ); i < ( end ); i++ ) \
{ \
x[ i ] = value; \
} \
#define array_fill( x, begin, end, value ) \
do \
{ \
ZPL_ASSERT( ( begin ) >= 0 && ( end ) <= array_count( x ) ); \
ZPL_ASSERT( size_of( value ) == size_of( ( x )[ 0 ] ) ); \
for ( ZPL_NS( sw ) i = ( begin ); i < ( end ); i++ ) \
{ \
x[ i ] = value; \
} \
} while ( 0 )
#define array_remove_at( x, index ) \
@ -4645,7 +4646,7 @@ ZPL_DEF_INLINE const char* str_tok( char* output, const char* src, const char* d
ZPL_DEF_INLINE const char* strntok( char* output, sw len, const char* src, const char* delimit );
ZPL_DEF_INLINE char* str_dup( AllocatorInfo a, char* src, sw max_len );
ZPL_DEF_INLINE char** str_split_lines( AllocatorInfo alloc, char* source, b32 strip_whitespace );
ZPL_DEF_INLINE char** str_split_lines( AllocatorInfo allocator, char* source, b32 strip_whitespace );
#define str_expand( str ) str, ZPL_NS( str_len )( str )
#define str_advance_while( str, cond ) \
@ -5126,10 +5127,10 @@ ZPL_IMPL_INLINE char* str_dup( AllocatorInfo a, char* src, sw max_len )
return dest;
}
ZPL_IMPL_INLINE char** str_split_lines( AllocatorInfo alloc, char* source, b32 strip_whitespace )
ZPL_IMPL_INLINE char** str_split_lines( AllocatorInfo allocator, char* source, b32 strip_whitespace )
{
char **lines = NULL, *p = source, *pd = p;
array_init( lines, alloc );
array_init( lines, allocator );
while ( *p )
{
@ -5601,7 +5602,7 @@ ZPL_DEF b32 file_write_contents( char const* filepath, void const* buffer, sw si
* @param strip_whitespace Strip whitespace when we split to lines?
* @return File content we've read itself
*/
ZPL_DEF char* file_read_lines( AllocatorInfo alloc, Array( char* ) * lines, char const* filename, b32 strip_whitespace );
ZPL_DEF char* file_read_lines( AllocatorInfo allocator, Array( char* ) * lines, char const* filename, b32 strip_whitespace );
//! @}
@ -5828,7 +5829,7 @@ ZPL_DEF char* path_get_full_name( AllocatorInfo a, char const* path );
* @param recurse [description]
* @return [description]
*/
ZPL_DEF /*zpl_string*/ char* path_dirlist( AllocatorInfo alloc, char const* dirname, b32 recurse );
ZPL_DEF /*zpl_string*/ char* path_dirlist( AllocatorInfo allocator, char const* dirname, b32 recurse );
/**
* Initialize dirinfo from specified path
@ -5966,7 +5967,7 @@ ZPL_DEF sw tar_pack( FileInfo* archive, char const** paths, sw paths_len );
* @param alloc memory allocator to use (ex. zpl_heap())
* @return error
*/
ZPL_DEF sw tar_pack_dir( FileInfo* archive, char const* path, AllocatorInfo alloc );
ZPL_DEF sw tar_pack_dir( FileInfo* archive, char const* path, AllocatorInfo allocator );
/**
* @brief Unpacks an existing archive
@ -6584,7 +6585,7 @@ typedef struct
typedef struct
{
AllocatorInfo alloc;
AllocatorInfo allocator;
OptsEntry* entries; ///< zpl_array
OptsError* errors; ///< zpl_array
OptsEntry** positioned; ///< zpl_array
@ -8761,7 +8762,7 @@ typedef struct
typedef struct
{
AllocatorInfo alloc;
AllocatorInfo allocator;
u32 max_threads, max_jobs, counter;
ThreadWorker* workers; ///< zpl_buffer
ThreadQueue queues[ ZPL_JOBS_MAX_PRIORITIES ];
@ -11248,16 +11249,16 @@ FileContents file_read_contents( AllocatorInfo a, b32 zero_terminate, char const
if ( file_open( &file, filepath ) == EFileError_NONE )
{
sw file_size = zpl_cast( sw ) file_size( &file );
if ( file_size > 0 )
sw fsize = zpl_cast( sw ) file_size( &file );
if ( fsize > 0 )
{
result.data = alloc( a, zero_terminate ? file_size + 1 : file_size );
result.size = file_size;
result.data = alloc( a, zero_terminate ? fsize + 1 : fsize );
result.size = fsize;
file_read_at( &file, result.data, result.size, 0 );
if ( zero_terminate )
{
u8* str = zpl_cast( u8* ) result.data;
str[ file_size ] = '\0';
u8* str = zpl_cast( u8* ) result.data;
str[ fsize ] = '\0';
}
}
file_close( &file );
@ -11294,16 +11295,16 @@ b32 file_write_contents( char const* filepath, void const* buffer, sw size, File
return write_ok;
}
char* file_read_lines( AllocatorInfo alloc, Array( char* ) * lines, char const* filename, b32 strip_whitespace )
char* file_read_lines( AllocatorInfo allocator, Array( char* ) * lines, char const* filename, b32 strip_whitespace )
{
FileInfo f = { 0 };
file_open( &f, filename );
sw fsize = ( sw )file_size( &f );
char* contents = ( char* )alloc( alloc, fsize + 1 );
char* contents = ( char* )alloc( allocator, fsize + 1 );
file_read( &f, contents, fsize );
contents[ fsize ] = 0;
*lines = str_split_lines( alloc, contents, strip_whitespace );
*lines = str_split_lines( allocator, contents, strip_whitespace );
file_close( &f );
return contents;
@ -11334,7 +11335,7 @@ typedef struct
u8 magic;
u8* buf; //< zpl_array OR plain buffer if we can't write
sw cursor;
AllocatorInfo alloc;
AllocatorInfo allocator;
FileStreamFlags flags;
sw cap;
@ -11366,10 +11367,10 @@ b8 file_stream_new( FileInfo* file, AllocatorInfo allocator )
if ( ! d )
return false;
zero_item( file );
d->magic = ZPL__FILE_STREAM_FD_MAGIC;
d->alloc = allocator;
d->flags = EFileStream_CLONE_WRITABLE;
d->cap = 0;
d->magic = ZPL__FILE_STREAM_FD_MAGIC;
d->allocator = allocator;
d->flags = EFileStream_CLONE_WRITABLE;
d->cap = 0;
if ( ! array_init( d->buf, allocator ) )
return false;
file->ops = memory_file_operations;
@ -11388,9 +11389,9 @@ b8 file_stream_open( FileInfo* file, AllocatorInfo allocator, u8* buffer, sw siz
if ( ! d )
return false;
zero_item( file );
d->magic = ZPL__FILE_STREAM_FD_MAGIC;
d->alloc = allocator;
d->flags = flags;
d->magic = ZPL__FILE_STREAM_FD_MAGIC;
d->allocator = allocator;
d->flags = flags;
if ( d->flags & EFileStream_CLONE_WRITABLE )
{
if ( ! array_init_reserve( d->buf, allocator, size ) )
@ -11483,11 +11484,11 @@ internal ZPL_FILE_WRITE_AT_PROC( _memory_file_write )
internal ZPL_FILE_CLOSE_PROC( _memory_file_close )
{
_memory_fd* d = _file_stream_from_fd( fd );
AllocatorInfo alloc = d->alloc;
_memory_fd* d = _file_stream_from_fd( fd );
AllocatorInfo allocator = d->allocator;
if ( d->flags & EFileStream_CLONE_WRITABLE )
array_free( d->buf );
free( alloc, d );
free( allocator, d );
}
FileOperations const memory_file_operations = { _memory_file_read, _memory_file_write, _memory_file_seek, _memory_file_close };
@ -11830,7 +11831,7 @@ FileError path_rmdir( char const* path )
return EFileError_UNKNOWN;
}
void _file_direntry( AllocatorInfo alloc, char const* dirname, String* output, b32 recurse )
void _file_direntry( AllocatorInfo allocator, char const* dirname, String* output, b32 recurse )
{
#if defined( ZPL_SYSTEM_UNIX ) || defined( ZPL_SYSTEM_OSX )
DIR * d, *cd;
@ -11848,7 +11849,7 @@ void _file_direntry( AllocatorInfo alloc, char const* dirname, String* output, b
if ( dir->d_name[ 0 ] == '.' && dir->d_name[ 1 ] == 0 )
continue;
String dirpath = string_make( alloc, dirname );
String dirpath = string_make( allocator, dirname );
dirpath = string_appendc( dirpath, "/" );
dirpath = string_appendc( dirpath, dir->d_name );
@ -11857,7 +11858,7 @@ void _file_direntry( AllocatorInfo alloc, char const* dirname, String* output, b
if ( recurse && ( cd = opendir( dirpath ) ) != NULL && dir->d_type == DT_DIR )
{
_file_direntry( alloc, dirpath, output, recurse );
_file_direntry( allocator, dirpath, output, recurse );
}
string_free( dirpath );
}
@ -11884,7 +11885,7 @@ void _file_direntry( AllocatorInfo alloc, char const* dirname, String* output, b
}
// attach search pattern
String findpath = string_make( alloc, directory );
String findpath = string_make( allocator, directory );
findpath = string_appendc( findpath, "\\" );
findpath = string_appendc( findpath, "*" );
@ -11901,7 +11902,7 @@ void _file_direntry( AllocatorInfo alloc, char const* dirname, String* output, b
if ( filename[ 0 ] == '.' && filename[ 1 ] == 0 )
continue;
String dirpath = string_make( alloc, directory );
String dirpath = string_make( allocator, directory );
dirpath = string_appendc( dirpath, "\\" );
dirpath = string_appendc( dirpath, filename );
DWORD attrs = GetFileAttributesW( ( const wchar_t* )utf8_to_ucs2_buf( ( const u8* )dirpath ) );
@ -11911,7 +11912,7 @@ void _file_direntry( AllocatorInfo alloc, char const* dirname, String* output, b
if ( recurse && ( data.attrib & _A_SUBDIR ) && ! ( attrs & FILE_ATTRIBUTE_REPARSE_POINT ) )
{
_file_direntry( alloc, dirpath, output, recurse );
_file_direntry( allocator, dirpath, output, recurse );
}
string_free( dirpath );
@ -11923,10 +11924,10 @@ void _file_direntry( AllocatorInfo alloc, char const* dirname, String* output, b
#endif
}
String path_dirlist( AllocatorInfo alloc, char const* dirname, b32 recurse )
String path_dirlist( AllocatorInfo allocator, char const* dirname, b32 recurse )
{
String buf = string_make_reserve( alloc, 4 );
_file_direntry( alloc, dirname, &buf, recurse );
String buf = string_make_reserve( allocator, 4 );
_file_direntry( allocator, dirname, &buf, recurse );
return buf;
}
@ -12136,9 +12137,9 @@ sw tar_pack( FileInfo* archive, char const** paths, sw paths_len )
return -( ZPL_TAR_ERROR_IO_ERROR );
}
s64 file_size = file_size( &file );
s64 fsize = file_size( &file );
str_fmt( hr.name, 12, "%s", paths[ i ] );
str_fmt( hr.size, 12, "%o", file_size );
str_fmt( hr.size, 12, "%o", fsize );
str_fmt( hr.mode, 8, "%o", 0664 );
str_fmt( hr.mtime, 12, "%o", fs_last_write_time( paths[ i ] ) );
hr.type = ZPL_TAR_TYPE_REGULAR;
@ -12148,9 +12149,9 @@ sw tar_pack( FileInfo* archive, char const** paths, sw paths_len )
// write data
{
s64 remaining_data = file_size;
s64 remaining_data = fsize;
s64 total_data = align_forward_i64( remaining_data, 512 );
s64 padding = ( total_data - file_size );
s64 padding = ( total_data - fsize );
char buf[ 4096 ] = { 0 };
s64 pos = 0;
sw bytes_read = 0;
@ -12192,10 +12193,10 @@ sw tar_pack( FileInfo* archive, char const** paths, sw paths_len )
return 0;
}
sw tar_pack_dir( FileInfo* archive, char const* path, AllocatorInfo alloc )
sw tar_pack_dir( FileInfo* archive, char const* path, AllocatorInfo allocator )
{
String filelst = path_dirlist( alloc, path, true );
char const** files = zpl_cast( char const** ) str_split_lines( alloc, filelst, false );
String filelst = path_dirlist( allocator, path, true );
char const** files = zpl_cast( char const** ) str_split_lines( allocator, filelst, false );
sw err = tar_pack( archive, files, array_count( files ) );
string_free( filelst );
array_free( files );
@ -15248,10 +15249,10 @@ ZPL_BEGIN_C_DECLS
void opts_init( Opts* opts, AllocatorInfo a, char const* app )
{
Opts opts_ = { 0 };
*opts = opts_;
opts->alloc = a;
opts->appname = app;
Opts opts_ = { 0 };
*opts = opts_;
opts->allocator = a;
opts->appname = app;
array_init( opts->entries, a );
array_init( opts->positioned, a );
@ -15353,7 +15354,7 @@ void _opts_set_value( Opts* opts, OptsEntry* t, char* b )
{
case EOpts_STRING :
{
t->text = string_make( opts->alloc, b );
t->text = string_make( opts->allocator, b );
}
break;
@ -19747,7 +19748,7 @@ void jobs_init_with_limit( JobsSystem* pool, AllocatorInfo a, u32 max_threads, u
JobsSystem pool_ = { 0 };
*pool = pool_;
pool->alloc = a;
pool->allocator = a;
pool->max_threads = max_threads;
pool->max_jobs = max_jobs;
pool->counter = 0;
@ -21643,7 +21644,7 @@ typedef uptr uintptr;
typedef sptr intptr;
# endif // ZPL_EXPOSE_TYPES
#endif // ZPL_H
#endif // ZPL_H
// TOC:
// zpl.h