lots of organization to files, figured out a good way to solve the build.cpp string problem and set it up
parent
1ef304558e
commit
e37cce743a
|
@ -7,7 +7,7 @@
|
|||
#include <string.h>
|
||||
|
||||
|
||||
#include "4coder_version.h"
|
||||
#include "common/4coder_version.h"
|
||||
#include "4coder_keycodes.h"
|
||||
#include "4coder_style.h"
|
||||
#include "4coder_rect.h"
|
||||
|
|
|
@ -435,13 +435,14 @@ static void
|
|||
buffer_seek_string_forward(Application_Links *app, Buffer_Summary *buffer, int32_t pos, int32_t end, char *str, int32_t size, int32_t *result){
|
||||
char read_buffer[512];
|
||||
|
||||
if (size <= 0){
|
||||
*result = pos;
|
||||
}
|
||||
else if (size > sizeof(read_buffer)){
|
||||
*result = pos;
|
||||
if (buffer->size > end){
|
||||
*result = buffer->size;
|
||||
}
|
||||
else{
|
||||
*result = end;
|
||||
}
|
||||
|
||||
if (size > 0 && size <= sizeof(read_buffer)){
|
||||
if (buffer->exists){
|
||||
String read_str = make_fixed_width_string(read_buffer);
|
||||
String needle_str = make_string(str, size);
|
||||
|
@ -488,13 +489,9 @@ buffer_seek_string_forward(Application_Links *app, Buffer_Summary *buffer, int32
|
|||
static void
|
||||
buffer_seek_string_backward(Application_Links *app, Buffer_Summary *buffer, int32_t pos, int32_t min, char *str, int32_t size, int32_t *result){
|
||||
char read_buffer[512];
|
||||
if (size <= 0){
|
||||
*result = min-1;
|
||||
}
|
||||
else if (size > sizeof(read_buffer)){
|
||||
*result = min-1;
|
||||
}
|
||||
else{
|
||||
|
||||
*result = min-1;
|
||||
if (size > 0 && size <= sizeof(read_buffer)){
|
||||
if (buffer->exists){
|
||||
String read_str = make_fixed_width_string(read_buffer);
|
||||
String needle_str = make_string(str, size);
|
||||
|
@ -524,8 +521,6 @@ buffer_seek_string_backward(Application_Links *app, Buffer_Summary *buffer, int3
|
|||
}
|
||||
}
|
||||
|
||||
*result = min-1;
|
||||
|
||||
finished:;
|
||||
}
|
||||
}
|
||||
|
@ -541,13 +536,14 @@ buffer_seek_string_insensitive_forward(Application_Links *app, Buffer_Summary *b
|
|||
Stream_Chunk stream = {0};
|
||||
stream.max_end = end;
|
||||
|
||||
if (size <= 0){
|
||||
*result = buffer->size;
|
||||
}
|
||||
else if (size > sizeof(read_buffer)){
|
||||
if (buffer->size > end){
|
||||
*result = buffer->size;
|
||||
}
|
||||
else{
|
||||
*result = end;
|
||||
}
|
||||
|
||||
if (size > 0 && size <= sizeof(read_buffer)){
|
||||
if (buffer->exists){
|
||||
String read_str = make_fixed_width_string(read_buffer);
|
||||
String needle_str = make_string(str, size);
|
||||
|
@ -573,8 +569,6 @@ buffer_seek_string_insensitive_forward(Application_Links *app, Buffer_Summary *b
|
|||
}
|
||||
}
|
||||
|
||||
*result = buffer->size;
|
||||
|
||||
finished:;
|
||||
}
|
||||
}
|
||||
|
@ -590,13 +584,8 @@ buffer_seek_string_insensitive_backward(Application_Links *app, Buffer_Summary *
|
|||
Stream_Chunk stream = {0};
|
||||
stream.min_start = min;
|
||||
|
||||
if (size <= 0){
|
||||
*result = -1;
|
||||
}
|
||||
else if (size > sizeof(read_buffer)){
|
||||
*result = -1;
|
||||
}
|
||||
else{
|
||||
*result = min-1;
|
||||
if (size > 0 && size <= sizeof(read_buffer)){
|
||||
if (buffer->exists){
|
||||
String read_str = make_fixed_width_string(read_buffer);
|
||||
String needle_str = make_string(str, size);
|
||||
|
@ -622,8 +611,6 @@ buffer_seek_string_insensitive_backward(Application_Links *app, Buffer_Summary *
|
|||
}
|
||||
}
|
||||
|
||||
*result = -1;
|
||||
|
||||
finished:;
|
||||
}
|
||||
}
|
||||
|
@ -3388,65 +3375,65 @@ read_config_line(Cpp_Token_Array array, int32_t *i_ptr){
|
|||
}
|
||||
|
||||
if (subscript_success){
|
||||
if (token.type == CPP_TOKEN_EQ){
|
||||
config_line.eq_token = read_config_token(array, &i);
|
||||
++i;
|
||||
if (i < array.count){
|
||||
Cpp_Token val_token = read_config_token(array, &i);
|
||||
|
||||
bool32 array_success = 1;
|
||||
if (val_token.type == CPP_TOKEN_BRACE_OPEN){
|
||||
array_success = 0;
|
||||
++i;
|
||||
if (i < array.count){
|
||||
config_line.val_array_start = i;
|
||||
|
||||
bool32 expecting_array_item = 1;
|
||||
for (; i < array.count; ++i){
|
||||
Cpp_Token array_token = read_config_token(array, &i);
|
||||
if (array_token.size == 0){
|
||||
break;
|
||||
}
|
||||
if (array_token.type == CPP_TOKEN_BRACE_CLOSE){
|
||||
config_line.val_array_end = i;
|
||||
array_success = 1;
|
||||
break;
|
||||
}
|
||||
else{
|
||||
if (array_token.type == CPP_TOKEN_COMMA){
|
||||
if (!expecting_array_item){
|
||||
expecting_array_item = 1;
|
||||
}
|
||||
else{
|
||||
break;
|
||||
}
|
||||
if (token.type == CPP_TOKEN_EQ){
|
||||
config_line.eq_token = read_config_token(array, &i);
|
||||
++i;
|
||||
if (i < array.count){
|
||||
Cpp_Token val_token = read_config_token(array, &i);
|
||||
|
||||
bool32 array_success = 1;
|
||||
if (val_token.type == CPP_TOKEN_BRACE_OPEN){
|
||||
array_success = 0;
|
||||
++i;
|
||||
if (i < array.count){
|
||||
config_line.val_array_start = i;
|
||||
|
||||
bool32 expecting_array_item = 1;
|
||||
for (; i < array.count; ++i){
|
||||
Cpp_Token array_token = read_config_token(array, &i);
|
||||
if (array_token.size == 0){
|
||||
break;
|
||||
}
|
||||
if (array_token.type == CPP_TOKEN_BRACE_CLOSE){
|
||||
config_line.val_array_end = i;
|
||||
array_success = 1;
|
||||
break;
|
||||
}
|
||||
else{
|
||||
if (expecting_array_item){
|
||||
expecting_array_item = 0;
|
||||
++config_line.val_array_count;
|
||||
if (array_token.type == CPP_TOKEN_COMMA){
|
||||
if (!expecting_array_item){
|
||||
expecting_array_item = 1;
|
||||
}
|
||||
else{
|
||||
break;
|
||||
}
|
||||
}
|
||||
else{
|
||||
if (expecting_array_item){
|
||||
expecting_array_item = 0;
|
||||
++config_line.val_array_count;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (array_success){
|
||||
config_line.val_token = val_token;
|
||||
++i;
|
||||
if (i < array.count){
|
||||
Cpp_Token semicolon_token = read_config_token(array, &i);
|
||||
if (semicolon_token.type == CPP_TOKEN_SEMICOLON){
|
||||
config_line.read_success = 1;
|
||||
|
||||
if (array_success){
|
||||
config_line.val_token = val_token;
|
||||
++i;
|
||||
if (i < array.count){
|
||||
Cpp_Token semicolon_token = read_config_token(array, &i);
|
||||
if (semicolon_token.type == CPP_TOKEN_SEMICOLON){
|
||||
config_line.read_success = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!config_line.read_success){
|
||||
for (; i < array.count; ++i){
|
||||
|
@ -3469,7 +3456,7 @@ get_config_item(Config_Line line, char *mem, Cpp_Token_Array array){
|
|||
item.array = array;
|
||||
item.mem = mem;
|
||||
if (line.id_token.size != 0){
|
||||
item.id = make_string(mem + line.id_token.start, line.id_token.size);
|
||||
item.id = make_string(mem + line.id_token.start, line.id_token.size);
|
||||
}
|
||||
|
||||
if (line.subscript_token.size != 0){
|
||||
|
@ -3488,48 +3475,48 @@ config_var(Config_Item item, char *var_name, int32_t *subscript, uint32_t token_
|
|||
if (item.line.val_token.type == token_type){
|
||||
if ((var_name == 0 && item.id.size == 0) || match(item.id, var_name)){
|
||||
if (subscript){
|
||||
if (item.has_subscript){
|
||||
*subscript = item.subscript_index;
|
||||
}
|
||||
else{
|
||||
subscript_succes = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (subscript_succes){
|
||||
if (var_out){
|
||||
switch (token_type){
|
||||
case CPP_TOKEN_BOOLEAN_CONSTANT:
|
||||
{
|
||||
*(bool32*)var_out = (item.mem[item.line.val_token.start] == 't');
|
||||
}break;
|
||||
|
||||
case CPP_TOKEN_INTEGER_CONSTANT:
|
||||
{
|
||||
String val = make_string(item.mem + item.line.val_token.start, item.line.val_token.size);
|
||||
*(int32_t*)var_out = str_to_int(val);
|
||||
}break;
|
||||
|
||||
case CPP_TOKEN_STRING_CONSTANT:
|
||||
{
|
||||
*(String*)var_out = make_string(item.mem + item.line.val_token.start + 1,item.line.val_token.size - 2);
|
||||
}break;
|
||||
|
||||
case CPP_TOKEN_BRACE_OPEN:
|
||||
{
|
||||
Config_Array_Reader *array_reader = (Config_Array_Reader*)var_out;
|
||||
array_reader->array = item.array;
|
||||
array_reader->mem = item.mem;
|
||||
array_reader->i = item.line.val_array_start;
|
||||
array_reader->val_array_end = item.line.val_array_end;
|
||||
array_reader->good = 1;
|
||||
}break;
|
||||
if (item.has_subscript){
|
||||
*subscript = item.subscript_index;
|
||||
}
|
||||
else{
|
||||
subscript_succes = 0;
|
||||
}
|
||||
}
|
||||
result = 1;
|
||||
|
||||
if (subscript_succes){
|
||||
if (var_out){
|
||||
switch (token_type){
|
||||
case CPP_TOKEN_BOOLEAN_CONSTANT:
|
||||
{
|
||||
*(bool32*)var_out = (item.mem[item.line.val_token.start] == 't');
|
||||
}break;
|
||||
|
||||
case CPP_TOKEN_INTEGER_CONSTANT:
|
||||
{
|
||||
String val = make_string(item.mem + item.line.val_token.start, item.line.val_token.size);
|
||||
*(int32_t*)var_out = str_to_int(val);
|
||||
}break;
|
||||
|
||||
case CPP_TOKEN_STRING_CONSTANT:
|
||||
{
|
||||
*(String*)var_out = make_string(item.mem + item.line.val_token.start + 1,item.line.val_token.size - 2);
|
||||
}break;
|
||||
|
||||
case CPP_TOKEN_BRACE_OPEN:
|
||||
{
|
||||
Config_Array_Reader *array_reader = (Config_Array_Reader*)var_out;
|
||||
array_reader->array = item.array;
|
||||
array_reader->mem = item.mem;
|
||||
array_reader->i = item.line.val_array_start;
|
||||
array_reader->val_array_end = item.line.val_array_end;
|
||||
array_reader->good = 1;
|
||||
}break;
|
||||
}
|
||||
}
|
||||
result = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return(result);
|
||||
}
|
||||
|
||||
|
@ -3585,9 +3572,9 @@ config_array_next_item(Config_Array_Reader *array_reader, Config_Item *item){
|
|||
++array_reader->i;
|
||||
goto doublebreak;
|
||||
}break;
|
||||
}
|
||||
}
|
||||
doublebreak:;
|
||||
}
|
||||
doublebreak:;
|
||||
|
||||
array_reader->good = result;
|
||||
return(result);
|
||||
|
@ -3689,16 +3676,16 @@ process_config_file(Application_Links *app){
|
|||
config_bool_var(item, "enable_code_wrapping", 0, &enable_code_wrapping);
|
||||
config_bool_var(item, "automatically_adjust_wrapping", 0, &automatically_adjust_wrapping);
|
||||
config_bool_var(item, "automatically_indent_text_on_save", 0, &automatically_indent_text_on_save);
|
||||
|
||||
|
||||
config_int_var(item, "default_wrap_width", 0, &new_wrap_width);
|
||||
config_int_var(item, "default_min_base_width", 0, &new_min_base_width);
|
||||
|
||||
|
||||
config_string_var(item, "default_theme_name", 0, &default_theme_name);
|
||||
config_string_var(item, "default_font_name", 0, &default_font_name);
|
||||
}
|
||||
}
|
||||
adjust_all_buffer_wrap_widths(app, new_wrap_width, new_min_base_width);
|
||||
}
|
||||
}
|
||||
}
|
||||
adjust_all_buffer_wrap_widths(app, new_wrap_width, new_min_base_width);
|
||||
}
|
||||
}
|
||||
|
||||
end_temp_memory(temp);
|
||||
|
@ -3748,7 +3735,7 @@ set_project_extensions(Project *project, String src){
|
|||
int32_t j = 0, k = 0;
|
||||
for (int32_t i = 0; i < src.size; ++i){
|
||||
switch (mode){
|
||||
case 0:
|
||||
case 0:
|
||||
{
|
||||
if (src.str[i] == '.'){
|
||||
mode = 1;
|
||||
|
@ -3766,7 +3753,7 @@ set_project_extensions(Project *project, String src){
|
|||
project->extension_space[j++] = src.str[i];
|
||||
}
|
||||
}break;
|
||||
}
|
||||
}
|
||||
}
|
||||
project->extension_space[j++] = 0;
|
||||
project->extension_count = k;
|
||||
|
@ -3778,28 +3765,28 @@ interpret_escaped_string(char *dst, String src){
|
|||
int32_t mode = 0;
|
||||
int32_t j = 0;
|
||||
for (int32_t i = 0; i < src.size; ++i){
|
||||
switch (mode){
|
||||
switch (mode){
|
||||
case 0:
|
||||
{
|
||||
if (src.str[i] == '\\'){
|
||||
mode = 1;
|
||||
if (src.str[i] == '\\'){
|
||||
mode = 1;
|
||||
}
|
||||
else{
|
||||
dst[j++] = src.str[i];
|
||||
}
|
||||
}break;
|
||||
|
||||
case 1:
|
||||
{
|
||||
switch (src.str[i]){
|
||||
case '\\':{dst[j++] = '\\'; mode = 0;}break;
|
||||
case 'n': {dst[j++] = '\n'; mode = 0;}break;
|
||||
case 't': {dst[j++] = '\t'; mode = 0;}break;
|
||||
case '"': {dst[j++] = '"'; mode = 0;}break;
|
||||
case '0': {dst[j++] = '\0'; mode = 0;}break;
|
||||
}
|
||||
}break;
|
||||
}
|
||||
else{
|
||||
dst[j++] = src.str[i];
|
||||
}
|
||||
}break;
|
||||
|
||||
case 1:
|
||||
{
|
||||
switch (src.str[i]){
|
||||
case '\\':{dst[j++] = '\\'; mode = 0;}break;
|
||||
case 'n': {dst[j++] = '\n'; mode = 0;}break;
|
||||
case 't': {dst[j++] = '\t'; mode = 0;}break;
|
||||
case '"': {dst[j++] = '"'; mode = 0;}break;
|
||||
case '0': {dst[j++] = '\0'; mode = 0;}break;
|
||||
}
|
||||
}break;
|
||||
}
|
||||
}
|
||||
dst[j] = 0;
|
||||
}
|
||||
|
@ -3817,37 +3804,37 @@ close_all_files_with_extension(Application_Links *app, Partition *scratch_part,
|
|||
buffers_to_close_count = 0;
|
||||
do_repeat = 0;
|
||||
|
||||
uint32_t access = AccessAll;
|
||||
Buffer_Summary buffer = {0};
|
||||
for (buffer = get_buffer_first(app, access);
|
||||
buffer.exists;
|
||||
get_buffer_next(app, &buffer, access)){
|
||||
|
||||
bool32 is_match = 1;
|
||||
if (extension_count > 0){
|
||||
String extension = file_extension(make_string(buffer.file_name, buffer.file_name_len));
|
||||
is_match = 0;
|
||||
for (int32_t i = 0; i < extension_count; ++i){
|
||||
if (match(extension, extension_list[i])){
|
||||
is_match = 1;
|
||||
break;
|
||||
uint32_t access = AccessAll;
|
||||
Buffer_Summary buffer = {0};
|
||||
for (buffer = get_buffer_first(app, access);
|
||||
buffer.exists;
|
||||
get_buffer_next(app, &buffer, access)){
|
||||
|
||||
bool32 is_match = 1;
|
||||
if (extension_count > 0){
|
||||
String extension = file_extension(make_string(buffer.file_name, buffer.file_name_len));
|
||||
is_match = 0;
|
||||
for (int32_t i = 0; i < extension_count; ++i){
|
||||
if (match(extension, extension_list[i])){
|
||||
is_match = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (is_match){
|
||||
if (buffers_to_close_count >= buffers_to_close_max){
|
||||
do_repeat = 1;
|
||||
break;
|
||||
}
|
||||
buffers_to_close[buffers_to_close_count++] = buffer.buffer_id;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_match){
|
||||
if (buffers_to_close_count >= buffers_to_close_max){
|
||||
do_repeat = 1;
|
||||
break;
|
||||
}
|
||||
buffers_to_close[buffers_to_close_count++] = buffer.buffer_id;
|
||||
for (int32_t i = 0; i < buffers_to_close_count; ++i){
|
||||
kill_buffer(app, buffer_identifier(buffers_to_close[i]), true, 0);
|
||||
}
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < buffers_to_close_count; ++i){
|
||||
kill_buffer(app, buffer_identifier(buffers_to_close[i]), true, 0);
|
||||
}
|
||||
}
|
||||
while(do_repeat);
|
||||
|
||||
end_temp_memory(temp);
|
||||
|
@ -3876,31 +3863,31 @@ open_all_files_with_extension(Application_Links *app, Partition *scratch_part, c
|
|||
if (extension_count > 0){
|
||||
is_match = 0;
|
||||
|
||||
String extension = make_string_cap(info->filename, info->filename_len, info->filename_len+1);
|
||||
extension = file_extension(extension);
|
||||
String extension = make_string_cap(info->filename, info->filename_len, info->filename_len+1);
|
||||
extension = file_extension(extension);
|
||||
for (int32_t j = 0; j < extension_count; ++j){
|
||||
if (match(extension, extension_list[j])){
|
||||
is_match = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_match){
|
||||
// NOTE(allen): There's no way in the 4coder API to use relative
|
||||
// paths at the moment, so everything should be full paths. Which is
|
||||
// managable. Here simply set the dir string size back to where it
|
||||
// was originally, so that new appends overwrite old ones.
|
||||
dir.size = dir_size;
|
||||
append_sc(&dir, info->filename);
|
||||
create_buffer(app, dir.str, dir.size, 0);
|
||||
}
|
||||
|
||||
if (is_match){
|
||||
// NOTE(allen): There's no way in the 4coder API to use relative
|
||||
// paths at the moment, so everything should be full paths. Which is
|
||||
// managable. Here simply set the dir string size back to where it
|
||||
// was originally, so that new appends overwrite old ones.
|
||||
dir.size = dir_size;
|
||||
append_sc(&dir, info->filename);
|
||||
create_buffer(app, dir.str, dir.size, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
free_file_list(app, list);
|
||||
|
||||
end_temp_memory(temp);
|
||||
|
||||
end_temp_memory(temp);
|
||||
}
|
||||
|
||||
static char**
|
||||
|
@ -3968,10 +3955,10 @@ CUSTOM_COMMAND_SIG(load_project){
|
|||
|
||||
if (result == LexResult_Finished){
|
||||
// Clear out current project
|
||||
if (current_project.close_all_code_when_this_project_closes){
|
||||
exec_command(app, close_all_code);
|
||||
}
|
||||
current_project = null_project;
|
||||
if (current_project.close_all_code_when_this_project_closes){
|
||||
exec_command(app, close_all_code);
|
||||
}
|
||||
current_project = null_project;
|
||||
|
||||
// Set new project directory
|
||||
{
|
||||
|
@ -3992,9 +3979,9 @@ CUSTOM_COMMAND_SIG(load_project){
|
|||
String str = {0};
|
||||
if (config_string_var(item, "extensions", 0, &str)){
|
||||
if (str.size < sizeof(current_project.extension_space)){
|
||||
set_project_extensions(¤t_project, str);
|
||||
print_message(app, str.str, str.size);
|
||||
print_message(app, "\n", 1);
|
||||
set_project_extensions(¤t_project, str);
|
||||
print_message(app, str.str, str.size);
|
||||
print_message(app, "\n", 1);
|
||||
}
|
||||
else{
|
||||
print_message(app, literal("STRING TOO LONG!\n"));
|
||||
|
@ -4067,35 +4054,35 @@ CUSTOM_COMMAND_SIG(load_project){
|
|||
}
|
||||
|
||||
if (read_string){
|
||||
if (config_int_var(array_item, 0, 0, 0)){
|
||||
append(&msg, "NULL, ");
|
||||
dest_str[0] = 0;
|
||||
if (config_int_var(array_item, 0, 0, 0)){
|
||||
append(&msg, "NULL, ");
|
||||
dest_str[0] = 0;
|
||||
}
|
||||
|
||||
String str = {0};
|
||||
if (config_string_var(array_item, 0, 0, &str)){
|
||||
if (str.size < dest_str_size){
|
||||
interpret_escaped_string(dest_str, str);
|
||||
append(&msg, dest_str);
|
||||
append(&msg, ", ");
|
||||
}
|
||||
else{
|
||||
append(&msg, "STRING TOO LONG!, ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String str = {0};
|
||||
if (config_string_var(array_item, 0, 0, &str)){
|
||||
if (str.size < dest_str_size){
|
||||
interpret_escaped_string(dest_str, str);
|
||||
append(&msg, dest_str);
|
||||
append(&msg, ", ");
|
||||
}
|
||||
else{
|
||||
append(&msg, "STRING TOO LONG!, ");
|
||||
if (read_bool){
|
||||
if (config_bool_var(array_item, 0, 0, dest_bool)){
|
||||
if (dest_bool){
|
||||
append(&msg, "true, ");
|
||||
}
|
||||
else{
|
||||
append(&msg, "false, ");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (read_bool){
|
||||
if (config_bool_var(array_item, 0, 0, dest_bool)){
|
||||
if (dest_bool){
|
||||
append(&msg, "true, ");
|
||||
}
|
||||
else{
|
||||
append(&msg, "false, ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
item_index++;
|
||||
}
|
||||
|
||||
|
@ -4106,7 +4093,7 @@ CUSTOM_COMMAND_SIG(load_project){
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (current_project.close_all_files_when_project_opens){
|
||||
close_all_files_with_extension(app, &global_part, 0, 0);
|
||||
}
|
||||
|
|
|
@ -264,11 +264,7 @@ match_check(Application_Links *app, Search_Range *range, int32_t *pos, Search_Ma
|
|||
}
|
||||
|
||||
static int32_t
|
||||
search_front_to_back_step(Application_Links *app,
|
||||
Search_Range *range,
|
||||
String word,
|
||||
int32_t *pos,
|
||||
Search_Match *result_ptr){
|
||||
search_front_to_back_step(Application_Links *app, Search_Range *range, String word, int32_t *pos, Search_Match *result_ptr){
|
||||
int32_t found_match = FindResult_None;
|
||||
|
||||
Search_Match result = *result_ptr;
|
||||
|
@ -284,16 +280,10 @@ search_front_to_back_step(Application_Links *app,
|
|||
|
||||
result.buffer = get_buffer(app, range->buffer, AccessAll);
|
||||
if (case_insensitive){
|
||||
buffer_seek_string_insensitive_forward(app, &result.buffer,
|
||||
start_pos, end_pos,
|
||||
word.str, word.size,
|
||||
&result.start);
|
||||
buffer_seek_string_insensitive_forward(app, &result.buffer, start_pos, end_pos, word.str, word.size, &result.start);
|
||||
}
|
||||
else{
|
||||
buffer_seek_string_forward(app, &result.buffer,
|
||||
start_pos, end_pos,
|
||||
word.str, word.size,
|
||||
&result.start);
|
||||
buffer_seek_string_forward(app, &result.buffer, start_pos, end_pos, word.str, word.size, &result.start);
|
||||
}
|
||||
|
||||
if (result.start < end_pos){
|
||||
|
@ -319,11 +309,7 @@ search_front_to_back_step(Application_Links *app,
|
|||
}
|
||||
|
||||
static int32_t
|
||||
search_front_to_back(Application_Links *app,
|
||||
Search_Range *range,
|
||||
String word,
|
||||
int32_t *pos,
|
||||
Search_Match *result_ptr){
|
||||
search_front_to_back(Application_Links *app, Search_Range *range, String word, int32_t *pos, Search_Match *result_ptr){
|
||||
int32_t found_match = FindResult_None;
|
||||
for (;found_match == FindResult_None;){
|
||||
found_match = search_front_to_back_step(app, range, word, pos, result_ptr);
|
||||
|
@ -332,11 +318,7 @@ search_front_to_back(Application_Links *app,
|
|||
}
|
||||
|
||||
static int32_t
|
||||
search_back_to_front_step(Application_Links *app,
|
||||
Search_Range *range,
|
||||
String word,
|
||||
int32_t *pos,
|
||||
Search_Match *result_ptr){
|
||||
search_back_to_front_step(Application_Links *app, Search_Range *range, String word, int32_t *pos, Search_Match *result_ptr){
|
||||
int32_t found_match = FindResult_None;
|
||||
|
||||
Search_Match result = *result_ptr;
|
||||
|
@ -372,11 +354,7 @@ search_back_to_front_step(Application_Links *app,
|
|||
}
|
||||
|
||||
static int32_t
|
||||
search_back_to_front(Application_Links *app,
|
||||
Search_Range *range,
|
||||
String word,
|
||||
int32_t *pos,
|
||||
Search_Match *result_ptr){
|
||||
search_back_to_front(Application_Links *app, Search_Range *range, String word, int32_t *pos, Search_Match *result_ptr){
|
||||
int32_t found_match = FindResult_None;
|
||||
for (;found_match == FindResult_None;){
|
||||
found_match = search_back_to_front_step(app, range, word, pos, result_ptr);
|
||||
|
|
|
@ -39,14 +39,14 @@ TYPEDEF int32_t View_ID;
|
|||
|
||||
/* DOC(A Key_Modifier acts as an index for specifying modifiers in arrays.) */
|
||||
ENUM(int32_t, Key_Modifier){
|
||||
MDFR_SHIFT_INDEX,
|
||||
MDFR_CONTROL_INDEX,
|
||||
MDFR_ALT_INDEX,
|
||||
MDFR_SHIFT_INDEX,
|
||||
MDFR_CONTROL_INDEX,
|
||||
MDFR_ALT_INDEX,
|
||||
MDFR_CAPS_INDEX,
|
||||
MDFR_HOLD_INDEX,
|
||||
|
||||
/* DOC(MDFR_INDEX_COUNT is used to specify the number of modifiers supported.) */
|
||||
MDFR_INDEX_COUNT
|
||||
MDFR_INDEX_COUNT
|
||||
};
|
||||
|
||||
/* DOC(A Key_Modifier_Flag field is used to specify a specific state of modifiers.
|
||||
|
@ -231,7 +231,7 @@ ENUM(uint32_t, Buffer_Create_Flag){
|
|||
|
||||
/* DOC(Buffer_Creation_Data is a struct used as a local handle for the creation of a buffer. )
|
||||
HIDE_MEMBERS() */
|
||||
STRUCT Buffer_Creation_Data{
|
||||
STRUCT Buffer_Creation_Data{
|
||||
Buffer_Create_Flag flags;
|
||||
char fname_space [256];
|
||||
int32_t fname_len;
|
||||
|
@ -343,7 +343,7 @@ ENUM(int32_t, Mouse_Cursor_Show_Type){
|
|||
MouseCursorShow_Never,
|
||||
/* DOC(The MouseCursorShow_Never mode always shows the cursor.) */
|
||||
MouseCursorShow_Always,
|
||||
// MouseCursorShow_WhenActive,// TODO(allen): coming soon
|
||||
// MouseCursorShow_WhenActive,// TODO(allen): coming soon
|
||||
};
|
||||
|
||||
/* DOC(A View_Split_Position specifies where a new view should be placed as a result of a view split operation.) */
|
||||
|
@ -359,7 +359,7 @@ ENUM(int32_t, View_Split_Position){
|
|||
};
|
||||
|
||||
/* DOC(Generic_Command acts as a name for a command, and can name an internal command or a custom command.) */
|
||||
UNION Generic_Command{
|
||||
UNION Generic_Command{
|
||||
/*DOC(If this Generic_Command represents an internal command the cmdid field will have a value less than cmdid_count, and this field is the command id for the command.)*/
|
||||
Command_ID cmdid;
|
||||
/*DOC(If this Generic_Command does not represent an internal command the command
|
||||
|
@ -370,23 +370,23 @@ ENUM(int32_t, View_Split_Position){
|
|||
/* DOC(Key_Event_Data describes a key event, including the translation to a character, the translation to a character ignoring the state of caps lock, and an array of all the modifiers that were pressed at the time of the event.) */
|
||||
STRUCT Key_Event_Data{
|
||||
/* DOC(This field is the raw keycode which is always non-zero in valid key events.) */
|
||||
Key_Code keycode;
|
||||
Key_Code keycode;
|
||||
|
||||
/* DOC(This field is the keycode after translation to a character, this is 0 if there is no translation.) */
|
||||
Key_Code character;
|
||||
Key_Code character;
|
||||
|
||||
/* DOC(This field is like the field character, except that the state of caps lock is ignored in the translation.) */
|
||||
Key_Code character_no_caps_lock;
|
||||
Key_Code character_no_caps_lock;
|
||||
|
||||
/* DOC(This field is an array indicating the state of modifiers at the time of the key press. The array is indexed using the values of Key_Modifier. A 1 indicates that the corresponding modifier was held, and a 0 indicates that it was not held.)
|
||||
|
||||
DOC_SEE(Key_Modifier)
|
||||
*/
|
||||
char modifiers[MDFR_INDEX_COUNT];
|
||||
char modifiers[MDFR_INDEX_COUNT];
|
||||
};
|
||||
|
||||
/* DOC(Mouse_State describes an entire mouse state complete with the position, left and right button states, the wheel state, and whether or not the mouse if in the window.) */
|
||||
STRUCT Mouse_State{
|
||||
STRUCT Mouse_State{
|
||||
/* DOC(This field indicates that the left button is held.) */
|
||||
char l;
|
||||
/* DOC(This field indicates that the right button is held.) */
|
||||
|
@ -402,9 +402,9 @@ STRUCT Key_Event_Data{
|
|||
/* DOC(
|
||||
This field is 0 when the wheel has not moved, it is 1 for a downward motion and -1 for an upward motion.
|
||||
) */
|
||||
char wheel;
|
||||
char wheel;
|
||||
/* DOC(This field indicates that the mouse is outside of the window.) */
|
||||
char out_of_window;
|
||||
char out_of_window;
|
||||
/* DOC(This field contains the x position of the mouse relative to the window where the left side is 0.) */
|
||||
int32_t x;
|
||||
/* DOC(This field contains the y position of the mouse relative to the window where the top side is 0.) */
|
||||
|
@ -456,7 +456,7 @@ STRUCT File_List{
|
|||
};
|
||||
|
||||
/* DOC(Buffer_Identifier acts as a loosely typed description of a buffer that can either be a name or an id.) */
|
||||
STRUCT Buffer_Identifier{
|
||||
STRUCT Buffer_Identifier{
|
||||
/* DOC(This field is the name of the buffer; it need not be null terminated. If id is specified this pointer should be NULL.) */
|
||||
char *name;
|
||||
|
||||
|
@ -464,7 +464,7 @@ STRUCT File_List{
|
|||
int32_t name_len;
|
||||
|
||||
/* DOC(This field is the id of the buffer. If name is specified this should be 0.) */
|
||||
Buffer_ID id;
|
||||
Buffer_ID id;
|
||||
};
|
||||
|
||||
/* DOC(This struct is a part of an incomplete feature.) */
|
||||
|
@ -684,7 +684,7 @@ DOC(User_Input describes a user input event which can be either a key press or m
|
|||
DOC_SEE(User_Input_Type_ID)
|
||||
DOC_SEE(Generic_Command)
|
||||
*/
|
||||
STRUCT User_Input{
|
||||
STRUCT User_Input{
|
||||
/* DOC(This field specifies whether the event was a key press or mouse event.) */
|
||||
User_Input_Type_ID type;
|
||||
/* DOC(This field indicates that an abort event has occurred and the command needs to shut down.) */
|
||||
|
@ -701,7 +701,7 @@ DOC_SEE(Generic_Command)
|
|||
|
||||
/* DOC(Query_Bar is a struct used to store information in the user's control
|
||||
that will be displayed as a drop down bar durring an interactive command.) */
|
||||
STRUCT Query_Bar{
|
||||
STRUCT Query_Bar{
|
||||
/* DOC(This specifies the prompt portion of the drop down bar.) */
|
||||
String prompt;
|
||||
/* DOC(This specifies the main string portion of the drop down bar.) */
|
||||
|
|
62
4cpp_lexer.h
62
4cpp_lexer.h
|
@ -149,6 +149,10 @@ static String_And_Flag keywords[] = {
|
|||
{make_lit_string("register") , CPP_TOKEN_KEY_OTHER},
|
||||
{make_lit_string("this") , CPP_TOKEN_KEY_OTHER},
|
||||
{make_lit_string("thread_local") , CPP_TOKEN_KEY_OTHER},
|
||||
|
||||
#if defined(FCPP_LEXER_EXTRA_KEYWORDS)
|
||||
FCPP_LEXER_EXTRA_KEYWORDS
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
|
@ -171,7 +175,7 @@ DOC_SEE(Cpp_Get_Token_Result)
|
|||
Cpp_Get_Token_Result result = {};
|
||||
Cpp_Token *token_array = array.tokens;
|
||||
Cpp_Token *token = 0;
|
||||
int32_t first = 0;
|
||||
int32_t first = 0;
|
||||
int32_t count = array.count;
|
||||
int32_t last = count;
|
||||
int32_t this_start = 0, next_start = 0;
|
||||
|
@ -218,7 +222,7 @@ DOC_SEE(Cpp_Get_Token_Result)
|
|||
result.token_index = -1;
|
||||
result.in_whitespace = 1;
|
||||
}
|
||||
|
||||
|
||||
if (result.token_index >= 0 && result.token_index < count){
|
||||
token = array.tokens + result.token_index;
|
||||
result.token_start = token->start;
|
||||
|
@ -939,7 +943,7 @@ cpp_lex_nonalloc_no_null_out_limit(Cpp_Lex_Data *S_ptr, char *chunk, int32_t siz
|
|||
}
|
||||
|
||||
Cpp_Lex_Result result = cpp_lex_nonalloc_no_null_no_limit(S_ptr, chunk, size, full_size,
|
||||
&temp_stack);
|
||||
&temp_stack);
|
||||
|
||||
token_array_out->count = temp_stack.count;
|
||||
|
||||
|
@ -996,23 +1000,23 @@ to make sure it returns LexResult_Finished to you:
|
|||
|
||||
CODE_EXAMPLE(
|
||||
Cpp_Token_Array lex_file(char *file_name){
|
||||
File_Data file = read_whole_file(file_name);
|
||||
|
||||
char *temp = (char*)malloc(4096); // hopefully big enough
|
||||
Cpp_Lex_Data lex_state = cpp_lex_data_init(temp);
|
||||
|
||||
Cpp_Token_Array array = {0};
|
||||
array.tokens = (Cpp_Token*)malloc(1 << 20); // hopefully big enough
|
||||
array.max_count = (1 << 20)/sizeof(Cpp_Token);
|
||||
|
||||
Cpp_Lex_Result result =
|
||||
cpp_lex_step(&lex_state, file.data, file.size, file.size,
|
||||
&array, NO_OUT_LIMIT);
|
||||
Assert(result == LexResult_Finished);
|
||||
|
||||
free(temp);
|
||||
|
||||
return(array);
|
||||
File_Data file = read_whole_file(file_name);
|
||||
|
||||
char *temp = (char*)malloc(4096); // hopefully big enough
|
||||
Cpp_Lex_Data lex_state = cpp_lex_data_init(temp);
|
||||
|
||||
Cpp_Token_Array array = {0};
|
||||
array.tokens = (Cpp_Token*)malloc(1 << 20); // hopefully big enough
|
||||
array.max_count = (1 << 20)/sizeof(Cpp_Token);
|
||||
|
||||
Cpp_Lex_Result result =
|
||||
cpp_lex_step(&lex_state, file.data, file.size, file.size,
|
||||
&array, NO_OUT_LIMIT);
|
||||
Assert(result == LexResult_Finished);
|
||||
|
||||
free(temp);
|
||||
|
||||
return(array);
|
||||
})
|
||||
|
||||
)
|
||||
|
@ -1538,15 +1542,15 @@ it is quick and convenient to lex files.
|
|||
|
||||
CODE_EXAMPLE(
|
||||
Cpp_Token_Array lex_file(char *file_name){
|
||||
File_Data file = read_whole_file(file_name);
|
||||
|
||||
// This array will be automatically grown if it runs
|
||||
// out of memory.
|
||||
Cpp_Token_Array array = cpp_make_token_array(100);
|
||||
|
||||
cpp_lex_file(file.data, file.size, &array);
|
||||
|
||||
return(array);
|
||||
File_Data file = read_whole_file(file_name);
|
||||
|
||||
// This array will be automatically grown if it runs
|
||||
// out of memory.
|
||||
Cpp_Token_Array array = cpp_make_token_array(100);
|
||||
|
||||
cpp_lex_file(file.data, file.size, &array);
|
||||
|
||||
return(array);
|
||||
})
|
||||
|
||||
)
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
// TODO(allen): can I get away from this one?
|
||||
#include <assert.h>
|
||||
#include "4ed_defines.h"
|
||||
#include "common/4coder_defines.h"
|
||||
|
||||
#define FSTRING_IMPLEMENTATION
|
||||
#define FSTRING_C
|
||||
|
@ -41,11 +41,8 @@
|
|||
#include "4ed_style.cpp"
|
||||
#include "4ed_command.cpp"
|
||||
|
||||
#include "buffer/4coder_shared.cpp"
|
||||
#include "buffer/4coder_gap_buffer.cpp"
|
||||
#define Buffer_Type Gap_Buffer
|
||||
#include "buffer/4coder_buffer_abstract.cpp"
|
||||
|
||||
#include "file/4coder_buffer.cpp"
|
||||
#include "file/4coder_undo.cpp"
|
||||
#include "file/4coder_file.cpp"
|
||||
#include "file/4coder_working_set.cpp"
|
||||
#include "file/4coder_hot_directory.cpp"
|
||||
|
|
|
@ -440,7 +440,7 @@ view_compute_cursor(View *view, Buffer_Seek seek, b32 return_hint){
|
|||
first_wrap_determination = 0;
|
||||
}
|
||||
else{
|
||||
assert_4tech(stop.pos == wrap_unit_end);
|
||||
assert(stop.pos == wrap_unit_end);
|
||||
do_wrap = 1;
|
||||
++wrap_array_index;
|
||||
wrap_unit_end = file->state.wrap_positions[wrap_array_index];
|
||||
|
@ -484,7 +484,7 @@ internal i32
|
|||
file_compute_lowest_line(Editing_File *file, f32 font_height){
|
||||
i32 lowest_line = 0;
|
||||
|
||||
Buffer_Type *buffer = &file->state.buffer;
|
||||
Gap_Buffer *buffer = &file->state.buffer;
|
||||
if (file->settings.unwrapped_lines){
|
||||
lowest_line = buffer->line_count;
|
||||
}
|
||||
|
@ -755,7 +755,7 @@ save_file_to_name(System_Functions *system, Models *models, Editing_File *file,
|
|||
i32 max = 0, size = 0;
|
||||
b32 dos_write_mode = file->settings.dos_write_mode;
|
||||
char *data = 0;
|
||||
Buffer_Type *buffer = &file->state.buffer;
|
||||
Gap_Buffer *buffer = &file->state.buffer;
|
||||
|
||||
if (dos_write_mode){
|
||||
max = buffer_size(buffer) + buffer->line_count + 1;
|
||||
|
@ -847,14 +847,14 @@ enum{
|
|||
};
|
||||
|
||||
internal i32
|
||||
file_grow_starts_as_needed(System_Functions *system, General_Memory *general, Buffer_Type *buffer, i32 additional_lines){
|
||||
file_grow_starts_as_needed(System_Functions *system, General_Memory *general, Gap_Buffer *buffer, i32 additional_lines){
|
||||
b32 result = GROW_NOT_NEEDED;
|
||||
i32 max = buffer->line_max;
|
||||
i32 count = buffer->line_count;
|
||||
i32 target_lines = count + additional_lines;
|
||||
|
||||
if (target_lines > max || max == 0){
|
||||
max = LargeRoundUp(target_lines + max, Kbytes(1));
|
||||
max = l_round_up_i32(target_lines + max, Kbytes(1));
|
||||
|
||||
i32 *new_lines = (i32*)general_memory_reallocate(system, general, buffer->line_starts, sizeof(i32)*count, sizeof(f32)*max);
|
||||
|
||||
|
@ -894,7 +894,7 @@ file_update_cursor_positions(Models *models, Editing_File *file){
|
|||
//
|
||||
|
||||
internal void
|
||||
file_measure_starts(System_Functions *system, General_Memory *general, Buffer_Type *buffer){
|
||||
file_measure_starts(System_Functions *system, General_Memory *general, Gap_Buffer *buffer){
|
||||
if (!buffer->line_starts){
|
||||
i32 max = buffer->line_max = Kbytes(1);
|
||||
buffer->line_starts = (i32*)general_memory_allocate(system, general, max*sizeof(i32));
|
||||
|
@ -922,7 +922,7 @@ file_measure_starts(System_Functions *system, General_Memory *general, Buffer_Ty
|
|||
// NOTE(allen): These calls assumes that the buffer's line starts are already correct,
|
||||
// and that the buffer's line_count is correct.
|
||||
internal void
|
||||
file_allocate_metadata_as_needed(System_Functions *system, General_Memory *general, Buffer_Type *buffer, void **mem, i32 *mem_max_count, i32 count, i32 item_size){
|
||||
file_allocate_metadata_as_needed(System_Functions *system, General_Memory *general, Gap_Buffer *buffer, void **mem, i32 *mem_max_count, i32 count, i32 item_size){
|
||||
if (*mem == 0){
|
||||
i32 max = ((count+1)*2);
|
||||
max = (max+(0x3FF))&(~(0x3FF));
|
||||
|
@ -996,7 +996,7 @@ struct Code_Wrap_State{
|
|||
f32 x;
|
||||
b32 consume_newline;
|
||||
|
||||
Buffer_Stream_Type stream;
|
||||
Gap_Buffer_Stream stream;
|
||||
i32 i;
|
||||
|
||||
f32 *adv;
|
||||
|
@ -1012,7 +1012,7 @@ wrap_state_init(Code_Wrap_State *state, Editing_File *file, f32 *adv){
|
|||
state->line_starts = file->state.buffer.line_starts;
|
||||
state->next_line_start = state->line_starts[1];
|
||||
|
||||
Buffer_Type *buffer = &file->state.buffer;
|
||||
Gap_Buffer *buffer = &file->state.buffer;
|
||||
i32 size = buffer_size(buffer);
|
||||
buffer_stringify_loop(&state->stream, buffer, 0, size);
|
||||
|
||||
|
@ -1262,9 +1262,11 @@ stickieness_guess(Cpp_Token_Type type, Cpp_Token_Type other_type, u16 flags, u16
|
|||
guess = 1000;
|
||||
}
|
||||
}
|
||||
else if (type == CPP_TOKEN_COMMA){
|
||||
guess = 20;
|
||||
}
|
||||
else if (type == CPP_TOKEN_COLON ||
|
||||
type == CPP_TOKEN_PARENTHESE_CLOSE ||
|
||||
type == CPP_TOKEN_COMMA ||
|
||||
type == CPP_TOKEN_BRACKET_OPEN ||
|
||||
type == CPP_TOKEN_BRACKET_CLOSE){
|
||||
if (on_left){
|
||||
|
@ -1490,7 +1492,7 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file,
|
|||
}
|
||||
}
|
||||
else{
|
||||
Buffer_Stream_Type stream = {0};
|
||||
Gap_Buffer_Stream stream = {0};
|
||||
|
||||
i32 word_stage = 0;
|
||||
i32 i = stop.pos;
|
||||
|
@ -1603,7 +1605,7 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file,
|
|||
step.start_x = x;
|
||||
step.this_token = wrap_state.token_ptr;
|
||||
|
||||
Buffer_Stream_Type stream = {0};
|
||||
Gap_Buffer_Stream stream = {0};
|
||||
|
||||
Potential_Wrap_Indent_Pair potential_wrap = {0};
|
||||
potential_wrap.wrap_position = i;
|
||||
|
@ -1737,6 +1739,10 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file,
|
|||
general_stickieness = next_stickieness;
|
||||
}
|
||||
|
||||
if (wrap_state.wrap_x.paren_top != 0 && this_type == CPP_TOKEN_COMMA){
|
||||
general_stickieness = 0;
|
||||
}
|
||||
|
||||
wrappable_score = 64*50;
|
||||
wrappable_score += 101 - general_stickieness - wrap_state.wrap_x.paren_safe_top*80;
|
||||
|
||||
|
@ -1893,14 +1899,14 @@ file_create_from_string(System_Functions *system, Models *models,
|
|||
Font_Set *font_set = models->font_set;
|
||||
General_Memory *general = &models->mem.general;
|
||||
Partition *part = &models->mem.part;
|
||||
Buffer_Init_Type init;
|
||||
Gap_Buffer_Init init;
|
||||
|
||||
file->state = null_editing_file_state;
|
||||
|
||||
init = buffer_begin_init(&file->state.buffer, val.str, val.size);
|
||||
for (; buffer_init_need_more(&init); ){
|
||||
i32 page_size = buffer_init_page_size(&init);
|
||||
page_size = LargeRoundUp(page_size, Kbytes(4));
|
||||
page_size = l_round_up_i32(page_size, Kbytes(4));
|
||||
if (page_size < Kbytes(4)) page_size = Kbytes(4);
|
||||
void *data = general_memory_allocate(system, general, page_size);
|
||||
buffer_init_provide_page(&init, data, page_size);
|
||||
|
@ -1977,7 +1983,7 @@ file_close(System_Functions *system, General_Memory *general, Editing_File *file
|
|||
general_memory_free(system, general, file->state.token_array.tokens);
|
||||
}
|
||||
|
||||
Buffer_Type *buffer = &file->state.buffer;
|
||||
Gap_Buffer *buffer = &file->state.buffer;
|
||||
if (buffer->data){
|
||||
general_memory_free(system, general, buffer->data);
|
||||
general_memory_free(system, general, buffer->line_starts);
|
||||
|
@ -2012,7 +2018,7 @@ Job_Callback_Sig(job_full_lex){
|
|||
Editing_File *file = (Editing_File*)data[0];
|
||||
General_Memory *general = (General_Memory*)data[1];
|
||||
|
||||
Buffer_Type *buffer = &file->state.buffer;
|
||||
Gap_Buffer *buffer = &file->state.buffer;
|
||||
i32 text_size = buffer_size(buffer);
|
||||
|
||||
i32 aligned_buffer_size = (text_size + 3)&(~3);
|
||||
|
@ -2074,7 +2080,7 @@ Job_Callback_Sig(job_full_lex){
|
|||
}
|
||||
} while (still_lexing);
|
||||
|
||||
i32 new_max = LargeRoundUp(tokens.count+1, Kbytes(1));
|
||||
i32 new_max = l_round_up_i32(tokens.count+1, Kbytes(1));
|
||||
|
||||
system->acquire_lock(FRAME_LOCK);
|
||||
{
|
||||
|
@ -2158,7 +2164,7 @@ file_first_lex_serial(System_Functions *system, Mem_Options *mem, Editing_File *
|
|||
{
|
||||
Temp_Memory temp = begin_temp_memory(part);
|
||||
|
||||
Buffer_Type *buffer = &file->state.buffer;
|
||||
Gap_Buffer *buffer = &file->state.buffer;
|
||||
i32 text_size = buffer_size(buffer);
|
||||
|
||||
i32 mem_size = partition_remaining(part);
|
||||
|
@ -2201,7 +2207,7 @@ file_first_lex_serial(System_Functions *system, Mem_Options *mem, Editing_File *
|
|||
}
|
||||
} while (still_lexing);
|
||||
|
||||
i32 new_max = LargeRoundUp(tokens.count+1, Kbytes(1));
|
||||
i32 new_max = l_round_up_i32(tokens.count+1, Kbytes(1));
|
||||
|
||||
{
|
||||
Assert(file->state.swap_array.tokens == 0);
|
||||
|
@ -2250,7 +2256,7 @@ file_relex_parallel(System_Functions *system, Mem_Options *mem, Editing_File *fi
|
|||
b32 result = 1;
|
||||
b32 inline_lex = !file->state.still_lexing;
|
||||
if (inline_lex){
|
||||
Buffer_Type *buffer = &file->state.buffer;
|
||||
Gap_Buffer *buffer = &file->state.buffer;
|
||||
i32 extra_tolerance = 100;
|
||||
|
||||
Cpp_Token_Array *array = &file->state.token_array;
|
||||
|
@ -2315,7 +2321,7 @@ file_relex_parallel(System_Functions *system, Mem_Options *mem, Editing_File *fi
|
|||
if (inline_lex){
|
||||
i32 new_count = cpp_relex_get_new_count(&state, array->count, &relex_array);
|
||||
if (new_count > array->max_count){
|
||||
i32 new_max = LargeRoundUp(new_count, Kbytes(1));
|
||||
i32 new_max = l_round_up_i32(new_count, Kbytes(1));
|
||||
array->tokens = (Cpp_Token*)
|
||||
general_memory_reallocate(system, general, array->tokens, array->count*sizeof(Cpp_Token), new_max*sizeof(Cpp_Token));
|
||||
array->max_count = new_max;
|
||||
|
@ -2376,7 +2382,7 @@ file_relex_serial(System_Functions *system, Mem_Options *mem, Editing_File *file
|
|||
|
||||
Assert(!file->state.still_lexing);
|
||||
|
||||
Buffer_Type *buffer = &file->state.buffer;
|
||||
Gap_Buffer *buffer = &file->state.buffer;
|
||||
Cpp_Token_Array *array = &file->state.token_array;
|
||||
|
||||
Temp_Memory temp = begin_temp_memory(part);
|
||||
|
@ -2430,7 +2436,7 @@ file_relex_serial(System_Functions *system, Mem_Options *mem, Editing_File *file
|
|||
|
||||
i32 new_count = cpp_relex_get_new_count(&state, array->count, &relex_array);
|
||||
if (new_count > array->max_count){
|
||||
i32 new_max = LargeRoundUp(new_count, Kbytes(1));
|
||||
i32 new_max = l_round_up_i32(new_count, Kbytes(1));
|
||||
array->tokens = (Cpp_Token*)
|
||||
general_memory_reallocate(system, general, array->tokens, array->count*sizeof(Cpp_Token), new_max*sizeof(Cpp_Token));
|
||||
array->max_count = new_max;
|
||||
|
@ -3137,7 +3143,7 @@ file_do_single_edit(System_Functions *system, Models *models, Editing_File *file
|
|||
}
|
||||
|
||||
// NOTE(allen): meta data
|
||||
Buffer_Type *buffer = &file->state.buffer;
|
||||
Gap_Buffer *buffer = &file->state.buffer;
|
||||
i32 line_start = buffer_get_line_index(&file->state.buffer, start);
|
||||
i32 line_end = buffer_get_line_index(&file->state.buffer, end);
|
||||
i32 replaced_line_count = line_end - line_start;
|
||||
|
@ -5989,7 +5995,7 @@ draw_file_loaded(View *view, i32_Rect rect, b32 is_active, Render_Target *target
|
|||
first_wrap_determination = 0;
|
||||
}
|
||||
else{
|
||||
assert_4tech(stop.pos == wrap_unit_end);
|
||||
assert(stop.pos == wrap_unit_end);
|
||||
do_wrap = 1;
|
||||
++wrap_array_index;
|
||||
wrap_unit_end = file->state.wrap_positions[wrap_array_index];
|
||||
|
|
97
4ed_math.h
97
4ed_math.h
|
@ -53,43 +53,6 @@ COS(f32 x_degrees){
|
|||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Rounding
|
||||
*/
|
||||
|
||||
inline i32
|
||||
TRUNC32(real32 x) { return (i32)x; }
|
||||
|
||||
inline i32
|
||||
FLOOR32(real32 x) { return (i32)(x)-((x!=(i32)(x) && x<0)?1:0); }
|
||||
|
||||
inline i32
|
||||
CEIL32(real32 x) { return (i32)(x)+((x!=(i32)(x) && x>0)?1:0); }
|
||||
|
||||
inline i32
|
||||
ROUND32(real32 x) { return FLOOR32(x + .5f); }
|
||||
|
||||
inline i32
|
||||
DIVCEIL32(i32 n, i32 d) {
|
||||
i32 q = (n/d);
|
||||
return q + (q*d < n);
|
||||
}
|
||||
|
||||
inline real32
|
||||
FRACPART32(real32 x) { return x - (i32)x; }
|
||||
|
||||
inline u32
|
||||
ROUNDPOT32(u32 v){
|
||||
v--;
|
||||
v |= v >> 1;
|
||||
v |= v >> 2;
|
||||
v |= v >> 4;
|
||||
v |= v >> 8;
|
||||
v |= v >> 16;
|
||||
v++;
|
||||
return v;
|
||||
}
|
||||
|
||||
/*
|
||||
* Vectors
|
||||
*/
|
||||
|
@ -413,10 +376,10 @@ perp(Vec2 v){
|
|||
|
||||
inline Vec2
|
||||
polar_to_cartesian(real32 theta_degrees, real32 length){
|
||||
Vec2 result;
|
||||
result.x = COS(theta_degrees)*length;
|
||||
result.y = SIN(theta_degrees)*length;
|
||||
return result;
|
||||
Vec2 result;
|
||||
result.x = COS(theta_degrees)*length;
|
||||
result.y = SIN(theta_degrees)*length;
|
||||
return result;
|
||||
}
|
||||
|
||||
inline Vec2
|
||||
|
@ -463,8 +426,8 @@ inline f32
|
|||
unlerp(f32 a, f32 x, f32 b){
|
||||
f32 r = x;
|
||||
if (b > a){
|
||||
r = (x - a) / (b - a);
|
||||
}
|
||||
r = (x - a) / (b - a);
|
||||
}
|
||||
return(r);
|
||||
}
|
||||
|
||||
|
@ -517,7 +480,7 @@ color_blend(u32 a, real32 t, u32 b){
|
|||
u8 byte[4];
|
||||
u32 comp;
|
||||
} A, B, R;
|
||||
|
||||
|
||||
A.comp = a;
|
||||
B.comp = b;
|
||||
|
||||
|
@ -589,23 +552,23 @@ rgba_to_hsla(Vec4 rgba){
|
|||
}
|
||||
else{
|
||||
switch (maxc){
|
||||
case 0:
|
||||
{
|
||||
hsla.x = (rgba.g - rgba.b) / delta;
|
||||
hsla.x += (rgba.g < rgba.b) * 6.f;
|
||||
}break;
|
||||
|
||||
case 1:
|
||||
{
|
||||
hsla.x = (rgba.b - rgba.r) / delta;
|
||||
hsla.x += 2.f;
|
||||
}break;
|
||||
|
||||
case 2:
|
||||
{
|
||||
hsla.x = (rgba.r - rgba.g) / delta;
|
||||
hsla.x += 4.f;
|
||||
}break;
|
||||
case 0:
|
||||
{
|
||||
hsla.x = (rgba.g - rgba.b) / delta;
|
||||
hsla.x += (rgba.g < rgba.b) * 6.f;
|
||||
}break;
|
||||
|
||||
case 1:
|
||||
{
|
||||
hsla.x = (rgba.b - rgba.r) / delta;
|
||||
hsla.x += 2.f;
|
||||
}break;
|
||||
|
||||
case 2:
|
||||
{
|
||||
hsla.x = (rgba.r - rgba.g) / delta;
|
||||
hsla.x += 4.f;
|
||||
}break;
|
||||
}
|
||||
hsla.x *= (1/6.f); // * 60 / 360
|
||||
hsla.y = delta / (1.f - ABS(2.f*hsla.z - 1.f));
|
||||
|
@ -626,27 +589,27 @@ hsla_to_rgba(Vec4 hsla){
|
|||
m = hsla.z - C*.5f;
|
||||
H = FLOOR32(hsla.x * 6.f);
|
||||
switch (H){
|
||||
case 0:
|
||||
case 0:
|
||||
rgba.r = C; rgba.g = X; rgba.b = 0;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
case 1:
|
||||
rgba.r = X; rgba.g = C; rgba.b = 0;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
case 2:
|
||||
rgba.r = 0; rgba.g = C; rgba.b = X;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
case 3:
|
||||
rgba.r = 0; rgba.g = X; rgba.b = C;
|
||||
break;
|
||||
|
||||
case 4:
|
||||
case 4:
|
||||
rgba.r = X; rgba.g = 0; rgba.b = C;
|
||||
break;
|
||||
|
||||
case 5:
|
||||
case 5:
|
||||
rgba.r = C; rgba.g = 0; rgba.b = X;
|
||||
break;
|
||||
}
|
||||
|
|
Binary file not shown.
|
@ -1,275 +0,0 @@
|
|||
/*
|
||||
* Mr. 4th Dimention - Allen Webster
|
||||
*
|
||||
* 23.10.2015
|
||||
*
|
||||
* An implementation of a gap buffer.
|
||||
*
|
||||
*/
|
||||
|
||||
// TOP
|
||||
|
||||
typedef struct Gap_Buffer{
|
||||
char *data;
|
||||
i32 size1;
|
||||
i32 gap_size;
|
||||
i32 size2;
|
||||
i32 max;
|
||||
|
||||
i32 *line_starts;
|
||||
i32 line_count;
|
||||
i32 line_max;
|
||||
} Gap_Buffer;
|
||||
|
||||
inline_4tech i32
|
||||
buffer_good(Gap_Buffer *buffer){
|
||||
i32 good = (buffer->data != 0);
|
||||
return(good);
|
||||
}
|
||||
|
||||
inline_4tech i32
|
||||
buffer_size(Gap_Buffer *buffer){
|
||||
i32 size = buffer->size1 + buffer->size2;
|
||||
return(size);
|
||||
}
|
||||
|
||||
typedef struct Gap_Buffer_Init{
|
||||
Gap_Buffer *buffer;
|
||||
char *data;
|
||||
i32 size;
|
||||
} Gap_Buffer_Init;
|
||||
|
||||
internal_4tech Gap_Buffer_Init
|
||||
buffer_begin_init(Gap_Buffer *buffer, char *data, i32 size){
|
||||
Gap_Buffer_Init init;
|
||||
init.buffer = buffer;
|
||||
init.data = data;
|
||||
init.size = size;
|
||||
return(init);
|
||||
}
|
||||
|
||||
internal_4tech i32
|
||||
buffer_init_need_more(Gap_Buffer_Init *init){
|
||||
i32 result = 1;
|
||||
if (init->buffer->data) result = 0;
|
||||
return(result);
|
||||
}
|
||||
|
||||
internal_4tech i32
|
||||
buffer_init_page_size(Gap_Buffer_Init *init){
|
||||
i32 result = init->size * 2;
|
||||
return(result);
|
||||
}
|
||||
|
||||
internal_4tech void
|
||||
buffer_init_provide_page(Gap_Buffer_Init *init, void *page, i32 page_size){
|
||||
Gap_Buffer *buffer = init->buffer;
|
||||
buffer->data = (char*)page;
|
||||
buffer->max = page_size;
|
||||
}
|
||||
|
||||
internal_4tech i32
|
||||
buffer_end_init(Gap_Buffer_Init *init, void *scratch, i32 scratch_size){
|
||||
Gap_Buffer *buffer = init->buffer;
|
||||
i32 osize1 = 0, size1 = 0, size2 = 0, size = init->size;
|
||||
i32 result = 0;
|
||||
|
||||
if (buffer->data){
|
||||
if (buffer->max >= init->size){
|
||||
size2 = size >> 1;
|
||||
size1 = osize1 = size - size2;
|
||||
|
||||
if (size1 > 0){
|
||||
size1 = eol_convert_in(buffer->data, init->data, size1);
|
||||
if (size2 > 0){
|
||||
size2 = eol_convert_in(buffer->data + size1, init->data + osize1, size2);
|
||||
}
|
||||
}
|
||||
|
||||
buffer->size1 = size1;
|
||||
buffer->size2 = size2;
|
||||
buffer->gap_size = buffer->max - size1 - size2;
|
||||
memmove_4tech(buffer->data + size1 + buffer->gap_size, buffer->data + size1, size2);
|
||||
|
||||
result = 1;
|
||||
}
|
||||
}
|
||||
|
||||
return(result);
|
||||
}
|
||||
|
||||
typedef struct Gap_Buffer_Stream{
|
||||
Gap_Buffer *buffer;
|
||||
char *data;
|
||||
i32 end;
|
||||
i32 separated;
|
||||
i32 absolute_end;
|
||||
|
||||
b32 use_termination_character;
|
||||
char terminator;
|
||||
} Gap_Buffer_Stream;
|
||||
static Gap_Buffer_Stream null_buffer_stream = {0};
|
||||
|
||||
internal_4tech b32
|
||||
buffer_stringify_loop(Gap_Buffer_Stream *stream, Gap_Buffer *buffer, i32 start, i32 end){
|
||||
b32 result = 0;
|
||||
|
||||
if (0 <= start && start < end && end <= buffer->size1 + buffer->size2){
|
||||
stream->buffer = buffer;
|
||||
stream->absolute_end = end;
|
||||
|
||||
if (start < buffer->size1){
|
||||
if (buffer->size1 < end){
|
||||
stream->separated = 1;
|
||||
}
|
||||
else{
|
||||
stream->separated = 0;
|
||||
}
|
||||
stream->data = buffer->data;
|
||||
}
|
||||
else{
|
||||
stream->separated = 0;
|
||||
stream->data = buffer->data + buffer->gap_size;
|
||||
}
|
||||
|
||||
if (stream->separated){
|
||||
stream->end = buffer->size1;
|
||||
}
|
||||
else{
|
||||
stream->end = end;
|
||||
}
|
||||
|
||||
if (stream->end > stream->absolute_end){
|
||||
stream->end = stream->absolute_end;
|
||||
}
|
||||
|
||||
result = 1;
|
||||
}
|
||||
|
||||
if (result == 0){
|
||||
if (stream->use_termination_character){
|
||||
stream->buffer = buffer;
|
||||
stream->absolute_end = end;
|
||||
stream->use_termination_character = 0;
|
||||
stream->data = (&stream->terminator) - buffer->size1 - buffer->size2;
|
||||
stream->end = stream->absolute_end + 1;
|
||||
result = 1;
|
||||
}
|
||||
}
|
||||
|
||||
return(result);
|
||||
}
|
||||
|
||||
internal_4tech b32
|
||||
buffer_stringify_next(Gap_Buffer_Stream *stream){
|
||||
b32 result = 0;
|
||||
Gap_Buffer *buffer = stream->buffer;
|
||||
if (stream->separated){
|
||||
stream->data = buffer->data + buffer->gap_size;
|
||||
stream->end = stream->absolute_end;
|
||||
stream->separated = 0;
|
||||
result = 1;
|
||||
}
|
||||
|
||||
if (result == 0){
|
||||
if (stream->use_termination_character){
|
||||
stream->use_termination_character = 0;
|
||||
stream->data = (&stream->terminator) - buffer->size1 - buffer->size2;
|
||||
stream->end = stream->absolute_end + 1;
|
||||
result = 1;
|
||||
}
|
||||
}
|
||||
|
||||
return(result);
|
||||
}
|
||||
|
||||
internal_4tech i32
|
||||
buffer_replace_range(Gap_Buffer *buffer, i32 start, i32 end, char *str, i32 len, i32 *shift_amount,
|
||||
void *scratch, i32 scratch_memory, i32 *request_amount){
|
||||
char *data = buffer->data;
|
||||
i32 size = buffer_size(buffer);
|
||||
i32 result = 0;
|
||||
i32 move_size = 0;
|
||||
|
||||
assert_4tech(0 <= start);
|
||||
assert_4tech(start <= end);
|
||||
assert_4tech(end <= size);
|
||||
|
||||
*shift_amount = (len - (end - start));
|
||||
if (*shift_amount + size <= buffer->max){
|
||||
if (end < buffer->size1){
|
||||
move_size = buffer->size1 - end;
|
||||
memmove_4tech(data + buffer->size1 + buffer->gap_size - move_size, data + end, move_size);
|
||||
buffer->size1 -= move_size;
|
||||
buffer->size2 += move_size;
|
||||
}
|
||||
if (start > buffer->size1){
|
||||
move_size = start - buffer->size1;
|
||||
memmove_4tech(data + buffer->size1, data + buffer->size1 + buffer->gap_size, move_size);
|
||||
buffer->size1 += move_size;
|
||||
buffer->size2 -= move_size;
|
||||
}
|
||||
|
||||
memcpy_4tech(data + start, str, len);
|
||||
buffer->size2 = size - end;
|
||||
buffer->size1 = start + len;
|
||||
buffer->gap_size -= *shift_amount;
|
||||
|
||||
assert_4tech(buffer->size1 + buffer->size2 == size + *shift_amount);
|
||||
assert_4tech(buffer->size1 + buffer->gap_size + buffer->size2 == buffer->max);
|
||||
}
|
||||
else{
|
||||
*request_amount = round_up_4tech(2*(*shift_amount + size), 4 << 10);
|
||||
result = 1;
|
||||
}
|
||||
|
||||
return(result);
|
||||
}
|
||||
|
||||
// TODO(allen): Now that we are just using Gap_Buffer we could afford to improve
|
||||
// this for the Gap_Buffer's behavior.
|
||||
internal_4tech i32
|
||||
buffer_batch_edit_step(Buffer_Batch_State *state, Gap_Buffer *buffer, Buffer_Edit *sorted_edits,
|
||||
char *strings, i32 edit_count, void *scratch, i32 scratch_size,
|
||||
i32 *request_amount){
|
||||
Buffer_Edit *edit = 0;
|
||||
i32 i = state->i;
|
||||
i32 shift_total = state->shift_total;
|
||||
i32 shift_amount = 0;
|
||||
i32 result = 0;
|
||||
|
||||
edit = sorted_edits + i;
|
||||
for (; i < edit_count; ++i, ++edit){
|
||||
result = buffer_replace_range(buffer, edit->start + shift_total, edit->end + shift_total,
|
||||
strings + edit->str_start, edit->len, &shift_amount,
|
||||
scratch, scratch_size, request_amount);
|
||||
if (result) break;
|
||||
shift_total += shift_amount;
|
||||
}
|
||||
|
||||
state->shift_total = shift_total;
|
||||
state->i = i;
|
||||
|
||||
return(result);
|
||||
}
|
||||
|
||||
internal_4tech void*
|
||||
buffer_edit_provide_memory(Gap_Buffer *buffer, void *new_data, i32 new_max){
|
||||
void *result = buffer->data;
|
||||
i32 size = buffer_size(buffer);
|
||||
i32 new_gap_size = new_max - size;
|
||||
|
||||
assert_4tech(new_max >= size);
|
||||
|
||||
memcpy_4tech(new_data, buffer->data, buffer->size1);
|
||||
memcpy_4tech((char*)new_data + buffer->size1 + new_gap_size, buffer->data + buffer->size1 + buffer->gap_size, buffer->size2);
|
||||
|
||||
buffer->data = (char*)new_data;
|
||||
buffer->gap_size = new_gap_size;
|
||||
buffer->max = new_max;
|
||||
|
||||
return(result);
|
||||
}
|
||||
|
||||
// BOTTOM
|
||||
|
|
@ -1,389 +0,0 @@
|
|||
/*
|
||||
* Mr. 4th Dimention - Allen Webster
|
||||
*
|
||||
* 23.10.2015
|
||||
*
|
||||
* Items shared by gap buffer types
|
||||
*
|
||||
*/
|
||||
|
||||
// TOP
|
||||
|
||||
// TODO(allen): eliminate the extra defs and the extra include.
|
||||
|
||||
#include "../4coder_seek_types.h"
|
||||
|
||||
#ifndef inline_4tech
|
||||
#define inline_4tech inline
|
||||
#endif
|
||||
|
||||
#ifndef internal_4tech
|
||||
#define internal_4tech static
|
||||
#endif
|
||||
|
||||
#ifndef memset_4tech
|
||||
#define memset_4tech memset
|
||||
#endif
|
||||
|
||||
#ifndef memzero_4tech
|
||||
#define memzero_4tech(x) do{ \
|
||||
char *p = (char*)&x; char *e = p + sizeof(x); \
|
||||
for (;p<e; ++p) {*p=0;} }while(0)
|
||||
#endif
|
||||
|
||||
#ifndef memcpy_4tech
|
||||
#define memcpy_4tech memcpy
|
||||
#endif
|
||||
|
||||
#ifndef memmove_4tech
|
||||
#define memmove_4tech memmove
|
||||
#endif
|
||||
|
||||
#ifndef debug_4tech
|
||||
#define debug_4tech(x) x
|
||||
#endif
|
||||
|
||||
#ifndef assert_4tech
|
||||
#define assert_4tech assert
|
||||
#endif
|
||||
|
||||
#ifndef ceil_4tech
|
||||
#define ceil_4tech CEIL32
|
||||
#endif
|
||||
|
||||
#ifndef div_ceil_4tech
|
||||
#define div_ceil_4tech DIVCEIL32
|
||||
#endif
|
||||
|
||||
#ifndef cat_4tech
|
||||
#define cat_4tech_(a,b) a##b
|
||||
#define cat_4tech(a,b) cat_4tech_(a,b)
|
||||
#endif
|
||||
|
||||
#ifndef round_up_4tech
|
||||
internal_4tech i32
|
||||
lroundup_(i32 x, i32 granularity){
|
||||
i32 original_x;
|
||||
original_x = x;
|
||||
x /= granularity;
|
||||
x *= granularity;
|
||||
if (x < original_x) x += granularity;
|
||||
return x;
|
||||
}
|
||||
#define round_up_4tech(x,g) lroundup_(x,g)
|
||||
#endif
|
||||
|
||||
#ifndef round_pot_4tech
|
||||
#define round_pot_4tech ROUNDPOT32
|
||||
#endif
|
||||
|
||||
typedef struct Buffer_Batch_State{
|
||||
i32 i;
|
||||
i32 shift_total;
|
||||
} Buffer_Batch_State;
|
||||
|
||||
typedef struct Cursor_With_Index{
|
||||
i32 pos;
|
||||
i32 index;
|
||||
} Cursor_With_Index;
|
||||
|
||||
inline_4tech void
|
||||
write_cursor_with_index(Cursor_With_Index *positions, i32 *count, i32 pos){
|
||||
positions[*count].index = *count;
|
||||
positions[*count].pos = pos;
|
||||
++*count;
|
||||
}
|
||||
|
||||
#define CursorSwap__(a,b) { Cursor_With_Index t = a; a = b; b = t; }
|
||||
|
||||
internal_4tech void
|
||||
buffer_quick_sort_cursors(Cursor_With_Index *positions, i32 start, i32 pivot){
|
||||
i32 mid = start;
|
||||
i32 pivot_pos = positions[pivot].pos;
|
||||
for (i32 i = mid; i < pivot; ++i){
|
||||
if (positions[i].pos < pivot_pos){
|
||||
CursorSwap__(positions[mid], positions[i]);
|
||||
++mid;
|
||||
}
|
||||
}
|
||||
CursorSwap__(positions[mid], positions[pivot]);
|
||||
|
||||
if (start < mid - 1) buffer_quick_sort_cursors(positions, start, mid - 1);
|
||||
if (mid + 1 < pivot) buffer_quick_sort_cursors(positions, mid + 1, pivot);
|
||||
}
|
||||
|
||||
// TODO(allen): Rewrite this without being a dumbass.
|
||||
internal_4tech void
|
||||
buffer_quick_unsort_cursors(Cursor_With_Index *positions, i32 start, i32 pivot){
|
||||
i32 mid = start;
|
||||
i32 pivot_index = positions[pivot].index;
|
||||
for (i32 i = mid; i < pivot; ++i){
|
||||
if (positions[i].index < pivot_index){
|
||||
CursorSwap__(positions[mid], positions[i]);
|
||||
++mid;
|
||||
}
|
||||
}
|
||||
CursorSwap__(positions[mid], positions[pivot]);
|
||||
|
||||
if (start < mid - 1) buffer_quick_unsort_cursors(positions, start, mid - 1);
|
||||
if (mid + 1 < pivot) buffer_quick_unsort_cursors(positions, mid + 1, pivot);
|
||||
}
|
||||
|
||||
#undef CursorSwap__
|
||||
|
||||
inline_4tech void
|
||||
buffer_sort_cursors(Cursor_With_Index *positions, i32 count){
|
||||
assert_4tech(count > 0);
|
||||
buffer_quick_sort_cursors(positions, 0, count-1);
|
||||
}
|
||||
|
||||
inline_4tech void
|
||||
buffer_unsort_cursors(Cursor_With_Index *positions, i32 count){
|
||||
assert_4tech(count > 0);
|
||||
buffer_quick_unsort_cursors(positions, 0, count-1);
|
||||
}
|
||||
|
||||
internal_4tech void
|
||||
buffer_update_cursors(Cursor_With_Index *sorted_positions, i32 count, i32 start, i32 end, i32 len){
|
||||
i32 shift_amount = (len - (end - start));
|
||||
Cursor_With_Index *position = sorted_positions + count - 1;
|
||||
|
||||
for (; position >= sorted_positions && position->pos > end; --position) position->pos += shift_amount;
|
||||
for (; position >= sorted_positions && position->pos >= start; --position) position->pos = start;
|
||||
}
|
||||
|
||||
internal_4tech i32
|
||||
buffer_batch_debug_sort_check(Buffer_Edit *sorted_edits, i32 edit_count){
|
||||
Buffer_Edit *edit = sorted_edits;
|
||||
i32 i = 0, start_point = 0;
|
||||
i32 result = 1;
|
||||
|
||||
for (i = 0; i < edit_count; ++i, ++edit){
|
||||
if (start_point > edit->start){
|
||||
result = 0; break;
|
||||
}
|
||||
start_point = (edit->end < edit->start + 1)?(edit->start + 1):(edit->end);
|
||||
}
|
||||
|
||||
return(result);
|
||||
}
|
||||
|
||||
internal_4tech i32
|
||||
buffer_batch_edit_max_shift(Buffer_Edit *sorted_edits, i32 edit_count){
|
||||
Buffer_Edit *edit;
|
||||
i32 i, result;
|
||||
i32 shift_total, shift_max;
|
||||
|
||||
result = 0;
|
||||
shift_total = 0;
|
||||
shift_max = 0;
|
||||
|
||||
edit = sorted_edits;
|
||||
for (i = 0; i < edit_count; ++i, ++edit){
|
||||
shift_total += (edit->len - (edit->end - edit->start));
|
||||
if (shift_total > shift_max) shift_max = shift_total;
|
||||
}
|
||||
|
||||
return(shift_max);
|
||||
}
|
||||
|
||||
internal_4tech i32
|
||||
buffer_batch_edit_update_cursors(Cursor_With_Index *sorted_positions, i32 count, Buffer_Edit *sorted_edits, i32 edit_count){
|
||||
Cursor_With_Index *position, *end_position;
|
||||
Buffer_Edit *edit, *end_edit;
|
||||
i32 start, end;
|
||||
i32 shift_amount;
|
||||
|
||||
position = sorted_positions;
|
||||
end_position = sorted_positions + count;
|
||||
|
||||
edit = sorted_edits;
|
||||
end_edit = sorted_edits + edit_count;
|
||||
|
||||
shift_amount = 0;
|
||||
|
||||
for (; edit < end_edit && position < end_position; ++edit){
|
||||
start = edit->start;
|
||||
end = edit->end;
|
||||
|
||||
for (; position->pos < start && position < end_position; ++position){
|
||||
position->pos += shift_amount;
|
||||
}
|
||||
|
||||
for (; position->pos <= end && position < end_position; ++position){
|
||||
position->pos = start + shift_amount;
|
||||
}
|
||||
|
||||
shift_amount += (edit->len - (end - start));
|
||||
}
|
||||
|
||||
for (; position < end_position; ++position){
|
||||
position->pos += shift_amount;
|
||||
}
|
||||
|
||||
for (; edit < end_edit; ++edit){
|
||||
shift_amount += (edit->len - (edit->end - edit->start));
|
||||
}
|
||||
|
||||
return(shift_amount);
|
||||
}
|
||||
|
||||
internal_4tech i32
|
||||
eol_convert_in(char *dest, char *src, i32 size){
|
||||
i32 i, j, k;
|
||||
|
||||
i = 0;
|
||||
k = 0;
|
||||
j = 0;
|
||||
|
||||
for (; j < size && src[j] != '\r'; ++j);
|
||||
memcpy_4tech(dest, src, j);
|
||||
|
||||
if (j < size){
|
||||
k = 1;
|
||||
++j;
|
||||
for (i = j; i < size; ++i){
|
||||
if (src[i] == '\r'){
|
||||
memcpy_4tech(dest + j - k, src + j, i - j);
|
||||
++k;
|
||||
j = i+1;
|
||||
}
|
||||
}
|
||||
memcpy_4tech(dest + j - k, src + j, i - j);
|
||||
j = i - k;
|
||||
}
|
||||
|
||||
return(j);
|
||||
}
|
||||
|
||||
internal_4tech i32
|
||||
eol_in_place_convert_in(char *data, i32 size){
|
||||
i32 i, j, k;
|
||||
|
||||
i = 0;
|
||||
k = 0;
|
||||
j = 0;
|
||||
|
||||
for (; j < size && data[j] != '\r'; ++j);
|
||||
|
||||
if (j < size){
|
||||
k = 1;
|
||||
++j;
|
||||
for (i = j; i < size; ++i){
|
||||
if (data[i] == '\r'){
|
||||
memmove_4tech(data + j - k, data + j, i - j);
|
||||
++k;
|
||||
j = i+1;
|
||||
}
|
||||
}
|
||||
memmove_4tech(data + j - k, data + j, i - j);
|
||||
j = i - k;
|
||||
}
|
||||
|
||||
return(j);
|
||||
}
|
||||
|
||||
internal_4tech i32
|
||||
eol_convert_out(char *dest, i32 max, char *src, i32 size, i32 *size_out){
|
||||
i32 result;
|
||||
i32 i, j;
|
||||
|
||||
// TODO(allen): iterative memory check?
|
||||
result = 1;
|
||||
i = 0;
|
||||
j = 0;
|
||||
|
||||
for (; i < size; ++i, ++j){
|
||||
if (src[i] == '\n'){
|
||||
dest[j] = '\r';
|
||||
++j;
|
||||
dest[j] = '\n';
|
||||
}
|
||||
else dest[j] = src[i];
|
||||
}
|
||||
|
||||
*size_out = j;
|
||||
return(result);
|
||||
}
|
||||
|
||||
internal_4tech i32
|
||||
eol_in_place_convert_out(char *data, i32 size, i32 max, i32 *size_out){
|
||||
i32 result;
|
||||
i32 i;
|
||||
|
||||
// TODO(allen): iterative memory check?
|
||||
result = 1;
|
||||
i = 0;
|
||||
|
||||
for (; i < size; ++i){
|
||||
if (data[i] == '\n'){
|
||||
memmove_4tech(data + i + 1, data + i, size - i);
|
||||
data[i] = '\r';
|
||||
++i;
|
||||
++size;
|
||||
}
|
||||
}
|
||||
|
||||
*size_out = size;
|
||||
return(result);
|
||||
}
|
||||
|
||||
inline_4tech i32
|
||||
is_whitespace(char c){
|
||||
i32 result;
|
||||
result = (c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == '\f' || c == '\v');
|
||||
return(result);
|
||||
}
|
||||
|
||||
inline_4tech i32
|
||||
is_alphanumeric_true(char c){
|
||||
return (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= '0' && c <= '9');
|
||||
}
|
||||
|
||||
inline_4tech i32
|
||||
is_alphanumeric(char c){
|
||||
return (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= '0' && c <= '9' || c == '_');
|
||||
}
|
||||
|
||||
inline_4tech i32
|
||||
is_upper(char c){
|
||||
return (c >= 'A' && c <= 'Z');
|
||||
}
|
||||
|
||||
inline_4tech i32
|
||||
is_lower(char c){
|
||||
return (c >= 'a' && c <= 'z');
|
||||
}
|
||||
|
||||
inline_4tech char
|
||||
to_upper(char c){
|
||||
if (is_lower(c)){
|
||||
c += 'A' - 'a';
|
||||
}
|
||||
return(c);
|
||||
}
|
||||
|
||||
internal_4tech i32
|
||||
is_match(char *a, char *b, i32 len){
|
||||
i32 result;
|
||||
|
||||
result = 1;
|
||||
for (;len > 0; --len, ++a, ++b)
|
||||
if (*a != *b) { result = 0; break; }
|
||||
|
||||
return(result);
|
||||
}
|
||||
|
||||
internal_4tech i32
|
||||
is_match_insensitive(char *a, char *b, i32 len){
|
||||
i32 result;
|
||||
|
||||
result = 1;
|
||||
for (;len > 0; --len, ++a, ++b)
|
||||
if (to_upper(*a) != to_upper(*b)) { result = 0; break; }
|
||||
|
||||
return(result);
|
||||
}
|
||||
|
||||
// BOTTOM
|
||||
|
|
@ -11,8 +11,9 @@ SET BUILD_MODE=%1
|
|||
if "%BUILD_MODE%" == "" (SET BUILD_MODE="/DDEV_BUILD")
|
||||
|
||||
pushd ..\build
|
||||
cl %OPTS% ..\code\build.cpp /Zi /Febuild %BUILD_MODE%
|
||||
cl %OPTS% ..\code\meta\build.cpp /Zi /Febuild %BUILD_MODE%
|
||||
if %ERRORLEVEL% neq 0 (set FirstError=1)
|
||||
if %ERRORLEVEL% neq 0 (goto END)
|
||||
popd
|
||||
|
||||
..\build\build
|
||||
|
@ -24,4 +25,5 @@ call "print_size.bat" 4ed_app.dll
|
|||
call "print_size.bat" 4ed.exe
|
||||
popd
|
||||
|
||||
::END
|
||||
call "ctime" -end 4ed_data.ctm %FirstError%
|
||||
|
|
2
build.sh
2
build.sh
|
@ -3,7 +3,7 @@
|
|||
WARNINGS="-Wno-write-strings"
|
||||
FLAGS="-D_GNU_SOURCE -fPIC -fpermissive -DDEV_BUILD"
|
||||
|
||||
g++ $WARNINGS $FLAGS build.cpp -g -o ../build/build
|
||||
g++ $WARNINGS $FLAGS meta/build.cpp -g -o ../build/build
|
||||
../build/build
|
||||
|
||||
|
||||
|
|
|
@ -1,48 +0,0 @@
|
|||
@echo off
|
||||
|
||||
call "ctime" -begin 4ed_data.ctm
|
||||
|
||||
set OPTS=/W4 /wd4310 /wd4100 /wd4201 /wd4505 /wd4996 /wd4127 /wd4510 /wd4512 /wd4610 /wd4390 /WX
|
||||
set OPTS=%OPTS% /GR- /EHa- /nologo /FC
|
||||
set INCLUDES=/I..\foreign /I..\foreign\freetype2
|
||||
set LIBS=user32.lib winmm.lib gdi32.lib opengl32.lib
|
||||
set LIBS=%LIBS% ..\foreign\freetype.lib
|
||||
set ICON=..\res\icon.res
|
||||
set DEFINES=
|
||||
set FirstError=0
|
||||
|
||||
pushd ..\meta
|
||||
REM cl %OPTS% ..\code\4ed_metagen.cpp %* /Femetagen
|
||||
if %ERRORLEVEL% neq 0 (set FirstError=1)
|
||||
popd
|
||||
|
||||
pushd ..\code
|
||||
REM "..\meta\metagen"
|
||||
if %ERRORLEVEL% neq 0 (set FirstError=1)
|
||||
|
||||
set CODE_DIR=%CD%
|
||||
popd
|
||||
|
||||
pushd ..\build
|
||||
|
||||
REM call "%CODE_DIR%\buildsuper.bat" ..\code\4coder_default_bindings.cpp
|
||||
REM call "%CODE_DIR%\buildsuper.bat" ..\code\internal_4coder_tests.cpp
|
||||
REM call "%CODE_DIR%\buildsuper.bat" ..\code\power\4coder_casey.cpp
|
||||
REM call "%CODE_DIR%\buildsuper.bat" ..\4vim\4coder_chronal.cpp
|
||||
if %ERRORLEVEL% neq 0 (set FirstError=1)
|
||||
|
||||
set EXPORTS=/EXPORT:app_get_functions
|
||||
cl %OPTS% %INCLUDES% %DEFINES% %CODE_DIR%\4ed_app_target.cpp %* /Fe4ed_app /LD /link /DEBUG /INCREMENTAL:NO /OPT:REF %EXPORTS%
|
||||
if %ERRORLEVEL% neq 0 (set FirstError=1)
|
||||
|
||||
cl %OPTS% %INCLUDES% %DEFINES% %CODE_DIR%\win32_4ed.cpp %LIBS% %ICON% %* /Fe4ed /link /DEBUG /NODEFAULTLIB:library
|
||||
if %ERRORLEVEL% neq 0 (set FirstError=1)
|
||||
|
||||
call "print_size.bat" 4ed_app.dll
|
||||
call "print_size.bat" 4ed.exe
|
||||
|
||||
popd
|
||||
|
||||
call "ctime" -end 4ed_data.ctm %FirstError%
|
||||
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
@echo off
|
||||
|
||||
set WARNINGOPS=/W4 /wd4310 /wd4100 /wd4201 /wd4505 /wd4996 /wd4127 /wd4510 /wd4512 /wd4610 /wd4390 /WX
|
||||
set WARNINGOPS=%WARNINGOPS% /GR- /EHa- /nologo /FC
|
||||
|
||||
pushd ..\build
|
||||
cl %WARNINGOPS% ..\code\test\fsm_table_generator.cpp /Fefsm_gen %*
|
||||
|
||||
pushd ..\code\test
|
||||
..\..\build\fsm_gen
|
||||
popd
|
||||
|
||||
cl %WARNINGOPS% ..\code\test\experiment.cpp /Fexperiment %*
|
||||
popd
|
|
@ -7,10 +7,10 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#ifndef FRED_DEFINES_H
|
||||
#define FRED_DEFINES_H
|
||||
// TOP
|
||||
|
||||
#include <string.h>
|
||||
#if !defined(FRED_DEFINES_H)
|
||||
#define FRED_DEFINES_H
|
||||
|
||||
#if !defined (FRED_TYPES)
|
||||
#include <stdint.h>
|
||||
|
@ -58,13 +58,14 @@ typedef double f64;
|
|||
#define TentativeAssert(c) Assert(c)
|
||||
#define NotImplemented Assert(!"This is not implemented yet!")
|
||||
#define InvalidCodePath Assert(!"Invalid code path!")
|
||||
#define InvalidPath InvalidCodePath
|
||||
|
||||
#define AllowLocal(name) (void)name
|
||||
#ifndef ArrayCount
|
||||
# define ArrayCount(array) (sizeof(array)/sizeof(array[0]))
|
||||
#endif
|
||||
|
||||
#define OffsetOfStruct(S,c) ((i64)(& ((S*)0)->c ))
|
||||
#define OffsetOfPtr(s,c) ((i64)((char*)(&(s)->c) - (char*)(s)))
|
||||
|
||||
#define Swap(T,a,b) do{ T t = a; a = b; b = t; } while(0)
|
||||
|
||||
|
@ -97,17 +98,6 @@ TMin(i32, -2147483647-1);
|
|||
TMin(i64, -9223372036854775807-1);
|
||||
#undef TMin
|
||||
|
||||
internal i32
|
||||
LargeRoundUp(i32 x, i32 granularity){
|
||||
i32 original_x = x;
|
||||
x /= granularity;
|
||||
x *= granularity;
|
||||
if (x < original_x){
|
||||
x += granularity;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
#define Bit_0 (1 << 0)
|
||||
#define Bit_1 (1 << 1)
|
||||
#define Bit_2 (1 << 2)
|
||||
|
@ -150,4 +140,57 @@ LargeRoundUp(i32 x, i32 granularity){
|
|||
#define Gbytes(n) (((u64)n) << 30)
|
||||
#define Tbytes(n) (((u64)n) << 40)
|
||||
|
||||
#endif
|
||||
//
|
||||
// Rounding
|
||||
//
|
||||
|
||||
internal u32
|
||||
l_round_up_u32(u32 x, u32 granularity){
|
||||
u32 new_x = x + granularity - 1;
|
||||
new_x = new_x - (new_x % granularity);
|
||||
return(new_x);
|
||||
}
|
||||
|
||||
internal i32
|
||||
l_round_up_i32(i32 x, i32 granularity){
|
||||
i32 new_x = (i32)l_round_up_u32((u32)x, (u32)granularity);
|
||||
return(new_x);
|
||||
}
|
||||
|
||||
inline i32
|
||||
TRUNC32(real32 x) { return (i32)x; }
|
||||
|
||||
inline i32
|
||||
FLOOR32(real32 x) { return (i32)(x)-((x!=(i32)(x) && x<0)?1:0); }
|
||||
|
||||
inline i32
|
||||
CEIL32(real32 x) { return (i32)(x)+((x!=(i32)(x) && x>0)?1:0); }
|
||||
|
||||
inline i32
|
||||
ROUND32(real32 x) { return FLOOR32(x + .5f); }
|
||||
|
||||
inline i32
|
||||
DIVCEIL32(i32 n, i32 d) {
|
||||
i32 q = (n/d);
|
||||
return q + (q*d < n);
|
||||
}
|
||||
|
||||
inline real32
|
||||
FRACPART32(real32 x) { return x - (i32)x; }
|
||||
|
||||
inline u32
|
||||
ROUNDPOT32(u32 v){
|
||||
v--;
|
||||
v |= v >> 1;
|
||||
v |= v >> 2;
|
||||
v |= v >> 4;
|
||||
v |= v >> 8;
|
||||
v |= v >> 16;
|
||||
v++;
|
||||
return v;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// BOTTOM
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
#define MAJOR 4
|
||||
#define MINOR 0
|
||||
#define PATCH 14
|
||||
#define PATCH 15
|
||||
|
||||
#define VN__(a,b,c) #a"."#b"."#c
|
||||
#define VN_(a,b,c) VN__(a,b,c)
|
File diff suppressed because it is too large
Load Diff
|
@ -47,63 +47,6 @@ edit_pos_set_scroll(File_Edit_Positions *edit_pos, GUI_Scroll_Vars scroll){
|
|||
edit_pos->last_set_type = EditPos_ScrollSet;
|
||||
}
|
||||
|
||||
//
|
||||
// Undo Basics
|
||||
//
|
||||
|
||||
enum Edit_Type{
|
||||
ED_NORMAL,
|
||||
ED_REVERSE_NORMAL,
|
||||
ED_UNDO,
|
||||
ED_REDO,
|
||||
};
|
||||
|
||||
struct Edit_Step{
|
||||
Edit_Type type;
|
||||
union{
|
||||
struct{
|
||||
b32 can_merge;
|
||||
Buffer_Edit edit;
|
||||
i32 next_block;
|
||||
i32 prev_block;
|
||||
};
|
||||
struct{
|
||||
i32 first_child;
|
||||
i32 inverse_first_child;
|
||||
i32 inverse_child_count;
|
||||
i32 special_type;
|
||||
};
|
||||
};
|
||||
i32 child_count;
|
||||
};
|
||||
|
||||
struct Edit_Stack{
|
||||
u8 *strings;
|
||||
i32 size, max;
|
||||
|
||||
Edit_Step *edits;
|
||||
i32 edit_count, edit_max;
|
||||
};
|
||||
|
||||
struct Small_Edit_Stack{
|
||||
u8 *strings;
|
||||
i32 size, max;
|
||||
|
||||
Buffer_Edit *edits;
|
||||
i32 edit_count, edit_max;
|
||||
};
|
||||
|
||||
struct Undo_Data{
|
||||
Edit_Stack undo;
|
||||
Edit_Stack redo;
|
||||
Edit_Stack history;
|
||||
Small_Edit_Stack children;
|
||||
|
||||
i32 history_block_count, history_head_block;
|
||||
i32 edit_history_cursor;
|
||||
b32 current_block_normal;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// Highlighting Information
|
||||
|
@ -138,7 +81,7 @@ struct Editing_File_Settings{
|
|||
static Editing_File_Settings null_editing_file_settings = {0};
|
||||
|
||||
struct Editing_File_State{
|
||||
Buffer_Type buffer;
|
||||
Gap_Buffer buffer;
|
||||
|
||||
i32 *wrap_line_index;
|
||||
i32 wrap_max;
|
||||
|
|
|
@ -9,7 +9,10 @@
|
|||
|
||||
// TOP
|
||||
|
||||
#include "4coder_file.cpp"
|
||||
#include "../common/4ed_defines.h"
|
||||
|
||||
#include "4coder_buffer.cpp"
|
||||
#include "4coder_undo.cpp"
|
||||
|
||||
int main(){
|
||||
return(0);
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* Mr. 4th Dimention - Allen Webster
|
||||
*
|
||||
* 06.01.2017
|
||||
*
|
||||
* Undo subsystem for 4coder
|
||||
*
|
||||
*/
|
||||
|
||||
// TOP
|
||||
|
||||
//
|
||||
// Undo Basics
|
||||
//
|
||||
|
||||
enum Edit_Type{
|
||||
ED_NORMAL,
|
||||
ED_REVERSE_NORMAL,
|
||||
ED_UNDO,
|
||||
ED_REDO,
|
||||
};
|
||||
|
||||
struct Edit_Step{
|
||||
Edit_Type type;
|
||||
union{
|
||||
struct{
|
||||
b32 can_merge;
|
||||
Buffer_Edit edit;
|
||||
i32 next_block;
|
||||
i32 prev_block;
|
||||
};
|
||||
struct{
|
||||
i32 first_child;
|
||||
i32 inverse_first_child;
|
||||
i32 inverse_child_count;
|
||||
i32 special_type;
|
||||
};
|
||||
};
|
||||
i32 child_count;
|
||||
};
|
||||
|
||||
struct Edit_Stack{
|
||||
u8 *strings;
|
||||
i32 size, max;
|
||||
|
||||
Edit_Step *edits;
|
||||
i32 edit_count, edit_max;
|
||||
};
|
||||
|
||||
struct Small_Edit_Stack{
|
||||
u8 *strings;
|
||||
i32 size, max;
|
||||
|
||||
Buffer_Edit *edits;
|
||||
i32 edit_count, edit_max;
|
||||
};
|
||||
|
||||
struct Undo_Data{
|
||||
Edit_Stack undo;
|
||||
Edit_Stack redo;
|
||||
Edit_Stack history;
|
||||
Small_Edit_Stack children;
|
||||
|
||||
i32 history_block_count, history_head_block;
|
||||
i32 edit_history_cursor;
|
||||
b32 current_block_normal;
|
||||
};
|
||||
|
||||
// BOTTOM
|
||||
|
|
@ -430,7 +430,6 @@ shut_down_track_system(File_Track_System *system){
|
|||
File_Track_Result result = FileTrack_Good;
|
||||
Win32_File_Track_Vars *vars = to_vars(system);
|
||||
|
||||
|
||||
DWORD win32_result = 0;
|
||||
|
||||
// NOTE(allen): Close all the handles stored in the table.
|
||||
|
|
|
@ -4,14 +4,16 @@
|
|||
*
|
||||
* 14.11.2015
|
||||
*
|
||||
* Linux layer for project codename "4ed"
|
||||
* Linux layer for 4coder
|
||||
*
|
||||
*/
|
||||
|
||||
// TOP
|
||||
|
||||
# include <assert.h>
|
||||
# include "4ed_defines.h"
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include "common/4coder_defines.h"
|
||||
#include "common/4coder_version.h"
|
||||
|
||||
#if FRED_SUPER
|
||||
|
||||
|
@ -19,7 +21,6 @@
|
|||
# define FSTRING_C
|
||||
# include "4coder_string.h"
|
||||
|
||||
#include "4coder_version.h"
|
||||
# include "4coder_keycodes.h"
|
||||
# include "4coder_style.h"
|
||||
# include "4coder_rect.h"
|
||||
|
@ -48,7 +49,6 @@ typedef void Custom_Command_Function;
|
|||
struct Application_Links;
|
||||
# include "4ed_os_custom_api.h"
|
||||
|
||||
//# include "4coder_custom.h"
|
||||
#else
|
||||
# include "4coder_default_bindings.cpp"
|
||||
|
||||
|
|
|
@ -9,81 +9,24 @@
|
|||
|
||||
// TOP
|
||||
|
||||
#include "4coder_version.h"
|
||||
#include "../common/4coder_defines.h"
|
||||
#include "../common/4coder_version.h"
|
||||
|
||||
#if !defined(FSTRING_GUARD)
|
||||
#include "internal_4coder_string.cpp"
|
||||
#include "../internal_4coder_string.cpp"
|
||||
#endif
|
||||
|
||||
#include "4cpp_lexer.h"
|
||||
#include "../4cpp_lexer.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "4coder_mem.h"
|
||||
#include "../4coder_mem.h"
|
||||
|
||||
// TODO(allen): In the end the metaprogramming base should be one sub-project, the site should be one sub-project, and this code generator should be one sub-project.
|
||||
#include "site/meta_parser.cpp"
|
||||
|
||||
#define InvalidPath Assert(!"Invalid path of execution")
|
||||
|
||||
typedef struct Out_Context{
|
||||
char out_directory_space[256];
|
||||
String out_directory;
|
||||
FILE *file;
|
||||
String *str;
|
||||
} Out_Context;
|
||||
|
||||
static void
|
||||
set_context_directory(Out_Context *context, char *dst_directory){
|
||||
context->out_directory = make_fixed_width_string(context->out_directory_space);
|
||||
copy_sc(&context->out_directory, dst_directory);
|
||||
}
|
||||
|
||||
static int32_t
|
||||
begin_file_out(Out_Context *out_context, char *filename, String *out){
|
||||
char str_space[512];
|
||||
String name = make_fixed_width_string(str_space);
|
||||
if (out_context->out_directory.size > 0){
|
||||
append_ss(&name, out_context->out_directory);
|
||||
append_sc(&name, "\\");
|
||||
}
|
||||
append_sc(&name, filename);
|
||||
terminate_with_null(&name);
|
||||
|
||||
int32_t r = 0;
|
||||
out_context->file = fopen(name.str, "wb");
|
||||
out_context->str = out;
|
||||
out->size = 0;
|
||||
if (out_context->file){
|
||||
r = 1;
|
||||
}
|
||||
|
||||
return(r);
|
||||
}
|
||||
|
||||
static void
|
||||
dump_file_out(Out_Context out_context){
|
||||
fwrite(out_context.str->str, 1, out_context.str->size, out_context.file);
|
||||
out_context.str->size = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
end_file_out(Out_Context out_context){
|
||||
dump_file_out(out_context);
|
||||
fclose(out_context.file);
|
||||
}
|
||||
|
||||
static String
|
||||
make_out_string(int32_t x){
|
||||
String str;
|
||||
str.size = 0;
|
||||
str.memory_size = x;
|
||||
str.str = (char*)malloc(x);
|
||||
return(str);
|
||||
}
|
||||
#include "meta_parser.cpp"
|
||||
#include "out_context.cpp"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
char *keys_that_need_codes[] = {
|
|
@ -10,10 +10,10 @@
|
|||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "4coder_version.h"
|
||||
#include "../common/4coder_version.h"
|
||||
|
||||
#define FSTRING_INLINE static
|
||||
#include "internal_4coder_string.cpp"
|
||||
#include "../internal_4coder_string.cpp"
|
||||
|
||||
//
|
||||
// reusable
|
||||
|
@ -21,7 +21,7 @@
|
|||
|
||||
#define IS_64BIT
|
||||
|
||||
// NOTE(allen): Compiler OS cracking.
|
||||
// NOTE(allen): Compiler/OS cracking.
|
||||
#if defined(_MSC_VER)
|
||||
|
||||
# define IS_CL
|
||||
|
@ -75,7 +75,7 @@ static int32_t prev_error = 0;
|
|||
static void init_time_system();
|
||||
static uint64_t get_time();
|
||||
static int32_t get_current_directory(char *buffer, int32_t max);
|
||||
static void execute(char *dir, char *str, char *args);
|
||||
static void execute_in_dir(char *dir, char *str, char *args);
|
||||
|
||||
static void make_folder_if_missing(char *dir, char *folder);
|
||||
static void clear_folder(char *folder);
|
||||
|
@ -169,7 +169,7 @@ get_current_directory(char *buffer, int32_t max){
|
|||
}
|
||||
|
||||
static void
|
||||
execute(char *dir, char *str, char *args){
|
||||
execute_in_dir(char *dir, char *str, char *args){
|
||||
if (dir){
|
||||
Temp_Dir temp = pushdir(dir);
|
||||
if (args){
|
||||
|
@ -201,8 +201,6 @@ slash_fix(char *path){
|
|||
|
||||
static void
|
||||
make_folder_if_missing(char *dir, char *folder){
|
||||
slash_fix(dir);
|
||||
|
||||
char space[1024];
|
||||
String path = make_fixed_width_string(space);
|
||||
append_sc(&path, dir);
|
||||
|
@ -225,7 +223,6 @@ make_folder_if_missing(char *dir, char *folder){
|
|||
|
||||
static void
|
||||
clear_folder(char *folder){
|
||||
slash_fix(folder);
|
||||
systemf("del /S /Q /F %s\\* & rmdir /S /Q %s & mkdir %s",
|
||||
folder, folder, folder);
|
||||
}
|
||||
|
@ -256,16 +253,11 @@ copy_file(char *path, char *file, char *folder1, char *folder2, char *newname){
|
|||
}
|
||||
terminate_with_null(&b);
|
||||
|
||||
slash_fix(src);
|
||||
slash_fix(dst);
|
||||
|
||||
CopyFileA(src, dst, 0);
|
||||
}
|
||||
|
||||
static void
|
||||
copy_all(char *source, char *tag, char *folder){
|
||||
slash_fix(source);
|
||||
slash_fix(folder);
|
||||
if (source){
|
||||
systemf("copy %s\\%s %s\\*", source, tag, folder);
|
||||
}
|
||||
|
@ -279,9 +271,6 @@ zip(char *parent, char *folder, char *dest){
|
|||
char cdir[512];
|
||||
get_current_directory(cdir, sizeof(cdir));
|
||||
|
||||
slash_fix(parent);
|
||||
slash_fix(dest);
|
||||
|
||||
Temp_Dir temp = pushdir(parent);
|
||||
systemf("%s\\zip %s\\4tech_gobble.zip", cdir, cdir);
|
||||
popdir(temp);
|
||||
|
@ -337,7 +326,7 @@ get_current_directory(char *buffer, int32_t max){
|
|||
}
|
||||
|
||||
static void
|
||||
execute(char *dir, char *str, char *args){
|
||||
execute_in_dir(char *dir, char *str, char *args){
|
||||
if (dir){
|
||||
if (args){
|
||||
Temp_Dir temp = pushdir(dir);
|
||||
|
@ -543,10 +532,6 @@ init_build_line(Build_Line *line){
|
|||
|
||||
static void
|
||||
build_cl(uint32_t flags, char *code_path, char *code_file, char *out_path, char *out_file, char *exports){
|
||||
slash_fix(out_path);
|
||||
slash_fix(code_path);
|
||||
slash_fix(code_file);
|
||||
|
||||
Build_Line line;
|
||||
init_build_line(&line);
|
||||
|
||||
|
@ -706,10 +691,6 @@ buildsuper(char *code_path, char *out_path, char *filename){
|
|||
Temp_Dir temp = pushdir(out_path);
|
||||
|
||||
#if defined(IS_CL)
|
||||
slash_fix(filename);
|
||||
slash_fix(out_path);
|
||||
slash_fix(code_path);
|
||||
|
||||
systemf("call \"%s\\buildsuper.bat\" %s", code_path, filename);
|
||||
|
||||
#elif defined(IS_GCC)
|
||||
|
@ -723,119 +704,21 @@ buildsuper(char *code_path, char *out_path, char *filename){
|
|||
popdir(temp);
|
||||
}
|
||||
|
||||
#define D_META_DIR "../meta"
|
||||
#define D_META_FSM_DIR "../meta/fsmgen"
|
||||
#define D_META_GEN_DIR "../meta/metagen"
|
||||
#define D_BUILD_DIR "../build"
|
||||
#define D_BUILD_SITE_DIR "../build/site"
|
||||
#define D_SITE_GEN_DIR "../build/site/sitegen"
|
||||
#define META_DIR "../meta"
|
||||
#define BUILD_DIR "../build"
|
||||
|
||||
#define D_SITE_DIR "../site"
|
||||
#define D_PACK_DIR "../distributions"
|
||||
#define D_PACK_DATA_DIR "../data/dist_files"
|
||||
#define D_DATA_DIR "../data/test"
|
||||
#define SITE_DIR "../site"
|
||||
#define PACK_DIR "../distributions"
|
||||
#define PACK_DATA_DIR "../data/dist_files"
|
||||
#define DATA_DIR "../data/test"
|
||||
|
||||
#define D_PACK_ALPHA_PAR_DIR "../current_dist"
|
||||
#define D_PACK_SUPER_PAR_DIR "../current_dist_super"
|
||||
#define D_PACK_POWER_PAR_DIR "../current_dist_power"
|
||||
#define PACK_ALPHA_PAR_DIR "../current_dist"
|
||||
#define PACK_SUPER_PAR_DIR "../current_dist_super"
|
||||
#define PACK_POWER_PAR_DIR "../current_dist_power"
|
||||
|
||||
#define D_PACK_ALPHA_DIR D_PACK_ALPHA_PAR_DIR"/4coder"
|
||||
#define D_PACK_SUPER_DIR D_PACK_SUPER_PAR_DIR"/4coder"
|
||||
#define D_PACK_POWER_DIR D_PACK_POWER_PAR_DIR"/power"
|
||||
|
||||
static char *META_DIR = 0;
|
||||
static char *META_FSM_DIR = 0;
|
||||
static char *META_GEN_DIR = 0;
|
||||
static char *BUILD_DIR = 0;
|
||||
static char *BUILD_SITE_DIR = 0;
|
||||
static char *SITE_GEN_DIR = 0;
|
||||
static char *SITE_DIR = 0;
|
||||
static char *PACK_DIR = 0;
|
||||
static char *PACK_DATA_DIR = 0;
|
||||
static char *DATA_DIR = 0;
|
||||
static char *PACK_ALPHA_PAR_DIR = 0;
|
||||
static char *PACK_SUPER_PAR_DIR = 0;
|
||||
static char *PACK_POWER_PAR_DIR = 0;
|
||||
static char *PACK_ALPHA_DIR = 0;
|
||||
static char *PACK_SUPER_DIR = 0;
|
||||
static char *PACK_POWER_DIR = 0;
|
||||
|
||||
static char*
|
||||
get_head(String builder){
|
||||
return(builder.str + builder.size);
|
||||
}
|
||||
|
||||
static void
|
||||
init_global_strings(){
|
||||
int32_t size = (1 << 12);
|
||||
char *base = (char*)malloc(size);
|
||||
String builder = make_string_cap(base, 0, size);
|
||||
String term = make_string((void*)"\0", 1);
|
||||
|
||||
META_DIR = get_head(builder);
|
||||
append_sc(&builder, D_META_DIR);
|
||||
append_ss(&builder, term);
|
||||
|
||||
META_FSM_DIR = get_head(builder);
|
||||
append_sc(&builder, D_META_FSM_DIR);
|
||||
append_ss(&builder, term);
|
||||
|
||||
META_GEN_DIR = get_head(builder);
|
||||
append_sc(&builder, D_META_GEN_DIR);
|
||||
append_ss(&builder, term);
|
||||
|
||||
BUILD_DIR = get_head(builder);
|
||||
append_sc(&builder, D_BUILD_DIR);
|
||||
append_ss(&builder, term);
|
||||
|
||||
BUILD_SITE_DIR = get_head(builder);
|
||||
append_sc(&builder, D_BUILD_SITE_DIR);
|
||||
append_ss(&builder, term);
|
||||
|
||||
SITE_GEN_DIR = get_head(builder);
|
||||
append_sc(&builder, D_SITE_GEN_DIR);
|
||||
append_ss(&builder, term);
|
||||
|
||||
SITE_DIR = get_head(builder);
|
||||
append_sc(&builder, D_SITE_DIR);
|
||||
append_ss(&builder, term);
|
||||
|
||||
PACK_DIR = get_head(builder);
|
||||
append_sc(&builder, D_PACK_DIR);
|
||||
append_ss(&builder, term);
|
||||
|
||||
PACK_DATA_DIR = get_head(builder);
|
||||
append_sc(&builder, D_PACK_DATA_DIR);
|
||||
append_ss(&builder, term);
|
||||
|
||||
DATA_DIR = get_head(builder);
|
||||
append_sc(&builder, D_DATA_DIR);
|
||||
append_ss(&builder, term);
|
||||
|
||||
PACK_ALPHA_PAR_DIR = get_head(builder);
|
||||
append_sc(&builder, D_PACK_ALPHA_PAR_DIR);
|
||||
append_ss(&builder, term);
|
||||
|
||||
PACK_SUPER_PAR_DIR = get_head(builder);
|
||||
append_sc(&builder, D_PACK_SUPER_PAR_DIR);
|
||||
append_ss(&builder, term);
|
||||
|
||||
PACK_POWER_PAR_DIR = get_head(builder);
|
||||
append_sc(&builder, D_PACK_POWER_PAR_DIR);
|
||||
append_ss(&builder, term);
|
||||
|
||||
PACK_ALPHA_DIR = get_head(builder);
|
||||
append_sc(&builder, D_PACK_ALPHA_DIR);
|
||||
append_ss(&builder, term);
|
||||
|
||||
PACK_SUPER_DIR = get_head(builder);
|
||||
append_sc(&builder, D_PACK_SUPER_DIR);
|
||||
append_ss(&builder, term);
|
||||
|
||||
PACK_POWER_DIR = get_head(builder);
|
||||
append_sc(&builder, D_PACK_POWER_DIR);
|
||||
append_ss(&builder, term);
|
||||
}
|
||||
#define PACK_ALPHA_DIR PACK_ALPHA_PAR_DIR"/4coder"
|
||||
#define PACK_SUPER_DIR PACK_SUPER_PAR_DIR"/4coder"
|
||||
#define PACK_POWER_DIR PACK_POWER_PAR_DIR"/power"
|
||||
|
||||
#if defined(IS_WINDOWS)
|
||||
#define PLAT_LAYER "win32_4ed.cpp"
|
||||
|
@ -845,18 +728,23 @@ init_global_strings(){
|
|||
#error No platform layer defined for this OS.
|
||||
#endif
|
||||
|
||||
#define DECL_STR(n,s) char n[] = s; slash_fix(n)
|
||||
|
||||
static void
|
||||
fsm_generator(char *cdir){
|
||||
{
|
||||
DECL_STR(file, "meta/fsm_table_generator.cpp");
|
||||
DECL_STR(dir, META_DIR);
|
||||
|
||||
BEGIN_TIME_SECTION();
|
||||
build(OPTS | DEBUG_INFO, cdir, "fsm_table_generator.cpp",
|
||||
META_DIR, "fsmgen", 0);
|
||||
build(OPTS | DEBUG_INFO, cdir, file, dir, "fsmgen", 0);
|
||||
END_TIME_SECTION("build fsm generator");
|
||||
}
|
||||
|
||||
if (prev_error == 0){
|
||||
DECL_STR(cmd, META_DIR"/fsmgen");
|
||||
BEGIN_TIME_SECTION();
|
||||
execute(cdir, META_FSM_DIR, 0);
|
||||
execute_in_dir(cdir, cmd, 0);
|
||||
END_TIME_SECTION("run fsm generator");
|
||||
}
|
||||
}
|
||||
|
@ -864,14 +752,18 @@ fsm_generator(char *cdir){
|
|||
static void
|
||||
metagen(char *cdir){
|
||||
{
|
||||
DECL_STR(file, "meta/4ed_metagen.cpp");
|
||||
DECL_STR(dir, META_DIR);
|
||||
|
||||
BEGIN_TIME_SECTION();
|
||||
build(OPTS | INCLUDES | DEBUG_INFO, cdir, "4ed_metagen.cpp", META_DIR, "metagen", 0);
|
||||
build(OPTS | INCLUDES | DEBUG_INFO, cdir, file, dir, "metagen", 0);
|
||||
END_TIME_SECTION("build metagen");
|
||||
}
|
||||
|
||||
if (prev_error == 0){
|
||||
DECL_STR(cmd, META_DIR"/metagen");
|
||||
BEGIN_TIME_SECTION();
|
||||
execute(cdir, META_GEN_DIR, 0);
|
||||
execute_in_dir(cdir, cmd, 0);
|
||||
END_TIME_SECTION("run metagen");
|
||||
}
|
||||
}
|
||||
|
@ -881,7 +773,7 @@ enum{
|
|||
Custom_Experiments,
|
||||
Custom_Casey,
|
||||
Custom_ChronalVim,
|
||||
CUSTOM_COUNT
|
||||
Custom_COUNT
|
||||
};
|
||||
|
||||
static void
|
||||
|
@ -895,52 +787,49 @@ do_buildsuper(char *cdir, int32_t custom_option){
|
|||
case Custom_Default:
|
||||
{
|
||||
copy_sc(&str, "../code/4coder_default_bindings.cpp");
|
||||
terminate_with_null(&str);
|
||||
buildsuper(cdir, BUILD_DIR, str.str);
|
||||
}break;
|
||||
|
||||
case Custom_Experiments:
|
||||
{
|
||||
#if defined(IS_WINDOWS)
|
||||
copy_sc(&str, "../code/internal_4coder_tests.cpp");
|
||||
terminate_with_null(&str);
|
||||
buildsuper(cdir, BUILD_DIR, str.str);
|
||||
#else
|
||||
copy_sc(&str, "../code/power/4coder_experiments.cpp");
|
||||
terminate_with_null(&str);
|
||||
buildsuper(cdir, BUILD_DIR, str.str);
|
||||
#endif
|
||||
}break;
|
||||
|
||||
case Custom_Casey:
|
||||
{
|
||||
copy_sc(&str, "../code/power/4coder_casey.cpp");
|
||||
terminate_with_null(&str);
|
||||
buildsuper(cdir, BUILD_DIR, str.str);
|
||||
}break;
|
||||
|
||||
case Custom_ChronalVim:
|
||||
{
|
||||
copy_sc(&str, "../4vim/4coder_chronal.cpp");
|
||||
terminate_with_null(&str);
|
||||
buildsuper(cdir, BUILD_DIR, str.str);
|
||||
}break;
|
||||
}
|
||||
|
||||
terminate_with_null(&str);
|
||||
|
||||
DECL_STR(dir, BUILD_DIR);
|
||||
buildsuper(cdir, dir, str.str);
|
||||
|
||||
END_TIME_SECTION("build custom");
|
||||
}
|
||||
|
||||
static void
|
||||
build_main(char *cdir, uint32_t flags){
|
||||
DECL_STR(dir, BUILD_DIR);
|
||||
{
|
||||
DECL_STR(file, "4ed_app_target.cpp");
|
||||
BEGIN_TIME_SECTION();
|
||||
build(OPTS | INCLUDES | SHARED_CODE | flags, cdir, "4ed_app_target.cpp", BUILD_DIR, "4ed_app"DLL, "/EXPORT:app_get_functions");
|
||||
build(OPTS | INCLUDES | SHARED_CODE | flags, cdir, file, dir, "4ed_app"DLL, "/EXPORT:app_get_functions");
|
||||
END_TIME_SECTION("build 4ed_app");
|
||||
}
|
||||
|
||||
{
|
||||
BEGIN_TIME_SECTION();
|
||||
build(OPTS | INCLUDES | LIBS | ICON | flags, cdir, PLAT_LAYER, BUILD_DIR, "4ed", 0);
|
||||
build(OPTS | INCLUDES | LIBS | ICON | flags, cdir, PLAT_LAYER, dir, "4ed", 0);
|
||||
END_TIME_SECTION("build 4ed");
|
||||
}
|
||||
}
|
||||
|
@ -957,24 +846,18 @@ standard_build(char *cdir, uint32_t flags){
|
|||
static void
|
||||
site_build(char *cdir, uint32_t flags){
|
||||
{
|
||||
DECL_STR(file, "site/sitegen.cpp");
|
||||
DECL_STR(dir, BUILD_DIR"/site");
|
||||
BEGIN_TIME_SECTION();
|
||||
// TODO(allen): Figure out how to do these strings the right way... fuck.
|
||||
#if defined(IS_WINDOWS)
|
||||
build(OPTS | SITE_INCLUDES | flags, cdir, "site\\sitegen.cpp", BUILD_SITE_DIR, "sitegen", 0);
|
||||
#else
|
||||
build(OPTS | SITE_INCLUDES | flags, cdir, "site/sitegen.cpp", BUILD_SITE_DIR, "sitegen", 0);
|
||||
#endif
|
||||
build(OPTS | SITE_INCLUDES | flags, cdir, file, dir, "sitegen", 0);
|
||||
END_TIME_SECTION("build sitegen");
|
||||
}
|
||||
|
||||
{
|
||||
BEGIN_TIME_SECTION();
|
||||
|
||||
#if defined(IS_WINDOWS)
|
||||
systemf("..\\build\\site\\sitegen . ..\\foreign\\site-resources site\\source_material ..\\site");
|
||||
#else
|
||||
systemf("../build/site/sitegen . ../foreign/site-resources site/source_material ../site");
|
||||
#endif
|
||||
DECL_STR(cmd, "../build/site/sitegen . ../site_resources site/source_material ../site");
|
||||
systemf(cmd);
|
||||
|
||||
END_TIME_SECTION("run sitegen");
|
||||
}
|
||||
|
@ -984,8 +867,7 @@ static void
|
|||
get_4coder_dist_name(String *zip_file, int32_t OS_specific, char *tier, char *ext){
|
||||
zip_file->size = 0;
|
||||
|
||||
append_sc(zip_file, PACK_DIR);
|
||||
append_sc(zip_file, "/");
|
||||
append_sc(zip_file, PACK_DIR"/");
|
||||
append_sc(zip_file, tier);
|
||||
append_sc(zip_file, "/4coder-");
|
||||
|
||||
|
@ -1027,69 +909,82 @@ package(char *cdir){
|
|||
// NOTE(allen): alpha
|
||||
build_main(cdir, OPTIMIZATION | KEEP_ASSERT | DEBUG_INFO);
|
||||
|
||||
clear_folder(PACK_ALPHA_PAR_DIR);
|
||||
make_folder_if_missing(PACK_ALPHA_DIR, "3rdparty");
|
||||
make_folder_if_missing(PACK_DIR, "alpha");
|
||||
copy_file(BUILD_DIR, "4ed"EXE, PACK_ALPHA_DIR, 0, 0);
|
||||
ONLY_WINDOWS(copy_file(BUILD_DIR, "4ed"PDB, PACK_ALPHA_DIR, 0, 0));
|
||||
copy_file(BUILD_DIR, "4ed_app"DLL, PACK_ALPHA_DIR, 0, 0);
|
||||
ONLY_WINDOWS(copy_file(BUILD_DIR, "4ed_app"PDB, PACK_ALPHA_DIR, 0, 0));
|
||||
copy_all (PACK_DATA_DIR, "*", PACK_ALPHA_DIR);
|
||||
copy_file(0, "README.txt", PACK_ALPHA_DIR, 0, 0);
|
||||
copy_file(0, "TODO.txt", PACK_ALPHA_DIR, 0, 0);
|
||||
copy_file(DATA_DIR, "release-config.4coder", PACK_ALPHA_DIR, 0, "config.4coder");
|
||||
DECL_STR(build_dir, BUILD_DIR);
|
||||
DECL_STR(site_dir, SITE_DIR);
|
||||
DECL_STR(pack_dir, PACK_DIR);
|
||||
DECL_STR(pack_data_dir, PACK_DATA_DIR);
|
||||
DECL_STR(data_dir, DATA_DIR);
|
||||
|
||||
DECL_STR(pack_alpha_par_dir, PACK_ALPHA_PAR_DIR);
|
||||
DECL_STR(pack_super_par_dir, PACK_SUPER_PAR_DIR);
|
||||
DECL_STR(pack_power_par_dir, PACK_POWER_PAR_DIR);
|
||||
|
||||
DECL_STR(pack_alpha_dir, PACK_ALPHA_DIR);
|
||||
DECL_STR(pack_super_dir, PACK_SUPER_DIR);
|
||||
DECL_STR(pack_power_dir, PACK_POWER_DIR);
|
||||
|
||||
clear_folder(pack_alpha_par_dir);
|
||||
make_folder_if_missing(pack_alpha_dir, "3rdparty");
|
||||
make_folder_if_missing(pack_dir, "alpha");
|
||||
copy_file(build_dir, "4ed"EXE, pack_alpha_dir, 0, 0);
|
||||
ONLY_WINDOWS(copy_file(build_dir, "4ed"PDB, pack_alpha_dir, 0, 0));
|
||||
copy_file(build_dir, "4ed_app"DLL, pack_alpha_dir, 0, 0);
|
||||
ONLY_WINDOWS(copy_file(build_dir, "4ed_app"PDB, pack_alpha_dir, 0, 0));
|
||||
copy_all (pack_data_dir, "*", pack_alpha_dir);
|
||||
copy_file(0, "README.txt", pack_alpha_dir, 0, 0);
|
||||
copy_file(0, "TODO.txt", pack_alpha_dir, 0, 0);
|
||||
copy_file(DATA_DIR, "release-config.4coder", pack_alpha_dir, 0, "config.4coder");
|
||||
|
||||
get_4coder_dist_name(&str, 1, "alpha", "zip");
|
||||
zip(PACK_ALPHA_PAR_DIR, "4coder", str.str);
|
||||
zip(pack_alpha_par_dir, "4coder", str.str);
|
||||
|
||||
// NOTE(allen): super
|
||||
build_main(cdir, OPTIMIZATION | KEEP_ASSERT | DEBUG_INFO | SUPER);
|
||||
do_buildsuper(cdir, Custom_Default);
|
||||
|
||||
clear_folder(PACK_SUPER_PAR_DIR);
|
||||
make_folder_if_missing(PACK_SUPER_DIR, "3rdparty");
|
||||
make_folder_if_missing(PACK_DIR, "super");
|
||||
make_folder_if_missing(PACK_DIR, "super-docs");
|
||||
clear_folder(pack_super_par_dir);
|
||||
make_folder_if_missing(pack_super_dir, "3rdparty");
|
||||
make_folder_if_missing(pack_dir, "super");
|
||||
make_folder_if_missing(pack_dir, "super-docs");
|
||||
|
||||
copy_file(BUILD_DIR, "4ed"EXE, PACK_SUPER_DIR, 0, 0);
|
||||
ONLY_WINDOWS(copy_file(BUILD_DIR, "4ed"PDB, PACK_SUPER_DIR, 0, 0));
|
||||
copy_file(BUILD_DIR, "4ed_app"DLL, PACK_SUPER_DIR, 0, 0);
|
||||
ONLY_WINDOWS(copy_file(BUILD_DIR, "4ed_app"PDB, PACK_SUPER_DIR, 0, 0));
|
||||
copy_file(BUILD_DIR, "4coder_custom"DLL, PACK_SUPER_DIR, 0, 0);
|
||||
copy_file(build_dir, "4ed"EXE, pack_super_dir, 0, 0);
|
||||
ONLY_WINDOWS(copy_file(build_dir, "4ed"PDB, pack_super_dir, 0, 0));
|
||||
copy_file(build_dir, "4ed_app"DLL, pack_super_dir, 0, 0);
|
||||
ONLY_WINDOWS(copy_file(build_dir, "4ed_app"PDB, pack_super_dir, 0, 0));
|
||||
copy_file(build_dir, "4coder_custom"DLL, pack_super_dir, 0, 0);
|
||||
|
||||
copy_all (PACK_DATA_DIR, "*", PACK_SUPER_DIR);
|
||||
copy_file(0, "README.txt", PACK_SUPER_DIR, 0, 0);
|
||||
copy_file(0, "TODO.txt", PACK_SUPER_DIR, 0, 0);
|
||||
copy_file(DATA_DIR, "release-config.4coder", PACK_SUPER_DIR, 0, "config.4coder");
|
||||
copy_all (pack_data_dir, "*", pack_super_dir);
|
||||
copy_file(0, "README.txt", pack_super_dir, 0, 0);
|
||||
copy_file(0, "TODO.txt", pack_super_dir, 0, 0);
|
||||
copy_file(data_dir, "release-config.4coder", pack_super_dir, 0, "config.4coder");
|
||||
|
||||
copy_all (0, "4coder_*.h", PACK_SUPER_DIR);
|
||||
copy_all (0, "4coder_*.cpp", PACK_SUPER_DIR);
|
||||
copy_all (0, "4cpp_*.h", PACK_SUPER_DIR);
|
||||
copy_all (0, "4cpp_*.c", PACK_SUPER_DIR);
|
||||
copy_file(0, "buildsuper"BAT, PACK_SUPER_DIR, 0, 0);
|
||||
copy_all (0, "4coder_*.h", pack_super_dir);
|
||||
copy_all (0, "4coder_*.cpp", pack_super_dir);
|
||||
copy_all (0, "4cpp_*.h", pack_super_dir);
|
||||
copy_all (0, "4cpp_*.c", pack_super_dir);
|
||||
copy_file(0, "buildsuper"BAT, pack_super_dir, 0, 0);
|
||||
|
||||
get_4coder_dist_name(&str, 0, "API", "html");
|
||||
str2 = front_of_directory(str);
|
||||
copy_file(SITE_DIR, "custom_docs.html", PACK_DIR, "super-docs", str2.str);
|
||||
copy_file(site_dir, "custom_docs.html", pack_dir, "super-docs", str2.str);
|
||||
|
||||
get_4coder_dist_name(&str, 1, "super", "zip");
|
||||
zip(PACK_SUPER_PAR_DIR, "4coder", str.str);
|
||||
zip(pack_super_par_dir, "4coder", str.str);
|
||||
|
||||
// NOTE(allen): power
|
||||
clear_folder(PACK_POWER_PAR_DIR);
|
||||
make_folder_if_missing(PACK_POWER_DIR, 0);
|
||||
make_folder_if_missing(PACK_DIR, "power");
|
||||
copy_all("power", "*", PACK_POWER_DIR);
|
||||
clear_folder(pack_power_par_dir);
|
||||
make_folder_if_missing(pack_power_dir, 0);
|
||||
make_folder_if_missing(pack_dir, "power");
|
||||
copy_all("power", "*", pack_power_dir);
|
||||
|
||||
get_4coder_dist_name(&str, 0, "power", "zip");
|
||||
zip(PACK_POWER_PAR_DIR, "power", str.str);
|
||||
zip(pack_power_par_dir, "power", str.str);
|
||||
}
|
||||
|
||||
#if defined(DEV_BUILD)
|
||||
|
||||
int main(int argc, char **argv){
|
||||
init_time_system();
|
||||
init_global_strings();
|
||||
|
||||
char cdir[256];
|
||||
|
||||
|
@ -1125,7 +1020,6 @@ int main(int argc, char **argv){
|
|||
|
||||
int main(int argc, char **argv){
|
||||
init_time_system();
|
||||
init_global_strings();
|
||||
|
||||
char cdir[256];
|
||||
|
|
@ -14,8 +14,8 @@
|
|||
#define Assert(n) do{ if (!(n)) { *(int*)0 = 0xA11E; } }while(0)
|
||||
#define ArrayCount(a) (sizeof(a)/sizeof(*a))
|
||||
|
||||
#include "4cpp_lexer_types.h"
|
||||
#include "4ed_mem_ansi.c"
|
||||
#include "../4cpp_lexer_types.h"
|
||||
#include "../4ed_mem_ansi.c"
|
||||
|
||||
typedef struct Whitespace_FSM{
|
||||
unsigned char pp_state;
|
|
@ -16,14 +16,14 @@
|
|||
#include "internal_4coder_string.cpp"
|
||||
#endif
|
||||
|
||||
#include "4cpp_lexer.h"
|
||||
#include "../4cpp_lexer.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "4coder_mem.h"
|
||||
#include "../4coder_mem.h"
|
||||
|
||||
typedef struct Parse_Context{
|
||||
Cpp_Token *token_s;
|
|
@ -3,5 +3,5 @@
|
|||
WARNINGS="-Wno-write-strings"
|
||||
FLAGS="-D_GNU_SOURCE -fPIC -fpermissive -DPACKAGE"
|
||||
|
||||
g++ $WARNINGS $FLAGS build.cpp -g -o ../build/build
|
||||
g++ $WARNINGS $FLAGS meta/build.cpp -g -o ../build/build
|
||||
../build/build
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
extensions=".c.cpp.h.hpp.bat.sh";
|
||||
|
||||
// NOTE(allen): There is some kind of bug where hitting f12 causes a crash. It looks like there is a special meaning placed on some fkeys by windows, which I have not found how to disable yet.
|
||||
fkey_command_win[1] = {"build.bat", "*compilation*", true};
|
||||
fkey_command_win[2] = {"..\\misc\\run.bat", "*run*"};
|
||||
fkey_command_win[3] = {"site\\build.bat", "*compilation*", true};
|
||||
fkey_command_win[4] = {"file\\run_tests.bat", "*tests*"};
|
||||
fkey_command_win[4] = {"file\\run_tests.bat", "*tests*", true};
|
||||
fkey_command_win[5] = {0, 0};
|
||||
fkey_command_win[6] = {0, 0};
|
||||
fkey_command_win[7] = {0, 0};
|
||||
|
|
|
@ -9,11 +9,6 @@
|
|||
|
||||
// TOP
|
||||
|
||||
#if !defined(ABSTRACT_DOCUMENT_H)
|
||||
#define ABSTRACT_DOCUMENT_H
|
||||
|
||||
#define NotImplemented Assert(!"Not Implemented!")
|
||||
|
||||
// Enriched Text
|
||||
|
||||
struct Enriched_Text{
|
||||
|
@ -65,20 +60,20 @@ enum{
|
|||
struct Document_Item{
|
||||
Document_Item *next;
|
||||
Document_Item *parent;
|
||||
int32_t type;
|
||||
i32 type;
|
||||
union{
|
||||
struct{
|
||||
Document_Item *first_child;
|
||||
Document_Item *last_child;
|
||||
String name;
|
||||
String id;
|
||||
int32_t show_title;
|
||||
i32 show_title;
|
||||
} section;
|
||||
|
||||
struct{
|
||||
Meta_Unit *unit;
|
||||
Alternate_Names_Array *alt_names;
|
||||
int32_t alt_name_type;
|
||||
i32 alt_name_type;
|
||||
} unit_elements;
|
||||
|
||||
struct{
|
||||
|
@ -108,7 +103,7 @@ struct Basic_List{
|
|||
};
|
||||
|
||||
struct Abstract_Item{
|
||||
int32_t item_type;
|
||||
i32 item_type;
|
||||
char *name;
|
||||
|
||||
// Document value members
|
||||
|
@ -118,7 +113,7 @@ struct Abstract_Item{
|
|||
// Document building members
|
||||
Partition *part;
|
||||
Document_Item *section_stack[16];
|
||||
int32_t section_top;
|
||||
i32 section_top;
|
||||
|
||||
// Image value members
|
||||
char *source_file;
|
||||
|
@ -130,7 +125,7 @@ struct Abstract_Item{
|
|||
static Abstract_Item null_abstract_item = {0};
|
||||
|
||||
struct Image_Instantiation{
|
||||
int32_t w, h;
|
||||
i32 w, h;
|
||||
};
|
||||
|
||||
struct Document_System{
|
||||
|
@ -148,8 +143,8 @@ create_document_system(Partition *part){
|
|||
}
|
||||
|
||||
static void*
|
||||
push_item_on_list(Partition *part, Basic_List *list, int32_t item_size){
|
||||
int32_t mem_size = item_size + sizeof(Basic_Node);
|
||||
push_item_on_list(Partition *part, Basic_List *list, i32 item_size){
|
||||
i32 mem_size = item_size + sizeof(Basic_Node);
|
||||
void *mem = push_block(part, mem_size);
|
||||
assert(mem != 0);
|
||||
memset(mem, 0, mem_size);
|
||||
|
@ -203,7 +198,7 @@ get_item_by_name(Basic_List list, char *name){
|
|||
}
|
||||
|
||||
static Image_Instantiation*
|
||||
get_image_instantiation(Basic_List list, int32_t w, int32_t h){
|
||||
get_image_instantiation(Basic_List list, i32 w, i32 h){
|
||||
Image_Instantiation *result = 0;
|
||||
|
||||
for (Basic_Node *node = list.head;
|
||||
|
@ -232,15 +227,15 @@ create_item(Partition *part, Basic_List *list, char *name){
|
|||
}
|
||||
|
||||
static void
|
||||
add_image_instantiation(Partition *part, Basic_List *list, int32_t w, int32_t h){
|
||||
add_image_instantiation(Partition *part, Basic_List *list, i32 w, i32 h){
|
||||
Image_Instantiation *instantiation = (Image_Instantiation*)push_item_on_list(part, list, sizeof(Image_Instantiation));
|
||||
instantiation->w = w;
|
||||
instantiation->h = h;
|
||||
}
|
||||
|
||||
static void
|
||||
set_section_name(Partition *part, Document_Item *item, char *name, int32_t show_title){
|
||||
int32_t name_len = str_size(name);
|
||||
set_section_name(Partition *part, Document_Item *item, char *name, i32 show_title){
|
||||
i32 name_len = str_size(name);
|
||||
item->section.name = make_string_cap(push_array(part, char, name_len+1), 0, name_len+1);
|
||||
partition_align(part, 8);
|
||||
append_sc(&item->section.name, name);
|
||||
|
@ -249,14 +244,14 @@ set_section_name(Partition *part, Document_Item *item, char *name, int32_t show_
|
|||
|
||||
static void
|
||||
set_section_id(Partition *part, Document_Item *item, char *id){
|
||||
int32_t id_len = str_size(id);
|
||||
i32 id_len = str_size(id);
|
||||
item->section.id = make_string_cap(push_array(part, char, id_len+1), 0, id_len+1);
|
||||
partition_align(part, 8);
|
||||
append_sc(&item->section.id, id);
|
||||
}
|
||||
|
||||
static void
|
||||
begin_document_description(Abstract_Item *doc, Partition *part, char *title, int32_t show_title){
|
||||
begin_document_description(Abstract_Item *doc, Partition *part, char *title, i32 show_title){
|
||||
*doc = null_abstract_item;
|
||||
doc->item_type = ItemType_Document;
|
||||
doc->part = part;
|
||||
|
@ -290,23 +285,23 @@ add_image_description(Document_System *system, char *source_file, char *extensio
|
|||
item->source_file = source_file;
|
||||
item->name = name;
|
||||
|
||||
int32_t w = 0, h = 0, comp = 0;
|
||||
int32_t stbi_r = stbi_info(source_file, &w, &h, &comp);
|
||||
i32 w = 0, h = 0, comp = 0;
|
||||
i32 stbi_r = stbi_info(source_file, &w, &h, &comp);
|
||||
if (!stbi_r){
|
||||
fprintf(stderr, "Did not find file %s\n", source_file);
|
||||
item->w_h_ratio = 1.f;
|
||||
item->h_w_ratio = 1.f;
|
||||
}
|
||||
else{
|
||||
item->w_h_ratio = ((float)w/(float)h);
|
||||
item->h_w_ratio = ((float)h/(float)w);
|
||||
item->w_h_ratio = ((float)w/(float)h);
|
||||
item->h_w_ratio = ((float)h/(float)w);
|
||||
}
|
||||
}
|
||||
return(item);
|
||||
}
|
||||
|
||||
static Abstract_Item*
|
||||
begin_document_description(Document_System *system, char *title, char *name, int32_t show_title){
|
||||
begin_document_description(Document_System *system, char *title, char *name, i32 show_title){
|
||||
Abstract_Item *item = create_item(system->part, &system->doc_list, name);
|
||||
if (item){
|
||||
begin_document_description(item, system->part, title, show_title);
|
||||
|
@ -380,7 +375,7 @@ add_element_list(Abstract_Item *doc, Meta_Unit *unit){
|
|||
}
|
||||
|
||||
static void
|
||||
add_element_list(Abstract_Item *doc, Meta_Unit *unit, Alternate_Names_Array *alt_names, int32_t alt_name_type){
|
||||
add_element_list(Abstract_Item *doc, Meta_Unit *unit, Alternate_Names_Array *alt_names, i32 alt_name_type){
|
||||
Document_Item *parent = doc->section_stack[doc->section_top];
|
||||
Document_Item *item = push_struct(doc->part, Document_Item);
|
||||
*item = null_document_item;
|
||||
|
@ -404,7 +399,7 @@ add_full_elements(Abstract_Item *doc, Meta_Unit *unit){
|
|||
}
|
||||
|
||||
static void
|
||||
add_full_elements(Abstract_Item *doc, Meta_Unit *unit, Alternate_Names_Array *alt_names, int32_t alt_name_type){
|
||||
add_full_elements(Abstract_Item *doc, Meta_Unit *unit, Alternate_Names_Array *alt_names, i32 alt_name_type){
|
||||
Document_Item *parent = doc->section_stack[doc->section_top];
|
||||
Document_Item *item = push_struct(doc->part, Document_Item);
|
||||
*item = null_document_item;
|
||||
|
@ -479,21 +474,21 @@ add_enriched_text(Abstract_Item *doc, Enriched_Text *text){
|
|||
#define HTML_EXAMPLE_CODE_CLOSE "</div>"
|
||||
|
||||
struct Section_Counter{
|
||||
int32_t counter[16];
|
||||
int32_t nest_level;
|
||||
i32 counter[16];
|
||||
i32 nest_level;
|
||||
};
|
||||
|
||||
static int32_t
|
||||
doc_get_link_string(Abstract_Item *doc, char *space, int32_t capacity){
|
||||
static i32
|
||||
doc_get_link_string(Abstract_Item *doc, char *space, i32 capacity){
|
||||
String str = make_string_cap(space, 0, capacity);
|
||||
append_sc(&str, doc->name);
|
||||
append_sc(&str, ".html");
|
||||
int32_t result = terminate_with_null(&str);
|
||||
i32 result = terminate_with_null(&str);
|
||||
return(result);
|
||||
}
|
||||
|
||||
static int32_t
|
||||
img_get_link_string(Abstract_Item *img, char *space, int32_t capacity, int32_t w, int32_t h){
|
||||
static i32
|
||||
img_get_link_string(Abstract_Item *img, char *space, i32 capacity, i32 w, i32 h){
|
||||
String str = make_string_cap(space, 0, capacity);
|
||||
append_sc(&str, img->name);
|
||||
|
||||
|
@ -504,14 +499,14 @@ img_get_link_string(Abstract_Item *img, char *space, int32_t capacity, int32_t w
|
|||
|
||||
append_sc(&str, ".");
|
||||
append_sc(&str, img->extension);
|
||||
int32_t result = terminate_with_null(&str);
|
||||
i32 result = terminate_with_null(&str);
|
||||
return(result);
|
||||
}
|
||||
|
||||
static void
|
||||
append_section_number_reduced(String *out, Section_Counter *section_counter, int32_t reduce){
|
||||
int32_t level = section_counter->nest_level-reduce;
|
||||
for (int32_t i = 1; i <= level; ++i){
|
||||
append_section_number_reduced(String *out, Section_Counter *section_counter, i32 reduce){
|
||||
i32 level = section_counter->nest_level-reduce;
|
||||
for (i32 i = 1; i <= level; ++i){
|
||||
append_int_to_str(out, section_counter->counter[i]);
|
||||
if (i != level){
|
||||
append_sc(out, ".");
|
||||
|
@ -524,11 +519,11 @@ append_section_number(String *out, Section_Counter *section_counter){
|
|||
append_section_number_reduced(out, section_counter, 0);
|
||||
}
|
||||
|
||||
static int32_t
|
||||
extract_command_body(String *out, String l, int32_t *i_in_out, int32_t *body_start_out, int32_t *body_end_out, String command_name, int32_t require_body){
|
||||
int32_t result = 0;
|
||||
static i32
|
||||
extract_command_body(String *out, String l, i32 *i_in_out, i32 *body_start_out, i32 *body_end_out, String command_name, i32 require_body){
|
||||
i32 result = 0;
|
||||
|
||||
int32_t i = *i_in_out;
|
||||
i32 i = *i_in_out;
|
||||
|
||||
for (; i < l.size; ++i){
|
||||
if (!char_is_whitespace(l.str[i])){
|
||||
|
@ -536,8 +531,8 @@ extract_command_body(String *out, String l, int32_t *i_in_out, int32_t *body_sta
|
|||
}
|
||||
}
|
||||
|
||||
int32_t found_command_body = 0;
|
||||
int32_t body_start = 0, body_end = 0;
|
||||
i32 found_command_body = 0;
|
||||
i32 body_start = 0, body_end = 0;
|
||||
if (l.str[i] == '{'){
|
||||
body_start = i+1;
|
||||
|
||||
|
@ -558,12 +553,12 @@ extract_command_body(String *out, String l, int32_t *i_in_out, int32_t *body_sta
|
|||
if (require_body){
|
||||
#define STR_START "<span style='color:#F00'>! Doc generator error: missing body for "
|
||||
#define STR_SLOW " !</span>"
|
||||
append_sc(out, STR_START);
|
||||
append_ss(out, command_name);
|
||||
append_sc(out, STR_SLOW);
|
||||
append_sc(out, STR_START);
|
||||
append_ss(out, command_name);
|
||||
append_sc(out, STR_SLOW);
|
||||
#undef STR
|
||||
|
||||
fprintf(stderr, "error: missing body for %.*s\n", command_name.size, command_name.str);
|
||||
|
||||
fprintf(stderr, "error: missing body for %.*s\n", command_name.size, command_name.str);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -614,7 +609,7 @@ write_enriched_text_html(String *out, Partition *part, Enriched_Text *text, Docu
|
|||
|
||||
append_sc(out, "<div>");
|
||||
|
||||
int32_t item_counter = 0;
|
||||
i32 item_counter = 0;
|
||||
|
||||
for (String line = get_first_double_line(source);
|
||||
line.str;
|
||||
|
@ -623,13 +618,13 @@ write_enriched_text_html(String *out, Partition *part, Enriched_Text *text, Docu
|
|||
append_sc(out, "<p>");
|
||||
|
||||
//append_ss(out, l);
|
||||
int32_t start = 0, i = 0;
|
||||
i32 start = 0, i = 0;
|
||||
for (; i < l.size; ++i){
|
||||
if (l.str[i] == '\\'){
|
||||
append_ss(out, substr(l, start, i-start));
|
||||
|
||||
int32_t command_start = i+1;
|
||||
int32_t command_end = command_start;
|
||||
i32 command_start = i+1;
|
||||
i32 command_end = command_start;
|
||||
for (; command_end < l.size; ++command_end){
|
||||
if (!char_is_alpha_numeric(l.str[command_end])){
|
||||
break;
|
||||
|
@ -684,7 +679,7 @@ write_enriched_text_html(String *out, Partition *part, Enriched_Text *text, Docu
|
|||
|
||||
i = command_end;
|
||||
|
||||
int32_t match_index = 0;
|
||||
i32 match_index = 0;
|
||||
if (string_set_match(enriched_commands, ArrayCount(enriched_commands), command_string, &match_index)){
|
||||
switch (match_index){
|
||||
case Cmd_BackSlash: append_sc(out, "\\"); break;
|
||||
|
@ -692,8 +687,8 @@ write_enriched_text_html(String *out, Partition *part, Enriched_Text *text, Docu
|
|||
|
||||
case Cmd_BeginStyle:
|
||||
{
|
||||
int32_t body_start = 0, body_end = 0;
|
||||
int32_t has_body = extract_command_body(out, l, &i, &body_start, &body_end, command_string, 1);
|
||||
i32 body_start = 0, body_end = 0;
|
||||
i32 has_body = extract_command_body(out, l, &i, &body_start, &body_end, command_string, 1);
|
||||
if (has_body){
|
||||
String body_text = substr(l, body_start, body_end - body_start);
|
||||
body_text = skip_chop_whitespace(body_text);
|
||||
|
@ -711,8 +706,8 @@ write_enriched_text_html(String *out, Partition *part, Enriched_Text *text, Docu
|
|||
// TODO(allen): upgrade this bs
|
||||
case Cmd_DocLink:
|
||||
{
|
||||
int32_t body_start = 0, body_end = 0;
|
||||
int32_t has_body = extract_command_body(out, l, &i, &body_start, &body_end, command_string, 1);
|
||||
i32 body_start = 0, body_end = 0;
|
||||
i32 has_body = extract_command_body(out, l, &i, &body_start, &body_end, command_string, 1);
|
||||
if (has_body){
|
||||
String body_text = substr(l, body_start, body_end - body_start);
|
||||
body_text = skip_chop_whitespace(body_text);
|
||||
|
@ -754,8 +749,8 @@ write_enriched_text_html(String *out, Partition *part, Enriched_Text *text, Docu
|
|||
case Cmd_Section:
|
||||
{
|
||||
// TODO(allen): undo the duplication of this body extraction code.
|
||||
int32_t body_start = 0, body_end = 0;
|
||||
int32_t has_body = extract_command_body(out, l, &i, &body_start, &body_end, command_string, 1);
|
||||
i32 body_start = 0, body_end = 0;
|
||||
i32 has_body = extract_command_body(out, l, &i, &body_start, &body_end, command_string, 1);
|
||||
if (has_body){
|
||||
String body_text = substr(l, body_start, body_end - body_start);
|
||||
body_text = skip_chop_whitespace(body_text);
|
||||
|
@ -768,8 +763,8 @@ write_enriched_text_html(String *out, Partition *part, Enriched_Text *text, Docu
|
|||
|
||||
case Cmd_BeginLink:
|
||||
{
|
||||
int32_t body_start = 0, body_end = 0;
|
||||
int32_t has_body = extract_command_body(out, l, &i, &body_start, &body_end, command_string, 1);
|
||||
i32 body_start = 0, body_end = 0;
|
||||
i32 has_body = extract_command_body(out, l, &i, &body_start, &body_end, command_string, 1);
|
||||
if (has_body){
|
||||
String body_text = substr(l, body_start, body_end - body_start);
|
||||
body_text = skip_chop_whitespace(body_text);
|
||||
|
@ -809,15 +804,15 @@ write_enriched_text_html(String *out, Partition *part, Enriched_Text *text, Docu
|
|||
case Cmd_Image:
|
||||
{
|
||||
// TODO(allen): generalize this
|
||||
int32_t body_start = 0, body_end = 0;
|
||||
int32_t has_body = extract_command_body(out, l, &i, &body_start, &body_end, command_string, 1);
|
||||
i32 body_start = 0, body_end = 0;
|
||||
i32 has_body = extract_command_body(out, l, &i, &body_start, &body_end, command_string, 1);
|
||||
|
||||
if (has_body){
|
||||
String body_text = substr(l, body_start, body_end - body_start);
|
||||
body_text = skip_chop_whitespace(body_text);
|
||||
|
||||
int32_t pixel_height = 10;
|
||||
int32_t pixel_width = HTML_WIDTH;
|
||||
i32 pixel_height = 10;
|
||||
i32 pixel_width = HTML_WIDTH;
|
||||
|
||||
body_start = 0, body_end = 0;
|
||||
has_body = extract_command_body(out, l, &i, &body_start, &body_end, command_string, 0);
|
||||
|
@ -862,11 +857,11 @@ write_enriched_text_html(String *out, Partition *part, Enriched_Text *text, Docu
|
|||
case Cmd_Video:
|
||||
{
|
||||
// TODO(allen): generalize this
|
||||
int32_t body_start = 0, body_end = 0;
|
||||
int32_t has_body = extract_command_body(out, l, &i, &body_start, &body_end, command_string, 1);
|
||||
i32 body_start = 0, body_end = 0;
|
||||
i32 has_body = extract_command_body(out, l, &i, &body_start, &body_end, command_string, 1);
|
||||
|
||||
int32_t pixel_width = HTML_WIDTH;
|
||||
int32_t pixel_height = (int32_t)(pixel_width * 0.5625);
|
||||
i32 pixel_width = HTML_WIDTH;
|
||||
i32 pixel_height = (i32)(pixel_width * 0.5625);
|
||||
|
||||
if (has_body){
|
||||
String body_text = substr(l, body_start, body_end - body_start);
|
||||
|
@ -879,7 +874,7 @@ write_enriched_text_html(String *out, Partition *part, Enriched_Text *text, Docu
|
|||
append_int_to_str(out, pixel_width);
|
||||
append_sc(out, "' height='");
|
||||
append_int_to_str(out, pixel_height);
|
||||
append_sc(out, "' src='");
|
||||
append_sc(out, "' src='");
|
||||
append_ss(out, youtube_str);
|
||||
append_sc(out, "' allowfullscreen> </iframe>");
|
||||
}
|
||||
|
@ -917,16 +912,16 @@ print_item_in_list(String *out, String name, char *id_postfix){
|
|||
}
|
||||
|
||||
static void
|
||||
init_used_links(Partition *part, Used_Links *used, int32_t count){
|
||||
init_used_links(Partition *part, Used_Links *used, i32 count){
|
||||
used->strs = push_array(part, String, count);
|
||||
used->count = 0;
|
||||
used->max = count;
|
||||
}
|
||||
|
||||
static int32_t
|
||||
static i32
|
||||
try_to_use(Used_Links *used, String str){
|
||||
int32_t result = 1;
|
||||
int32_t index = 0;
|
||||
i32 result = 1;
|
||||
i32 index = 0;
|
||||
|
||||
if (string_set_match(used->strs, used->count, str, &index)){
|
||||
result = 0;
|
||||
|
@ -939,7 +934,7 @@ try_to_use(Used_Links *used, String str){
|
|||
}
|
||||
|
||||
static void
|
||||
print_struct_html(String *out, Item_Node *member, int32_t hide_children){
|
||||
print_struct_html(String *out, Item_Node *member, i32 hide_children){
|
||||
String name = member->name;
|
||||
String type = member->type;
|
||||
String type_postfix = member->type_postfix;
|
||||
|
@ -991,7 +986,7 @@ print_function_html(String *out, Used_Links *used, String cpp_name, String ret,
|
|||
else{
|
||||
append_sc(out, "(<div style='margin-left: 4mm;'>");
|
||||
|
||||
for (int32_t j = 0; j < breakdown.count; ++j){
|
||||
for (i32 j = 0; j < breakdown.count; ++j){
|
||||
append_ss(out, breakdown.args[j].param_string);
|
||||
if (j < breakdown.count - 1){
|
||||
append_s_char(out, ',');
|
||||
|
@ -1020,7 +1015,7 @@ print_macro_html(String *out, String name, Argument_Breakdown breakdown){
|
|||
else{
|
||||
append_sc (out, "(<div style='margin-left: 4mm;'>");
|
||||
|
||||
for (int32_t j = 0; j < breakdown.count; ++j){
|
||||
for (i32 j = 0; j < breakdown.count; ++j){
|
||||
append_ss(out, breakdown.args[j].param_string);
|
||||
if (j < breakdown.count - 1){
|
||||
append_s_char(out, ',');
|
||||
|
@ -1048,11 +1043,11 @@ static String
|
|||
get_next_doc_chunk(String source, String prev_chunk, Doc_Chunk_Type *type){
|
||||
String chunk = {0};
|
||||
String word = {0};
|
||||
int32_t pos = source.size;
|
||||
int32_t word_index = 0;
|
||||
i32 pos = source.size;
|
||||
i32 word_index = 0;
|
||||
Doc_Chunk_Type t = DocChunk_PlainText;
|
||||
|
||||
int32_t start_pos = (int32_t)(prev_chunk.str - source.str) + prev_chunk.size;
|
||||
i32 start_pos = (i32)(prev_chunk.str - source.str) + prev_chunk.size;
|
||||
String source_tail = substr_tail(source, start_pos);
|
||||
|
||||
Assert(DocChunk_Count == ArrayCount(doc_chunk_headers));
|
||||
|
@ -1061,9 +1056,9 @@ get_next_doc_chunk(String source, String prev_chunk, Doc_Chunk_Type *type){
|
|||
word.str;
|
||||
word = get_next_word(source_tail, word), ++word_index){
|
||||
|
||||
for (int32_t i = 1; i < DocChunk_Count; ++i){
|
||||
for (i32 i = 1; i < DocChunk_Count; ++i){
|
||||
if (match_ss(word, doc_chunk_headers[i])){
|
||||
pos = (int32_t)(word.str - source.str);
|
||||
pos = (i32)(word.str - source.str);
|
||||
t = (Doc_Chunk_Type)i;
|
||||
goto doublebreak;
|
||||
}
|
||||
|
@ -1075,8 +1070,8 @@ get_next_doc_chunk(String source, String prev_chunk, Doc_Chunk_Type *type){
|
|||
if (word_index == 0){
|
||||
*type = t;
|
||||
|
||||
int32_t nest_level = 1;
|
||||
int32_t i = find_s_char(source, pos, '(');
|
||||
i32 nest_level = 1;
|
||||
i32 i = find_s_char(source, pos, '(');
|
||||
for (++i; i < source.size; ++i){
|
||||
if (source.str[i] == '('){
|
||||
++nest_level;
|
||||
|
@ -1094,8 +1089,8 @@ get_next_doc_chunk(String source, String prev_chunk, Doc_Chunk_Type *type){
|
|||
|
||||
chunk = substr(source, start_pos, pos - start_pos);
|
||||
|
||||
int32_t is_all_white = 1;
|
||||
for (int32_t i = 0; i < chunk.size; ++i){
|
||||
i32 is_all_white = 1;
|
||||
for (i32 i = 0; i < chunk.size; ++i){
|
||||
if (!char_is_whitespace(chunk.str[i])){
|
||||
is_all_white = 0;
|
||||
break;
|
||||
|
@ -1137,8 +1132,8 @@ print_doc_description(String *out, Partition *part, String src){
|
|||
|
||||
case DocChunk_CodeExample:
|
||||
{
|
||||
int32_t start = 0;
|
||||
int32_t end = chunk.size-1;
|
||||
i32 start = 0;
|
||||
i32 end = chunk.size-1;
|
||||
while (start < end && chunk.str[start] != '(') ++start;
|
||||
start += 1;
|
||||
while (end > start && chunk.str[end] != ')') --end;
|
||||
|
@ -1148,14 +1143,14 @@ print_doc_description(String *out, Partition *part, String src){
|
|||
|
||||
if (start < end){
|
||||
String code_example = substr(chunk, start, end - start);
|
||||
int32_t first_line = 1;
|
||||
i32 first_line = 1;
|
||||
|
||||
for (String line = get_first_line(code_example);
|
||||
line.str;
|
||||
line = get_next_line(code_example, line)){
|
||||
|
||||
if (!(first_line && line.size == 0)){
|
||||
int32_t space_i = 0;
|
||||
i32 space_i = 0;
|
||||
for (; space_i < line.size; ++space_i){
|
||||
if (line.str[space_i] == ' '){
|
||||
append_sc(out, " ");
|
||||
|
@ -1210,11 +1205,11 @@ print_struct_docs(String *out, Partition *part, Item_Node *member){
|
|||
|
||||
static void
|
||||
print_see_also(String *out, Documentation *doc){
|
||||
int32_t doc_see_count = doc->see_also_count;
|
||||
i32 doc_see_count = doc->see_also_count;
|
||||
if (doc_see_count > 0){
|
||||
append_sc(out, HTML_DOC_HEAD_OPEN"See Also"HTML_DOC_HEAD_CLOSE);
|
||||
|
||||
for (int32_t j = 0; j < doc_see_count; ++j){
|
||||
for (i32 j = 0; j < doc_see_count; ++j){
|
||||
String see_also = doc->see_also[j];
|
||||
append_sc(out, HTML_DOC_ITEM_OPEN"<a href='#");
|
||||
append_ss(out, see_also);
|
||||
|
@ -1238,11 +1233,11 @@ print_function_docs(String *out, Partition *part, String name, String doc_string
|
|||
|
||||
perform_doc_parse(part, doc_string, &doc);
|
||||
|
||||
int32_t doc_param_count = doc.param_count;
|
||||
i32 doc_param_count = doc.param_count;
|
||||
if (doc_param_count > 0){
|
||||
append_sc(out, HTML_DOC_HEAD_OPEN"Parameters"HTML_DOC_HEAD_CLOSE);
|
||||
|
||||
for (int32_t j = 0; j < doc_param_count; ++j){
|
||||
for (i32 j = 0; j < doc_param_count; ++j){
|
||||
String param_name = doc.param_name[j];
|
||||
String param_docs = doc.param_docs[j];
|
||||
|
||||
|
@ -1277,7 +1272,7 @@ print_function_docs(String *out, Partition *part, String name, String doc_string
|
|||
}
|
||||
|
||||
static void
|
||||
print_item_html(String *out, Partition *part, Used_Links *used, Item_Node *item, char *id_postfix, char *section, int32_t I, Alternate_Name *alt_name, int32_t alt_name_type){
|
||||
print_item_html(String *out, Partition *part, Used_Links *used, Item_Node *item, char *id_postfix, char *section, i32 I, Alternate_Name *alt_name, i32 alt_name_type){
|
||||
Temp_Memory temp = begin_temp_memory(part);
|
||||
|
||||
String name = item->name;
|
||||
|
@ -1304,7 +1299,7 @@ print_item_html(String *out, Partition *part, Used_Links *used, Item_Node *item,
|
|||
append_sc(out, id_postfix);
|
||||
append_sc(out, "' style='margin-bottom: 1cm;'>");
|
||||
|
||||
int32_t has_cpp_name = 0;
|
||||
i32 has_cpp_name = 0;
|
||||
if (item->cpp_name.str != 0){
|
||||
if (try_to_use(used, item->cpp_name)){
|
||||
append_sc(out, "<div id='");
|
||||
|
@ -1451,7 +1446,7 @@ print_item_html(String *out, Partition *part, Used_Links *used, Item_Node *item,
|
|||
{
|
||||
String doc_string = item->doc_string;
|
||||
|
||||
int32_t hide_members = 0;
|
||||
i32 hide_members = 0;
|
||||
|
||||
if (doc_string.size == 0){
|
||||
hide_members = 1;
|
||||
|
@ -1607,26 +1602,26 @@ doc_item_head_html(String *out, Partition *part, Document_System *doc_system, Us
|
|||
|
||||
Meta_Unit *unit = item->unit_elements.unit;
|
||||
Alternate_Names_Array *alt_names = item->unit_elements.alt_names;
|
||||
int32_t count = unit->set.count;
|
||||
i32 count = unit->set.count;
|
||||
|
||||
switch (item->unit_elements.alt_name_type){
|
||||
case AltName_Standard:
|
||||
{
|
||||
for (int32_t i = 0; i < count; ++i){
|
||||
for (i32 i = 0; i < count; ++i){
|
||||
print_item_in_list(out, unit->set.items[i].name, "_doc");
|
||||
}
|
||||
}break;
|
||||
|
||||
case AltName_Macro:
|
||||
{
|
||||
for (int32_t i = 0; i < count; ++i){
|
||||
for (i32 i = 0; i < count; ++i){
|
||||
print_item_in_list(out, alt_names->names[i].macro, "_doc");
|
||||
}
|
||||
}break;
|
||||
|
||||
case AltName_Public_Name:
|
||||
{
|
||||
for (int32_t i = 0; i < count; ++i){
|
||||
for (i32 i = 0; i < count; ++i){
|
||||
print_item_in_list(out, alt_names->names[i].public_name, "_doc");
|
||||
}
|
||||
}break;
|
||||
|
@ -1639,7 +1634,7 @@ doc_item_head_html(String *out, Partition *part, Document_System *doc_system, Us
|
|||
{
|
||||
Meta_Unit *unit = item->unit_elements.unit;
|
||||
Alternate_Names_Array *alt_names = item->unit_elements.alt_names;
|
||||
int32_t count = unit->set.count;
|
||||
i32 count = unit->set.count;
|
||||
|
||||
char section_space[32];
|
||||
String section_str = make_fixed_width_string(section_space);
|
||||
|
@ -1647,14 +1642,14 @@ doc_item_head_html(String *out, Partition *part, Document_System *doc_system, Us
|
|||
terminate_with_null(§ion_str);
|
||||
|
||||
if (alt_names){
|
||||
int32_t I = 1;
|
||||
for (int32_t i = 0; i < count; ++i, ++I){
|
||||
i32 I = 1;
|
||||
for (i32 i = 0; i < count; ++i, ++I){
|
||||
print_item_html(out, part, used_links, &unit->set.items[i], "_doc", section_str.str, I, &alt_names->names[i], item->unit_elements.alt_name_type);
|
||||
}
|
||||
}
|
||||
else{
|
||||
int32_t I = 1;
|
||||
for (int32_t i = 0; i < count; ++i, ++I){
|
||||
i32 I = 1;
|
||||
for (i32 i = 0; i < count; ++i, ++I){
|
||||
print_item_html(out, part, used_links, &unit->set.items[i], "_doc", section_str.str, I, 0, 0);
|
||||
}
|
||||
}
|
||||
|
@ -1664,7 +1659,7 @@ doc_item_head_html(String *out, Partition *part, Document_System *doc_system, Us
|
|||
{
|
||||
append_sc(out, "<h3 style='margin:0;'>Table of Contents</h3><ul>");
|
||||
|
||||
int32_t i = 1;
|
||||
i32 i = 1;
|
||||
for (Document_Item *toc_item = item->parent->section.first_child;
|
||||
toc_item != 0;
|
||||
toc_item = toc_item->next){
|
||||
|
@ -1709,7 +1704,7 @@ generate_item_html(String *out, Partition *part, Document_System *doc_system, Us
|
|||
doc_item_head_html(out, part, doc_system, used_links, item, section_counter);
|
||||
|
||||
if (item->type == Doc_Root || item->type == Doc_Section){
|
||||
int32_t level = ++section_counter->nest_level;
|
||||
i32 level = ++section_counter->nest_level;
|
||||
section_counter->counter[level] = 1;
|
||||
for (Document_Item *m = item->section.first_child;
|
||||
m != 0;
|
||||
|
@ -1735,7 +1730,5 @@ generate_document_html(String *out, Partition *part, Document_System *doc_system
|
|||
generate_item_html(out, part, doc_system, &used_links, doc->root_item, §ion_counter);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// BOTTOM
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ SET OPTS=%OPTS% /GR- /EHa- /nologo /FC
|
|||
SET FirstError=0
|
||||
|
||||
pushd ..\build
|
||||
cl %OPTS% ..\code\build.cpp /Zi /Febuild /DSITE_BUILD
|
||||
cl %OPTS% ..\code\meta\build.cpp /Zi /Febuild /DSITE_BUILD
|
||||
if %ERRORLEVEL% neq 0 (set FirstError=1)
|
||||
popd
|
||||
|
||||
|
|
|
@ -4,5 +4,5 @@ WARNINGS="-Wno-write-strings"
|
|||
FLAGS="-D_GNU_SOURCE -fPIC -fpermissive -DSITE_BUILD"
|
||||
|
||||
BASEDIR="$PWD"
|
||||
g++ $WARNINGS $FLAGS $BASEDIR/build.cpp -g -o ../build/build
|
||||
g++ $WARNINGS $FLAGS $BASEDIR/meta/build.cpp -g -o ../build/build
|
||||
../build/build
|
||||
|
|
|
@ -16,27 +16,22 @@
|
|||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||
#include "stb_image_write.h"
|
||||
|
||||
#include "4coder_version.h"
|
||||
#define FSTRING_IMPLEMENTATION
|
||||
#include "4coder_string.h"
|
||||
#include "4cpp_lexer.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "4coder_mem.h"
|
||||
#include "../common/4coder_defines.h"
|
||||
#include "../common/4coder_version.h"
|
||||
#define FSTRING_IMPLEMENTATION
|
||||
#include "../4coder_string.h"
|
||||
#include "../4cpp_lexer.h"
|
||||
|
||||
#define CEIL32(x) ((int32_t) ( (x>0)?(x+1.f):(x) ))
|
||||
#define FLOOR32(x) ((int32_t) ( (x>0)?(x):(x-1.f) ))
|
||||
#include "../4coder_mem.h"
|
||||
|
||||
#include "meta_parser.cpp"
|
||||
#include "out_context.cpp"
|
||||
#include "../meta/meta_parser.cpp"
|
||||
#include "../meta/out_context.cpp"
|
||||
#include "abstract_document.cpp"
|
||||
|
||||
#define InvalidPath Assert(!"Invalid path of execution")
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//
|
||||
|
@ -44,14 +39,14 @@
|
|||
//
|
||||
|
||||
static void
|
||||
print_function_body_code(String *out, Parse_Context *context, int32_t start){
|
||||
print_function_body_code(String *out, Parse_Context *context, i32 start){
|
||||
String pstr = {0}, lexeme = {0};
|
||||
Cpp_Token *token = 0;
|
||||
|
||||
int32_t do_print = 0;
|
||||
int32_t nest_level = 0;
|
||||
int32_t finish = 0;
|
||||
int32_t do_whitespace_print = 0;
|
||||
i32 do_print = 0;
|
||||
i32 nest_level = 0;
|
||||
i32 finish = 0;
|
||||
i32 do_whitespace_print = 0;
|
||||
for (; (token = get_token(context)) != 0; get_next_token(context)){
|
||||
if (do_whitespace_print){
|
||||
pstr = str_start_end(context->data, start, token->start);
|
||||
|
@ -92,7 +87,7 @@ print_function_body_code(String *out, Parse_Context *context, int32_t start){
|
|||
}
|
||||
|
||||
static Alternate_Names_Array
|
||||
allocate_app_api(Partition *part, int32_t count){
|
||||
allocate_app_api(Partition *part, i32 count){
|
||||
Alternate_Names_Array app_api = {0};
|
||||
app_api.names = push_array(part, Alternate_Name, count);
|
||||
memset(app_api.names, 0, sizeof(Alternate_Name)*count);
|
||||
|
@ -129,7 +124,7 @@ assert_files_are_equal(char *directory, char *filename1, char *filename2){
|
|||
static void
|
||||
do_html_output(Document_System *doc_system, Partition *part, char *dst_directory, Abstract_Item *doc){
|
||||
// NOTE(allen): Output
|
||||
int32_t out_size = 10 << 20;
|
||||
i32 out_size = 10 << 20;
|
||||
Tail_Temp_Partition temp = begin_tail_part(part, out_size);
|
||||
|
||||
String out = str_alloc(&temp.part, out_size);
|
||||
|
@ -212,7 +207,7 @@ generate_4coder_docs(Document_System *doc_system, Partition *part, char *code_di
|
|||
// NOTE(allen): Compute and store variations of the custom function names
|
||||
*custom_func_names = allocate_app_api(part, custom_funcs_unit->set.count);
|
||||
|
||||
for (int32_t i = 0; i < custom_funcs_unit->set.count; ++i){
|
||||
for (i32 i = 0; i < custom_funcs_unit->set.count; ++i){
|
||||
String name_string = custom_funcs_unit->set.items[i].name;
|
||||
String *macro = &custom_func_names->names[i].macro;
|
||||
String *public_name = &custom_func_names->names[i].public_name;
|
||||
|
@ -337,7 +332,7 @@ generate_tutorials(Document_System *doc_system, Partition *part, char *src_direc
|
|||
}
|
||||
|
||||
static String
|
||||
push_string(Partition *part, int32_t size){
|
||||
push_string(Partition *part, i32 size){
|
||||
String str = {0};
|
||||
str.memory_size = size;
|
||||
str.str = push_array(part, char, size);
|
||||
|
@ -346,8 +341,8 @@ push_string(Partition *part, int32_t size){
|
|||
}
|
||||
|
||||
static void
|
||||
do_image_resize(Partition *part, char *src_file, char *dst_file, char *extension, int32_t w, int32_t h){
|
||||
int x, y, channels;
|
||||
do_image_resize(Partition *part, char *src_file, char *dst_file, char *extension, i32 w, i32 h){
|
||||
i32 x = 0, y = 0, channels = 0;
|
||||
stbi_uc *image = stbi_load(src_file, &x, &y, &channels, 0);
|
||||
|
||||
stbi_uc *resized_image = (stbi_uc*)malloc(w*h*channels);
|
||||
|
@ -363,7 +358,7 @@ do_image_resize(Partition *part, char *src_file, char *dst_file, char *extension
|
|||
|
||||
static void
|
||||
generate_site(char *code_directory, char *asset_directory, char *src_directory, char *dst_directory){
|
||||
int32_t size = (512 << 20);
|
||||
i32 size = (512 << 20);
|
||||
void *mem = malloc(size);
|
||||
memset(mem, 0, size);
|
||||
|
||||
|
|
|
@ -1,206 +0,0 @@
|
|||
/*
|
||||
* Mr. 4th Dimention - Allen Webster
|
||||
*
|
||||
* 12.12.2014
|
||||
*
|
||||
* Application layer for project codename "4ed"
|
||||
*
|
||||
*/
|
||||
|
||||
// TOP
|
||||
|
||||
#include "4ed_meta.h"
|
||||
#include "4ed_dll_reader.h"
|
||||
#include "4ed_dll_reader.cpp"
|
||||
|
||||
i32
|
||||
compare(char *a, char *b, i32 len){
|
||||
i32 result;
|
||||
char *e;
|
||||
|
||||
result = 0;
|
||||
e = a + len;
|
||||
for (;a < e && *a == *b; ++a, ++b);
|
||||
if (a < e){
|
||||
if (*a < *b) result = -1;
|
||||
else result = 1;
|
||||
}
|
||||
|
||||
return(result);
|
||||
}
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
Data
|
||||
load_file(char *filename){
|
||||
Data result;
|
||||
FILE * file;
|
||||
|
||||
result = {};
|
||||
file = fopen(filename, "rb");
|
||||
if (!file){
|
||||
printf("file %s not found\n", filename);
|
||||
}
|
||||
else{
|
||||
fseek(file, 0, SEEK_END);
|
||||
result.size = ftell(file);
|
||||
fseek(file, 0, SEEK_SET);
|
||||
result.data = (byte*)malloc(result.size);
|
||||
fread(result.data, 1, result.size, file);
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
return(result);
|
||||
}
|
||||
|
||||
void
|
||||
show_reloc_block(Data file, DLL_Data *dll, PE_Section_Definition *reloc_section){
|
||||
byte *base;
|
||||
Relocation_Block_Header *header;
|
||||
Relocation_Block_Entry *entry;
|
||||
u32 cursor;
|
||||
u32 bytes_in_table;
|
||||
u32 block_end;
|
||||
|
||||
base = file.data + reloc_section->disk_location;
|
||||
if (dll->is_64bit) bytes_in_table = dll->opt_header_64->data_directory[image_dir_base_reloc_table].size;
|
||||
else bytes_in_table = dll->opt_header_32->data_directory[image_dir_base_reloc_table].size;
|
||||
|
||||
for (cursor = 0; cursor < bytes_in_table;){
|
||||
header = (Relocation_Block_Header*)(base + cursor);
|
||||
block_end = cursor + header->block_size;
|
||||
cursor += sizeof(Relocation_Block_Header);
|
||||
|
||||
printf("block-size: %d\n", header->block_size);
|
||||
printf("offset-base: %d\n", header->page_base_offset);
|
||||
|
||||
for (;cursor < block_end;){
|
||||
entry = (Relocation_Block_Entry*)(base + cursor);
|
||||
cursor += sizeof(Relocation_Block_Entry);
|
||||
printf("reloc: type %d offset %d\n",
|
||||
(i32)(entry->entry & reloc_entry_type_mask) >> reloc_entry_type_shift,
|
||||
(i32)(entry->entry & reloc_entry_offset_mask));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
typedef int32_t (Function)(int a, int b);
|
||||
|
||||
#include <Windows.h>
|
||||
|
||||
#define UseWinDll 0
|
||||
|
||||
int
|
||||
main(int argc, char **argv){
|
||||
Function *func;
|
||||
i32 x;
|
||||
|
||||
#if UseWinDll
|
||||
HMODULE module;
|
||||
|
||||
if (argc < 2){
|
||||
printf("usage: dll_reader <dll-file>\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
module = LoadLibraryA(argv[1]);
|
||||
|
||||
if (!module){
|
||||
printf("failed to load file %s\n", argv[1]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
func = (Function*)GetProcAddress(module, "test_func");
|
||||
|
||||
#else
|
||||
Data file, img;
|
||||
DLL_Data dll;
|
||||
DLL_Loaded dll_loaded;
|
||||
PE_Section_Definition *section_def;
|
||||
i32 error;
|
||||
i32 i;
|
||||
|
||||
if (argc < 2){
|
||||
printf("usage: dll_reader <dll-file>\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
file = load_file(argv[1]);
|
||||
|
||||
if (!file.data){
|
||||
printf("failed to load file %s\n", argv[1]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (!dll_parse_headers(file, &dll, &error)){
|
||||
printf("header error %d\n", error);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
printf("this appears to be a dll\n");
|
||||
|
||||
printf("symbol-count: %d symbol-addr: %d\n",
|
||||
dll.coff_header->number_of_symbols,
|
||||
dll.coff_header->pointer_to_symbol_table);
|
||||
|
||||
if (dll.is_64bit) printf("64bit\n");
|
||||
else printf("32bit\n");
|
||||
|
||||
printf("built for machine: %s\n", dll_machine_type_str(dll.coff_header->machine, 0));
|
||||
|
||||
if (dll.is_64bit){
|
||||
printf("number of directories: %d\n", dll.opt_header_64->number_of_rva_and_sizes);
|
||||
}
|
||||
else{
|
||||
printf("number of directories: %d\n", dll.opt_header_32->number_of_rva_and_sizes);
|
||||
}
|
||||
|
||||
printf("\nbeginning section decode now\n");
|
||||
|
||||
section_def = dll.section_defs;
|
||||
for (i = 0; i < dll.coff_header->number_of_sections; ++i, ++section_def){
|
||||
if (section_def->name[7] == 0){
|
||||
printf("name: %s\n", section_def->name);
|
||||
}
|
||||
else{
|
||||
printf("name: %.*s\n", 8, section_def->name);
|
||||
}
|
||||
printf("img-size: %d img-loc: %d\ndisk-size: %d disk-loc: %d\n",
|
||||
section_def->loaded_size, section_def->loaded_location,
|
||||
section_def->disk_size, section_def->disk_location);
|
||||
|
||||
if (compare(section_def->name, ".reloc", 6) == 0){
|
||||
show_reloc_block(file, &dll, section_def);
|
||||
}
|
||||
}
|
||||
|
||||
img.size = dll_total_loaded_size(&dll);
|
||||
printf("image size: %d\n", img.size);
|
||||
|
||||
img.data = (byte*)
|
||||
VirtualAlloc((LPVOID)Tbytes(3), img.size,
|
||||
MEM_COMMIT | MEM_RESERVE,
|
||||
PAGE_READWRITE);
|
||||
dll_load(img, &dll_loaded, file, &dll);
|
||||
|
||||
DWORD _extra;
|
||||
VirtualProtect(img.data + dll_loaded.text_start,
|
||||
dll_loaded.text_size,
|
||||
PAGE_EXECUTE_READ,
|
||||
&_extra);
|
||||
|
||||
func = (Function*)dll_load_function(&dll_loaded, "test_func", 9);
|
||||
#endif
|
||||
|
||||
x = func(10, 20);
|
||||
printf("%d\n", x);
|
||||
|
||||
x = func(1, 2);
|
||||
printf("%d\n", x);
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
// BOTTOM
|
|
@ -1,37 +0,0 @@
|
|||
/*
|
||||
* Mr. 4th Dimention - Allen Webster
|
||||
*
|
||||
* 12.12.2014
|
||||
*
|
||||
* Application layer for project codename "4ed"
|
||||
*
|
||||
*/
|
||||
|
||||
// TOP
|
||||
|
||||
#define dll_export extern "C"
|
||||
|
||||
int stuff[] = {
|
||||
1, 2
|
||||
};
|
||||
|
||||
struct Crap{
|
||||
int x;
|
||||
int *stuff;
|
||||
};
|
||||
|
||||
Crap crap = { 0, stuff };
|
||||
|
||||
dll_export int
|
||||
test_func(int a, int b){
|
||||
int r;
|
||||
r = a + crap.stuff[crap.x];
|
||||
|
||||
crap.stuff[crap.x] = b;
|
||||
crap.x = (crap.x+1)&1;
|
||||
|
||||
return(r);
|
||||
}
|
||||
|
||||
// BOTTOM
|
||||
|
|
@ -1,523 +0,0 @@
|
|||
/*
|
||||
* Mr. 4th Dimention - Allen Webster
|
||||
*
|
||||
* 21.1.2015
|
||||
*
|
||||
* Test for CPP lexer & parser layer for project codename "4ed"
|
||||
*
|
||||
*/
|
||||
|
||||
// TODO(allen): In what corner cases, such as invalid files
|
||||
// does the new lexer suffer???
|
||||
|
||||
// TOP
|
||||
|
||||
#include "../4ed_meta.h"
|
||||
#define FSTRING_IMPLEMENTATION
|
||||
#include "../4coder_string.h"
|
||||
|
||||
#include "../4cpp_types.h"
|
||||
#include "../4cpp_lexer_types.h"
|
||||
|
||||
namespace new_lex{
|
||||
# include "4cpp_new_lexer.h"
|
||||
}
|
||||
|
||||
#define FCPP_LEXER_IMPLEMENTATION
|
||||
#include "../4cpp_lexer.h"
|
||||
|
||||
#include <windows.h>
|
||||
#include <intrin.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static Data
|
||||
dump_file(char *filename){
|
||||
Data data = {};
|
||||
HANDLE file;
|
||||
DWORD hi, lo;
|
||||
|
||||
file = CreateFile(filename, GENERIC_READ, 0, 0,
|
||||
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
|
||||
|
||||
if (file != INVALID_HANDLE_VALUE){
|
||||
lo = GetFileSize(file, &hi);
|
||||
assert(hi == 0);
|
||||
|
||||
data.size = (int)lo;
|
||||
data.data = (byte*)malloc(data.size + 1);
|
||||
|
||||
ReadFile(file, data.data, lo, &lo, 0);
|
||||
data.data[data.size] = 0;
|
||||
|
||||
assert((int)lo == data.size);
|
||||
|
||||
CloseHandle(file);
|
||||
}
|
||||
|
||||
return(data);
|
||||
}
|
||||
|
||||
typedef struct File_Info{
|
||||
String filename;
|
||||
int folder;
|
||||
} File_Info;
|
||||
|
||||
typedef struct File_List{
|
||||
// Ignore this, it's for internal stuff.
|
||||
void *block;
|
||||
|
||||
// The list of files and folders.
|
||||
File_Info *infos;
|
||||
int count;
|
||||
|
||||
// Ignore this, it's for internal stuff.
|
||||
int block_size;
|
||||
} File_List;
|
||||
|
||||
void*
|
||||
Win32GetMemory(int size){
|
||||
return (malloc(size));
|
||||
}
|
||||
|
||||
void
|
||||
Win32FreeMemory(void *ptr){
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
static void
|
||||
system_set_file_list(File_List *file_list, String directory){
|
||||
if (directory.size > 0){
|
||||
char dir_space[MAX_PATH + 32];
|
||||
String dir = make_string(dir_space, 0, MAX_PATH + 32);
|
||||
append(&dir, directory);
|
||||
char trail_str[] = "\\*";
|
||||
append(&dir, trail_str);
|
||||
terminate_with_null(&dir);
|
||||
|
||||
WIN32_FIND_DATA find_data;
|
||||
HANDLE search;
|
||||
search = FindFirstFileA(dir.str, &find_data);
|
||||
|
||||
if (search != INVALID_HANDLE_VALUE){
|
||||
i32 count = 0;
|
||||
i32 file_count = 0;
|
||||
BOOL more_files = 1;
|
||||
do{
|
||||
if (!match(find_data.cFileName, ".") &&
|
||||
!match(find_data.cFileName, "..")){
|
||||
++file_count;
|
||||
i32 size = 0;
|
||||
for(;find_data.cFileName[size];++size);
|
||||
count += size + 1;
|
||||
}
|
||||
more_files = FindNextFile(search, &find_data);
|
||||
}while(more_files);
|
||||
FindClose(search);
|
||||
|
||||
i32 required_size = count + file_count * sizeof(File_Info);
|
||||
if (file_list->block_size < required_size){
|
||||
Win32FreeMemory(file_list->block);
|
||||
file_list->block = Win32GetMemory(required_size);
|
||||
file_list->block_size = required_size;
|
||||
}
|
||||
|
||||
file_list->infos = (File_Info*)file_list->block;
|
||||
char *name = (char*)(file_list->infos + file_count);
|
||||
if (file_list->block){
|
||||
search = FindFirstFileA(dir.str, &find_data);
|
||||
|
||||
if (search != INVALID_HANDLE_VALUE){
|
||||
File_Info *info = file_list->infos;
|
||||
more_files = 1;
|
||||
do{
|
||||
if (!match(find_data.cFileName, ".") &&
|
||||
!match(find_data.cFileName, "..")){
|
||||
info->folder = (find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
|
||||
info->filename.str = name;
|
||||
|
||||
i32 i = 0;
|
||||
for(;find_data.cFileName[i];++i) *name++ = find_data.cFileName[i];
|
||||
info->filename.size = i;
|
||||
info->filename.memory_size = info->filename.size + 1;
|
||||
*name++ = 0;
|
||||
replace_char(&info->filename, '\\', '/');
|
||||
++info;
|
||||
}
|
||||
more_files = FindNextFile(search, &find_data);
|
||||
}while(more_files);
|
||||
FindClose(search);
|
||||
|
||||
file_list->count = file_count;
|
||||
|
||||
}else{
|
||||
Win32FreeMemory(file_list->block);
|
||||
file_list->block = 0;
|
||||
file_list->block_size = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
if (directory.str == 0){
|
||||
Win32FreeMemory(file_list->block);
|
||||
file_list->block = 0;
|
||||
file_list->block_size = 0;
|
||||
}
|
||||
file_list->infos = 0;
|
||||
file_list->count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
#define TOKEN_MAX (1 << 12)
|
||||
#define TOKEN_ARRAY_SIZE (TOKEN_MAX*sizeof(Cpp_Token))
|
||||
|
||||
static void
|
||||
init_test_stack(Cpp_Token_Stack *stack){
|
||||
stack->tokens = (Cpp_Token*)malloc(TOKEN_ARRAY_SIZE);
|
||||
stack->count = 0;
|
||||
stack->max_count = TOKEN_MAX;
|
||||
}
|
||||
|
||||
Cpp_Lex_Data lex_data = {};
|
||||
|
||||
struct Experiment{
|
||||
Cpp_Token_Stack correct_stack;
|
||||
Cpp_Token_Stack testing_stack;
|
||||
int passed_total, test_total;
|
||||
};
|
||||
int
|
||||
passed(Experiment exp){
|
||||
return (exp.passed_total == exp.test_total && exp.passed_total > 1);
|
||||
}
|
||||
|
||||
struct Times{
|
||||
i64 handcoded;
|
||||
i64 fsm;
|
||||
};
|
||||
Times time;
|
||||
void
|
||||
begin_t(Times *t){
|
||||
time = *t;
|
||||
}
|
||||
void
|
||||
end_t(Times *t){
|
||||
*t = time;
|
||||
}
|
||||
|
||||
static int
|
||||
equivalent_comments(Cpp_Token *a, Cpp_Token *b, char *data){
|
||||
String s_a = make_string(data + a->start, a->size);
|
||||
String s_b = make_string(data + b->start, b->size);
|
||||
|
||||
s_a = skip_chop_whitespace(s_a);
|
||||
s_b = skip_chop_whitespace(s_b);
|
||||
|
||||
int result = match(s_a, s_b);
|
||||
|
||||
return(result);
|
||||
}
|
||||
|
||||
static void
|
||||
run_experiment(Experiment *exp, char *filename, int verbose,
|
||||
int chunks, int max_tokens){
|
||||
String extension = {};
|
||||
Data file_data;
|
||||
new_lex::Lex_Data ld = {0};
|
||||
int pass;
|
||||
int k, chunk_size, is_last;
|
||||
|
||||
extension = file_extension(make_string_slowly(filename));
|
||||
|
||||
if (match(extension, "cpp") || match(extension, "h")){
|
||||
file_data = dump_file(filename);
|
||||
if (file_data.size < (100 << 10)){
|
||||
pass = 1;
|
||||
if (verbose >= 0) printf("testing on file: %s\n", filename);
|
||||
exp->test_total++;
|
||||
|
||||
exp->correct_stack.count = 0;
|
||||
exp->testing_stack.count = 0;
|
||||
|
||||
memset(exp->correct_stack.tokens, 0, TOKEN_ARRAY_SIZE);
|
||||
memset(exp->testing_stack.tokens, 0, TOKEN_ARRAY_SIZE);
|
||||
|
||||
char *data = (char*)file_data.data;
|
||||
int size = file_data.size;
|
||||
|
||||
ld.tb = (char*)malloc(file_data.size + 1);
|
||||
|
||||
{
|
||||
i64 start;
|
||||
|
||||
start = __rdtsc();
|
||||
cpp_lex_file_nonalloc(data, size, &exp->correct_stack, lex_data);
|
||||
time.handcoded += (__rdtsc() - start);
|
||||
|
||||
if (max_tokens == 0){
|
||||
if (chunks){
|
||||
start = __rdtsc();
|
||||
int relevant_size = file_data.size + 1;
|
||||
is_last = 0;
|
||||
for (k = 0; k < relevant_size; k += chunks){
|
||||
chunk_size = chunks;
|
||||
if (chunk_size + k >= relevant_size){
|
||||
chunk_size = relevant_size - k;
|
||||
is_last = 1;
|
||||
}
|
||||
|
||||
int result =
|
||||
new_lex::cpp_lex_nonalloc(&ld,
|
||||
(char*)file_data.data + k, chunk_size,
|
||||
&exp->testing_stack);
|
||||
|
||||
if (result == new_lex::LexFinished ||
|
||||
result == new_lex::LexNeedTokenMemory) break;
|
||||
}
|
||||
time.fsm += (__rdtsc() - start);
|
||||
}
|
||||
else{
|
||||
start = __rdtsc();
|
||||
new_lex::cpp_lex_size_nonalloc(
|
||||
&ld, (char*)file_data.data, file_data.size,
|
||||
file_data.size, &exp->testing_stack);
|
||||
|
||||
time.fsm += (__rdtsc() - start);
|
||||
}
|
||||
}
|
||||
else{
|
||||
if (chunks){
|
||||
start = __rdtsc();
|
||||
int relevant_size = file_data.size;
|
||||
is_last = 0;
|
||||
for (k = 0; k < relevant_size; k += chunks){
|
||||
chunk_size = chunks;
|
||||
if (chunk_size + k >= relevant_size){
|
||||
chunk_size = relevant_size - k;
|
||||
is_last = 1;
|
||||
}
|
||||
|
||||
int result = 0;
|
||||
int still_lexing = 1;
|
||||
do{
|
||||
result =
|
||||
new_lex::cpp_lex_size_nonalloc(&ld,
|
||||
(char*)file_data.data + k, chunk_size,
|
||||
file_data.size,
|
||||
&exp->testing_stack,
|
||||
max_tokens);
|
||||
if (result == new_lex::LexFinished ||
|
||||
result == new_lex::LexNeedTokenMemory ||
|
||||
result == new_lex::LexNeedChunk){
|
||||
still_lexing = 0;
|
||||
}
|
||||
} while(still_lexing);
|
||||
|
||||
|
||||
if (result == new_lex::LexFinished ||
|
||||
result == new_lex::LexNeedTokenMemory) break;
|
||||
}
|
||||
time.fsm += (__rdtsc() - start);
|
||||
}
|
||||
else{
|
||||
start = __rdtsc();
|
||||
int still_lexing = 1;
|
||||
do{
|
||||
int result =
|
||||
new_lex::cpp_lex_size_nonalloc(&ld,
|
||||
(char*)file_data.data, file_data.size, file_data.size,
|
||||
&exp->testing_stack,
|
||||
max_tokens);
|
||||
if (result == new_lex::LexFinished ||
|
||||
result == new_lex::LexNeedTokenMemory){
|
||||
still_lexing = 0;
|
||||
}
|
||||
} while(still_lexing);
|
||||
time.fsm += (__rdtsc() - start);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
free(ld.tb);
|
||||
|
||||
if (exp->correct_stack.count != exp->testing_stack.count){
|
||||
pass = 0;
|
||||
if (verbose >= 0){
|
||||
printf("error: stack size mismatch %d original and %d testing\n",
|
||||
exp->correct_stack.count, exp->testing_stack.count);
|
||||
}
|
||||
}
|
||||
|
||||
int min_count = exp->correct_stack.count;
|
||||
if (min_count > exp->testing_stack.count) min_count = exp->testing_stack.count;
|
||||
|
||||
for (int j = 0; j < min_count; ++j){
|
||||
Cpp_Token *correct, *testing;
|
||||
correct = exp->correct_stack.tokens + j;
|
||||
testing = exp->testing_stack.tokens + j;
|
||||
|
||||
if (correct->type != testing->type){
|
||||
pass = 0;
|
||||
if (verbose >= 1) printf("type mismatch at token %d\n", j);
|
||||
}
|
||||
|
||||
if (correct->start != testing->start || correct->size != testing->size){
|
||||
|
||||
int mismatch = 1;
|
||||
if (correct->type == testing->type &&
|
||||
(correct->type == CPP_TOKEN_COMMENT ||
|
||||
correct->type == CPP_TOKEN_ERROR_MESSAGE)){
|
||||
if (equivalent_comments(correct, testing, data)){
|
||||
mismatch = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (mismatch){
|
||||
pass = 0;
|
||||
if (verbose >= 1){
|
||||
printf("token range mismatch at token %d\n"
|
||||
" %d:%d original %d:%d testing\n"
|
||||
" %.*s original %.*s testing\n",
|
||||
j,
|
||||
correct->start, correct->size, testing->start, testing->size,
|
||||
correct->size, data + correct->start,
|
||||
testing->size, data + testing->start);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (correct->flags != testing->flags){
|
||||
pass = 0;
|
||||
if (verbose >= 1) printf("token flag mismatch at token %d\n", j);
|
||||
}
|
||||
}
|
||||
|
||||
if (pass){
|
||||
exp->passed_total++;
|
||||
if (verbose >= 0) printf("test passed!\n\n");
|
||||
}
|
||||
else{
|
||||
if (verbose >= 0) printf("test failed, you failed, fix it now!\n\n");
|
||||
}
|
||||
}
|
||||
|
||||
free(file_data.data);
|
||||
}
|
||||
}
|
||||
|
||||
#define OUTLINE(type) "%-30s "type"\n"
|
||||
#define OUTLINE_VAR(t, var) #var, (t)var
|
||||
|
||||
void
|
||||
show_time(Times t, int repeats, char *type){
|
||||
f32 speed_up = ((f32)t.handcoded) / (t.fsm);
|
||||
printf(
|
||||
"\n%s time for %d repeates\n"
|
||||
OUTLINE("%lld")
|
||||
OUTLINE("%lld")
|
||||
OUTLINE("%f"),
|
||||
type,
|
||||
repeats,
|
||||
OUTLINE_VAR(i64, t.handcoded),
|
||||
OUTLINE_VAR(i64, t.fsm),
|
||||
OUTLINE_VAR(f32, speed_up)
|
||||
);
|
||||
}
|
||||
|
||||
#define BASE_DIR "w:/4ed/data/test/"
|
||||
|
||||
int main(){
|
||||
int repeats = 1;
|
||||
int verbose_level = -1;
|
||||
int chunk_start = 0;
|
||||
int chunk_end = 16;
|
||||
#define TEST_FILE "parser_test_gcc.cpp"
|
||||
#define SINGLE_ITEM 0
|
||||
int token_limit = 0;
|
||||
|
||||
int chunks = (chunk_start > 0 && chunk_start <= chunk_end);
|
||||
int c = 0;
|
||||
|
||||
char test_directory[] = BASE_DIR;
|
||||
File_List all_files = {};
|
||||
Experiment exp = {};
|
||||
Experiment chunk_exp = {};
|
||||
Times exp_t = {};
|
||||
Times chunk_exp_t = {};
|
||||
|
||||
init_test_stack(&exp.correct_stack);
|
||||
init_test_stack(&exp.testing_stack);
|
||||
|
||||
init_test_stack(&chunk_exp.correct_stack);
|
||||
init_test_stack(&chunk_exp.testing_stack);
|
||||
|
||||
AllowLocal(test_directory);
|
||||
AllowLocal(all_files);
|
||||
|
||||
#if SINGLE_ITEM
|
||||
(void)(repeats);
|
||||
(void)(verbose_level);
|
||||
|
||||
if (chunks){
|
||||
begin_t(&chunk_exp_t);
|
||||
printf("With chunks of %d\n", chunks);
|
||||
for (c = chunk_start; c <= chunk_end; ++c){
|
||||
run_experiment(&chunk_exp, BASE_DIR TEST_FILE, 1, c, token_limit);
|
||||
}
|
||||
end_t(&chunk_exp_t);
|
||||
}
|
||||
|
||||
begin_t(&exp_t);
|
||||
printf("Unchunked\n");
|
||||
run_experiment(&exp, BASE_DIR TEST_FILE, 1, 0, token_limit);
|
||||
end_t(&exp_t);
|
||||
|
||||
#else
|
||||
|
||||
system_set_file_list(&all_files, make_lit_string(test_directory));
|
||||
|
||||
for (int j = 0; j < repeats; ++j){
|
||||
for (int i = 0; i < all_files.count; ++i){
|
||||
if (all_files.infos[i].folder == 0){
|
||||
if (chunks){
|
||||
begin_t(&chunk_exp_t);
|
||||
for (c = chunk_start; c <= chunk_end; ++c){
|
||||
run_experiment(&chunk_exp, all_files.infos[i].filename.str, verbose_level, c, token_limit);
|
||||
}
|
||||
end_t(&chunk_exp_t);
|
||||
}
|
||||
|
||||
begin_t(&exp_t);
|
||||
if (verbose_level == -1 && chunks){
|
||||
for (c = chunk_start; c <= chunk_end; ++c){
|
||||
run_experiment(&exp, all_files.infos[i].filename.str, verbose_level, 0, token_limit);
|
||||
}
|
||||
}
|
||||
else{
|
||||
run_experiment(&exp, all_files.infos[i].filename.str, verbose_level, 0, token_limit);
|
||||
}
|
||||
end_t(&exp_t);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (chunks){
|
||||
printf("chunks of sizes %d through %d tested\n", chunk_start, chunk_end);
|
||||
printf("chunked passed %d / %d tests\n", chunk_exp.passed_total, chunk_exp.test_total);
|
||||
}
|
||||
|
||||
printf("unchunk passed %d / %d tests\n", exp.passed_total, exp.test_total);
|
||||
|
||||
if (passed(exp) && (chunks == 0 || passed(chunk_exp))){
|
||||
if (chunks){
|
||||
show_time(chunk_exp_t, repeats, "Chunked");
|
||||
}
|
||||
show_time(exp_t, repeats, "Unchunked");
|
||||
}
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
// BOTTOM
|
|
@ -3,14 +3,16 @@
|
|||
*
|
||||
* 12.12.2014
|
||||
*
|
||||
* Win32 layer for project codename "4ed"
|
||||
* Win32 layer for 4coder
|
||||
*
|
||||
*/
|
||||
|
||||
// TOP
|
||||
|
||||
#include <assert.h>
|
||||
#include "4ed_defines.h"
|
||||
#include <string.h>
|
||||
#include "common/4coder_defines.h"
|
||||
#include "common/4coder_version.h"
|
||||
|
||||
#if defined(FRED_SUPER)
|
||||
|
||||
|
@ -18,7 +20,6 @@
|
|||
# define FSTRING_C
|
||||
# include "4coder_string.h"
|
||||
|
||||
# include "4coder_version.h"
|
||||
# include "4coder_keycodes.h"
|
||||
# include "4coder_style.h"
|
||||
# include "4coder_rect.h"
|
||||
|
@ -47,7 +48,6 @@ typedef void Custom_Command_Function;
|
|||
struct Application_Links;
|
||||
# include "4coder_custom_api.h"
|
||||
|
||||
//# include "4coder_custom.h"
|
||||
#else
|
||||
# include "4coder_default_bindings.cpp"
|
||||
|
||||
|
@ -581,7 +581,7 @@ Sys_Grow_Thread_Memory_Sig(system_grow_thread_memory){
|
|||
system_acquire_lock(CANCEL_LOCK0 + memory->id - 1);
|
||||
old_data = memory->data;
|
||||
old_size = memory->size;
|
||||
new_size = LargeRoundUp(memory->size*2, Kbytes(4));
|
||||
new_size = l_round_up_i32(memory->size*2, Kbytes(4));
|
||||
memory->data = system_get_memory(new_size);
|
||||
memory->size = new_size;
|
||||
if (old_data){
|
||||
|
@ -710,9 +710,7 @@ Sys_Yield_Coroutine_Sig(system_yield_coroutine){
|
|||
|
||||
internal
|
||||
Sys_File_Can_Be_Made_Sig(system_file_can_be_made){
|
||||
HANDLE file;
|
||||
file = CreateFile((char*)filename, FILE_APPEND_DATA, 0, 0,
|
||||
OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
|
||||
HANDLE file = CreateFile((char*)filename, FILE_APPEND_DATA, 0, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
|
||||
|
||||
if (!file || file == INVALID_HANDLE_VALUE){
|
||||
return 0;
|
||||
|
@ -951,13 +949,7 @@ Sys_Load_Close_Sig(system_load_close){
|
|||
internal
|
||||
Sys_Save_File_Sig(system_save_file){
|
||||
b32 result = 0;
|
||||
HANDLE file = CreateFile(filename,
|
||||
GENERIC_WRITE,
|
||||
0,
|
||||
0,
|
||||
CREATE_ALWAYS,
|
||||
FILE_ATTRIBUTE_NORMAL,
|
||||
0);
|
||||
HANDLE file = CreateFile(filename, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
|
||||
|
||||
if (file != INVALID_HANDLE_VALUE){
|
||||
DWORD written_total = 0;
|
||||
|
@ -966,7 +958,7 @@ Sys_Save_File_Sig(system_save_file){
|
|||
result = 1;
|
||||
|
||||
while (written_total < size){
|
||||
if (!WriteFile(file, buffer, size, &written_size, 0)){
|
||||
if (!WriteFile(file, buffer + written_total, size - written_total, &written_size, 0)){
|
||||
result = 0;
|
||||
break;
|
||||
}
|
||||
|
@ -1675,8 +1667,7 @@ Win32Callback(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){
|
|||
i32 new_x = LOWORD(lParam);
|
||||
i32 new_y = HIWORD(lParam);
|
||||
|
||||
if (new_x != win32vars.input_chunk.pers.mouse_x
|
||||
|| new_y != win32vars.input_chunk.pers.mouse_y){
|
||||
if (new_x != win32vars.input_chunk.pers.mouse_x || new_y != win32vars.input_chunk.pers.mouse_y){
|
||||
win32vars.input_chunk.pers.mouse_x = new_x;
|
||||
win32vars.input_chunk.pers.mouse_y = new_y;
|
||||
|
||||
|
|
Loading…
Reference in New Issue