mirror of
https://github.com/Ed94/refactor.git
synced 2025-06-30 19:01:04 -07:00
Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
50033cc819 | |||
22f74f3dc6 | |||
6395d022f1 | |||
4d5cbd3e8d | |||
b21e1bf603 | |||
12779449a4 |
6
.vscode/launch.json
vendored
6
.vscode/launch.json
vendored
@ -47,10 +47,10 @@
|
|||||||
"request": "launch",
|
"request": "launch",
|
||||||
"program": "${workspaceFolder}/build/refactor.exe",
|
"program": "${workspaceFolder}/build/refactor.exe",
|
||||||
"args": [
|
"args": [
|
||||||
"-source=./refactor.cpp",
|
"-src=./project/refactor.cpp",
|
||||||
"-destination=./Test/refactor.cpp",
|
"-dst=./Test/refactor.cpp",
|
||||||
|
|
||||||
"-specification=./Test/zpl.refactor"
|
"-spec=./Test/zpl.refactor"
|
||||||
],
|
],
|
||||||
"stopAtEntry": false,
|
"stopAtEntry": false,
|
||||||
"cwd": "${workspaceRoot}",
|
"cwd": "${workspaceRoot}",
|
||||||
|
2
LICENSE
2
LICENSE
@ -1,6 +1,6 @@
|
|||||||
BSD 3-Clause License
|
BSD 3-Clause License
|
||||||
|
|
||||||
Copyright (c) 2023, Ed_
|
Copyright (c) 2023, Edward R. Gonzalez
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are met:
|
modification, are permitted provided that the following conditions are met:
|
||||||
|
@ -79,8 +79,6 @@ With the refactors applied a meson configuraiton is setup (`meson.build` in test
|
|||||||
* Can have a heavy memory cost, so most likely do not want on by default.
|
* Can have a heavy memory cost, so most likely do not want on by default.
|
||||||
* Make comments ignored by default, and just have ability to specify custom comments.
|
* Make comments ignored by default, and just have ability to specify custom comments.
|
||||||
* Would need a directive to add refactors to comments.
|
* Would need a directive to add refactors to comments.
|
||||||
* Directive to add cpp namespaces on specific lines of a file, or near specific signatures.
|
|
||||||
* This can honestly be done also with placing words on specific lines..
|
|
||||||
* Provide a GUI build.
|
* Provide a GUI build.
|
||||||
* Provide as a single-header library.
|
* Provide as a single-header library.
|
||||||
* Could add a test case where this library is refactored into pure C (most likely c99 or c11).
|
* Could add a test case where this library is refactored into pure C (most likely c99 or c11).
|
||||||
|
@ -34,8 +34,8 @@ namespace zpl_random_, rng_
|
|||||||
namespace zpl_pr, process_
|
namespace zpl_pr, process_
|
||||||
namespace zpl__, __
|
namespace zpl__, __
|
||||||
namespace ZPL_ADT_, EADT
|
namespace ZPL_ADT_, EADT
|
||||||
namespace ZPL_ALLOCATION_, EAllocation
|
namespace ZPL_ALLOCATION_, EAllocation_
|
||||||
namespace ZPL_CSV_ERROR, ECSV_Error
|
namespace ZPL_CSV_ERROR, ECSV_Error_
|
||||||
namespace ZPL_FILE_MODE_, EFileMode_
|
namespace ZPL_FILE_MODE_, EFileMode_
|
||||||
namespace ZPL_FILE_ERROR_, EFileError_
|
namespace ZPL_FILE_ERROR_, EFileError_
|
||||||
namespace ZPL_SEEK_WHENCE_, ESeekWhence_
|
namespace ZPL_SEEK_WHENCE_, ESeekWhence_
|
||||||
|
@ -9,7 +9,7 @@ namespace Global
|
|||||||
namespace Memory
|
namespace Memory
|
||||||
{
|
{
|
||||||
zpl_arena Global_Arena {};
|
zpl_arena Global_Arena {};
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
zpl_arena_init_from_allocator( & Global_Arena, zpl_heap(), Initial_Reserve );
|
zpl_arena_init_from_allocator( & Global_Arena, zpl_heap(), Initial_Reserve );
|
||||||
@ -19,16 +19,16 @@ namespace Memory
|
|||||||
zpl_assert_crash( "Failed to reserve memory for Tests:: Global_Arena" );
|
zpl_assert_crash( "Failed to reserve memory for Tests:: Global_Arena" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void resize( uw new_size )
|
void resize( uw new_size )
|
||||||
{
|
{
|
||||||
void* new_memory = zpl_resize( zpl_heap(), Global_Arena.physical_start, Global_Arena.total_size, new_size );
|
void* new_memory = zpl_resize( zpl_heap(), Global_Arena.physical_start, Global_Arena.total_size, new_size );
|
||||||
|
|
||||||
if ( new_memory == nullptr )
|
if ( new_memory == nullptr )
|
||||||
{
|
{
|
||||||
fatal("Failed to resize global arena!");
|
fatal("Failed to resize global arena!");
|
||||||
}
|
}
|
||||||
|
|
||||||
Global_Arena.physical_start = new_memory;
|
Global_Arena.physical_start = new_memory;
|
||||||
Global_Arena.total_size = new_size;
|
Global_Arena.total_size = new_size;
|
||||||
}
|
}
|
||||||
@ -36,7 +36,7 @@ namespace Memory
|
|||||||
void cleanup()
|
void cleanup()
|
||||||
{
|
{
|
||||||
zpl_arena_free( & Global_Arena);
|
zpl_arena_free( & Global_Arena);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ bool opts_custom_add(zpl_opts* opts, zpl_opts_entry *t, char* b)
|
|||||||
{
|
{
|
||||||
if (t->type != ZPL_OPTS_STRING)
|
if (t->type != ZPL_OPTS_STRING)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
t->text = zpl_string_append_length(t->text, " ", 1);
|
t->text = zpl_string_append_length(t->text, " ", 1);
|
||||||
@ -53,23 +53,23 @@ bool opts_custom_add(zpl_opts* opts, zpl_opts_entry *t, char* b)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
b32 opts_custom_compile(zpl_opts *opts, int argc, char **argv)
|
b32 opts_custom_compile(zpl_opts *opts, int argc, char **argv)
|
||||||
{
|
{
|
||||||
zpl_b32 had_errors = false;
|
zpl_b32 had_errors = false;
|
||||||
|
|
||||||
for (int i = 1; i < argc; ++i)
|
for (int i = 1; i < argc; ++i)
|
||||||
{
|
{
|
||||||
char* arg = argv[i];
|
char* arg = argv[i];
|
||||||
|
|
||||||
if (*arg)
|
if (*arg)
|
||||||
{
|
{
|
||||||
arg = (char*)zpl_str_trim(arg, false);
|
arg = (char*)zpl_str_trim(arg, false);
|
||||||
|
|
||||||
if (*arg == '-')
|
if (*arg == '-')
|
||||||
{
|
{
|
||||||
zpl_opts_entry* entry = 0;
|
zpl_opts_entry* entry = 0;
|
||||||
zpl_b32 checkln = false;
|
zpl_b32 checkln = false;
|
||||||
if ( *(arg + 1) == '-')
|
if ( *(arg + 1) == '-')
|
||||||
{
|
{
|
||||||
checkln = true;
|
checkln = true;
|
||||||
++arg;
|
++arg;
|
||||||
@ -83,15 +83,15 @@ b32 opts_custom_compile(zpl_opts *opts, int argc, char **argv)
|
|||||||
|
|
||||||
entry = zpl__opts_find(opts, b, (e - b), checkln);
|
entry = zpl__opts_find(opts, b, (e - b), checkln);
|
||||||
|
|
||||||
if (entry)
|
if (entry)
|
||||||
{
|
{
|
||||||
char *ob = b;
|
char *ob = b;
|
||||||
b = e;
|
b = e;
|
||||||
|
|
||||||
/**/
|
/**/
|
||||||
if (*e == '=')
|
if (*e == '=')
|
||||||
{
|
{
|
||||||
if (entry->type == ZPL_OPTS_FLAG)
|
if (entry->type == ZPL_OPTS_FLAG)
|
||||||
{
|
{
|
||||||
*e = '\0';
|
*e = '\0';
|
||||||
zpl__opts_push_error(opts, ob, ZPL_OPTS_ERR_EXTRA_VALUE);
|
zpl__opts_push_error(opts, ob, ZPL_OPTS_ERR_EXTRA_VALUE);
|
||||||
@ -101,14 +101,14 @@ b32 opts_custom_compile(zpl_opts *opts, int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
b = e = e + 1;
|
b = e = e + 1;
|
||||||
}
|
}
|
||||||
else if (*e == '\0')
|
else if (*e == '\0')
|
||||||
{
|
{
|
||||||
char *sp = argv[i+1];
|
char *sp = argv[i+1];
|
||||||
|
|
||||||
if (sp && *sp != '-' && (zpl_array_count(opts->positioned) < 1 || entry->type != ZPL_OPTS_FLAG))
|
if (sp && *sp != '-' && (zpl_array_count(opts->positioned) < 1 || entry->type != ZPL_OPTS_FLAG))
|
||||||
{
|
{
|
||||||
if (entry->type == ZPL_OPTS_FLAG)
|
if (entry->type == ZPL_OPTS_FLAG)
|
||||||
{
|
{
|
||||||
zpl__opts_push_error(opts, b, ZPL_OPTS_ERR_EXTRA_VALUE);
|
zpl__opts_push_error(opts, b, ZPL_OPTS_ERR_EXTRA_VALUE);
|
||||||
had_errors = true;
|
had_errors = true;
|
||||||
@ -119,10 +119,10 @@ b32 opts_custom_compile(zpl_opts *opts, int argc, char **argv)
|
|||||||
arg = sp;
|
arg = sp;
|
||||||
b = e = sp;
|
b = e = sp;
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (entry->type != ZPL_OPTS_FLAG)
|
if (entry->type != ZPL_OPTS_FLAG)
|
||||||
{
|
{
|
||||||
zpl__opts_push_error(opts, ob, ZPL_OPTS_ERR_MISSING_VALUE);
|
zpl__opts_push_error(opts, ob, ZPL_OPTS_ERR_MISSING_VALUE);
|
||||||
had_errors = true;
|
had_errors = true;
|
||||||
@ -145,20 +145,20 @@ b32 opts_custom_compile(zpl_opts *opts, int argc, char **argv)
|
|||||||
opts_custom_add(opts, entry, b );
|
opts_custom_add(opts, entry, b );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
zpl__opts_push_error(opts, b, ZPL_OPTS_ERR_OPTION);
|
zpl__opts_push_error(opts, b, ZPL_OPTS_ERR_OPTION);
|
||||||
had_errors = true;
|
had_errors = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (zpl_array_count(opts->positioned))
|
else if (zpl_array_count(opts->positioned))
|
||||||
{
|
{
|
||||||
zpl_opts_entry *l = zpl_array_back(opts->positioned);
|
zpl_opts_entry *l = zpl_array_back(opts->positioned);
|
||||||
zpl_array_pop(opts->positioned);
|
zpl_array_pop(opts->positioned);
|
||||||
zpl__opts_set_value(opts, l, arg);
|
zpl__opts_set_value(opts, l, arg);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
zpl__opts_push_error(opts, arg, ZPL_OPTS_ERR_VALUE);
|
zpl__opts_push_error(opts, arg, ZPL_OPTS_ERR_VALUE);
|
||||||
had_errors = true;
|
had_errors = true;
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
BLOAT.
|
BLOAT.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#ifdef BLOAT_IMPL
|
#ifdef BLOAT_IMPL
|
||||||
# define ZPL_IMPLEMENTATION
|
# define ZPL_IMPLEMENTATION
|
||||||
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
#pragma region ZPL INCLUDE
|
#pragma region ZPL INCLUDE
|
||||||
#if __clang__
|
#if __clang__
|
||||||
# pragma clang diagnostic push
|
# pragma clang diagnostic push
|
||||||
# pragma clang diagnostic ignored "-Wmissing-braces"
|
# pragma clang diagnostic ignored "-Wmissing-braces"
|
||||||
# pragma clang diagnostic ignored "-Wbraced-scalar-init"
|
# pragma clang diagnostic ignored "-Wbraced-scalar-init"
|
||||||
#endif
|
#endif
|
||||||
@ -111,25 +111,25 @@ b32 opts_custom_compile(zpl_opts *opts, int argc, char **argv);
|
|||||||
|
|
||||||
|
|
||||||
inline
|
inline
|
||||||
sw log_fmt(char const *fmt, ...)
|
sw log_fmt(char const *fmt, ...)
|
||||||
{
|
{
|
||||||
if ( Global::ShouldShowDebug == false )
|
if ( Global::ShouldShowDebug == false )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
sw res;
|
sw res;
|
||||||
va_list va;
|
va_list va;
|
||||||
|
|
||||||
va_start(va, fmt);
|
va_start(va, fmt);
|
||||||
res = zpl_printf_va(fmt, va);
|
res = zpl_printf_va(fmt, va);
|
||||||
va_end(va);
|
va_end(va);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline
|
inline
|
||||||
void fatal(char const *fmt, ...)
|
void fatal(char const *fmt, ...)
|
||||||
{
|
{
|
||||||
zpl_local_persist zpl_thread_local
|
zpl_local_persist zpl_thread_local
|
||||||
char buf[ZPL_PRINTF_MAXLEN] = { 0 };
|
char buf[ZPL_PRINTF_MAXLEN] = { 0 };
|
||||||
|
|
||||||
va_list va;
|
va_list va;
|
||||||
|
@ -4,13 +4,13 @@
|
|||||||
namespace IO
|
namespace IO
|
||||||
{
|
{
|
||||||
using array_string = zpl_array( zpl_string );
|
using array_string = zpl_array( zpl_string );
|
||||||
|
|
||||||
namespace StaticData
|
namespace StaticData
|
||||||
{
|
{
|
||||||
array_string Sources = nullptr;
|
array_string Sources = nullptr;
|
||||||
array_string Destinations = nullptr;
|
array_string Destinations = nullptr;
|
||||||
zpl_string Specification = nullptr;
|
zpl_string Specification = nullptr;
|
||||||
|
|
||||||
// Current source and destination index.
|
// Current source and destination index.
|
||||||
// Used to keep track of which file get_next_source or write refer to.
|
// Used to keep track of which file get_next_source or write refer to.
|
||||||
sw Current = -1;
|
sw Current = -1;
|
||||||
@ -22,12 +22,12 @@ namespace IO
|
|||||||
zpl_arena MemSrc;
|
zpl_arena MemSrc;
|
||||||
}
|
}
|
||||||
using namespace StaticData;
|
using namespace StaticData;
|
||||||
|
|
||||||
|
|
||||||
void prepare()
|
void prepare()
|
||||||
{
|
{
|
||||||
const sw num_srcs = zpl_array_count( Sources );
|
const sw num_srcs = zpl_array_count( Sources );
|
||||||
|
|
||||||
// Determine the largest content size.
|
// Determine the largest content size.
|
||||||
sw left = num_srcs;
|
sw left = num_srcs;
|
||||||
zpl_string* path = Sources;
|
zpl_string* path = Sources;
|
||||||
@ -35,14 +35,14 @@ namespace IO
|
|||||||
{
|
{
|
||||||
zpl_file src = {};
|
zpl_file src = {};
|
||||||
zpl_file_error error = zpl_file_open( & src, *path );
|
zpl_file_error error = zpl_file_open( & src, *path );
|
||||||
|
|
||||||
if ( error != ZPL_FILE_ERROR_NONE )
|
if ( error != ZPL_FILE_ERROR_NONE )
|
||||||
{
|
{
|
||||||
fatal("IO::Prepare - Could not open source file: %s", *path );
|
fatal("IO::Prepare - Could not open source file: %s", *path );
|
||||||
}
|
}
|
||||||
|
|
||||||
const sw fsize = zpl_file_size( & src );
|
const sw fsize = zpl_file_size( & src );
|
||||||
|
|
||||||
if ( fsize > Largest_Src_Size )
|
if ( fsize > Largest_Src_Size )
|
||||||
{
|
{
|
||||||
Largest_Src_Size = fsize;
|
Largest_Src_Size = fsize;
|
||||||
@ -51,12 +51,12 @@ namespace IO
|
|||||||
zpl_file_close( & src );
|
zpl_file_close( & src );
|
||||||
}
|
}
|
||||||
while ( path++, left--, left > 0 );
|
while ( path++, left--, left > 0 );
|
||||||
|
|
||||||
uw persist_size = Largest_Src_Size * 2 + 8;
|
uw persist_size = Largest_Src_Size * 2 + 8;
|
||||||
|
|
||||||
zpl_arena_init_from_allocator( & MemSrc, zpl_heap(), persist_size );
|
zpl_arena_init_from_allocator( & MemSrc, zpl_heap(), persist_size );
|
||||||
}
|
}
|
||||||
|
|
||||||
void cleanup()
|
void cleanup()
|
||||||
{
|
{
|
||||||
zpl_arena_free( & MemSpec );
|
zpl_arena_free( & MemSpec );
|
||||||
|
@ -10,16 +10,16 @@ namespace IO
|
|||||||
// Preps the IO by loading all the files and checking to see what the largest size is.
|
// Preps the IO by loading all the files and checking to see what the largest size is.
|
||||||
// The file with the largest size is used to determine the size of the persistent memory.
|
// The file with the largest size is used to determine the size of the persistent memory.
|
||||||
void prepare();
|
void prepare();
|
||||||
|
|
||||||
// Frees the persistent and transient memory arenas.
|
// Frees the persistent and transient memory arenas.
|
||||||
void cleanup();
|
void cleanup();
|
||||||
|
|
||||||
// Provides the content of the specification.
|
// Provides the content of the specification.
|
||||||
Array_Line get_specification();
|
Array_Line get_specification();
|
||||||
|
|
||||||
// Provides the content of the next source, broken up as a series of lines.
|
// Provides the content of the next source, broken up as a series of lines.
|
||||||
char* get_next_source();
|
char* get_next_source();
|
||||||
|
|
||||||
// Writes the refactored content ot the current corresponding destination.
|
// Writes the refactored content ot the current corresponding destination.
|
||||||
void write( zpl_string refactored );
|
void write( zpl_string refactored );
|
||||||
}
|
}
|
||||||
|
@ -195,7 +195,7 @@ namespace Spec
|
|||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
find_next_token( type, token, line, length );
|
find_next_token( type, token, line, length );
|
||||||
|
|
||||||
// First argument is signature.
|
// First argument is signature.
|
||||||
@ -211,7 +211,7 @@ namespace Spec
|
|||||||
case Tok::Word:
|
case Tok::Word:
|
||||||
if ( ignore)
|
if ( ignore)
|
||||||
zpl_array_append( Ignore_Words, entry );
|
zpl_array_append( Ignore_Words, entry );
|
||||||
|
|
||||||
else
|
else
|
||||||
zpl_array_append( Words, entry );
|
zpl_array_append( Words, entry );
|
||||||
break;
|
break;
|
||||||
@ -248,7 +248,7 @@ namespace Spec
|
|||||||
{
|
{
|
||||||
case Tok::Word:
|
case Tok::Word:
|
||||||
zpl_array_append( Words, entry );
|
zpl_array_append( Words, entry );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Tok::Namespace:
|
case Tok::Namespace:
|
||||||
zpl_array_append( Namespaces, entry );
|
zpl_array_append( Namespaces, entry );
|
||||||
@ -288,7 +288,7 @@ namespace Spec
|
|||||||
{
|
{
|
||||||
case Tok::Word:
|
case Tok::Word:
|
||||||
zpl_array_append( Words, entry );
|
zpl_array_append( Words, entry );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Tok::Namespace:
|
case Tok::Namespace:
|
||||||
zpl_array_append( Namespaces, entry );
|
zpl_array_append( Namespaces, entry );
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
namespace Spec
|
namespace Spec
|
||||||
{
|
{
|
||||||
enum Tok
|
enum Tok
|
||||||
{
|
{
|
||||||
Not,
|
Not,
|
||||||
Comment,
|
Comment,
|
||||||
@ -19,7 +19,7 @@ namespace Spec
|
|||||||
char const* str_tok( Tok tok )
|
char const* str_tok( Tok tok )
|
||||||
{
|
{
|
||||||
static
|
static
|
||||||
char const* tok_to_str[ Tok::Num_Tok ] =
|
char const* tok_to_str[ Tok::Num_Tok ] =
|
||||||
{
|
{
|
||||||
"not",
|
"not",
|
||||||
"comments",
|
"comments",
|
||||||
@ -35,7 +35,7 @@ namespace Spec
|
|||||||
char strlen_tok( Tok tok )
|
char strlen_tok( Tok tok )
|
||||||
{
|
{
|
||||||
static
|
static
|
||||||
const u8 tok_to_len[ Tok::Num_Tok ] =
|
const u8 tok_to_len[ Tok::Num_Tok ] =
|
||||||
{
|
{
|
||||||
3,
|
3,
|
||||||
8,
|
8,
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
#include "IO.cpp"
|
#include "IO.cpp"
|
||||||
#include "Spec.cpp"
|
#include "Spec.cpp"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void parse_options( int num, char** arguments )
|
void parse_options( int num, char** arguments )
|
||||||
{
|
{
|
||||||
zpl_opts opts;
|
zpl_opts opts;
|
||||||
@ -28,32 +26,32 @@ void parse_options( int num, char** arguments )
|
|||||||
|
|
||||||
Global::ShouldShowDebug = true;
|
Global::ShouldShowDebug = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( zpl_opts_has_arg( & opts, "num" ) )
|
if ( zpl_opts_has_arg( & opts, "num" ) )
|
||||||
{
|
{
|
||||||
num = zpl_opts_integer( & opts, "num", -1 );
|
num = zpl_opts_integer( & opts, "num", -1 );
|
||||||
uw global_reserve = num * sizeof(zpl_string) * IO::Path_Size_Largest * 2 + 8;
|
uw global_reserve = num * sizeof(zpl_string) * IO::Path_Size_Largest * 2 + 8;
|
||||||
|
|
||||||
if ( global_reserve > zpl_megabytes(1) )
|
if ( global_reserve > zpl_megabytes(1) )
|
||||||
{
|
{
|
||||||
Memory::resize( global_reserve + zpl_megabytes(2) );
|
Memory::resize( global_reserve + zpl_megabytes(2) );
|
||||||
}
|
}
|
||||||
|
|
||||||
zpl_array_init_reserve( IO::Sources, g_allocator, num );
|
zpl_array_init_reserve( IO::Sources, g_allocator, num );
|
||||||
zpl_array_init_reserve( IO::Destinations, g_allocator, num );
|
zpl_array_init_reserve( IO::Destinations, g_allocator, num );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
num = 1;
|
num = 1;
|
||||||
|
|
||||||
zpl_array_init_reserve( IO::Sources, g_allocator, 1 );
|
zpl_array_init_reserve( IO::Sources, g_allocator, 1 );
|
||||||
zpl_array_init_reserve( IO::Destinations, g_allocator, 1 );
|
zpl_array_init_reserve( IO::Destinations, g_allocator, 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( zpl_opts_has_arg( & opts, "src" ) )
|
if ( zpl_opts_has_arg( & opts, "src" ) )
|
||||||
{
|
{
|
||||||
zpl_string opt = zpl_opts_string( & opts, "src", "INVALID SRC ARGUMENT" );
|
zpl_string opt = zpl_opts_string( & opts, "src", "INVALID SRC ARGUMENT" );
|
||||||
|
|
||||||
if ( num == 1 )
|
if ( num == 1 )
|
||||||
{
|
{
|
||||||
zpl_string path = zpl_string_make_length( g_allocator, opt, zpl_string_length( opt ));
|
zpl_string path = zpl_string_make_length( g_allocator, opt, zpl_string_length( opt ));
|
||||||
@ -66,20 +64,20 @@ void parse_options( int num, char** arguments )
|
|||||||
uw left = num;
|
uw left = num;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
char* path = buffer;
|
char* path = buffer;
|
||||||
sw length = 0;
|
sw length = 0;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
path[length] = *opt;
|
path[length] = *opt;
|
||||||
}
|
}
|
||||||
while ( length++, opt++, *opt != ' ' && *opt != '\0' );
|
while ( length++, opt++, *opt != ' ' && *opt != '\0' );
|
||||||
|
|
||||||
zpl_string path_string = zpl_string_make_length( g_allocator, path, length );
|
zpl_string path_string = zpl_string_make_length( g_allocator, path, length );
|
||||||
zpl_array_append( IO::Sources, path_string );
|
zpl_array_append( IO::Sources, path_string );
|
||||||
|
|
||||||
opt++;
|
opt++;
|
||||||
}
|
}
|
||||||
while ( --left );
|
while ( --left );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -110,14 +108,14 @@ void parse_options( int num, char** arguments )
|
|||||||
do
|
do
|
||||||
{
|
{
|
||||||
path[length] = *opt;
|
path[length] = *opt;
|
||||||
}
|
}
|
||||||
while ( length++, opt++, *opt != ' ' && *opt != '\0' );
|
while ( length++, opt++, *opt != ' ' && *opt != '\0' );
|
||||||
|
|
||||||
zpl_string path_string = zpl_string_make_length( g_allocator, path, length );
|
zpl_string path_string = zpl_string_make_length( g_allocator, path, length );
|
||||||
zpl_array_append( IO::Destinations, path_string );
|
zpl_array_append( IO::Destinations, path_string );
|
||||||
|
|
||||||
opt++;
|
opt++;
|
||||||
}
|
}
|
||||||
while ( --left );
|
while ( --left );
|
||||||
|
|
||||||
if ( zpl_array_count(IO::Destinations) != zpl_array_count( IO::Sources ) )
|
if ( zpl_array_count(IO::Destinations) != zpl_array_count( IO::Sources ) )
|
||||||
@ -132,7 +130,7 @@ void parse_options( int num, char** arguments )
|
|||||||
do
|
do
|
||||||
{
|
{
|
||||||
zpl_array_append( IO::Destinations, IO::Sources[num - left] );
|
zpl_array_append( IO::Destinations, IO::Sources[num - left] );
|
||||||
}
|
}
|
||||||
while ( --left );
|
while ( --left );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -163,7 +161,7 @@ void parse_options( int num, char** arguments )
|
|||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Refactor will problably have the execution and arg parsing (main and opts)
|
Refactor will problably have the execution and arg parsing (main and opts)
|
||||||
moved to a separate file.
|
moved to a separate file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -172,7 +170,7 @@ zpl_arena Refactor_Buffer;
|
|||||||
void refactor()
|
void refactor()
|
||||||
{
|
{
|
||||||
ct static char const* include_sig = "include";
|
ct static char const* include_sig = "include";
|
||||||
|
|
||||||
struct Token
|
struct Token
|
||||||
{
|
{
|
||||||
u32 Start;
|
u32 Start;
|
||||||
@ -280,7 +278,7 @@ void refactor()
|
|||||||
{
|
{
|
||||||
Spec::Entry* ignore = Spec::Ignore_Includes;
|
Spec::Entry* ignore = Spec::Ignore_Includes;
|
||||||
sw ignores_left = zpl_array_count( Spec::Ignore_Includes);
|
sw ignores_left = zpl_array_count( Spec::Ignore_Includes);
|
||||||
Snapshot backup = { src, left, col, line };
|
Snapshot backup = { src, left, col, line };
|
||||||
|
|
||||||
if ( '#' != src[0] )
|
if ( '#' != src[0] )
|
||||||
break;
|
break;
|
||||||
@ -336,84 +334,9 @@ void refactor()
|
|||||||
}
|
}
|
||||||
|
|
||||||
restore( backup );
|
restore( backup );
|
||||||
}
|
}
|
||||||
while (false);
|
while (false);
|
||||||
|
|
||||||
// Word Ignores
|
|
||||||
{
|
|
||||||
Spec::Entry* ignore = Spec::Ignore_Words;
|
|
||||||
sw ignores_left = zpl_array_count( Spec::Ignore_Words);
|
|
||||||
|
|
||||||
for ( ; ignores_left; ignores_left--, ignore++ )
|
|
||||||
{
|
|
||||||
if ( ignore->Sig[0] != src[0] )
|
|
||||||
continue;
|
|
||||||
|
|
||||||
zpl_string_clear( current );
|
|
||||||
|
|
||||||
u32 sig_length = zpl_string_length( ignore->Sig );
|
|
||||||
current = zpl_string_append_length( current, src, sig_length );
|
|
||||||
|
|
||||||
if ( zpl_string_are_equal( ignore->Sig, current ) )
|
|
||||||
{
|
|
||||||
char before = src[-1];
|
|
||||||
char after = src[sig_length];
|
|
||||||
|
|
||||||
if ( zpl_char_is_alphanumeric( before ) || before == '_'
|
|
||||||
|| zpl_char_is_alphanumeric( after ) || after == '_' )
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
log_fmt("\nIgnored %-81s line %d, col %d", current, line, col );
|
|
||||||
|
|
||||||
move_forward( sig_length );
|
|
||||||
goto Skip;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Namespace Ignores
|
|
||||||
{
|
|
||||||
Spec::Entry* ignore = Spec::Ignore_Namespaces;
|
|
||||||
sw ignores_left = zpl_array_count( Spec::Ignore_Namespaces);
|
|
||||||
|
|
||||||
for ( ; ignores_left; ignores_left--, ignore++ )
|
|
||||||
{
|
|
||||||
if ( ignore->Sig[0] != src[0] )
|
|
||||||
{
|
|
||||||
ignore++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
zpl_string_clear( current );
|
|
||||||
|
|
||||||
u32 sig_length = zpl_string_length( ignore->Sig );
|
|
||||||
current = zpl_string_append_length( current, src, sig_length );
|
|
||||||
|
|
||||||
if ( zpl_string_are_equal( ignore->Sig, current ) )
|
|
||||||
{
|
|
||||||
u32 length = sig_length;
|
|
||||||
char const* ns_content = src + sig_length;
|
|
||||||
|
|
||||||
while ( zpl_char_is_alphanumeric( ns_content[0] ) || ns_content[0] == '_' )
|
|
||||||
{
|
|
||||||
length++;
|
|
||||||
ns_content++;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if Build_Debug
|
|
||||||
zpl_string_clear( preview );
|
|
||||||
preview = zpl_string_append_length( preview, src, length );
|
|
||||||
log_fmt("\nIgnored %-40s %-40s line %d, column %d", preview, ignore->Sig, line, col );
|
|
||||||
#endif
|
|
||||||
|
|
||||||
move_forward( length );
|
|
||||||
goto Skip;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Includes to match
|
// Includes to match
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
@ -487,9 +410,43 @@ void refactor()
|
|||||||
}
|
}
|
||||||
|
|
||||||
restore( backup );
|
restore( backup );
|
||||||
}
|
}
|
||||||
while (false);
|
while (false);
|
||||||
|
|
||||||
|
// Word Ignores
|
||||||
|
{
|
||||||
|
Spec::Entry* ignore = Spec::Ignore_Words;
|
||||||
|
sw ignores_left = zpl_array_count( Spec::Ignore_Words);
|
||||||
|
|
||||||
|
for ( ; ignores_left; ignores_left--, ignore++ )
|
||||||
|
{
|
||||||
|
if ( ignore->Sig[0] != src[0] )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
zpl_string_clear( current );
|
||||||
|
|
||||||
|
u32 sig_length = zpl_string_length( ignore->Sig );
|
||||||
|
current = zpl_string_append_length( current, src, sig_length );
|
||||||
|
|
||||||
|
if ( zpl_string_are_equal( ignore->Sig, current ) )
|
||||||
|
{
|
||||||
|
char before = src[-1];
|
||||||
|
char after = src[sig_length];
|
||||||
|
|
||||||
|
if ( zpl_char_is_alphanumeric( before ) || before == '_'
|
||||||
|
|| zpl_char_is_alphanumeric( after ) || after == '_' )
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
log_fmt("\nIgnored %-81s line %d, col %d", current, line, col );
|
||||||
|
|
||||||
|
move_forward( sig_length );
|
||||||
|
goto Skip;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Words to match
|
// Words to match
|
||||||
{
|
{
|
||||||
Spec::Entry* word = Spec::Words;
|
Spec::Entry* word = Spec::Words;
|
||||||
@ -538,6 +495,53 @@ void refactor()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Namespace Ignores
|
||||||
|
{
|
||||||
|
Spec::Entry* ignore = Spec::Ignore_Namespaces;
|
||||||
|
sw ignores_left = zpl_array_count( Spec::Ignore_Namespaces);
|
||||||
|
|
||||||
|
for ( ; ignores_left; ignores_left--, ignore++ )
|
||||||
|
{
|
||||||
|
if ( ignore->Sig[0] != src[0] )
|
||||||
|
{
|
||||||
|
ignore++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (( zpl_char_is_alphanumeric( src[-1] ) || src[-1] == '_') )
|
||||||
|
{
|
||||||
|
ignore++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
zpl_string_clear( current );
|
||||||
|
|
||||||
|
u32 sig_length = zpl_string_length( ignore->Sig );
|
||||||
|
current = zpl_string_append_length( current, src, sig_length );
|
||||||
|
|
||||||
|
if ( zpl_string_are_equal( ignore->Sig, current ) )
|
||||||
|
{
|
||||||
|
u32 length = sig_length;
|
||||||
|
char const* ns_content = src + sig_length;
|
||||||
|
|
||||||
|
while ( zpl_char_is_alphanumeric( ns_content[0] ) || ns_content[0] == '_' )
|
||||||
|
{
|
||||||
|
length++;
|
||||||
|
ns_content++;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if Build_Debug
|
||||||
|
zpl_string_clear( preview );
|
||||||
|
preview = zpl_string_append_length( preview, src, length );
|
||||||
|
log_fmt("\nIgnored %-40s %-40s line %d, column %d", preview, ignore->Sig, line, col );
|
||||||
|
#endif
|
||||||
|
|
||||||
|
move_forward( length );
|
||||||
|
goto Skip;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Namespaces to match
|
// Namespaces to match
|
||||||
{
|
{
|
||||||
Spec::Entry* nspace = Spec::Namespaces;
|
Spec::Entry* nspace = Spec::Namespaces;
|
||||||
@ -549,6 +553,9 @@ void refactor()
|
|||||||
if ( nspace->Sig[0] != src[0] )
|
if ( nspace->Sig[0] != src[0] )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
if (( zpl_char_is_alphanumeric( src[-1] ) || src[-1] == '_') )
|
||||||
|
continue;
|
||||||
|
|
||||||
zpl_string_clear( current );
|
zpl_string_clear( current );
|
||||||
|
|
||||||
u32 sig_length = zpl_string_length( nspace->Sig );
|
u32 sig_length = zpl_string_length( nspace->Sig );
|
||||||
@ -568,7 +575,7 @@ void refactor()
|
|||||||
Token entry {};
|
Token entry {};
|
||||||
|
|
||||||
entry.Start = pos;
|
entry.Start = pos;
|
||||||
entry.End = pos + length;
|
entry.End = pos + sig_length;
|
||||||
entry.Sig = nspace->Sig;
|
entry.Sig = nspace->Sig;
|
||||||
|
|
||||||
buffer_size += sig_length;
|
buffer_size += sig_length;
|
||||||
@ -576,7 +583,7 @@ void refactor()
|
|||||||
if ( nspace->Sub != nullptr )
|
if ( nspace->Sub != nullptr )
|
||||||
{
|
{
|
||||||
entry.Sub = nspace->Sub;
|
entry.Sub = nspace->Sub;
|
||||||
buffer_size += zpl_string_length( entry.Sub ) - length;
|
buffer_size += zpl_string_length( entry.Sub ) - sig_length;
|
||||||
}
|
}
|
||||||
|
|
||||||
zpl_array_append( tokens, entry );
|
zpl_array_append( tokens, entry );
|
||||||
@ -595,7 +602,7 @@ void refactor()
|
|||||||
|
|
||||||
Skip:
|
Skip:
|
||||||
move_forward( 1 );
|
move_forward( 1 );
|
||||||
}
|
}
|
||||||
while ( left );
|
while ( left );
|
||||||
End_Search:
|
End_Search:
|
||||||
|
|
||||||
@ -607,7 +614,7 @@ End_Search:
|
|||||||
// Prep data for building the content
|
// Prep data for building the content
|
||||||
left = zpl_array_count( tokens);
|
left = zpl_array_count( tokens);
|
||||||
|
|
||||||
char* content = IO::Current_Content;
|
char* content = IO::Current_Content;
|
||||||
|
|
||||||
zpl_string refactored = zpl_string_make_reserve( zpl_arena_allocator( & Refactor_Buffer ), buffer_size );
|
zpl_string refactored = zpl_string_make_reserve( zpl_arena_allocator( & Refactor_Buffer ), buffer_size );
|
||||||
|
|
||||||
@ -643,7 +650,7 @@ End_Search:
|
|||||||
|
|
||||||
entry--;
|
entry--;
|
||||||
|
|
||||||
if ( entry->End < IO::Current_Size )
|
if ( entry->End < IO::Current_Size )
|
||||||
{
|
{
|
||||||
refactored = zpl_string_append_length( refactored, content, IO::Current_Size - 1 - entry->End );
|
refactored = zpl_string_append_length( refactored, content, IO::Current_Size - 1 - entry->End );
|
||||||
}
|
}
|
||||||
@ -660,7 +667,7 @@ End_Search:
|
|||||||
int main( int num, char** arguments )
|
int main( int num, char** arguments )
|
||||||
{
|
{
|
||||||
Memory::setup();
|
Memory::setup();
|
||||||
|
|
||||||
parse_options( num, arguments);
|
parse_options( num, arguments);
|
||||||
|
|
||||||
IO::prepare();
|
IO::prepare();
|
||||||
@ -676,7 +683,7 @@ int main( int num, char** arguments )
|
|||||||
refactor();
|
refactor();
|
||||||
|
|
||||||
zpl_printf("\nRefactored: %s", IO::Sources[IO::Current]);
|
zpl_printf("\nRefactored: %s", IO::Sources[IO::Current]);
|
||||||
}
|
}
|
||||||
while ( --left );
|
while ( --left );
|
||||||
|
|
||||||
zpl_arena_free( & Refactor_Buffer );
|
zpl_arena_free( & Refactor_Buffer );
|
||||||
|
Reference in New Issue
Block a user