lots of organization to files, figured out a good way to solve the build.cpp string problem and set it up
This commit is contained in:
parent
1ef304558e
commit
e37cce743a
|
@ -7,7 +7,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
#include "4coder_version.h"
|
#include "common/4coder_version.h"
|
||||||
#include "4coder_keycodes.h"
|
#include "4coder_keycodes.h"
|
||||||
#include "4coder_style.h"
|
#include "4coder_style.h"
|
||||||
#include "4coder_rect.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){
|
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];
|
char read_buffer[512];
|
||||||
|
|
||||||
if (size <= 0){
|
if (buffer->size > end){
|
||||||
*result = pos;
|
*result = buffer->size;
|
||||||
}
|
|
||||||
else if (size > sizeof(read_buffer)){
|
|
||||||
*result = pos;
|
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
*result = end;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (size > 0 && size <= sizeof(read_buffer)){
|
||||||
if (buffer->exists){
|
if (buffer->exists){
|
||||||
String read_str = make_fixed_width_string(read_buffer);
|
String read_str = make_fixed_width_string(read_buffer);
|
||||||
String needle_str = make_string(str, size);
|
String needle_str = make_string(str, size);
|
||||||
|
@ -488,13 +489,9 @@ buffer_seek_string_forward(Application_Links *app, Buffer_Summary *buffer, int32
|
||||||
static void
|
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){
|
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];
|
char read_buffer[512];
|
||||||
if (size <= 0){
|
|
||||||
*result = min-1;
|
*result = min-1;
|
||||||
}
|
if (size > 0 && size <= sizeof(read_buffer)){
|
||||||
else if (size > sizeof(read_buffer)){
|
|
||||||
*result = min-1;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
if (buffer->exists){
|
if (buffer->exists){
|
||||||
String read_str = make_fixed_width_string(read_buffer);
|
String read_str = make_fixed_width_string(read_buffer);
|
||||||
String needle_str = make_string(str, size);
|
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:;
|
finished:;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -541,13 +536,14 @@ buffer_seek_string_insensitive_forward(Application_Links *app, Buffer_Summary *b
|
||||||
Stream_Chunk stream = {0};
|
Stream_Chunk stream = {0};
|
||||||
stream.max_end = end;
|
stream.max_end = end;
|
||||||
|
|
||||||
if (size <= 0){
|
if (buffer->size > end){
|
||||||
*result = buffer->size;
|
|
||||||
}
|
|
||||||
else if (size > sizeof(read_buffer)){
|
|
||||||
*result = buffer->size;
|
*result = buffer->size;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
*result = end;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (size > 0 && size <= sizeof(read_buffer)){
|
||||||
if (buffer->exists){
|
if (buffer->exists){
|
||||||
String read_str = make_fixed_width_string(read_buffer);
|
String read_str = make_fixed_width_string(read_buffer);
|
||||||
String needle_str = make_string(str, size);
|
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:;
|
finished:;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -590,13 +584,8 @@ buffer_seek_string_insensitive_backward(Application_Links *app, Buffer_Summary *
|
||||||
Stream_Chunk stream = {0};
|
Stream_Chunk stream = {0};
|
||||||
stream.min_start = min;
|
stream.min_start = min;
|
||||||
|
|
||||||
if (size <= 0){
|
*result = min-1;
|
||||||
*result = -1;
|
if (size > 0 && size <= sizeof(read_buffer)){
|
||||||
}
|
|
||||||
else if (size > sizeof(read_buffer)){
|
|
||||||
*result = -1;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
if (buffer->exists){
|
if (buffer->exists){
|
||||||
String read_str = make_fixed_width_string(read_buffer);
|
String read_str = make_fixed_width_string(read_buffer);
|
||||||
String needle_str = make_string(str, size);
|
String needle_str = make_string(str, size);
|
||||||
|
@ -622,8 +611,6 @@ buffer_seek_string_insensitive_backward(Application_Links *app, Buffer_Summary *
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*result = -1;
|
|
||||||
|
|
||||||
finished:;
|
finished:;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3388,65 +3375,65 @@ read_config_line(Cpp_Token_Array array, int32_t *i_ptr){
|
||||||
}
|
}
|
||||||
|
|
||||||
if (subscript_success){
|
if (subscript_success){
|
||||||
if (token.type == CPP_TOKEN_EQ){
|
if (token.type == CPP_TOKEN_EQ){
|
||||||
config_line.eq_token = read_config_token(array, &i);
|
config_line.eq_token = read_config_token(array, &i);
|
||||||
++i;
|
++i;
|
||||||
if (i < array.count){
|
if (i < array.count){
|
||||||
Cpp_Token val_token = read_config_token(array, &i);
|
Cpp_Token val_token = read_config_token(array, &i);
|
||||||
|
|
||||||
bool32 array_success = 1;
|
bool32 array_success = 1;
|
||||||
if (val_token.type == CPP_TOKEN_BRACE_OPEN){
|
if (val_token.type == CPP_TOKEN_BRACE_OPEN){
|
||||||
array_success = 0;
|
array_success = 0;
|
||||||
++i;
|
++i;
|
||||||
if (i < array.count){
|
if (i < array.count){
|
||||||
config_line.val_array_start = i;
|
config_line.val_array_start = i;
|
||||||
|
|
||||||
bool32 expecting_array_item = 1;
|
bool32 expecting_array_item = 1;
|
||||||
for (; i < array.count; ++i){
|
for (; i < array.count; ++i){
|
||||||
Cpp_Token array_token = read_config_token(array, &i);
|
Cpp_Token array_token = read_config_token(array, &i);
|
||||||
if (array_token.size == 0){
|
if (array_token.size == 0){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (array_token.type == CPP_TOKEN_BRACE_CLOSE){
|
if (array_token.type == CPP_TOKEN_BRACE_CLOSE){
|
||||||
config_line.val_array_end = i;
|
config_line.val_array_end = i;
|
||||||
array_success = 1;
|
array_success = 1;
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
else{
|
|
||||||
if (array_token.type == CPP_TOKEN_COMMA){
|
|
||||||
if (!expecting_array_item){
|
|
||||||
expecting_array_item = 1;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
if (expecting_array_item){
|
if (array_token.type == CPP_TOKEN_COMMA){
|
||||||
expecting_array_item = 0;
|
if (!expecting_array_item){
|
||||||
++config_line.val_array_count;
|
expecting_array_item = 1;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
if (expecting_array_item){
|
||||||
|
expecting_array_item = 0;
|
||||||
|
++config_line.val_array_count;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
if (array_success){
|
||||||
if (array_success){
|
config_line.val_token = val_token;
|
||||||
config_line.val_token = val_token;
|
++i;
|
||||||
++i;
|
if (i < array.count){
|
||||||
if (i < array.count){
|
Cpp_Token semicolon_token = read_config_token(array, &i);
|
||||||
Cpp_Token semicolon_token = read_config_token(array, &i);
|
if (semicolon_token.type == CPP_TOKEN_SEMICOLON){
|
||||||
if (semicolon_token.type == CPP_TOKEN_SEMICOLON){
|
config_line.read_success = 1;
|
||||||
config_line.read_success = 1;
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!config_line.read_success){
|
if (!config_line.read_success){
|
||||||
for (; i < array.count; ++i){
|
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.array = array;
|
||||||
item.mem = mem;
|
item.mem = mem;
|
||||||
if (line.id_token.size != 0){
|
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){
|
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 (item.line.val_token.type == token_type){
|
||||||
if ((var_name == 0 && item.id.size == 0) || match(item.id, var_name)){
|
if ((var_name == 0 && item.id.size == 0) || match(item.id, var_name)){
|
||||||
if (subscript){
|
if (subscript){
|
||||||
if (item.has_subscript){
|
if (item.has_subscript){
|
||||||
*subscript = item.subscript_index;
|
*subscript = item.subscript_index;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
subscript_succes = 0;
|
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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);
|
return(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3585,9 +3572,9 @@ config_array_next_item(Config_Array_Reader *array_reader, Config_Item *item){
|
||||||
++array_reader->i;
|
++array_reader->i;
|
||||||
goto doublebreak;
|
goto doublebreak;
|
||||||
}break;
|
}break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
doublebreak:;
|
}
|
||||||
|
doublebreak:;
|
||||||
|
|
||||||
array_reader->good = result;
|
array_reader->good = result;
|
||||||
return(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, "enable_code_wrapping", 0, &enable_code_wrapping);
|
||||||
config_bool_var(item, "automatically_adjust_wrapping", 0, &automatically_adjust_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_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_wrap_width", 0, &new_wrap_width);
|
||||||
config_int_var(item, "default_min_base_width", 0, &new_min_base_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_theme_name", 0, &default_theme_name);
|
||||||
config_string_var(item, "default_font_name", 0, &default_font_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);
|
end_temp_memory(temp);
|
||||||
|
@ -3748,7 +3735,7 @@ set_project_extensions(Project *project, String src){
|
||||||
int32_t j = 0, k = 0;
|
int32_t j = 0, k = 0;
|
||||||
for (int32_t i = 0; i < src.size; ++i){
|
for (int32_t i = 0; i < src.size; ++i){
|
||||||
switch (mode){
|
switch (mode){
|
||||||
case 0:
|
case 0:
|
||||||
{
|
{
|
||||||
if (src.str[i] == '.'){
|
if (src.str[i] == '.'){
|
||||||
mode = 1;
|
mode = 1;
|
||||||
|
@ -3766,7 +3753,7 @@ set_project_extensions(Project *project, String src){
|
||||||
project->extension_space[j++] = src.str[i];
|
project->extension_space[j++] = src.str[i];
|
||||||
}
|
}
|
||||||
}break;
|
}break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
project->extension_space[j++] = 0;
|
project->extension_space[j++] = 0;
|
||||||
project->extension_count = k;
|
project->extension_count = k;
|
||||||
|
@ -3778,28 +3765,28 @@ interpret_escaped_string(char *dst, String src){
|
||||||
int32_t mode = 0;
|
int32_t mode = 0;
|
||||||
int32_t j = 0;
|
int32_t j = 0;
|
||||||
for (int32_t i = 0; i < src.size; ++i){
|
for (int32_t i = 0; i < src.size; ++i){
|
||||||
switch (mode){
|
switch (mode){
|
||||||
case 0:
|
case 0:
|
||||||
{
|
{
|
||||||
if (src.str[i] == '\\'){
|
if (src.str[i] == '\\'){
|
||||||
mode = 1;
|
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;
|
dst[j] = 0;
|
||||||
}
|
}
|
||||||
|
@ -3817,37 +3804,37 @@ close_all_files_with_extension(Application_Links *app, Partition *scratch_part,
|
||||||
buffers_to_close_count = 0;
|
buffers_to_close_count = 0;
|
||||||
do_repeat = 0;
|
do_repeat = 0;
|
||||||
|
|
||||||
uint32_t access = AccessAll;
|
uint32_t access = AccessAll;
|
||||||
Buffer_Summary buffer = {0};
|
Buffer_Summary buffer = {0};
|
||||||
for (buffer = get_buffer_first(app, access);
|
for (buffer = get_buffer_first(app, access);
|
||||||
buffer.exists;
|
buffer.exists;
|
||||||
get_buffer_next(app, &buffer, access)){
|
get_buffer_next(app, &buffer, access)){
|
||||||
|
|
||||||
bool32 is_match = 1;
|
bool32 is_match = 1;
|
||||||
if (extension_count > 0){
|
if (extension_count > 0){
|
||||||
String extension = file_extension(make_string(buffer.file_name, buffer.file_name_len));
|
String extension = file_extension(make_string(buffer.file_name, buffer.file_name_len));
|
||||||
is_match = 0;
|
is_match = 0;
|
||||||
for (int32_t i = 0; i < extension_count; ++i){
|
for (int32_t i = 0; i < extension_count; ++i){
|
||||||
if (match(extension, extension_list[i])){
|
if (match(extension, extension_list[i])){
|
||||||
is_match = 1;
|
is_match = 1;
|
||||||
break;
|
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){
|
for (int32_t i = 0; i < buffers_to_close_count; ++i){
|
||||||
if (buffers_to_close_count >= buffers_to_close_max){
|
kill_buffer(app, buffer_identifier(buffers_to_close[i]), true, 0);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while(do_repeat);
|
while(do_repeat);
|
||||||
|
|
||||||
end_temp_memory(temp);
|
end_temp_memory(temp);
|
||||||
|
@ -3876,31 +3863,31 @@ open_all_files_with_extension(Application_Links *app, Partition *scratch_part, c
|
||||||
if (extension_count > 0){
|
if (extension_count > 0){
|
||||||
is_match = 0;
|
is_match = 0;
|
||||||
|
|
||||||
String extension = make_string_cap(info->filename, info->filename_len, info->filename_len+1);
|
String extension = make_string_cap(info->filename, info->filename_len, info->filename_len+1);
|
||||||
extension = file_extension(extension);
|
extension = file_extension(extension);
|
||||||
for (int32_t j = 0; j < extension_count; ++j){
|
for (int32_t j = 0; j < extension_count; ++j){
|
||||||
if (match(extension, extension_list[j])){
|
if (match(extension, extension_list[j])){
|
||||||
is_match = 1;
|
is_match = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_match){
|
if (is_match){
|
||||||
// NOTE(allen): There's no way in the 4coder API to use relative
|
// 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
|
// paths at the moment, so everything should be full paths. Which is
|
||||||
// managable. Here simply set the dir string size back to where it
|
// managable. Here simply set the dir string size back to where it
|
||||||
// was originally, so that new appends overwrite old ones.
|
// was originally, so that new appends overwrite old ones.
|
||||||
dir.size = dir_size;
|
dir.size = dir_size;
|
||||||
append_sc(&dir, info->filename);
|
append_sc(&dir, info->filename);
|
||||||
create_buffer(app, dir.str, dir.size, 0);
|
create_buffer(app, dir.str, dir.size, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
free_file_list(app, list);
|
free_file_list(app, list);
|
||||||
|
|
||||||
end_temp_memory(temp);
|
end_temp_memory(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
static char**
|
static char**
|
||||||
|
@ -3968,10 +3955,10 @@ CUSTOM_COMMAND_SIG(load_project){
|
||||||
|
|
||||||
if (result == LexResult_Finished){
|
if (result == LexResult_Finished){
|
||||||
// Clear out current project
|
// Clear out current project
|
||||||
if (current_project.close_all_code_when_this_project_closes){
|
if (current_project.close_all_code_when_this_project_closes){
|
||||||
exec_command(app, close_all_code);
|
exec_command(app, close_all_code);
|
||||||
}
|
}
|
||||||
current_project = null_project;
|
current_project = null_project;
|
||||||
|
|
||||||
// Set new project directory
|
// Set new project directory
|
||||||
{
|
{
|
||||||
|
@ -3992,9 +3979,9 @@ CUSTOM_COMMAND_SIG(load_project){
|
||||||
String str = {0};
|
String str = {0};
|
||||||
if (config_string_var(item, "extensions", 0, &str)){
|
if (config_string_var(item, "extensions", 0, &str)){
|
||||||
if (str.size < sizeof(current_project.extension_space)){
|
if (str.size < sizeof(current_project.extension_space)){
|
||||||
set_project_extensions(¤t_project, str);
|
set_project_extensions(¤t_project, str);
|
||||||
print_message(app, str.str, str.size);
|
print_message(app, str.str, str.size);
|
||||||
print_message(app, "\n", 1);
|
print_message(app, "\n", 1);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
print_message(app, literal("STRING TOO LONG!\n"));
|
print_message(app, literal("STRING TOO LONG!\n"));
|
||||||
|
@ -4067,35 +4054,35 @@ CUSTOM_COMMAND_SIG(load_project){
|
||||||
}
|
}
|
||||||
|
|
||||||
if (read_string){
|
if (read_string){
|
||||||
if (config_int_var(array_item, 0, 0, 0)){
|
if (config_int_var(array_item, 0, 0, 0)){
|
||||||
append(&msg, "NULL, ");
|
append(&msg, "NULL, ");
|
||||||
dest_str[0] = 0;
|
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 (read_bool){
|
||||||
if (config_string_var(array_item, 0, 0, &str)){
|
if (config_bool_var(array_item, 0, 0, dest_bool)){
|
||||||
if (str.size < dest_str_size){
|
if (dest_bool){
|
||||||
interpret_escaped_string(dest_str, str);
|
append(&msg, "true, ");
|
||||||
append(&msg, dest_str);
|
}
|
||||||
append(&msg, ", ");
|
else{
|
||||||
}
|
append(&msg, "false, ");
|
||||||
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, ");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
item_index++;
|
item_index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4106,7 +4093,7 @@ CUSTOM_COMMAND_SIG(load_project){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (current_project.close_all_files_when_project_opens){
|
if (current_project.close_all_files_when_project_opens){
|
||||||
close_all_files_with_extension(app, &global_part, 0, 0);
|
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
|
static int32_t
|
||||||
search_front_to_back_step(Application_Links *app,
|
search_front_to_back_step(Application_Links *app, Search_Range *range, String word, int32_t *pos, Search_Match *result_ptr){
|
||||||
Search_Range *range,
|
|
||||||
String word,
|
|
||||||
int32_t *pos,
|
|
||||||
Search_Match *result_ptr){
|
|
||||||
int32_t found_match = FindResult_None;
|
int32_t found_match = FindResult_None;
|
||||||
|
|
||||||
Search_Match result = *result_ptr;
|
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);
|
result.buffer = get_buffer(app, range->buffer, AccessAll);
|
||||||
if (case_insensitive){
|
if (case_insensitive){
|
||||||
buffer_seek_string_insensitive_forward(app, &result.buffer,
|
buffer_seek_string_insensitive_forward(app, &result.buffer, start_pos, end_pos, word.str, word.size, &result.start);
|
||||||
start_pos, end_pos,
|
|
||||||
word.str, word.size,
|
|
||||||
&result.start);
|
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
buffer_seek_string_forward(app, &result.buffer,
|
buffer_seek_string_forward(app, &result.buffer, start_pos, end_pos, word.str, word.size, &result.start);
|
||||||
start_pos, end_pos,
|
|
||||||
word.str, word.size,
|
|
||||||
&result.start);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.start < end_pos){
|
if (result.start < end_pos){
|
||||||
|
@ -319,11 +309,7 @@ search_front_to_back_step(Application_Links *app,
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t
|
static int32_t
|
||||||
search_front_to_back(Application_Links *app,
|
search_front_to_back(Application_Links *app, Search_Range *range, String word, int32_t *pos, Search_Match *result_ptr){
|
||||||
Search_Range *range,
|
|
||||||
String word,
|
|
||||||
int32_t *pos,
|
|
||||||
Search_Match *result_ptr){
|
|
||||||
int32_t found_match = FindResult_None;
|
int32_t found_match = FindResult_None;
|
||||||
for (;found_match == FindResult_None;){
|
for (;found_match == FindResult_None;){
|
||||||
found_match = search_front_to_back_step(app, range, word, pos, result_ptr);
|
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
|
static int32_t
|
||||||
search_back_to_front_step(Application_Links *app,
|
search_back_to_front_step(Application_Links *app, Search_Range *range, String word, int32_t *pos, Search_Match *result_ptr){
|
||||||
Search_Range *range,
|
|
||||||
String word,
|
|
||||||
int32_t *pos,
|
|
||||||
Search_Match *result_ptr){
|
|
||||||
int32_t found_match = FindResult_None;
|
int32_t found_match = FindResult_None;
|
||||||
|
|
||||||
Search_Match result = *result_ptr;
|
Search_Match result = *result_ptr;
|
||||||
|
@ -372,11 +354,7 @@ search_back_to_front_step(Application_Links *app,
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t
|
static int32_t
|
||||||
search_back_to_front(Application_Links *app,
|
search_back_to_front(Application_Links *app, Search_Range *range, String word, int32_t *pos, Search_Match *result_ptr){
|
||||||
Search_Range *range,
|
|
||||||
String word,
|
|
||||||
int32_t *pos,
|
|
||||||
Search_Match *result_ptr){
|
|
||||||
int32_t found_match = FindResult_None;
|
int32_t found_match = FindResult_None;
|
||||||
for (;found_match == FindResult_None;){
|
for (;found_match == FindResult_None;){
|
||||||
found_match = search_back_to_front_step(app, range, word, pos, result_ptr);
|
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.) */
|
/* DOC(A Key_Modifier acts as an index for specifying modifiers in arrays.) */
|
||||||
ENUM(int32_t, Key_Modifier){
|
ENUM(int32_t, Key_Modifier){
|
||||||
MDFR_SHIFT_INDEX,
|
MDFR_SHIFT_INDEX,
|
||||||
MDFR_CONTROL_INDEX,
|
MDFR_CONTROL_INDEX,
|
||||||
MDFR_ALT_INDEX,
|
MDFR_ALT_INDEX,
|
||||||
MDFR_CAPS_INDEX,
|
MDFR_CAPS_INDEX,
|
||||||
MDFR_HOLD_INDEX,
|
MDFR_HOLD_INDEX,
|
||||||
|
|
||||||
/* DOC(MDFR_INDEX_COUNT is used to specify the number of modifiers supported.) */
|
/* 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.
|
/* 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. )
|
/* DOC(Buffer_Creation_Data is a struct used as a local handle for the creation of a buffer. )
|
||||||
HIDE_MEMBERS() */
|
HIDE_MEMBERS() */
|
||||||
STRUCT Buffer_Creation_Data{
|
STRUCT Buffer_Creation_Data{
|
||||||
Buffer_Create_Flag flags;
|
Buffer_Create_Flag flags;
|
||||||
char fname_space [256];
|
char fname_space [256];
|
||||||
int32_t fname_len;
|
int32_t fname_len;
|
||||||
|
@ -343,7 +343,7 @@ ENUM(int32_t, Mouse_Cursor_Show_Type){
|
||||||
MouseCursorShow_Never,
|
MouseCursorShow_Never,
|
||||||
/* DOC(The MouseCursorShow_Never mode always shows the cursor.) */
|
/* DOC(The MouseCursorShow_Never mode always shows the cursor.) */
|
||||||
MouseCursorShow_Always,
|
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.) */
|
/* 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.) */
|
/* 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.)*/
|
/*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;
|
Command_ID cmdid;
|
||||||
/*DOC(If this Generic_Command does not represent an internal command the command
|
/*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.) */
|
/* 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{
|
STRUCT Key_Event_Data{
|
||||||
/* DOC(This field is the raw keycode which is always non-zero in valid key events.) */
|
/* 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.) */
|
/* 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.) */
|
/* 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(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)
|
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.) */
|
/* 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.) */
|
/* DOC(This field indicates that the left button is held.) */
|
||||||
char l;
|
char l;
|
||||||
/* DOC(This field indicates that the right button is held.) */
|
/* DOC(This field indicates that the right button is held.) */
|
||||||
|
@ -402,9 +402,9 @@ STRUCT Key_Event_Data{
|
||||||
/* DOC(
|
/* DOC(
|
||||||
This field is 0 when the wheel has not moved, it is 1 for a downward motion and -1 for an upward motion.
|
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.) */
|
/* 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.) */
|
/* DOC(This field contains the x position of the mouse relative to the window where the left side is 0.) */
|
||||||
int32_t x;
|
int32_t x;
|
||||||
/* DOC(This field contains the y position of the mouse relative to the window where the top side is 0.) */
|
/* 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.) */
|
/* 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.) */
|
/* 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;
|
char *name;
|
||||||
|
|
||||||
|
@ -464,7 +464,7 @@ STRUCT File_List{
|
||||||
int32_t name_len;
|
int32_t name_len;
|
||||||
|
|
||||||
/* DOC(This field is the id of the buffer. If name is specified this should be 0.) */
|
/* 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.) */
|
/* 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(User_Input_Type_ID)
|
||||||
DOC_SEE(Generic_Command)
|
DOC_SEE(Generic_Command)
|
||||||
*/
|
*/
|
||||||
STRUCT User_Input{
|
STRUCT User_Input{
|
||||||
/* DOC(This field specifies whether the event was a key press or mouse event.) */
|
/* DOC(This field specifies whether the event was a key press or mouse event.) */
|
||||||
User_Input_Type_ID type;
|
User_Input_Type_ID type;
|
||||||
/* DOC(This field indicates that an abort event has occurred and the command needs to shut down.) */
|
/* 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
|
/* 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.) */
|
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.) */
|
/* DOC(This specifies the prompt portion of the drop down bar.) */
|
||||||
String prompt;
|
String prompt;
|
||||||
/* DOC(This specifies the main string portion of the drop down bar.) */
|
/* 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("register") , CPP_TOKEN_KEY_OTHER},
|
||||||
{make_lit_string("this") , CPP_TOKEN_KEY_OTHER},
|
{make_lit_string("this") , CPP_TOKEN_KEY_OTHER},
|
||||||
{make_lit_string("thread_local") , 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_Get_Token_Result result = {};
|
||||||
Cpp_Token *token_array = array.tokens;
|
Cpp_Token *token_array = array.tokens;
|
||||||
Cpp_Token *token = 0;
|
Cpp_Token *token = 0;
|
||||||
int32_t first = 0;
|
int32_t first = 0;
|
||||||
int32_t count = array.count;
|
int32_t count = array.count;
|
||||||
int32_t last = count;
|
int32_t last = count;
|
||||||
int32_t this_start = 0, next_start = 0;
|
int32_t this_start = 0, next_start = 0;
|
||||||
|
@ -218,7 +222,7 @@ DOC_SEE(Cpp_Get_Token_Result)
|
||||||
result.token_index = -1;
|
result.token_index = -1;
|
||||||
result.in_whitespace = 1;
|
result.in_whitespace = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.token_index >= 0 && result.token_index < count){
|
if (result.token_index >= 0 && result.token_index < count){
|
||||||
token = array.tokens + result.token_index;
|
token = array.tokens + result.token_index;
|
||||||
result.token_start = token->start;
|
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,
|
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;
|
token_array_out->count = temp_stack.count;
|
||||||
|
|
||||||
|
@ -996,23 +1000,23 @@ to make sure it returns LexResult_Finished to you:
|
||||||
|
|
||||||
CODE_EXAMPLE(
|
CODE_EXAMPLE(
|
||||||
Cpp_Token_Array lex_file(char *file_name){
|
Cpp_Token_Array lex_file(char *file_name){
|
||||||
File_Data file = read_whole_file(file_name);
|
File_Data file = read_whole_file(file_name);
|
||||||
|
|
||||||
char *temp = (char*)malloc(4096); // hopefully big enough
|
char *temp = (char*)malloc(4096); // hopefully big enough
|
||||||
Cpp_Lex_Data lex_state = cpp_lex_data_init(temp);
|
Cpp_Lex_Data lex_state = cpp_lex_data_init(temp);
|
||||||
|
|
||||||
Cpp_Token_Array array = {0};
|
Cpp_Token_Array array = {0};
|
||||||
array.tokens = (Cpp_Token*)malloc(1 << 20); // hopefully big enough
|
array.tokens = (Cpp_Token*)malloc(1 << 20); // hopefully big enough
|
||||||
array.max_count = (1 << 20)/sizeof(Cpp_Token);
|
array.max_count = (1 << 20)/sizeof(Cpp_Token);
|
||||||
|
|
||||||
Cpp_Lex_Result result =
|
Cpp_Lex_Result result =
|
||||||
cpp_lex_step(&lex_state, file.data, file.size, file.size,
|
cpp_lex_step(&lex_state, file.data, file.size, file.size,
|
||||||
&array, NO_OUT_LIMIT);
|
&array, NO_OUT_LIMIT);
|
||||||
Assert(result == LexResult_Finished);
|
Assert(result == LexResult_Finished);
|
||||||
|
|
||||||
free(temp);
|
free(temp);
|
||||||
|
|
||||||
return(array);
|
return(array);
|
||||||
})
|
})
|
||||||
|
|
||||||
)
|
)
|
||||||
|
@ -1538,15 +1542,15 @@ it is quick and convenient to lex files.
|
||||||
|
|
||||||
CODE_EXAMPLE(
|
CODE_EXAMPLE(
|
||||||
Cpp_Token_Array lex_file(char *file_name){
|
Cpp_Token_Array lex_file(char *file_name){
|
||||||
File_Data file = read_whole_file(file_name);
|
File_Data file = read_whole_file(file_name);
|
||||||
|
|
||||||
// This array will be automatically grown if it runs
|
// This array will be automatically grown if it runs
|
||||||
// out of memory.
|
// out of memory.
|
||||||
Cpp_Token_Array array = cpp_make_token_array(100);
|
Cpp_Token_Array array = cpp_make_token_array(100);
|
||||||
|
|
||||||
cpp_lex_file(file.data, file.size, &array);
|
cpp_lex_file(file.data, file.size, &array);
|
||||||
|
|
||||||
return(array);
|
return(array);
|
||||||
})
|
})
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
// TODO(allen): can I get away from this one?
|
// TODO(allen): can I get away from this one?
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include "4ed_defines.h"
|
#include "common/4coder_defines.h"
|
||||||
|
|
||||||
#define FSTRING_IMPLEMENTATION
|
#define FSTRING_IMPLEMENTATION
|
||||||
#define FSTRING_C
|
#define FSTRING_C
|
||||||
|
@ -41,11 +41,8 @@
|
||||||
#include "4ed_style.cpp"
|
#include "4ed_style.cpp"
|
||||||
#include "4ed_command.cpp"
|
#include "4ed_command.cpp"
|
||||||
|
|
||||||
#include "buffer/4coder_shared.cpp"
|
#include "file/4coder_buffer.cpp"
|
||||||
#include "buffer/4coder_gap_buffer.cpp"
|
#include "file/4coder_undo.cpp"
|
||||||
#define Buffer_Type Gap_Buffer
|
|
||||||
#include "buffer/4coder_buffer_abstract.cpp"
|
|
||||||
|
|
||||||
#include "file/4coder_file.cpp"
|
#include "file/4coder_file.cpp"
|
||||||
#include "file/4coder_working_set.cpp"
|
#include "file/4coder_working_set.cpp"
|
||||||
#include "file/4coder_hot_directory.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;
|
first_wrap_determination = 0;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
assert_4tech(stop.pos == wrap_unit_end);
|
assert(stop.pos == wrap_unit_end);
|
||||||
do_wrap = 1;
|
do_wrap = 1;
|
||||||
++wrap_array_index;
|
++wrap_array_index;
|
||||||
wrap_unit_end = file->state.wrap_positions[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){
|
file_compute_lowest_line(Editing_File *file, f32 font_height){
|
||||||
i32 lowest_line = 0;
|
i32 lowest_line = 0;
|
||||||
|
|
||||||
Buffer_Type *buffer = &file->state.buffer;
|
Gap_Buffer *buffer = &file->state.buffer;
|
||||||
if (file->settings.unwrapped_lines){
|
if (file->settings.unwrapped_lines){
|
||||||
lowest_line = buffer->line_count;
|
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;
|
i32 max = 0, size = 0;
|
||||||
b32 dos_write_mode = file->settings.dos_write_mode;
|
b32 dos_write_mode = file->settings.dos_write_mode;
|
||||||
char *data = 0;
|
char *data = 0;
|
||||||
Buffer_Type *buffer = &file->state.buffer;
|
Gap_Buffer *buffer = &file->state.buffer;
|
||||||
|
|
||||||
if (dos_write_mode){
|
if (dos_write_mode){
|
||||||
max = buffer_size(buffer) + buffer->line_count + 1;
|
max = buffer_size(buffer) + buffer->line_count + 1;
|
||||||
|
@ -847,14 +847,14 @@ enum{
|
||||||
};
|
};
|
||||||
|
|
||||||
internal i32
|
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;
|
b32 result = GROW_NOT_NEEDED;
|
||||||
i32 max = buffer->line_max;
|
i32 max = buffer->line_max;
|
||||||
i32 count = buffer->line_count;
|
i32 count = buffer->line_count;
|
||||||
i32 target_lines = count + additional_lines;
|
i32 target_lines = count + additional_lines;
|
||||||
|
|
||||||
if (target_lines > max || max == 0){
|
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);
|
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
|
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){
|
if (!buffer->line_starts){
|
||||||
i32 max = buffer->line_max = Kbytes(1);
|
i32 max = buffer->line_max = Kbytes(1);
|
||||||
buffer->line_starts = (i32*)general_memory_allocate(system, general, max*sizeof(i32));
|
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,
|
// NOTE(allen): These calls assumes that the buffer's line starts are already correct,
|
||||||
// and that the buffer's line_count is correct.
|
// and that the buffer's line_count is correct.
|
||||||
internal void
|
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){
|
if (*mem == 0){
|
||||||
i32 max = ((count+1)*2);
|
i32 max = ((count+1)*2);
|
||||||
max = (max+(0x3FF))&(~(0x3FF));
|
max = (max+(0x3FF))&(~(0x3FF));
|
||||||
|
@ -996,7 +996,7 @@ struct Code_Wrap_State{
|
||||||
f32 x;
|
f32 x;
|
||||||
b32 consume_newline;
|
b32 consume_newline;
|
||||||
|
|
||||||
Buffer_Stream_Type stream;
|
Gap_Buffer_Stream stream;
|
||||||
i32 i;
|
i32 i;
|
||||||
|
|
||||||
f32 *adv;
|
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->line_starts = file->state.buffer.line_starts;
|
||||||
state->next_line_start = state->line_starts[1];
|
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);
|
i32 size = buffer_size(buffer);
|
||||||
buffer_stringify_loop(&state->stream, buffer, 0, size);
|
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;
|
guess = 1000;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (type == CPP_TOKEN_COMMA){
|
||||||
|
guess = 20;
|
||||||
|
}
|
||||||
else if (type == CPP_TOKEN_COLON ||
|
else if (type == CPP_TOKEN_COLON ||
|
||||||
type == CPP_TOKEN_PARENTHESE_CLOSE ||
|
type == CPP_TOKEN_PARENTHESE_CLOSE ||
|
||||||
type == CPP_TOKEN_COMMA ||
|
|
||||||
type == CPP_TOKEN_BRACKET_OPEN ||
|
type == CPP_TOKEN_BRACKET_OPEN ||
|
||||||
type == CPP_TOKEN_BRACKET_CLOSE){
|
type == CPP_TOKEN_BRACKET_CLOSE){
|
||||||
if (on_left){
|
if (on_left){
|
||||||
|
@ -1490,7 +1492,7 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
Buffer_Stream_Type stream = {0};
|
Gap_Buffer_Stream stream = {0};
|
||||||
|
|
||||||
i32 word_stage = 0;
|
i32 word_stage = 0;
|
||||||
i32 i = stop.pos;
|
i32 i = stop.pos;
|
||||||
|
@ -1603,7 +1605,7 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file,
|
||||||
step.start_x = x;
|
step.start_x = x;
|
||||||
step.this_token = wrap_state.token_ptr;
|
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_Indent_Pair potential_wrap = {0};
|
||||||
potential_wrap.wrap_position = i;
|
potential_wrap.wrap_position = i;
|
||||||
|
@ -1737,6 +1739,10 @@ file_measure_wraps(System_Functions *system, Models *models, Editing_File *file,
|
||||||
general_stickieness = next_stickieness;
|
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 = 64*50;
|
||||||
wrappable_score += 101 - general_stickieness - wrap_state.wrap_x.paren_safe_top*80;
|
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;
|
Font_Set *font_set = models->font_set;
|
||||||
General_Memory *general = &models->mem.general;
|
General_Memory *general = &models->mem.general;
|
||||||
Partition *part = &models->mem.part;
|
Partition *part = &models->mem.part;
|
||||||
Buffer_Init_Type init;
|
Gap_Buffer_Init init;
|
||||||
|
|
||||||
file->state = null_editing_file_state;
|
file->state = null_editing_file_state;
|
||||||
|
|
||||||
init = buffer_begin_init(&file->state.buffer, val.str, val.size);
|
init = buffer_begin_init(&file->state.buffer, val.str, val.size);
|
||||||
for (; buffer_init_need_more(&init); ){
|
for (; buffer_init_need_more(&init); ){
|
||||||
i32 page_size = buffer_init_page_size(&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);
|
if (page_size < Kbytes(4)) page_size = Kbytes(4);
|
||||||
void *data = general_memory_allocate(system, general, page_size);
|
void *data = general_memory_allocate(system, general, page_size);
|
||||||
buffer_init_provide_page(&init, data, 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);
|
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){
|
if (buffer->data){
|
||||||
general_memory_free(system, general, buffer->data);
|
general_memory_free(system, general, buffer->data);
|
||||||
general_memory_free(system, general, buffer->line_starts);
|
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];
|
Editing_File *file = (Editing_File*)data[0];
|
||||||
General_Memory *general = (General_Memory*)data[1];
|
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 text_size = buffer_size(buffer);
|
||||||
|
|
||||||
i32 aligned_buffer_size = (text_size + 3)&(~3);
|
i32 aligned_buffer_size = (text_size + 3)&(~3);
|
||||||
|
@ -2074,7 +2080,7 @@ Job_Callback_Sig(job_full_lex){
|
||||||
}
|
}
|
||||||
} while (still_lexing);
|
} 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);
|
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);
|
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 text_size = buffer_size(buffer);
|
||||||
|
|
||||||
i32 mem_size = partition_remaining(part);
|
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);
|
} 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);
|
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 result = 1;
|
||||||
b32 inline_lex = !file->state.still_lexing;
|
b32 inline_lex = !file->state.still_lexing;
|
||||||
if (inline_lex){
|
if (inline_lex){
|
||||||
Buffer_Type *buffer = &file->state.buffer;
|
Gap_Buffer *buffer = &file->state.buffer;
|
||||||
i32 extra_tolerance = 100;
|
i32 extra_tolerance = 100;
|
||||||
|
|
||||||
Cpp_Token_Array *array = &file->state.token_array;
|
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){
|
if (inline_lex){
|
||||||
i32 new_count = cpp_relex_get_new_count(&state, array->count, &relex_array);
|
i32 new_count = cpp_relex_get_new_count(&state, array->count, &relex_array);
|
||||||
if (new_count > array->max_count){
|
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*)
|
array->tokens = (Cpp_Token*)
|
||||||
general_memory_reallocate(system, general, array->tokens, array->count*sizeof(Cpp_Token), new_max*sizeof(Cpp_Token));
|
general_memory_reallocate(system, general, array->tokens, array->count*sizeof(Cpp_Token), new_max*sizeof(Cpp_Token));
|
||||||
array->max_count = new_max;
|
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);
|
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;
|
Cpp_Token_Array *array = &file->state.token_array;
|
||||||
|
|
||||||
Temp_Memory temp = begin_temp_memory(part);
|
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);
|
i32 new_count = cpp_relex_get_new_count(&state, array->count, &relex_array);
|
||||||
if (new_count > array->max_count){
|
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*)
|
array->tokens = (Cpp_Token*)
|
||||||
general_memory_reallocate(system, general, array->tokens, array->count*sizeof(Cpp_Token), new_max*sizeof(Cpp_Token));
|
general_memory_reallocate(system, general, array->tokens, array->count*sizeof(Cpp_Token), new_max*sizeof(Cpp_Token));
|
||||||
array->max_count = new_max;
|
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
|
// 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_start = buffer_get_line_index(&file->state.buffer, start);
|
||||||
i32 line_end = buffer_get_line_index(&file->state.buffer, end);
|
i32 line_end = buffer_get_line_index(&file->state.buffer, end);
|
||||||
i32 replaced_line_count = line_end - line_start;
|
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;
|
first_wrap_determination = 0;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
assert_4tech(stop.pos == wrap_unit_end);
|
assert(stop.pos == wrap_unit_end);
|
||||||
do_wrap = 1;
|
do_wrap = 1;
|
||||||
++wrap_array_index;
|
++wrap_array_index;
|
||||||
wrap_unit_end = file->state.wrap_positions[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
|
#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
|
* Vectors
|
||||||
*/
|
*/
|
||||||
|
@ -413,10 +376,10 @@ perp(Vec2 v){
|
||||||
|
|
||||||
inline Vec2
|
inline Vec2
|
||||||
polar_to_cartesian(real32 theta_degrees, real32 length){
|
polar_to_cartesian(real32 theta_degrees, real32 length){
|
||||||
Vec2 result;
|
Vec2 result;
|
||||||
result.x = COS(theta_degrees)*length;
|
result.x = COS(theta_degrees)*length;
|
||||||
result.y = SIN(theta_degrees)*length;
|
result.y = SIN(theta_degrees)*length;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Vec2
|
inline Vec2
|
||||||
|
@ -463,8 +426,8 @@ inline f32
|
||||||
unlerp(f32 a, f32 x, f32 b){
|
unlerp(f32 a, f32 x, f32 b){
|
||||||
f32 r = x;
|
f32 r = x;
|
||||||
if (b > a){
|
if (b > a){
|
||||||
r = (x - a) / (b - a);
|
r = (x - a) / (b - a);
|
||||||
}
|
}
|
||||||
return(r);
|
return(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -517,7 +480,7 @@ color_blend(u32 a, real32 t, u32 b){
|
||||||
u8 byte[4];
|
u8 byte[4];
|
||||||
u32 comp;
|
u32 comp;
|
||||||
} A, B, R;
|
} A, B, R;
|
||||||
|
|
||||||
A.comp = a;
|
A.comp = a;
|
||||||
B.comp = b;
|
B.comp = b;
|
||||||
|
|
||||||
|
@ -589,23 +552,23 @@ rgba_to_hsla(Vec4 rgba){
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
switch (maxc){
|
switch (maxc){
|
||||||
case 0:
|
case 0:
|
||||||
{
|
{
|
||||||
hsla.x = (rgba.g - rgba.b) / delta;
|
hsla.x = (rgba.g - rgba.b) / delta;
|
||||||
hsla.x += (rgba.g < rgba.b) * 6.f;
|
hsla.x += (rgba.g < rgba.b) * 6.f;
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
{
|
{
|
||||||
hsla.x = (rgba.b - rgba.r) / delta;
|
hsla.x = (rgba.b - rgba.r) / delta;
|
||||||
hsla.x += 2.f;
|
hsla.x += 2.f;
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
{
|
{
|
||||||
hsla.x = (rgba.r - rgba.g) / delta;
|
hsla.x = (rgba.r - rgba.g) / delta;
|
||||||
hsla.x += 4.f;
|
hsla.x += 4.f;
|
||||||
}break;
|
}break;
|
||||||
}
|
}
|
||||||
hsla.x *= (1/6.f); // * 60 / 360
|
hsla.x *= (1/6.f); // * 60 / 360
|
||||||
hsla.y = delta / (1.f - ABS(2.f*hsla.z - 1.f));
|
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;
|
m = hsla.z - C*.5f;
|
||||||
H = FLOOR32(hsla.x * 6.f);
|
H = FLOOR32(hsla.x * 6.f);
|
||||||
switch (H){
|
switch (H){
|
||||||
case 0:
|
case 0:
|
||||||
rgba.r = C; rgba.g = X; rgba.b = 0;
|
rgba.r = C; rgba.g = X; rgba.b = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
rgba.r = X; rgba.g = C; rgba.b = 0;
|
rgba.r = X; rgba.g = C; rgba.b = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
rgba.r = 0; rgba.g = C; rgba.b = X;
|
rgba.r = 0; rgba.g = C; rgba.b = X;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
rgba.r = 0; rgba.g = X; rgba.b = C;
|
rgba.r = 0; rgba.g = X; rgba.b = C;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 4:
|
case 4:
|
||||||
rgba.r = X; rgba.g = 0; rgba.b = C;
|
rgba.r = X; rgba.g = 0; rgba.b = C;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 5:
|
case 5:
|
||||||
rgba.r = C; rgba.g = 0; rgba.b = X;
|
rgba.r = C; rgba.g = 0; rgba.b = X;
|
||||||
break;
|
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")
|
if "%BUILD_MODE%" == "" (SET BUILD_MODE="/DDEV_BUILD")
|
||||||
|
|
||||||
pushd ..\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 (set FirstError=1)
|
||||||
|
if %ERRORLEVEL% neq 0 (goto END)
|
||||||
popd
|
popd
|
||||||
|
|
||||||
..\build\build
|
..\build\build
|
||||||
|
@ -24,4 +25,5 @@ call "print_size.bat" 4ed_app.dll
|
||||||
call "print_size.bat" 4ed.exe
|
call "print_size.bat" 4ed.exe
|
||||||
popd
|
popd
|
||||||
|
|
||||||
|
::END
|
||||||
call "ctime" -end 4ed_data.ctm %FirstError%
|
call "ctime" -end 4ed_data.ctm %FirstError%
|
||||||
|
|
2
build.sh
2
build.sh
|
@ -3,7 +3,7 @@
|
||||||
WARNINGS="-Wno-write-strings"
|
WARNINGS="-Wno-write-strings"
|
||||||
FLAGS="-D_GNU_SOURCE -fPIC -fpermissive -DDEV_BUILD"
|
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
|
../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
|
// TOP
|
||||||
#define FRED_DEFINES_H
|
|
||||||
|
|
||||||
#include <string.h>
|
#if !defined(FRED_DEFINES_H)
|
||||||
|
#define FRED_DEFINES_H
|
||||||
|
|
||||||
#if !defined (FRED_TYPES)
|
#if !defined (FRED_TYPES)
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
@ -58,13 +58,14 @@ typedef double f64;
|
||||||
#define TentativeAssert(c) Assert(c)
|
#define TentativeAssert(c) Assert(c)
|
||||||
#define NotImplemented Assert(!"This is not implemented yet!")
|
#define NotImplemented Assert(!"This is not implemented yet!")
|
||||||
#define InvalidCodePath Assert(!"Invalid code path!")
|
#define InvalidCodePath Assert(!"Invalid code path!")
|
||||||
|
#define InvalidPath InvalidCodePath
|
||||||
|
|
||||||
#define AllowLocal(name) (void)name
|
#define AllowLocal(name) (void)name
|
||||||
#ifndef ArrayCount
|
#ifndef ArrayCount
|
||||||
# define ArrayCount(array) (sizeof(array)/sizeof(array[0]))
|
# define ArrayCount(array) (sizeof(array)/sizeof(array[0]))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define OffsetOfStruct(S,c) ((i64)(& ((S*)0)->c ))
|
#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)
|
#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);
|
TMin(i64, -9223372036854775807-1);
|
||||||
#undef TMin
|
#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_0 (1 << 0)
|
||||||
#define Bit_1 (1 << 1)
|
#define Bit_1 (1 << 1)
|
||||||
#define Bit_2 (1 << 2)
|
#define Bit_2 (1 << 2)
|
||||||
|
@ -150,4 +140,57 @@ LargeRoundUp(i32 x, i32 granularity){
|
||||||
#define Gbytes(n) (((u64)n) << 30)
|
#define Gbytes(n) (((u64)n) << 30)
|
||||||
#define Tbytes(n) (((u64)n) << 40)
|
#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 MAJOR 4
|
||||||
#define MINOR 0
|
#define MINOR 0
|
||||||
#define PATCH 14
|
#define PATCH 15
|
||||||
|
|
||||||
#define VN__(a,b,c) #a"."#b"."#c
|
#define VN__(a,b,c) #a"."#b"."#c
|
||||||
#define VN_(a,b,c) VN__(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;
|
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
|
// Highlighting Information
|
||||||
|
@ -138,7 +81,7 @@ struct Editing_File_Settings{
|
||||||
static Editing_File_Settings null_editing_file_settings = {0};
|
static Editing_File_Settings null_editing_file_settings = {0};
|
||||||
|
|
||||||
struct Editing_File_State{
|
struct Editing_File_State{
|
||||||
Buffer_Type buffer;
|
Gap_Buffer buffer;
|
||||||
|
|
||||||
i32 *wrap_line_index;
|
i32 *wrap_line_index;
|
||||||
i32 wrap_max;
|
i32 wrap_max;
|
||||||
|
|
|
@ -9,7 +9,10 @@
|
||||||
|
|
||||||
// TOP
|
// TOP
|
||||||
|
|
||||||
#include "4coder_file.cpp"
|
#include "../common/4ed_defines.h"
|
||||||
|
|
||||||
|
#include "4coder_buffer.cpp"
|
||||||
|
#include "4coder_undo.cpp"
|
||||||
|
|
||||||
int main(){
|
int main(){
|
||||||
return(0);
|
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;
|
File_Track_Result result = FileTrack_Good;
|
||||||
Win32_File_Track_Vars *vars = to_vars(system);
|
Win32_File_Track_Vars *vars = to_vars(system);
|
||||||
|
|
||||||
|
|
||||||
DWORD win32_result = 0;
|
DWORD win32_result = 0;
|
||||||
|
|
||||||
// NOTE(allen): Close all the handles stored in the table.
|
// NOTE(allen): Close all the handles stored in the table.
|
||||||
|
|
|
@ -4,14 +4,16 @@
|
||||||
*
|
*
|
||||||
* 14.11.2015
|
* 14.11.2015
|
||||||
*
|
*
|
||||||
* Linux layer for project codename "4ed"
|
* Linux layer for 4coder
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// TOP
|
// TOP
|
||||||
|
|
||||||
# include <assert.h>
|
#include <assert.h>
|
||||||
# include "4ed_defines.h"
|
#include <string.h>
|
||||||
|
#include "common/4coder_defines.h"
|
||||||
|
#include "common/4coder_version.h"
|
||||||
|
|
||||||
#if FRED_SUPER
|
#if FRED_SUPER
|
||||||
|
|
||||||
|
@ -19,7 +21,6 @@
|
||||||
# define FSTRING_C
|
# define FSTRING_C
|
||||||
# include "4coder_string.h"
|
# include "4coder_string.h"
|
||||||
|
|
||||||
#include "4coder_version.h"
|
|
||||||
# include "4coder_keycodes.h"
|
# include "4coder_keycodes.h"
|
||||||
# include "4coder_style.h"
|
# include "4coder_style.h"
|
||||||
# include "4coder_rect.h"
|
# include "4coder_rect.h"
|
||||||
|
@ -48,7 +49,6 @@ typedef void Custom_Command_Function;
|
||||||
struct Application_Links;
|
struct Application_Links;
|
||||||
# include "4ed_os_custom_api.h"
|
# include "4ed_os_custom_api.h"
|
||||||
|
|
||||||
//# include "4coder_custom.h"
|
|
||||||
#else
|
#else
|
||||||
# include "4coder_default_bindings.cpp"
|
# include "4coder_default_bindings.cpp"
|
||||||
|
|
||||||
|
|
|
@ -9,81 +9,24 @@
|
||||||
|
|
||||||
// TOP
|
// TOP
|
||||||
|
|
||||||
#include "4coder_version.h"
|
#include "../common/4coder_defines.h"
|
||||||
|
#include "../common/4coder_version.h"
|
||||||
|
|
||||||
#if !defined(FSTRING_GUARD)
|
#if !defined(FSTRING_GUARD)
|
||||||
#include "internal_4coder_string.cpp"
|
#include "../internal_4coder_string.cpp"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "4cpp_lexer.h"
|
#include "../4cpp_lexer.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <assert.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 "meta_parser.cpp"
|
||||||
#include "site/meta_parser.cpp"
|
#include "out_context.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);
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
char *keys_that_need_codes[] = {
|
char *keys_that_need_codes[] = {
|
|
@ -10,10 +10,10 @@
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "4coder_version.h"
|
#include "../common/4coder_version.h"
|
||||||
|
|
||||||
#define FSTRING_INLINE static
|
#define FSTRING_INLINE static
|
||||||
#include "internal_4coder_string.cpp"
|
#include "../internal_4coder_string.cpp"
|
||||||
|
|
||||||
//
|
//
|
||||||
// reusable
|
// reusable
|
||||||
|
@ -21,7 +21,7 @@
|
||||||
|
|
||||||
#define IS_64BIT
|
#define IS_64BIT
|
||||||
|
|
||||||
// NOTE(allen): Compiler OS cracking.
|
// NOTE(allen): Compiler/OS cracking.
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
|
|
||||||
# define IS_CL
|
# define IS_CL
|
||||||
|
@ -75,7 +75,7 @@ static int32_t prev_error = 0;
|
||||||
static void init_time_system();
|
static void init_time_system();
|
||||||
static uint64_t get_time();
|
static uint64_t get_time();
|
||||||
static int32_t get_current_directory(char *buffer, int32_t max);
|
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 make_folder_if_missing(char *dir, char *folder);
|
||||||
static void clear_folder(char *folder);
|
static void clear_folder(char *folder);
|
||||||
|
@ -169,7 +169,7 @@ get_current_directory(char *buffer, int32_t max){
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
execute(char *dir, char *str, char *args){
|
execute_in_dir(char *dir, char *str, char *args){
|
||||||
if (dir){
|
if (dir){
|
||||||
Temp_Dir temp = pushdir(dir);
|
Temp_Dir temp = pushdir(dir);
|
||||||
if (args){
|
if (args){
|
||||||
|
@ -201,8 +201,6 @@ slash_fix(char *path){
|
||||||
|
|
||||||
static void
|
static void
|
||||||
make_folder_if_missing(char *dir, char *folder){
|
make_folder_if_missing(char *dir, char *folder){
|
||||||
slash_fix(dir);
|
|
||||||
|
|
||||||
char space[1024];
|
char space[1024];
|
||||||
String path = make_fixed_width_string(space);
|
String path = make_fixed_width_string(space);
|
||||||
append_sc(&path, dir);
|
append_sc(&path, dir);
|
||||||
|
@ -225,7 +223,6 @@ make_folder_if_missing(char *dir, char *folder){
|
||||||
|
|
||||||
static void
|
static void
|
||||||
clear_folder(char *folder){
|
clear_folder(char *folder){
|
||||||
slash_fix(folder);
|
|
||||||
systemf("del /S /Q /F %s\\* & rmdir /S /Q %s & mkdir %s",
|
systemf("del /S /Q /F %s\\* & rmdir /S /Q %s & mkdir %s",
|
||||||
folder, folder, folder);
|
folder, folder, folder);
|
||||||
}
|
}
|
||||||
|
@ -256,16 +253,11 @@ copy_file(char *path, char *file, char *folder1, char *folder2, char *newname){
|
||||||
}
|
}
|
||||||
terminate_with_null(&b);
|
terminate_with_null(&b);
|
||||||
|
|
||||||
slash_fix(src);
|
|
||||||
slash_fix(dst);
|
|
||||||
|
|
||||||
CopyFileA(src, dst, 0);
|
CopyFileA(src, dst, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
copy_all(char *source, char *tag, char *folder){
|
copy_all(char *source, char *tag, char *folder){
|
||||||
slash_fix(source);
|
|
||||||
slash_fix(folder);
|
|
||||||
if (source){
|
if (source){
|
||||||
systemf("copy %s\\%s %s\\*", source, tag, folder);
|
systemf("copy %s\\%s %s\\*", source, tag, folder);
|
||||||
}
|
}
|
||||||
|
@ -279,9 +271,6 @@ zip(char *parent, char *folder, char *dest){
|
||||||
char cdir[512];
|
char cdir[512];
|
||||||
get_current_directory(cdir, sizeof(cdir));
|
get_current_directory(cdir, sizeof(cdir));
|
||||||
|
|
||||||
slash_fix(parent);
|
|
||||||
slash_fix(dest);
|
|
||||||
|
|
||||||
Temp_Dir temp = pushdir(parent);
|
Temp_Dir temp = pushdir(parent);
|
||||||
systemf("%s\\zip %s\\4tech_gobble.zip", cdir, cdir);
|
systemf("%s\\zip %s\\4tech_gobble.zip", cdir, cdir);
|
||||||
popdir(temp);
|
popdir(temp);
|
||||||
|
@ -337,7 +326,7 @@ get_current_directory(char *buffer, int32_t max){
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
execute(char *dir, char *str, char *args){
|
execute_in_dir(char *dir, char *str, char *args){
|
||||||
if (dir){
|
if (dir){
|
||||||
if (args){
|
if (args){
|
||||||
Temp_Dir temp = pushdir(dir);
|
Temp_Dir temp = pushdir(dir);
|
||||||
|
@ -543,10 +532,6 @@ init_build_line(Build_Line *line){
|
||||||
|
|
||||||
static void
|
static void
|
||||||
build_cl(uint32_t flags, char *code_path, char *code_file, char *out_path, char *out_file, char *exports){
|
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;
|
Build_Line line;
|
||||||
init_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);
|
Temp_Dir temp = pushdir(out_path);
|
||||||
|
|
||||||
#if defined(IS_CL)
|
#if defined(IS_CL)
|
||||||
slash_fix(filename);
|
|
||||||
slash_fix(out_path);
|
|
||||||
slash_fix(code_path);
|
|
||||||
|
|
||||||
systemf("call \"%s\\buildsuper.bat\" %s", code_path, filename);
|
systemf("call \"%s\\buildsuper.bat\" %s", code_path, filename);
|
||||||
|
|
||||||
#elif defined(IS_GCC)
|
#elif defined(IS_GCC)
|
||||||
|
@ -723,119 +704,21 @@ buildsuper(char *code_path, char *out_path, char *filename){
|
||||||
popdir(temp);
|
popdir(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define D_META_DIR "../meta"
|
#define META_DIR "../meta"
|
||||||
#define D_META_FSM_DIR "../meta/fsmgen"
|
#define BUILD_DIR "../build"
|
||||||
#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 D_SITE_DIR "../site"
|
#define SITE_DIR "../site"
|
||||||
#define D_PACK_DIR "../distributions"
|
#define PACK_DIR "../distributions"
|
||||||
#define D_PACK_DATA_DIR "../data/dist_files"
|
#define PACK_DATA_DIR "../data/dist_files"
|
||||||
#define D_DATA_DIR "../data/test"
|
#define DATA_DIR "../data/test"
|
||||||
|
|
||||||
#define D_PACK_ALPHA_PAR_DIR "../current_dist"
|
#define PACK_ALPHA_PAR_DIR "../current_dist"
|
||||||
#define D_PACK_SUPER_PAR_DIR "../current_dist_super"
|
#define PACK_SUPER_PAR_DIR "../current_dist_super"
|
||||||
#define D_PACK_POWER_PAR_DIR "../current_dist_power"
|
#define PACK_POWER_PAR_DIR "../current_dist_power"
|
||||||
|
|
||||||
#define D_PACK_ALPHA_DIR D_PACK_ALPHA_PAR_DIR"/4coder"
|
#define PACK_ALPHA_DIR PACK_ALPHA_PAR_DIR"/4coder"
|
||||||
#define D_PACK_SUPER_DIR D_PACK_SUPER_PAR_DIR"/4coder"
|
#define PACK_SUPER_DIR PACK_SUPER_PAR_DIR"/4coder"
|
||||||
#define D_PACK_POWER_DIR D_PACK_POWER_PAR_DIR"/power"
|
#define PACK_POWER_DIR 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(IS_WINDOWS)
|
#if defined(IS_WINDOWS)
|
||||||
#define PLAT_LAYER "win32_4ed.cpp"
|
#define PLAT_LAYER "win32_4ed.cpp"
|
||||||
|
@ -845,18 +728,23 @@ init_global_strings(){
|
||||||
#error No platform layer defined for this OS.
|
#error No platform layer defined for this OS.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define DECL_STR(n,s) char n[] = s; slash_fix(n)
|
||||||
|
|
||||||
static void
|
static void
|
||||||
fsm_generator(char *cdir){
|
fsm_generator(char *cdir){
|
||||||
{
|
{
|
||||||
|
DECL_STR(file, "meta/fsm_table_generator.cpp");
|
||||||
|
DECL_STR(dir, META_DIR);
|
||||||
|
|
||||||
BEGIN_TIME_SECTION();
|
BEGIN_TIME_SECTION();
|
||||||
build(OPTS | DEBUG_INFO, cdir, "fsm_table_generator.cpp",
|
build(OPTS | DEBUG_INFO, cdir, file, dir, "fsmgen", 0);
|
||||||
META_DIR, "fsmgen", 0);
|
|
||||||
END_TIME_SECTION("build fsm generator");
|
END_TIME_SECTION("build fsm generator");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (prev_error == 0){
|
if (prev_error == 0){
|
||||||
|
DECL_STR(cmd, META_DIR"/fsmgen");
|
||||||
BEGIN_TIME_SECTION();
|
BEGIN_TIME_SECTION();
|
||||||
execute(cdir, META_FSM_DIR, 0);
|
execute_in_dir(cdir, cmd, 0);
|
||||||
END_TIME_SECTION("run fsm generator");
|
END_TIME_SECTION("run fsm generator");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -864,14 +752,18 @@ fsm_generator(char *cdir){
|
||||||
static void
|
static void
|
||||||
metagen(char *cdir){
|
metagen(char *cdir){
|
||||||
{
|
{
|
||||||
|
DECL_STR(file, "meta/4ed_metagen.cpp");
|
||||||
|
DECL_STR(dir, META_DIR);
|
||||||
|
|
||||||
BEGIN_TIME_SECTION();
|
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");
|
END_TIME_SECTION("build metagen");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (prev_error == 0){
|
if (prev_error == 0){
|
||||||
|
DECL_STR(cmd, META_DIR"/metagen");
|
||||||
BEGIN_TIME_SECTION();
|
BEGIN_TIME_SECTION();
|
||||||
execute(cdir, META_GEN_DIR, 0);
|
execute_in_dir(cdir, cmd, 0);
|
||||||
END_TIME_SECTION("run metagen");
|
END_TIME_SECTION("run metagen");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -881,7 +773,7 @@ enum{
|
||||||
Custom_Experiments,
|
Custom_Experiments,
|
||||||
Custom_Casey,
|
Custom_Casey,
|
||||||
Custom_ChronalVim,
|
Custom_ChronalVim,
|
||||||
CUSTOM_COUNT
|
Custom_COUNT
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -895,52 +787,49 @@ do_buildsuper(char *cdir, int32_t custom_option){
|
||||||
case Custom_Default:
|
case Custom_Default:
|
||||||
{
|
{
|
||||||
copy_sc(&str, "../code/4coder_default_bindings.cpp");
|
copy_sc(&str, "../code/4coder_default_bindings.cpp");
|
||||||
terminate_with_null(&str);
|
|
||||||
buildsuper(cdir, BUILD_DIR, str.str);
|
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case Custom_Experiments:
|
case Custom_Experiments:
|
||||||
{
|
{
|
||||||
#if defined(IS_WINDOWS)
|
#if defined(IS_WINDOWS)
|
||||||
copy_sc(&str, "../code/internal_4coder_tests.cpp");
|
copy_sc(&str, "../code/internal_4coder_tests.cpp");
|
||||||
terminate_with_null(&str);
|
|
||||||
buildsuper(cdir, BUILD_DIR, str.str);
|
|
||||||
#else
|
#else
|
||||||
copy_sc(&str, "../code/power/4coder_experiments.cpp");
|
copy_sc(&str, "../code/power/4coder_experiments.cpp");
|
||||||
terminate_with_null(&str);
|
|
||||||
buildsuper(cdir, BUILD_DIR, str.str);
|
|
||||||
#endif
|
#endif
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case Custom_Casey:
|
case Custom_Casey:
|
||||||
{
|
{
|
||||||
copy_sc(&str, "../code/power/4coder_casey.cpp");
|
copy_sc(&str, "../code/power/4coder_casey.cpp");
|
||||||
terminate_with_null(&str);
|
|
||||||
buildsuper(cdir, BUILD_DIR, str.str);
|
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case Custom_ChronalVim:
|
case Custom_ChronalVim:
|
||||||
{
|
{
|
||||||
copy_sc(&str, "../4vim/4coder_chronal.cpp");
|
copy_sc(&str, "../4vim/4coder_chronal.cpp");
|
||||||
terminate_with_null(&str);
|
|
||||||
buildsuper(cdir, BUILD_DIR, str.str);
|
|
||||||
}break;
|
}break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
terminate_with_null(&str);
|
||||||
|
|
||||||
|
DECL_STR(dir, BUILD_DIR);
|
||||||
|
buildsuper(cdir, dir, str.str);
|
||||||
|
|
||||||
END_TIME_SECTION("build custom");
|
END_TIME_SECTION("build custom");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
build_main(char *cdir, uint32_t flags){
|
build_main(char *cdir, uint32_t flags){
|
||||||
|
DECL_STR(dir, BUILD_DIR);
|
||||||
{
|
{
|
||||||
|
DECL_STR(file, "4ed_app_target.cpp");
|
||||||
BEGIN_TIME_SECTION();
|
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");
|
END_TIME_SECTION("build 4ed_app");
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
BEGIN_TIME_SECTION();
|
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");
|
END_TIME_SECTION("build 4ed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -957,24 +846,18 @@ standard_build(char *cdir, uint32_t flags){
|
||||||
static void
|
static void
|
||||||
site_build(char *cdir, uint32_t flags){
|
site_build(char *cdir, uint32_t flags){
|
||||||
{
|
{
|
||||||
|
DECL_STR(file, "site/sitegen.cpp");
|
||||||
|
DECL_STR(dir, BUILD_DIR"/site");
|
||||||
BEGIN_TIME_SECTION();
|
BEGIN_TIME_SECTION();
|
||||||
// TODO(allen): Figure out how to do these strings the right way... fuck.
|
build(OPTS | SITE_INCLUDES | flags, cdir, file, dir, "sitegen", 0);
|
||||||
#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
|
|
||||||
END_TIME_SECTION("build sitegen");
|
END_TIME_SECTION("build sitegen");
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
BEGIN_TIME_SECTION();
|
BEGIN_TIME_SECTION();
|
||||||
|
|
||||||
#if defined(IS_WINDOWS)
|
DECL_STR(cmd, "../build/site/sitegen . ../site_resources site/source_material ../site");
|
||||||
systemf("..\\build\\site\\sitegen . ..\\foreign\\site-resources site\\source_material ..\\site");
|
systemf(cmd);
|
||||||
#else
|
|
||||||
systemf("../build/site/sitegen . ../foreign/site-resources site/source_material ../site");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
END_TIME_SECTION("run sitegen");
|
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){
|
get_4coder_dist_name(String *zip_file, int32_t OS_specific, char *tier, char *ext){
|
||||||
zip_file->size = 0;
|
zip_file->size = 0;
|
||||||
|
|
||||||
append_sc(zip_file, PACK_DIR);
|
append_sc(zip_file, PACK_DIR"/");
|
||||||
append_sc(zip_file, "/");
|
|
||||||
append_sc(zip_file, tier);
|
append_sc(zip_file, tier);
|
||||||
append_sc(zip_file, "/4coder-");
|
append_sc(zip_file, "/4coder-");
|
||||||
|
|
||||||
|
@ -1027,69 +909,82 @@ package(char *cdir){
|
||||||
// NOTE(allen): alpha
|
// NOTE(allen): alpha
|
||||||
build_main(cdir, OPTIMIZATION | KEEP_ASSERT | DEBUG_INFO);
|
build_main(cdir, OPTIMIZATION | KEEP_ASSERT | DEBUG_INFO);
|
||||||
|
|
||||||
clear_folder(PACK_ALPHA_PAR_DIR);
|
DECL_STR(build_dir, BUILD_DIR);
|
||||||
make_folder_if_missing(PACK_ALPHA_DIR, "3rdparty");
|
DECL_STR(site_dir, SITE_DIR);
|
||||||
make_folder_if_missing(PACK_DIR, "alpha");
|
DECL_STR(pack_dir, PACK_DIR);
|
||||||
copy_file(BUILD_DIR, "4ed"EXE, PACK_ALPHA_DIR, 0, 0);
|
DECL_STR(pack_data_dir, PACK_DATA_DIR);
|
||||||
ONLY_WINDOWS(copy_file(BUILD_DIR, "4ed"PDB, PACK_ALPHA_DIR, 0, 0));
|
DECL_STR(data_dir, DATA_DIR);
|
||||||
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));
|
DECL_STR(pack_alpha_par_dir, PACK_ALPHA_PAR_DIR);
|
||||||
copy_all (PACK_DATA_DIR, "*", PACK_ALPHA_DIR);
|
DECL_STR(pack_super_par_dir, PACK_SUPER_PAR_DIR);
|
||||||
copy_file(0, "README.txt", PACK_ALPHA_DIR, 0, 0);
|
DECL_STR(pack_power_par_dir, PACK_POWER_PAR_DIR);
|
||||||
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(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");
|
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
|
// NOTE(allen): super
|
||||||
build_main(cdir, OPTIMIZATION | KEEP_ASSERT | DEBUG_INFO | SUPER);
|
build_main(cdir, OPTIMIZATION | KEEP_ASSERT | DEBUG_INFO | SUPER);
|
||||||
do_buildsuper(cdir, Custom_Default);
|
do_buildsuper(cdir, Custom_Default);
|
||||||
|
|
||||||
clear_folder(PACK_SUPER_PAR_DIR);
|
clear_folder(pack_super_par_dir);
|
||||||
make_folder_if_missing(PACK_SUPER_DIR, "3rdparty");
|
make_folder_if_missing(pack_super_dir, "3rdparty");
|
||||||
make_folder_if_missing(PACK_DIR, "super");
|
make_folder_if_missing(pack_dir, "super");
|
||||||
make_folder_if_missing(PACK_DIR, "super-docs");
|
make_folder_if_missing(pack_dir, "super-docs");
|
||||||
|
|
||||||
copy_file(BUILD_DIR, "4ed"EXE, 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));
|
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);
|
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));
|
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, "4coder_custom"DLL, pack_super_dir, 0, 0);
|
||||||
|
|
||||||
copy_all (PACK_DATA_DIR, "*", PACK_SUPER_DIR);
|
copy_all (pack_data_dir, "*", pack_super_dir);
|
||||||
copy_file(0, "README.txt", PACK_SUPER_DIR, 0, 0);
|
copy_file(0, "README.txt", pack_super_dir, 0, 0);
|
||||||
copy_file(0, "TODO.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_file(data_dir, "release-config.4coder", pack_super_dir, 0, "config.4coder");
|
||||||
|
|
||||||
copy_all (0, "4coder_*.h", PACK_SUPER_DIR);
|
copy_all (0, "4coder_*.h", pack_super_dir);
|
||||||
copy_all (0, "4coder_*.cpp", PACK_SUPER_DIR);
|
copy_all (0, "4coder_*.cpp", pack_super_dir);
|
||||||
copy_all (0, "4cpp_*.h", PACK_SUPER_DIR);
|
copy_all (0, "4cpp_*.h", pack_super_dir);
|
||||||
copy_all (0, "4cpp_*.c", PACK_SUPER_DIR);
|
copy_all (0, "4cpp_*.c", pack_super_dir);
|
||||||
copy_file(0, "buildsuper"BAT, PACK_SUPER_DIR, 0, 0);
|
copy_file(0, "buildsuper"BAT, pack_super_dir, 0, 0);
|
||||||
|
|
||||||
get_4coder_dist_name(&str, 0, "API", "html");
|
get_4coder_dist_name(&str, 0, "API", "html");
|
||||||
str2 = front_of_directory(str);
|
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");
|
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
|
// NOTE(allen): power
|
||||||
clear_folder(PACK_POWER_PAR_DIR);
|
clear_folder(pack_power_par_dir);
|
||||||
make_folder_if_missing(PACK_POWER_DIR, 0);
|
make_folder_if_missing(pack_power_dir, 0);
|
||||||
make_folder_if_missing(PACK_DIR, "power");
|
make_folder_if_missing(pack_dir, "power");
|
||||||
copy_all("power", "*", PACK_POWER_DIR);
|
copy_all("power", "*", pack_power_dir);
|
||||||
|
|
||||||
get_4coder_dist_name(&str, 0, "power", "zip");
|
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)
|
#if defined(DEV_BUILD)
|
||||||
|
|
||||||
int main(int argc, char **argv){
|
int main(int argc, char **argv){
|
||||||
init_time_system();
|
init_time_system();
|
||||||
init_global_strings();
|
|
||||||
|
|
||||||
char cdir[256];
|
char cdir[256];
|
||||||
|
|
||||||
|
@ -1125,7 +1020,6 @@ int main(int argc, char **argv){
|
||||||
|
|
||||||
int main(int argc, char **argv){
|
int main(int argc, char **argv){
|
||||||
init_time_system();
|
init_time_system();
|
||||||
init_global_strings();
|
|
||||||
|
|
||||||
char cdir[256];
|
char cdir[256];
|
||||||
|
|
|
@ -14,8 +14,8 @@
|
||||||
#define Assert(n) do{ if (!(n)) { *(int*)0 = 0xA11E; } }while(0)
|
#define Assert(n) do{ if (!(n)) { *(int*)0 = 0xA11E; } }while(0)
|
||||||
#define ArrayCount(a) (sizeof(a)/sizeof(*a))
|
#define ArrayCount(a) (sizeof(a)/sizeof(*a))
|
||||||
|
|
||||||
#include "4cpp_lexer_types.h"
|
#include "../4cpp_lexer_types.h"
|
||||||
#include "4ed_mem_ansi.c"
|
#include "../4ed_mem_ansi.c"
|
||||||
|
|
||||||
typedef struct Whitespace_FSM{
|
typedef struct Whitespace_FSM{
|
||||||
unsigned char pp_state;
|
unsigned char pp_state;
|
|
@ -16,14 +16,14 @@
|
||||||
#include "internal_4coder_string.cpp"
|
#include "internal_4coder_string.cpp"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "4cpp_lexer.h"
|
#include "../4cpp_lexer.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
#include "4coder_mem.h"
|
#include "../4coder_mem.h"
|
||||||
|
|
||||||
typedef struct Parse_Context{
|
typedef struct Parse_Context{
|
||||||
Cpp_Token *token_s;
|
Cpp_Token *token_s;
|
|
@ -3,5 +3,5 @@
|
||||||
WARNINGS="-Wno-write-strings"
|
WARNINGS="-Wno-write-strings"
|
||||||
FLAGS="-D_GNU_SOURCE -fPIC -fpermissive -DPACKAGE"
|
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
|
../build/build
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
extensions=".c.cpp.h.hpp.bat.sh";
|
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[1] = {"build.bat", "*compilation*", true};
|
||||||
fkey_command_win[2] = {"..\\misc\\run.bat", "*run*"};
|
fkey_command_win[2] = {"..\\misc\\run.bat", "*run*"};
|
||||||
fkey_command_win[3] = {"site\\build.bat", "*compilation*", true};
|
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[5] = {0, 0};
|
||||||
fkey_command_win[6] = {0, 0};
|
fkey_command_win[6] = {0, 0};
|
||||||
fkey_command_win[7] = {0, 0};
|
fkey_command_win[7] = {0, 0};
|
||||||
|
|
|
@ -9,11 +9,6 @@
|
||||||
|
|
||||||
// TOP
|
// TOP
|
||||||
|
|
||||||
#if !defined(ABSTRACT_DOCUMENT_H)
|
|
||||||
#define ABSTRACT_DOCUMENT_H
|
|
||||||
|
|
||||||
#define NotImplemented Assert(!"Not Implemented!")
|
|
||||||
|
|
||||||
// Enriched Text
|
// Enriched Text
|
||||||
|
|
||||||
struct Enriched_Text{
|
struct Enriched_Text{
|
||||||
|
@ -65,20 +60,20 @@ enum{
|
||||||
struct Document_Item{
|
struct Document_Item{
|
||||||
Document_Item *next;
|
Document_Item *next;
|
||||||
Document_Item *parent;
|
Document_Item *parent;
|
||||||
int32_t type;
|
i32 type;
|
||||||
union{
|
union{
|
||||||
struct{
|
struct{
|
||||||
Document_Item *first_child;
|
Document_Item *first_child;
|
||||||
Document_Item *last_child;
|
Document_Item *last_child;
|
||||||
String name;
|
String name;
|
||||||
String id;
|
String id;
|
||||||
int32_t show_title;
|
i32 show_title;
|
||||||
} section;
|
} section;
|
||||||
|
|
||||||
struct{
|
struct{
|
||||||
Meta_Unit *unit;
|
Meta_Unit *unit;
|
||||||
Alternate_Names_Array *alt_names;
|
Alternate_Names_Array *alt_names;
|
||||||
int32_t alt_name_type;
|
i32 alt_name_type;
|
||||||
} unit_elements;
|
} unit_elements;
|
||||||
|
|
||||||
struct{
|
struct{
|
||||||
|
@ -108,7 +103,7 @@ struct Basic_List{
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Abstract_Item{
|
struct Abstract_Item{
|
||||||
int32_t item_type;
|
i32 item_type;
|
||||||
char *name;
|
char *name;
|
||||||
|
|
||||||
// Document value members
|
// Document value members
|
||||||
|
@ -118,7 +113,7 @@ struct Abstract_Item{
|
||||||
// Document building members
|
// Document building members
|
||||||
Partition *part;
|
Partition *part;
|
||||||
Document_Item *section_stack[16];
|
Document_Item *section_stack[16];
|
||||||
int32_t section_top;
|
i32 section_top;
|
||||||
|
|
||||||
// Image value members
|
// Image value members
|
||||||
char *source_file;
|
char *source_file;
|
||||||
|
@ -130,7 +125,7 @@ struct Abstract_Item{
|
||||||
static Abstract_Item null_abstract_item = {0};
|
static Abstract_Item null_abstract_item = {0};
|
||||||
|
|
||||||
struct Image_Instantiation{
|
struct Image_Instantiation{
|
||||||
int32_t w, h;
|
i32 w, h;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Document_System{
|
struct Document_System{
|
||||||
|
@ -148,8 +143,8 @@ create_document_system(Partition *part){
|
||||||
}
|
}
|
||||||
|
|
||||||
static void*
|
static void*
|
||||||
push_item_on_list(Partition *part, Basic_List *list, int32_t item_size){
|
push_item_on_list(Partition *part, Basic_List *list, i32 item_size){
|
||||||
int32_t mem_size = item_size + sizeof(Basic_Node);
|
i32 mem_size = item_size + sizeof(Basic_Node);
|
||||||
void *mem = push_block(part, mem_size);
|
void *mem = push_block(part, mem_size);
|
||||||
assert(mem != 0);
|
assert(mem != 0);
|
||||||
memset(mem, 0, mem_size);
|
memset(mem, 0, mem_size);
|
||||||
|
@ -203,7 +198,7 @@ get_item_by_name(Basic_List list, char *name){
|
||||||
}
|
}
|
||||||
|
|
||||||
static Image_Instantiation*
|
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;
|
Image_Instantiation *result = 0;
|
||||||
|
|
||||||
for (Basic_Node *node = list.head;
|
for (Basic_Node *node = list.head;
|
||||||
|
@ -232,15 +227,15 @@ create_item(Partition *part, Basic_List *list, char *name){
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
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));
|
Image_Instantiation *instantiation = (Image_Instantiation*)push_item_on_list(part, list, sizeof(Image_Instantiation));
|
||||||
instantiation->w = w;
|
instantiation->w = w;
|
||||||
instantiation->h = h;
|
instantiation->h = h;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
set_section_name(Partition *part, Document_Item *item, char *name, int32_t show_title){
|
set_section_name(Partition *part, Document_Item *item, char *name, i32 show_title){
|
||||||
int32_t name_len = str_size(name);
|
i32 name_len = str_size(name);
|
||||||
item->section.name = make_string_cap(push_array(part, char, name_len+1), 0, name_len+1);
|
item->section.name = make_string_cap(push_array(part, char, name_len+1), 0, name_len+1);
|
||||||
partition_align(part, 8);
|
partition_align(part, 8);
|
||||||
append_sc(&item->section.name, name);
|
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
|
static void
|
||||||
set_section_id(Partition *part, Document_Item *item, char *id){
|
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);
|
item->section.id = make_string_cap(push_array(part, char, id_len+1), 0, id_len+1);
|
||||||
partition_align(part, 8);
|
partition_align(part, 8);
|
||||||
append_sc(&item->section.id, id);
|
append_sc(&item->section.id, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
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 = null_abstract_item;
|
||||||
doc->item_type = ItemType_Document;
|
doc->item_type = ItemType_Document;
|
||||||
doc->part = part;
|
doc->part = part;
|
||||||
|
@ -290,23 +285,23 @@ add_image_description(Document_System *system, char *source_file, char *extensio
|
||||||
item->source_file = source_file;
|
item->source_file = source_file;
|
||||||
item->name = name;
|
item->name = name;
|
||||||
|
|
||||||
int32_t w = 0, h = 0, comp = 0;
|
i32 w = 0, h = 0, comp = 0;
|
||||||
int32_t stbi_r = stbi_info(source_file, &w, &h, &comp);
|
i32 stbi_r = stbi_info(source_file, &w, &h, &comp);
|
||||||
if (!stbi_r){
|
if (!stbi_r){
|
||||||
fprintf(stderr, "Did not find file %s\n", source_file);
|
fprintf(stderr, "Did not find file %s\n", source_file);
|
||||||
item->w_h_ratio = 1.f;
|
item->w_h_ratio = 1.f;
|
||||||
item->h_w_ratio = 1.f;
|
item->h_w_ratio = 1.f;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
item->w_h_ratio = ((float)w/(float)h);
|
item->w_h_ratio = ((float)w/(float)h);
|
||||||
item->h_w_ratio = ((float)h/(float)w);
|
item->h_w_ratio = ((float)h/(float)w);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return(item);
|
return(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Abstract_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);
|
Abstract_Item *item = create_item(system->part, &system->doc_list, name);
|
||||||
if (item){
|
if (item){
|
||||||
begin_document_description(item, system->part, title, show_title);
|
begin_document_description(item, system->part, title, show_title);
|
||||||
|
@ -380,7 +375,7 @@ add_element_list(Abstract_Item *doc, Meta_Unit *unit){
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
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 *parent = doc->section_stack[doc->section_top];
|
||||||
Document_Item *item = push_struct(doc->part, Document_Item);
|
Document_Item *item = push_struct(doc->part, Document_Item);
|
||||||
*item = null_document_item;
|
*item = null_document_item;
|
||||||
|
@ -404,7 +399,7 @@ add_full_elements(Abstract_Item *doc, Meta_Unit *unit){
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
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 *parent = doc->section_stack[doc->section_top];
|
||||||
Document_Item *item = push_struct(doc->part, Document_Item);
|
Document_Item *item = push_struct(doc->part, Document_Item);
|
||||||
*item = null_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>"
|
#define HTML_EXAMPLE_CODE_CLOSE "</div>"
|
||||||
|
|
||||||
struct Section_Counter{
|
struct Section_Counter{
|
||||||
int32_t counter[16];
|
i32 counter[16];
|
||||||
int32_t nest_level;
|
i32 nest_level;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int32_t
|
static i32
|
||||||
doc_get_link_string(Abstract_Item *doc, char *space, int32_t capacity){
|
doc_get_link_string(Abstract_Item *doc, char *space, i32 capacity){
|
||||||
String str = make_string_cap(space, 0, capacity);
|
String str = make_string_cap(space, 0, capacity);
|
||||||
append_sc(&str, doc->name);
|
append_sc(&str, doc->name);
|
||||||
append_sc(&str, ".html");
|
append_sc(&str, ".html");
|
||||||
int32_t result = terminate_with_null(&str);
|
i32 result = terminate_with_null(&str);
|
||||||
return(result);
|
return(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t
|
static i32
|
||||||
img_get_link_string(Abstract_Item *img, char *space, int32_t capacity, int32_t w, int32_t h){
|
img_get_link_string(Abstract_Item *img, char *space, i32 capacity, i32 w, i32 h){
|
||||||
String str = make_string_cap(space, 0, capacity);
|
String str = make_string_cap(space, 0, capacity);
|
||||||
append_sc(&str, img->name);
|
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, ".");
|
||||||
append_sc(&str, img->extension);
|
append_sc(&str, img->extension);
|
||||||
int32_t result = terminate_with_null(&str);
|
i32 result = terminate_with_null(&str);
|
||||||
return(result);
|
return(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
append_section_number_reduced(String *out, Section_Counter *section_counter, int32_t reduce){
|
append_section_number_reduced(String *out, Section_Counter *section_counter, i32 reduce){
|
||||||
int32_t level = section_counter->nest_level-reduce;
|
i32 level = section_counter->nest_level-reduce;
|
||||||
for (int32_t i = 1; i <= level; ++i){
|
for (i32 i = 1; i <= level; ++i){
|
||||||
append_int_to_str(out, section_counter->counter[i]);
|
append_int_to_str(out, section_counter->counter[i]);
|
||||||
if (i != level){
|
if (i != level){
|
||||||
append_sc(out, ".");
|
append_sc(out, ".");
|
||||||
|
@ -524,11 +519,11 @@ append_section_number(String *out, Section_Counter *section_counter){
|
||||||
append_section_number_reduced(out, section_counter, 0);
|
append_section_number_reduced(out, section_counter, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t
|
static i32
|
||||||
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){
|
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){
|
||||||
int32_t result = 0;
|
i32 result = 0;
|
||||||
|
|
||||||
int32_t i = *i_in_out;
|
i32 i = *i_in_out;
|
||||||
|
|
||||||
for (; i < l.size; ++i){
|
for (; i < l.size; ++i){
|
||||||
if (!char_is_whitespace(l.str[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;
|
i32 found_command_body = 0;
|
||||||
int32_t body_start = 0, body_end = 0;
|
i32 body_start = 0, body_end = 0;
|
||||||
if (l.str[i] == '{'){
|
if (l.str[i] == '{'){
|
||||||
body_start = i+1;
|
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){
|
if (require_body){
|
||||||
#define STR_START "<span style='color:#F00'>! Doc generator error: missing body for "
|
#define STR_START "<span style='color:#F00'>! Doc generator error: missing body for "
|
||||||
#define STR_SLOW " !</span>"
|
#define STR_SLOW " !</span>"
|
||||||
append_sc(out, STR_START);
|
append_sc(out, STR_START);
|
||||||
append_ss(out, command_name);
|
append_ss(out, command_name);
|
||||||
append_sc(out, STR_SLOW);
|
append_sc(out, STR_SLOW);
|
||||||
#undef STR
|
#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>");
|
append_sc(out, "<div>");
|
||||||
|
|
||||||
int32_t item_counter = 0;
|
i32 item_counter = 0;
|
||||||
|
|
||||||
for (String line = get_first_double_line(source);
|
for (String line = get_first_double_line(source);
|
||||||
line.str;
|
line.str;
|
||||||
|
@ -623,13 +618,13 @@ write_enriched_text_html(String *out, Partition *part, Enriched_Text *text, Docu
|
||||||
append_sc(out, "<p>");
|
append_sc(out, "<p>");
|
||||||
|
|
||||||
//append_ss(out, l);
|
//append_ss(out, l);
|
||||||
int32_t start = 0, i = 0;
|
i32 start = 0, i = 0;
|
||||||
for (; i < l.size; ++i){
|
for (; i < l.size; ++i){
|
||||||
if (l.str[i] == '\\'){
|
if (l.str[i] == '\\'){
|
||||||
append_ss(out, substr(l, start, i-start));
|
append_ss(out, substr(l, start, i-start));
|
||||||
|
|
||||||
int32_t command_start = i+1;
|
i32 command_start = i+1;
|
||||||
int32_t command_end = command_start;
|
i32 command_end = command_start;
|
||||||
for (; command_end < l.size; ++command_end){
|
for (; command_end < l.size; ++command_end){
|
||||||
if (!char_is_alpha_numeric(l.str[command_end])){
|
if (!char_is_alpha_numeric(l.str[command_end])){
|
||||||
break;
|
break;
|
||||||
|
@ -684,7 +679,7 @@ write_enriched_text_html(String *out, Partition *part, Enriched_Text *text, Docu
|
||||||
|
|
||||||
i = command_end;
|
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)){
|
if (string_set_match(enriched_commands, ArrayCount(enriched_commands), command_string, &match_index)){
|
||||||
switch (match_index){
|
switch (match_index){
|
||||||
case Cmd_BackSlash: append_sc(out, "\\"); break;
|
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:
|
case Cmd_BeginStyle:
|
||||||
{
|
{
|
||||||
int32_t body_start = 0, body_end = 0;
|
i32 body_start = 0, body_end = 0;
|
||||||
int32_t has_body = extract_command_body(out, l, &i, &body_start, &body_end, command_string, 1);
|
i32 has_body = extract_command_body(out, l, &i, &body_start, &body_end, command_string, 1);
|
||||||
if (has_body){
|
if (has_body){
|
||||||
String body_text = substr(l, body_start, body_end - body_start);
|
String body_text = substr(l, body_start, body_end - body_start);
|
||||||
body_text = skip_chop_whitespace(body_text);
|
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
|
// TODO(allen): upgrade this bs
|
||||||
case Cmd_DocLink:
|
case Cmd_DocLink:
|
||||||
{
|
{
|
||||||
int32_t body_start = 0, body_end = 0;
|
i32 body_start = 0, body_end = 0;
|
||||||
int32_t has_body = extract_command_body(out, l, &i, &body_start, &body_end, command_string, 1);
|
i32 has_body = extract_command_body(out, l, &i, &body_start, &body_end, command_string, 1);
|
||||||
if (has_body){
|
if (has_body){
|
||||||
String body_text = substr(l, body_start, body_end - body_start);
|
String body_text = substr(l, body_start, body_end - body_start);
|
||||||
body_text = skip_chop_whitespace(body_text);
|
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:
|
case Cmd_Section:
|
||||||
{
|
{
|
||||||
// TODO(allen): undo the duplication of this body extraction code.
|
// TODO(allen): undo the duplication of this body extraction code.
|
||||||
int32_t body_start = 0, body_end = 0;
|
i32 body_start = 0, body_end = 0;
|
||||||
int32_t has_body = extract_command_body(out, l, &i, &body_start, &body_end, command_string, 1);
|
i32 has_body = extract_command_body(out, l, &i, &body_start, &body_end, command_string, 1);
|
||||||
if (has_body){
|
if (has_body){
|
||||||
String body_text = substr(l, body_start, body_end - body_start);
|
String body_text = substr(l, body_start, body_end - body_start);
|
||||||
body_text = skip_chop_whitespace(body_text);
|
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:
|
case Cmd_BeginLink:
|
||||||
{
|
{
|
||||||
int32_t body_start = 0, body_end = 0;
|
i32 body_start = 0, body_end = 0;
|
||||||
int32_t has_body = extract_command_body(out, l, &i, &body_start, &body_end, command_string, 1);
|
i32 has_body = extract_command_body(out, l, &i, &body_start, &body_end, command_string, 1);
|
||||||
if (has_body){
|
if (has_body){
|
||||||
String body_text = substr(l, body_start, body_end - body_start);
|
String body_text = substr(l, body_start, body_end - body_start);
|
||||||
body_text = skip_chop_whitespace(body_text);
|
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:
|
case Cmd_Image:
|
||||||
{
|
{
|
||||||
// TODO(allen): generalize this
|
// TODO(allen): generalize this
|
||||||
int32_t body_start = 0, body_end = 0;
|
i32 body_start = 0, body_end = 0;
|
||||||
int32_t has_body = extract_command_body(out, l, &i, &body_start, &body_end, command_string, 1);
|
i32 has_body = extract_command_body(out, l, &i, &body_start, &body_end, command_string, 1);
|
||||||
|
|
||||||
if (has_body){
|
if (has_body){
|
||||||
String body_text = substr(l, body_start, body_end - body_start);
|
String body_text = substr(l, body_start, body_end - body_start);
|
||||||
body_text = skip_chop_whitespace(body_text);
|
body_text = skip_chop_whitespace(body_text);
|
||||||
|
|
||||||
int32_t pixel_height = 10;
|
i32 pixel_height = 10;
|
||||||
int32_t pixel_width = HTML_WIDTH;
|
i32 pixel_width = HTML_WIDTH;
|
||||||
|
|
||||||
body_start = 0, body_end = 0;
|
body_start = 0, body_end = 0;
|
||||||
has_body = extract_command_body(out, l, &i, &body_start, &body_end, command_string, 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:
|
case Cmd_Video:
|
||||||
{
|
{
|
||||||
// TODO(allen): generalize this
|
// TODO(allen): generalize this
|
||||||
int32_t body_start = 0, body_end = 0;
|
i32 body_start = 0, body_end = 0;
|
||||||
int32_t has_body = extract_command_body(out, l, &i, &body_start, &body_end, command_string, 1);
|
i32 has_body = extract_command_body(out, l, &i, &body_start, &body_end, command_string, 1);
|
||||||
|
|
||||||
int32_t pixel_width = HTML_WIDTH;
|
i32 pixel_width = HTML_WIDTH;
|
||||||
int32_t pixel_height = (int32_t)(pixel_width * 0.5625);
|
i32 pixel_height = (i32)(pixel_width * 0.5625);
|
||||||
|
|
||||||
if (has_body){
|
if (has_body){
|
||||||
String body_text = substr(l, body_start, body_end - body_start);
|
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_int_to_str(out, pixel_width);
|
||||||
append_sc(out, "' height='");
|
append_sc(out, "' height='");
|
||||||
append_int_to_str(out, pixel_height);
|
append_int_to_str(out, pixel_height);
|
||||||
append_sc(out, "' src='");
|
append_sc(out, "' src='");
|
||||||
append_ss(out, youtube_str);
|
append_ss(out, youtube_str);
|
||||||
append_sc(out, "' allowfullscreen> </iframe>");
|
append_sc(out, "' allowfullscreen> </iframe>");
|
||||||
}
|
}
|
||||||
|
@ -917,16 +912,16 @@ print_item_in_list(String *out, String name, char *id_postfix){
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
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->strs = push_array(part, String, count);
|
||||||
used->count = 0;
|
used->count = 0;
|
||||||
used->max = count;
|
used->max = count;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t
|
static i32
|
||||||
try_to_use(Used_Links *used, String str){
|
try_to_use(Used_Links *used, String str){
|
||||||
int32_t result = 1;
|
i32 result = 1;
|
||||||
int32_t index = 0;
|
i32 index = 0;
|
||||||
|
|
||||||
if (string_set_match(used->strs, used->count, str, &index)){
|
if (string_set_match(used->strs, used->count, str, &index)){
|
||||||
result = 0;
|
result = 0;
|
||||||
|
@ -939,7 +934,7 @@ try_to_use(Used_Links *used, String str){
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
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 name = member->name;
|
||||||
String type = member->type;
|
String type = member->type;
|
||||||
String type_postfix = member->type_postfix;
|
String type_postfix = member->type_postfix;
|
||||||
|
@ -991,7 +986,7 @@ print_function_html(String *out, Used_Links *used, String cpp_name, String ret,
|
||||||
else{
|
else{
|
||||||
append_sc(out, "(<div style='margin-left: 4mm;'>");
|
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);
|
append_ss(out, breakdown.args[j].param_string);
|
||||||
if (j < breakdown.count - 1){
|
if (j < breakdown.count - 1){
|
||||||
append_s_char(out, ',');
|
append_s_char(out, ',');
|
||||||
|
@ -1020,7 +1015,7 @@ print_macro_html(String *out, String name, Argument_Breakdown breakdown){
|
||||||
else{
|
else{
|
||||||
append_sc (out, "(<div style='margin-left: 4mm;'>");
|
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);
|
append_ss(out, breakdown.args[j].param_string);
|
||||||
if (j < breakdown.count - 1){
|
if (j < breakdown.count - 1){
|
||||||
append_s_char(out, ',');
|
append_s_char(out, ',');
|
||||||
|
@ -1048,11 +1043,11 @@ static String
|
||||||
get_next_doc_chunk(String source, String prev_chunk, Doc_Chunk_Type *type){
|
get_next_doc_chunk(String source, String prev_chunk, Doc_Chunk_Type *type){
|
||||||
String chunk = {0};
|
String chunk = {0};
|
||||||
String word = {0};
|
String word = {0};
|
||||||
int32_t pos = source.size;
|
i32 pos = source.size;
|
||||||
int32_t word_index = 0;
|
i32 word_index = 0;
|
||||||
Doc_Chunk_Type t = DocChunk_PlainText;
|
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);
|
String source_tail = substr_tail(source, start_pos);
|
||||||
|
|
||||||
Assert(DocChunk_Count == ArrayCount(doc_chunk_headers));
|
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.str;
|
||||||
word = get_next_word(source_tail, word), ++word_index){
|
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])){
|
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;
|
t = (Doc_Chunk_Type)i;
|
||||||
goto doublebreak;
|
goto doublebreak;
|
||||||
}
|
}
|
||||||
|
@ -1075,8 +1070,8 @@ get_next_doc_chunk(String source, String prev_chunk, Doc_Chunk_Type *type){
|
||||||
if (word_index == 0){
|
if (word_index == 0){
|
||||||
*type = t;
|
*type = t;
|
||||||
|
|
||||||
int32_t nest_level = 1;
|
i32 nest_level = 1;
|
||||||
int32_t i = find_s_char(source, pos, '(');
|
i32 i = find_s_char(source, pos, '(');
|
||||||
for (++i; i < source.size; ++i){
|
for (++i; i < source.size; ++i){
|
||||||
if (source.str[i] == '('){
|
if (source.str[i] == '('){
|
||||||
++nest_level;
|
++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);
|
chunk = substr(source, start_pos, pos - start_pos);
|
||||||
|
|
||||||
int32_t is_all_white = 1;
|
i32 is_all_white = 1;
|
||||||
for (int32_t i = 0; i < chunk.size; ++i){
|
for (i32 i = 0; i < chunk.size; ++i){
|
||||||
if (!char_is_whitespace(chunk.str[i])){
|
if (!char_is_whitespace(chunk.str[i])){
|
||||||
is_all_white = 0;
|
is_all_white = 0;
|
||||||
break;
|
break;
|
||||||
|
@ -1137,8 +1132,8 @@ print_doc_description(String *out, Partition *part, String src){
|
||||||
|
|
||||||
case DocChunk_CodeExample:
|
case DocChunk_CodeExample:
|
||||||
{
|
{
|
||||||
int32_t start = 0;
|
i32 start = 0;
|
||||||
int32_t end = chunk.size-1;
|
i32 end = chunk.size-1;
|
||||||
while (start < end && chunk.str[start] != '(') ++start;
|
while (start < end && chunk.str[start] != '(') ++start;
|
||||||
start += 1;
|
start += 1;
|
||||||
while (end > start && chunk.str[end] != ')') --end;
|
while (end > start && chunk.str[end] != ')') --end;
|
||||||
|
@ -1148,14 +1143,14 @@ print_doc_description(String *out, Partition *part, String src){
|
||||||
|
|
||||||
if (start < end){
|
if (start < end){
|
||||||
String code_example = substr(chunk, start, end - start);
|
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);
|
for (String line = get_first_line(code_example);
|
||||||
line.str;
|
line.str;
|
||||||
line = get_next_line(code_example, line)){
|
line = get_next_line(code_example, line)){
|
||||||
|
|
||||||
if (!(first_line && line.size == 0)){
|
if (!(first_line && line.size == 0)){
|
||||||
int32_t space_i = 0;
|
i32 space_i = 0;
|
||||||
for (; space_i < line.size; ++space_i){
|
for (; space_i < line.size; ++space_i){
|
||||||
if (line.str[space_i] == ' '){
|
if (line.str[space_i] == ' '){
|
||||||
append_sc(out, " ");
|
append_sc(out, " ");
|
||||||
|
@ -1210,11 +1205,11 @@ print_struct_docs(String *out, Partition *part, Item_Node *member){
|
||||||
|
|
||||||
static void
|
static void
|
||||||
print_see_also(String *out, Documentation *doc){
|
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){
|
if (doc_see_count > 0){
|
||||||
append_sc(out, HTML_DOC_HEAD_OPEN"See Also"HTML_DOC_HEAD_CLOSE);
|
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];
|
String see_also = doc->see_also[j];
|
||||||
append_sc(out, HTML_DOC_ITEM_OPEN"<a href='#");
|
append_sc(out, HTML_DOC_ITEM_OPEN"<a href='#");
|
||||||
append_ss(out, see_also);
|
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);
|
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){
|
if (doc_param_count > 0){
|
||||||
append_sc(out, HTML_DOC_HEAD_OPEN"Parameters"HTML_DOC_HEAD_CLOSE);
|
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_name = doc.param_name[j];
|
||||||
String param_docs = doc.param_docs[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
|
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);
|
Temp_Memory temp = begin_temp_memory(part);
|
||||||
|
|
||||||
String name = item->name;
|
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, id_postfix);
|
||||||
append_sc(out, "' style='margin-bottom: 1cm;'>");
|
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 (item->cpp_name.str != 0){
|
||||||
if (try_to_use(used, item->cpp_name)){
|
if (try_to_use(used, item->cpp_name)){
|
||||||
append_sc(out, "<div id='");
|
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;
|
String doc_string = item->doc_string;
|
||||||
|
|
||||||
int32_t hide_members = 0;
|
i32 hide_members = 0;
|
||||||
|
|
||||||
if (doc_string.size == 0){
|
if (doc_string.size == 0){
|
||||||
hide_members = 1;
|
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;
|
Meta_Unit *unit = item->unit_elements.unit;
|
||||||
Alternate_Names_Array *alt_names = item->unit_elements.alt_names;
|
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){
|
switch (item->unit_elements.alt_name_type){
|
||||||
case AltName_Standard:
|
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");
|
print_item_in_list(out, unit->set.items[i].name, "_doc");
|
||||||
}
|
}
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case AltName_Macro:
|
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");
|
print_item_in_list(out, alt_names->names[i].macro, "_doc");
|
||||||
}
|
}
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
case AltName_Public_Name:
|
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");
|
print_item_in_list(out, alt_names->names[i].public_name, "_doc");
|
||||||
}
|
}
|
||||||
}break;
|
}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;
|
Meta_Unit *unit = item->unit_elements.unit;
|
||||||
Alternate_Names_Array *alt_names = item->unit_elements.alt_names;
|
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];
|
char section_space[32];
|
||||||
String section_str = make_fixed_width_string(section_space);
|
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);
|
terminate_with_null(§ion_str);
|
||||||
|
|
||||||
if (alt_names){
|
if (alt_names){
|
||||||
int32_t I = 1;
|
i32 I = 1;
|
||||||
for (int32_t i = 0; i < count; ++i, ++I){
|
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);
|
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{
|
else{
|
||||||
int32_t I = 1;
|
i32 I = 1;
|
||||||
for (int32_t i = 0; i < count; ++i, ++I){
|
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);
|
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>");
|
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;
|
for (Document_Item *toc_item = item->parent->section.first_child;
|
||||||
toc_item != 0;
|
toc_item != 0;
|
||||||
toc_item = toc_item->next){
|
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);
|
doc_item_head_html(out, part, doc_system, used_links, item, section_counter);
|
||||||
|
|
||||||
if (item->type == Doc_Root || item->type == Doc_Section){
|
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;
|
section_counter->counter[level] = 1;
|
||||||
for (Document_Item *m = item->section.first_child;
|
for (Document_Item *m = item->section.first_child;
|
||||||
m != 0;
|
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);
|
generate_item_html(out, part, doc_system, &used_links, doc->root_item, §ion_counter);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// BOTTOM
|
// BOTTOM
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ SET OPTS=%OPTS% /GR- /EHa- /nologo /FC
|
||||||
SET FirstError=0
|
SET FirstError=0
|
||||||
|
|
||||||
pushd ..\build
|
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)
|
if %ERRORLEVEL% neq 0 (set FirstError=1)
|
||||||
popd
|
popd
|
||||||
|
|
||||||
|
|
|
@ -4,5 +4,5 @@ WARNINGS="-Wno-write-strings"
|
||||||
FLAGS="-D_GNU_SOURCE -fPIC -fpermissive -DSITE_BUILD"
|
FLAGS="-D_GNU_SOURCE -fPIC -fpermissive -DSITE_BUILD"
|
||||||
|
|
||||||
BASEDIR="$PWD"
|
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
|
../build/build
|
||||||
|
|
|
@ -16,27 +16,22 @@
|
||||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||||
#include "stb_image_write.h"
|
#include "stb_image_write.h"
|
||||||
|
|
||||||
#include "4coder_version.h"
|
|
||||||
#define FSTRING_IMPLEMENTATION
|
|
||||||
#include "4coder_string.h"
|
|
||||||
#include "4cpp_lexer.h"
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.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) ))
|
#include "../4coder_mem.h"
|
||||||
#define FLOOR32(x) ((int32_t) ( (x>0)?(x):(x-1.f) ))
|
|
||||||
|
|
||||||
#include "meta_parser.cpp"
|
#include "../meta/meta_parser.cpp"
|
||||||
#include "out_context.cpp"
|
#include "../meta/out_context.cpp"
|
||||||
#include "abstract_document.cpp"
|
#include "abstract_document.cpp"
|
||||||
|
|
||||||
#define InvalidPath Assert(!"Invalid path of execution")
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -44,14 +39,14 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
static void
|
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};
|
String pstr = {0}, lexeme = {0};
|
||||||
Cpp_Token *token = 0;
|
Cpp_Token *token = 0;
|
||||||
|
|
||||||
int32_t do_print = 0;
|
i32 do_print = 0;
|
||||||
int32_t nest_level = 0;
|
i32 nest_level = 0;
|
||||||
int32_t finish = 0;
|
i32 finish = 0;
|
||||||
int32_t do_whitespace_print = 0;
|
i32 do_whitespace_print = 0;
|
||||||
for (; (token = get_token(context)) != 0; get_next_token(context)){
|
for (; (token = get_token(context)) != 0; get_next_token(context)){
|
||||||
if (do_whitespace_print){
|
if (do_whitespace_print){
|
||||||
pstr = str_start_end(context->data, start, token->start);
|
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
|
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};
|
Alternate_Names_Array app_api = {0};
|
||||||
app_api.names = push_array(part, Alternate_Name, count);
|
app_api.names = push_array(part, Alternate_Name, count);
|
||||||
memset(app_api.names, 0, sizeof(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
|
static void
|
||||||
do_html_output(Document_System *doc_system, Partition *part, char *dst_directory, Abstract_Item *doc){
|
do_html_output(Document_System *doc_system, Partition *part, char *dst_directory, Abstract_Item *doc){
|
||||||
// NOTE(allen): Output
|
// NOTE(allen): Output
|
||||||
int32_t out_size = 10 << 20;
|
i32 out_size = 10 << 20;
|
||||||
Tail_Temp_Partition temp = begin_tail_part(part, out_size);
|
Tail_Temp_Partition temp = begin_tail_part(part, out_size);
|
||||||
|
|
||||||
String out = str_alloc(&temp.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
|
// NOTE(allen): Compute and store variations of the custom function names
|
||||||
*custom_func_names = allocate_app_api(part, custom_funcs_unit->set.count);
|
*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 name_string = custom_funcs_unit->set.items[i].name;
|
||||||
String *macro = &custom_func_names->names[i].macro;
|
String *macro = &custom_func_names->names[i].macro;
|
||||||
String *public_name = &custom_func_names->names[i].public_name;
|
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
|
static String
|
||||||
push_string(Partition *part, int32_t size){
|
push_string(Partition *part, i32 size){
|
||||||
String str = {0};
|
String str = {0};
|
||||||
str.memory_size = size;
|
str.memory_size = size;
|
||||||
str.str = push_array(part, char, size);
|
str.str = push_array(part, char, size);
|
||||||
|
@ -346,8 +341,8 @@ push_string(Partition *part, int32_t size){
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
do_image_resize(Partition *part, char *src_file, char *dst_file, char *extension, int32_t w, int32_t h){
|
do_image_resize(Partition *part, char *src_file, char *dst_file, char *extension, i32 w, i32 h){
|
||||||
int x, y, channels;
|
i32 x = 0, y = 0, channels = 0;
|
||||||
stbi_uc *image = stbi_load(src_file, &x, &y, &channels, 0);
|
stbi_uc *image = stbi_load(src_file, &x, &y, &channels, 0);
|
||||||
|
|
||||||
stbi_uc *resized_image = (stbi_uc*)malloc(w*h*channels);
|
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
|
static void
|
||||||
generate_site(char *code_directory, char *asset_directory, char *src_directory, char *dst_directory){
|
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);
|
void *mem = malloc(size);
|
||||||
memset(mem, 0, 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
|
* 12.12.2014
|
||||||
*
|
*
|
||||||
* Win32 layer for project codename "4ed"
|
* Win32 layer for 4coder
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// TOP
|
// TOP
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include "4ed_defines.h"
|
#include <string.h>
|
||||||
|
#include "common/4coder_defines.h"
|
||||||
|
#include "common/4coder_version.h"
|
||||||
|
|
||||||
#if defined(FRED_SUPER)
|
#if defined(FRED_SUPER)
|
||||||
|
|
||||||
|
@ -18,7 +20,6 @@
|
||||||
# define FSTRING_C
|
# define FSTRING_C
|
||||||
# include "4coder_string.h"
|
# include "4coder_string.h"
|
||||||
|
|
||||||
# include "4coder_version.h"
|
|
||||||
# include "4coder_keycodes.h"
|
# include "4coder_keycodes.h"
|
||||||
# include "4coder_style.h"
|
# include "4coder_style.h"
|
||||||
# include "4coder_rect.h"
|
# include "4coder_rect.h"
|
||||||
|
@ -47,7 +48,6 @@ typedef void Custom_Command_Function;
|
||||||
struct Application_Links;
|
struct Application_Links;
|
||||||
# include "4coder_custom_api.h"
|
# include "4coder_custom_api.h"
|
||||||
|
|
||||||
//# include "4coder_custom.h"
|
|
||||||
#else
|
#else
|
||||||
# include "4coder_default_bindings.cpp"
|
# 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);
|
system_acquire_lock(CANCEL_LOCK0 + memory->id - 1);
|
||||||
old_data = memory->data;
|
old_data = memory->data;
|
||||||
old_size = memory->size;
|
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->data = system_get_memory(new_size);
|
||||||
memory->size = new_size;
|
memory->size = new_size;
|
||||||
if (old_data){
|
if (old_data){
|
||||||
|
@ -710,9 +710,7 @@ Sys_Yield_Coroutine_Sig(system_yield_coroutine){
|
||||||
|
|
||||||
internal
|
internal
|
||||||
Sys_File_Can_Be_Made_Sig(system_file_can_be_made){
|
Sys_File_Can_Be_Made_Sig(system_file_can_be_made){
|
||||||
HANDLE file;
|
HANDLE file = CreateFile((char*)filename, FILE_APPEND_DATA, 0, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
|
||||||
file = CreateFile((char*)filename, FILE_APPEND_DATA, 0, 0,
|
|
||||||
OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
|
|
||||||
|
|
||||||
if (!file || file == INVALID_HANDLE_VALUE){
|
if (!file || file == INVALID_HANDLE_VALUE){
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -951,13 +949,7 @@ Sys_Load_Close_Sig(system_load_close){
|
||||||
internal
|
internal
|
||||||
Sys_Save_File_Sig(system_save_file){
|
Sys_Save_File_Sig(system_save_file){
|
||||||
b32 result = 0;
|
b32 result = 0;
|
||||||
HANDLE file = CreateFile(filename,
|
HANDLE file = CreateFile(filename, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
|
||||||
GENERIC_WRITE,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
CREATE_ALWAYS,
|
|
||||||
FILE_ATTRIBUTE_NORMAL,
|
|
||||||
0);
|
|
||||||
|
|
||||||
if (file != INVALID_HANDLE_VALUE){
|
if (file != INVALID_HANDLE_VALUE){
|
||||||
DWORD written_total = 0;
|
DWORD written_total = 0;
|
||||||
|
@ -966,7 +958,7 @@ Sys_Save_File_Sig(system_save_file){
|
||||||
result = 1;
|
result = 1;
|
||||||
|
|
||||||
while (written_total < size){
|
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;
|
result = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1675,8 +1667,7 @@ Win32Callback(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){
|
||||||
i32 new_x = LOWORD(lParam);
|
i32 new_x = LOWORD(lParam);
|
||||||
i32 new_y = HIWORD(lParam);
|
i32 new_y = HIWORD(lParam);
|
||||||
|
|
||||||
if (new_x != win32vars.input_chunk.pers.mouse_x
|
if (new_x != win32vars.input_chunk.pers.mouse_x || new_y != win32vars.input_chunk.pers.mouse_y){
|
||||||
|| new_y != win32vars.input_chunk.pers.mouse_y){
|
|
||||||
win32vars.input_chunk.pers.mouse_x = new_x;
|
win32vars.input_chunk.pers.mouse_x = new_x;
|
||||||
win32vars.input_chunk.pers.mouse_y = new_y;
|
win32vars.input_chunk.pers.mouse_y = new_y;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue