Merge non-sense, who knows, here goes

master
Allen Webster 2019-06-01 16:58:28 -07:00
parent 70cae408d1
commit 2ef8f361d7
148 changed files with 14530 additions and 15053 deletions

View File

@ -22,8 +22,6 @@
#include "4coder_API/4coder_types.h"
#include "4coder_generated/app_functions.h"
#include "4coder_base_types.cpp"
extern "C" _GET_VERSION_SIG(get_alpha_4coder_version){
return((maj == MAJOR && min == MINOR && patch == PATCH));
}

View File

@ -429,30 +429,6 @@ STRUCT Mouse_State{
};
};
/* DOC(Range describes an integer range typically used for ranges within a buffer. Ranges are not used to pass into the API, but this struct is used for returns.
Throughout the API ranges are thought of in the form [min,max) where max is "one past the end" of the range that is actually read/edited/modified.) */
UNION Range{
STRUCT{
/* DOC(This is the smaller value in the range.) */
i32 min;
/* DOC(This is the larger value in the range.) */
i32 max;
};
STRUCT{
/* DOC(This is the start of the range, unioned with min.) */
i32 start;
/* DOC(This is the end of the range, unioned with max.) */
i32 end;
};
STRUCT{
/* DOC(This is the first value in the range, unioned with min.) */
i32 first;
/* DOC(This is one_past_the_last value in the range, unioned with max.) */
i32 one_past_last;
};
};
/* DOC(An array of ranges. This is just a plain pointer bundled with a count, no additional special structure.) */
STRUCT Range_Array{
/* DOC(A pointer to the array of ranges.) */
@ -629,6 +605,25 @@ STRUCT Partial_Cursor{
i32 character;
};
STRUCT Range_Partial_Cursor{
struct{
Partial_Cursor min;
Partial_Cursor max;
};
struct{
Partial_Cursor begin;
Partial_Cursor end;
};
struct{
Partial_Cursor start;
Partial_Cursor end;
};
struct{
Partial_Cursor first;
Partial_Cursor one_past_last;
};
};
STRUCT File_Attributes{
u64 size;
u64 last_write_time;
@ -785,9 +780,11 @@ ENUM(u32, Glyph_Flag){
/* DOC(Query_Bar is a struct used to store information in the user's control that will be displayed as a drop down bar durring an interactive command.) */
STRUCT Query_Bar{
/* DOC(This specifies the prompt portion of the drop down bar.) */
String prompt;
String_Const_u8 prompt;
/* DOC(This specifies the main string portion of the drop down bar.) */
String string;
String_Const_u8 string;
/* DOC(This specifies the memory capacity allocated for string.) */
umem string_capacity;
};
STRUCT Query_Bar_Ptr_Array{
@ -902,6 +899,7 @@ ENUM(i32, Record_Error){
RecordError_InvalidBuffer,
RecordError_NoHistoryAttached,
RecordError_IndexOutOfBounds,
RecordError_SubIndexOutOfBounds,
RecordError_InitialStateDummyRecord,
RecordError_WrongRecordTypeAtIndex,
};
@ -920,8 +918,8 @@ STRUCT Record_Info{
i32 edit_number;
union{
struct{
String string_forward;
String string_backward;
String_Const_u8 string_forward;
String_Const_u8 string_backward;
i32 first;
} single;
struct{
@ -971,16 +969,6 @@ what event triggered the abort event.) */
b32 abort;
};
/*
DOC(Data is used for passing and returing pointer size pairs.)
*/
STRUCT Data{
/* DOC(A pointer to the data.) */
u8 *data;
/* DOC(The size of the data in bytes.) */
u64 size;
};
STRUCT Frame_Info{
i32 index;
f32 literal_dt;
@ -1048,8 +1036,8 @@ TYPEDEF_FUNC i32 Hook_Function(struct Application_Links *app);
TYPEDEF_FUNC i32 Open_File_Hook_Function(struct Application_Links *app, Buffer_ID buffer_id);
#define OPEN_FILE_HOOK_SIG(name) i32 name(struct Application_Links *app, Buffer_ID buffer_id)
TYPEDEF_FUNC i32 File_Edit_Range_Function(struct Application_Links *app, Buffer_ID buffer_id, Range range, String text);
#define FILE_EDIT_RANGE_SIG(name) i32 name(struct Application_Links *app, Buffer_ID buffer_id, Range range, String text)
TYPEDEF_FUNC i32 File_Edit_Range_Function(struct Application_Links *app, Buffer_ID buffer_id, Range range, String_Const_u8 text);
#define FILE_EDIT_RANGE_SIG(name) i32 name(struct Application_Links *app, Buffer_ID buffer_id, Range range, String_Const_u8 text)
TYPEDEF_FUNC i32 File_Edit_Finished_Function(struct Application_Links *app, Buffer_ID *buffer_ids, i32 buffer_id_count);
#define FILE_EDIT_FINISHED_SIG(name) i32 name(struct Application_Links *app, Buffer_ID *buffer_ids, i32 buffer_id_count)
@ -1072,21 +1060,19 @@ TYPEDEF_FUNC Color_Table Modify_Color_Table_Function(struct Application_Links *a
ENUM(u32, Clipboard_Change_Flag){
ClipboardFlag_FromOS = 0x1,
};
TYPEDEF_FUNC void Clipboard_Change_Hook_Function(struct Application_Links *app, String contents, Clipboard_Change_Flag flags);
#define CLIPBOARD_CHANGE_HOOK_SIG(name) void name(struct Application_Links *app, String contents, Clipboard_Change_Flag flags)
TYPEDEF_FUNC void Clipboard_Change_Hook_Function(struct Application_Links *app, String_Const_u8 contents, Clipboard_Change_Flag flags);
#define CLIPBOARD_CHANGE_HOOK_SIG(name) void name(struct Application_Links *app, String_Const_u8 contents, Clipboard_Change_Flag flags)
TYPEDEF_FUNC Rect_i32 Get_View_Buffer_Region_Function(struct Application_Links *app, View_ID view_id, Rect_i32 sub_region);
#define GET_VIEW_BUFFER_REGION_SIG(name) Rect_i32 name(struct Application_Links *app, View_ID view_id, Rect_i32 sub_region)
STRUCT Buffer_Name_Conflict_Entry{
Buffer_ID buffer_id;
char *file_name;
i32 file_name_len;
char *base_name;
i32 base_name_len;
char *unique_name_in_out;
i32 unique_name_len_in_out;
i32 unique_name_capacity;
String_Const_u8 file_name;
String_Const_u8 base_name;
u8 *unique_name_in_out;
umem unique_name_len_in_out;
umem unique_name_capacity;
};
TYPEDEF_FUNC void Buffer_Name_Resolver_Function(struct Application_Links *app, Buffer_Name_Conflict_Entry *conflicts, i32 conflict_count);
@ -1141,7 +1127,7 @@ typedef i32 _Get_Version_Function(i32 maj, i32 min, i32 patch);
#define _GET_VERSION_SIG(n) i32 n(i32 maj, i32 min, i32 patch)
STRUCT color_picker{
String title;
String_Const_u8 title;
argb_color *dest;
b32 *finished;
};

View File

@ -30,6 +30,7 @@ static b32
get_buffer_summary(Application_Links *app, Buffer_ID buffer_id, Access_Flag access, Buffer_Summary *buffer){
b32 result = false;
if (buffer_exists(app, buffer_id)){
Scratch_Block scratch(app);
Access_Flag buffer_access_flags = 0;
buffer_get_access_flags(app, buffer_id, &buffer_access_flags);
if ((buffer_access_flags & ~access) == 0){
@ -39,12 +40,17 @@ get_buffer_summary(Application_Links *app, Buffer_ID buffer_id, Access_Flag acce
buffer->buffer_id = buffer_id;
buffer_get_size(app, buffer_id, &buffer->size);
buffer_get_line_count(app, buffer_id, &buffer->line_count);
String file_name = make_fixed_width_string(buffer->file_name);
buffer_get_file_name(app, buffer_id, &file_name, 0);
buffer->file_name_len = file_name.size;
String buffer_name = make_fixed_width_string(buffer->buffer_name);
buffer_get_unique_buffer_name(app, buffer_id, &buffer_name, 0);
buffer->buffer_name_len = buffer_name.size;
String_Const_u8 file_name_get = {};
buffer_get_file_name(app, buffer_id, scratch, &file_name_get);
block_copy(buffer->file_name, file_name_get.str, file_name_get.size);
buffer->file_name_len = (i32)file_name_get.size;
String_Const_u8 buffer_name_get = {};
buffer_get_unique_buffer_name(app, buffer_id, scratch, &buffer_name_get);
block_copy(buffer->buffer_name, buffer_name_get.str, buffer_name_get.size);
buffer->buffer_name_len = (i32)buffer_name_get.size;
buffer_get_dirty_state(app, buffer_id, &buffer->dirty);
buffer_get_setting(app, buffer_id, BufferSetting_Lex, &buffer->is_lexed);
buffer->tokens_are_ready = buffer_tokens_are_ready(app, buffer_id);
@ -93,69 +99,9 @@ get_view_summary(Application_Links *app, View_ID view_id, Access_Flag access, Vi
return(result);
}
static b32
exec_system_command(Application_Links *app, View_Summary *view, Buffer_Identifier buffer_id,
char *path, int32_t path_len, char *command, i32 command_len, Command_Line_Interface_Flag flags){
b32 result = false;
String path_string = make_string(path, path_len);
String command_string = make_string(command, command_len);
Child_Process_ID child_process_id = 0;
if (create_child_process(app, path_string, command_string, &child_process_id)){
result = true;
Buffer_ID buffer_attach_id = 0;
if (buffer_id.name != 0 && buffer_id.name_len > 0){
String buffer_name = make_string(buffer_id.name, buffer_id.name_len);
if (!get_buffer_by_name(app, buffer_name, AccessAll, &buffer_attach_id)){
if (create_buffer(app, buffer_name, BufferCreate_AlwaysNew|BufferCreate_NeverAttachToFile, &buffer_attach_id)){
buffer_set_setting(app, buffer_attach_id, BufferSetting_ReadOnly, true);
buffer_set_setting(app, buffer_attach_id, BufferSetting_Unimportant, true);
}
}
}
else if (buffer_id.id != 0){
buffer_attach_id = buffer_id.id;
}
if (buffer_attach_id != 0){
Child_Process_Set_Target_Flags set_buffer_flags = 0;
if (!HasFlag(flags, CLI_OverlapWithConflict)){
set_buffer_flags |= ChildProcessSet_FailIfBufferAlreadyAttachedToAProcess;
}
if (HasFlag(flags, CLI_CursorAtEnd)){
set_buffer_flags |= ChildProcessSet_CursorAtEnd;
}
if (child_process_set_target_buffer(app, child_process_id, buffer_attach_id, set_buffer_flags)){
Buffer_Summary buffer = {};
get_buffer_summary(app, buffer_attach_id, AccessAll, &buffer);
buffer_replace_range(app, buffer_attach_id, make_range(0, buffer.size), make_lit_string(""));
if (HasFlag(flags, CLI_SendEndSignal)){
buffer_send_end_signal(app, buffer_attach_id);
}
if (view != 0){
view_set_buffer(app, view->view_id, buffer_attach_id, 0);
get_view_summary(app, view->view_id, AccessAll, view);
}
}
}
}
return(result);
}
static b32
exec_system_command(Application_Links *app, View_ID view, Buffer_Identifier buffer_id,
char *path, int32_t path_len, char *command, i32 command_len, Command_Line_Interface_Flag flags){
View_Summary view_summary = {};
get_view_summary(app, view, AccessAll, &view_summary);
return(exec_system_command(app, &view_summary, buffer_id, path, path_len, command, command_len, flags));
}
static b32
clipboard_post(Application_Links *app, i32 clipboard_id, char *str, i32 len){
return(clipboard_post(app, clipboard_id, make_string(str, len)));
return(clipboard_post(app, clipboard_id, SCu8(str, len)));
}
static i32
@ -167,10 +113,11 @@ clipboard_count(Application_Links *app, i32 clipboard_id){
static i32
clipboard_index(Application_Links *app, i32 clipboard_id, i32 item_index, char *out, i32 len){
i32 required_size = 0;
String string = make_string_cap(out, 0, len);
clipboard_index(app, clipboard_id, item_index, &string, &required_size);
return(required_size);
Scratch_Block scratch(app);
String_Const_u8 string = {};
clipboard_index(app, clipboard_id, item_index, scratch, &string);
block_copy(out, string.str, clamp_top((i32)string.size, len));
return((i32)string.size);
}
static Buffer_Summary
@ -207,7 +154,7 @@ static Buffer_Summary
get_buffer_by_name(Application_Links *app, char *name, i32 len, Access_Flag access){
Buffer_ID id = 0;
Buffer_Summary buffer = {};
if (get_buffer_by_name(app, make_string(name, len), access, &id)){
if (get_buffer_by_name(app, SCu8(name, len), access, &id)){
get_buffer_summary(app, id, access, &buffer);
}
return(buffer);
@ -217,7 +164,7 @@ static Buffer_Summary
get_buffer_by_file_name(Application_Links *app, char *name, i32 len, Access_Flag access){
Buffer_ID id = 0;
Buffer_Summary buffer = {};
if (get_buffer_by_file_name(app, make_string(name, len), access, &id)){
if (get_buffer_by_file_name(app, SCu8(name, len), access, &id)){
get_buffer_summary(app, id, access, &buffer);
}
return(buffer);
@ -237,7 +184,7 @@ static b32
buffer_replace_range(Application_Links *app, Buffer_Summary *buffer, i32 start, i32 one_past_last, char *str, i32 len){
b32 result = false;
if (buffer != 0 && buffer->exists){
result = buffer_replace_range(app, buffer->buffer_id, make_range(start, one_past_last), make_string(str, len));
result = buffer_replace_range(app, buffer->buffer_id, make_range(start, one_past_last), SCu8(str, len));
get_buffer_summary(app, buffer->buffer_id, AccessAll, buffer);
}
return(result);
@ -343,7 +290,7 @@ static Buffer_Summary
create_buffer(Application_Links *app, char *filename, i32 filename_len, Buffer_Create_Flag flags){
Buffer_Summary buffer = {};
Buffer_ID buffer_id = 0;
if (create_buffer(app, make_string(filename, filename_len), flags, &buffer_id)){
if (create_buffer(app, SCu8(filename, filename_len), flags, &buffer_id)){
get_buffer_summary(app, buffer_id, AccessAll, &buffer);
}
return(buffer);
@ -353,7 +300,7 @@ static b32
save_buffer(Application_Links *app, Buffer_Summary *buffer, char *file_name, i32 file_name_len, u32 flags){
b32 result = false;
if (buffer != 0 && buffer->exists){
result = buffer_save(app, buffer->buffer_id, make_string(file_name, file_name_len), flags);
result = buffer_save(app, buffer->buffer_id, SCu8(file_name, file_name_len), flags);
get_buffer_summary(app, buffer->buffer_id, AccessAll, buffer);
}
return(result);
@ -367,7 +314,7 @@ kill_buffer(Application_Links *app, Buffer_Identifier buffer, Buffer_Kill_Flag f
}
else if (buffer.name != 0){
Buffer_ID id = 0;
if (get_buffer_by_name(app, make_string(buffer.name, buffer.name_len), AccessAll, &id)){
if (get_buffer_by_name(app, SCu8(buffer.name, buffer.name_len), AccessAll, &id)){
buffer_kill(app, id, flags, &result);
}
}
@ -446,14 +393,6 @@ open_view(Application_Links *app, View_Summary *view_location, View_Split_Positi
return(view);
}
static View_ID
open_view(Application_Links *app, View_ID view_location, View_Split_Position position){
View_Summary summary = {};
get_view_summary(app, view_location, AccessAll, &summary);
summary = open_view(app, &summary, position);
return(summary.view_id);
}
static b32
close_view(Application_Links *app, View_Summary *view){
b32 result = false;
@ -499,12 +438,6 @@ view_get_managed_scope(Application_Links *app, View_ID view_id){
return(scope);
}
typedef i32 View_Split_Kind;
enum{
ViewSplitKind_Ratio,
ViewSplitKind_FixedPixels,
};
static b32
view_compute_cursor(Application_Links *app, View_Summary *view, Buffer_Seek seek, Full_Cursor *cursor_out){
b32 result = false;
@ -615,7 +548,7 @@ get_face_id(Application_Links *app, Buffer_Summary *buffer){
static void
print_message(Application_Links *app, char *str, i32 len){
print_message(app, make_string(str, len));
print_message(app, SCu8(str, len));
}
#if 0
@ -632,51 +565,57 @@ change_theme(Application_Links *app, char *name, i32 len){
static i32
directory_get_hot(Application_Links *app, char *out, i32 capacity){
i32 required_size = 0;
String string = make_string_cap(out, 0, capacity);
get_hot_directory(app, &string, &required_size);
return(required_size);
Scratch_Block scratch(app);
String_Const_u8 string = {};
get_hot_directory(app, scratch, &string);
block_copy(out, string.str, clamp_top((i32)string.size, capacity));
return((i32)string.size);
}
static b32
directory_set_hot(Application_Links *app, char *str, i32 len){
return(set_hot_directory(app, make_string(str, len)));
return(set_hot_directory(app, SCu8(str, len)));
}
static File_List
get_file_list(Application_Links *app, char *dir, i32 len){
File_List list = {};
get_file_list(app, make_string(dir, len), &list);
get_file_list(app, SCu8(dir, len), &list);
return(list);
}
static b32
file_exists(Application_Links *app, char *file_name, i32 len){
File_Attributes attributes = {};
file_get_attributes(app, make_string(file_name, len), &attributes);
file_get_attributes(app, SCu8(file_name, len), &attributes);
return(attributes.last_write_time > 0);
}
static b32
directory_cd(Application_Links *app, char *dir, i32 *len, i32 capacity, char *rel_path, i32 rel_len){
String directory = make_string_cap(dir, *len, capacity);
String relative_path = make_string(rel_path, rel_len);
b32 result = directory_cd(app, &directory, relative_path);
*len = directory.size;
String_Const_u8 directory = SCu8(dir, *len);
String_Const_u8 relative_path = SCu8(rel_path, rel_len);
Scratch_Block scratch(app);
String_Const_u8 new_directory = {};
b32 result = directory_cd(app, directory, relative_path, scratch, &new_directory);
i32 new_len = clamp_top((i32)new_directory.size, capacity);
block_copy(dir, new_directory.str, new_len);
*len = new_len;
return(result);
}
static i32
get_4ed_path(Application_Links *app, char *out, i32 capacity){
i32 required_size = 0;
String string = make_string_cap(out, 0, capacity);
get_4ed_path(app, &string, &required_size);
return(required_size);
Scratch_Block scratch(app);
String_Const_u8 string = {};
get_4ed_path(app, scratch, &string);
block_copy(out, string.str, clamp_top((i32)string.size, capacity));
return((i32)string.size);
}
static void
set_window_title(Application_Links *app, char *title){
String title_string = make_string_slowly(title);
String_Const_u8 title_string = SCu8(title);
set_window_title(app, title_string);
}

View File

@ -24,6 +24,71 @@
#if !defined(REMOVE_TRANSITION_HELPER_31)
static b32
exec_system_command(Application_Links *app, View_Summary *view, Buffer_Identifier buffer_id,
char *path, int32_t path_len, char *command, i32 command_len, Command_Line_Interface_Flag flags){
return(exec_system_command(app, (view == 0)?0:view->view_id, buffer_id,
SCu8(path, path_len), SCu8(command, command_len), flags));
#if 0
b32 result = false;
String_Const_u8 path_string = SCu8((u8*)path, path_len);
String_Const_u8 command_string = SCu8((u8*)command, command_len);
Child_Process_ID child_process_id = 0;
if (create_child_process(app, path_string, command_string, &child_process_id)){
result = true;
Buffer_ID buffer_attach_id = 0;
if (buffer_id.name != 0 && buffer_id.name_len > 0){
String_Const_u8 buffer_name = SCu8((u8*)buffer_id.name, buffer_id.name_len);
if (!get_buffer_by_name(app, buffer_name, AccessAll, &buffer_attach_id)){
if (create_buffer(app, buffer_name, BufferCreate_AlwaysNew|BufferCreate_NeverAttachToFile, &buffer_attach_id)){
buffer_set_setting(app, buffer_attach_id, BufferSetting_ReadOnly, true);
buffer_set_setting(app, buffer_attach_id, BufferSetting_Unimportant, true);
}
}
}
else if (buffer_id.id != 0){
buffer_attach_id = buffer_id.id;
}
if (buffer_attach_id != 0){
Child_Process_Set_Target_Flags set_buffer_flags = 0;
if (!HasFlag(flags, CLI_OverlapWithConflict)){
set_buffer_flags |= ChildProcessSet_FailIfBufferAlreadyAttachedToAProcess;
}
if (HasFlag(flags, CLI_CursorAtEnd)){
set_buffer_flags |= ChildProcessSet_CursorAtEnd;
}
if (child_process_set_target_buffer(app, child_process_id, buffer_attach_id, set_buffer_flags)){
Buffer_Summary buffer = {};
get_buffer_summary(app, buffer_attach_id, AccessAll, &buffer);
buffer_replace_range(app, buffer_attach_id, make_range(0, buffer.size), string_u8_litexpr(""));
if (HasFlag(flags, CLI_SendEndSignal)){
buffer_send_end_signal(app, buffer_attach_id);
}
if (view != 0){
view_set_buffer(app, view->view_id, buffer_attach_id, 0);
get_view_summary(app, view->view_id, AccessAll, view);
}
}
}
}
return(result);
#endif
}
static b32
exec_system_command(Application_Links *app, View_ID view, Buffer_Identifier buffer_id,
char *path, int32_t path_len, char *command, i32 command_len, Command_Line_Interface_Flag flags){
View_Summary view_summary = {};
get_view_summary(app, view, AccessAll, &view_summary);
return(exec_system_command(app, &view_summary, buffer_id, path, path_len, command, command_len, flags));
}
static char
buffer_get_char(Application_Links *app, Buffer_Summary *buffer, i32 pos){
return(buffer==0?0:buffer_get_char(app, buffer->buffer_id, pos));
@ -45,14 +110,31 @@ get_first_token_at_line(Application_Links *app, Buffer_Summary *buffer, Cpp_Toke
}
static b32
read_line(Application_Links *app, Partition *part, Buffer_Summary *buffer, i32 line, String *str,
read_line(Application_Links *app, Arena *arena, Buffer_Summary *buffer, i32 line, String *str,
Partial_Cursor *start_out, Partial_Cursor *one_past_last_out){
return(buffer==0?0:read_line(app, part, buffer->buffer_id, line, str, start_out, one_past_last_out));
String_Const_u8 string = {};
Range_Partial_Cursor out = {};
b32 result = (buffer != 0 && is_valid_line(app, buffer->buffer_id, line));
if (result){
out = get_line_range(app, buffer->buffer_id, line);
string = scratch_read(app, arena, buffer->buffer_id, make_range_from_cursors(out));
}
*start_out = out.start;
*one_past_last_out = out.one_past_last;
*str = string_old_from_new(string);
return(result);
}
static b32
read_line(Application_Links *app, Partition *part, Buffer_Summary *buffer, i32 line, String *str){
return(buffer==0?0:read_line(app, part, buffer->buffer_id, line, str));
read_line(Application_Links *app, Arena *arena, Buffer_Summary *buffer, i32 line, String *str){
String_Const_u8 string = {};
b32 result = (buffer != 0 && is_valid_line(app, buffer->buffer_id, line));
if (result){
Range_Partial_Cursor range = get_line_range(app, buffer->buffer_id, line);
string = scratch_read(app, arena, buffer->buffer_id, make_range_from_cursors(range));
}
*str = string_old_from_new(string);
return(result);
}
@ -67,19 +149,10 @@ init_stream_tokens(Stream_Tokens_DEP *stream, Application_Links *app, Buffer_Sum
}
static String
token_get_lexeme(Application_Links *app, Buffer_Summary *buffer, Cpp_Token *token, char *out_buffer, i32 out_buffer_size){
token_get_lexeme(Application_Links *app, Arena *arena, Buffer_Summary *buffer, Cpp_Token *token){
String result = {};
if (buffer != 0){
result = token_get_lexeme(app, buffer->buffer_id, token, out_buffer, out_buffer_size);
}
return(result);
}
static String
token_get_lexeme(Application_Links *app, Partition *part, Buffer_Summary *buffer, Cpp_Token *token){
String result = {};
if (buffer != 0){
result = token_get_lexeme(app, part, buffer->buffer_id, token);
if (buffer != 0 && token != 0){
result = string_old_from_new(token_get_lexeme(app, arena, buffer->buffer_id, *token));
}
return(result);
}
@ -88,7 +161,12 @@ static String
get_token_or_word_under_pos(Application_Links *app, Buffer_Summary *buffer, i32 pos, char *space, i32 capacity){
String result = {};
if (buffer != 0){
result = get_token_or_word_under_pos(app, buffer->buffer_id, pos, space, capacity);
Scratch_Block scratch(app);
String_Const_u8 string = get_token_or_word_under_pos(app, scratch, buffer->buffer_id, pos);
i32 size = (i32)string.size;
size = clamp_top(size, capacity);
block_copy(space, string.str, size);
result = make_string_cap(space, size, capacity);
}
return(result);
}
@ -174,17 +252,17 @@ buffer_seek_alpha_numeric_end(Application_Links *app, Buffer_Summary *buffer, in
}
static Cpp_Token_Array
buffer_get_all_tokens(Application_Links *app, Partition *part, Buffer_Summary *buffer){
buffer_get_all_tokens(Application_Links *app, Arena *arena, Buffer_Summary *buffer){
Cpp_Token_Array result = {};
if (buffer != 0){
result = buffer_get_all_tokens(app, part, buffer->buffer_id);
result = buffer_get_all_tokens(app, arena, buffer->buffer_id);
}
return(result);
}
static i32
buffer_boundary_seek(Application_Links *app, Buffer_Summary *buffer, Partition *part, i32 start_pos, b32 seek_forward, Seek_Boundary_Flag flags){
return(buffer==0?0:buffer_boundary_seek(app, buffer->buffer_id, part, start_pos, seek_forward, flags));
buffer_boundary_seek(Application_Links *app, Buffer_Summary *buffer, Arena *arena, i32 start_pos, b32 seek_forward, Seek_Boundary_Flag flags){
return(buffer==0?0:buffer_boundary_seek(app, buffer->buffer_id, arena, start_pos, seek_forward, flags));
}
static void
@ -204,35 +282,35 @@ buffer_seek_delimiter_backward(Application_Links *app, Buffer_Summary *buffer, i
static void
buffer_seek_string_forward(Application_Links *app, Buffer_Summary *buffer, i32 pos, i32 end, char *str, i32 size, i32 *result){
if (buffer != 0){
buffer_seek_string_forward(app, buffer->buffer_id, pos, end, str, size, result);
buffer_seek_string_forward(app, buffer->buffer_id, pos, end, SCu8(str, size), result);
}
}
static void
buffer_seek_string_backward(Application_Links *app, Buffer_Summary *buffer, i32 pos, i32 end, char *str, i32 size, i32 *result){
if (buffer != 0){
buffer_seek_string_backward(app, buffer->buffer_id, pos, end, str, size, result);
buffer_seek_string_backward(app, buffer->buffer_id, pos, end, SCu8(str, size), result);
}
}
static void
buffer_seek_string_insensitive_forward(Application_Links *app, Buffer_Summary *buffer, i32 pos, i32 end, char *str, i32 size, i32 *result){
if (buffer != 0){
buffer_seek_string_insensitive_forward(app, buffer->buffer_id, pos, end, str, size, result);
buffer_seek_string_insensitive_forward(app, buffer->buffer_id, pos, end, SCu8(str, size), result);
}
}
static void
buffer_seek_string_insensitive_backward(Application_Links *app, Buffer_Summary *buffer, i32 pos, i32 end, char *str, i32 size, i32 *result){
if (buffer != 0){
buffer_seek_string_insensitive_backward(app, buffer->buffer_id, pos, end, str, size, result);
buffer_seek_string_insensitive_backward(app, buffer->buffer_id, pos, end, SCu8(str, size), result);
}
}
static void
buffer_seek_string(Application_Links *app, Buffer_Summary *buffer, i32 pos, i32 end, i32 min, char *str, i32 size, i32 *result, Buffer_Seek_String_Flags flags){
if (buffer != 0){
buffer_seek_string(app, buffer->buffer_id, pos, end, min, str, size, result, flags);
buffer_seek_string(app, buffer->buffer_id, pos, end, min, SCu8(str, size), result, flags);
}
}
@ -245,7 +323,12 @@ static String
read_identifier_at_pos(Application_Links *app, Buffer_Summary *buffer, i32 pos, char *space, i32 max, Range *range_out){
String result = {};
if (buffer != 0){
result = read_identifier_at_pos(app, buffer->buffer_id, pos, space, max, range_out);
Scratch_Block scratch(app);
String_Const_u8 string = read_identifier_at_pos(app, scratch, buffer->buffer_id, pos, range_out);
i32 size = (i32)string.size;
size = clamp_top(size, max);
block_copy(space, string.str, size);
result = make_string_cap(space, size, max);
}
return(result);
}
@ -277,7 +360,9 @@ view_buffer_snipe_range(Application_Links *app, View_Summary *view, Buffer_Summa
static void
query_replace_base(Application_Links *app, View_Summary *view, Buffer_Summary *buffer, i32 pos, String r, String w){
query_replace_base(app, view==0?0:view->view_id, buffer==0?0:buffer->buffer_id, pos, r, w);
query_replace_base(app, view==0?0:view->view_id, buffer==0?0:buffer->buffer_id, pos,
string_new_u8_from_old(r),
string_new_u8_from_old(w));
}
static Statement_Parser
@ -320,18 +405,18 @@ find_prev_scope(Application_Links *app, Buffer_Summary *buffer, i32 start_pos, u
}
static Range_Array
get_enclosure_ranges(Application_Links *app, Partition *part, Buffer_Summary *buffer, i32 pos, u32 flags){
get_enclosure_ranges(Application_Links *app, Arena *arena, Buffer_Summary *buffer, i32 pos, u32 flags){
Range_Array result = {};
if (buffer != 0){
result = get_enclosure_ranges(app, part, buffer->buffer_id, pos, flags);
result = get_enclosure_ranges(app, arena, buffer->buffer_id, pos, flags);
}
return(result);
}
static void
mark_enclosures(Application_Links *app, Partition *scratch, Managed_Scope render_scope, Buffer_Summary *buffer, i32 pos, u32 flags, Marker_Visual_Type type, int_color *back_colors, int_color *fore_colors, i32 color_count){
mark_enclosures(Application_Links *app, Managed_Scope render_scope, Buffer_Summary *buffer, i32 pos, u32 flags, Marker_Visual_Type type, int_color *back_colors, int_color *fore_colors, i32 color_count){
if (buffer != 0){
mark_enclosures(app, scratch, render_scope, buffer->buffer_id, pos, flags, type, back_colors, fore_colors, color_count);
mark_enclosures(app, render_scope, buffer->buffer_id, pos, flags, type, back_colors, fore_colors, color_count);
}
}
@ -345,7 +430,7 @@ buffer_find_hard_start(Application_Links *app, Buffer_Summary *buffer, i32 line_
}
static Buffer_Batch_Edit
make_batch_from_indent_marks(Application_Links *app, Partition *arena, Buffer_Summary *buffer, i32 first_line, i32 one_past_last_line, i32 *indent_marks, Indent_Options opts){
make_batch_from_indent_marks(Application_Links *app, Arena *arena, Buffer_Summary *buffer, i32 first_line, i32 one_past_last_line, i32 *indent_marks, Indent_Options opts){
Buffer_Batch_Edit result = {};
if (buffer != 0){
make_batch_from_indent_marks(app, arena, buffer->buffer_id, first_line, one_past_last_line, indent_marks, opts);
@ -354,9 +439,9 @@ make_batch_from_indent_marks(Application_Links *app, Partition *arena, Buffer_Su
}
static void
set_line_indents(Application_Links *app, Partition *part, Buffer_Summary *buffer, i32 first_line, i32 one_past_last_line, i32 *indent_marks, Indent_Options opts){
set_line_indents(Application_Links *app, Arena *arena, Buffer_Summary *buffer, i32 first_line, i32 one_past_last_line, i32 *indent_marks, Indent_Options opts){
if (buffer != 0){
set_line_indents(app, part, buffer->buffer_id, first_line, one_past_last_line, indent_marks, opts);
set_line_indents(app, arena, buffer->buffer_id, first_line, one_past_last_line, indent_marks, opts);
}
}
@ -370,7 +455,7 @@ find_anchor_token(Application_Links *app, Buffer_Summary *buffer, Cpp_Token_Arra
}
static i32*
get_indentation_marks(Application_Links *app, Partition *arena, Buffer_Summary *buffer,
get_indentation_marks(Application_Links *app, Arena *arena, Buffer_Summary *buffer,
Cpp_Token_Array tokens, i32 first_line, i32 one_past_last_line,
b32 exact_align, i32 tab_width){
return(buffer==0?0:get_indentation_marks(app, arena, buffer->buffer_id, tokens, first_line, one_past_last_line, exact_align, tab_width));
@ -396,8 +481,8 @@ get_indent_lines_whole_tokens(Application_Links *app, Buffer_Summary *buffer, Cp
}
static b32
buffer_auto_indent(Application_Links *app, Partition *part, Buffer_Summary *buffer, i32 start, i32 end, i32 tab_width, Auto_Indent_Flag flags){
return(buffer==0?0:buffer_auto_indent(app, part, buffer->buffer_id, start, end, tab_width, flags));
buffer_auto_indent(Application_Links *app, Arena *arena, Buffer_Summary *buffer, i32 start, i32 end, i32 tab_width, Auto_Indent_Flag flags){
return(buffer==0?0:buffer_auto_indent(app, arena, buffer->buffer_id, start, end, tab_width, flags));
}
static b32
@ -405,13 +490,6 @@ buffer_auto_indent(Application_Links *app, Buffer_Summary *buffer, i32 start, i3
return(buffer==0?0:buffer_auto_indent(app, buffer->buffer_id, start, end, tab_width, flags));
}
static void
print_positions_buffered(Application_Links *app, Buffer_Summary *buffer, Function_Positions *positions_array, i32 positions_count, Buffered_Write_Stream *stream){
if (buffer != 0){
print_positions_buffered(app, buffer->buffer_id, positions_array, positions_count, stream);
}
}
static Get_Positions_Results
get_function_positions(Application_Links *app, Buffer_Summary *buffer, i32 first_token_index, Function_Positions *positions_array, i32 positions_max){
Get_Positions_Results result = {};
@ -422,9 +500,9 @@ get_function_positions(Application_Links *app, Buffer_Summary *buffer, i32 first
}
static void
list_all_functions(Application_Links *app, Partition *part, Buffer_Summary *optional_target_buffer){
list_all_functions(Application_Links *app, Buffer_Summary *optional_target_buffer){
if (optional_target_buffer != 0){
list_all_functions(app, part, optional_target_buffer->buffer_id);
list_all_functions(app, optional_target_buffer->buffer_id);
}
}
@ -440,14 +518,14 @@ c_line_comment_starts_at_position(Application_Links *app, Buffer_Summary *buffer
static void
write_string(Application_Links *app, View_Summary *view, Buffer_Summary *buffer, String string){
write_string(app, view==0?0:view->view_id, buffer==0?0:buffer->buffer_id, string);
write_string(app, view==0?0:view->view_id, buffer==0?0:buffer->buffer_id, string_new_u8_from_old(string));
}
static b32
open_file(Application_Links *app, Buffer_Summary *buffer_out, char *filename, i32 filename_len, b32 background, b32 never_new){
b32 result = false;
Buffer_ID id_out = 0;
result = open_file(app, &id_out, filename, filename_len, background, never_new);
result = open_file(app, &id_out, SCu8(filename, filename_len), background, never_new);
if (result && buffer_out != 0){
get_buffer_summary(app, id_out, AccessAll, buffer_out);
}
@ -541,7 +619,7 @@ refresh_buffer(Application_Links *app, Buffer_Summary *buffer){
}
static Sticky_Jump_Array
parse_buffer_to_jump_array(Application_Links *app, Partition *arena, Buffer_Summary buffer){
parse_buffer_to_jump_array(Application_Links *app, Arena *arena, Buffer_Summary buffer){
return(parse_buffer_to_jump_array(app, arena, buffer.buffer_id));
}
@ -562,33 +640,18 @@ get_buffer_face_description(Application_Links *app, Buffer_Summary *buffer){
static void
set_buffer_face_by_name(Application_Links *app, Buffer_Summary *buffer, char *name, i32 len){
if (buffer != 0){
set_buffer_face_by_name(app, buffer->buffer_id, name, len);
set_buffer_face_by_name(app, buffer->buffer_id, SCu8(name, len));
}
}
static i32
get_build_directory(Application_Links *app, Buffer_Summary *buffer, String *dir_out){
return(get_build_directory(app, buffer==0?0:buffer->buffer_id, dir_out));
}
static i32
standard_build_search(Application_Links *app, View_Summary *view, String *dir, String *command, b32 perform_backup, b32 use_path_in_command, String filename, String command_name){
return(standard_build_search(app, view==0?0:view->view_id, dir, command, perform_backup, use_path_in_command, filename, command_name));
}
static i32
execute_standard_build_search(Application_Links *app, View_Summary *view, String *dir, String *command, i32 perform_backup){
return(execute_standard_build_search(app, view==0?0:view->view_id, dir, command, perform_backup));
}
static void
execute_standard_build(Application_Links *app, View_Summary *view, Buffer_ID active_buffer){
execute_standard_build(app, view==0?0:view->view_id, active_buffer);
standard_search_and_build(app, view==0?0:view->view_id, active_buffer);
}
static b32
post_buffer_range_to_clipboard(Application_Links *app, Partition *scratch, i32 clipboard_index, Buffer_Summary *buffer, i32 first, i32 one_past_last){
return(post_buffer_range_to_clipboard(app, scratch, clipboard_index, buffer==0?0:buffer->buffer_id, first, one_past_last));
post_buffer_range_to_clipboard(Application_Links *app, i32 clipboard_index, Buffer_Summary *buffer, i32 first, i32 one_past_last){
return(post_buffer_range_to_clipboard(app, clipboard_index, buffer==0?0:buffer->buffer_id, first, one_past_last));
}
static void
@ -597,13 +660,13 @@ view_set_vertical_focus(Application_Links *app, View_Summary *view, i32 y_top, i
}
static b32
advance_cursor_in_jump_view(Application_Links *app, Partition *part, View_Summary *view, i32 skip_repeats, i32 skip_sub_error, i32 direction, Name_Line_Column_Location *location_out){
return(advance_cursor_in_jump_view(app, part, view==0?0:view->view_id, skip_repeats, skip_sub_error, direction, location_out));
advance_cursor_in_jump_view(Application_Links *app, View_Summary *view, i32 skip_repeats, i32 skip_sub_error, i32 direction, Name_Line_Column_Location *location_out){
return(advance_cursor_in_jump_view(app, view==0?0:view->view_id, skip_repeats, skip_sub_error, direction, location_out));
}
static Parsed_Jump
seek_next_jump_in_view(Application_Links *app, Partition *part, View_Summary *view, i32 skip_sub_errors, i32 direction, i32 *line_out){
return(seek_next_jump_in_view(app, part, view==0?0:view->view_id, skip_sub_errors, direction, line_out));
seek_next_jump_in_view(Application_Links *app, Arena *arena, View_Summary *view, i32 skip_sub_errors, i32 direction, i32 *line_out){
return(seek_next_jump_in_view(app, arena, view==0?0:view->view_id, skip_sub_errors, direction, line_out));
}
static void
@ -617,18 +680,8 @@ goto_jump_in_order(Application_Links *app, Marker_List *list, View_Summary *jump
}
static void
open_jump_lister(Application_Links *app, Partition *scratch, Heap *heap, View_Summary *ui_view, Buffer_ID list_buffer_id, Jump_Lister_Activation_Rule activation_rule, View_Summary *optional_target_view){
open_jump_lister(app, scratch, heap, ui_view==0?0:ui_view->view_id, list_buffer_id, activation_rule, optional_target_view==0?0:optional_target_view->view_id);
}
static void
activate_project_command(Application_Links *app, Partition *scratch, Heap *heap, View_Summary *view, Lister_State *state, String text_field, void *user_data, b32 activated_by_mouse){
activate_project_command(app, scratch, heap, view==0?0:view->view_id, state, text_field, user_data, activated_by_mouse);
}
static void
activate_snippet(Application_Links *app, Partition *scratch, Heap *heap, View_Summary *view, struct Lister_State *state, String text_field, void *user_data, b32 activated_by_mouse){
activate_snippet(app, scratch, heap, view==0?0:view->view_id, state, text_field, user_data, activated_by_mouse);
open_jump_lister(Application_Links *app, Heap *heap, View_Summary *ui_view, Buffer_ID list_buffer_id, Jump_Lister_Activation_Rule activation_rule, View_Summary *optional_target_view){
open_jump_lister(app, heap, ui_view==0?0:ui_view->view_id, list_buffer_id, activation_rule, optional_target_view==0?0:optional_target_view->view_id);
}
static void
@ -643,7 +696,7 @@ character_pos_to_pos(Application_Links *app, View_Summary *view, i32 character_p
static b32
view_open_file(Application_Links *app, View_Summary *view, char *filename, i32 filename_len, b32 never_new){
return(view_open_file(app, view==0?0:view->view_id, filename, filename_len, never_new));
return(view_open_file(app, view==0?0:view->view_id, SCu8(filename, filename_len), never_new));
}
static f32
@ -681,8 +734,8 @@ refresh_view(Application_Links *app, View_Summary *view){
}
static String
get_string_in_view_range(Application_Links *app, Partition *arena, View_Summary *view){
return(get_string_in_view_range(app, arena, view==0?0:view->view_id));
get_string_in_view_range(Application_Links *app, Arena *arena, View_Summary *view){
return(string_old_from_new(get_string_in_view_range(app, arena, view==0?0:view->view_id)));
}
static b32
@ -748,28 +801,160 @@ get_prev_view_looped_primary_panels(Application_Links *app, View_Summary *view_s
}
static void
list__parameters(Application_Links *app, Heap *heap, Partition *scratch, String *strings, i32 count, Search_Range_Flag match_flags, View_Summary default_target_view){
list__parameters(app, heap, scratch, strings, count, match_flags, default_target_view.view_id);
list__parameters(Application_Links *app, Heap *heap, String_Const_u8 *strings, i32 count, Search_Range_Flag match_flags, View_Summary default_target_view){
list__parameters(app, heap, strings, count, match_flags, default_target_view.view_id);
}
static void
list_query__parameters(Application_Links *app, Heap *heap, Partition *scratch, b32 substrings, b32 case_insensitive, View_Summary default_target_view){
list_query__parameters(app, heap, scratch, substrings, case_insensitive, default_target_view.view_id);
list_query__parameters(Application_Links *app, Heap *heap, b32 substrings, b32 case_insensitive, View_Summary default_target_view){
list_query__parameters(app, heap, substrings, case_insensitive, default_target_view.view_id);
}
static Buffer_ID
create_or_switch_to_buffer_by_name(Application_Links *app, char *name, i32 name_length, View_Summary default_target_view){
return(create_or_switch_to_buffer_by_name(app, make_string(name, name_length), default_target_view.view_id));
return(create_or_switch_to_buffer_and_clear_by_name(app, SCu8(name, name_length), default_target_view.view_id));
}
static void
list_identifier__parameters(Application_Links *app, Heap *heap, Partition *scratch, b32 substrings, b32 case_insensitive, View_Summary default_target_view){
list_identifier__parameters(app, heap, scratch, substrings, case_insensitive, default_target_view.view_id);
list_identifier__parameters(Application_Links *app, Heap *heap, b32 substrings, b32 case_insensitive, View_Summary default_target_view){
list_identifier__parameters(app, heap, substrings, case_insensitive, default_target_view.view_id);
}
static void
list_type_definition__parameters(Application_Links *app, Heap *heap, Partition *scratch, String str, View_Summary default_target_view){
list_type_definition__parameters(app, heap, scratch, str, default_target_view.view_id);
list_type_definition__parameters(Application_Links *app, Heap *heap, String str, View_Summary default_target_view){
list_type_definition__parameters(app, heap, string_new_u8_from_old(str), default_target_view.view_id);
}
static b32
backspace_utf8(String *str){
b32 result = false;
uint8_t *s = (uint8_t*)str->str;
if (str->size > 0){
u32 i = str->size-1;
for (; i > 0; --i){
if (s[i] <= 0x7F || s[i] >= 0xC0){
break;
}
}
str->size = i;
result = true;
}
return(result);
}
static void
change_mapping(Application_Links *app, String mapping){
change_mapping(app, string_new_u8_from_old(mapping));
}
static void
query_replace_parameter(Application_Links *app, String replace_str, i32 start_pos, b32 add_replace_query_bar){
query_replace_parameter(app, SCu8(string_new_from_old(replace_str)), start_pos, add_replace_query_bar);
}
static String
hot_directory_push(Application_Links *app, Arena *arena){
return(string_old_from_new(push_hot_directory(app, arena)));
}
static void
append_int_to_str_left_pad(String *str, i32 x, i32 minimum_width, char pad_char){
i32 length = int_to_str_size(x);
i32 left_over = minimum_width - length;
if (left_over > 0){
append_padding(str, pad_char, str->size + left_over);
}
append_int_to_str(str, x);
}
static void
condense_whitespace(String *a){
*a = skip_chop_whitespace(*a);
int size = a->size;
a->size = 0;
int i = 0;
for (;i < size;){
if (char_is_whitespace(a->str[i])){
a->str[a->size++] = ' ';
for (;(i < size) && char_is_whitespace(a->str[i]);){
++i;
}
}
else{
a->str[a->size++] = a->str[i++];
}
}
}
static Face_ID
get_existing_face_id_matching_name(Application_Links *app, char *name, i32 len){
return(get_existing_face_id_matching_name(app, SCu8(name, len)));
}
static Face_ID
get_face_id_by_name(Application_Links *app, char *name, i32 len, Face_Description *base_description){
return(get_face_id_by_name(app, SCu8(name, len), base_description));
}
static void
set_global_face_by_name(Application_Links *app, char *name, i32 len, b32 apply_to_all_buffers){
set_global_face_by_name(app, SCu8(name, len), apply_to_all_buffers);
}
static void
insert_string__no_buffering(Buffer_Insertion *insertion, String string){
insert_string__no_buffering(insertion, string_new_u8_from_old(string));
}
static void
insert_string(Buffer_Insertion *insertion, String string){
insert_string(insertion, string_new_u8_from_old(string));
}
static void
save_all_dirty_buffers_with_postfix(Application_Links *app, String postfix){
save_all_dirty_buffers_with_postfix(app, string_new_u8_from_old(postfix));
}
static void
delete_file_base(Application_Links *app, String file_name, Buffer_ID buffer_id){
delete_file_base(app, string_new_u8_from_old(file_name), buffer_id);
}
static b32
ms_style_verify(String line, i32 left_paren_pos, i32 right_paren_pos){
return(ms_style_verify(string_new_u8_from_old(line), left_paren_pos, right_paren_pos));
}
static i32
try_skip_rust_arrow(String line){
return((i32)(try_skip_rust_arrow(string_new_u8_from_old(line))));
}
static b32
check_is_note(String line, i32 colon_pos){
return(check_is_note(string_new_u8_from_old(line), colon_pos));
}
static void
close_all_files_with_extension(Application_Links *app, CString_Array extension_array){
Scratch_Block scratch(app);
String_Const_u8_Array array = {};
array.count = extension_array.count;
array.strings = push_array(scratch, String_Const_u8, array.count);
for (i32 i = 0; i < array.count; i += 1){
array.strings[i] = SCu8(extension_array.strings[i]);
}
close_all_files_with_extension(app, array);
}
static void
open_all_files_in_directory_pattern_match(Application_Links *app,
String dir,
Project_File_Pattern_Array whitelist,
Project_File_Pattern_Array blacklist,
u32 flags){
open_all_files_in_directory_pattern_match(app, string_new_u8_from_old(dir), whitelist, blacklist, flags);
}
#endif

View File

@ -0,0 +1,54 @@
/*
* 4coder app links base allocator
*/
// TOP
internal void
scratch_block__init(Scratch_Block *block, Arena *arena){
block->temp = begin_temp(arena);
}
Scratch_Block::Scratch_Block(Temp_Memory t){
this->temp = t;
}
Scratch_Block::Scratch_Block(Arena *arena){
scratch_block__init(this, arena);
}
Scratch_Block::Scratch_Block(Application_Links *app){
scratch_block__init(this, context_get_arena(app));
}
Scratch_Block::~Scratch_Block(){
end_temp(this->temp);
}
Scratch_Block::operator Arena*(){
return(this->temp.temp_memory_arena.arena);
}
void Scratch_Block::restore(void){
end_temp(this->temp);
}
////////////////////////////////
internal Arena
make_arena_app_links(Application_Links *app, umem chunk_size, umem align){
return(make_arena(context_get_base_allocator(app), chunk_size, align));
}
internal Arena
make_arena_app_links(Application_Links *app, umem chunk_size){
return(make_arena_app_links(app, chunk_size, 8));
}
internal Arena
make_arena_app_links(Application_Links *app){
return(make_arena_app_links(app, KB(16), 8));
}
// BOTTOM

View File

@ -49,9 +49,8 @@ buffer_find_hard_start(Application_Links *app, Buffer_ID buffer, i32 line_start,
return(result);
}
// TODO(allen): rewrite with arena and linked list batch.
static Buffer_Batch_Edit
make_batch_from_indent_marks(Application_Links *app, Partition *arena, Buffer_ID buffer,
make_batch_from_indent_marks(Application_Links *app, Arena *arena, Buffer_ID buffer,
i32 first_line, i32 one_past_last_line, i32 *indent_marks,
Indent_Options opts){
i32 *shifted_indent_marks = indent_marks - first_line;
@ -60,7 +59,7 @@ make_batch_from_indent_marks(Application_Links *app, Partition *arena, Buffer_ID
i32 edit_max = one_past_last_line - first_line;
Buffer_Edit *edits = push_array(arena, Buffer_Edit, edit_max);
char *str_base = push_array(arena, char, 0);
List_String_Const_u8 list = {};
for (i32 line_number = first_line;
line_number < one_past_last_line;
@ -77,51 +76,49 @@ make_batch_from_indent_marks(Application_Links *app, Partition *arena, Buffer_ID
}
if (correct_indentation != hard_start.indent_pos){
i32 str_size = correct_indentation;
umem str_size = 0;
char *str = 0;
if (opts.use_tabs){
str_size = correct_indentation/opts.tab_width + correct_indentation%opts.tab_width;
}
char *str = push_array(arena, char, str_size);
if (opts.use_tabs){
i32 indent = 0;
i32 j = 0;
for (;indent + opts.tab_width <= correct_indentation;
indent += opts.tab_width){
str[j++] = '\t';
}
for (;indent < correct_indentation;
indent += 1){
str[j++] = ' ';
}
i32 tab_count = correct_indentation/opts.tab_width;
i32 indent = tab_count*opts.tab_width;
i32 space_count = correct_indentation - indent;
str_size = tab_count + space_count;
str = push_array(arena, char, str_size);
block_fill_u8(str, tab_count, '\t');
block_fill_u8(str + tab_count, space_count, ' ');
}
else{
for (i32 j = 0; j < correct_indentation;){
str[j++] = ' ';
}
str_size = correct_indentation;
str = push_array(arena, char, str_size);
block_fill_u8(str, str_size, ' ');
}
Buffer_Edit new_edit = {};
new_edit.str_start = (i32)(str - str_base);
new_edit.len = str_size;
new_edit.start = line_start_pos;
new_edit.end = hard_start.char_pos;
edits[edit_count++] = new_edit;
umem str_position = list.total_size;
string_list_push(arena, &list, SCu8(str, str_size));
edits[edit_count].str_start = (i32)str_position;
edits[edit_count].len = (i32)str_size;
edits[edit_count].start = line_start_pos;
edits[edit_count].end = hard_start.char_pos;
edit_count += 1;
}
Assert(edit_count <= edit_max);
}
String_Const_u8 contiguous_text = string_list_flatten(arena, list);
Buffer_Batch_Edit result = {};
result.str = str_base;
result.str_len = (i32)(push_array(arena, char, 0) - str_base);
result.str = (char*)contiguous_text.str;
result.str_len = (i32)contiguous_text.size;
result.edits = edits;
result.edit_count = edit_count;
return(result);
}
static void
set_line_indents(Application_Links *app, Partition *part, Buffer_ID buffer, i32 first_line, i32 one_past_last_line, i32 *indent_marks, Indent_Options opts){
Buffer_Batch_Edit batch = make_batch_from_indent_marks(app, part, buffer, first_line, one_past_last_line, indent_marks, opts);
set_line_indents(Application_Links *app, Arena *arena, Buffer_ID buffer, i32 first_line, i32 one_past_last_line, i32 *indent_marks, Indent_Options opts){
Buffer_Batch_Edit batch = make_batch_from_indent_marks(app, arena, buffer, first_line, one_past_last_line, indent_marks, opts);
if (batch.edit_count > 0){
buffer_batch_edit(app, buffer, batch.str, batch.edits, batch.edit_count);
}
@ -232,7 +229,7 @@ find_anchor_token(Application_Links *app, Buffer_ID buffer, Cpp_Token_Array toke
}
static i32*
get_indentation_marks(Application_Links *app, Partition *arena, Buffer_ID buffer,
get_indentation_marks(Application_Links *app, Arena *arena, Buffer_ID buffer,
Cpp_Token_Array tokens, i32 first_line, i32 one_past_last_line,
b32 exact_align, i32 tab_width){
i32 indent_mark_count = one_past_last_line - first_line;
@ -549,18 +546,18 @@ get_indent_lines_whole_tokens(Application_Links *app, Buffer_ID buffer, Cpp_Toke
}
static b32
buffer_auto_indent(Application_Links *app, Partition *part, Buffer_ID buffer, i32 start, i32 end, i32 tab_width, Auto_Indent_Flag flags){
buffer_auto_indent(Application_Links *app, Arena *scratch, Buffer_ID buffer, i32 start, i32 end, i32 tab_width, Auto_Indent_Flag flags){
b32 result = false;
if (buffer_exists(app, buffer) && buffer_tokens_are_ready(app, buffer)){
result = true;
Temp_Memory temp = begin_temp_memory(part);
Temp_Memory temp = begin_temp(scratch);
// Stage 1: Read the tokens to be used for indentation.
Cpp_Token_Array tokens = {};
buffer_token_count(app, buffer, &tokens.count);
tokens.max_count = tokens.count;
tokens.tokens = push_array(part, Cpp_Token, tokens.count);
tokens.tokens = push_array(scratch, Cpp_Token, tokens.count);
buffer_read_tokens(app, buffer, 0, tokens.count, tokens.tokens);
// Stage 2: Decide where the first and last lines are.
@ -576,7 +573,7 @@ buffer_auto_indent(Application_Links *app, Partition *part, Buffer_ID buffer, i3
// Stage 3: Decide Indent Amounts
// Get an array representing how much each line in
// the range [line_start,line_end) should be indented.
i32 *indent_marks = get_indentation_marks(app, part, buffer, tokens, line_start, line_end, (flags & AutoIndent_ExactAlignBlock), tab_width);
i32 *indent_marks = get_indentation_marks(app, scratch, buffer, tokens, line_start, line_end, (flags & AutoIndent_ExactAlignBlock), tab_width);
// Stage 4: Set the Line Indents
Indent_Options opts = {};
@ -584,9 +581,9 @@ buffer_auto_indent(Application_Links *app, Partition *part, Buffer_ID buffer, i3
opts.use_tabs = (flags & AutoIndent_UseTab);
opts.tab_width = tab_width;
set_line_indents(app, part, buffer, line_start, line_end, indent_marks, opts);
set_line_indents(app, scratch, buffer, line_start, line_end, indent_marks, opts);
end_temp_memory(temp);
end_temp(temp);
}
return(result);
@ -594,7 +591,8 @@ buffer_auto_indent(Application_Links *app, Partition *part, Buffer_ID buffer, i3
static b32
buffer_auto_indent(Application_Links *app, Buffer_ID buffer, i32 start, i32 end, i32 tab_width, Auto_Indent_Flag flags){
return(buffer_auto_indent(app, &global_part, buffer, start, end, tab_width, flags));
Arena *scratch = context_get_arena(app);
return(buffer_auto_indent(app, scratch, buffer, start, end, tab_width, flags));
}
//
@ -618,7 +616,8 @@ CUSTOM_DOC("Audo-indents the entire current buffer.")
view_get_buffer(app, view, AccessOpen, &buffer);
i32 buffer_size = 0;
buffer_get_size(app, buffer, &buffer_size);
buffer_auto_indent(app, &global_part, buffer, 0, buffer_size, DEF_TAB_WIDTH, DEFAULT_INDENT_FLAGS | AutoIndent_FullTokens);
Arena *scratch = context_get_arena(app);
buffer_auto_indent(app, scratch, buffer, 0, buffer_size, DEF_TAB_WIDTH, DEFAULT_INDENT_FLAGS | AutoIndent_FullTokens);
}
CUSTOM_COMMAND_SIG(auto_tab_line_at_cursor)
@ -630,7 +629,8 @@ CUSTOM_DOC("Auto-indents the line on which the cursor sits.")
view_get_buffer(app, view, AccessOpen, &buffer);
i32 pos = 0;
view_get_cursor_pos(app, view, &pos);
buffer_auto_indent(app, &global_part, buffer, pos, pos, DEF_TAB_WIDTH, DEFAULT_INDENT_FLAGS | AutoIndent_FullTokens);
Arena *scratch = context_get_arena(app);
buffer_auto_indent(app, scratch, buffer, pos, pos, DEF_TAB_WIDTH, DEFAULT_INDENT_FLAGS | AutoIndent_FullTokens);
move_past_lead_whitespace(app, view, buffer);
}
@ -642,7 +642,8 @@ CUSTOM_DOC("Auto-indents the range between the cursor and the mark.")
Buffer_ID buffer = 0;
view_get_buffer(app, view, AccessOpen, &buffer);
Range range = get_view_range(app, view);
buffer_auto_indent(app, &global_part, buffer, range.min, range.max, DEF_TAB_WIDTH, DEFAULT_INDENT_FLAGS | AutoIndent_FullTokens);
Arena *scratch = context_get_arena(app);
buffer_auto_indent(app, scratch, buffer, range.min, range.max, DEF_TAB_WIDTH, DEFAULT_INDENT_FLAGS | AutoIndent_FullTokens);
move_past_lead_whitespace(app, view, buffer);
}
@ -661,7 +662,8 @@ CUSTOM_DOC("Inserts a character and auto-indents the line on which the cursor si
}
i32 pos = 0;
view_get_cursor_pos(app, view, &pos);
buffer_auto_indent(app, &global_part, buffer, pos, pos, DEF_TAB_WIDTH, flags);
Arena *scratch = context_get_arena(app);
buffer_auto_indent(app, scratch, buffer, pos, pos, DEF_TAB_WIDTH, flags);
move_past_lead_whitespace(app, view, buffer);
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -4,142 +4,124 @@
// TOP
// NOTE(allen|a4.0.9): This is provided to establish a default method of getting
// a "build directory". This function tries to setup the build directory in the
// directory of the given buffer, if it cannot get that information it get's the
// 4coder hot directory.
//
// There is no requirement that a custom build system in 4coder actually use the
// directory given by this function.
static i32
get_build_directory(Application_Links *app, Buffer_ID buffer, String *dir_out){
Arena *scratch = context_get_arena(app);
Temp_Memory_Arena temp = begin_temp_memory(scratch);
i32 result = BuildDir_None;
if (buffer != 0){
String file_name = buffer_push_file_name(app, buffer, scratch);
String base_name = buffer_push_base_buffer_name(app, buffer, scratch);
if (!match(file_name, base_name)){
remove_last_folder(&file_name);
append(dir_out, file_name);
result = BuildDir_AtFile;
}
}
if (result == BuildDir_None){
if (get_hot_directory(app, dir_out, 0)){
result = BuildDir_AtHot;
}
}
end_temp_memory(temp);
return(result);
}
// TODO(allen): Better names for the "standard build search" family.
static i32
standard_build_search(Application_Links *app, View_ID view, String *dir, String *command, b32 perform_backup, b32 use_path_in_command, String filename, String command_name){
i32 result = false;
for(;;){
i32 old_size = dir->size;
append_ss(dir, filename);
if (file_exists(app, dir->str, dir->size)){
dir->size = old_size;
if (use_path_in_command){
append(command, '"');
append(command, *dir);
append(command, command_name);
append(command, '"');
}
else{
append_ss(command, command_name);
}
char space[512];
String message = make_fixed_width_string(space);
append_ss(&message, make_lit_string("Building with: "));
append_ss(&message, *command);
append_s_char(&message, '\n');
print_message(app, message.str, message.size);
if (global_config.automatically_save_changes_on_build){
save_all_dirty_buffers(app);
}
exec_system_command(app, view, buffer_identifier(literal("*compilation*")), dir->str, dir->size, command->str, command->size, CLI_OverlapWithConflict|CLI_SendEndSignal);
result = true;
break;
}
dir->size = old_size;
if (directory_cd(app, dir->str, &dir->size, dir->memory_size, literal("..")) == 0){
if (perform_backup){
dir->size = directory_get_hot(app, dir->str, dir->memory_size);
char backup_space[256];
String backup_command = make_fixed_width_string(backup_space);
append_ss(&backup_command, make_lit_string("echo could not find "));
append_ss(&backup_command, filename);
exec_system_command(app, view, buffer_identifier(literal("*compilation*")), dir->str, dir->size, backup_command.str, backup_command.size, CLI_OverlapWithConflict|CLI_SendEndSignal);
}
break;
}
}
return(result);
}
#if defined(IS_WINDOWS)
// NOTE(allen): Build search rule for windows.
static i32
execute_standard_build_search(Application_Links *app, View_ID view, String *dir, String *command, i32 perform_backup){
i32 result = standard_build_search(app, view, dir, command, perform_backup, true, make_lit_string("build.bat"), make_lit_string("build"));
return(result);
}
#elif defined(IS_LINUX) || defined(IS_MAC)
// NOTE(allen): Build search rule for linux and mac.
static i32
execute_standard_build_search(Application_Links *app, View_ID view, String *dir, String *command, b32 perform_backup){
char dir_space[512];
String dir_copy = make_fixed_width_string(dir_space);
copy(&dir_copy, *dir);
i32 result = standard_build_search(app, view, dir, command, 0, 1, make_lit_string("build.sh"), make_lit_string("build.sh"));
if (!result){
result = standard_build_search(app, view, &dir_copy, command, perform_backup, 0, make_lit_string("Makefile"), make_lit_string("make"));
static String_Const_u8
push_build_directory_at_file(Application_Links *app, Arena *arena, Buffer_ID buffer){
String_Const_u8 result = {};
String_Const_u8 file_name = buffer_push_file_name(app, buffer, arena);
Temp_Memory restore_point = begin_temp(arena);
String_Const_u8 base_name = buffer_push_base_buffer_name(app, buffer, arena);
b32 is_match = string_match(file_name, base_name);
end_temp(restore_point);
if (!is_match){
result = string_copy(arena, string_remove_last_folder(file_name));
}
return(result);
}
#if OS_WINDOWS
global String_Const_u8 standard_build_file_name_array[] = {
string_u8_litinit("build.bat"),
};
global String_Const_u8 standard_build_cmd_string_array[] = {
string_u8_litinit("build"),
};
#elif OS_LINUX || OS_MAC
global String_Const_u8 standard_build_file_name_array[] = {
string_u8_litinit("build.sh"),
string_u8_litinit("Makefile"),
};
global String_Const_u8 standard_build_cmd_string_array[] = {
string_u8_litinit("build.sh"),
string_u8_litinit("make"),
};
#else
# error No build search rule for this platform.
#error OS needs standard search and build rules
#endif
static String_Const_u8
push_fallback_command(Arena *arena, String_Const_u8 file_name){
return(string_u8_pushf(arena, "echo could not find %.*s", string_expand(file_name)));
}
static String_Const_u8
push_fallback_command(Arena *arena){
return(push_fallback_command(arena, standard_build_file_name_array[0]));
}
global_const Buffer_Identifier standard_build_build_buffer_identifier = buffer_identifier(string_u8_litexpr("*compilation*"));
global_const u32 standard_build_exec_flags = CLI_OverlapWithConflict|CLI_SendEndSignal;
static void
standard_build_exec_command(Application_Links *app, View_ID view, String_Const_u8 dir, String_Const_u8 cmd){
exec_system_command(app, view, standard_build_build_buffer_identifier,
dir, cmd,
standard_build_exec_flags);
}
static b32
standard_search_and_build_from_dir(Application_Links *app, View_ID view, String_Const_u8 start_dir){
Scratch_Block scratch(app);
// NOTE(allen): Search
String_Const_u8 full_file_path = {};
String_Const_u8 cmd_string = {};
for (i32 i = 0; i < ArrayCount(standard_build_file_name_array); i += 1){
full_file_path = push_file_search_up_path(app, scratch, start_dir, standard_build_file_name_array[i]);
if (full_file_path.size > 0){
cmd_string = standard_build_cmd_string_array[i];
break;
}
}
b32 result = (full_file_path.size > 0);
if (result){
// NOTE(allen): Build
String_Const_u8 path = string_remove_last_folder(full_file_path);
#if OS_WINDOWS
String_Const_u8 command = string_u8_pushf(scratch, "%.*s/%.*s",
string_expand(path),
string_expand(cmd_string));
#elif OS_LINUX || OS_MAC
String_Const_u8 command = cmd_string;
#else
#error OS needs standard search and build rules
#endif
if (global_config.automatically_save_changes_on_build){
save_all_dirty_buffers(app);
}
standard_build_exec_command(app, view, path, command);
print_message(app, string_u8_pushf(scratch, "Building with: %.*s\n",
string_expand(full_file_path)));
}
return(result);
}
// NOTE(allen): This searches first using the active file's directory,
// then if no build script is found, it searches from 4coders hot directory.
static void
execute_standard_build(Application_Links *app, View_ID view, Buffer_ID active_buffer){
char dir_space[512];
String dir = make_fixed_width_string(dir_space);
char command_str_space[512];
String command = make_fixed_width_string(command_str_space);
i32 build_dir_type = get_build_directory(app, active_buffer, &dir);
if (build_dir_type == BuildDir_AtFile){
if (!execute_standard_build_search(app, view, &dir, &command, false)){
dir.size = 0;
command.size = 0;
build_dir_type = get_build_directory(app, 0, &dir);
standard_search_and_build(Application_Links *app, View_ID view, Buffer_ID active_buffer){
Scratch_Block scratch(app);
b32 did_build = false;
String_Const_u8 build_dir = push_build_directory_at_file(app, scratch, active_buffer);
if (build_dir.size > 0){
did_build = standard_search_and_build_from_dir(app, view, build_dir);
}
if (!did_build){
build_dir = push_hot_directory(app, scratch);
if (build_dir.size > 0){
did_build = standard_search_and_build_from_dir(app, view, build_dir);
}
}
if (build_dir_type == BuildDir_AtHot){
execute_standard_build_search(app, view, &dir, &command, true);
if (!did_build){
standard_build_exec_command(app, view,
push_hot_directory(app, scratch),
push_fallback_command(scratch));
}
}
@ -150,18 +132,21 @@ CUSTOM_DOC("Looks for a build.bat, build.sh, or makefile in the current and pare
get_active_view(app, AccessAll, &view);
Buffer_ID buffer = 0;
view_get_buffer(app, view, AccessAll, &buffer);
execute_standard_build(app, view, buffer);
standard_search_and_build(app, view, buffer);
memset(&prev_location, 0, sizeof(prev_location));
lock_jump_buffer(make_lit_string("*compilation*"));
lock_jump_buffer(string_u8_litexpr("*compilation*"));
}
#define GET_COMP_BUFFER(app,id) get_buffer_by_name(app, make_lit_string("*compilation*"), AccessAll, (id))
static b32
get_comp_buffer(Application_Links *app, Buffer_ID *id_out){
return(get_buffer_by_name(app, string_u8_litexpr("*compilation*"), AccessAll, id_out));
}
static View_ID
get_or_open_build_panel(Application_Links *app){
View_ID view = 0;
Buffer_ID buffer = 0;
GET_COMP_BUFFER(app, &buffer);
get_comp_buffer(app, &buffer);
if (buffer != 0){
view = get_first_view_with_buffer(app, buffer);
}
@ -174,8 +159,8 @@ get_or_open_build_panel(Application_Links *app){
static void
set_fancy_compilation_buffer_font(Application_Links *app){
Buffer_ID buffer = 0;
GET_COMP_BUFFER(app, &buffer);
set_buffer_face_by_name(app, buffer, literal("Inconsolata"));
get_comp_buffer(app, &buffer);
set_buffer_face_by_name(app, buffer, string_u8_litexpr("Inconsolata"));
}
CUSTOM_COMMAND_SIG(build_in_build_panel)
@ -188,11 +173,11 @@ CUSTOM_DOC("Looks for a build.bat, build.sh, or makefile in the current and pare
View_ID build_view = get_or_open_build_panel(app);
execute_standard_build(app, build_view, buffer);
standard_search_and_build(app, build_view, buffer);
set_fancy_compilation_buffer_font(app);
memset(&prev_location, 0, sizeof(prev_location));
lock_jump_buffer(make_lit_string("*compilation*"));
lock_jump_buffer(string_u8_litexpr("*compilation*"));
}
CUSTOM_COMMAND_SIG(close_build_panel)

View File

@ -7,12 +7,6 @@
#if !defined(FCODER_BUILD_COMMANDS_H)
#define FCODER_BUILD_COMMANDS_H
enum Get_Build_Directory_Result{
BuildDir_None,
BuildDir_AtFile,
BuildDir_AtHot
};
#endif
// BOTTOM

View File

@ -5,20 +5,18 @@
// TOP
static b32
post_buffer_range_to_clipboard(Application_Links *app, Partition *scratch, i32 clipboard_index, Buffer_ID buffer, i32 first, i32 one_past_last){
post_buffer_range_to_clipboard(Application_Links *app, i32 clipboard_index, Buffer_ID buffer, i32 first, i32 one_past_last){
b32 success = false;
i32 buffer_size = 0;
buffer_get_size(app, buffer, &buffer_size);
if (buffer != 0 && 0 <= first && first < one_past_last && one_past_last <= buffer_size){
Temp_Memory temp = begin_temp_memory(scratch);
i32 size = one_past_last - first;
char *str = push_array(scratch, char, size);
if (str != 0){
buffer_read_range(app, buffer, first, one_past_last, str);
clipboard_post(app, clipboard_index, str, size);
Scratch_Block scratch(app);
Range range = make_range(first, one_past_last);
String_Const_u8 string = scratch_read(app, scratch, buffer, range);
if (string.size > 0){
clipboard_post(app, clipboard_index, string);
success = true;
}
end_temp_memory(temp);
}
return(success);
}
@ -31,7 +29,7 @@ CUSTOM_DOC("Copy the text in the range from the cursor to the mark onto the clip
Buffer_ID buffer = 0;
view_get_buffer(app, view, AccessProtected, &buffer);
Range range = get_view_range(app, view);
post_buffer_range_to_clipboard(app, &global_part, 0, buffer, range.min, range.max);
post_buffer_range_to_clipboard(app, 0, buffer, range.min, range.max);
}
CUSTOM_COMMAND_SIG(cut)
@ -42,48 +40,46 @@ CUSTOM_DOC("Cut the text in the range from the cursor to the mark onto the clipb
Buffer_ID buffer = 0;
view_get_buffer(app, view, AccessOpen, &buffer);
Range range = get_view_range(app, view);
if (post_buffer_range_to_clipboard(app, &global_part, 0, buffer, range.min, range.max)){
buffer_replace_range(app, buffer, range, make_lit_string(""));
if (post_buffer_range_to_clipboard(app, 0, buffer, range.min, range.max)){
buffer_replace_range(app, buffer, range, string_u8_litexpr(""));
}
}
CUSTOM_COMMAND_SIG(paste)
CUSTOM_DOC("At the cursor, insert the text at the top of the clipboard.")
{
i32 count = clipboard_count(app, 0);
i32 count = 0;
clipboard_count(app, 0, &count);
if (count > 0){
View_ID view = 0;
get_active_view(app, AccessOpen, &view);
if_view_has_highlighted_range_delete_range(app, view);
Managed_Scope scope = view_get_managed_scope(app, view);
Managed_Scope scope = 0;
view_get_managed_scope(app, view, &scope);
managed_variable_set(app, scope, view_next_rewrite_loc, RewritePaste);
i32 paste_index = 0;
managed_variable_set(app, scope, view_paste_index_loc, paste_index);
i32 len = clipboard_index(app, 0, paste_index, 0, 0);
char *str = 0;
if (len <= app->memory_size){
str = (char*)app->memory;
}
Scratch_Block scratch(app);
if (str != 0){
clipboard_index(app, 0, paste_index, str, len);
String_Const_u8 string = {};
clipboard_index(app, 0, paste_index, scratch, &string);
if (string.size > 0){
Buffer_ID buffer = 0;
view_get_buffer(app, view, AccessOpen, &buffer);
i32 pos = 0;
view_get_cursor_pos(app, view, &pos);
buffer_replace_range(app, buffer, make_range(pos), make_string(str, len));
buffer_replace_range(app, buffer, make_range(pos), string);
view_set_mark(app, view, seek_pos(pos));
view_set_cursor(app, view, seek_pos(pos + len), true);
view_set_cursor(app, view, seek_pos(pos + (i32)string.size), true);
// TODO(allen): Send this to all views.
Theme_Color paste = {};
paste.tag = Stag_Paste;
get_theme_colors(app, &paste, 1);
view_post_fade(app, view, 0.667f, pos, pos + len, paste.color);
view_post_fade(app, view, 0.667f, pos, pos + (i32)string.size, paste.color);
}
}
}
@ -91,11 +87,15 @@ CUSTOM_DOC("At the cursor, insert the text at the top of the clipboard.")
CUSTOM_COMMAND_SIG(paste_next)
CUSTOM_DOC("If the previous command was paste or paste_next, replaces the paste range with the next text down on the clipboard, otherwise operates as the paste command.")
{
i32 count = clipboard_count(app, 0);
Scratch_Block scratch(app);
i32 count = 0;
clipboard_count(app, 0, &count);
if (count > 0){
View_ID view = 0;
get_active_view(app, AccessOpen, &view);
Managed_Scope scope = view_get_managed_scope(app, view);
Managed_Scope scope = 0;
view_get_managed_scope(app, view, &scope);
no_mark_snap_to_cursor(app, scope);
u64 rewrite = 0;
@ -107,31 +107,24 @@ CUSTOM_DOC("If the previous command was paste or paste_next, replaces the paste
i32 paste_index = (i32)prev_paste_index + 1;
managed_variable_set(app, scope, view_paste_index_loc, paste_index);
i32 len = clipboard_index(app, 0, paste_index, 0, 0);
char *str = 0;
String_Const_u8 string = {};
clipboard_index(app, 0, paste_index, scratch, &string);
if (len <= app->memory_size){
str = (char*)app->memory;
}
Buffer_ID buffer = 0;
view_get_buffer(app, view, AccessOpen, &buffer);
Range range = get_view_range(app, view);
i32 pos = range.min;
buffer_replace_range(app, buffer, range, string);
view_set_cursor(app, view, seek_pos(pos + (i32)string.size), true);
// TODO(allen): Send this to all views.
Theme_Color paste = {};
paste.tag = Stag_Paste;
get_theme_colors(app, &paste, 1);
view_post_fade(app, view, 0.667f, pos, pos + (i32)string.size, paste.color);
if (str != 0){
clipboard_index(app, 0, paste_index, str, len);
Buffer_ID buffer = 0;
view_get_buffer(app, view, AccessOpen, &buffer);
Range range = get_view_range(app, view);
i32 pos = range.min;
buffer_replace_range(app, buffer, range, make_string(str, len));
view_set_cursor(app, view, seek_pos(pos + len), true);
// TODO(allen): Send this to all views.
Theme_Color paste = {};
paste.tag = Stag_Paste;
get_theme_colors(app, &paste, 1);
view_post_fade(app, view, 0.667f, pos, pos + len, paste.color);
}
}
else{
exec_command(app, paste);

View File

@ -5,15 +5,15 @@
// TOP
static void
write_string(Application_Links *app, View_ID view, Buffer_ID buffer, String string){
write_string(Application_Links *app, View_ID view, Buffer_ID buffer, String_Const_u8 string){
i32 pos = 0;
view_get_cursor_pos(app, view, &pos);
buffer_replace_range(app, buffer, make_range(pos), string);
view_set_cursor(app, view, seek_pos(pos + string.size), 1);
view_set_cursor(app, view, seek_pos(pos + (i32)string.size), 1);
}
static void
write_string(Application_Links *app, String string){
write_string(Application_Links *app, String_Const_u8 string){
View_ID view = 0;
get_active_view(app, AccessOpen, &view);
Buffer_ID buffer = 0;
@ -23,23 +23,15 @@ write_string(Application_Links *app, String string){
static void
write_named_comment_string(Application_Links *app, char *type_string){
char space[512];
String str = make_fixed_width_string(space);
String name = global_config.user_name;
Scratch_Block scratch(app);
String_Const_u8 name = global_config.user_name;
String_Const_u8 str = {};
if (name.size > 0){
append(&str, "// ");
append(&str, type_string);
append(&str, "(");
append(&str, name);
append(&str, "): ");
str = string_u8_pushf(scratch, "// %s(%.*s): ", type_string, string_expand(name));
}
else{
append(&str, "// ");
append(&str, type_string);
append(&str, ": ");
str = string_u8_pushf(scratch, "// %s: ", type_string);
}
write_string(app, str);
}
@ -51,9 +43,9 @@ long_braces(Application_Links *app, char *text, i32 size){
view_get_buffer(app, view, AccessOpen, &buffer);
i32 pos = 0;
view_get_cursor_pos(app, view, &pos);
buffer_replace_range(app, buffer, make_range(pos), make_string(text, size));
buffer_replace_range(app, buffer, make_range(pos), SCu8(text, size));
view_set_cursor(app, view, seek_pos(pos + 2), true);
buffer_auto_indent(app, &global_part, buffer, pos, pos + size, DEF_TAB_WIDTH, DEFAULT_INDENT_FLAGS | AutoIndent_FullTokens);
buffer_auto_indent(app, buffer, pos, pos + size, DEF_TAB_WIDTH, DEFAULT_INDENT_FLAGS | AutoIndent_FullTokens);
move_past_lead_whitespace(app, view, buffer);
}
@ -84,7 +76,7 @@ CUSTOM_DOC("At the cursor, insert a '{' and '}break;' separated by a blank line.
CUSTOM_COMMAND_SIG(if0_off)
CUSTOM_DOC("Surround the range between the cursor and mark with an '#if 0' and an '#endif'")
{
place_begin_and_end_on_own_lines(app, &global_part, "#if 0", "#endif");
place_begin_and_end_on_own_lines(app, "#if 0", "#endif");
}
CUSTOM_COMMAND_SIG(write_todo)
@ -108,13 +100,13 @@ CUSTOM_DOC("At the cursor, insert a '// NOTE' comment, includes user name if it
CUSTOM_COMMAND_SIG(write_block)
CUSTOM_DOC("At the cursor, insert a block comment.")
{
write_string(app, make_lit_string("/* */"));
write_string(app, string_u8_litexpr("/* */"));
}
CUSTOM_COMMAND_SIG(write_zero_struct)
CUSTOM_DOC("At the cursor, insert a ' = {};'.")
{
write_string(app, make_lit_string(" = {};"));
write_string(app, string_u8_litexpr(" = {};"));
}
static i32
@ -150,7 +142,7 @@ CUSTOM_DOC("Insert '//' at the beginning of the line after leading whitespace.")
i32 pos = get_start_of_line_at_cursor(app, view, buffer);
b32 alread_has_comment = c_line_comment_starts_at_position(app, buffer, pos);
if (!alread_has_comment){
buffer_replace_range(app, buffer, make_range(pos), make_lit_string("//"));
buffer_replace_range(app, buffer, make_range(pos), string_u8_litexpr("//"));
}
}
@ -164,7 +156,7 @@ CUSTOM_DOC("If present, delete '//' at the beginning of the line after leading w
i32 pos = get_start_of_line_at_cursor(app, view, buffer);
b32 alread_has_comment = c_line_comment_starts_at_position(app, buffer, pos);
if (alread_has_comment){
buffer_replace_range(app, buffer, make_range(pos, pos + 2), make_lit_string(""));
buffer_replace_range(app, buffer, make_range(pos, pos + 2), string_u8_litexpr(""));
}
}
@ -178,10 +170,10 @@ CUSTOM_DOC("Turns uncommented lines into commented lines and vice versa for comm
i32 pos = get_start_of_line_at_cursor(app, view, buffer);
b32 alread_has_comment = c_line_comment_starts_at_position(app, buffer, pos);
if (alread_has_comment){
buffer_replace_range(app, buffer, make_range(pos, pos + 2), make_lit_string(""));
buffer_replace_range(app, buffer, make_range(pos, pos + 2), string_u8_litexpr(""));
}
else{
buffer_replace_range(app, buffer, make_range(pos), make_lit_string("//"));
buffer_replace_range(app, buffer, make_range(pos), string_u8_litexpr("//"));
}
}
@ -218,43 +210,43 @@ static Snippet default_snippets[] = {
};
static void
activate_snippet(Application_Links *app, Partition *scratch, Heap *heap, View_ID view, struct Lister_State *state, String text_field, void *user_data, b32 activated_by_mouse){
activate_snippet(Application_Links *app, Heap *heap, View_ID view, struct Lister_State *state, String_Const_u8 text_field, void *user_data, b32 activated_by_mouse){
i32 index = (i32)PtrAsInt(user_data);
Snippet_Array snippets = *(Snippet_Array*)state->lister.data.user_data;
if (0 <= index && index < snippets.count){
Snippet snippet = snippets.snippets[index];
lister_default(app, scratch, heap, view, state, ListerActivation_Finished);
lister_default(app, heap, view, state, ListerActivation_Finished);
Buffer_ID buffer = 0;
view_get_buffer(app, view, AccessOpen, &buffer);
i32 pos = 0;
view_get_cursor_pos(app, view, &pos);
buffer_replace_range(app, buffer, make_range(pos), make_string_slowly(snippet.text));
buffer_replace_range(app, buffer, make_range(pos), SCu8(snippet.text));
view_set_cursor(app, view, seek_pos(pos + snippet.cursor_offset), true);
view_set_mark(app, view, seek_pos(pos + snippet.mark_offset));
}
else{
lister_default(app, scratch, heap, view, state, ListerActivation_Finished);
lister_default(app, heap, view, state, ListerActivation_Finished);
}
}
static void
snippet_lister__parameterized(Application_Links *app, Snippet_Array snippet_array){
Partition *arena = &global_part;
View_ID view = 0;
get_active_view(app, AccessAll, &view);
view_end_ui_mode(app, view);
Temp_Memory temp = begin_temp_memory(arena);
Arena *scratch = context_get_arena(app);
Temp_Memory temp = begin_temp(scratch);
i32 option_count = snippet_array.count;
Lister_Option *options = push_array(arena, Lister_Option, option_count);
Lister_Option *options = push_array(scratch, Lister_Option, option_count);
for (i32 i = 0; i < snippet_array.count; i += 1){
options[i].string = make_string_slowly(snippet_array.snippets[i].name);
options[i].status = make_string_slowly(snippet_array.snippets[i].text);
options[i].string = SCu8(snippet_array.snippets[i].name);
options[i].status = SCu8(snippet_array.snippets[i].text);
options[i].user_data = IntAsPtr(i);
}
begin_integrated_lister__basic_list(app, "Snippet:", activate_snippet, &snippet_array, sizeof(snippet_array), options, option_count, 0, view);
end_temp_memory(temp);
end_temp(temp);
}
CUSTOM_COMMAND_SIG(snippet_lister)

File diff suppressed because it is too large Load Diff

View File

@ -19,9 +19,9 @@ struct Error_Location{
struct Config_Error{
Config_Error *next;
Config_Error *prev;
String file_name;
char *pos;
String text;
String_Const_u8 file_name;
u8 *pos;
String_Const_u8 text;
};
struct Config_Error_List{
@ -35,16 +35,16 @@ struct Config_Parser{
Cpp_Token *token;
Cpp_Token *end;
String file_name;
String data;
String_Const_u8 file_name;
String_Const_u8 data;
Partition *arena;
Arena *arena;
Config_Error_List errors;
};
struct Config_LValue{
String identifier;
String_Const_u8 identifier;
i32 index;
};
@ -76,7 +76,7 @@ struct Config_RValue{
b32 boolean;
i32 integer;
u32 uinteger;
String string;
String_Const_u8 string;
char character;
Config_Compound *compound;
};
@ -99,9 +99,9 @@ enum{
};
struct Config_Layout{
Config_Layout_Type type;
char *pos;
u8 *pos;
union{
String identifier;
String_Const_u8 identifier;
i32 integer;
};
};
@ -118,7 +118,7 @@ struct Config_Assignment{
Config_Assignment *next;
Config_Assignment *prev;
char *pos;
u8 *pos;
Config_LValue *l;
Config_RValue *r;
@ -133,8 +133,8 @@ struct Config{
Config_Error_List errors;
String file_name;
String data;
String_Const_u8 file_name;
String_Const_u8 data;
};
////////////////////////////////
@ -149,12 +149,12 @@ enum{
struct Config_Get_Result{
b32 success;
Config_RValue_Type type;
char *pos;
u8 *pos;
union{
b32 boolean;
i32 integer;
u32 uinteger;
String string;
String_Const_u8 string;
char character;
Config_Compound *compound;
};
@ -179,28 +179,17 @@ struct Config_Get_Result_List{
////////////////////////////////
struct Extension_List{
char space[256];
char *exts[94];
i32 count;
};
struct CString_Array{
char **strings;
i32 count;
};
struct Config_Data{
char user_name_space[256];
String user_name;
u8 user_name_space[256];
String_Const_u8 user_name;
Extension_List code_exts;
String_Const_u8_Array code_exts;
char current_mapping_space[256];
String current_mapping;
u8 current_mapping_space[256];
String_Const_u8 current_mapping;
char mode_space[64];
String mode;
u8 mode_space[64];
String_Const_u8 mode;
b32 use_scroll_bars;
b32 use_file_bars;
@ -224,27 +213,27 @@ struct Config_Data{
i32 default_wrap_width;
i32 default_min_base_width;
char default_theme_name_space[256];
String default_theme_name;
u8 default_theme_name_space[256];
String_Const_u8 default_theme_name;
b32 highlight_line_at_cursor;
char default_font_name_space[256];
String default_font_name;
u8 default_font_name_space[256];
String_Const_u8 default_font_name;
i32 default_font_size;
b32 default_font_hinting;
char default_compiler_bat_space[256];
String default_compiler_bat;
u8 default_compiler_bat_space[256];
String_Const_u8 default_compiler_bat;
char default_flags_bat_space[1024];
String default_flags_bat;
u8 default_flags_bat_space[1024];
String_Const_u8 default_flags_bat;
char default_compiler_sh_space[256];
String default_compiler_sh;
u8 default_compiler_sh_space[256];
String_Const_u8 default_compiler_sh;
char default_flags_sh_space[1024];
String default_flags_sh;
u8 default_flags_sh_space[1024];
String_Const_u8 default_flags_sh;
b32 lalt_lctrl_is_altgr;
};

View File

@ -11,24 +11,25 @@ unlock_jump_buffer(void){
}
static void
lock_jump_buffer(String name){
if (name.size < locked_buffer.memory_size){
copy(&locked_buffer, name);
lock_jump_buffer(String_Const_u8 name){
if (name.size < sizeof(locked_buffer_space)){
block_copy(locked_buffer_space, name.str, name.size);
locked_buffer = SCu8(locked_buffer_space, name.size);
}
}
static void
lock_jump_buffer(char *name, i32 size){
lock_jump_buffer(make_string(name, size));
lock_jump_buffer(SCu8(name, size));
}
static void
lock_jump_buffer(Application_Links *app, Buffer_ID buffer_id){
Arena *scratch = context_get_arena(app);
Temp_Memory_Arena temp = begin_temp_memory(scratch);
String buffer_name = buffer_push_unique_buffer_name(app, buffer_id, scratch);
Temp_Memory temp = begin_temp(scratch);
String_Const_u8 buffer_name = buffer_push_unique_buffer_name(app, buffer_id, scratch);
lock_jump_buffer(buffer_name);
end_temp_memory(temp);
end_temp(temp);
}
static View_ID
@ -63,13 +64,15 @@ new_view_settings(Application_Links *app, View_ID view){
static void
view_set_passive(Application_Links *app, View_ID view_id, b32 value){
Managed_Scope scope = view_get_managed_scope(app, view_id);
Managed_Scope scope = 0;
view_get_managed_scope(app, view_id, &scope);
managed_variable_set(app, scope, view_is_passive_loc, (u64)value);
}
static b32
view_get_is_passive(Application_Links *app, View_ID view_id){
Managed_Scope scope = view_get_managed_scope(app, view_id);
Managed_Scope scope = 0;
view_get_managed_scope(app, view_id, &scope);
u64 is_passive = 0;
managed_variable_get(app, scope, view_is_passive_loc, &is_passive);
return(is_passive != 0);
@ -149,7 +152,7 @@ static void
view_buffer_set(Application_Links *app, Buffer_ID *buffers, i32 *positions, i32 count){
if (count > 0){
Arena *arena = context_get_arena(app);
Temp_Memory_Arena temp = begin_temp_memory(arena);
Temp_Memory temp = begin_temp(arena);
struct View_Node{
View_Node *next;
@ -194,7 +197,7 @@ view_buffer_set(Application_Links *app, Buffer_ID *buffers, i32 *positions, i32
}
}
end_temp_memory(temp);
end_temp(temp);
}
}
@ -251,7 +254,7 @@ CUSTOM_DOC("Create a new panel by horizontally splitting the active panel.")
// NOTE(allen): Credits to nj/FlyingSolomon for authoring the original version of this helper.
static Buffer_ID
create_or_switch_to_buffer_by_name(Application_Links *app, String name_string, View_ID default_target_view){
create_or_switch_to_buffer_and_clear_by_name(Application_Links *app, String_Const_u8 name_string, View_ID default_target_view){
Buffer_ID search_buffer = 0;
get_buffer_by_name(app, name_string, AccessAll, &search_buffer);
if (search_buffer != 0){
@ -273,7 +276,7 @@ create_or_switch_to_buffer_by_name(Application_Links *app, String name_string, V
buffer_get_size(app, search_buffer, &buffer_size);
buffer_send_end_signal(app, search_buffer);
buffer_replace_range(app, search_buffer, make_range(0, buffer_size), make_lit_string(""));
buffer_replace_range(app, search_buffer, make_range(0, buffer_size), string_u8_litexpr(""));
}
else{
create_buffer(app, name_string, BufferCreate_AlwaysNew, &search_buffer);
@ -361,9 +364,10 @@ CUSTOM_COMMAND_SIG(remap_interactive)
CUSTOM_DOC("Switch to a named key binding map.")
{
Query_Bar bar = {};
char space[1024];
bar.prompt = make_lit_string("Map Name: ");
bar.string = make_fixed_width_string(space);
u8 space[1024];
bar.prompt = string_u8_litexpr("Map Name: ");
bar.string = SCu8(space, (umem)0);
bar.string_capacity = sizeof(space);
if (!query_user_string(app, &bar)) return;
change_mapping(app, bar.string);
}
@ -372,28 +376,26 @@ CUSTOM_DOC("Switch to a named key binding map.")
static void
default_4coder_initialize(Application_Links *app, char **command_line_files, i32 file_count, i32 override_font_size, b32 override_hinting){
i32 part_size = (32 << 20);
void *part_mem = memory_allocate(app, part_size);
global_part = make_part(part_mem, part_size);
i32 heap_size = (4 << 20);
void *heap_mem = memory_allocate(app, heap_size);
heap_init(&global_heap);
heap_extend(&global_heap, heap_mem, heap_size);
static char message[] =
"Welcome to " VERSION "\n"
"If you're new to 4coder there are some tutorials at http://4coder.net/tutorials.html\n"
"Direct bug reports and feature requests to https://github.com/4coder-editor/4coder/issues\n"
"Other questions and discussion can be directed to editor@4coder.net or 4coder.handmade.network\n"
"The change log can be found in CHANGES.txt\n"
"\n";
print_message(app, message, sizeof(message) - 1);
#define M \
"Welcome to " VERSION "\n" \
"If you're new to 4coder there are some tutorials at http://4coder.net/tutorials.html\n" \
"Direct bug reports and feature requests to https://github.com/4coder-editor/4coder/issues\n" \
"Other questions and discussion can be directed to editor@4coder.net or 4coder.handmade.network\n" \
"The change log can be found in CHANGES.txt\n" \
"\n"
print_message(app, string_u8_litexpr(M));
#undef M
#if 0
load_folder_of_themes_into_live_set(app, &global_part, "themes");
#endif
load_config_and_apply(app, &global_part, &global_config, override_font_size, override_hinting);
global_config_arena = make_arena_app_links(app);
load_config_and_apply(app, &global_config_arena, &global_config, override_font_size, override_hinting);
view_rewrite_loc = managed_variable_create_or_get_id(app, "DEFAULT.rewrite" , 0);
view_next_rewrite_loc = managed_variable_create_or_get_id(app, "DEFAULT.next_rewrite" , 0);
@ -403,23 +405,20 @@ default_4coder_initialize(Application_Links *app, char **command_line_files, i32
view_ui_data = managed_variable_create_or_get_id(app, "DEFAULT.ui_data" , 0);
// open command line files
Temp_Memory temp = begin_temp_memory(&global_part);
char *space = push_array(&global_part, char, (32 << 10));
String file_name = make_string_cap(space, 0, (32 << 10));
i32 hot_directory_length = 0;
if (get_hot_directory(app, &file_name, &hot_directory_length)){
for (i32 i = 0; i < file_count; i += 1){
String input_name = make_string_slowly(command_line_files[i]);
file_name.size = hot_directory_length;
append(&file_name, input_name);
Buffer_ID ignore = 0;
if (!create_buffer(app, file_name, BufferCreate_NeverNew|BufferCreate_MustAttachToFile, &ignore)){
create_buffer(app, input_name, 0, &ignore);
}
Arena *scratch = context_get_arena(app);
Temp_Memory temp = begin_temp(scratch);
String_Const_u8 hot_directory = push_hot_directory(app, scratch);
for (i32 i = 0; i < file_count; i += 1){
Temp_Memory temp2 = begin_temp(scratch);
String_Const_u8 input_name = SCu8(command_line_files[i]);
String_Const_u8 file_name = string_u8_pushf(scratch, "%.*s/%.*s", string_expand(hot_directory), string_expand(input_name));
Buffer_ID ignore = 0;
if (!create_buffer(app, file_name, BufferCreate_NeverNew|BufferCreate_MustAttachToFile, &ignore)){
create_buffer(app, input_name, 0, &ignore);
}
end_temp(temp2);
}
end_temp_memory(temp);
end_temp(temp);
}
static void
@ -461,25 +460,23 @@ default_4coder_side_by_side_panels(Application_Links *app, Buffer_Identifier lef
}
static void
default_4coder_side_by_side_panels(Application_Links *app, char **command_line_files, i32 file_count){
Buffer_Identifier left = buffer_identifier(literal("*scratch*"));
Buffer_Identifier right = buffer_identifier(literal("*messages*"));
default_4coder_side_by_side_panels(Application_Links *app, Buffer_Identifier left, Buffer_Identifier right, char **command_line_files, i32 file_count){
if (file_count > 0){
char *left_name = command_line_files[0];
i32 left_len = str_size(left_name);
left = buffer_identifier(left_name, left_len);
left = buffer_identifier(SCu8(command_line_files[0]));
if (file_count > 1){
char *right_name = command_line_files[1];
i32 right_len = str_size(right_name);
right = buffer_identifier(right_name, right_len);
right = buffer_identifier(SCu8(command_line_files[1]));
}
}
default_4coder_side_by_side_panels(app, left, right);
}
static void
default_4coder_side_by_side_panels(Application_Links *app, char **command_line_files, i32 file_count){
Buffer_Identifier left = buffer_identifier(string_u8_litexpr("*scratch*"));
Buffer_Identifier right = buffer_identifier(string_u8_litexpr("*messages*"));
default_4coder_side_by_side_panels(app, left, right, command_line_files, file_count);
}
static void
default_4coder_side_by_side_panels(Application_Links *app){
default_4coder_side_by_side_panels(app, 0, 0);
@ -496,14 +493,10 @@ default_4coder_one_panel(Application_Links *app, Buffer_Identifier buffer){
static void
default_4coder_one_panel(Application_Links *app, char **command_line_files, i32 file_count){
Buffer_Identifier buffer = buffer_identifier(literal("*messages*"));
Buffer_Identifier buffer = buffer_identifier(string_u8_litexpr("*messages*"));
if (file_count > 0){
char *name = command_line_files[0];
i32 len = str_size(name);
buffer = buffer_identifier(name, len);
buffer = buffer_identifier(SCu8(command_line_files[0]));
}
default_4coder_one_panel(app, buffer);
}

View File

@ -36,7 +36,7 @@ struct ID_Pos_Jump_Location{
};
struct Name_Line_Column_Location{
String file;
String_Const_u8 file;
i32 line;
i32 column;
};
@ -60,7 +60,7 @@ struct ID_Pos_Jump_Location_Array{
////////////////////////////////
struct Named_Mapping{
String name;
String_Const_u8 name;
Custom_Command_Function *remap_command;
};

View File

@ -27,8 +27,8 @@ static char *default_extensions[] = {
#define AUTO_CENTER_AFTER_JUMPS true
#endif
static b32 auto_center_after_jumps = AUTO_CENTER_AFTER_JUMPS;
static char locked_buffer_space[256];
static String locked_buffer = make_fixed_width_string(locked_buffer_space);
static u8 locked_buffer_space[256];
static String_Const_u8 locked_buffer = {};
static View_ID build_footer_panel_view_id = 0;
@ -41,8 +41,8 @@ static Managed_Variable_ID view_is_passive_loc = 0;
static Managed_Variable_ID view_snap_mark_to_cursor = 0;
static Managed_Variable_ID view_ui_data = 0;
static char out_buffer_space[1024];
static char command_space[1024];
static u8 out_buffer_space[1024];
static u8 command_space[1024];
static char hot_directory_space[1024];
@ -56,7 +56,6 @@ static b32 cursor_is_hidden = false;
static b32 show_fps_hud = false;
static Partition global_part;
static Heap global_heap;
enum{
@ -68,6 +67,7 @@ static i32 fcoder_mode = FCoderMode_Original;
static ID_Line_Column_Jump_Location prev_location = {};
static Arena global_config_arena = {};
static Config_Data global_config = {};
static char previous_isearch_query[256] = {};

View File

@ -14,9 +14,9 @@ CUSTOM_COMMAND_SIG(set_bindings_default);
CUSTOM_COMMAND_SIG(set_bindings_mac_default);
static Named_Mapping named_maps_values[] = {
{make_lit_string("mac-default") , set_bindings_mac_default },
{make_lit_string("choose") , set_bindings_choose },
{make_lit_string("default") , set_bindings_default },
{string_u8_litexpr("mac-default") , set_bindings_mac_default },
{string_u8_litexpr("choose") , set_bindings_choose },
{string_u8_litexpr("default") , set_bindings_default },
};
START_HOOK_SIG(default_start){
@ -82,14 +82,16 @@ START_HOOK_SIG(default_start){
COMMAND_CALLER_HOOK(default_command_caller){
View_ID view = 0;
get_active_view(app, AccessAll, &view);
Managed_Scope scope = view_get_managed_scope(app, view);
Managed_Scope scope = 0;
view_get_managed_scope(app, view, &scope);
managed_variable_set(app, scope, view_next_rewrite_loc, 0);
if (fcoder_mode == FCoderMode_NotepadLike){
View_ID view_it = 0;
for (get_view_next(app, 0, AccessAll, &view_it);
view_it != 0;
get_view_next(app, view_it, AccessAll, &view_it)){
Managed_Scope scope_it = view_get_managed_scope(app, view_it);
Managed_Scope scope_it = 0;
view_get_managed_scope(app, view_it, &scope_it);
managed_variable_set(app, scope_it, view_snap_mark_to_cursor, true);
}
}
@ -104,7 +106,8 @@ COMMAND_CALLER_HOOK(default_command_caller){
for (get_view_next(app, 0, AccessAll, &view_it);
view_it != 0;
get_view_next(app, view_it, AccessAll, &view_it)){
Managed_Scope scope_it = view_get_managed_scope(app, view_it);
Managed_Scope scope_it = 0;
view_get_managed_scope(app, view_it, &scope_it);
u64 val = 0;
if (managed_variable_get(app, scope_it, view_snap_mark_to_cursor, &val)){
if (val != 0){
@ -120,8 +123,8 @@ COMMAND_CALLER_HOOK(default_command_caller){
}
struct Highlight_Record{
i32 first;
i32 one_past_last;
Highlight_Record *next;
Range range;
int_color color;
};
@ -147,28 +150,32 @@ sort_highlight_record(Highlight_Record *records, i32 first, i32 one_past_last){
}
static Range_Array
get_enclosure_ranges(Application_Links *app, Partition *part, Buffer_ID buffer, i32 pos, u32 flags){
get_enclosure_ranges(Application_Links *app, Arena *arena, Buffer_ID buffer, i32 pos, u32 flags){
Range_Array array = {};
array.ranges = push_array(part, Range, 0);
i32 max = 100;
array.ranges = push_array(arena, Range, max);
for (;;){
Range range = {};
if (find_scope_range(app, buffer, pos, &range, flags)){
Range *r = push_array(part, Range, 1);
*r = range;
array.ranges[array.count] = range;
array.count += 1;
pos = range.first;
if (array.count >= max){
break;
}
}
else{
break;
}
}
array.count = (i32)(push_array(part, Range, 0) - array.ranges);
return(array);
}
static void
mark_enclosures(Application_Links *app, Partition *scratch, Managed_Scope render_scope, Buffer_ID buffer, i32 pos, u32 flags,
mark_enclosures(Application_Links *app, Managed_Scope render_scope, Buffer_ID buffer, i32 pos, u32 flags,
Marker_Visual_Type type, int_color *back_colors, int_color *fore_colors, i32 color_count){
Temp_Memory temp = begin_temp_memory(scratch);
Arena *scratch = context_get_arena(app);
Temp_Memory temp = begin_temp(scratch);
Range_Array ranges = get_enclosure_ranges(app, scratch, buffer, pos, flags);
if (ranges.count > 0){
@ -212,7 +219,7 @@ mark_enclosures(Application_Links *app, Partition *scratch, Managed_Scope render
}
}
end_temp_memory(temp);
end_temp(temp);
}
static argb_color default_colors[Stag_COUNT] = {};
@ -311,7 +318,7 @@ GET_VIEW_BUFFER_REGION_SIG(default_view_buffer_region){
if (global_config.show_line_number_margins){
i32 line_count = 0;
buffer_get_line_count(app, buffer, &line_count);
i32 line_count_digit_count = int_to_str_size(line_count);
i32 line_count_digit_count = (i32)digit_count_from_integer(line_count, 10);
i32 margin_width = ceil32((f32)line_count_digit_count*metrics.typical_character_width);
sub_region.x0 += margin_width + 2;
}
@ -376,8 +383,8 @@ default_buffer_render_caller(Application_Links *app, Frame_Info frame_info, View
get_active_view(app, AccessAll, &active_view);
b32 is_active_view = (active_view == view_id);
Arena *arena = context_get_arena(app);
Temp_Memory_Arena major_temp = begin_temp_memory(arena);
Arena *scratch = context_get_arena(app);
Temp_Memory major_temp = begin_temp(scratch);
static Managed_Scope render_scope = 0;
if (render_scope == 0){
@ -404,7 +411,7 @@ default_buffer_render_caller(Application_Links *app, Frame_Info frame_info, View
Fancy_Color base_color = fancy_id(Stag_Base);
Fancy_Color pop2_color = fancy_id(Stag_Pop2);
Temp_Memory_Arena temp = begin_temp_memory(arena);
Temp_Memory temp = begin_temp(scratch);
i32 cursor_position = 0;
view_get_cursor_pos(app, view_id, &cursor_position);
@ -412,43 +419,44 @@ default_buffer_render_caller(Application_Links *app, Frame_Info frame_info, View
view_compute_cursor(app, view_id, seek_pos(cursor_position), &cursor);
Fancy_String_List list = {};
push_fancy_string(arena, &list, base_color, buffer_push_unique_buffer_name(app, buffer_id, arena));
push_fancy_stringf(arena, &list, base_color, " - Row: %3.d Col: %3.d -", cursor.line, cursor.character);
String_Const_u8 unique_name = buffer_push_unique_buffer_name(app, buffer_id, scratch);
push_fancy_string(scratch, &list, base_color, unique_name);
push_fancy_stringf(scratch, &list, base_color, " - Row: %3.d Col: %3.d -", cursor.line, cursor.character);
b32 is_dos_mode = false;
if (buffer_get_setting(app, buffer_id, BufferSetting_Eol, &is_dos_mode)){
if (is_dos_mode){
push_fancy_string(arena, &list, base_color, make_lit_string(" dos"));
push_fancy_string(scratch, &list, base_color, string_u8_litexpr(" dos"));
}
else{
push_fancy_string(arena, &list, base_color, make_lit_string(" nix"));
push_fancy_string(scratch, &list, base_color, string_u8_litexpr(" nix"));
}
}
else{
push_fancy_string(arena, &list, base_color, make_lit_string(" ???"));
push_fancy_string(scratch, &list, base_color, string_u8_litexpr(" ???"));
}
{
Dirty_State dirty = 0;
buffer_get_dirty_state(app, buffer_id, &dirty);
char space[3];
String str = make_fixed_width_string(space);
u8 space[3];
String_u8 str = Su8(space, 0, 3);
if (dirty != 0){
append(&str, " ");
string_append(&str, string_u8_litexpr(" "));
}
if (HasFlag(dirty, DirtyState_UnsavedChanges)){
append(&str, "*");
string_append(&str, string_u8_litexpr("*"));
}
if (HasFlag(dirty, DirtyState_UnloadedChanges)){
append(&str, "!");
string_append(&str, string_u8_litexpr("!"));
}
push_fancy_string(arena, &list, pop2_color, str);
push_fancy_string(scratch, &list, pop2_color, str.string);
}
Vec2 p = bar.p0 + V2(0.f, 2.f);
draw_fancy_string(app, face_id, list.first, p, Stag_Default, 0);
end_temp_memory(temp);
end_temp(temp);
}
}
}
@ -466,19 +474,19 @@ default_buffer_render_caller(Application_Links *app, Frame_Info frame_info, View
bar.y1 = bar.y0 + line_height + 2.f;
r_cursor.y0 = bar.y1;
Temp_Memory_Arena temp = begin_temp_memory(arena);
Temp_Memory temp = begin_temp(scratch);
Fancy_String_List list = {};
Fancy_Color default_color = fancy_id(Stag_Default);
Fancy_Color pop1_color = fancy_id(Stag_Pop1);
push_fancy_string(arena, &list, pop1_color , query_bar->prompt);
push_fancy_string(arena, &list, default_color, query_bar->string);
push_fancy_string(scratch, &list, pop1_color , query_bar->prompt);
push_fancy_string(scratch, &list, default_color, query_bar->string);
Vec2 p = bar.p0 + V2(0.f, 2.f);
draw_fancy_string(app, face_id, list.first, p, Stag_Default, 0);
end_temp_memory(temp);
end_temp(temp);
}
}
}
@ -487,9 +495,9 @@ default_buffer_render_caller(Application_Links *app, Frame_Info frame_info, View
if (global_config.show_line_number_margins){
i32 line_count = 0;
buffer_get_line_count(app, buffer_id, &line_count);
i32 line_count_digit_count = int_to_str_size(line_count);
i32 line_count_digit_count = (i32)digit_count_from_integer(line_count, 10);
// TODO(allen): I need a "digit width"
f32 zero = get_string_advance(app, face_id, make_lit_string("0"));
f32 zero = get_string_advance(app, face_id, string_u8_litexpr("0"));
f32 margin_width = (f32)line_count_digit_count*zero;
Rect_f32 left_margin = r_cursor;
@ -509,10 +517,10 @@ default_buffer_render_caller(Application_Links *app, Frame_Info frame_info, View
Vec2 p = panel_space_from_view_space(cursor.wrapped_p, scroll_vars.scroll_p);
p += V2(buffer_rect.p0);
p.x = left_margin.x0;
Temp_Memory_Arena temp = begin_temp_memory(arena);
Fancy_String *line_string = push_fancy_stringf(arena, line_color, "%*d", line_count_digit_count, cursor.line);
Temp_Memory temp = begin_temp(scratch);
Fancy_String *line_string = push_fancy_stringf(scratch, line_color, "%*d", line_count_digit_count, cursor.line);
draw_fancy_string(app, face_id, line_string, p, Stag_Margin_Active, 0);
end_temp_memory(temp);
end_temp(temp);
i32 next_line = cursor.line + 1;
view_compute_cursor(app, view_id, seek_line_char(next_line, 1), &cursor);
if (cursor.line < next_line){
@ -524,70 +532,82 @@ default_buffer_render_caller(Application_Links *app, Frame_Info frame_info, View
}
}
// TODO(allen): eliminate scratch partition usage
Partition *scratch = &global_part;
// NOTE(allen): Scan for TODOs and NOTEs
{
Temp_Memory temp = begin_temp_memory(scratch);
i32 text_size = on_screen_range.one_past_last - on_screen_range.first;
char *text = push_array(scratch, char, text_size);
buffer_read_range(app, buffer_id, on_screen_range.first, on_screen_range.one_past_last, text);
Temp_Memory temp = begin_temp(scratch);
String_Const_u8 tail = scratch_read(app, scratch, buffer_id, on_screen_range);
Highlight_Record *records = push_array(scratch, Highlight_Record, 0);
String tail = make_string(text, text_size);
for (i32 i = 0; i < text_size; tail.str += 1, tail.size -= 1, i += 1){
if (match_part(tail, make_lit_string("NOTE"))){
Highlight_Record *record_first = 0;
Highlight_Record *record_last = 0;
i32 record_count = 0;
i32 index = 0;
for (;tail.size > 0; tail = string_skip(tail, 1), index += 1){
if (string_match(string_prefix(tail, 4), string_u8_litexpr("NOTE"))){
Highlight_Record *record = push_array(scratch, Highlight_Record, 1);
record->first = i + on_screen_range.first;
record->one_past_last = record->first + 4;
sll_queue_push(record_first, record_last, record);
record_count += 1;
record->range.first = on_screen_range.first + index;
record->range.one_past_last = record->range.first + 4;
record->color = Stag_Text_Cycle_2;
tail.str += 3;
tail.size -= 3;
i += 3;
tail = string_skip(tail, 3);
index += 3;
}
else if (match_part(tail, make_lit_string("TODO"))){
else if (string_match(string_prefix(tail, 4), string_u8_litexpr("TODO"))){
Highlight_Record *record = push_array(scratch, Highlight_Record, 1);
record->first = i + on_screen_range.first;
record->one_past_last = record->first + 4;
sll_queue_push(record_first, record_last, record);
record_count += 1;
record->range.first = on_screen_range.first + index;
record->range.one_past_last = record->range.first + 4;
record->color = Stag_Text_Cycle_1;
tail.str += 3;
tail.size -= 3;
i += 3;
tail = string_skip(tail, 3);
index += 3;
}
}
i32 record_count = (i32)(push_array(scratch, Highlight_Record, 0) - records);
push_array(scratch, Highlight_Record, 1);
Highlight_Record *records = push_array(scratch, Highlight_Record, record_count);
i32 record_index = 0;
for (Highlight_Record *node = record_first;
node != 0;
node = node->next){
records[record_index] = *node;
record_index += 1;
}
if (record_count > 0){
sort_highlight_record(records, 0, record_count);
Temp_Memory marker_temp = begin_temp_memory(scratch);
Marker *markers = push_array(scratch, Marker, 0);
Marker *markers = push_array_zero(scratch, Marker, 2*record_count);
i32 marker_index_first = 0;
i32 marker_index = 0;
int_color current_color = records[0].color;
{
Marker *marker = push_array(scratch, Marker, 2);
marker[0].pos = records[0].first;
marker[1].pos = records[0].one_past_last;
Marker *marker = &markers[marker_index];
marker[0].pos = records[0].range.first;
marker[1].pos = records[0].range.one_past_last;
marker_index += 2;
}
for (i32 i = 1; i <= record_count; i += 1){
b32 do_emit = i == record_count || (records[i].color != current_color);
b32 do_emit = (i == record_count || records[i].color != current_color);
if (do_emit){
i32 marker_count = (i32)(push_array(scratch, Marker, 0) - markers);
i32 marker_count = marker_index - marker_index_first;
Managed_Object o = alloc_buffer_markers_on_buffer(app, buffer_id, marker_count, &render_scope);
managed_object_store_data(app, o, 0, marker_count, markers);
managed_object_store_data(app, o, 0, marker_count, markers + marker_index_first);
Marker_Visual v = create_marker_visual(app, o);
marker_visual_set_effect(app, v, VisualType_CharacterHighlightRanges, SymbolicColor_Default, current_color, 0);
marker_visual_set_priority(app, v, VisualPriority_Lowest);
end_temp_memory(marker_temp);
current_color = records[i].color;
marker_index_first = marker_index;
}
if (i < record_count){
Marker *marker = &markers[marker_index];
marker[0].pos = records[i].range.first;
marker[1].pos = records[i].range.one_past_last;
marker_index += 2;
}
Marker *marker = push_array(scratch, Marker, 2);
marker[0].pos = records[i].first;
marker[1].pos = records[i].one_past_last;
}
}
end_temp_memory(temp);
end_temp(temp);
}
// NOTE(allen): Cursor and mark
@ -700,7 +720,7 @@ default_buffer_render_caller(Application_Links *app, Frame_Info frame_info, View
for (u16 i = 0; i < color_count; i += 1){
colors[i] = Stag_Back_Cycle_1 + i;
}
mark_enclosures(app, scratch, render_scope, buffer_id, cursor_pos, FindScope_Brace, VisualType_LineHighlightRanges, colors, 0, color_count);
mark_enclosures(app, render_scope, buffer_id, cursor_pos, FindScope_Brace, VisualType_LineHighlightRanges, colors, 0, color_count);
}
if (do_matching_paren_highlight){
i32 pos = cursor_pos;
@ -716,7 +736,7 @@ default_buffer_render_caller(Application_Links *app, Frame_Info frame_info, View
for (u16 i = 0; i < color_count; i += 1){
colors[i] = Stag_Text_Cycle_1 + i;
}
mark_enclosures(app, scratch, render_scope, buffer_id, pos, FindScope_Paren, VisualType_CharacterBlocks, 0, colors, color_count);
mark_enclosures(app, render_scope, buffer_id, pos, FindScope_Paren, VisualType_CharacterBlocks, 0, colors, color_count);
}
draw_clip_push(app, buffer_rect);
@ -758,28 +778,24 @@ default_buffer_render_caller(Application_Links *app, Frame_Info frame_info, View
dts[1] = history_animation_dt[j];
i32 frame_index = history_frame_index[j];
char space[256];
String str = make_fixed_width_string(space);
Fancy_Color white = fancy_rgba(1.f, 1.f, 1.f, 1.f);
Fancy_Color pink = fancy_rgba(1.f, 0.f, 1.f, 1.f);
Fancy_Color green = fancy_rgba(0.f, 1.f, 0.f, 1.f);
Fancy_String_List list = {};
push_fancy_stringf(arena, &list, pink , "FPS: ");
push_fancy_stringf(arena, &list, green, "[");
push_fancy_stringf(arena, &list, white, "%5d", frame_index);
push_fancy_stringf(arena, &list, green, "]: ");
push_fancy_stringf(scratch, &list, pink , "FPS: ");
push_fancy_stringf(scratch, &list, green, "[");
push_fancy_stringf(scratch, &list, white, "%5d", frame_index);
push_fancy_stringf(scratch, &list, green, "]: ");
for (i32 k = 0; k < 2; k += 1){
f32 dt = dts[k];
str.size = 0;
if (dt == 0.f){
push_fancy_stringf(arena, &list, white, "----------");
push_fancy_stringf(scratch, &list, white, "----------");
}
else{
push_fancy_stringf(arena, &list, white, "%10.6f", dt);
push_fancy_stringf(scratch, &list, white, "%10.6f", dt);
}
push_fancy_stringf(arena, &list, green, " | ");
push_fancy_stringf(scratch, &list, green, " | ");
}
draw_fancy_string(app, face_id, list.first, p, Stag_Default, 0, 0, V2(1.f, 0.f));
@ -789,7 +805,7 @@ default_buffer_render_caller(Application_Links *app, Frame_Info frame_info, View
animate_in_n_milliseconds(app, 1000);
}
end_temp_memory(major_temp);
end_temp(major_temp);
managed_scope_clear_self_all_dependent_scopes(app, render_scope);
}
@ -962,7 +978,7 @@ HOOK_SIG(default_view_adjust){
Face_ID face_id = 0;
get_face_id(app, buffer, &face_id);
f32 em = get_string_advance(app, face_id, make_lit_string("m"));
f32 em = get_string_advance(app, face_id, string_u8_litexpr("m"));
f32 wrap_width = view_width - 2.0f*em;
f32 min_width = 40.0f*em;
@ -980,12 +996,9 @@ HOOK_SIG(default_view_adjust){
BUFFER_NAME_RESOLVER_SIG(default_buffer_name_resolution){
if (conflict_count > 1){
// List of unresolved conflicts
Partition *part = &global_part;
Temp_Memory temp = begin_temp_memory(part);
i32 *unresolved = push_array(part, i32, conflict_count);
if (unresolved == 0) return;
Scratch_Block scratch(app);
i32 *unresolved = push_array(scratch, i32, conflict_count);
i32 unresolved_count = conflict_count;
for (i32 i = 0; i < conflict_count; ++i){
unresolved[i] = i;
@ -1000,57 +1013,50 @@ BUFFER_NAME_RESOLVER_SIG(default_buffer_name_resolution){
i32 conflict_index = unresolved[i];
Buffer_Name_Conflict_Entry *conflict = &conflicts[conflict_index];
i32 len = conflict->base_name_len;
if (len < 0){
len = 0;
}
if (len > conflict->unique_name_capacity){
len = conflict->unique_name_capacity;
}
conflict->unique_name_len_in_out = len;
memcpy(conflict->unique_name_in_out, conflict->base_name, len);
umem size = conflict->base_name.size;
size = clamp_top(size, conflict->unique_name_capacity);
conflict->unique_name_len_in_out = size;
memcpy(conflict->unique_name_in_out, conflict->base_name.str, size);
if (conflict->file_name != 0){
char uniqueifier_space[256];
String uniqueifier = make_fixed_width_string(uniqueifier_space);
if (conflict->file_name.str != 0){
Scratch_Block per_file_closer(scratch);
String_Const_u8 uniqueifier = {};
String s_file_name = make_string(conflict->file_name, conflict->file_name_len);
s_file_name = path_of_directory(s_file_name);
if (s_file_name.size > 0){
s_file_name.size -= 1;
char *end = s_file_name.str + s_file_name.size;
String_Const_u8 file_name = string_remove_last_folder(conflict->file_name);
if (file_name.size > 0){
file_name = string_chop(file_name, 1);
u8 *end = file_name.str + file_name.size;
b32 past_the_end = false;
for (i32 j = 0; j < x; ++j){
s_file_name = path_of_directory(s_file_name);
file_name = string_remove_last_folder(file_name);
if (j + 1 < x){
s_file_name.size -= 1;
file_name = string_chop(file_name, 1);
}
if (s_file_name.size <= 0){
if (file_name.size == 0){
if (j + 1 < x){
past_the_end = true;
}
s_file_name.size = 0;
break;
}
}
char *start = s_file_name.str + s_file_name.size;
u8 *start = file_name.str + file_name.size;
append(&uniqueifier, make_string(start, (i32)(end - start)));
uniqueifier = SCu8(start, end);
if (past_the_end){
append(&uniqueifier, "~");
append_int_to_str(&uniqueifier, i);
uniqueifier = string_u8_pushf(scratch, "%.*s~%d",
string_expand(uniqueifier), i);
}
}
else{
append_int_to_str(&uniqueifier, i);
uniqueifier = string_u8_pushf(scratch, "%d", i);
}
String builder = make_string_cap(conflict->unique_name_in_out,
conflict->unique_name_len_in_out,
conflict->unique_name_capacity);
append(&builder, " <");
append(&builder, uniqueifier);
append(&builder, ">");
String_u8 builder = Su8(conflict->unique_name_in_out,
conflict->unique_name_len_in_out,
conflict->unique_name_capacity);
string_append(&builder, string_u8_litexpr(" <"));
string_append(&builder, uniqueifier);
string_append(&builder, string_u8_litexpr(">"));
conflict->unique_name_len_in_out = builder.size;
}
}
@ -1060,19 +1066,21 @@ BUFFER_NAME_RESOLVER_SIG(default_buffer_name_resolution){
for (i32 i = 0; i < unresolved_count; ++i){
i32 conflict_index = unresolved[i];
Buffer_Name_Conflict_Entry *conflict = &conflicts[conflict_index];
String conflict_name = make_string(conflict->unique_name_in_out,
conflict->unique_name_len_in_out);
String_Const_u8 conflict_name = SCu8(conflict->unique_name_in_out,
conflict->unique_name_len_in_out);
b32 hit_conflict = false;
if (conflict->file_name != 0){
if (conflict->file_name.str != 0){
for (i32 j = 0; j < unresolved_count; ++j){
if (i == j) continue;
i32 conflict_j_index = unresolved[j];
Buffer_Name_Conflict_Entry *conflict_j = &conflicts[conflict_j_index];
if (match(conflict_name, make_string(conflict_j->unique_name_in_out,
conflict_j->unique_name_len_in_out))){
String_Const_u8 conflict_name_j = SCu8(conflict_j->unique_name_in_out,
conflict_j->unique_name_len_in_out);
if (string_match(conflict_name, conflict_name_j)){
hit_conflict = true;
break;
}
@ -1093,8 +1101,6 @@ BUFFER_NAME_RESOLVER_SIG(default_buffer_name_resolution){
break;
}
}
end_temp_memory(temp);
}
}
@ -1103,38 +1109,38 @@ OPEN_FILE_HOOK_SIG(default_file_settings){
b32 treat_as_todo = false;
b32 lex_without_strings = false;
CString_Array extensions = get_code_extensions(&global_config.code_exts);
String_Const_u8_Array extensions = global_config.code_exts;
Parse_Context_ID parse_context_id = 0;
Arena *scratch = context_get_arena(app);
Temp_Memory_Arena temp = begin_temp_memory(scratch);
Temp_Memory temp = begin_temp(scratch);
String file_name = buffer_push_file_name(app, buffer_id, scratch);
String_Const_u8 file_name = buffer_push_file_name(app, buffer_id, scratch);
i32 buffer_size = 0;
buffer_get_size(app, buffer_id, &buffer_size);
if (file_name.size > 0 && buffer_size < (32 << 20)){
String ext = file_extension(file_name);
if (file_name.size > 0 && buffer_size < MB(32)){
String_Const_u8 ext = string_file_extension(file_name);
for (i32 i = 0; i < extensions.count; ++i){
if (match(ext, extensions.strings[i])){
if (string_match(ext, extensions.strings[i])){
treat_as_code = true;
if (match(ext, "cs")){
if (string_match(ext, string_u8_litexpr("cs"))){
if (parse_context_language_cs == 0){
init_language_cs(app);
}
parse_context_id = parse_context_language_cs;
}
if (match(ext, "java")){
if (string_match(ext, string_u8_litexpr("java"))){
if (parse_context_language_java == 0){
init_language_java(app);
}
parse_context_id = parse_context_language_java;
}
if (match(ext, "rs")){
if (string_match(ext, string_u8_litexpr("rs"))){
if (parse_context_language_rust == 0){
init_language_rust(app);
}
@ -1142,7 +1148,11 @@ OPEN_FILE_HOOK_SIG(default_file_settings){
lex_without_strings = true;
}
if (match(ext, "cpp") || match(ext, "h") || match(ext, "c") || match(ext, "hpp") || match(ext, "cc")){
if (string_match(ext, string_u8_litexpr("cpp")) ||
string_match(ext, string_u8_litexpr("h")) ||
string_match(ext, string_u8_litexpr("c")) ||
string_match(ext, string_u8_litexpr("hpp")) ||
string_match(ext, string_u8_litexpr("cc"))){
if (parse_context_language_cpp == 0){
init_language_cpp(app);
}
@ -1150,7 +1160,7 @@ OPEN_FILE_HOOK_SIG(default_file_settings){
}
// TODO(NAME): Real GLSL highlighting
if (match(ext, "glsl")){
if (string_match(ext, string_u8_litexpr("glsl"))){
if (parse_context_language_cpp == 0){
init_language_cpp(app);
}
@ -1158,7 +1168,7 @@ OPEN_FILE_HOOK_SIG(default_file_settings){
}
// TODO(NAME): Real Objective-C highlighting
if (match(ext, "m")){
if (string_match(ext, string_u8_litexpr("m"))){
if (parse_context_language_cpp == 0){
init_language_cpp(app);
}
@ -1170,7 +1180,8 @@ OPEN_FILE_HOOK_SIG(default_file_settings){
}
if (!treat_as_code){
treat_as_todo = match_insensitive(front_of_directory(file_name), "todo.txt");
treat_as_todo = string_match_insensitive(string_front_of_path(file_name),
string_u8_litexpr("todo.txt"));
}
}
@ -1204,8 +1215,8 @@ OPEN_FILE_HOOK_SIG(default_file_settings){
use_lexer = true;
}
String buffer_name = buffer_push_base_buffer_name(app, buffer_id, scratch);
if (match(buffer_name, "*compilation*")){
String_Const_u8 buffer_name = buffer_push_base_buffer_name(app, buffer_id, scratch);
if (string_match(buffer_name, string_u8_litexpr("*compilation*"))){
wrap_lines = false;
}
if (buffer_size >= (1 << 20)){
@ -1224,7 +1235,7 @@ OPEN_FILE_HOOK_SIG(default_file_settings){
buffer_set_setting(app, buffer_id, BufferSetting_VirtualWhitespace, use_virtual_whitespace);
buffer_set_setting(app, buffer_id, BufferSetting_Lex, use_lexer);
end_temp_memory(temp);
end_temp(temp);
// no meaning for return
return(0);
@ -1243,7 +1254,7 @@ OPEN_FILE_HOOK_SIG(default_file_save){
if (is_virtual){
i32 buffer_size = 0;
buffer_get_size(app, buffer_id, &buffer_size);
buffer_auto_indent(app, &global_part, buffer_id, 0, buffer_size, DEF_TAB_WIDTH, DEFAULT_INDENT_FLAGS | AutoIndent_FullTokens);
buffer_auto_indent(app, buffer_id, 0, buffer_size, DEF_TAB_WIDTH, DEFAULT_INDENT_FLAGS | AutoIndent_FullTokens);
}
}
// no meaning for return
@ -1268,16 +1279,11 @@ FILE_EDIT_FINISHED_SIG(default_file_edit_finished){
}
OPEN_FILE_HOOK_SIG(default_end_file){
Arena *scratch = context_get_arena(app);
Temp_Memory_Arena temp = begin_temp_memory(scratch);
char space[1024];
String buffer_name = buffer_push_unique_buffer_name(app, buffer_id, scratch);
String str = make_fixed_width_string(space);
append(&str, "Ending file: ");
append(&str, buffer_name);
append(&str, "\n");
print_message(app, str.str, str.size);
end_temp_memory(temp);
Scratch_Block scratch(app);
String_Const_u8 buffer_name = buffer_push_unique_buffer_name(app, buffer_id, scratch);
String_Const_u8 str = string_u8_pushf(scratch, "Ending file: %.*s\n",
string_expand(buffer_name));
print_message(app, str);
// no meaning for return
return(0);
}

View File

@ -10,11 +10,17 @@
// NOTE(allen): Define USE_OLD_STYLE_JUMPS before 4coder_default_include.cpp to get
// the direct jumps (instead of sticky jumps).
#define REMOVE_OLD_STRING
#define REMOVE_TRANSITION_HELPER_31
#include "4coder_API/4coder_custom.h"
#include "4coder_os_comp_cracking.h"
#include "4coder_generated/command_metadata.h"
#include "4coder_base_types.cpp"
#include "4coder_stringf.cpp"
#include "4coder_app_links_allocator.cpp"
#include "4coder_lib/4coder_arena.cpp"
#include "4coder_lib/4coder_heap.cpp"
@ -36,6 +42,7 @@
#include "4coder_auto_indent.h"
#include "4coder_search.h"
#include "4coder_build_commands.h"
#include "4coder_jumping.h"
#include "4coder_jump_sticky.h"
#include "4coder_jump_lister.h"
#include "4coder_project_commands.h"

View File

@ -64,14 +64,14 @@ CUSTOM_DOC("Delete characters in a rectangular region. Range testing is done by
i32 start = cursor.pos;
if (view_compute_cursor(app, view, seek_wrapped_xy((float)rect.x1, y, 0), &cursor)){
i32 end = cursor.pos;
buffer_replace_range(app, buffer, make_range(start, end), make_lit_string(""));
buffer_replace_range(app, buffer, make_range(start, end), string_u8_litexpr(""));
}
}
}
}
static void
pad_buffer_line(Application_Links *app, Partition *part, Buffer_ID buffer, i32 line, char padchar, i32 target){
pad_buffer_line(Application_Links *app, Buffer_ID buffer, i32 line, char padchar, i32 target){
Partial_Cursor start = {};
Partial_Cursor end = {};
@ -79,12 +79,13 @@ pad_buffer_line(Application_Links *app, Partition *part, Buffer_ID buffer, i32 l
if (buffer_compute_cursor(app, buffer, seek_line_char(line, 65536), &end)){
if (start.line == line){
if (end.character-1 < target){
Temp_Memory temp = begin_temp_memory(part);
Arena *scratch = context_get_arena(app);
Temp_Memory temp = begin_temp(scratch);
i32 size = target - (end.character - 1);
char *str = push_array(part, char, size);
memset(str, ' ', size);
buffer_replace_range(app, buffer, make_range(end.pos), make_string(str, size));
end_temp_memory(temp);
char *str = push_array(scratch, char, size);
block_fill_u8(str, size, ' ');
buffer_replace_range(app, buffer, make_range(end.pos), SCu8(str, size));
end_temp(temp);
}
}
}
@ -136,8 +137,6 @@ struct Buffer_Rect{
CUSTOM_COMMAND_SIG(multi_line_edit)
CUSTOM_DOC("Begin multi-line mode. In multi-line mode characters are inserted at every line between the mark and cursor. All characters are inserted at the same character offset into the line. This mode uses line_char coordinates.")
{
Partition *part = &global_part;
View_ID view = 0;
get_active_view(app, AccessOpen, &view);
Buffer_ID buffer = 0;
@ -167,7 +166,7 @@ CUSTOM_DOC("Begin multi-line mode. In multi-line mode characters are inserted a
i32 pos = cursor.character - 1;
for (i32 i = rect.line0; i <= rect.line1; ++i){
pad_buffer_line(app, &global_part, buffer, i, ' ', pos);
pad_buffer_line(app, buffer, i, ' ', pos);
}
i32 line_count = rect.line1 - rect.line0 + 1;
@ -179,8 +178,9 @@ CUSTOM_DOC("Begin multi-line mode. In multi-line mode characters are inserted a
if (in.key.character && key_is_unmodified(&in.key)){
char str = (char)in.key.character;
Temp_Memory temp = begin_temp_memory(part);
Buffer_Edit *edit = push_array(part, Buffer_Edit, line_count);
Arena *scratch = context_get_arena(app);
Temp_Memory temp = begin_temp(scratch);
Buffer_Edit *edit = push_array(scratch, Buffer_Edit, line_count);
Buffer_Edit *edits = edit;
for (i32 i = rect.line0; i <= rect.line1; ++i){
@ -197,7 +197,7 @@ CUSTOM_DOC("Begin multi-line mode. In multi-line mode characters are inserted a
i32 edit_count = (int)(edit - edits);
buffer_batch_edit(app, buffer, &str, edits, edit_count);
end_temp_memory(temp);
end_temp(temp);
++pos;
@ -205,8 +205,9 @@ CUSTOM_DOC("Begin multi-line mode. In multi-line mode characters are inserted a
}
else if (in.key.keycode == key_back){
if (pos > 0){
Temp_Memory temp = begin_temp_memory(part);
Buffer_Edit *edit = push_array(part, Buffer_Edit, line_count);
Arena *scratch = context_get_arena(app);
Temp_Memory temp = begin_temp(scratch);
Buffer_Edit *edit = push_array(scratch, Buffer_Edit, line_count);
Buffer_Edit *edits = edit;
for (i32 i = rect.line0; i <= rect.line1; ++i){
@ -223,7 +224,7 @@ CUSTOM_DOC("Begin multi-line mode. In multi-line mode characters are inserted a
i32 edit_count = (int)(edit - edits);
buffer_batch_edit(app, buffer, 0, edits, edit_count);
end_temp_memory(temp);
end_temp(temp);
--pos;
}
@ -237,11 +238,15 @@ CUSTOM_DOC("Begin multi-line mode. In multi-line mode characters are inserted a
// NOTE(allen): An experimental mutli-pasting thing
CUSTOM_COMMAND_SIG(multi_paste){
i32 count = clipboard_count(app, 0);
Scratch_Block scratch(app);
i32 count = 0;
clipboard_count(app, 0, &count);
if (count > 0){
View_ID view = 0;
get_active_view(app, AccessOpen, &view);
Managed_Scope scope = view_get_managed_scope(app, view);
Managed_Scope scope = 0;
view_get_managed_scope(app, view, &scope);
u64 rewrite = 0;
managed_variable_get(app, scope, view_rewrite_loc, &rewrite);
@ -252,35 +257,34 @@ CUSTOM_COMMAND_SIG(multi_paste){
i32 paste_index = (i32)prev_paste_index + 1;
managed_variable_set(app, scope, view_paste_index_loc, paste_index);
i32 len = clipboard_index(app, 0, paste_index, 0, 0);
String_Const_u8 string = {};
clipboard_index(app, 0, paste_index, scratch, &string);
if (len + 1 <= app->memory_size){
char *str = (char*)app->memory;
str[0] = '\n';
clipboard_index(app, 0, paste_index, str + 1, len);
Buffer_ID buffer = 0;
view_get_buffer(app, view, AccessOpen, &buffer);
Range range = get_view_range(app, view);
buffer_replace_range(app, buffer, make_range(range.max), make_string(str, len + 1));
view_set_mark(app, view, seek_pos(range.max + 1));
view_set_cursor(app, view, seek_pos(range.max + len + 1), true);
// TODO(allen): Send this to all views.
Theme_Color paste;
paste.tag = Stag_Paste;
get_theme_colors(app, &paste, 1);
view_post_fade(app, view, 0.667f, range.max + 1, range.max + len + 1, paste.color);
}
String_Const_u8 insert_string = string_u8_pushf(scratch, "\n%.*s", string_expand(string));
Buffer_ID buffer = 0;
view_get_buffer(app, view, AccessOpen, &buffer);
Range range = get_view_range(app, view);
buffer_replace_range(app, buffer, make_range(range.max), insert_string);
view_set_mark(app, view, seek_pos(range.max + 1));
view_set_cursor(app, view, seek_pos((i32)(range.max + insert_string.size)), true);
// TODO(allen): Send this to all views.
Theme_Color paste = {};
paste.tag = Stag_Paste;
get_theme_colors(app, &paste, 1);
view_post_fade(app, view, 0.667f, range.max + 1, (i32)(range.max + insert_string.size), paste.color);
}
else{
exec_command(app, paste);
paste(app);
}
}
}
static Range
multi_paste_range(Application_Links *app, View_ID view, Range range, i32 paste_count, b32 old_to_new){
Scratch_Block scratch(app);
Range finish_range = range;
if (paste_count >= 1){
Buffer_ID buffer = 0;
@ -292,31 +296,31 @@ multi_paste_range(Application_Links *app, View_ID view, Range range, i32 paste_c
total_size -= 1;
if (total_size <= app->memory_size){
char *str = (char*)app->memory;
i32 position = 0;
i32 first = paste_count - 1;
i32 one_past_last = -1;
i32 step = -1;
if (!old_to_new){
first = 0;
one_past_last = paste_count;
step = 1;
}
List_String_Const_u8 list = {};
for (i32 paste_index = first; paste_index != one_past_last; paste_index += step){
if (paste_index != first){
str[position] = '\n';
++position;
string_list_push(scratch, &list, SCu8("\n", 1));
}
String_Const_u8 string = {};
if (clipboard_index(app, 0, paste_index, scratch, &string)){
string_list_push(scratch, &list, string);
}
i32 len = clipboard_index(app, 0, paste_index, str + position, total_size - position);
position += len;
}
String_Const_u8 flattened = string_list_flatten(scratch, list);
i32 pos = range.min;
buffer_replace_range(app, buffer, range, make_string(str, total_size));
buffer_replace_range(app, buffer, range, flattened);
finish_range.min = pos;
finish_range.max = pos + total_size;
view_set_mark(app, view, seek_pos(finish_range.min));
@ -347,7 +351,7 @@ multi_paste_interactive_up_down(Application_Links *app, i32 paste_count, i32 cli
range = multi_paste_range(app, view, range, paste_count, old_to_new);
Query_Bar bar = {};
bar.prompt = make_lit_string("Up and Down to condense and expand paste stages; R to reverse order; Return to finish; Escape to abort.");
bar.prompt = string_u8_litexpr("Up and Down to condense and expand paste stages; R to reverse order; Return to finish; Escape to abort.");
if (start_query_bar(app, &bar, 0) == 0) return;
User_Input in = {};
@ -384,34 +388,31 @@ multi_paste_interactive_up_down(Application_Links *app, i32 paste_count, i32 cli
if (in.abort){
Buffer_ID buffer = 0;
view_get_buffer(app, view, AccessOpen, &buffer);
buffer_replace_range(app, buffer, range, make_lit_string(""));
buffer_replace_range(app, buffer, range, SCu8(""));
}
}
CUSTOM_COMMAND_SIG(multi_paste_interactive){
i32 clip_count = clipboard_count(app, 0);
i32 clip_count = 0;
clipboard_count(app, 0, &clip_count);
if (clip_count > 0){
multi_paste_interactive_up_down(app, 1, clip_count);
}
}
CUSTOM_COMMAND_SIG(multi_paste_interactive_quick){
i32 clip_count = clipboard_count(app, 0);
i32 clip_count = 0;
clipboard_count(app, 0, &clip_count);
if (clip_count > 0){
char string_space[256];
u8 string_space[256];
Query_Bar bar = {};
bar.prompt = make_lit_string("How Many Slots To Paste: ");
bar.string = make_fixed_width_string(string_space);
bar.prompt = string_u8_litexpr("How Many Slots To Paste: ");
bar.string = SCu8(string_space, (umem)0);
bar.string_capacity = sizeof(string_space);
query_user_number(app, &bar);
i32 initial_paste_count = str_to_int_s(bar.string);
if (initial_paste_count > clip_count){
initial_paste_count = clip_count;
}
if (initial_paste_count < 1){
initial_paste_count = 1;
}
i32 initial_paste_count = (i32)string_to_integer(bar.string, 10);
initial_paste_count = clamp(1, initial_paste_count, clip_count);
end_query_bar(app, &bar, 0);
multi_paste_interactive_up_down(app, initial_paste_count, clip_count);
@ -430,9 +431,8 @@ CUSTOM_DOC("If the cursor is found to be on the name of a function parameter in
i32 cursor_pos = 0;
view_get_cursor_pos(app, view, &cursor_pos);
Partition *part = &global_part;
Temp_Memory temp = begin_temp_memory(part);
Arena *scratch = context_get_arena(app);
Temp_Memory temp = begin_temp(scratch);
Cpp_Get_Token_Result result;
if (buffer_get_token_index(app, buffer, cursor_pos, &result)){
@ -446,123 +446,113 @@ CUSTOM_DOC("If the cursor is found to be on the name of a function parameter in
Cpp_Token token = stream.tokens[token_index];
if (token.type == CPP_TOKEN_IDENTIFIER){
Cpp_Token original_token = token;
String_Const_u8 old_lexeme = scratch_read(app, scratch, buffer, token);
char old_lexeme_base[128];
String old_lexeme = make_fixed_width_string(old_lexeme_base);
i32 proc_body_found = 0;
b32 still_looping = 0;
if (token.size < sizeof(old_lexeme_base)){
Cpp_Token original_token = token;
old_lexeme.size = token.size;
buffer_read_range(app, buffer, token.start, token.start+token.size, old_lexeme.str);
++token_index;
do{
for (; token_index < stream.end; ++token_index){
Cpp_Token *token_ptr = stream.tokens + token_index;
switch (token_ptr->type){
case CPP_TOKEN_BRACE_OPEN:
{
proc_body_found = 1;
goto doublebreak;
}break;
case CPP_TOKEN_BRACE_CLOSE:
case CPP_TOKEN_PARENTHESE_OPEN:
{
goto doublebreak;
}break;
}
}
still_looping = forward_stream_tokens(&stream);
}while(still_looping);
doublebreak:;
if (proc_body_found){
i32 proc_body_found = 0;
b32 still_looping = 0;
u8 with_space[1024];
Query_Bar with = {};
with.prompt = string_u8_litexpr("New Name: ");
with.string = SCu8(with_space, (umem)0);
with.string_capacity = sizeof(with_space);
if (!query_user_string(app, &with)) return;
String_Const_u8 replace_string = with.string;
// TODO(allen): fix this up to work with arena better
i32 edit_max = Thousand(100);
Buffer_Edit *edits = push_array(scratch, Buffer_Edit, edit_max);
i32 edit_count = 0;
if (edit_max >= 1){
Buffer_Edit edit = {};
edit.str_start = 0;
edit.len = (i32)replace_string.size;
edit.start = original_token.start;
edit.end = original_token.start + original_token.size;
edits[edit_count] = edit;
edit_count += 1;
}
i32 nesting_level = 0;
i32 closed_correctly = 0;
++token_index;
still_looping = 0;
do{
for (; token_index < stream.end; ++token_index){
Cpp_Token *token_ptr = stream.tokens + token_index;
switch (token_ptr->type){
case CPP_TOKEN_IDENTIFIER:
{
if (token_ptr->size == old_lexeme.size){
String_Const_u8 other_lexeme = scratch_read(app, scratch, buffer, *token_ptr);
if (string_match(old_lexeme, other_lexeme)){
Buffer_Edit edit = {};
edit.str_start = 0;
edit.len = (i32)replace_string.size;
edit.start = token_ptr->start;
edit.end = token_ptr->start + token_ptr->size;
if (edit_count < edit_max){
edits[edit_count] = edit;
edit_count += 1;
}
else{
goto doublebreak2;
}
}
}
}break;
case CPP_TOKEN_BRACE_OPEN:
{
proc_body_found = 1;
goto doublebreak;
++nesting_level;
}break;
case CPP_TOKEN_BRACE_CLOSE:
case CPP_TOKEN_PARENTHESE_OPEN:
{
goto doublebreak;
if (nesting_level == 0){
closed_correctly = 1;
goto doublebreak2;
}
else{
--nesting_level;
}
}break;
}
}
still_looping = forward_stream_tokens(&stream);
}while(still_looping);
doublebreak:;
doublebreak2:;
if (proc_body_found){
Query_Bar with;
char with_space[1024];
with.prompt = make_lit_string("New Name: ");
with.string = make_fixed_width_string(with_space);
if (!query_user_string(app, &with)) return;
String replace_string = with.string;
Buffer_Edit *edits = push_array(part, Buffer_Edit, 0);
i32 edit_max = (part_remaining(part))/sizeof(Buffer_Edit);
i32 edit_count = 0;
if (edit_max >= 1){
Buffer_Edit edit;
edit.str_start = 0;
edit.len = replace_string.size;
edit.start = original_token.start;
edit.end = original_token.start + original_token.size;
edits[edit_count] = edit;
++edit_count;
}
i32 nesting_level = 0;
i32 closed_correctly = 0;
++token_index;
still_looping = 0;
do{
for (; token_index < stream.end; ++token_index){
Cpp_Token *token_ptr = stream.tokens + token_index;
switch (token_ptr->type){
case CPP_TOKEN_IDENTIFIER:
{
if (token_ptr->size == old_lexeme.size){
char other_lexeme_base[128];
String other_lexeme = make_fixed_width_string(other_lexeme_base);
other_lexeme.size = old_lexeme.size;
buffer_read_range(app, buffer, token_ptr->start, token_ptr->start+token_ptr->size, other_lexeme.str);
if (match(old_lexeme, other_lexeme)){
Buffer_Edit edit;
edit.str_start = 0;
edit.len = replace_string.size;
edit.start = token_ptr->start;
edit.end = token_ptr->start + token_ptr->size;
if (edit_count < edit_max){
edits[edit_count] = edit;
++edit_count;
}
else{
goto doublebreak2;
}
}
}
}break;
case CPP_TOKEN_BRACE_OPEN:
{
++nesting_level;
}break;
case CPP_TOKEN_BRACE_CLOSE:
{
if (nesting_level == 0){
closed_correctly = 1;
goto doublebreak2;
}
else{
--nesting_level;
}
}break;
}
}
still_looping = forward_stream_tokens(&stream);
}while(still_looping);
doublebreak2:;
if (closed_correctly){
buffer_batch_edit(app, buffer, replace_string.str, edits, edit_count);
}
if (closed_correctly){
buffer_batch_edit(app, buffer, (char*)replace_string.str, edits, edit_count);
}
}
}
@ -570,7 +560,7 @@ CUSTOM_DOC("If the cursor is found to be on the name of a function parameter in
}
}
end_temp_memory(temp);
end_temp(temp);
}
typedef u32 Write_Explicit_Enum_Values_Mode;
@ -589,9 +579,8 @@ write_explicit_enum_values_parameters(Application_Links *app, Write_Explicit_Enu
i32 pos = 0;
view_get_cursor_pos(app, view, &pos);
Partition *part = &global_part;
Temp_Memory temp = begin_temp_memory(part);
Arena *scratch = context_get_arena(app);
Temp_Memory temp = begin_temp(scratch);
Cpp_Get_Token_Result result;
if (buffer_get_token_index(app, buffer, pos, &result)){
@ -632,10 +621,9 @@ write_explicit_enum_values_parameters(Application_Links *app, Write_Explicit_Enu
i32 count_estimate = 1 + (seeker_index - token_index)/2;
i32 edit_count = 0;
Buffer_Edit *edits = push_array(part, Buffer_Edit, count_estimate);
Buffer_Edit *edits = push_array(scratch, Buffer_Edit, count_estimate);
char *string_base = push_array(part, char, 0);
String string = make_string(string_base, 0, part_remaining(part));
List_String_Const_char list = {};
closed_correctly = false;
still_looping = false;
@ -680,24 +668,27 @@ write_explicit_enum_values_parameters(Application_Links *app, Write_Explicit_Enu
good_edit:;
if (edit_is_good){
i32 str_pos = string.size;
i32 str_pos = (i32)(list.total_size);
append(&string, " = ");
append_int_to_str(&string, value);
string_list_pushf(scratch, &list, " = %d", value);
if (closed_correctly){
append(&string, "\n");
string_list_push_lit(scratch, &list, "\n");
}
if (mode == WriteExplicitEnumValues_Integers){
++value;
}
else if (mode == WriteExplicitEnumValues_Flags){
if (value < (1 << 31)){
value <<= 1;
}
switch (mode){
case WriteExplicitEnumValues_Integers:
{
++value;
}break;
case WriteExplicitEnumValues_Flags:
{
if (value < (1 << 31)){
value <<= 1;
}
}break;
}
i32 str_size = string.size - str_pos;
i32 str_size = (i32)(list.total_size) - str_pos;
Buffer_Edit edit;
edit.str_start = str_pos;
@ -727,7 +718,8 @@ write_explicit_enum_values_parameters(Application_Links *app, Write_Explicit_Enu
finished:;
if (closed_correctly){
buffer_batch_edit(app, buffer, string_base, edits, edit_count);
String_Const_char text = string_list_flatten(scratch, list);
buffer_batch_edit(app, buffer, text.str, edits, edit_count);
}
}
}
@ -735,7 +727,7 @@ write_explicit_enum_values_parameters(Application_Links *app, Write_Explicit_Enu
}
}
end_temp_memory(temp);
end_temp(temp);
}
CUSTOM_COMMAND_SIG(write_explicit_enum_values)
@ -755,91 +747,85 @@ CUSTOM_DOC("If the cursor is found to be on the '{' of an enum definition, the v
//
struct Replace_Target{
Replace_Target *next;
Buffer_ID buffer_id;
i32 start_pos;
};
static void
replace_all_occurrences_parameters(Application_Links *app, Heap *heap, Partition *part, String target_string, String new_string){
if (target_string.size <= 0) return;
global_history_edit_group_begin(app);
for (b32 got_all_occurrences = false;
!got_all_occurrences;){
replace_all_occurrences_parameters(Application_Links *app, Heap *heap, String_Const_u8 target_string, String_Const_u8 new_string){
if (target_string.size > 0){
global_history_edit_group_begin(app);
// Initialize a generic search all buffers
Search_Set set = {};
Search_Iter iter = {};
initialize_generic_search_all_buffers(app, heap, &target_string, 1, SearchFlag_MatchSubstring, 0, 0, &set, &iter);
// Visit all locations and create replacement list
Temp_Memory temp = begin_temp_memory(part);
Replace_Target *targets = push_array(part, Replace_Target, 0);
Arena *scratch = context_get_arena(app);
Temp_Memory temp = begin_temp(scratch);
Replace_Target *target_first = 0;
Replace_Target *target_last = 0;
i32 target_count = 0;
got_all_occurrences = true;
for (Search_Match match = search_next_match(app, &set, &iter);
match.found_match;
match = search_next_match(app, &set, &iter)){
Replace_Target *new_target = push_array(part, Replace_Target, 1);
if (new_target != 0){
new_target->buffer_id = match.buffer;
new_target->start_pos = match.start;
++target_count;
}
else{
if (!has_substr(new_string, target_string)){
got_all_occurrences = false;
}
else{
print_message(app, literal("Could not replace all occurrences, ran out of memory\n"));
}
break;
}
Replace_Target *new_target = push_array(scratch, Replace_Target, 1);
sll_queue_push(target_first, target_last, new_target);
++target_count;
new_target->buffer_id = match.buffer;
new_target->start_pos = match.start;
}
// Use replacement list to do replacements
i32 shift_per_replacement = new_string.size - target_string.size;
i32 current_offset = 0;
i32 current_buffer_id = 0;
Replace_Target *target = targets;
for (i32 i = 0; i < target_count; ++i, ++target){
imem shift_per_replacement = new_string.size - target_string.size;
imem current_offset = 0;
Buffer_ID current_buffer_id = 0;
for (Replace_Target *target = target_first;
target != 0;
target = target->next){
if (target->buffer_id != current_buffer_id){
current_buffer_id = target->buffer_id;
current_offset = 0;
}
i32 pos = target->start_pos + current_offset;
buffer_replace_range(app, target->buffer_id, make_range(pos, pos + target_string.size), new_string);
i32 pos = target->start_pos + (i32)current_offset;
buffer_replace_range(app, target->buffer_id, make_range(pos, pos + (i32)target_string.size), new_string);
current_offset += shift_per_replacement;
}
end_temp_memory(temp);
end_temp(temp);
global_history_edit_group_end(app);
}
global_history_edit_group_end(app);
}
CUSTOM_COMMAND_SIG(replace_all_occurrences)
CUSTOM_DOC("Queries the user for two strings, and replaces all occurrences of the first string with the second string in all open buffers.")
{
Query_Bar replace;
char replace_space[1024];
replace.prompt = make_lit_string("Replace (In All Buffers): ");
replace.string = make_fixed_width_string(replace_space);
u8 replace_space[1024];
Query_Bar replace = {};
replace.prompt = string_u8_litexpr("Replace (In All Buffers): ");
replace.string = SCu8(replace_space, (umem)0);
replace.string_capacity = sizeof(replace_space);
Query_Bar with;
char with_space[1024];
with.prompt = make_lit_string("With: ");
with.string = make_fixed_width_string(with_space);
u8 with_space[1024];
Query_Bar with = {};
with.prompt = string_u8_litexpr("With: ");
with.string = SCu8(with_space, (umem)0);
with.string_capacity = sizeof(with_space);
if (!query_user_string(app, &replace)) return;
if (replace.string.size == 0) return;
if (!query_user_string(app, &with)) return;
String r = replace.string;
String w = with.string;
replace_all_occurrences_parameters(app, &global_heap, &global_part, r, w);
String_Const_u8 r = replace.string;
String_Const_u8 w = with.string;
replace_all_occurrences_parameters(app, &global_heap, r, w);
}
extern "C" i32

View File

@ -90,49 +90,45 @@ fancy_string_list_push(Fancy_String_List *list, Fancy_String *string){
}
static Fancy_String *
push_fancy_string(Arena *arena, Fancy_String_List *list, Fancy_Color fore, Fancy_Color back, String value){
Fancy_String *result = push_array(arena, Fancy_String, 1);
memset(result, 0, sizeof(*result));
result->value = string_push_copy(arena, value);
push_fancy_string(Arena *arena, Fancy_String_List *list, Fancy_Color fore, Fancy_Color back, String_Const_u8 value){
Fancy_String *result = push_array_zero(arena, Fancy_String, 1);
result->value = string_copy(arena, value);
result->fore = fore;
result->back = back;
if (list != 0){
fancy_string_list_push(list, result);
}
return(result);
}
static Fancy_String *
push_fancy_string(Arena *arena, Fancy_Color fore, Fancy_Color back, String value){
push_fancy_string(Arena *arena, Fancy_Color fore, Fancy_Color back, String_Const_u8 value){
return(push_fancy_string(arena, 0, fore, back, value));
}
static Fancy_String *
push_fancy_string(Arena *arena, Fancy_String_List *list, Fancy_Color fore, String value){
push_fancy_string(Arena *arena, Fancy_String_List *list, Fancy_Color fore, String_Const_u8 value){
return(push_fancy_string(arena, list, fore, fancy_pass_through(), value));
}
static Fancy_String *
push_fancy_string(Arena *arena, Fancy_Color fore, String value){
push_fancy_string(Arena *arena, Fancy_Color fore, String_Const_u8 value){
return(push_fancy_string(arena, 0, fore, fancy_pass_through(), value));
}
static Fancy_String *
push_fancy_string(Arena *arena, Fancy_String_List *list, String value){
push_fancy_string(Arena *arena, Fancy_String_List *list, String_Const_u8 value){
return(push_fancy_string(arena, list, fancy_pass_through(), fancy_pass_through(), value));
}
static Fancy_String *
push_fancy_string(Arena *arena, String value){
push_fancy_string(Arena *arena, String_Const_u8 value){
return(push_fancy_string(arena, 0, fancy_pass_through(), fancy_pass_through(), value));
}
static Fancy_String*
push_fancy_stringfv(Arena *arena, Fancy_String_List *list, Fancy_Color fore, Fancy_Color back, char *format, va_list args){
String str = string_push_fv(arena, format, args);
String_Const_u8 str = string_u8_pushfv(arena, format, args);
Fancy_String *result = 0;
if (str.size > 0){
result = push_fancy_string(arena, list, fore, back, str);

View File

@ -38,7 +38,7 @@ struct Fancy_Color{
struct Fancy_String{
Fancy_String *next;
String value;
String_Const_u8 value;
Face_ID font_id;
Fancy_Color fore;

View File

@ -10,7 +10,7 @@
#include "4coder_lib/4coder_arena.h"
#include "4coder_lib/4coder_arena.cpp"
#include "4coder_os_comp_cracking.h"
#include "4coder_base_types.h"
#define FSTRING_IMPLEMENTATION
#include "4coder_lib/4coder_string.h"
@ -18,9 +18,7 @@
#include <stdlib.h>
#include <string.h>
typedef int32_t bool32;
#if defined(IS_WINDOWS)
#if OS_WINDOWS
//// WINDOWS BEGIN ////
#define UNICODE
@ -29,7 +27,7 @@ typedef TCHAR Filename_Character;
#define SLASH '\\'
//// WINDOWS END ////
#elif defined(IS_LINUX) || defined(IS_MAC)
#elif OS_LINUX || OS_MAC
//// UNIX BEGIN ////
#include <sys/types.h>
@ -47,7 +45,7 @@ typedef char Filename_Character;
struct Cross_Platform_File_Info{
Filename_Character *name;
int32_t len;
bool32 is_folder;
b32 is_folder;
};
struct Cross_Platform_File_List{
@ -57,18 +55,17 @@ struct Cross_Platform_File_List{
Filename_Character path_name[4096];
};
typedef bool32 File_Filter(Filename_Character *name, int32_t len);
typedef b32 File_Filter(Filename_Character *name, int32_t len);
static Cross_Platform_File_List
get_file_list(Partition *part, Filename_Character *dir, File_Filter *filter);
get_file_list(Arena *arena, Filename_Character *dir, File_Filter *filter);
static Filename_Character*
encode(Partition *part, char *str){
encode(Arena *arena, char *str){
int32_t size = 0;
for (;str[size]!=0;++size);
Filename_Character *out = push_array(part, Filename_Character, size + 1);
push_align(part, 8);
Filename_Character *out = push_array(arena, Filename_Character, size + 1);
if (out == 0){
fprintf(stdout, "fatal error: ran out of memory encoding string to filename\n");
@ -86,10 +83,9 @@ encode(Partition *part, char *str){
}
static char*
unencode(Partition *part, Filename_Character *str, int32_t len){
Temp_Memory temp = begin_temp_memory(part);
char *out = push_array(part, char, len + 1);
push_align(part, 8);
unencode(Arena *arena, Filename_Character *str, int32_t len){
Temp_Memory temp = begin_temp(arena);
char *out = push_array(arena, char, len + 1);
if (out == 0){
fprintf(stdout, "fatal error: ran out of memory unencoding string to filename\n");
@ -102,7 +98,7 @@ unencode(Partition *part, Filename_Character *str, int32_t len){
}
else{
out = 0;
end_temp_memory(temp);
end_temp(temp);
break;
}
}
@ -110,14 +106,14 @@ unencode(Partition *part, Filename_Character *str, int32_t len){
return(out);
}
static bool32
static b32
filter_all(Filename_Character *name, int32_t len){
return(true);
}
static bool32
static b32
filter_is_code_file(Filename_Character *name, int32_t len){
bool32 is_code = false;
b32 is_code = false;
if (len >= 5){
Filename_Character *ext = &name[len - 4];
if (ext[0] == '.' && ext[1] == 'c' && ext[2] == 'p' && ext[3] == 'p'){
@ -145,12 +141,12 @@ filter_is_code_file(Filename_Character *name, int32_t len){
return(is_code);
}
#if defined(IS_WINDOWS)
#if OS_WINDOWS
//// WINDOWS BEGIN ////
static Cross_Platform_File_List
get_file_list(Partition *part, Filename_Character *pattern, File_Filter *filter){
if (part == 0){
get_file_list(Arena *arena, Filename_Character *pattern, File_Filter *filter){
if (arena == 0){
fprintf(stdout, "fatal error: NULL part passed to %s\n", __FUNCTION__);
exit(1);
}
@ -217,8 +213,8 @@ get_file_list(Partition *part, Filename_Character *pattern, File_Filter *filter)
for(;name[size];++size);
uint32_t attribs = find_data.dwFileAttributes;
bool32 is_folder = ((attribs & FILE_ATTRIBUTE_DIRECTORY) != 0);
bool32 is_hidden = ((attribs & FILE_ATTRIBUTE_HIDDEN) != 0);
b32 is_folder = ((attribs & FILE_ATTRIBUTE_DIRECTORY) != 0);
b32 is_hidden = ((attribs & FILE_ATTRIBUTE_HIDDEN) != 0);
if (!is_hidden){
if (name[0] != '.' && (is_folder || filter(name, size))){
@ -232,11 +228,11 @@ get_file_list(Partition *part, Filename_Character *pattern, File_Filter *filter)
FindClose(search);
Cross_Platform_File_List list = {};
Temp_Memory part_reset = begin_temp_memory(part);
Temp_Memory part_reset = begin_temp(arena);
int32_t rounded_char_size = (character_count*sizeof(Filename_Character) + 7)&(~7);
int32_t memsize = rounded_char_size + file_count*sizeof(Cross_Platform_File_Info);
void *mem = push_array(part, uint8_t, memsize);
void *mem = push_array(arena, u8, memsize);
if (mem == 0){
fprintf(stdout, "fatal error: not enough memory on the partition for a file list.\n");
exit(1);
@ -265,14 +261,14 @@ get_file_list(Partition *part, Filename_Character *pattern, File_Filter *filter)
for(;name[size]!=0;++size);
uint32_t attribs = find_data.dwFileAttributes;
bool32 is_folder = ((attribs & FILE_ATTRIBUTE_DIRECTORY) != 0);
bool32 is_hidden = ((attribs & FILE_ATTRIBUTE_HIDDEN) != 0);
b32 is_folder = ((attribs & FILE_ATTRIBUTE_DIRECTORY) != 0);
b32 is_hidden = ((attribs & FILE_ATTRIBUTE_HIDDEN) != 0);
if (!is_hidden){
if (name[0] != '.' && (is_folder || filter(name, size))){
if (info_ptr + 1 > info_ptr_end || char_ptr + size + 1 > char_ptr_end){
memset(&list, 0, sizeof(list));
end_temp_memory(part_reset);
end_temp(part_reset);
FindClose(search);
return(list);
}
@ -304,12 +300,12 @@ get_file_list(Partition *part, Filename_Character *pattern, File_Filter *filter)
}
//// WINDOWS END ////
#elif defined(IS_LINUX) || defined(IS_MAC)
#elif OS_LINUX || OS_MAC
//// UNIX BEGIN ////
static bool32
static b32
match_pattern(Filename_Character *name, Filename_Character *pattern){
bool32 match = false;
b32 match = false;
if (sizeof(*name) == 1){
Absolutes absolutes = {};
String pattern_str = make_string_slowly(pattern);
@ -380,7 +376,7 @@ get_file_list(Partition *part, Filename_Character *pattern, File_Filter *filter)
int32_t size = 0;
for(;name[size];++size);
bool32 is_folder = false;
b32 is_folder = false;
if (entry->d_type == DT_LNK){
struct stat st;
if (stat(entry->d_name, &st) != -1){
@ -430,7 +426,7 @@ get_file_list(Partition *part, Filename_Character *pattern, File_Filter *filter)
int32_t size = 0;
for(;name[size];++size);
bool32 is_folder = false;
b32 is_folder = false;
if (entry->d_type == DT_LNK){
struct stat st;
if (stat(entry->d_name, &st) != -1){
@ -477,27 +473,23 @@ get_file_list(Partition *part, Filename_Character *pattern, File_Filter *filter)
# error metdata generator not supported on this platform
#endif
static String
file_dump(Partition *part, char *name){
String text = {};
static String_Const_char
file_dump(Arena *arena, char *name){
String_Const_char text = {};
FILE *file = fopen(name, "rb");
if (file != 0){
fseek(file, 0, SEEK_END);
text.size = ftell(file);
fseek(file, 0, SEEK_SET);
text.memory_size = text.size + 1;
text.str = push_array(part, char, text.memory_size);
push_align(part, 8);
text.str = push_array(arena, char, text.size + 1);
if (text.str == 0){
fprintf(stdout, "fatal error: not enough memory in partition for file dumping");
exit(1);
}
fread(text.str, 1, text.size, file);
terminate_with_null(&text);
text.str[text.size] = 0;
fclose(file);
}
return(text);
}

View File

@ -4,6 +4,7 @@
// TOP
// TODO(allen): transition wrappers
static Face_Description
get_buffer_face_description(Application_Links *app, Buffer_ID buffer){
Face_ID current_id = 0;
@ -17,7 +18,8 @@ get_buffer_face_description(Application_Links *app, Buffer_ID buffer){
static Face_Description
get_global_face_description(Application_Links *app){
Face_ID current_id = get_face_id(app, 0);
Face_ID current_id = 0;
get_face_id(app, 0, &current_id);
Face_Description description = get_face_description(app, current_id);
return(description);
}
@ -25,7 +27,7 @@ get_global_face_description(Application_Links *app){
static b32
descriptions_match(Face_Description *a, Face_Description *b){
b32 result = false;
if (match(a->font.name, b->font.name) && a->font.in_local_font_folder == b->font.in_local_font_folder){
if (string_match(SCchar(a->font.name), SCchar(b->font.name)) && a->font.in_local_font_folder == b->font.in_local_font_folder){
if (memcmp((&a->pt_size), (&b->pt_size), sizeof(*a) - sizeof(a->font)) == 0){
result = true;
}
@ -34,13 +36,12 @@ descriptions_match(Face_Description *a, Face_Description *b){
}
static Face_ID
get_existing_face_id_matching_name(Application_Links *app, char *name, i32 len){
String name_str = make_string(name, len);
get_existing_face_id_matching_name(Application_Links *app, String_Const_u8 name){
Face_ID largest_id = get_largest_face_id(app);
Face_ID result = 0;
for (Face_ID id = 1; id <= largest_id; ++id){
Face_Description compare = get_face_description(app, id);
if (match(compare.font.name, name_str)){
if (string_match(SCu8(compare.font.name), name)){
result = id;
break;
}
@ -63,15 +64,15 @@ get_existing_face_id_matching_description(Application_Links *app, Face_Descripti
}
static Face_ID
get_face_id_by_name(Application_Links *app, char *name, i32 len, Face_Description *base_description){
get_face_id_by_name(Application_Links *app, String_Const_u8 name, Face_Description *base_description){
Face_ID new_id = 0;
String str = make_string(name, len);
if (!match(str, base_description->font.name)){
new_id = get_existing_face_id_matching_name(app, name, len);
name.size = clamp_top(name.size, sizeof(base_description->font.name) - 1);
if (!string_match(name, SCu8(base_description->font.name))){
new_id = get_existing_face_id_matching_name(app, name);
if (new_id == 0){
Face_Description description = *base_description;
copy_fast_unsafe_cs(description.font.name, str);
description.font.name[str.size] = 0;
block_copy(description.font.name, name.str, name.size);
description.font.name[name.size] = 0;
description.font.in_local_font_folder = false;
new_id = try_create_new_face(app, &description);
if (new_id == 0){
@ -96,10 +97,11 @@ get_face_id_by_description(Application_Links *app, Face_Description *description
}
static void
set_global_face_by_name(Application_Links *app, char *name, i32 len, b32 apply_to_all_buffers){
Face_ID global_face_id = get_face_id(app, 0);
set_global_face_by_name(Application_Links *app, String_Const_u8 name, b32 apply_to_all_buffers){
Face_ID global_face_id = 0;
get_face_id(app, 0, &global_face_id);
Face_Description description = get_face_description(app, global_face_id);
Face_ID new_id = get_face_id_by_name(app, name, len, &description);
Face_ID new_id = get_face_id_by_name(app, name, &description);
if (new_id != 0){
set_global_face(app, new_id, apply_to_all_buffers);
}
@ -107,7 +109,8 @@ set_global_face_by_name(Application_Links *app, char *name, i32 len, b32 apply_t
static void
change_global_face_by_description(Application_Links *app, Face_Description description, b32 apply_to_all_buffers){
Face_ID face_id = get_face_id(app, 0);
Face_ID face_id = 0;
get_face_id(app, 0, &face_id);
if (!try_modify_face(app, face_id, &description)){
description.font.in_local_font_folder = !description.font.in_local_font_folder;
try_modify_face(app, face_id, &description);
@ -115,12 +118,12 @@ change_global_face_by_description(Application_Links *app, Face_Description descr
}
static void
set_buffer_face_by_name(Application_Links *app, Buffer_ID buffer, char *name, i32 len){
set_buffer_face_by_name(Application_Links *app, Buffer_ID buffer, String_Const_u8 name){
Face_ID current_id = 0;
get_face_id(app, buffer, &current_id);
if (current_id != 0){
Face_Description description = get_face_description(app, current_id);
Face_ID new_id = get_face_id_by_name(app, name, len, &description);
Face_ID new_id = get_face_id_by_name(app, name, &description);
if (new_id != 0){
buffer_set_face(app, buffer, new_id);
}

View File

@ -10,53 +10,6 @@
// iterating tokens is now.
//
static Buffered_Write_Stream
make_buffered_write_stream(Buffer_ID output_buffer_id, Partition *buffering_arena){
Buffered_Write_Stream stream = {};
stream.output_buffer_id = output_buffer_id;
stream.buffering_arena = buffering_arena;
stream.buffer = push_array(buffering_arena, char, 0);
return(stream);
}
static void
buffered_write_stream_flush(Application_Links *app, Buffered_Write_Stream *stream){
Buffer_ID buffer = stream->output_buffer_id;
i32 buffer_size = 0;
buffer_get_size(app, buffer, &buffer_size);
i32 stream_size = (i32)(push_array(stream->buffering_arena, char, 0) - stream->buffer);
buffer_replace_range(app, buffer, make_range(buffer_size), make_string(stream->buffer, stream_size));
stream->buffering_arena->pos -= stream_size;
}
static void
buffered_write_stream_write(Application_Links *app, Buffered_Write_Stream *stream, String text){
for (;text.size > 0;){
char *buffered = push_array(stream->buffering_arena, char, text.size);
if (buffered != 0){
memcpy(buffered, text.str, text.size);
text.size = 0;
}
else{
i32 partial_size = part_remaining(stream->buffering_arena);
buffered = push_array(stream->buffering_arena, char, partial_size);
Assert(partial_size < text.size);
memcpy(buffered, text.str, partial_size);
text.size -= partial_size;
text.str += partial_size;
buffered_write_stream_flush(app, stream);
}
}
}
static void
buffered_write_stream_write_int(Application_Links *app, Buffered_Write_Stream *stream, i32 x){
char space[128];
String integer_string = make_fixed_width_string(space);
append_int_to_str(&integer_string, x);
buffered_write_stream_write(app, stream, integer_string);
}
static Get_Positions_Results
get_function_positions(Application_Links *app, Buffer_ID buffer, i32 first_token_index, Function_Positions *positions_array, i32 positions_max){
Get_Positions_Results result = {};
@ -188,11 +141,13 @@ get_function_positions(Application_Links *app, Buffer_ID buffer, i32 first_token
}
static void
print_positions_buffered(Application_Links *app, Buffer_ID buffer, Function_Positions *positions_array, i32 positions_count, Buffered_Write_Stream *stream){
print_positions_buffered(Application_Links *app, Buffer_Insertion *out, Function_Positions *positions_array, i32 positions_count){
Arena *scratch = context_get_arena(app);
Temp_Memory_Arena temp = begin_temp_memory(scratch);
Temp_Memory temp = begin_temp(scratch);
String buffer_name = buffer_push_unique_buffer_name(app, buffer, scratch);
Buffer_ID buffer = out->buffer;
String_Const_u8 buffer_name = buffer_push_unique_buffer_name(app, buffer, scratch);
for (i32 i = 0; i < positions_count; ++i){
Function_Positions *positions = &positions_array[i];
@ -206,10 +161,7 @@ print_positions_buffered(Application_Links *app, Buffer_ID buffer, Function_Posi
Token_Range token_range = buffer_get_token_range(app, buffer);
if (token_range.first != 0){
buffered_write_stream_write(app, stream, buffer_name);
buffered_write_stream_write(app, stream, make_lit_string(":"));
buffered_write_stream_write_int(app, stream, line_number);
buffered_write_stream_write(app, stream, make_lit_string(": "));
insertf(out, "%.*s:%d: ", string_expand(buffer_name), line_number);
Cpp_Token prev_token = {};
Token_Iterator token_it = make_token_iterator(token_range, start_index);
@ -217,13 +169,6 @@ print_positions_buffered(Application_Links *app, Buffer_ID buffer, Function_Posi
token != 0 && token_iterator_current_index(&token_it) <= end_index;
token = token_iterator_goto_next_raw(&token_it)){
if ((token->flags & CPP_TFLAG_PP_BODY) == 0 && token->type != CPP_TOKEN_COMMENT){
char space[2 << 10];
i32 token_size = token->size;
if (token_size > sizeof(space)){
token_size = sizeof(space);
}
buffer_read_range(app, buffer, token->start, token->start + token_size, space);
if ((prev_token.type == CPP_TOKEN_IDENTIFIER ||
prev_token.type == CPP_TOKEN_STAR ||
prev_token.type == CPP_TOKEN_COMMA ||
@ -234,24 +179,29 @@ print_positions_buffered(Application_Links *app, Buffer_ID buffer, Function_Posi
token->type == CPP_TOKEN_COMMA
)
){
buffered_write_stream_write(app, stream, make_lit_string(" "));
insertc(out, ' ');
}
buffered_write_stream_write(app, stream, make_string(space, token_size));
Temp_Memory token_temp = begin_temp(scratch);
String_Const_u8 lexeme = get_token_lexeme(app, scratch, buffer, *token);
insert_string(out, lexeme);
end_temp(token_temp);
prev_token = *token;
}
}
buffered_write_stream_write(app, stream, make_lit_string("\n"));
insertc(out, '\n');
}
}
end_temp_memory(temp);
end_temp(temp);
}
static void
list_all_functions(Application_Links *app, Partition *part, Buffer_ID optional_target_buffer){
String decls_name = make_lit_string("*decls*");
list_all_functions(Application_Links *app, Buffer_ID optional_target_buffer){
// TODO(allen): Use create or switch to buffer and clear here?
String_Const_u8 decls_name = string_u8_litexpr("*decls*");
Buffer_ID decls_buffer = 0;
get_buffer_by_name(app, decls_name, AccessAll, &decls_buffer);
if (!buffer_exists(app, decls_buffer)){
@ -264,15 +214,18 @@ list_all_functions(Application_Links *app, Partition *part, Buffer_ID optional_t
buffer_send_end_signal(app, decls_buffer);
i32 size = 0;
buffer_get_size(app, decls_buffer, &size);
buffer_replace_range(app, decls_buffer, make_range(0, size), make_lit_string(""));
buffer_replace_range(app, decls_buffer, make_range(0, size), string_u8_litexpr(""));
}
Temp_Memory temp = begin_temp_memory(part);
Arena *scratch = context_get_arena(app);
Temp_Memory temp = begin_temp(scratch);
// TODO(allen): rewrite get_function_positions to allocate on arena
i32 positions_max = (4<<10)/sizeof(Function_Positions);
Function_Positions *positions_array = push_array(part, Function_Positions, positions_max);
Function_Positions *positions_array = push_array(scratch, Function_Positions, positions_max);
Buffered_Write_Stream buffered_write_stream = make_buffered_write_stream(decls_buffer, part);
Cursor insertion_cursor = make_cursor(push_array(scratch, u8, KB(256)), KB(256));
Buffer_Insertion out = begin_buffer_insertion_at_buffered(app, decls_buffer, 0, &insertion_cursor);
Buffer_ID buffer_it = 0;
for (get_buffer_next(app, 0, AccessAll, &buffer_it);
@ -293,8 +246,7 @@ list_all_functions(Application_Links *app, Partition *part, Buffer_ID optional_t
token_index = get_positions_results.next_token_index;
still_looping = get_positions_results.still_looping;
print_positions_buffered(app, buffer, positions_array, positions_count, &buffered_write_stream);
//print_positions(app, &buffer, positions_array, positions_count, &decls_buffer, part);
print_positions_buffered(app, &out, positions_array, positions_count);
}while(still_looping);
if (optional_target_buffer != 0){
@ -306,15 +258,15 @@ list_all_functions(Application_Links *app, Partition *part, Buffer_ID optional_t
}
}
buffered_write_stream_flush(app, &buffered_write_stream);
end_buffer_insertion(&out);
View_ID view = 0;
get_active_view(app, AccessAll, &view);
view_set_buffer(app, view, decls_buffer, 0);
lock_jump_buffer(decls_name.str, decls_name.size);
lock_jump_buffer(decls_name);
end_temp_memory(temp);
end_temp(temp);
}
@ -326,7 +278,7 @@ CUSTOM_DOC("Creates a jump list of lines of the current buffer that appear to de
Buffer_ID buffer = 0;
view_get_buffer(app, view, AccessProtected, &buffer);
if (buffer_exists(app, buffer)){
list_all_functions(app, &global_part, buffer);
list_all_functions(app, buffer);
}
}
@ -338,27 +290,27 @@ CUSTOM_DOC("Creates a lister of locations that look like function definitions an
Buffer_ID buffer = 0;
view_get_buffer(app, view, AccessProtected, &buffer);
if (buffer_exists(app, buffer)){
list_all_functions(app, &global_part, buffer);
list_all_functions(app, buffer);
get_active_view(app, AccessAll, &view);
open_jump_lister(app, &global_part, &global_heap, view, buffer, JumpListerActivation_OpenInUIView, 0);
open_jump_lister(app, &global_heap, view, buffer, JumpListerActivation_OpenInUIView, 0);
}
}
CUSTOM_COMMAND_SIG(list_all_functions_all_buffers)
CUSTOM_DOC("Creates a jump list of lines from all buffers that appear to define or declare functions.")
{
list_all_functions(app, &global_part, 0);
list_all_functions(app, 0);
}
CUSTOM_COMMAND_SIG(list_all_functions_all_buffers_lister)
CUSTOM_DOC("Creates a lister of locations that look like function definitions and declarations all buffers.")
{
list_all_functions(app, &global_part, 0);
list_all_functions(app, 0);
View_ID view = 0;
get_active_view(app, AccessAll, &view);
Buffer_ID buffer = 0;
view_get_buffer(app, view, AccessAll, &buffer);
open_jump_lister(app, &global_part, &global_heap, view, buffer, JumpListerActivation_OpenInUIView, 0);
open_jump_lister(app, &global_heap, view, buffer, JumpListerActivation_OpenInUIView, 0);
}
// BOTTOM

View File

@ -19,12 +19,6 @@ struct Get_Positions_Results{
b32 still_looping;
};
struct Buffered_Write_Stream{
Buffer_ID output_buffer_id;
Partition *buffering_arena;
char *buffer;
};
#endif
// BOTTOM

View File

@ -3,21 +3,22 @@ struct Application_Links;
#define GLOBAL_SET_MAPPING_SIG(n) b32 n(Application_Links *app, void *data, i32 size)
#define GLOBAL_GET_SCREEN_RECTANGLE_SIG(n) b32 n(Application_Links *app, Rect_f32 *rect_out)
#define CONTEXT_GET_ARENA_SIG(n) Arena* n(Application_Links *app)
#define CREATE_CHILD_PROCESS_SIG(n) b32 n(Application_Links *app, String path, String command, Child_Process_ID *child_process_id_out)
#define CONTEXT_GET_BASE_ALLOCATOR_SIG(n) Base_Allocator* n(Application_Links *app)
#define CREATE_CHILD_PROCESS_SIG(n) b32 n(Application_Links *app, String_Const_u8 path, String_Const_u8 command, Child_Process_ID *child_process_id_out)
#define CHILD_PROCESS_SET_TARGET_BUFFER_SIG(n) b32 n(Application_Links *app, Child_Process_ID child_process_id, Buffer_ID buffer_id, Child_Process_Set_Target_Flags flags)
#define BUFFER_GET_ATTACHED_CHILD_PROCESS_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, Child_Process_ID *child_process_id_out)
#define CHILD_PROCESS_GET_ATTACHED_BUFFER_SIG(n) b32 n(Application_Links *app, Child_Process_ID child_process_id, Buffer_ID *buffer_id_out)
#define CHILD_PROCESS_GET_STATE_SIG(n) b32 n(Application_Links *app, Child_Process_ID child_process_id, Process_State *process_state_out)
#define CLIPBOARD_POST_SIG(n) b32 n(Application_Links *app, i32 clipboard_id, String string)
#define CLIPBOARD_POST_SIG(n) b32 n(Application_Links *app, i32 clipboard_id, String_Const_u8 string)
#define CLIPBOARD_COUNT_SIG(n) b32 n(Application_Links *app, i32 clipboard_id, i32 *count_out)
#define CLIPBOARD_INDEX_SIG(n) b32 n(Application_Links *app, i32 clipboard_id, i32 item_index, String *string_out, i32 *required_size_out)
#define CLIPBOARD_INDEX_SIG(n) b32 n(Application_Links *app, i32 clipboard_id, i32 item_index, Arena *out, String_Const_u8 *string_out)
#define CREATE_PARSE_CONTEXT_SIG(n) Parse_Context_ID n(Application_Links *app, Parser_String_And_Type *kw, u32 kw_count, Parser_String_And_Type *pp, u32 pp_count)
#define GET_BUFFER_COUNT_SIG(n) i32 n(Application_Links *app)
#define GET_BUFFER_NEXT_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, Access_Flag access, Buffer_ID *buffer_id_out)
#define GET_BUFFER_BY_NAME_SIG(n) b32 n(Application_Links *app, String name, Access_Flag access, Buffer_ID *buffer_id_out)
#define GET_BUFFER_BY_FILE_NAME_SIG(n) b32 n(Application_Links *app, String file_name, Access_Flag access, Buffer_ID *buffer_id_out)
#define GET_BUFFER_BY_NAME_SIG(n) b32 n(Application_Links *app, String_Const_u8 name, Access_Flag access, Buffer_ID *buffer_id_out)
#define GET_BUFFER_BY_FILE_NAME_SIG(n) b32 n(Application_Links *app, String_Const_u8 file_name, Access_Flag access, Buffer_ID *buffer_id_out)
#define BUFFER_READ_RANGE_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, i32 start, i32 one_past_last, char *out)
#define BUFFER_REPLACE_RANGE_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, Range range, String string)
#define BUFFER_REPLACE_RANGE_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, Range range, String_Const_u8 string)
#define BUFFER_BATCH_EDIT_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, char *str, Buffer_Edit *edits, i32 edit_count)
#define BUFFER_COMPUTE_CURSOR_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, Buffer_Seek seek, Partial_Cursor *cursor_out)
#define BUFFER_EXISTS_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id)
@ -25,9 +26,9 @@ struct Application_Links;
#define BUFFER_GET_ACCESS_FLAGS_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, Access_Flag *access_flags_out)
#define BUFFER_GET_SIZE_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, i32 *size_out)
#define BUFFER_GET_LINE_COUNT_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, i32 *line_count_out)
#define BUFFER_GET_BASE_BUFFER_NAME_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, String *name_out, i32 *required_size_out)
#define BUFFER_GET_UNIQUE_BUFFER_NAME_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, String *name_out, i32 *required_size_out)
#define BUFFER_GET_FILE_NAME_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, String *name_out, i32 *required_size_out)
#define BUFFER_GET_BASE_BUFFER_NAME_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, Arena *out, String_Const_u8 *name_out)
#define BUFFER_GET_UNIQUE_BUFFER_NAME_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, Arena *out, String_Const_u8 *name_out)
#define BUFFER_GET_FILE_NAME_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, Arena *out, String_Const_u8 *name_out)
#define BUFFER_GET_DIRTY_STATE_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, Dirty_State *dirty_state_out)
#define BUFFER_DIRECTLY_SET_DIRTY_STATE_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, Dirty_State dirty_state)
#define BUFFER_TOKENS_ARE_READY_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id)
@ -39,8 +40,8 @@ struct Application_Links;
#define BUFFER_GET_TOKEN_RANGE_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, Cpp_Token **first_token_out, Cpp_Token **one_past_last_token_out)
#define BUFFER_GET_TOKEN_INDEX_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, i32 pos, Cpp_Get_Token_Result *get_result)
#define BUFFER_SEND_END_SIGNAL_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id)
#define CREATE_BUFFER_SIG(n) b32 n(Application_Links *app, String file_name, Buffer_Create_Flag flags, Buffer_ID *new_buffer_id_out)
#define BUFFER_SAVE_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, String file_name, u32 flags)
#define CREATE_BUFFER_SIG(n) b32 n(Application_Links *app, String_Const_u8 file_name, Buffer_Create_Flag flags, Buffer_ID *new_buffer_id_out)
#define BUFFER_SAVE_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, String_Const_u8 file_name, u32 flags)
#define BUFFER_KILL_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, Buffer_Kill_Flag flags, Buffer_Kill_Result *result_out)
#define BUFFER_REOPEN_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, Buffer_Reopen_Flag flags, Buffer_Reopen_Result *result_out)
#define BUFFER_GET_FILE_ATTRIBUTES_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, File_Attributes *attributes_out)
@ -105,7 +106,7 @@ struct Application_Links;
#define MARKER_VISUAL_SET_VIEW_KEY_SIG(n) b32 n(Application_Links *app, Marker_Visual visual, View_ID key_view_id)
#define DESTROY_MARKER_VISUAL_SIG(n) b32 n(Application_Links *app, Marker_Visual visual)
#define BUFFER_MARKERS_GET_ATTACHED_VISUAL_COUNT_SIG(n) i32 n(Application_Links *app, Managed_Object object)
#define BUFFER_MARKERS_GET_ATTACHED_VISUAL_SIG(n) Marker_Visual* n(Application_Links *app, Partition *part, Managed_Object object)
#define BUFFER_MARKERS_GET_ATTACHED_VISUAL_SIG(n) Marker_Visual* n(Application_Links *app, Arena *arena, Managed_Object object)
#define MANAGED_OBJECT_GET_ITEM_SIZE_SIG(n) u32 n(Application_Links *app, Managed_Object object)
#define MANAGED_OBJECT_GET_ITEM_COUNT_SIG(n) u32 n(Application_Links *app, Managed_Object object)
#define MANAGED_OBJECT_GET_TYPE_SIG(n) Managed_Object_Type n(Application_Links *app, Managed_Object object)
@ -120,7 +121,7 @@ struct Application_Links;
#define GET_ACTIVE_QUERY_BARS_SIG(n) b32 n(Application_Links *app, View_ID view_id, i32 max_result_count, Query_Bar_Ptr_Array *array_out)
#define START_QUERY_BAR_SIG(n) b32 n(Application_Links *app, Query_Bar *bar, u32 flags)
#define END_QUERY_BAR_SIG(n) void n(Application_Links *app, Query_Bar *bar, u32 flags)
#define PRINT_MESSAGE_SIG(n) b32 n(Application_Links *app, String message)
#define PRINT_MESSAGE_SIG(n) b32 n(Application_Links *app, String_Const_u8 message)
#define GET_LARGEST_FACE_ID_SIG(n) Face_ID n(Application_Links *app)
#define SET_GLOBAL_FACE_SIG(n) b32 n(Application_Links *app, Face_ID id, b32 apply_to_all_buffers)
#define BUFFER_HISTORY_GET_MAX_RECORD_INDEX_SIG(n) b32 n(Application_Links *app, Buffer_ID buffer_id, History_Record_Index *index_out)
@ -144,26 +145,26 @@ struct Application_Links;
#define SET_THEME_COLORS_SIG(n) void n(Application_Links *app, Theme_Color *colors, i32 count)
#define GET_THEME_COLORS_SIG(n) void n(Application_Links *app, Theme_Color *colors, i32 count)
#define FINALIZE_COLOR_SIG(n) argb_color n(Application_Links *app, int_color color)
#define GET_HOT_DIRECTORY_SIG(n) b32 n(Application_Links *app, String *out, i32 *required_size_out)
#define SET_HOT_DIRECTORY_SIG(n) b32 n(Application_Links *app, String string)
#define GET_FILE_LIST_SIG(n) b32 n(Application_Links *app, String directory, File_List *list_out)
#define GET_HOT_DIRECTORY_SIG(n) b32 n(Application_Links *app, Arena *out, String_Const_u8 *out_directory)
#define SET_HOT_DIRECTORY_SIG(n) b32 n(Application_Links *app, String_Const_u8 string)
#define GET_FILE_LIST_SIG(n) b32 n(Application_Links *app, String_Const_u8 directory, File_List *list_out)
#define FREE_FILE_LIST_SIG(n) void n(Application_Links *app, File_List list)
#define SET_GUI_UP_DOWN_KEYS_SIG(n) void n(Application_Links *app, Key_Code up_key, Key_Modifier up_key_modifier, Key_Code down_key, Key_Modifier down_key_modifier)
#define MEMORY_ALLOCATE_SIG(n) void* n(Application_Links *app, i32 size)
#define MEMORY_SET_PROTECTION_SIG(n) b32 n(Application_Links *app, void *ptr, i32 size, Memory_Protect_Flags flags)
#define MEMORY_FREE_SIG(n) void n(Application_Links *app, void *ptr, i32 size)
#define FILE_GET_ATTRIBUTES_SIG(n) b32 n(Application_Links *app, String file_name, File_Attributes *attributes_out)
#define DIRECTORY_CD_SIG(n) b32 n(Application_Links *app, String *directory, String relative_path)
#define GET_4ED_PATH_SIG(n) b32 n(Application_Links *app, String *path_out, i32 *required_size_out)
#define FILE_GET_ATTRIBUTES_SIG(n) b32 n(Application_Links *app, String_Const_u8 file_name, File_Attributes *attributes_out)
#define DIRECTORY_CD_SIG(n) b32 n(Application_Links *app, String_Const_u8 directory, String_Const_u8 relative_path, Arena *out, String_Const_u8 *directory_out)
#define GET_4ED_PATH_SIG(n) b32 n(Application_Links *app, Arena *out, String_Const_u8 *path_out)
#define SHOW_MOUSE_CURSOR_SIG(n) void n(Application_Links *app, Mouse_Cursor_Show_Type show)
#define SET_EDIT_FINISHED_HOOK_REPEAT_SPEED_SIG(n) b32 n(Application_Links *app, u32 milliseconds)
#define SET_FULLSCREEN_SIG(n) b32 n(Application_Links *app, b32 full_screen)
#define IS_FULLSCREEN_SIG(n) b32 n(Application_Links *app)
#define SEND_EXIT_SIGNAL_SIG(n) void n(Application_Links *app)
#define SET_WINDOW_TITLE_SIG(n) b32 n(Application_Links *app, String title)
#define SET_WINDOW_TITLE_SIG(n) b32 n(Application_Links *app, String_Const_u8 title)
#define GET_MICROSECONDS_TIMESTAMP_SIG(n) Microsecond_Time_Stamp n(Application_Links *app)
#define DRAW_STRING_SIG(n) Vec2 n(Application_Links *app, Face_ID font_id, String str, Vec2 point, int_color color, u32 flags, Vec2 delta)
#define GET_STRING_ADVANCE_SIG(n) f32 n(Application_Links *app, Face_ID font_id, String str)
#define DRAW_STRING_SIG(n) Vec2 n(Application_Links *app, Face_ID font_id, String_Const_u8 str, Vec2 point, int_color color, u32 flags, Vec2 delta)
#define GET_STRING_ADVANCE_SIG(n) f32 n(Application_Links *app, Face_ID font_id, String_Const_u8 str)
#define DRAW_RECTANGLE_SIG(n) void n(Application_Links *app, Rect_f32 rect, int_color color)
#define DRAW_RECTANGLE_OUTLINE_SIG(n) void n(Application_Links *app, f32_Rect rect, int_color color)
#define DRAW_CLIP_PUSH_SIG(n) void n(Application_Links *app, f32_Rect clip_box)
@ -180,12 +181,13 @@ struct Application_Links;
#define DRAW_RENDER_LAYOUT_SIG(n) void n(Application_Links *app, View_ID view_id)
#define OPEN_COLOR_PICKER_SIG(n) void n(Application_Links *app, color_picker *picker)
#define ANIMATE_IN_N_MILLISECONDS_SIG(n) void n(Application_Links *app, u32 n)
#define FIND_ALL_IN_RANGE_INSENSITIVE_SIG(n) Found_String_List n(Application_Links *app, Buffer_ID buffer_id, i32 start, i32 end, String key, Partition *memory)
#define FIND_ALL_IN_RANGE_INSENSITIVE_SIG(n) Found_String_List n(Application_Links *app, Buffer_ID buffer_id, i32 start, i32 end, String_Const_u8 key, Arena *arena)
#define GET_VIEW_VISIBLE_RANGE_SIG(n) Range n(Application_Links *app, View_ID view_id)
typedef GLOBAL_SET_SETTING_SIG(Global_Set_Setting_Function);
typedef GLOBAL_SET_MAPPING_SIG(Global_Set_Mapping_Function);
typedef GLOBAL_GET_SCREEN_RECTANGLE_SIG(Global_Get_Screen_Rectangle_Function);
typedef CONTEXT_GET_ARENA_SIG(Context_Get_Arena_Function);
typedef CONTEXT_GET_BASE_ALLOCATOR_SIG(Context_Get_Base_Allocator_Function);
typedef CREATE_CHILD_PROCESS_SIG(Create_Child_Process_Function);
typedef CHILD_PROCESS_SET_TARGET_BUFFER_SIG(Child_Process_Set_Target_Buffer_Function);
typedef BUFFER_GET_ATTACHED_CHILD_PROCESS_SIG(Buffer_Get_Attached_Child_Process_Function);
@ -371,6 +373,7 @@ Global_Set_Setting_Function *global_set_setting;
Global_Set_Mapping_Function *global_set_mapping;
Global_Get_Screen_Rectangle_Function *global_get_screen_rectangle;
Context_Get_Arena_Function *context_get_arena;
Context_Get_Base_Allocator_Function *context_get_base_allocator;
Create_Child_Process_Function *create_child_process;
Child_Process_Set_Target_Buffer_Function *child_process_set_target_buffer;
Buffer_Get_Attached_Child_Process_Function *buffer_get_attached_child_process;
@ -555,6 +558,7 @@ Global_Set_Setting_Function *global_set_setting_;
Global_Set_Mapping_Function *global_set_mapping_;
Global_Get_Screen_Rectangle_Function *global_get_screen_rectangle_;
Context_Get_Arena_Function *context_get_arena_;
Context_Get_Base_Allocator_Function *context_get_base_allocator_;
Create_Child_Process_Function *create_child_process_;
Child_Process_Set_Target_Buffer_Function *child_process_set_target_buffer_;
Buffer_Get_Attached_Child_Process_Function *buffer_get_attached_child_process_;
@ -747,6 +751,7 @@ app_links->global_set_setting_ = Global_Set_Setting;\
app_links->global_set_mapping_ = Global_Set_Mapping;\
app_links->global_get_screen_rectangle_ = Global_Get_Screen_Rectangle;\
app_links->context_get_arena_ = Context_Get_Arena;\
app_links->context_get_base_allocator_ = Context_Get_Base_Allocator;\
app_links->create_child_process_ = Create_Child_Process;\
app_links->child_process_set_target_buffer_ = Child_Process_Set_Target_Buffer;\
app_links->buffer_get_attached_child_process_ = Buffer_Get_Attached_Child_Process;\
@ -931,21 +936,22 @@ static b32 global_set_setting(Application_Links *app, Global_Setting_ID setting,
static b32 global_set_mapping(Application_Links *app, void *data, i32 size){return(app->global_set_mapping(app, data, size));}
static b32 global_get_screen_rectangle(Application_Links *app, Rect_f32 *rect_out){return(app->global_get_screen_rectangle(app, rect_out));}
static Arena* context_get_arena(Application_Links *app){return(app->context_get_arena(app));}
static b32 create_child_process(Application_Links *app, String path, String command, Child_Process_ID *child_process_id_out){return(app->create_child_process(app, path, command, child_process_id_out));}
static Base_Allocator* context_get_base_allocator(Application_Links *app){return(app->context_get_base_allocator(app));}
static b32 create_child_process(Application_Links *app, String_Const_u8 path, String_Const_u8 command, Child_Process_ID *child_process_id_out){return(app->create_child_process(app, path, command, child_process_id_out));}
static b32 child_process_set_target_buffer(Application_Links *app, Child_Process_ID child_process_id, Buffer_ID buffer_id, Child_Process_Set_Target_Flags flags){return(app->child_process_set_target_buffer(app, child_process_id, buffer_id, flags));}
static b32 buffer_get_attached_child_process(Application_Links *app, Buffer_ID buffer_id, Child_Process_ID *child_process_id_out){return(app->buffer_get_attached_child_process(app, buffer_id, child_process_id_out));}
static b32 child_process_get_attached_buffer(Application_Links *app, Child_Process_ID child_process_id, Buffer_ID *buffer_id_out){return(app->child_process_get_attached_buffer(app, child_process_id, buffer_id_out));}
static b32 child_process_get_state(Application_Links *app, Child_Process_ID child_process_id, Process_State *process_state_out){return(app->child_process_get_state(app, child_process_id, process_state_out));}
static b32 clipboard_post(Application_Links *app, i32 clipboard_id, String string){return(app->clipboard_post(app, clipboard_id, string));}
static b32 clipboard_post(Application_Links *app, i32 clipboard_id, String_Const_u8 string){return(app->clipboard_post(app, clipboard_id, string));}
static b32 clipboard_count(Application_Links *app, i32 clipboard_id, i32 *count_out){return(app->clipboard_count(app, clipboard_id, count_out));}
static b32 clipboard_index(Application_Links *app, i32 clipboard_id, i32 item_index, String *string_out, i32 *required_size_out){return(app->clipboard_index(app, clipboard_id, item_index, string_out, required_size_out));}
static b32 clipboard_index(Application_Links *app, i32 clipboard_id, i32 item_index, Arena *out, String_Const_u8 *string_out){return(app->clipboard_index(app, clipboard_id, item_index, out, string_out));}
static Parse_Context_ID create_parse_context(Application_Links *app, Parser_String_And_Type *kw, u32 kw_count, Parser_String_And_Type *pp, u32 pp_count){return(app->create_parse_context(app, kw, kw_count, pp, pp_count));}
static i32 get_buffer_count(Application_Links *app){return(app->get_buffer_count(app));}
static b32 get_buffer_next(Application_Links *app, Buffer_ID buffer_id, Access_Flag access, Buffer_ID *buffer_id_out){return(app->get_buffer_next(app, buffer_id, access, buffer_id_out));}
static b32 get_buffer_by_name(Application_Links *app, String name, Access_Flag access, Buffer_ID *buffer_id_out){return(app->get_buffer_by_name(app, name, access, buffer_id_out));}
static b32 get_buffer_by_file_name(Application_Links *app, String file_name, Access_Flag access, Buffer_ID *buffer_id_out){return(app->get_buffer_by_file_name(app, file_name, access, buffer_id_out));}
static b32 get_buffer_by_name(Application_Links *app, String_Const_u8 name, Access_Flag access, Buffer_ID *buffer_id_out){return(app->get_buffer_by_name(app, name, access, buffer_id_out));}
static b32 get_buffer_by_file_name(Application_Links *app, String_Const_u8 file_name, Access_Flag access, Buffer_ID *buffer_id_out){return(app->get_buffer_by_file_name(app, file_name, access, buffer_id_out));}
static b32 buffer_read_range(Application_Links *app, Buffer_ID buffer_id, i32 start, i32 one_past_last, char *out){return(app->buffer_read_range(app, buffer_id, start, one_past_last, out));}
static b32 buffer_replace_range(Application_Links *app, Buffer_ID buffer_id, Range range, String string){return(app->buffer_replace_range(app, buffer_id, range, string));}
static b32 buffer_replace_range(Application_Links *app, Buffer_ID buffer_id, Range range, String_Const_u8 string){return(app->buffer_replace_range(app, buffer_id, range, string));}
static b32 buffer_batch_edit(Application_Links *app, Buffer_ID buffer_id, char *str, Buffer_Edit *edits, i32 edit_count){return(app->buffer_batch_edit(app, buffer_id, str, edits, edit_count));}
static b32 buffer_compute_cursor(Application_Links *app, Buffer_ID buffer_id, Buffer_Seek seek, Partial_Cursor *cursor_out){return(app->buffer_compute_cursor(app, buffer_id, seek, cursor_out));}
static b32 buffer_exists(Application_Links *app, Buffer_ID buffer_id){return(app->buffer_exists(app, buffer_id));}
@ -953,9 +959,9 @@ static b32 buffer_ready(Application_Links *app, Buffer_ID buffer_id){return(app-
static b32 buffer_get_access_flags(Application_Links *app, Buffer_ID buffer_id, Access_Flag *access_flags_out){return(app->buffer_get_access_flags(app, buffer_id, access_flags_out));}
static b32 buffer_get_size(Application_Links *app, Buffer_ID buffer_id, i32 *size_out){return(app->buffer_get_size(app, buffer_id, size_out));}
static b32 buffer_get_line_count(Application_Links *app, Buffer_ID buffer_id, i32 *line_count_out){return(app->buffer_get_line_count(app, buffer_id, line_count_out));}
static b32 buffer_get_base_buffer_name(Application_Links *app, Buffer_ID buffer_id, String *name_out, i32 *required_size_out){return(app->buffer_get_base_buffer_name(app, buffer_id, name_out, required_size_out));}
static b32 buffer_get_unique_buffer_name(Application_Links *app, Buffer_ID buffer_id, String *name_out, i32 *required_size_out){return(app->buffer_get_unique_buffer_name(app, buffer_id, name_out, required_size_out));}
static b32 buffer_get_file_name(Application_Links *app, Buffer_ID buffer_id, String *name_out, i32 *required_size_out){return(app->buffer_get_file_name(app, buffer_id, name_out, required_size_out));}
static b32 buffer_get_base_buffer_name(Application_Links *app, Buffer_ID buffer_id, Arena *out, String_Const_u8 *name_out){return(app->buffer_get_base_buffer_name(app, buffer_id, out, name_out));}
static b32 buffer_get_unique_buffer_name(Application_Links *app, Buffer_ID buffer_id, Arena *out, String_Const_u8 *name_out){return(app->buffer_get_unique_buffer_name(app, buffer_id, out, name_out));}
static b32 buffer_get_file_name(Application_Links *app, Buffer_ID buffer_id, Arena *out, String_Const_u8 *name_out){return(app->buffer_get_file_name(app, buffer_id, out, name_out));}
static b32 buffer_get_dirty_state(Application_Links *app, Buffer_ID buffer_id, Dirty_State *dirty_state_out){return(app->buffer_get_dirty_state(app, buffer_id, dirty_state_out));}
static b32 buffer_directly_set_dirty_state(Application_Links *app, Buffer_ID buffer_id, Dirty_State dirty_state){return(app->buffer_directly_set_dirty_state(app, buffer_id, dirty_state));}
static b32 buffer_tokens_are_ready(Application_Links *app, Buffer_ID buffer_id){return(app->buffer_tokens_are_ready(app, buffer_id));}
@ -967,8 +973,8 @@ static b32 buffer_read_tokens(Application_Links *app, Buffer_ID buffer_id, i32 s
static b32 buffer_get_token_range(Application_Links *app, Buffer_ID buffer_id, Cpp_Token **first_token_out, Cpp_Token **one_past_last_token_out){return(app->buffer_get_token_range(app, buffer_id, first_token_out, one_past_last_token_out));}
static b32 buffer_get_token_index(Application_Links *app, Buffer_ID buffer_id, i32 pos, Cpp_Get_Token_Result *get_result){return(app->buffer_get_token_index(app, buffer_id, pos, get_result));}
static b32 buffer_send_end_signal(Application_Links *app, Buffer_ID buffer_id){return(app->buffer_send_end_signal(app, buffer_id));}
static b32 create_buffer(Application_Links *app, String file_name, Buffer_Create_Flag flags, Buffer_ID *new_buffer_id_out){return(app->create_buffer(app, file_name, flags, new_buffer_id_out));}
static b32 buffer_save(Application_Links *app, Buffer_ID buffer_id, String file_name, u32 flags){return(app->buffer_save(app, buffer_id, file_name, flags));}
static b32 create_buffer(Application_Links *app, String_Const_u8 file_name, Buffer_Create_Flag flags, Buffer_ID *new_buffer_id_out){return(app->create_buffer(app, file_name, flags, new_buffer_id_out));}
static b32 buffer_save(Application_Links *app, Buffer_ID buffer_id, String_Const_u8 file_name, u32 flags){return(app->buffer_save(app, buffer_id, file_name, flags));}
static b32 buffer_kill(Application_Links *app, Buffer_ID buffer_id, Buffer_Kill_Flag flags, Buffer_Kill_Result *result_out){return(app->buffer_kill(app, buffer_id, flags, result_out));}
static b32 buffer_reopen(Application_Links *app, Buffer_ID buffer_id, Buffer_Reopen_Flag flags, Buffer_Reopen_Result *result_out){return(app->buffer_reopen(app, buffer_id, flags, result_out));}
static b32 buffer_get_file_attributes(Application_Links *app, Buffer_ID buffer_id, File_Attributes *attributes_out){return(app->buffer_get_file_attributes(app, buffer_id, attributes_out));}
@ -1033,7 +1039,7 @@ static b32 marker_visual_set_priority(Application_Links *app, Marker_Visual visu
static b32 marker_visual_set_view_key(Application_Links *app, Marker_Visual visual, View_ID key_view_id){return(app->marker_visual_set_view_key(app, visual, key_view_id));}
static b32 destroy_marker_visual(Application_Links *app, Marker_Visual visual){return(app->destroy_marker_visual(app, visual));}
static i32 buffer_markers_get_attached_visual_count(Application_Links *app, Managed_Object object){return(app->buffer_markers_get_attached_visual_count(app, object));}
static Marker_Visual* buffer_markers_get_attached_visual(Application_Links *app, Partition *part, Managed_Object object){return(app->buffer_markers_get_attached_visual(app, part, object));}
static Marker_Visual* buffer_markers_get_attached_visual(Application_Links *app, Arena *arena, Managed_Object object){return(app->buffer_markers_get_attached_visual(app, arena, object));}
static u32 managed_object_get_item_size(Application_Links *app, Managed_Object object){return(app->managed_object_get_item_size(app, object));}
static u32 managed_object_get_item_count(Application_Links *app, Managed_Object object){return(app->managed_object_get_item_count(app, object));}
static Managed_Object_Type managed_object_get_type(Application_Links *app, Managed_Object object){return(app->managed_object_get_type(app, object));}
@ -1048,7 +1054,7 @@ static Mouse_State get_mouse_state(Application_Links *app){return(app->get_mouse
static b32 get_active_query_bars(Application_Links *app, View_ID view_id, i32 max_result_count, Query_Bar_Ptr_Array *array_out){return(app->get_active_query_bars(app, view_id, max_result_count, array_out));}
static b32 start_query_bar(Application_Links *app, Query_Bar *bar, u32 flags){return(app->start_query_bar(app, bar, flags));}
static void end_query_bar(Application_Links *app, Query_Bar *bar, u32 flags){(app->end_query_bar(app, bar, flags));}
static b32 print_message(Application_Links *app, String message){return(app->print_message(app, message));}
static b32 print_message(Application_Links *app, String_Const_u8 message){return(app->print_message(app, message));}
static Face_ID get_largest_face_id(Application_Links *app){return(app->get_largest_face_id(app));}
static b32 set_global_face(Application_Links *app, Face_ID id, b32 apply_to_all_buffers){return(app->set_global_face(app, id, apply_to_all_buffers));}
static b32 buffer_history_get_max_record_index(Application_Links *app, Buffer_ID buffer_id, History_Record_Index *index_out){return(app->buffer_history_get_max_record_index(app, buffer_id, index_out));}
@ -1072,26 +1078,26 @@ static Available_Font get_available_font(Application_Links *app, i32 index){retu
static void set_theme_colors(Application_Links *app, Theme_Color *colors, i32 count){(app->set_theme_colors(app, colors, count));}
static void get_theme_colors(Application_Links *app, Theme_Color *colors, i32 count){(app->get_theme_colors(app, colors, count));}
static argb_color finalize_color(Application_Links *app, int_color color){return(app->finalize_color(app, color));}
static b32 get_hot_directory(Application_Links *app, String *out, i32 *required_size_out){return(app->get_hot_directory(app, out, required_size_out));}
static b32 set_hot_directory(Application_Links *app, String string){return(app->set_hot_directory(app, string));}
static b32 get_file_list(Application_Links *app, String directory, File_List *list_out){return(app->get_file_list(app, directory, list_out));}
static b32 get_hot_directory(Application_Links *app, Arena *out, String_Const_u8 *out_directory){return(app->get_hot_directory(app, out, out_directory));}
static b32 set_hot_directory(Application_Links *app, String_Const_u8 string){return(app->set_hot_directory(app, string));}
static b32 get_file_list(Application_Links *app, String_Const_u8 directory, File_List *list_out){return(app->get_file_list(app, directory, list_out));}
static void free_file_list(Application_Links *app, File_List list){(app->free_file_list(app, list));}
static void set_gui_up_down_keys(Application_Links *app, Key_Code up_key, Key_Modifier up_key_modifier, Key_Code down_key, Key_Modifier down_key_modifier){(app->set_gui_up_down_keys(app, up_key, up_key_modifier, down_key, down_key_modifier));}
static void* memory_allocate(Application_Links *app, i32 size){return(app->memory_allocate(app, size));}
static b32 memory_set_protection(Application_Links *app, void *ptr, i32 size, Memory_Protect_Flags flags){return(app->memory_set_protection(app, ptr, size, flags));}
static void memory_free(Application_Links *app, void *ptr, i32 size){(app->memory_free(app, ptr, size));}
static b32 file_get_attributes(Application_Links *app, String file_name, File_Attributes *attributes_out){return(app->file_get_attributes(app, file_name, attributes_out));}
static b32 directory_cd(Application_Links *app, String *directory, String relative_path){return(app->directory_cd(app, directory, relative_path));}
static b32 get_4ed_path(Application_Links *app, String *path_out, i32 *required_size_out){return(app->get_4ed_path(app, path_out, required_size_out));}
static b32 file_get_attributes(Application_Links *app, String_Const_u8 file_name, File_Attributes *attributes_out){return(app->file_get_attributes(app, file_name, attributes_out));}
static b32 directory_cd(Application_Links *app, String_Const_u8 directory, String_Const_u8 relative_path, Arena *out, String_Const_u8 *directory_out){return(app->directory_cd(app, directory, relative_path, out, directory_out));}
static b32 get_4ed_path(Application_Links *app, Arena *out, String_Const_u8 *path_out){return(app->get_4ed_path(app, out, path_out));}
static void show_mouse_cursor(Application_Links *app, Mouse_Cursor_Show_Type show){(app->show_mouse_cursor(app, show));}
static b32 set_edit_finished_hook_repeat_speed(Application_Links *app, u32 milliseconds){return(app->set_edit_finished_hook_repeat_speed(app, milliseconds));}
static b32 set_fullscreen(Application_Links *app, b32 full_screen){return(app->set_fullscreen(app, full_screen));}
static b32 is_fullscreen(Application_Links *app){return(app->is_fullscreen(app));}
static void send_exit_signal(Application_Links *app){(app->send_exit_signal(app));}
static b32 set_window_title(Application_Links *app, String title){return(app->set_window_title(app, title));}
static b32 set_window_title(Application_Links *app, String_Const_u8 title){return(app->set_window_title(app, title));}
static Microsecond_Time_Stamp get_microseconds_timestamp(Application_Links *app){return(app->get_microseconds_timestamp(app));}
static Vec2 draw_string(Application_Links *app, Face_ID font_id, String str, Vec2 point, int_color color, u32 flags, Vec2 delta){return(app->draw_string(app, font_id, str, point, color, flags, delta));}
static f32 get_string_advance(Application_Links *app, Face_ID font_id, String str){return(app->get_string_advance(app, font_id, str));}
static Vec2 draw_string(Application_Links *app, Face_ID font_id, String_Const_u8 str, Vec2 point, int_color color, u32 flags, Vec2 delta){return(app->draw_string(app, font_id, str, point, color, flags, delta));}
static f32 get_string_advance(Application_Links *app, Face_ID font_id, String_Const_u8 str){return(app->get_string_advance(app, font_id, str));}
static void draw_rectangle(Application_Links *app, Rect_f32 rect, int_color color){(app->draw_rectangle(app, rect, color));}
static void draw_rectangle_outline(Application_Links *app, f32_Rect rect, int_color color){(app->draw_rectangle_outline(app, rect, color));}
static void draw_clip_push(Application_Links *app, f32_Rect clip_box){(app->draw_clip_push(app, clip_box));}
@ -1108,28 +1114,29 @@ static b32 compute_render_layout(Application_Links *app, View_ID view_id, Buffer
static void draw_render_layout(Application_Links *app, View_ID view_id){(app->draw_render_layout(app, view_id));}
static void open_color_picker(Application_Links *app, color_picker *picker){(app->open_color_picker(app, picker));}
static void animate_in_n_milliseconds(Application_Links *app, u32 n){(app->animate_in_n_milliseconds(app, n));}
static Found_String_List find_all_in_range_insensitive(Application_Links *app, Buffer_ID buffer_id, i32 start, i32 end, String key, Partition *memory){return(app->find_all_in_range_insensitive(app, buffer_id, start, end, key, memory));}
static Found_String_List find_all_in_range_insensitive(Application_Links *app, Buffer_ID buffer_id, i32 start, i32 end, String_Const_u8 key, Arena *arena){return(app->find_all_in_range_insensitive(app, buffer_id, start, end, key, arena));}
static Range get_view_visible_range(Application_Links *app, View_ID view_id){return(app->get_view_visible_range(app, view_id));}
#else
static b32 global_set_setting(Application_Links *app, Global_Setting_ID setting, i32 value){return(app->global_set_setting_(app, setting, value));}
static b32 global_set_mapping(Application_Links *app, void *data, i32 size){return(app->global_set_mapping_(app, data, size));}
static b32 global_get_screen_rectangle(Application_Links *app, Rect_f32 *rect_out){return(app->global_get_screen_rectangle_(app, rect_out));}
static Arena* context_get_arena(Application_Links *app){return(app->context_get_arena_(app));}
static b32 create_child_process(Application_Links *app, String path, String command, Child_Process_ID *child_process_id_out){return(app->create_child_process_(app, path, command, child_process_id_out));}
static Base_Allocator* context_get_base_allocator(Application_Links *app){return(app->context_get_base_allocator_(app));}
static b32 create_child_process(Application_Links *app, String_Const_u8 path, String_Const_u8 command, Child_Process_ID *child_process_id_out){return(app->create_child_process_(app, path, command, child_process_id_out));}
static b32 child_process_set_target_buffer(Application_Links *app, Child_Process_ID child_process_id, Buffer_ID buffer_id, Child_Process_Set_Target_Flags flags){return(app->child_process_set_target_buffer_(app, child_process_id, buffer_id, flags));}
static b32 buffer_get_attached_child_process(Application_Links *app, Buffer_ID buffer_id, Child_Process_ID *child_process_id_out){return(app->buffer_get_attached_child_process_(app, buffer_id, child_process_id_out));}
static b32 child_process_get_attached_buffer(Application_Links *app, Child_Process_ID child_process_id, Buffer_ID *buffer_id_out){return(app->child_process_get_attached_buffer_(app, child_process_id, buffer_id_out));}
static b32 child_process_get_state(Application_Links *app, Child_Process_ID child_process_id, Process_State *process_state_out){return(app->child_process_get_state_(app, child_process_id, process_state_out));}
static b32 clipboard_post(Application_Links *app, i32 clipboard_id, String string){return(app->clipboard_post_(app, clipboard_id, string));}
static b32 clipboard_post(Application_Links *app, i32 clipboard_id, String_Const_u8 string){return(app->clipboard_post_(app, clipboard_id, string));}
static b32 clipboard_count(Application_Links *app, i32 clipboard_id, i32 *count_out){return(app->clipboard_count_(app, clipboard_id, count_out));}
static b32 clipboard_index(Application_Links *app, i32 clipboard_id, i32 item_index, String *string_out, i32 *required_size_out){return(app->clipboard_index_(app, clipboard_id, item_index, string_out, required_size_out));}
static b32 clipboard_index(Application_Links *app, i32 clipboard_id, i32 item_index, Arena *out, String_Const_u8 *string_out){return(app->clipboard_index_(app, clipboard_id, item_index, out, string_out));}
static Parse_Context_ID create_parse_context(Application_Links *app, Parser_String_And_Type *kw, u32 kw_count, Parser_String_And_Type *pp, u32 pp_count){return(app->create_parse_context_(app, kw, kw_count, pp, pp_count));}
static i32 get_buffer_count(Application_Links *app){return(app->get_buffer_count_(app));}
static b32 get_buffer_next(Application_Links *app, Buffer_ID buffer_id, Access_Flag access, Buffer_ID *buffer_id_out){return(app->get_buffer_next_(app, buffer_id, access, buffer_id_out));}
static b32 get_buffer_by_name(Application_Links *app, String name, Access_Flag access, Buffer_ID *buffer_id_out){return(app->get_buffer_by_name_(app, name, access, buffer_id_out));}
static b32 get_buffer_by_file_name(Application_Links *app, String file_name, Access_Flag access, Buffer_ID *buffer_id_out){return(app->get_buffer_by_file_name_(app, file_name, access, buffer_id_out));}
static b32 get_buffer_by_name(Application_Links *app, String_Const_u8 name, Access_Flag access, Buffer_ID *buffer_id_out){return(app->get_buffer_by_name_(app, name, access, buffer_id_out));}
static b32 get_buffer_by_file_name(Application_Links *app, String_Const_u8 file_name, Access_Flag access, Buffer_ID *buffer_id_out){return(app->get_buffer_by_file_name_(app, file_name, access, buffer_id_out));}
static b32 buffer_read_range(Application_Links *app, Buffer_ID buffer_id, i32 start, i32 one_past_last, char *out){return(app->buffer_read_range_(app, buffer_id, start, one_past_last, out));}
static b32 buffer_replace_range(Application_Links *app, Buffer_ID buffer_id, Range range, String string){return(app->buffer_replace_range_(app, buffer_id, range, string));}
static b32 buffer_replace_range(Application_Links *app, Buffer_ID buffer_id, Range range, String_Const_u8 string){return(app->buffer_replace_range_(app, buffer_id, range, string));}
static b32 buffer_batch_edit(Application_Links *app, Buffer_ID buffer_id, char *str, Buffer_Edit *edits, i32 edit_count){return(app->buffer_batch_edit_(app, buffer_id, str, edits, edit_count));}
static b32 buffer_compute_cursor(Application_Links *app, Buffer_ID buffer_id, Buffer_Seek seek, Partial_Cursor *cursor_out){return(app->buffer_compute_cursor_(app, buffer_id, seek, cursor_out));}
static b32 buffer_exists(Application_Links *app, Buffer_ID buffer_id){return(app->buffer_exists_(app, buffer_id));}
@ -1137,9 +1144,9 @@ static b32 buffer_ready(Application_Links *app, Buffer_ID buffer_id){return(app-
static b32 buffer_get_access_flags(Application_Links *app, Buffer_ID buffer_id, Access_Flag *access_flags_out){return(app->buffer_get_access_flags_(app, buffer_id, access_flags_out));}
static b32 buffer_get_size(Application_Links *app, Buffer_ID buffer_id, i32 *size_out){return(app->buffer_get_size_(app, buffer_id, size_out));}
static b32 buffer_get_line_count(Application_Links *app, Buffer_ID buffer_id, i32 *line_count_out){return(app->buffer_get_line_count_(app, buffer_id, line_count_out));}
static b32 buffer_get_base_buffer_name(Application_Links *app, Buffer_ID buffer_id, String *name_out, i32 *required_size_out){return(app->buffer_get_base_buffer_name_(app, buffer_id, name_out, required_size_out));}
static b32 buffer_get_unique_buffer_name(Application_Links *app, Buffer_ID buffer_id, String *name_out, i32 *required_size_out){return(app->buffer_get_unique_buffer_name_(app, buffer_id, name_out, required_size_out));}
static b32 buffer_get_file_name(Application_Links *app, Buffer_ID buffer_id, String *name_out, i32 *required_size_out){return(app->buffer_get_file_name_(app, buffer_id, name_out, required_size_out));}
static b32 buffer_get_base_buffer_name(Application_Links *app, Buffer_ID buffer_id, Arena *out, String_Const_u8 *name_out){return(app->buffer_get_base_buffer_name_(app, buffer_id, out, name_out));}
static b32 buffer_get_unique_buffer_name(Application_Links *app, Buffer_ID buffer_id, Arena *out, String_Const_u8 *name_out){return(app->buffer_get_unique_buffer_name_(app, buffer_id, out, name_out));}
static b32 buffer_get_file_name(Application_Links *app, Buffer_ID buffer_id, Arena *out, String_Const_u8 *name_out){return(app->buffer_get_file_name_(app, buffer_id, out, name_out));}
static b32 buffer_get_dirty_state(Application_Links *app, Buffer_ID buffer_id, Dirty_State *dirty_state_out){return(app->buffer_get_dirty_state_(app, buffer_id, dirty_state_out));}
static b32 buffer_directly_set_dirty_state(Application_Links *app, Buffer_ID buffer_id, Dirty_State dirty_state){return(app->buffer_directly_set_dirty_state_(app, buffer_id, dirty_state));}
static b32 buffer_tokens_are_ready(Application_Links *app, Buffer_ID buffer_id){return(app->buffer_tokens_are_ready_(app, buffer_id));}
@ -1151,8 +1158,8 @@ static b32 buffer_read_tokens(Application_Links *app, Buffer_ID buffer_id, i32 s
static b32 buffer_get_token_range(Application_Links *app, Buffer_ID buffer_id, Cpp_Token **first_token_out, Cpp_Token **one_past_last_token_out){return(app->buffer_get_token_range_(app, buffer_id, first_token_out, one_past_last_token_out));}
static b32 buffer_get_token_index(Application_Links *app, Buffer_ID buffer_id, i32 pos, Cpp_Get_Token_Result *get_result){return(app->buffer_get_token_index_(app, buffer_id, pos, get_result));}
static b32 buffer_send_end_signal(Application_Links *app, Buffer_ID buffer_id){return(app->buffer_send_end_signal_(app, buffer_id));}
static b32 create_buffer(Application_Links *app, String file_name, Buffer_Create_Flag flags, Buffer_ID *new_buffer_id_out){return(app->create_buffer_(app, file_name, flags, new_buffer_id_out));}
static b32 buffer_save(Application_Links *app, Buffer_ID buffer_id, String file_name, u32 flags){return(app->buffer_save_(app, buffer_id, file_name, flags));}
static b32 create_buffer(Application_Links *app, String_Const_u8 file_name, Buffer_Create_Flag flags, Buffer_ID *new_buffer_id_out){return(app->create_buffer_(app, file_name, flags, new_buffer_id_out));}
static b32 buffer_save(Application_Links *app, Buffer_ID buffer_id, String_Const_u8 file_name, u32 flags){return(app->buffer_save_(app, buffer_id, file_name, flags));}
static b32 buffer_kill(Application_Links *app, Buffer_ID buffer_id, Buffer_Kill_Flag flags, Buffer_Kill_Result *result_out){return(app->buffer_kill_(app, buffer_id, flags, result_out));}
static b32 buffer_reopen(Application_Links *app, Buffer_ID buffer_id, Buffer_Reopen_Flag flags, Buffer_Reopen_Result *result_out){return(app->buffer_reopen_(app, buffer_id, flags, result_out));}
static b32 buffer_get_file_attributes(Application_Links *app, Buffer_ID buffer_id, File_Attributes *attributes_out){return(app->buffer_get_file_attributes_(app, buffer_id, attributes_out));}
@ -1217,7 +1224,7 @@ static b32 marker_visual_set_priority(Application_Links *app, Marker_Visual visu
static b32 marker_visual_set_view_key(Application_Links *app, Marker_Visual visual, View_ID key_view_id){return(app->marker_visual_set_view_key_(app, visual, key_view_id));}
static b32 destroy_marker_visual(Application_Links *app, Marker_Visual visual){return(app->destroy_marker_visual_(app, visual));}
static i32 buffer_markers_get_attached_visual_count(Application_Links *app, Managed_Object object){return(app->buffer_markers_get_attached_visual_count_(app, object));}
static Marker_Visual* buffer_markers_get_attached_visual(Application_Links *app, Partition *part, Managed_Object object){return(app->buffer_markers_get_attached_visual_(app, part, object));}
static Marker_Visual* buffer_markers_get_attached_visual(Application_Links *app, Arena *arena, Managed_Object object){return(app->buffer_markers_get_attached_visual_(app, arena, object));}
static u32 managed_object_get_item_size(Application_Links *app, Managed_Object object){return(app->managed_object_get_item_size_(app, object));}
static u32 managed_object_get_item_count(Application_Links *app, Managed_Object object){return(app->managed_object_get_item_count_(app, object));}
static Managed_Object_Type managed_object_get_type(Application_Links *app, Managed_Object object){return(app->managed_object_get_type_(app, object));}
@ -1232,7 +1239,7 @@ static Mouse_State get_mouse_state(Application_Links *app){return(app->get_mouse
static b32 get_active_query_bars(Application_Links *app, View_ID view_id, i32 max_result_count, Query_Bar_Ptr_Array *array_out){return(app->get_active_query_bars_(app, view_id, max_result_count, array_out));}
static b32 start_query_bar(Application_Links *app, Query_Bar *bar, u32 flags){return(app->start_query_bar_(app, bar, flags));}
static void end_query_bar(Application_Links *app, Query_Bar *bar, u32 flags){(app->end_query_bar_(app, bar, flags));}
static b32 print_message(Application_Links *app, String message){return(app->print_message_(app, message));}
static b32 print_message(Application_Links *app, String_Const_u8 message){return(app->print_message_(app, message));}
static Face_ID get_largest_face_id(Application_Links *app){return(app->get_largest_face_id_(app));}
static b32 set_global_face(Application_Links *app, Face_ID id, b32 apply_to_all_buffers){return(app->set_global_face_(app, id, apply_to_all_buffers));}
static b32 buffer_history_get_max_record_index(Application_Links *app, Buffer_ID buffer_id, History_Record_Index *index_out){return(app->buffer_history_get_max_record_index_(app, buffer_id, index_out));}
@ -1256,26 +1263,26 @@ static Available_Font get_available_font(Application_Links *app, i32 index){retu
static void set_theme_colors(Application_Links *app, Theme_Color *colors, i32 count){(app->set_theme_colors_(app, colors, count));}
static void get_theme_colors(Application_Links *app, Theme_Color *colors, i32 count){(app->get_theme_colors_(app, colors, count));}
static argb_color finalize_color(Application_Links *app, int_color color){return(app->finalize_color_(app, color));}
static b32 get_hot_directory(Application_Links *app, String *out, i32 *required_size_out){return(app->get_hot_directory_(app, out, required_size_out));}
static b32 set_hot_directory(Application_Links *app, String string){return(app->set_hot_directory_(app, string));}
static b32 get_file_list(Application_Links *app, String directory, File_List *list_out){return(app->get_file_list_(app, directory, list_out));}
static b32 get_hot_directory(Application_Links *app, Arena *out, String_Const_u8 *out_directory){return(app->get_hot_directory_(app, out, out_directory));}
static b32 set_hot_directory(Application_Links *app, String_Const_u8 string){return(app->set_hot_directory_(app, string));}
static b32 get_file_list(Application_Links *app, String_Const_u8 directory, File_List *list_out){return(app->get_file_list_(app, directory, list_out));}
static void free_file_list(Application_Links *app, File_List list){(app->free_file_list_(app, list));}
static void set_gui_up_down_keys(Application_Links *app, Key_Code up_key, Key_Modifier up_key_modifier, Key_Code down_key, Key_Modifier down_key_modifier){(app->set_gui_up_down_keys_(app, up_key, up_key_modifier, down_key, down_key_modifier));}
static void* memory_allocate(Application_Links *app, i32 size){return(app->memory_allocate_(app, size));}
static b32 memory_set_protection(Application_Links *app, void *ptr, i32 size, Memory_Protect_Flags flags){return(app->memory_set_protection_(app, ptr, size, flags));}
static void memory_free(Application_Links *app, void *ptr, i32 size){(app->memory_free_(app, ptr, size));}
static b32 file_get_attributes(Application_Links *app, String file_name, File_Attributes *attributes_out){return(app->file_get_attributes_(app, file_name, attributes_out));}
static b32 directory_cd(Application_Links *app, String *directory, String relative_path){return(app->directory_cd_(app, directory, relative_path));}
static b32 get_4ed_path(Application_Links *app, String *path_out, i32 *required_size_out){return(app->get_4ed_path_(app, path_out, required_size_out));}
static b32 file_get_attributes(Application_Links *app, String_Const_u8 file_name, File_Attributes *attributes_out){return(app->file_get_attributes_(app, file_name, attributes_out));}
static b32 directory_cd(Application_Links *app, String_Const_u8 directory, String_Const_u8 relative_path, Arena *out, String_Const_u8 *directory_out){return(app->directory_cd_(app, directory, relative_path, out, directory_out));}
static b32 get_4ed_path(Application_Links *app, Arena *out, String_Const_u8 *path_out){return(app->get_4ed_path_(app, out, path_out));}
static void show_mouse_cursor(Application_Links *app, Mouse_Cursor_Show_Type show){(app->show_mouse_cursor_(app, show));}
static b32 set_edit_finished_hook_repeat_speed(Application_Links *app, u32 milliseconds){return(app->set_edit_finished_hook_repeat_speed_(app, milliseconds));}
static b32 set_fullscreen(Application_Links *app, b32 full_screen){return(app->set_fullscreen_(app, full_screen));}
static b32 is_fullscreen(Application_Links *app){return(app->is_fullscreen_(app));}
static void send_exit_signal(Application_Links *app){(app->send_exit_signal_(app));}
static b32 set_window_title(Application_Links *app, String title){return(app->set_window_title_(app, title));}
static b32 set_window_title(Application_Links *app, String_Const_u8 title){return(app->set_window_title_(app, title));}
static Microsecond_Time_Stamp get_microseconds_timestamp(Application_Links *app){return(app->get_microseconds_timestamp_(app));}
static Vec2 draw_string(Application_Links *app, Face_ID font_id, String str, Vec2 point, int_color color, u32 flags, Vec2 delta){return(app->draw_string_(app, font_id, str, point, color, flags, delta));}
static f32 get_string_advance(Application_Links *app, Face_ID font_id, String str){return(app->get_string_advance_(app, font_id, str));}
static Vec2 draw_string(Application_Links *app, Face_ID font_id, String_Const_u8 str, Vec2 point, int_color color, u32 flags, Vec2 delta){return(app->draw_string_(app, font_id, str, point, color, flags, delta));}
static f32 get_string_advance(Application_Links *app, Face_ID font_id, String_Const_u8 str){return(app->get_string_advance_(app, font_id, str));}
static void draw_rectangle(Application_Links *app, Rect_f32 rect, int_color color){(app->draw_rectangle_(app, rect, color));}
static void draw_rectangle_outline(Application_Links *app, f32_Rect rect, int_color color){(app->draw_rectangle_outline_(app, rect, color));}
static void draw_clip_push(Application_Links *app, f32_Rect clip_box){(app->draw_clip_push_(app, clip_box));}
@ -1292,6 +1299,6 @@ static b32 compute_render_layout(Application_Links *app, View_ID view_id, Buffer
static void draw_render_layout(Application_Links *app, View_ID view_id){(app->draw_render_layout_(app, view_id));}
static void open_color_picker(Application_Links *app, color_picker *picker){(app->open_color_picker_(app, picker));}
static void animate_in_n_milliseconds(Application_Links *app, u32 n){(app->animate_in_n_milliseconds_(app, n));}
static Found_String_List find_all_in_range_insensitive(Application_Links *app, Buffer_ID buffer_id, i32 start, i32 end, String key, Partition *memory){return(app->find_all_in_range_insensitive_(app, buffer_id, start, end, key, memory));}
static Found_String_List find_all_in_range_insensitive(Application_Links *app, Buffer_ID buffer_id, i32 start, i32 end, String_Const_u8 key, Arena *arena){return(app->find_all_in_range_insensitive_(app, buffer_id, start, end, key, arena));}
static Range get_view_visible_range(Application_Links *app, View_ID view_id){return(app->get_view_visible_range_(app, view_id));}
#endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -26,20 +26,9 @@ struct Bind_Buffer{
////////////////////////////////
struct File_Handle_Path{
FILE *file;
String path;
};
struct File_Name_Data{
String file_name;
String data;
};
struct File_Name_Path_Data{
String file_name;
String path;
String data;
String_Const_u8 file_name;
Data data;
};
////////////////////////////////
@ -93,6 +82,14 @@ struct Sort_Pair_i32{
i32 key;
};
////////////////////////////////
struct History_Group{
Application_Links *app;
Buffer_ID buffer;
History_Record_Index first;
};
#endif
// BOTTOM

View File

@ -14,11 +14,11 @@ begin_buffer_insertion_at(Application_Links *app, Buffer_ID buffer_id, i32 at){
}
static Buffer_Insertion
begin_buffer_insertion_at_buffered(Application_Links *app, Buffer_ID buffer_id, i32 at, Partition *part){
begin_buffer_insertion_at_buffered(Application_Links *app, Buffer_ID buffer_id, i32 at, Cursor *cursor){
Buffer_Insertion result = begin_buffer_insertion_at(app, buffer_id, at);
result.buffering = true;
result.part = part;
result.temp = begin_temp_memory(part);
result.cursor = cursor;
result.temp = begin_temp(cursor);
return(result);
}
@ -35,32 +35,39 @@ begin_buffer_insertion(Application_Links *app){
}
static void
insert_string__no_buffering(Buffer_Insertion *insertion, String string){
buffer_replace_range(insertion->app, insertion->buffer, make_range(insertion->at), string);
insert_string__no_buffering(Buffer_Insertion *insertion, String_Const_u8 string){
buffer_replace_range(insertion->app, insertion->buffer, make_range((i32)insertion->at), string);
insertion->at += string.size;
}
static void
insert__flush(Buffer_Insertion *insertion){
Partition *part = insertion->part;
i32 pos = insertion->temp.pos;
String string = make_string(part->base + pos, part->pos - pos);
Cursor *cursor = insertion->cursor;
umem pos = insertion->temp.temp_memory_cursor.pos;
String_Const_u8 string = SCu8(cursor->base + pos, cursor->pos - pos);
insert_string__no_buffering(insertion, string);
end_temp_memory(insertion->temp);
end_temp(insertion->temp);
}
static char*
insert__reserve(Buffer_Insertion *insertion, i32 size){
char *space = push_array(insertion->part, char, size);
insert__reserve(Buffer_Insertion *insertion, umem size){
char *space = push_array(insertion->cursor, char, size);
if (space == 0){
insert__flush(insertion);
space = push_array(insertion->part, char, size);
space = push_array(insertion->cursor, char, size);
}
return(space);
}
static void
insert_string(Buffer_Insertion *insertion, String string){
end_buffer_insertion(Buffer_Insertion *insertion){
if (insertion->buffering){
insert__flush(insertion);
}
}
static void
insert_string(Buffer_Insertion *insertion, String_Const_u8 string){
if (!insertion->buffering){
insert_string__no_buffering(insertion, string);
}
@ -75,28 +82,27 @@ insert_string(Buffer_Insertion *insertion, String string){
}
}
static i32
static umem
insertf(Buffer_Insertion *insertion, char *format, ...){
Arena *arena = context_get_arena(insertion->app);
Temp_Memory_Arena temp = begin_temp_memory(arena);
Arena *scratch = context_get_arena(insertion->app);
Temp_Memory temp = begin_temp(scratch);
va_list args;
va_start(args, format);
String string = string_push_fv(arena, format, args);
String_Const_u8 string = string_u8_pushfv(scratch, format, args);
va_end(args);
insert_string(insertion, string);
end_temp_memory(temp);
end_temp(temp);
return(string.size);
}
static void
insertc(Buffer_Insertion *insertion, char C){
insert_string(insertion, make_string(&C, 1));
insert_string(insertion, SCu8(&C, 1));
}
static b32
insert_line_from_buffer(Buffer_Insertion *insertion, Buffer_ID buffer_id, i32 line, i32 truncate_at){
Partition *part = &global_part;
Temp_Memory temp = begin_temp_memory(part);
Scratch_Block scratch(insertion->app);
Partial_Cursor begin = {};
Partial_Cursor end = {};
@ -109,25 +115,18 @@ insert_line_from_buffer(Buffer_Insertion *insertion, Buffer_ID buffer_id, i32 li
buffer_get_size(insertion->app, buffer_id, &buffer_size);
if (0 <= begin.pos && begin.pos <= end.pos && end.pos <= buffer_size){
i32 size = (end.pos - begin.pos);
if(truncate_at && (size > truncate_at))
{
if (truncate_at && (size > truncate_at)){
size = truncate_at;
}
char *memory = push_array(part, char, size);
if (memory != 0){
String str = make_string(memory, 0, size);
success = true;
buffer_read_range(insertion->app, buffer_id, begin.pos, end.pos, str.str);
str.size = size;
insert_string(insertion, str);
}
String_Const_u8 string = scratch_read(insertion->app, scratch, buffer_id, begin.pos, end.pos);
insert_string(insertion, string);
success = true;
}
}
}
}
end_temp_memory(temp);
return(success);
}

View File

@ -10,9 +10,9 @@
struct Buffer_Insertion{
Application_Links *app;
Buffer_ID buffer;
i32 at;
umem at;
b32 buffering;
Partition *part;
Cursor *cursor;
Temp_Memory temp;
};

View File

@ -8,7 +8,8 @@ compiler errors and jumping to them in the corresponding buffer.
CUSTOM_COMMAND_SIG(goto_jump_at_cursor_direct)
CUSTOM_DOC("If the cursor is found to be on a jump location, parses the jump location and brings up the file and position in another view and changes the active panel to the view containing the jump.")
{
Temp_Memory temp = begin_temp_memory(&global_part);
Arena *scratch = context_get_arena(app);
Temp_Memory temp = begin_temp(scratch);
View_ID view = 0;
get_active_view(app, AccessProtected, &view);
Buffer_ID buffer = 0;
@ -18,7 +19,7 @@ CUSTOM_DOC("If the cursor is found to be on a jump location, parses the jump loc
Full_Cursor cursor = {};
view_compute_cursor(app, view, seek_pos(pos), &cursor);
Parsed_Jump jump = parse_jump_from_buffer_line(app, &global_part, buffer, cursor.line, false);
Parsed_Jump jump = parse_jump_from_buffer_line(app, scratch, buffer, cursor.line, false);
if (jump.success){
change_active_panel(app);
View_ID target_view = 0;
@ -29,13 +30,14 @@ CUSTOM_DOC("If the cursor is found to be on a jump location, parses the jump loc
}
}
end_temp_memory(temp);
end_temp(temp);
}
CUSTOM_COMMAND_SIG(goto_jump_at_cursor_same_panel_direct)
CUSTOM_DOC("If the cursor is found to be on a jump location, parses the jump location and brings up the file and position in this view, losing the compilation output or jump list..")
{
Temp_Memory temp = begin_temp_memory(&global_part);
Arena *scratch = context_get_arena(app);
Temp_Memory temp = begin_temp(scratch);
View_ID view = 0;
get_active_view(app, AccessProtected, &view);
Buffer_ID buffer = 0;
@ -45,7 +47,7 @@ CUSTOM_DOC("If the cursor is found to be on a jump location, parses the jump loc
Full_Cursor cursor = {};
view_compute_cursor(app, view, seek_pos(pos), &cursor);
Parsed_Jump jump = parse_jump_from_buffer_line(app, &global_part, buffer, cursor.line, false);
Parsed_Jump jump = parse_jump_from_buffer_line(app, scratch, buffer, cursor.line, false);
if (jump.success){
View_ID target_view = view;
if (get_jump_buffer(app, &buffer, &jump.location)){
@ -53,7 +55,7 @@ CUSTOM_DOC("If the cursor is found to be on a jump location, parses the jump loc
}
}
end_temp_memory(temp);
end_temp(temp);
}
CUSTOM_COMMAND_SIG(goto_next_jump_direct)
@ -62,7 +64,7 @@ CUSTOM_DOC("If a buffer containing jump locations has been locked in, goes to th
b32 skip_repeats = true;
b32 skip_sub_errors = true;
i32 dir = 1;
seek_jump(app, &global_part, skip_repeats, skip_sub_errors, dir);
seek_jump(app, skip_repeats, skip_sub_errors, dir);
}
CUSTOM_COMMAND_SIG(goto_prev_jump_direct)
@ -71,7 +73,7 @@ CUSTOM_DOC("If a buffer containing jump locations has been locked in, goes to th
b32 skip_repeats = true;
b32 skip_sub_errors = true;
i32 dir = -1;
seek_jump(app, &global_part, skip_repeats, skip_sub_errors, dir);
seek_jump(app, skip_repeats, skip_sub_errors, dir);
}
CUSTOM_COMMAND_SIG(goto_next_jump_no_skips_direct)
@ -80,7 +82,7 @@ CUSTOM_DOC("If a buffer containing jump locations has been locked in, goes to th
b32 skip_repeats = false;
b32 skip_sub_errors = true;
i32 dir = 1;
seek_jump(app, &global_part, skip_repeats, skip_sub_errors, dir);
seek_jump(app, skip_repeats, skip_sub_errors, dir);
}
CUSTOM_COMMAND_SIG(goto_prev_jump_no_skips_direct)
@ -89,20 +91,18 @@ CUSTOM_DOC("If a buffer containing jump locations has been locked in, goes to th
b32 skip_repeats = false;
b32 skip_sub_errors = true;
i32 dir = -1;
seek_jump(app, &global_part, skip_repeats, skip_sub_errors, dir);
seek_jump(app, skip_repeats, skip_sub_errors, dir);
}
CUSTOM_COMMAND_SIG(goto_first_jump_direct)
CUSTOM_DOC("If a buffer containing jump locations has been locked in, goes to the first jump in the buffer.")
{
Temp_Memory temp = begin_temp_memory(&global_part);
View_ID view = get_view_for_locked_jump_buffer(app);
if (view != 0){
view_set_cursor(app, view, seek_pos(0), true);
memset(&prev_location, 0, sizeof(prev_location));
seek_jump(app, &global_part, false, true, 1);
seek_jump(app, false, true, 1);
}
end_temp_memory(temp);
}
//

View File

@ -5,9 +5,9 @@
// TOP
static void
activate_jump(Application_Links *app, Partition *scratch, Heap *heap,
activate_jump(Application_Links *app, Heap *heap,
View_ID view, struct Lister_State *state,
String text_field, void *user_data, b32 activated_by_mouse){
String_Const_u8 text_field, void *user_data, b32 activated_by_mouse){
Lister_Activation_Code result_code = ListerActivation_Finished;
i32 list_index = (i32)PtrAsInt(user_data);
Jump_Lister_Parameters *params = (Jump_Lister_Parameters*)state->lister.data.user_data;
@ -58,29 +58,29 @@ activate_jump(Application_Links *app, Partition *scratch, Heap *heap,
}
}
lister_default(app, scratch, heap, view, state, result_code);
lister_default(app, heap, view, state, result_code);
}
static void
open_jump_lister(Application_Links *app, Partition *scratch, Heap *heap, View_ID ui_view, Buffer_ID list_buffer_id, Jump_Lister_Activation_Rule activation_rule, View_ID optional_target_view){
open_jump_lister(Application_Links *app, Heap *heap, View_ID ui_view, Buffer_ID list_buffer_id, Jump_Lister_Activation_Rule activation_rule, View_ID optional_target_view){
Marker_List *list = get_or_make_list_for_buffer(app, scratch, heap, list_buffer_id);
Marker_List *list = get_or_make_list_for_buffer(app, heap, list_buffer_id);
if (list != 0){
i32 estimated_string_space_size = 0;
view_end_ui_mode(app, ui_view);
Temp_Memory temp = begin_temp_memory(scratch);
Arena *scratch = context_get_arena(app);
Temp_Memory temp = begin_temp(scratch);
i32 option_count = list->jump_count;
Lister_Option *options = push_array(scratch, Lister_Option, option_count);
Managed_Object stored_jumps = list->jump_array;
for (i32 i = 0; i < option_count; i += 1){
Sticky_Jump_Stored stored = {};
managed_object_load_data(app, stored_jumps, i, 1, &stored);
String line = {};
read_line(app, scratch, list_buffer_id, stored.list_line, &line);
String_Const_u8 line = scratch_read_line(app, scratch, list_buffer_id, stored.list_line);
options[i].string = line;
memset(&options[i].status, 0, sizeof(options[i].status));
options[i].user_data = IntAsPtr(i);
i32 aligned_size = line.size + 1 + 7;
i32 aligned_size = ((i32)line.size) + 1 + 7;
aligned_size = aligned_size - aligned_size%8;
estimated_string_space_size += aligned_size;
}
@ -97,7 +97,7 @@ open_jump_lister(Application_Links *app, Partition *scratch, Heap *heap, View_ID
options, option_count,
estimated_string_space_size,
ui_view);
end_temp_memory(temp);
end_temp(temp);
}
}
@ -108,7 +108,7 @@ CUSTOM_DOC("When executed on a buffer with jumps, creates a persistent lister fo
get_active_view(app, AccessAll, &view);
Buffer_ID buffer = 0;
view_get_buffer(app, view, AccessAll, &buffer);
open_jump_lister(app, &global_part, &global_heap, view, buffer, JumpListerActivation_OpenInNextViewKeepUI, 0);
open_jump_lister(app, &global_heap, view, buffer, JumpListerActivation_OpenInNextViewKeepUI, 0);
}
// BOTTOM

View File

@ -39,9 +39,10 @@ binary_search(u32 *array, i32 stride, i32 count, u32 x){
}
static Sticky_Jump_Array
parse_buffer_to_jump_array(Application_Links *app, Partition *arena, Buffer_ID buffer){
Sticky_Jump_Array result = {};
result.jumps = push_array(arena, Sticky_Jump, 0);
parse_buffer_to_jump_array(Application_Links *app, Arena *arena, Buffer_ID buffer){
Sticky_Jump_Node *jump_first = 0;;
Sticky_Jump_Node *jump_last = 0;
i32 jump_count = 0;
for (i32 line = 1;; line += 1){
b32 output_jump = false;
@ -50,41 +51,53 @@ parse_buffer_to_jump_array(Application_Links *app, Partition *arena, Buffer_ID b
Buffer_ID out_buffer_id = 0;
i32 out_pos = 0;
Temp_Memory temp = begin_temp_memory(arena);
String line_str = {};
if (read_line(app, arena, buffer, line, &line_str)){
Parsed_Jump parsed_jump = parse_jump_location(line_str);
if (parsed_jump.success){
Buffer_ID jump_buffer = {};
if (open_file(app, &jump_buffer, parsed_jump.location.file.str, parsed_jump.location.file.size, false, true)){
if (buffer_exists(app, jump_buffer)){
Partial_Cursor cursor = {};
if (buffer_compute_cursor(app, jump_buffer, seek_line_char(parsed_jump.location.line, parsed_jump.location.column), &cursor)){
out_buffer_id = jump_buffer;
out_pos = cursor.pos;
output_jump = true;
{
Scratch_Block line_auto_closer(arena);
if (is_valid_line(app, buffer, line)){
String_Const_u8 line_str = scratch_read_line(app, arena, buffer, line);
Parsed_Jump parsed_jump = parse_jump_location(line_str);
if (parsed_jump.success){
Buffer_ID jump_buffer = {};
if (open_file(app, &jump_buffer, parsed_jump.location.file, false, true)){
if (buffer_exists(app, jump_buffer)){
Partial_Cursor cursor = {};
if (buffer_compute_cursor(app, jump_buffer, seek_line_char(parsed_jump.location.line, parsed_jump.location.column), &cursor)){
out_buffer_id = jump_buffer;
out_pos = cursor.pos;
output_jump = true;
}
}
}
}
}
else{
break;
}
}
else{
end_temp_memory(temp);
break;
}
end_temp_memory(temp);
if (output_jump){
Sticky_Jump *jump = push_array(arena, Sticky_Jump, 1);
jump->list_line = line;
jump->list_colon_index = colon_index;
jump->is_sub_error = is_sub_error;
jump->jump_buffer_id = out_buffer_id;
jump->jump_pos = out_pos;
Sticky_Jump_Node *jump = push_array(arena, Sticky_Jump_Node, 1);
sll_queue_push(jump_first, jump_last, jump);
jump_count += 1;
jump->jump.list_line = line;
jump->jump.list_colon_index = colon_index;
jump->jump.is_sub_error = is_sub_error;
jump->jump.jump_buffer_id = out_buffer_id;
jump->jump.jump_pos = out_pos;
}
}
result.count = (i32)(push_array(arena, Sticky_Jump, 0) - result.jumps);
Sticky_Jump_Array result = {};
result.count = jump_count;
result.jumps = push_array(arena, Sticky_Jump, result.count);
i32 index = 0;
for (Sticky_Jump_Node *node = jump_first;
node != 0;
node = node->next){
result.jumps[index] = node->jump;
index += 1;
}
return(result);
}
@ -92,14 +105,13 @@ static char sticky_jump_marker_handle_var[] = "DEFAULT.sticky_jump_marker_han
static i32 sticky_jump_marker_handle_loc;
static void
init_marker_list(Application_Links *app, Partition *scratch, Heap *heap, Buffer_ID buffer, Marker_List *list){
Arena *scratch_arena = context_get_arena(app);
Temp_Memory_Arena temp_arena = begin_temp_memory(scratch_arena);
init_marker_list(Application_Links *app, Heap *heap, Buffer_ID buffer, Marker_List *list){
Arena *scratch = context_get_arena(app);
Temp_Memory temp = begin_temp(scratch);
String buffer_name = buffer_push_base_buffer_name(app, buffer, scratch_arena);
b32 is_compilation_buffer = match(buffer_name, "*compilation*");
String_Const_u8 buffer_name = buffer_push_base_buffer_name(app, buffer, scratch);
b32 is_compilation_buffer = string_match(buffer_name, string_u8_litexpr("*compilation*"));
Temp_Memory temp = begin_temp_memory(scratch);
Sticky_Jump_Array jumps = parse_buffer_to_jump_array(app, scratch, buffer);
Range_Array buffer_ranges = get_ranges_of_duplicate_keys(scratch, &jumps.jumps->jump_buffer_id, sizeof(*jumps.jumps), jumps.count);
Sort_Pair_i32 *range_index_buffer_id_pairs = push_array(scratch, Sort_Pair_i32, buffer_ranges.count);
@ -116,15 +128,24 @@ init_marker_list(Application_Links *app, Partition *scratch, Heap *heap, Buffer_
Sticky_Jump_Stored *stored = push_array(scratch, Sticky_Jump_Stored, jumps.count);
Managed_Scope scope_array[2] = {};
scope_array[0] = buffer_get_managed_scope(app, buffer);
buffer_get_managed_scope(app, buffer, &scope_array[0]);
for (i32 i = 0; i < scoped_buffer_ranges.count; i += 1){
Range buffer_range_indices = scoped_buffer_ranges.ranges[i];
Temp_Memory marker_temp = begin_temp_memory(scratch);
Marker *markers = push_array(scratch, Marker, 0);
u32 total_jump_count = 0;
for (i32 j = buffer_range_indices.first;
j < buffer_range_indices.one_past_last;
j += 1){
i32 range_index = range_index_buffer_id_pairs[j].index;
Range range = buffer_ranges.ranges[range_index];
total_jump_count += range_size(range);
}
Temp_Memory marker_temp = begin_temp(scratch);
Marker *markers = push_array(scratch, Marker, total_jump_count);
Buffer_ID target_buffer_id = 0;
u32 marker_index = 0;
for (i32 j = buffer_range_indices.first;
j < buffer_range_indices.one_past_last;
j += 1){
@ -134,19 +155,18 @@ init_marker_list(Application_Links *app, Partition *scratch, Heap *heap, Buffer_
target_buffer_id = jumps.jumps[range.first].jump_buffer_id;
}
for (i32 k = range.first; k < range.one_past_last; k += 1){
Marker *new_marker = push_array(scratch, Marker, 1);
new_marker->pos = jumps.jumps[k].jump_pos;
new_marker->lean_right = false;
markers[marker_index].pos = jumps.jumps[k].jump_pos;
markers[marker_index].lean_right = false;
stored[k].list_line = jumps.jumps[k].list_line;
stored[k].list_colon_index = jumps.jumps[k].list_colon_index;
stored[k].is_sub_error = jumps.jumps[k].is_sub_error;
stored[k].jump_buffer_id = jumps.jumps[k].jump_buffer_id;
stored[k].index_into_marker_array = total_jump_count;
total_jump_count += 1;
stored[k].index_into_marker_array = marker_index;
marker_index += 1;
}
}
scope_array[1] = buffer_get_managed_scope(app, target_buffer_id);
buffer_get_managed_scope(app, target_buffer_id, &scope_array[1]);
Managed_Scope scope = get_managed_scope_with_multiple_dependencies(app, scope_array, ArrayCount(scope_array));
Managed_Object marker_handle = alloc_buffer_markers_on_buffer(app, target_buffer_id, total_jump_count, &scope);
managed_object_store_data(app, marker_handle, 0, total_jump_count, markers);
@ -156,7 +176,7 @@ init_marker_list(Application_Links *app, Partition *scratch, Heap *heap, Buffer_
marker_visual_set_effect(app, visual, VisualType_LineHighlights, Stag_Highlight_Junk, 0, 0);
}
end_temp_memory(marker_temp);
end_temp(marker_temp);
Assert(managed_object_get_item_size(app, marker_handle) == sizeof(Marker));
Assert(managed_object_get_item_count(app, marker_handle) == total_jump_count);
@ -169,14 +189,12 @@ init_marker_list(Application_Links *app, Partition *scratch, Heap *heap, Buffer_
Managed_Object stored_jump_array = alloc_managed_memory_in_scope(app, scope_array[0], sizeof(Sticky_Jump_Stored), jumps.count);
managed_object_store_data(app, stored_jump_array, 0, jumps.count, stored);
end_temp_memory(temp);
list->jump_array = stored_jump_array;
list->jump_count = jumps.count;
buffer_get_size(app, buffer, &list->previous_size);
list->buffer_id = buffer;
end_temp_memory(temp_arena);
end_temp(temp);
}
static void
@ -212,7 +230,7 @@ get_marker_list_for_buffer(Buffer_ID buffer_id){
}
static Marker_List*
get_or_make_list_for_buffer(Application_Links *app, Partition *scratch, Heap *heap, Buffer_ID buffer_id){
get_or_make_list_for_buffer(Application_Links *app, Heap *heap, Buffer_ID buffer_id){
Marker_List *result = get_marker_list_for_buffer(buffer_id);
if (result != 0){
i32 buffer_size = 0;
@ -225,7 +243,7 @@ get_or_make_list_for_buffer(Application_Links *app, Partition *scratch, Heap *he
}
if (result == 0){
result = make_new_marker_list_for_buffer(heap, buffer_id);
init_marker_list(app, scratch, heap, buffer_id, result);
init_marker_list(app, heap, buffer_id, result);
if (result->jump_count == 0){
delete_marker_list(result);
result = 0;
@ -248,15 +266,15 @@ get_stored_jump_from_list(Application_Links *app, Marker_List *list, i32 index,
}
static Sticky_Jump_Stored*
get_all_stored_jumps_from_list(Application_Links *app, Partition *arena, Marker_List *list){
get_all_stored_jumps_from_list(Application_Links *app, Arena *arena, Marker_List *list){
Sticky_Jump_Stored *stored = 0;
if (list != 0){
Temp_Memory restore_point = begin_temp_memory(arena);
Temp_Memory restore_point = begin_temp(arena);
stored = push_array(arena, Sticky_Jump_Stored, list->jump_count);
if (stored != 0){
if (!managed_object_load_data(app, list->jump_array, 0, list->jump_count, stored)){
stored = 0;
end_temp_memory(restore_point);
end_temp(restore_point);
}
}
}
@ -271,8 +289,8 @@ get_jump_from_list(Application_Links *app, Marker_List *list, i32 index, ID_Pos_
Buffer_ID target_buffer_id = stored.jump_buffer_id;
Managed_Scope scope_array[2] = {};
scope_array[0] = buffer_get_managed_scope(app, list->buffer_id);
scope_array[1] = buffer_get_managed_scope(app, target_buffer_id);
buffer_get_managed_scope(app, list->buffer_id, &scope_array[0]);
buffer_get_managed_scope(app, target_buffer_id, &scope_array[1]);
Managed_Scope scope = get_managed_scope_with_multiple_dependencies(app, scope_array, ArrayCount(scope_array));
sticky_jump_marker_handle_loc = managed_variable_create_or_get_id(app, sticky_jump_marker_handle_var, 0);
@ -313,24 +331,26 @@ get_is_sub_error_from_list(Application_Links *app, Marker_List *list, i32 index)
}
static i32
get_index_nearest_from_list(Application_Links *app, Partition *scratch, Marker_List *list, i32 line){
get_index_nearest_from_list(Application_Links *app, Marker_List *list, i32 line){
i32 result = -1;
if (list != 0){
Temp_Memory temp = begin_temp_memory(scratch);
Arena *scratch = context_get_arena(app);
Temp_Memory temp = begin_temp(scratch);
Sticky_Jump_Stored *stored = get_all_stored_jumps_from_list(app, scratch, list);
if (stored != 0){
result = binary_search((u32*)&stored->list_line, sizeof(*stored), list->jump_count, line);
}
end_temp_memory(temp);
end_temp(temp);
}
return(result);
}
static i32
get_index_exact_from_list(Application_Links *app, Partition *scratch, Marker_List *list, i32 line){
get_index_exact_from_list(Application_Links *app, Marker_List *list, i32 line){
i32 result = -1;
if (list != 0){
Temp_Memory temp = begin_temp_memory(scratch);
Arena *scratch = context_get_arena(app);
Temp_Memory temp = begin_temp(scratch);
Sticky_Jump_Stored *stored = get_all_stored_jumps_from_list(app, scratch, list);
if (stored != 0){
i32 index = binary_search((u32*)&stored->list_line, sizeof(*stored), list->jump_count, line);
@ -338,7 +358,7 @@ get_index_exact_from_list(Application_Links *app, Partition *scratch, Marker_Lis
result = index;
}
}
end_temp_memory(temp);
end_temp(temp);
}
return(result);
}
@ -347,21 +367,19 @@ CUSTOM_COMMAND_SIG(goto_jump_at_cursor_sticky)
CUSTOM_DOC("If the cursor is found to be on a jump location, parses the jump location and brings up the file and position in another view and changes the active panel to the view containing the jump.")
{
Heap *heap = &global_heap;
Partition *part = &global_part;
Temp_Memory temp = begin_temp_memory(part);
View_ID view = 0;
get_active_view(app, AccessProtected, &view);
Buffer_ID buffer = 0;
view_get_buffer(app, view, AccessProtected, &buffer);
Marker_List *list = get_or_make_list_for_buffer(app, part, heap, buffer);
Marker_List *list = get_or_make_list_for_buffer(app, heap, buffer);
i32 pos = 0;
view_get_cursor_pos(app, view, &pos);
Full_Cursor cursor = {};
view_compute_cursor(app, view, seek_pos(pos), &cursor);
i32 list_index = get_index_exact_from_list(app, part, list, cursor.line);
i32 list_index = get_index_exact_from_list(app, list, cursor.line);
if (list_index >= 0){
ID_Pos_Jump_Location location = {};
@ -375,30 +393,26 @@ CUSTOM_DOC("If the cursor is found to be on a jump location, parses the jump loc
}
}
}
end_temp_memory(temp);
}
CUSTOM_COMMAND_SIG(goto_jump_at_cursor_same_panel_sticky)
CUSTOM_DOC("If the cursor is found to be on a jump location, parses the jump location and brings up the file and position in this view, losing the compilation output or jump list.")
{
Heap *heap = &global_heap;
Partition *part = &global_part;
Temp_Memory temp = begin_temp_memory(part);
View_ID view = 0;
get_active_view(app, AccessProtected, &view);
Buffer_ID buffer = 0;
view_get_buffer(app, view, AccessProtected, &buffer);
Marker_List *list = get_or_make_list_for_buffer(app, part, heap, buffer);
Marker_List *list = get_or_make_list_for_buffer(app, heap, buffer);
i32 pos = 0;
view_get_cursor_pos(app, view, &pos);
Full_Cursor cursor = {};
view_compute_cursor(app, view, seek_pos(pos), &cursor);
i32 list_index = get_index_exact_from_list(app, part, list, cursor.line);
i32 list_index = get_index_exact_from_list(app, list, cursor.line);
if (list_index >= 0){
ID_Pos_Jump_Location location = {};
@ -408,8 +422,6 @@ CUSTOM_DOC("If the cursor is found to be on a jump location, parses the jump loc
}
}
}
end_temp_memory(temp);
}
static void
@ -473,19 +485,19 @@ goto_next_filtered_jump(Application_Links *app, Marker_List *list, View_ID jump_
}
static Locked_Jump_State
get_locked_jump_state(Application_Links *app, Partition *part, Heap *heap){
get_locked_jump_state(Application_Links *app, Heap *heap){
Locked_Jump_State result = {};
result.view = get_view_for_locked_jump_buffer(app);
if (result.view != 0){
Buffer_ID buffer = 0;
view_get_buffer(app, result.view, AccessAll, &buffer);
result.list = get_or_make_list_for_buffer(app, part, heap, buffer);
result.list = get_or_make_list_for_buffer(app, heap, buffer);
i32 cursor_position = 0;
view_get_cursor_pos(app, result.view, &cursor_position);
Full_Cursor cursor = {};
view_compute_cursor(app, result.view, seek_pos(cursor_position), &cursor);
result.list_index = get_index_nearest_from_list(app, part, result.list, cursor.line);
result.list_index = get_index_nearest_from_list(app, result.list, cursor.line);
}
return(result);
}
@ -494,9 +506,8 @@ CUSTOM_COMMAND_SIG(goto_next_jump_sticky)
CUSTOM_DOC("If a buffer containing jump locations has been locked in, goes to the next jump in the buffer, skipping sub jump locations.")
{
Heap *heap = &global_heap;
Partition *part = &global_part;
Locked_Jump_State jump_state = get_locked_jump_state(app, part, heap);
Locked_Jump_State jump_state = get_locked_jump_state(app, heap);
if (jump_state.view != 0){
i32 cursor_position = 0;
view_get_cursor_pos(app, jump_state.view, &cursor_position);
@ -513,9 +524,8 @@ CUSTOM_DOC("If a buffer containing jump locations has been locked in, goes to th
CUSTOM_COMMAND_SIG(goto_prev_jump_sticky)
CUSTOM_DOC("If a buffer containing jump locations has been locked in, goes to the previous jump in the buffer, skipping sub jump locations."){
Heap *heap = &global_heap;
Partition *part = &global_part;
Locked_Jump_State jump_state = get_locked_jump_state(app, part, heap);
Locked_Jump_State jump_state = get_locked_jump_state(app, heap);
if (jump_state.view != 0){
if (jump_state.list_index > 0){
--jump_state.list_index;
@ -528,9 +538,8 @@ CUSTOM_COMMAND_SIG(goto_next_jump_no_skips_sticky)
CUSTOM_DOC("If a buffer containing jump locations has been locked in, goes to the next jump in the buffer, and does not skip sub jump locations.")
{
Heap *heap = &global_heap;
Partition *part = &global_part;
Locked_Jump_State jump_state = get_locked_jump_state(app, part, heap);
Locked_Jump_State jump_state = get_locked_jump_state(app, heap);
if (jump_state.view != 0){
i32 cursor_position = 0;
view_get_cursor_pos(app, jump_state.view, &cursor_position);
@ -548,9 +557,8 @@ CUSTOM_COMMAND_SIG(goto_prev_jump_no_skips_sticky)
CUSTOM_DOC("If a buffer containing jump locations has been locked in, goes to the previous jump in the buffer, and does not skip sub jump locations.")
{
Heap *heap = &global_heap;
Partition *part = &global_part;
Locked_Jump_State jump_state = get_locked_jump_state(app, part, heap);
Locked_Jump_State jump_state = get_locked_jump_state(app, heap);
if (jump_state.view != 0){
if (jump_state.list_index > 0){
--jump_state.list_index;
@ -563,9 +571,8 @@ CUSTOM_COMMAND_SIG(goto_first_jump_sticky)
CUSTOM_DOC("If a buffer containing jump locations has been locked in, goes to the first jump in the buffer.")
{
Heap *heap = &global_heap;
Partition *part = &global_part;
Locked_Jump_State jump_state = get_locked_jump_state(app, part, heap);
Locked_Jump_State jump_state = get_locked_jump_state(app, heap);
if (jump_state.view != 0){
i32 list_index = 0;
ID_Pos_Jump_Location location = {};
@ -581,9 +588,8 @@ CUSTOM_COMMAND_SIG(goto_first_jump_same_panel_sticky)
CUSTOM_DOC("If a buffer containing jump locations has been locked in, goes to the first jump in the buffer and views the buffer in the panel where the jump list was.")
{
Heap *heap = &global_heap;
Partition *part = &global_part;
Locked_Jump_State jump_state = get_locked_jump_state(app, part, heap);
Locked_Jump_State jump_state = get_locked_jump_state(app, heap);
if (jump_state.view != 0){
i32 list_index = 0;
ID_Pos_Jump_Location location = {};

View File

@ -23,6 +23,11 @@ struct Sticky_Jump_Stored{
i32 index_into_marker_array;
};
struct Sticky_Jump_Node{
Sticky_Jump_Node *next;
Sticky_Jump jump;
};
struct Sticky_Jump_Array{
Sticky_Jump *jumps;
i32 count;

View File

@ -5,24 +5,24 @@
// TOP
static b32
ms_style_verify(String line, i32 left_paren_pos, i32 right_paren_pos){
ms_style_verify(String_Const_u8 line, umem left_paren_pos, umem right_paren_pos){
i32 result = false;
String line_part = substr_tail(line, right_paren_pos);
if (match_part_sc(line_part, ") : ")){
String_Const_u8 line_part = string_skip(line, right_paren_pos);
if (string_match(string_prefix(line_part, 4), string_u8_litexpr(") : "))){
result = true;
}
else if (match_part_sc(line_part, "): ")){
else if (string_match(string_prefix(line_part, 3), string_u8_litexpr("): "))){
result = true;
}
if (result){
String number = substr(line, left_paren_pos + 1, right_paren_pos - left_paren_pos - 2);
if (!str_is_int_s(number)){
String_Const_u8 number = string_skip(string_prefix(line, right_paren_pos - 1), left_paren_pos + 1);
if (!string_is_integer(number, 10)){
result = false;
i32 comma_pos = find_s_char(number, 0, ',');
umem comma_pos = string_find_first(number, ',');
if (comma_pos < number.size){
String sub_number0 = substr(number, 0, comma_pos);
String sub_number1 = substr(number, comma_pos + 1, number.size - comma_pos - 1);
if (str_is_int_s(sub_number0) && str_is_int_s(sub_number1)){
String_Const_u8 sub_number0 = string_prefix(number, comma_pos);
String_Const_u8 sub_number1 = string_skip(number, comma_pos + 1);
if (string_is_integer(sub_number0, 10) && string_is_integer(sub_number1, 10)){
result = true;
}
}
@ -31,25 +31,25 @@ ms_style_verify(String line, i32 left_paren_pos, i32 right_paren_pos){
return(result);
}
static i32
try_skip_rust_arrow(String line){
i32 pos = 0;
if (match_part(line, "-->")){
String sub = substr_tail(line, 3);
sub = skip_chop_whitespace(sub);
pos = (i32)(sub.str - line.str);
static umem
try_skip_rust_arrow(String_Const_u8 line){
umem pos = 0;
if (string_match(string_prefix(line, 3), string_u8_litexpr("-->"))){
String_Const_u8 sub = string_skip(line, 3);
sub = string_skip_chop_whitespace(sub);
pos = (umem)(sub.str - line.str);
}
return(pos);
}
static b32
check_is_note(String line, i32 colon_pos){
check_is_note(String_Const_u8 line, umem colon_pos){
b32 is_note = false;
i32 note_pos = find_substr(line, colon_pos, make_lit_string("note"));
umem note_pos = colon_pos + string_find_first(string_skip(line, colon_pos), string_u8_litexpr("note"));
if (note_pos < line.size){
b32 is_all_whitespace = true;
for (i32 i = colon_pos + 1; i < note_pos; i += 1){
if (!char_is_whitespace(line.str[i])){
for (umem i = colon_pos + 1; i < note_pos; i += 1){
if (!character_is_whitespace(line.str[i])){
is_all_whitespace = false;
break;
}
@ -62,54 +62,53 @@ check_is_note(String line, i32 colon_pos){
}
static Parsed_Jump
parse_jump_location(String line){
parse_jump_location(String_Const_u8 line){
Parsed_Jump jump = {};
jump.sub_jump_indented = (line.str[0] == ' ');
jump.sub_jump_indented = (string_get_character(line, 0) == ' ');
i32 whitespace_length = 0;
line = skip_chop_whitespace(line, &whitespace_length);
String_Const_u8 reduced_line = string_skip_chop_whitespace(line);
umem whitespace_length = (umem)(reduced_line.str - line.str);
line = reduced_line;
i32 left_paren_pos = find_s_char(line, 0, '(');
i32 right_paren_pos = find_s_char(line, left_paren_pos, ')');
umem left_paren_pos = string_find_first(line, '(');
umem right_paren_pos = left_paren_pos + string_find_first(string_skip(line, left_paren_pos), ')');
for (;!jump.is_ms_style && right_paren_pos < line.size;){
if (ms_style_verify(line, left_paren_pos, right_paren_pos)){
jump.is_ms_style = true;
jump.colon_position = find_s_char(line, right_paren_pos, ':');
jump.colon_position = (i32)(right_paren_pos + string_find_first(string_skip(line, right_paren_pos), ':'));
if (jump.colon_position < line.size){
if (check_is_note(line, jump.colon_position)){
jump.sub_jump_note = true;
}
String location_str = substr(line, 0, jump.colon_position);
String_Const_u8 location_str = string_prefix(line, jump.colon_position);
location_str = string_skip_chop_whitespace(location_str);
location_str = skip_chop_whitespace(location_str);
i32 close_pos = right_paren_pos;
i32 open_pos = left_paren_pos;
i32 close_pos = (i32)right_paren_pos;
i32 open_pos = (i32)left_paren_pos;
if (0 < open_pos && open_pos < location_str.size){
String file = substr(location_str, 0, open_pos);
file = skip_chop_whitespace(file);
String_Const_u8 file = SCu8(location_str.str, open_pos);
file = string_skip_chop_whitespace(file);
if (file.size > 0){
String line_number = substr(location_str, open_pos + 1, close_pos-open_pos - 1);
line_number = skip_chop_whitespace(line_number);
String_Const_u8 line_number = string_skip(string_prefix(location_str, close_pos), open_pos + 1);
line_number = string_skip_chop_whitespace(line_number);
if (line_number.size > 0){
i32 comma_pos = find_s_char(line_number, 0, ',');
umem comma_pos = string_find_first(line_number, ',');
if (comma_pos < line_number.size){
i32 start = comma_pos + 1;
String column_number = substr(line_number, start, line_number.size-start);
line_number = substr(line_number, 0, comma_pos);
jump.location.line = str_to_int_s(line_number);
jump.location.column = str_to_int_s(column_number);
String_Const_u8 column_number = string_skip(line_number, comma_pos + 1);
line_number = string_prefix(line_number, comma_pos);
jump.location.line = (i32)string_to_integer(line_number, 10);
jump.location.column = (i32)string_to_integer(column_number, 10);
}
else{
jump.location.line = str_to_int_s(line_number);
jump.location.line = (i32)string_to_integer(line_number, 10);
jump.location.column = 0;
}
jump.location.file = file;
jump.colon_position = jump.colon_position + whitespace_length;
jump.colon_position = jump.colon_position + (i32)whitespace_length;
jump.success = true;
}
}
@ -117,43 +116,41 @@ parse_jump_location(String line){
}
}
else{
left_paren_pos = find_s_char(line, left_paren_pos + 1, '(');
right_paren_pos = find_s_char(line, left_paren_pos, ')');
left_paren_pos = string_find_first(string_skip(line, left_paren_pos + 1), '(') + left_paren_pos + 1;
right_paren_pos = string_find_first(string_skip(line, left_paren_pos), ')') + left_paren_pos;
}
}
if (!jump.is_ms_style){
i32 start = try_skip_rust_arrow(line);
i32 start = (i32)try_skip_rust_arrow(line);
if (start != 0){
jump.has_rust_arrow = true;
}
i32 colon_pos1 = find_s_char(line, start, ':');
umem colon_pos1 = string_find_first(string_skip(line, start), ':') + start;
if (line.size > colon_pos1 + 1){
if (char_is_slash(line.str[colon_pos1 + 1])){
colon_pos1 = find_s_char(line, colon_pos1 + 1, ':');
if (character_is_slash(string_get_character(line, colon_pos1 + 1))){
colon_pos1 = string_find_first(string_skip(line, colon_pos1 + 1), ':') + colon_pos1 + 1;
}
}
i32 colon_pos2 = find_s_char(line, colon_pos1 + 1, ':');
i32 colon_pos3 = find_s_char(line, colon_pos2 + 1, ':');
umem colon_pos2 = string_find_first(string_skip(line, colon_pos1 + 1), ':') + colon_pos1 + 1;
umem colon_pos3 = string_find_first(string_skip(line, colon_pos2 + 1), ':') + colon_pos2 + 1;
if (colon_pos3 < line.size){
if (check_is_note(line, colon_pos3)){
jump.sub_jump_note = true;
}
String filename = substr(line, start, colon_pos1 - start);
String line_number = substr(line, colon_pos1 + 1, colon_pos2 - colon_pos1 - 1);
String column_number = substr(line, colon_pos2 + 1, colon_pos3 - colon_pos2 - 1);
String_Const_u8 file_name = string_skip(string_prefix(line, colon_pos1), start);
String_Const_u8 line_number = string_skip(string_prefix(line, colon_pos2), colon_pos1 + 1);
String_Const_u8 column_number = string_skip(string_prefix(line, colon_pos3), colon_pos2 + 1);
if (filename.size > 0 &&
line_number.size > 0 &&
column_number.size > 0){
jump.location.file = filename;
jump.location.line = str_to_int_s(line_number);
jump.location.column = str_to_int_s(column_number);
jump.colon_position = colon_pos3 + whitespace_length;
if (file_name.size > 0 && line_number.size > 0 && column_number.size > 0){
jump.location.file = file_name;
jump.location.line = (i32)string_to_integer(line_number, 10);
jump.location.column = (i32)string_to_integer(column_number, 10);
jump.colon_position = (i32)(colon_pos3 + whitespace_length);
jump.success = true;
}
}
@ -163,15 +160,15 @@ parse_jump_location(String line){
jump.sub_jump_note = true;
}
String filename = substr(line, 0, colon_pos1);
String line_number = substr(line, colon_pos1 + 1, colon_pos2 - colon_pos1 - 1);
String_Const_u8 file_name = string_prefix(line, colon_pos1);
String_Const_u8 line_number = string_skip(string_prefix(line, colon_pos2), colon_pos1 + 1);
if (str_is_int_s(line_number)){
if (filename.size > 0 && line_number.size > 0){
jump.location.file = filename;
jump.location.line = str_to_int_s(line_number);
if (string_is_integer(line_number, 10)){
if (file_name.size > 0 && line_number.size > 0){
jump.location.file = file_name;
jump.location.line = (i32)string_to_integer(line_number, 10);
jump.location.column = 0;
jump.colon_position = colon_pos3 + whitespace_length;
jump.colon_position = (i32)(colon_pos3 + whitespace_length);
jump.success = true;
}
}
@ -189,20 +186,20 @@ parse_jump_location(String line){
}
static Parsed_Jump
parse_jump_location(String line, b32 skip_sub_jump){
parse_jump_location(String_Const_u8 line, Jump_Flag flags){
Parsed_Jump jump = parse_jump_location(line);
if (jump.is_sub_jump && skip_sub_jump){
memset(&jump, 0, sizeof(jump));
if (HasFlag(flags, JumpFlag_SkipSubs) && jump.is_sub_jump){
block_zero_struct(&jump);
}
return(jump);
}
static Parsed_Jump
parse_jump_from_buffer_line(Application_Links *app, Partition *arena, Buffer_ID buffer_id, i32 line, b32 skip_sub_errors){
parse_jump_from_buffer_line(Application_Links *app, Arena *arena, Buffer_ID buffer_id, i32 line, Jump_Flag flags){
Parsed_Jump jump = {};
String line_str = {};
if (read_line(app, arena, buffer_id, line, &line_str)){
jump = parse_jump_location(line_str, skip_sub_errors);
String_Const_u8 line_str = scratch_read_line(app, arena, buffer_id, line);
if (line_str.size > 0){
jump = parse_jump_location(line_str, flags);
}
return(jump);
}
@ -211,7 +208,7 @@ parse_jump_from_buffer_line(Application_Links *app, Partition *arena, Buffer_ID
static b32
get_jump_buffer(Application_Links *app, Buffer_ID *buffer, Name_Line_Column_Location *location){
return(open_file(app, buffer, location->file.str, location->file.size, false, true));
return(open_file(app, buffer, location->file, false, true));
}
static b32
@ -269,16 +266,16 @@ jump_to_location(Application_Links *app, View_ID view, Buffer_ID buffer, ID_Pos_
////////////////////////////////
static Parsed_Jump
seek_next_jump_in_buffer(Application_Links *app, Partition *part,
i32 buffer_id, i32 first_line, b32 skip_sub_errors, i32 direction,
seek_next_jump_in_buffer(Application_Links *app, Arena *arena,
i32 buffer_id, i32 first_line, Jump_Flag flags, i32 direction,
i32 *line_out){
Assert(direction == 1 || direction == -1);
Parsed_Jump jump = {};
i32 line = first_line;
String line_str = {};
for (;;){
if (read_line(app, part, buffer_id, line, &line_str)){
jump = parse_jump_location(line_str, skip_sub_errors);
if (is_valid_line(app, buffer_id, line)){
String_Const_u8 line_str = scratch_read_line(app, arena, buffer_id, line);
jump = parse_jump_location(line_str, flags);
if (jump.success){
break;
}
@ -288,11 +285,8 @@ seek_next_jump_in_buffer(Application_Links *app, Partition *part,
break;
}
}
if (line < 0){
line = 0;
}
if (jump.success){
*line_out = line;
*line_out = clamp_bot(line, 0);
}
return(jump);
}
@ -311,7 +305,7 @@ convert_name_based_to_id_based(Application_Links *app, Name_Line_Column_Location
}
static Parsed_Jump
seek_next_jump_in_view(Application_Links *app, Partition *part, View_ID view, i32 skip_sub_errors, i32 direction, i32 *line_out){
seek_next_jump_in_view(Application_Links *app, Arena *arena, View_ID view, i32 skip_sub_errors, i32 direction, i32 *line_out){
i32 cursor_position = 0;
view_get_cursor_pos(app, view, &cursor_position);
Full_Cursor cursor = {};
@ -319,7 +313,7 @@ seek_next_jump_in_view(Application_Links *app, Partition *part, View_ID view, i3
i32 line = cursor.line;
Buffer_ID buffer = 0;
view_get_buffer(app, view, AccessAll, &buffer);
Parsed_Jump jump = seek_next_jump_in_buffer(app, part, buffer, line + direction, skip_sub_errors, direction, &line);
Parsed_Jump jump = seek_next_jump_in_buffer(app, arena, buffer, line + direction, skip_sub_errors, direction, &line);
if (jump.success){
*line_out = line;
}
@ -336,7 +330,7 @@ skip_this_jump(ID_Line_Column_Jump_Location prev, ID_Line_Column_Jump_Location j
}
static b32
advance_cursor_in_jump_view(Application_Links *app, Partition *part, View_ID view, i32 skip_repeats, i32 skip_sub_error, i32 direction, Name_Line_Column_Location *location_out){
advance_cursor_in_jump_view(Application_Links *app, View_ID view, i32 skip_repeats, i32 skip_sub_error, i32 direction, Name_Line_Column_Location *location_out){
b32 result = true;
Name_Line_Column_Location location = {};
@ -345,8 +339,9 @@ advance_cursor_in_jump_view(Application_Links *app, Partition *part, View_ID vie
i32 colon_index = 0;
do{
Temp_Memory temp = begin_temp_memory(part);
Parsed_Jump parsed_jump = seek_next_jump_in_view(app, part, view, skip_sub_error, direction, &line);
Arena *scratch = context_get_arena(app);
Temp_Memory temp = begin_temp(scratch);
Parsed_Jump parsed_jump = seek_next_jump_in_view(app, scratch, view, skip_sub_error, direction, &line);
if (parsed_jump.success){
jump = convert_name_based_to_id_based(app, parsed_jump.location);
view_set_cursor(app, view, seek_line_char(line, parsed_jump.colon_position + 1), true);
@ -356,7 +351,7 @@ advance_cursor_in_jump_view(Application_Links *app, Partition *part, View_ID vie
jump.buffer_id = 0;
result = false;
}
end_temp_memory(temp);
end_temp(temp);
}while(skip_repeats && skip_this_jump(prev_location, jump));
if (result){
@ -370,13 +365,13 @@ advance_cursor_in_jump_view(Application_Links *app, Partition *part, View_ID vie
}
static b32
seek_jump(Application_Links *app, Partition *part, b32 skip_repeats, b32 skip_sub_errors, i32 direction){
seek_jump(Application_Links *app, b32 skip_repeats, b32 skip_sub_errors, i32 direction){
b32 result = false;
View_ID view = get_view_for_locked_jump_buffer(app);
if (view != 0){
Name_Line_Column_Location location = {};
if (advance_cursor_in_jump_view(app, &global_part, view, skip_repeats, skip_sub_errors, direction, &location)){
if (advance_cursor_in_jump_view(app, view, skip_repeats, skip_sub_errors, direction, &location)){
Buffer_ID buffer = {};
if (get_jump_buffer(app, &buffer, &location)){
View_ID target_view = 0;

17
4coder_jumping.h Normal file
View File

@ -0,0 +1,17 @@
/*
4coder_jumping.h - Typesused when writing code to jump to locations and seek through jump lists.
*/
// TOP
#if !defined(FCODER_JUMPING_H)
#define FCODER_JUMPING_H
typedef u32 Jump_Flag;
enum{
JumpFlag_SkipSubs = 1,
};
#endif
// BOTTOM

View File

@ -9,8 +9,9 @@ distribute, and modify this file as you see fit.
// TOP
#if !defined(Migrating__Arena)
static Partition
make_part(void *memory, i32_4tech size){
make_part(void *memory, i32 size){
Partition part = {};
part.base = (char*)memory;
part.pos = 0;
@ -19,7 +20,7 @@ make_part(void *memory, i32_4tech size){
}
static void*
part_allocate(Partition *data, i32_4tech size){
part_allocate(Partition *data, i32 size){
void *ret = 0;
if (size < 0){
size = 0;
@ -32,15 +33,15 @@ part_allocate(Partition *data, i32_4tech size){
}
static void
part_reduce(Partition *data, i32_4tech size){
part_reduce(Partition *data, i32 size){
if (size > 0 && size <= data->pos){
data->pos -= size;
}
}
static void
part_align(Partition *data, i32_4tech boundary){
i32_4tech p = data->pos;
part_align(Partition *data, i32 boundary){
i32 p = data->pos;
p += boundary - 1;
data->pos = p - p%boundary;
}
@ -50,13 +51,13 @@ part_current(Partition *data){
return(data->base + data->pos);
}
static i32_4tech
static i32
part_remaining(Partition *data){
return(data->max - data->pos);
}
static Partition
part_sub_part(Partition *data, i32_4tech size){
part_sub_part(Partition *data, i32 size){
Partition result = {};
void *d = part_allocate(data, size);
if (d != 0){
@ -79,12 +80,12 @@ end_temp_memory(Temp_Memory temp){
}
static void*
push_allocator_allocate(Partition *part, i32_4tech size){
push_allocator_allocate(Partition *part, i32 size){
return(part_allocate(part, size));
}
static void
push_allocator_align(Partition *part, i32_4tech b){
push_allocator_align(Partition *part, i32 b){
part_align(part, b);
}
@ -93,7 +94,7 @@ push_allocator_align(Partition *part, i32_4tech b){
#if defined(FCODER_CUSTOM_H)
static Arena
make_arena(Application_Links *app, i32_4tech chunk_size, i32_4tech initial_align){
make_arena(Application_Links *app, i32 chunk_size, i32 initial_align){
Arena arena = {};
arena.app = app;
arena.chunk_size = chunk_size;
@ -102,7 +103,7 @@ make_arena(Application_Links *app, i32_4tech chunk_size, i32_4tech initial_align
}
static Arena
make_arena(Application_Links *app, i32_4tech chunk_size){
make_arena(Application_Links *app, i32 chunk_size){
return(make_arena(app, chunk_size, 1));
}
@ -124,15 +125,15 @@ arena_release_all(Arena *arena){
}
static void
arena_change_chunk_size(Arena *arena, i32_4tech chunk_size){
arena_change_chunk_size(Arena *arena, i32 chunk_size){
arena->chunk_size = chunk_size;
}
static Partition_Chained*
arena__new_part(Arena *arena, i32_4tech new_chunk_size){
arena__new_part(Arena *arena, i32 new_chunk_size){
Application_Links *app = arena->app;
i32_4tech memory_size = new_chunk_size + sizeof(Partition_Chained);
i32_4tech boundardy = 4096;
i32 memory_size = new_chunk_size + sizeof(Partition_Chained);
i32 boundardy = 4096;
if (memory_size < boundardy){
memory_size = boundardy;
}
@ -155,7 +156,7 @@ arena__new_part(Arena *arena){
}
static void
arena__align_inner(Arena *arena, i32_4tech b){
arena__align_inner(Arena *arena, i32 b){
if (arena->align != 1){
Partition_Chained *part = arena->part;
if (part == 0){
@ -166,7 +167,7 @@ arena__align_inner(Arena *arena, i32_4tech b){
}
static void*
arena_allocate(Arena *arena, i32_4tech size){
arena_allocate(Arena *arena, i32 size){
void *result = 0;
Partition_Chained *part = arena->part;
if (part == 0){
@ -175,7 +176,7 @@ arena_allocate(Arena *arena, i32_4tech size){
arena__align_inner(arena, arena->align);
result = part_allocate(&part->part, size);
if (result == 0){
i32_4tech new_chunk_size = arena->chunk_size;
i32 new_chunk_size = arena->chunk_size;
if (size > new_chunk_size){
new_chunk_size = size;
}
@ -188,13 +189,13 @@ arena_allocate(Arena *arena, i32_4tech size){
}
static void
arena_align(Arena *arena, i32_4tech b){
arena_align(Arena *arena, i32 b){
arena__align_inner(arena, b);
arena->align = b;
}
static Partition*
arena_use_as_part(Arena *arena, i32_4tech minimum_part_size){
arena_use_as_part(Arena *arena, i32 minimum_part_size){
if (minimum_part_size < arena->chunk_size){
minimum_part_size = arena->chunk_size;
}
@ -254,12 +255,12 @@ end_temp_memory(Arena *arena, Temp_Memory_Arena_Light temp){
}
static void*
push_allocator_allocate(Arena *arena, i32_4tech size){
push_allocator_allocate(Arena *arena, i32 size){
return(arena_allocate(arena, size));
}
static void
push_allocator_align(Arena *arena, i32_4tech b){
push_allocator_align(Arena *arena, i32 b){
arena_align(arena, b);
}
@ -285,6 +286,7 @@ Scratch_Block::operator Arena*(){
#define push_array(A, T, size) (T*)push_allocator_allocate((A), sizeof(T)*(size))
#define push_align(A, b) push_allocator_align((A), (b))
#define reset_temp_memory end_temp_memory
#endif
// BOTTOM

View File

@ -12,47 +12,16 @@ distribute, and modify this file as you see fit.
#if !defined(FCODER_ARENA_H)
#define FCODER_ARENA_H
// 4tech_standard_preamble.h
#if !defined(FTECH_INTEGERS)
#define FTECH_INTEGERS
#include <stdint.h>
typedef int8_t i8_4tech;
typedef int16_t i16_4tech;
typedef int32_t i32_4tech;
typedef int64_t i64_4tech;
typedef uint8_t u8_4tech;
typedef uint16_t u16_4tech;
typedef uint32_t u32_4tech;
typedef uint64_t u64_4tech;
#if defined(FTECH_32_BIT)
typedef u32_4tech umem_4tech;
#else
typedef u64_4tech umem_4tech;
#endif
typedef float f32_4tech;
typedef double f64_4tech;
typedef int8_t b8_4tech;
typedef int32_t b32_4tech;
#endif
#if !defined(Assert)
# define Assert(n) do{ if (!(n)) *(int*)0 = 0xA11E; }while(0)
#endif
// standard preamble end
#if !defined(Migrating__Arena)
struct Partition{
char *base;
i32_4tech pos;
i32_4tech max;
i32 pos;
i32 max;
};
struct Temp_Memory{
Partition *part;
i32_4tech pos;
i32 pos;
};
#if defined(FCODER_CUSTOM_H)
@ -65,19 +34,19 @@ struct Partition_Chained{
struct Arena{
struct Application_Links *app;
Partition_Chained *part;
i32_4tech chunk_size;
i32_4tech align;
i32 chunk_size;
i32 align;
};
struct Temp_Memory_Arena{
Arena *arena;
Partition_Chained *part;
i32_4tech pos;
i32 pos;
};
struct Temp_Memory_Arena_Light{
Partition_Chained *part;
i32_4tech pos;
i32 pos;
};
struct Scratch_Block{
@ -93,5 +62,7 @@ struct Scratch_Block{
#endif
#endif
// BOTTOM

View File

@ -52,24 +52,24 @@ heap_init(Heap *heap){
}
static void
heap_extend(Heap *heap, void *memory, i32_4tech size){
heap_extend(Heap *heap, void *memory, i32 size){
heap_assert_good(heap);
if (size >= sizeof(Heap_Node)){
Heap_Node *new_node = (Heap_Node*)memory;
heap__insert_prev(&heap->in_order, &new_node->order);
heap__insert_next(&heap->free_nodes, &new_node->alloc);
new_node->size = size - sizeof(*new_node);
heap->total_space += (umem_4tech)size;
heap->total_space += (umem)size;
}
heap_assert_good(heap);
}
static void*
heap__reserve_chunk(Heap *heap, Heap_Node *node, i32_4tech size){
u8_4tech *ptr = (u8_4tech*)(node + 1);
i32_4tech left_over_size = node->size - size;
heap__reserve_chunk(Heap *heap, Heap_Node *node, i32 size){
u8 *ptr = (u8*)(node + 1);
i32 left_over_size = node->size - size;
if (left_over_size > sizeof(*node)){
i32_4tech new_node_size = left_over_size - sizeof(*node);
i32 new_node_size = left_over_size - sizeof(*node);
Heap_Node *new_node = (Heap_Node*)(ptr + size);
heap__insert_next(&node->order, &new_node->order);
heap__insert_next(&node->alloc, &new_node->alloc);
@ -84,10 +84,10 @@ heap__reserve_chunk(Heap *heap, Heap_Node *node, i32_4tech size){
}
static void*
heap_allocate(Heap *heap, i32_4tech size){
heap_allocate(Heap *heap, i32 size){
if (heap->in_order.next != 0){
heap_assert_good(heap);
i32_4tech aligned_size = (size + sizeof(Heap_Node) - 1);
i32 aligned_size = (size + sizeof(Heap_Node) - 1);
aligned_size = aligned_size - (aligned_size%sizeof(Heap_Node));
for (Heap_Basic_Node *n = heap->free_nodes.next;
n != &heap->free_nodes;
@ -109,7 +109,7 @@ heap__merge(Heap *heap, Heap_Node *l, Heap_Node *r){
if (&l->order != &heap->in_order && &r->order != &heap->in_order &&
l->alloc.next != 0 && l->alloc.prev != 0 &&
r->alloc.next != 0 && r->alloc.prev != 0){
u8_4tech *ptr = (u8_4tech*)(l + 1) + l->size;
u8 *ptr = (u8*)(l + 1) + l->size;
if (PtrDif(ptr, r) == 0){
heap__remove(&r->order);
heap__remove(&r->alloc);

View File

@ -12,58 +12,6 @@ distribute, and modify this file as you see fit.
#if !defined(FCODER_HEAP_H)
#define FCODER_HEAP_H
// 4tech_standard_preamble.h
#if !defined(FTECH_INTEGERS)
#define FTECH_INTEGERS
#include <stdint.h>
typedef int8_t i8_4tech;
typedef int16_t i16_4tech;
typedef int32_t i32_4tech;
typedef int64_t i64_4tech;
typedef uint8_t u8_4tech;
typedef uint16_t u16_4tech;
typedef uint32_t u32_4tech;
typedef uint64_t u64_4tech;
#if defined(FTECH_32_BIT)
typedef u32_4tech umem_4tech;
#else
typedef u64_4tech umem_4tech;
#endif
typedef float f32_4tech;
typedef double f64_4tech;
typedef int8_t b8_4tech;
typedef int32_t b32_4tech;
#endif
#if !defined(Assert)
# define Assert(n) do{ if (!(n)) *(int*)0 = 0xA11E; }while(0)
#endif
#if !defined(Member)
# define Member(T, m) (((T*)0)->m)
#endif
#if !defined(PtrDif)
#define PtrDif(a,b) ((uint8_t*)(a) - (uint8_t*)(b))
#endif
#if !defined(PtrAsInt)
#define PtrAsInt(a) PtrDif(a,0)
#endif
#if !defined(OffsetOfMember)
#define OffsetOfMember(S,m) PtrAsInt(&Member(S,m))
#endif
#if !defined(CastFromMember)
#define CastFromMember(S,m,ptr) (S*)( (uint8_t*)(ptr) - OffsetOfMember(S,m) )
#endif
// standard preamble end
struct Heap_Basic_Node{
Heap_Basic_Node *next;
Heap_Basic_Node *prev;
@ -74,17 +22,17 @@ struct Heap_Node{
struct{
Heap_Basic_Node order;
Heap_Basic_Node alloc;
i32_4tech size;
i32 size;
};
u8_4tech force_size__[64];
u8 force_size__[64];
};
};
struct Heap{
Heap_Basic_Node in_order;
Heap_Basic_Node free_nodes;
i32_4tech used_space;
i32_4tech total_space;
i32 used_space;
i32 total_space;
};
//#define DO_HEAP_CHECKS

File diff suppressed because it is too large Load Diff

View File

@ -12,67 +12,35 @@ distribute, and modify this file as you see fit.
#if !defined(FCODER_TABLE_H)
#define FCODER_TABLE_H
// 4tech_standard_preamble.h
#if !defined(FTECH_INTEGERS)
#define FTECH_INTEGERS
#include <stdint.h>
typedef int8_t i8_4tech;
typedef int16_t i16_4tech;
typedef int32_t i32_4tech;
typedef int64_t i64_4tech;
typedef uint8_t u8_4tech;
typedef uint16_t u16_4tech;
typedef uint32_t u32_4tech;
typedef uint64_t u64_4tech;
#if defined(FTECH_32_BIT)
typedef u32_4tech umem_4tech;
#else
typedef u64_4tech umem_4tech;
#endif
typedef float f32_4tech;
typedef double f64_4tech;
typedef int8_t b8_4tech;
typedef int32_t b32_4tech;
#endif
#if !defined(Assert)
# define Assert(n) do{ if (!(n)) *(int*)0 = 0xA11E; }while(0)
#endif
// standard preamble end
#define TableHashEmpty 0
#define TableHashDeleted 1
#define TableHashMin 0x10000000
#include <string.h>
typedef u32_4tech Hash_Function(void *item, void *arg);
typedef i32_4tech Compare_Function(void *key, void *item, void *arg);
typedef u32 Hash_Function(void *item, void *arg);
typedef i32 Compare_Function(void *key, void *item, void *arg);
struct Table{
u32_4tech *hash_array;
u32 *hash_array;
char *data_array;
i32_4tech count, max;
i32_4tech item_size;
i32 count, max;
i32 item_size;
};
static i32_4tech
table_required_mem_size(i32_4tech table_size, i32_4tech item_size){
i32_4tech hash_size = ((table_size*sizeof(u32_4tech)) + 7) & ~7;
i32_4tech mem_size = hash_size + table_size*item_size;
static i32
table_required_mem_size(i32 table_size, i32 item_size){
i32 hash_size = ((table_size*sizeof(u32)) + 7) & ~7;
i32 mem_size = hash_size + table_size*item_size;
return(mem_size);
}
static void
table_init_memory(Table *table, void *memory, i32_4tech table_size, i32_4tech item_size){
i32_4tech hash_size = table_size * sizeof(u32_4tech);
table_init_memory(Table *table, void *memory, i32 table_size, i32 item_size){
i32 hash_size = table_size * sizeof(u32);
hash_size = (hash_size + 7) & ~7;
table->hash_array = (u32_4tech*)memory;
table->hash_array = (u32*)memory;
table->data_array = (char*)(table->hash_array) + hash_size;
table->count = 0;
@ -80,23 +48,23 @@ table_init_memory(Table *table, void *memory, i32_4tech table_size, i32_4tech it
table->item_size = item_size;
}
static i32_4tech
static i32
table_at_capacity(Table *table){
i32_4tech result = true;
i32 result = true;
if (table->count * 8 < table->max * 7){
result = false;
}
return(result);
}
static i32_4tech
static i32
table_add(Table *table, void *item, void *arg, Hash_Function *hash_func, Compare_Function *comp_func){
Assert(table->count * 8 < table->max * 7);
u32_4tech hash = (hash_func(item, arg) | TableHashMin);
i32_4tech i = hash % table->max;
i32_4tech start = i;
u32_4tech *inspect = table->hash_array + i;
u32 hash = (hash_func(item, arg) | TableHashMin);
i32 i = hash % table->max;
i32 start = i;
u32 *inspect = table->hash_array + i;
while (*inspect >= TableHashMin){
if (*inspect == hash){
@ -119,14 +87,14 @@ table_add(Table *table, void *item, void *arg, Hash_Function *hash_func, Compare
return(0);
}
static i32_4tech
table_find_pos(Table *table, void *search_key, void *arg, i32_4tech *pos, i32_4tech *index, Hash_Function *hash_func, Compare_Function *comp_func){
static i32
table_find_pos(Table *table, void *search_key, void *arg, i32 *pos, i32 *index, Hash_Function *hash_func, Compare_Function *comp_func){
Assert((table->count - 1) * 8 < table->max * 7);
u32_4tech hash = (hash_func(search_key, arg) | TableHashMin);
i32_4tech i = hash % table->max;
i32_4tech start = i;
u32_4tech *inspect = table->hash_array + i;
u32 hash = (hash_func(search_key, arg) | TableHashMin);
i32 i = hash % table->max;
i32 start = i;
u32 *inspect = table->hash_array + i;
while (*inspect != TableHashEmpty){
if (*inspect == hash){
@ -151,7 +119,7 @@ table_find_pos(Table *table, void *search_key, void *arg, i32_4tech *pos, i32_4t
static void*
table_find_item(Table *table, void *search_key, void *arg, Hash_Function *hash_func, Compare_Function *comp_func){
void *result = 0;
i32_4tech pos;
i32 pos;
if (table_find_pos(table, search_key, arg, &pos, 0, hash_func, comp_func)){
result = table->data_array + pos;
}
@ -159,15 +127,15 @@ table_find_item(Table *table, void *search_key, void *arg, Hash_Function *hash_f
}
static void
table_remove_index(Table *table, i32_4tech index){
table_remove_index(Table *table, i32 index){
table->hash_array[index] = TableHashDeleted;
--table->count;
}
static i32_4tech
static i32
table_remove_match(Table *table, void *search_key, void *arg, Hash_Function *hash_func, Compare_Function *comp_func){
i32_4tech result = false;
i32_4tech index;
i32 result = false;
i32 index;
if (table_find_pos(table, search_key, arg, 0, &index, hash_func, comp_func)){
table_remove_index(table, index);
result = true;
@ -186,11 +154,11 @@ table_rehash(Table *src, Table *dst, void *arg, Hash_Function *hash_func, Compar
Assert((dst->count + src->count - 1) * 7 < dst->max * 8);
Assert(dst->item_size == src->item_size);
i32_4tech count = src->count;
i32_4tech item_size = src->item_size;
u32_4tech *hash_item = src->hash_array;
i32 count = src->count;
i32 item_size = src->item_size;
u32 *hash_item = src->hash_array;
char *data_item = src->data_array;
for (i32_4tech i = 0, c = 0;
for (i32 i = 0, c = 0;
c < count;
++i, ++hash_item, data_item += item_size){
if (*hash_item >= TableHashMin){
@ -200,71 +168,65 @@ table_rehash(Table *src, Table *dst, void *arg, Hash_Function *hash_func, Compar
}
}
static u32_4tech
static u32
tbl_string_hash(void *item, void *arg){
String *string = (String*)item;
u32_4tech x = 5381;
String_Const_u8 *string = (String_Const_u8*)item;
u32 x = 5381;
(void)arg;
char *str = string->str;
i32_4tech len = string->size;
i32_4tech i = 0;
while (i < len){
char c = str[i++];
u8 *str = string->str;
umem len = string->size;
for (umem i = 0; i < len; i += 1){
u8 c = str[i];
x = ((x << 5) + x) + c;
}
return(x);
}
static i32_4tech
static i32
tbl_string_compare(void *a, void *b, void *arg){
String *stra = (String*)a;
String *strb = (String*)b;
i32_4tech result = !match_ss(*stra, *strb);
String_Const_u8 *stra = (String_Const_u8*)a;
String_Const_u8 *strb = (String_Const_u8*)b;
i32 result = (!string_match(*stra, *strb));
return(result);
}
struct Offset_String{
i32_4tech offset;
i32_4tech size;
umem offset;
umem size;
};
static u32_4tech
static u32
tbl_offset_string_hash(void *item, void *arg){
Offset_String *string = (Offset_String*)item;
u32_4tech x = 5381;
char *str = ((char*)arg) + string->offset;
i32_4tech len = string->size;
i32_4tech i = 0;
while (i < len){
char c = str[i++];
u32 x = 5381;
u8 *str = ((u8*)arg) + string->offset;
umem size = string->size;
for (umem i = 0; i < size; i += 1){
u8 c = str[i];
x = ((x << 5) + x) + c;
}
return(x);
}
static i32_4tech
static i32
tbl_offset_string_compare(void *a, void *b, void *arg){
Offset_String *ostra = (Offset_String*)a;
Offset_String *ostrb = (Offset_String*)b;
String stra = make_string((char*)arg + ostra->offset, ostra->size);
String strb = make_string((char*)arg + ostrb->offset, ostrb->size);
i32_4tech result = !match_ss(stra, strb);
String_Const_u8 stra = SCu8((u8*)arg + ostra->offset, ostra->size);
String_Const_u8 strb = SCu8((u8*)arg + ostrb->offset, ostrb->size);
i32 result = (!string_match(stra, strb));
return(result);
}
struct String_Space{
char *space;
i32_4tech pos;
i32_4tech new_pos;
i32_4tech max;
i32 pos;
i32 new_pos;
i32 max;
};
static Offset_String
strspace_append(String_Space *space, char *str, i32_4tech len){
strspace_append(String_Space *space, char *str, i32 len){
Offset_String result = {};
if (space->new_pos + len <= space->max){
result.offset = space->new_pos;

View File

@ -12,39 +12,7 @@
#if !defined(FED_UTF8_CONVERSION_H)
#define FED_UTF8_CONVERSION_H
// 4tech_standard_preamble.h
#if !defined(FTECH_INTEGERS)
#define FTECH_INTEGERS
#include <stdint.h>
typedef int8_t i8_4tech;
typedef int16_t i16_4tech;
typedef int32_t i32_4tech;
typedef int64_t i64_4tech;
typedef uint8_t u8_4tech;
typedef uint16_t u16_4tech;
typedef uint32_t u32_4tech;
typedef uint64_t u64_4tech;
#if defined(FTECH_32_BIT)
typedef u32_4tech umem_4tech;
#else
typedef u64_4tech umem_4tech;
#endif
typedef float f32_4tech;
typedef double f64_4tech;
typedef int8_t b8_4tech;
typedef int32_t b32_4tech;
#endif
#if !defined(Assert)
# define Assert(n) do{ if (!(n)) *(int*)0 = 0xA11E; }while(0)
#endif
// standard preamble end
static u32_4tech cp_min_by_utf8_length[] = {
static u32 cp_min_by_utf8_length[] = {
0x0,
0x0,
0x80,
@ -52,45 +20,45 @@ static u32_4tech cp_min_by_utf8_length[] = {
0x10000,
};
static u32_4tech surrogate_min = 0xD800;
static u32_4tech surrogate_max = 0xDFFF;
static u32 surrogate_min = 0xD800;
static u32 surrogate_max = 0xDFFF;
static u32_4tech nonchar_min = 0xFDD0;
static u32_4tech nonchar_max = 0xFDEF;
static u32 nonchar_min = 0xFDD0;
static u32 nonchar_max = 0xFDEF;
static b32_4tech
codepoint_is_whitespace(u32_4tech codepoint){
b32_4tech result = false;
static b32
codepoint_is_whitespace(u32 codepoint){
b32 result = false;
if (codepoint == ' ' || codepoint == '\r' || codepoint == '\n' || codepoint == '\t'){
result = true;
}
return(result);
}
static u32_4tech
utf8_to_u32_length_unchecked(u8_4tech *buffer, u32_4tech *length_out){
u32_4tech result = 0;
static u32
utf8_to_u32_length_unchecked(u8 *buffer, u32 *length_out){
u32 result = 0;
if (buffer[0] < 0x80){
result = (u32_4tech)buffer[0];
result = (u32)buffer[0];
*length_out = 1;
}
else if (buffer[0] < 0xE0){
result = ((u32_4tech)((buffer[0])&0x1F)) << 6;
result |= ((u32_4tech)((buffer[1])&0x3F));
result = ((u32)((buffer[0])&0x1F)) << 6;
result |= ((u32)((buffer[1])&0x3F));
*length_out = 2;
}
else if (buffer[0] < 0xF0){
result = ((u32_4tech)((buffer[0])&0x0F)) << 12;
result |= ((u32_4tech)((buffer[1])&0x3F)) << 6;
result |= ((u32_4tech)((buffer[2])&0x3F));
result = ((u32)((buffer[0])&0x0F)) << 12;
result |= ((u32)((buffer[1])&0x3F)) << 6;
result |= ((u32)((buffer[2])&0x3F));
*length_out = 3;
}
else{
result = ((u32_4tech)((buffer[0])&0x07)) << 18;
result |= ((u32_4tech)((buffer[1])&0x3F)) << 12;
result |= ((u32_4tech)((buffer[2])&0x3F)) << 6;
result |= ((u32_4tech)((buffer[3])&0x3F));
result = ((u32)((buffer[0])&0x07)) << 18;
result |= ((u32)((buffer[1])&0x3F)) << 12;
result |= ((u32)((buffer[2])&0x3F)) << 6;
result |= ((u32)((buffer[3])&0x3F));
*length_out = 4;
}
@ -102,19 +70,19 @@ utf8_to_u32_length_unchecked(u8_4tech *buffer, u32_4tech *length_out){
return(result);
}
static u32_4tech
utf8_to_u32_unchecked(u8_4tech *buffer){
u32_4tech ignore;
u32_4tech result = utf8_to_u32_length_unchecked(buffer, &ignore);
static u32
utf8_to_u32_unchecked(u8 *buffer){
u32 ignore;
u32 result = utf8_to_u32_length_unchecked(buffer, &ignore);
return(result);
}
static u32_4tech
utf8_to_u32(u8_4tech **buffer_ptr, u8_4tech *end){
u8_4tech *buffer = *buffer_ptr;
u32_4tech limit = (u32_4tech)(end - buffer);
static u32
utf8_to_u32(u8 **buffer_ptr, u8 *end){
u8 *buffer = *buffer_ptr;
u32 limit = (u32)(end - buffer);
u32_4tech length = 0;
u32 length = 0;
if (buffer[0] < 0x80){
length = 1;
}
@ -134,40 +102,40 @@ utf8_to_u32(u8_4tech **buffer_ptr, u8_4tech *end){
length = 0;
}
for (u32_4tech i = 1; i < length; ++i){
for (u32 i = 1; i < length; ++i){
if ((buffer[i] & 0xC0) != 0x80){
length = 0;
break;
}
}
u32_4tech result = 0;
u32 result = 0;
if (length != 0 && length <= limit){
switch (length){
case 1:
{
result = (u32_4tech)buffer[0];
result = (u32)buffer[0];
}break;
case 2:
{
result = ((u32_4tech)((buffer[0])&0x1F)) << 6;
result |= ((u32_4tech)((buffer[1])&0x3F));
result = ((u32)((buffer[0])&0x1F)) << 6;
result |= ((u32)((buffer[1])&0x3F));
}break;
case 3:
{
result = ((u32_4tech)((buffer[0])&0x0F)) << 12;
result |= ((u32_4tech)((buffer[1])&0x3F)) << 6;
result |= ((u32_4tech)((buffer[2])&0x3F));
result = ((u32)((buffer[0])&0x0F)) << 12;
result |= ((u32)((buffer[1])&0x3F)) << 6;
result |= ((u32)((buffer[2])&0x3F));
}break;
case 4:
{
result = ((u32_4tech)((buffer[0])&0x07)) << 18;
result |= ((u32_4tech)((buffer[1])&0x3F)) << 12;
result |= ((u32_4tech)((buffer[2])&0x3F)) << 6;
result |= ((u32_4tech)((buffer[3])&0x3F));
result = ((u32)((buffer[0])&0x07)) << 18;
result |= ((u32)((buffer[1])&0x3F)) << 12;
result |= ((u32)((buffer[2])&0x3F)) << 6;
result |= ((u32)((buffer[3])&0x3F));
}break;
}
@ -186,28 +154,28 @@ utf8_to_u32(u8_4tech **buffer_ptr, u8_4tech *end){
}
static void
u32_to_utf8_unchecked(u32_4tech codepoint, u8_4tech *buffer, u32_4tech *length_out){
u32_to_utf8_unchecked(u32 codepoint, u8 *buffer, u32 *length_out){
if (codepoint <= 0x7F){
buffer[0] = (u8_4tech)codepoint;
buffer[0] = (u8)codepoint;
*length_out = 1;
}
else if (codepoint <= 0x7FF){
buffer[0] = (u8_4tech)(0xC0 | (codepoint >> 6));
buffer[1] = (u8_4tech)(0x80 | (codepoint & 0x3F));
buffer[0] = (u8)(0xC0 | (codepoint >> 6));
buffer[1] = (u8)(0x80 | (codepoint & 0x3F));
*length_out = 2;
}
else if (codepoint <= 0xFFFF){
buffer[0] = (u8_4tech)(0xE0 | (codepoint >> 12));
buffer[1] = (u8_4tech)(0x80 | ((codepoint >> 6) & 0x3F));
buffer[2] = (u8_4tech)(0x80 | (codepoint & 0x3F));
buffer[0] = (u8)(0xE0 | (codepoint >> 12));
buffer[1] = (u8)(0x80 | ((codepoint >> 6) & 0x3F));
buffer[2] = (u8)(0x80 | (codepoint & 0x3F));
*length_out = 3;
}
else if (codepoint <= 0x10FFFF){
codepoint &= 0x001FFFFF;
buffer[0] = (u8_4tech)(0xF0 | (codepoint >> 18));
buffer[1] = (u8_4tech)(0x80 | ((codepoint >> 12) & 0x3F));
buffer[2] = (u8_4tech)(0x80 | ((codepoint >> 6) & 0x3F));
buffer[3] = (u8_4tech)(0x80 | (codepoint & 0x3F));
buffer[0] = (u8)(0xF0 | (codepoint >> 18));
buffer[1] = (u8)(0x80 | ((codepoint >> 12) & 0x3F));
buffer[2] = (u8)(0x80 | ((codepoint >> 6) & 0x3F));
buffer[3] = (u8)(0x80 | (codepoint & 0x3F));
*length_out = 4;
}
else{
@ -215,25 +183,25 @@ u32_to_utf8_unchecked(u32_4tech codepoint, u8_4tech *buffer, u32_4tech *length_o
}
}
static umem_4tech
utf8_to_utf16_minimal_checking(u16_4tech *dst, umem_4tech max_wchars, u8_4tech *src, umem_4tech length, b32_4tech *error){
u8_4tech *s = src;
u8_4tech *s_end = s + length;
static umem
utf8_to_utf16_minimal_checking(u16 *dst, umem max_wchars, u8 *src, umem length, b32 *error){
u8 *s = src;
u8 *s_end = s + length;
u16_4tech *d = dst;
u16_4tech *d_end = d + max_wchars;
umem_4tech limit = length;
u16 *d = dst;
u16 *d_end = d + max_wchars;
umem limit = length;
umem_4tech needed_max = 0;
u32_4tech advance = 1;
umem needed_max = 0;
u32 advance = 1;
*error = false;
for(; s < s_end;){
u32_4tech codepoint = 0;
u32_4tech utf8_size = 0;
u32 codepoint = 0;
u32 utf8_size = 0;
if (s[0] < 0x80){
codepoint = (u32_4tech)s[0];
codepoint = (u32)s[0];
utf8_size = 1;
}
else if (s[0] < 0xE0){
@ -242,8 +210,8 @@ utf8_to_utf16_minimal_checking(u16_4tech *dst, umem_4tech max_wchars, u8_4tech *
break;
}
codepoint = ((u32_4tech)((s[0])&0x1F)) << 6;
codepoint |= ((u32_4tech)((s[1])&0x3F));
codepoint = ((u32)((s[0])&0x1F)) << 6;
codepoint |= ((u32)((s[1])&0x3F));
utf8_size = 2;
}
else if (s[0] < 0xF0){
@ -252,9 +220,9 @@ utf8_to_utf16_minimal_checking(u16_4tech *dst, umem_4tech max_wchars, u8_4tech *
break;
}
codepoint = ((u32_4tech)((s[0])&0x0F)) << 12;
codepoint |= ((u32_4tech)((s[1])&0x3F)) << 6;
codepoint |= ((u32_4tech)((s[2])&0x3F));
codepoint = ((u32)((s[0])&0x0F)) << 12;
codepoint |= ((u32)((s[1])&0x3F)) << 6;
codepoint |= ((u32)((s[2])&0x3F));
utf8_size = 3;
}
else if (s[0] < 0xF8){
@ -263,10 +231,10 @@ utf8_to_utf16_minimal_checking(u16_4tech *dst, umem_4tech max_wchars, u8_4tech *
break;
}
codepoint = ((u32_4tech)((s[0])&0x07)) << 18;
codepoint |= ((u32_4tech)((s[1])&0x3F)) << 12;
codepoint |= ((u32_4tech)((s[2])&0x3F)) << 6;
codepoint |= ((u32_4tech)((s[3])&0x3F));
codepoint = ((u32)((s[0])&0x07)) << 18;
codepoint |= ((u32)((s[1])&0x3F)) << 12;
codepoint |= ((u32)((s[2])&0x3F)) << 6;
codepoint |= ((u32)((s[3])&0x3F));
utf8_size = 4;
}
else{
@ -283,23 +251,23 @@ utf8_to_utf16_minimal_checking(u16_4tech *dst, umem_4tech max_wchars, u8_4tech *
limit -= utf8_size;
if (codepoint <= 0xD7FF || (codepoint >= 0xE000 && codepoint <= 0xFFFF)){
*d = (u16_4tech)(codepoint);
*d = (u16)(codepoint);
d += advance;
needed_max += 1;
}
else if (codepoint >= 0x10000 && codepoint <= 0x10FFFF){
codepoint -= 0x10000;
u32_4tech high = (codepoint >> 10) & 0x03FF;
u32_4tech low = (codepoint) & 0x03FF;
u32 high = (codepoint >> 10) & 0x03FF;
u32 low = (codepoint) & 0x03FF;
high += 0xD800;
low += 0xDC00;
if (d + advance < d_end){
*d = (u16_4tech)high;
*d = (u16)high;
d += advance;
*d = (u16_4tech)low;
*d = (u16)low;
d += advance;
}
else{
@ -321,22 +289,22 @@ utf8_to_utf16_minimal_checking(u16_4tech *dst, umem_4tech max_wchars, u8_4tech *
return(needed_max);
}
static umem_4tech
utf16_to_utf8_minimal_checking(u8_4tech *dst, umem_4tech max_chars, u16_4tech *src, umem_4tech length, b32_4tech *error){
u16_4tech *s = src;
u16_4tech *s_end = s + length;
static umem
utf16_to_utf8_minimal_checking(u8 *dst, umem max_chars, u16 *src, umem length, b32 *error){
u16 *s = src;
u16 *s_end = s + length;
u8_4tech *d = dst;
u8_4tech *d_end = d + max_chars;
umem_4tech limit = length;
u8 *d = dst;
u8 *d_end = d + max_chars;
umem limit = length;
umem_4tech needed_max = 0;
umem needed_max = 0;
*error = false;
for (; s < s_end;){
u32_4tech codepoint = 0;
u32_4tech utf16_size = 0;
u32 codepoint = 0;
u32 utf16_size = 0;
if (s[0] <= 0xD7FF || (s[0] >= 0xE000 && s[0] <= 0xFFFF)){
codepoint = s[0];
@ -349,8 +317,8 @@ utf16_to_utf8_minimal_checking(u8_4tech *dst, umem_4tech max_chars, u16_4tech *s
break;
}
u32_4tech high = s[0] - 0xD800;
u32_4tech low = s[1] - 0xDC00;
u32 high = s[0] - 0xD800;
u32 low = s[1] - 0xDC00;
codepoint = ((high << 10) | (low)) + 0x10000;
utf16_size = 2;
}
@ -363,29 +331,29 @@ utf16_to_utf8_minimal_checking(u8_4tech *dst, umem_4tech max_chars, u16_4tech *s
s += utf16_size;
limit -= utf16_size;
u8_4tech d_fill[4];
u32_4tech d_fill_count = 0;
u8 d_fill[4];
u32 d_fill_count = 0;
if (codepoint <= 0x7F){
d_fill[0] = (u8_4tech)codepoint;
d_fill[0] = (u8)codepoint;
d_fill_count = 1;
}
else if (codepoint <= 0x7FF){
d_fill[0] = (u8_4tech)(0xC0 | (codepoint >> 6));
d_fill[1] = (u8_4tech)(0x80 | (codepoint & 0x3F));
d_fill[0] = (u8)(0xC0 | (codepoint >> 6));
d_fill[1] = (u8)(0x80 | (codepoint & 0x3F));
d_fill_count = 2;
}
else if (codepoint <= 0xFFFF){
d_fill[0] = (u8_4tech)(0xE0 | (codepoint >> 12));
d_fill[1] = (u8_4tech)(0x80 | ((codepoint >> 6) & 0x3F));
d_fill[2] = (u8_4tech)(0x80 | (codepoint & 0x3F));
d_fill[0] = (u8)(0xE0 | (codepoint >> 12));
d_fill[1] = (u8)(0x80 | ((codepoint >> 6) & 0x3F));
d_fill[2] = (u8)(0x80 | (codepoint & 0x3F));
d_fill_count = 3;
}
else if (codepoint <= 0x10FFFF){
d_fill[0] = (u8_4tech)(0xF0 | (codepoint >> 18));
d_fill[1] = (u8_4tech)(0x80 | ((codepoint >> 12) & 0x3F));
d_fill[2] = (u8_4tech)(0x80 | ((codepoint >> 6) & 0x3F));
d_fill[3] = (u8_4tech)(0x80 | (codepoint & 0x3F));
d_fill[0] = (u8)(0xF0 | (codepoint >> 18));
d_fill[1] = (u8)(0x80 | ((codepoint >> 12) & 0x3F));
d_fill[2] = (u8)(0x80 | ((codepoint >> 6) & 0x3F));
d_fill[3] = (u8)(0x80 | (codepoint & 0x3F));
d_fill_count = 4;
}
else{
@ -394,7 +362,7 @@ utf16_to_utf8_minimal_checking(u8_4tech *dst, umem_4tech max_chars, u16_4tech *s
}
if (d + d_fill_count <= d_end){
for (u32_4tech i = 0; i < d_fill_count; ++i){
for (u32 i = 0; i < d_fill_count; ++i){
*d = d_fill[i];
++d;
}
@ -406,8 +374,8 @@ utf16_to_utf8_minimal_checking(u8_4tech *dst, umem_4tech max_chars, u16_4tech *s
}
static void
byte_to_ascii(u8_4tech n, u8_4tech *out){
u8_4tech C = '0' + (n / 0x10);
byte_to_ascii(u8 n, u8 *out){
u8 C = '0' + (n / 0x10);
if ((n / 0x10) > 0x9){
C = ('A' - 0xA) + (n / 0x10);
}

View File

@ -15,8 +15,8 @@
struct String_And_Flag{
char *str;
u32_4tech length;
u32_4tech flags;
u32 length;
u32 flags;
};
static String_And_Flag default_preprops[] = {
@ -55,7 +55,7 @@ static String_And_Flag default_preprops[] = {
#include FCPP_LEXER_EXTRA_PREPROPS
#endif
};
static i32_4tech default_preprops_count = sizeof(default_preprops)/sizeof(default_preprops[0]);
static i32 default_preprops_count = sizeof(default_preprops)/sizeof(default_preprops[0]);
static String_And_Flag default_keywords[] = {
// CPP_TOKEN_BOOLEAN_CONSTANT
@ -162,7 +162,7 @@ static String_And_Flag default_keywords[] = {
#include FCPP_LEXER_EXTRA_KEYWORDS
#endif
};
static i32_4tech default_keywords_count = sizeof(default_keywords)/sizeof(default_keywords[0]);
static i32 default_keywords_count = sizeof(default_keywords)/sizeof(default_keywords[0]);
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
u16_4tech whitespace_fsm_eq_classes[] = {
u16 whitespace_fsm_eq_classes[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 20, 10, 10, 10, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@ -17,15 +17,15 @@ u16_4tech whitespace_fsm_eq_classes[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};
const i32_4tech num_whitespace_fsm_eq_classes = 3;
const i32 num_whitespace_fsm_eq_classes = 3;
u8_4tech whitespace_fsm_table[] = {
u8 whitespace_fsm_table[] = {
10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};
u16_4tech int_fsm_eq_classes[] = {
u16 int_fsm_eq_classes[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@ -44,16 +44,16 @@ u16_4tech int_fsm_eq_classes[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};
const i32_4tech num_int_fsm_eq_classes = 4;
const i32 num_int_fsm_eq_classes = 4;
u8_4tech int_fsm_table[] = {
u8 int_fsm_table[] = {
8, 9, 10, 11, 12, 13, 14, 15,
3, 5, 10, 6, 12, 7, 14, 15,
1, 9, 7, 7, 12, 13, 7, 15,
2, 4, 6, 11, 7, 13, 14, 15,
};
u16_4tech raw_str_eq_classes[] = {
u16 raw_str_eq_classes[] = {
0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 6, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
9, 3, 12, 3, 3, 3, 3, 3, 15, 9, 3, 3, 3, 3, 3, 3,
@ -72,9 +72,9 @@ u16_4tech raw_str_eq_classes[] = {
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
};
const i32_4tech num_raw_str_eq_classes = 6;
const i32 num_raw_str_eq_classes = 6;
u8_4tech raw_str_table[] = {
u8 raw_str_table[] = {
3, 6, 6,
0, 1, 2,
3, 2, 2,
@ -83,11 +83,11 @@ u8_4tech raw_str_table[] = {
4, 1, 2,
};
u8_4tech raw_str_flags[] = {
u8 raw_str_flags[] = {
0x00,0x00,0x01,
};
u16_4tech normal_str_eq_classes[] = {
u16 normal_str_eq_classes[] = {
0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 6, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 9, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
@ -106,9 +106,9 @@ u16_4tech normal_str_eq_classes[] = {
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
};
const i32_4tech num_normal_str_eq_classes = 5;
const i32 num_normal_str_eq_classes = 5;
u8_4tech normal_str_table[] = {
u8 normal_str_table[] = {
4, 0, 4,
0, 0, 2,
4, 2, 4,
@ -116,11 +116,11 @@ u8_4tech normal_str_table[] = {
1, 0, 1,
};
u8_4tech normal_str_flags[] = {
u8 normal_str_flags[] = {
0x00,0x00,0x01,
};
u16_4tech include_str_eq_classes[] = {
u16 include_str_eq_classes[] = {
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
@ -139,15 +139,15 @@ u16_4tech include_str_eq_classes[] = {
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
};
const i32_4tech num_include_str_eq_classes = 3;
const i32 num_include_str_eq_classes = 3;
u8_4tech include_str_table[] = {
u8 include_str_table[] = {
2,
0,
1,
};
u16_4tech normal_char_eq_classes[] = {
u16 normal_char_eq_classes[] = {
0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 6, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 9, 3, 3, 3, 3, 3, 3, 3, 3,
@ -166,9 +166,9 @@ u16_4tech normal_char_eq_classes[] = {
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
};
const i32_4tech num_normal_char_eq_classes = 5;
const i32 num_normal_char_eq_classes = 5;
u8_4tech normal_char_table[] = {
u8 normal_char_table[] = {
4, 0, 4,
0, 0, 2,
4, 2, 4,
@ -176,11 +176,11 @@ u8_4tech normal_char_table[] = {
1, 0, 1,
};
u8_4tech normal_char_flags[] = {
u8 normal_char_flags[] = {
0x00,0x00,0x01,
};
u16_4tech main_fsm_eq_classes[] = {
u16 main_fsm_eq_classes[] = {
0, 31, 31, 31, 31, 31, 31, 31, 31, 31, 62, 93, 93, 93, 31, 31,
31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
124,155,186,217,248,155,279,310,341,341,372,403,341,434,465,496,
@ -199,9 +199,9 @@ u16_4tech main_fsm_eq_classes[] = {
713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,
};
const i32_4tech num_main_fsm_eq_classes = 32;
const i32 num_main_fsm_eq_classes = 32;
u8_4tech main_fsm_table[] = {
u8 main_fsm_table[] = {
31, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61,
0, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 15, 15, 17, 17, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 30,
0, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 46, 15, 17, 17, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 30,
@ -236,7 +236,7 @@ u8_4tech main_fsm_table[] = {
26, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 15, 15, 17, 17, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 30,
};
u16_4tech pp_include_fsm_eq_classes[] = {
u16 pp_include_fsm_eq_classes[] = {
0, 31, 31, 31, 31, 31, 31, 31, 31, 31, 62, 93, 93, 93, 31, 31,
31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
124,155,186,217,248,155,279,310,341,341,372,403,341,434,465,496,
@ -255,9 +255,9 @@ u16_4tech pp_include_fsm_eq_classes[] = {
713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,
};
const i32_4tech num_pp_include_fsm_eq_classes = 32;
const i32 num_pp_include_fsm_eq_classes = 32;
u8_4tech pp_include_fsm_table[] = {
u8 pp_include_fsm_table[] = {
31, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61,
0, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 15, 15, 17, 17, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 30,
0, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 46, 15, 17, 17, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 30,
@ -292,7 +292,7 @@ u8_4tech pp_include_fsm_table[] = {
26, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 15, 15, 17, 17, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 30,
};
u16_4tech pp_macro_fsm_eq_classes[] = {
u16 pp_macro_fsm_eq_classes[] = {
0, 31, 31, 31, 31, 31, 31, 31, 31, 31, 62, 93, 93, 93, 31, 31,
31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
124,155,186,217,248,155,279,310,341,341,372,403,341,434,465,496,
@ -311,9 +311,9 @@ u16_4tech pp_macro_fsm_eq_classes[] = {
713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,
};
const i32_4tech num_pp_macro_fsm_eq_classes = 32;
const i32 num_pp_macro_fsm_eq_classes = 32;
u8_4tech pp_macro_fsm_table[] = {
u8 pp_macro_fsm_table[] = {
31, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61,
0, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 15, 15, 17, 17, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 30,
0, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 46, 15, 17, 17, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 30,
@ -348,7 +348,7 @@ u8_4tech pp_macro_fsm_table[] = {
26, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 15, 15, 17, 17, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 30,
};
u16_4tech pp_identifier_fsm_eq_classes[] = {
u16 pp_identifier_fsm_eq_classes[] = {
0, 31, 31, 31, 31, 31, 31, 31, 31, 31, 62, 93, 93, 93, 31, 31,
31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
124,155,186,217,248,155,279,310,341,341,372,403,341,434,465,496,
@ -367,9 +367,9 @@ u16_4tech pp_identifier_fsm_eq_classes[] = {
713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,
};
const i32_4tech num_pp_identifier_fsm_eq_classes = 32;
const i32 num_pp_identifier_fsm_eq_classes = 32;
u8_4tech pp_identifier_fsm_table[] = {
u8 pp_identifier_fsm_table[] = {
31, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61,
0, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 15, 15, 17, 17, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 30,
0, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 46, 15, 17, 17, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 30,
@ -404,7 +404,7 @@ u8_4tech pp_identifier_fsm_table[] = {
26, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 15, 15, 17, 17, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 30,
};
u16_4tech pp_body_if_fsm_eq_classes[] = {
u16 pp_body_if_fsm_eq_classes[] = {
0, 31, 31, 31, 31, 31, 31, 31, 31, 31, 62, 93, 93, 93, 31, 31,
31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
124,155,186,217,248,155,279,310,341,341,372,403,341,434,465,496,
@ -423,9 +423,9 @@ u16_4tech pp_body_if_fsm_eq_classes[] = {
713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,
};
const i32_4tech num_pp_body_if_fsm_eq_classes = 32;
const i32 num_pp_body_if_fsm_eq_classes = 32;
u8_4tech pp_body_if_fsm_table[] = {
u8 pp_body_if_fsm_table[] = {
31, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61,
0, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 15, 15, 17, 17, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 30,
0, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 46, 15, 17, 17, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 30,
@ -460,7 +460,7 @@ u8_4tech pp_body_if_fsm_table[] = {
26, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 15, 15, 17, 17, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 30,
};
u16_4tech pp_body_fsm_eq_classes[] = {
u16 pp_body_fsm_eq_classes[] = {
0, 31, 31, 31, 31, 31, 31, 31, 31, 31, 62, 93, 93, 93, 31, 31,
31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
124,155,186,217,248,155,279,310,341,341,372,403,341,434,465,496,
@ -479,9 +479,9 @@ u16_4tech pp_body_fsm_eq_classes[] = {
713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,
};
const i32_4tech num_pp_body_fsm_eq_classes = 32;
const i32 num_pp_body_fsm_eq_classes = 32;
u8_4tech pp_body_fsm_table[] = {
u8 pp_body_fsm_table[] = {
31, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61,
0, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 15, 15, 17, 17, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 30,
0, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 46, 15, 17, 17, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 30,
@ -516,7 +516,7 @@ u8_4tech pp_body_fsm_table[] = {
26, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 15, 15, 17, 17, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 30,
};
u16_4tech pp_number_fsm_eq_classes[] = {
u16 pp_number_fsm_eq_classes[] = {
0, 31, 31, 31, 31, 31, 31, 31, 31, 31, 62, 93, 93, 93, 31, 31,
31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
124,155,186,217,248,155,279,310,341,341,372,403,341,434,465,496,
@ -535,9 +535,9 @@ u16_4tech pp_number_fsm_eq_classes[] = {
713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,
};
const i32_4tech num_pp_number_fsm_eq_classes = 32;
const i32 num_pp_number_fsm_eq_classes = 32;
u8_4tech pp_number_fsm_table[] = {
u8 pp_number_fsm_table[] = {
31, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61,
0, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 15, 15, 17, 17, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 30,
0, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 46, 15, 17, 17, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 30,
@ -572,7 +572,7 @@ u8_4tech pp_number_fsm_table[] = {
26, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 15, 15, 17, 17, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 30,
};
u16_4tech pp_error_fsm_eq_classes[] = {
u16 pp_error_fsm_eq_classes[] = {
0, 31, 31, 31, 31, 31, 31, 31, 31, 31, 62, 31, 31, 31, 31, 31,
31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
@ -591,15 +591,15 @@ u16_4tech pp_error_fsm_eq_classes[] = {
31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
};
const i32_4tech num_pp_error_fsm_eq_classes = 3;
const i32 num_pp_error_fsm_eq_classes = 3;
u8_4tech pp_error_fsm_table[] = {
u8 pp_error_fsm_table[] = {
31, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61,
30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61,
};
u16_4tech pp_junk_fsm_eq_classes[] = {
u16 pp_junk_fsm_eq_classes[] = {
0, 31, 31, 31, 31, 31, 31, 31, 31, 31, 62, 93, 93, 93, 31, 31,
31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
124,155,186,217,248,155,279,310,341,341,372,403,341,434,465,496,
@ -618,9 +618,9 @@ u16_4tech pp_junk_fsm_eq_classes[] = {
713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,713,
};
const i32_4tech num_pp_junk_fsm_eq_classes = 32;
const i32 num_pp_junk_fsm_eq_classes = 32;
u8_4tech pp_junk_fsm_table[] = {
u8 pp_junk_fsm_table[] = {
31, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61,
0, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 15, 15, 17, 17, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 30,
0, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 46, 15, 17, 17, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 30,
@ -655,7 +655,7 @@ u8_4tech pp_junk_fsm_table[] = {
26, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 15, 15, 17, 17, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 30,
};
u16_4tech no_string_fsm_eq_classes[] = {
u16 no_string_fsm_eq_classes[] = {
0, 31, 31, 31, 31, 31, 31, 31, 31, 31, 62, 93, 93, 93, 31, 31,
31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
124,155,186,217,248,155,279,186,310,310,341,372,310,403,434,465,
@ -674,9 +674,9 @@ u16_4tech no_string_fsm_eq_classes[] = {
651,651,651,651,651,651,651,651,651,651,651,651,651,651,651,651,
};
const i32_4tech num_no_string_fsm_eq_classes = 26;
const i32 num_no_string_fsm_eq_classes = 26;
u8_4tech no_string_fsm_table[] = {
u8 no_string_fsm_table[] = {
31, 32, 33, 34, 35, 32, 32, 32, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61,
0, 32, 33, 34, 35, 62, 62, 62, 39, 40, 41, 42, 43, 44, 45, 15, 15, 17, 17, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 30,
0, 32, 33, 34, 35, 62, 62, 62, 39, 40, 41, 42, 43, 44, 45, 46, 15, 17, 17, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 30,

View File

@ -392,9 +392,9 @@ DOC_SEE(cpp_make_token_array)
HIDE_MEMBERS() */
STRUCT Cpp_Keyword_Table{
void *mem;
umem_4tech memsize;
u64_4tech *keywords;
u32_4tech max;
umem memsize;
u64 *keywords;
u32 max;
};
/* DOC(Cpp_Lex_Data represents the state of the lexer so that the system may be resumable and the user can manage the lexer state and decide when to resume lexing with it. To create a new lexer state call cpp_lex_data_init.
@ -404,31 +404,31 @@ DOC_SEE(cpp_lex_data_init)
HIDE_MEMBERS() */
STRUCT Cpp_Lex_Data{
char tb[32];
i32_4tech tb_pos;
i32_4tech token_start;
i32 tb_pos;
i32 token_start;
i32_4tech pos;
i32_4tech pos_overide;
i32_4tech chunk_pos;
i32 pos;
i32 pos_overide;
i32 chunk_pos;
Cpp_Lex_FSM fsm;
u8_4tech white_done;
u8_4tech pp_state;
u8_4tech completed;
u8 white_done;
u8 pp_state;
u8 completed;
Cpp_Token token;
char raw_delim[16];
i32_4tech delim_length;
i32 delim_length;
b8_4tech str_raw;
b8_4tech str_include;
b8_4tech ignore_string_delims;
b8 str_raw;
b8 str_include;
b8 ignore_string_delims;
Cpp_Keyword_Table keyword_table;
Cpp_Keyword_Table preprops_table;
i32_4tech __pc__;
i32 __pc__;
};
/* DOC(Cpp_Lex_Result is returned from the lexing engine to indicate why it stopped lexing.) */

View File

@ -16,7 +16,6 @@ CUSTOM_DOC("A lister mode command that quits the list without executing any acti
CUSTOM_COMMAND_SIG(lister__activate)
CUSTOM_DOC("A lister mode command that activates the list's action on the highlighted item.")
{
Partition *scratch = &global_part;
Heap *heap = &global_heap;
View_ID view = 0;
get_active_view(app, AccessAll, &view);
@ -26,7 +25,7 @@ CUSTOM_DOC("A lister mode command that activates the list's action on the highli
if (0 <= state->raw_item_index && state->raw_item_index < state->lister.data.options.count){
user_data = lister_get_user_data(&state->lister.data, state->raw_item_index);
}
lister_call_activate_handler(app, scratch, heap, view, state, user_data, false);
lister_call_activate_handler(app, heap, view, state, user_data, false);
}
}
@ -77,7 +76,6 @@ CUSTOM_DOC("A lister mode command that dispatches to the lister's navigate down
CUSTOM_COMMAND_SIG(lister__wheel_scroll)
CUSTOM_DOC("A lister mode command that scrolls the list in response to the mouse wheel.")
{
Partition *scratch = &global_part;
View_ID view = 0;
get_active_view(app, AccessAll, &view);
GUI_Scroll_Vars scroll = {};
@ -87,19 +85,18 @@ CUSTOM_DOC("A lister mode command that scrolls the list in response to the mouse
view_set_scroll(app, view, scroll);
Lister_State *state = view_get_lister_state(view);
if (state->initialized){
lister_update_ui(app, scratch, view, state);
lister_update_ui(app, view, state);
}
}
CUSTOM_COMMAND_SIG(lister__mouse_press)
CUSTOM_DOC("A lister mode command that beings a click interaction with a list item under the mouse.")
{
Partition *scratch = &global_part;
View_ID view = 0;
get_active_view(app, AccessAll, &view);
Lister_State *state = view_get_lister_state(view);
if (state->initialized){
UI_Item clicked = lister_get_clicked_item(app, view, scratch);
UI_Item clicked = lister_get_clicked_item(app, view);
state->hot_user_data = clicked.user_data;
}
}
@ -107,15 +104,14 @@ CUSTOM_DOC("A lister mode command that beings a click interaction with a list it
CUSTOM_COMMAND_SIG(lister__mouse_release)
CUSTOM_DOC("A lister mode command that ends a click interaction with a list item under the mouse, possibly activating it.")
{
Partition *scratch = &global_part;
Heap *heap = &global_heap;
View_ID view = 0;
get_active_view(app, AccessAll, &view);
Lister_State *state = view_get_lister_state(view);
if (state->initialized && state->hot_user_data != 0){
UI_Item clicked = lister_get_clicked_item(app, view, scratch);
UI_Item clicked = lister_get_clicked_item(app, view);
if (state->hot_user_data == clicked.user_data){
lister_call_activate_handler(app, scratch, heap, view, state, clicked.user_data, true);
lister_call_activate_handler(app, heap, view, state, clicked.user_data, true);
}
}
state->hot_user_data = 0;
@ -124,19 +120,17 @@ CUSTOM_DOC("A lister mode command that ends a click interaction with a list item
CUSTOM_COMMAND_SIG(lister__repaint)
CUSTOM_DOC("A lister mode command that updates the lists UI data.")
{
Partition *scratch = &global_part;
View_ID view = 0;
get_active_view(app, AccessAll, &view);
Lister_State *state = view_get_lister_state(view);
if (state->initialized){
lister_update_ui(app, scratch, view, state);
lister_update_ui(app, view, state);
}
}
CUSTOM_COMMAND_SIG(lister__write_character__default)
CUSTOM_DOC("A lister mode command that inserts a new character to the text field.")
{
Partition *scratch = &global_part;
View_ID view = 0;
get_active_view(app, AccessAll, &view);
Lister_State *state = view_get_lister_state(view);
@ -145,11 +139,11 @@ CUSTOM_DOC("A lister mode command that inserts a new character to the text field
u8 character[4];
u32 length = to_writable_character(in, character);
if (length > 0){
append(&state->lister.data.text_field, make_string(character, length));
append(&state->lister.data.key_string, make_string(character, length));
lister_append_text_field(&state->lister, SCu8(character, length));
lister_append_key(&state->lister, SCu8(character, length));
state->item_index = 0;
view_zero_scroll(app, view);
lister_update_ui(app, scratch, view, state);
lister_update_ui(app, view, state);
}
}
}
@ -157,23 +151,21 @@ CUSTOM_DOC("A lister mode command that inserts a new character to the text field
CUSTOM_COMMAND_SIG(lister__backspace_text_field__default)
CUSTOM_DOC("A lister mode command that backspaces one character from the text field.")
{
Partition *scratch = &global_part;
View_ID view = 0;
get_active_view(app, AccessAll, &view);
Lister_State *state = view_get_lister_state(view);
if (state->initialized){
backspace_utf8(&state->lister.data.text_field);
backspace_utf8(&state->lister.data.key_string);
state->lister.data.text_field.string = backspace_utf8(state->lister.data.text_field.string);
state->lister.data.key_string.string = backspace_utf8(state->lister.data.key_string.string);
state->item_index = 0;
view_zero_scroll(app, view);
lister_update_ui(app, scratch, view, state);
lister_update_ui(app, view, state);
}
}
CUSTOM_COMMAND_SIG(lister__move_up__default)
CUSTOM_DOC("A lister mode command that moves the highlighted item one up in the list.")
{
Partition *scratch = &global_part;
View_ID view = 0;
get_active_view(app, AccessAll, &view);
Lister_State *state = view_get_lister_state(view);
@ -183,14 +175,13 @@ CUSTOM_DOC("A lister mode command that moves the highlighted item one up in the
state->item_index = state->item_count_after_filter - 1;
}
state->set_view_vertical_focus_to_item = true;
lister_update_ui(app, scratch, view, state);
lister_update_ui(app, view, state);
}
}
CUSTOM_COMMAND_SIG(lister__move_down__default)
CUSTOM_DOC("A lister mode command that moves the highlighted item one down in the list.")
{
Partition *scratch = &global_part;
View_ID view = 0;
get_active_view(app, AccessAll, &view);
Lister_State *state = view_get_lister_state(view);
@ -200,14 +191,13 @@ CUSTOM_DOC("A lister mode command that moves the highlighted item one down in th
state->item_index = 0;
}
state->set_view_vertical_focus_to_item = true;
lister_update_ui(app, scratch, view, state);
lister_update_ui(app, view, state);
}
}
CUSTOM_COMMAND_SIG(lister__write_character__file_path)
CUSTOM_DOC("A lister mode command that inserts a character into the text field of a file system list.")
{
Partition *scratch = &global_part;
View_ID view = 0;
get_active_view(app, AccessAll, &view);
Lister_State *state = view_get_lister_state(view);
@ -216,16 +206,17 @@ CUSTOM_DOC("A lister mode command that inserts a character into the text field o
u8 character[4];
u32 length = to_writable_character(in, character);
if (length > 0){
append(&state->lister.data.text_field, make_string(character, length));
copy(&state->lister.data.key_string, front_of_directory(state->lister.data.text_field));
lister_append_text_field(&state->lister, SCu8(character, length));
String_Const_u8 front_name = string_front_of_path(state->lister.data.text_field.string);
lister_set_key(&state->lister, front_name);
if (character[0] == '/' || character[0] == '\\'){
String new_hot = state->lister.data.text_field;
directory_set_hot(app, new_hot.str, new_hot.size);
String_Const_u8 new_hot = state->lister.data.text_field.string;
set_hot_directory(app, new_hot);
lister_call_refresh_handler(app, &state->lister);
}
state->item_index = 0;
view_zero_scroll(app, view);
lister_update_ui(app, scratch, view, state);
lister_update_ui(app, view, state);
}
}
}
@ -233,17 +224,17 @@ CUSTOM_DOC("A lister mode command that inserts a character into the text field o
CUSTOM_COMMAND_SIG(lister__backspace_text_field__file_path)
CUSTOM_DOC("A lister mode command that backspaces one character from the text field of a file system list.")
{
Partition *scratch = &global_part;
View_ID view = 0;
get_active_view(app, AccessAll, &view);
Lister_State *state = view_get_lister_state(view);
if (state->initialized){
if (state->lister.data.text_field.size > 0){
char last_char = state->lister.data.text_field.str[state->lister.data.text_field.size - 1];
backspace_utf8(&state->lister.data.text_field);
state->lister.data.text_field.string = backspace_utf8(state->lister.data.text_field.string);
if (last_char == '/' || last_char == '\\'){
User_Input input = get_command_input(app);
String new_hot = path_of_directory(state->lister.data.text_field);
String_Const_u8 text_field = state->lister.data.text_field.string;
String_Const_u8 new_hot = string_remove_last_folder(text_field);
b32 is_modified = (input.key.modifiers[MDFR_SHIFT_INDEX] ||
input.key.modifiers[MDFR_CONTROL_INDEX] ||
input.key.modifiers[MDFR_ALT_INDEX] ||
@ -252,20 +243,22 @@ CUSTOM_DOC("A lister mode command that backspaces one character from the text fi
if (whole_word_backspace){
state->lister.data.text_field.size = new_hot.size;
}
directory_set_hot(app, new_hot.str, new_hot.size);
set_hot_directory(app, new_hot);
// TODO(allen): We have to protect against lister_call_refresh_handler changing
// the text_field here. Clean this up.
String dingus = state->lister.data.text_field;
String_u8 dingus = state->lister.data.text_field;
lister_call_refresh_handler(app, &state->lister);
state->lister.data.text_field = dingus;
}
else{
copy(&state->lister.data.key_string, front_of_directory(state->lister.data.text_field));
String_Const_u8 text_field = state->lister.data.text_field.string;
String_Const_u8 new_key = string_front_of_path(text_field);
lister_set_key(&state->lister, new_key);
}
state->item_index = 0;
view_zero_scroll(app, view);
lister_update_ui(app, scratch, view, state);
lister_update_ui(app, view, state);
}
}
}
@ -273,7 +266,6 @@ CUSTOM_DOC("A lister mode command that backspaces one character from the text fi
CUSTOM_COMMAND_SIG(lister__write_character__fixed_list)
CUSTOM_DOC("A lister mode command that handles input for the fixed sure to kill list.")
{
Partition *scratch = &global_part;
Heap *heap = &global_heap;
View_ID view = 0;
get_active_view(app, AccessAll, &view);
@ -289,14 +281,15 @@ CUSTOM_DOC("A lister mode command that handles input for the fixed sure to kill
node != 0;
node = node->next){
char *hotkeys = (char*)(node + 1);
if (has_substr(hotkeys, make_string(character, length))){
String_Const_u8 hot_key_string = SCu8(hotkeys);
if (string_find_first(hot_key_string, SCu8(character, length)) < hot_key_string.size){
user_data = node->user_data;
did_shortcut_key = true;
break;
}
}
if (did_shortcut_key){
lister_call_activate_handler(app, scratch, heap, view, state, user_data, false);
lister_call_activate_handler(app, heap, view, state, user_data, false);
}
}
}
@ -330,24 +323,24 @@ begin_integrated_lister__with_refresh_handler(Application_Links *app, char *quer
void *user_data, i32 user_data_size,
View_ID view){
if (handlers.refresh != 0){
Partition *scratch = &global_part;
Heap *heap = &global_heap;
view_begin_ui_mode(app, view);
view_set_setting(app, view, ViewSetting_UICommandMap, default_lister_ui_map);
Lister_State *state = view_get_lister_state(view);
init_lister_state(app, state, heap);
lister_first_init(app, &state->lister, user_data, user_data_size);
lister_set_query_string(&state->lister.data, query_string);
lister_set_query(&state->lister, query_string);
state->lister.data.handlers = handlers;
handlers.refresh(app, &state->lister);
lister_update_ui(app, scratch, view, state);
lister_update_ui(app, view, state);
}
else{
char space[256];
String str = make_fixed_width_string(space);
append(&str, "ERROR: No refresh handler specified for lister (query_string = \"");
append(&str, query_string);
append(&str, "\")\n");
Scratch_Block scratch(app);
List_String_Const_u8 list = {};
string_list_push(scratch, &list, string_u8_litexpr("ERROR: No refresh handler specified for lister (query_string = \""));
string_list_push(scratch, &list, SCu8(query_string));
string_list_push(scratch, &list, string_u8_litexpr("\")\n"));
String_Const_u8 str = string_list_flatten(scratch, list);
print_message(app, str);
}
}
@ -368,7 +361,6 @@ begin_integrated_lister__basic_list(Application_Links *app, char *query_string,
Lister_Option *options, i32 option_count,
i32 estimated_string_space_size,
View_ID view){
Partition *scratch = &global_part;
Heap *heap = &global_heap;
view_begin_ui_mode(app, view);
view_set_setting(app, view, ViewSetting_UICommandMap, default_lister_ui_map);
@ -378,10 +370,10 @@ begin_integrated_lister__basic_list(Application_Links *app, char *query_string,
for (i32 i = 0; i < option_count; i += 1){
lister_add_item(&state->lister, options[i].string, options[i].status, options[i].user_data, 0);
}
lister_set_query_string(&state->lister.data, query_string);
lister_set_query(&state->lister, query_string);
state->lister.data.handlers = lister_get_default_handlers();
state->lister.data.handlers.activate = activate;
lister_update_ui(app, scratch, view, state);
lister_update_ui(app, view, state);
}
static void
@ -391,7 +383,6 @@ begin_integrated_lister__with_fixed_options(Application_Links *app, char *query_
Lister_Fixed_Option *options, i32 option_count,
i32 estimated_string_space_size,
View_ID view){
Partition *scratch = &global_part;
Heap *heap = &global_heap;
view_begin_ui_mode(app, view);
view_set_setting(app, view, ViewSetting_UICommandMap, default_lister_ui_map);
@ -400,18 +391,18 @@ begin_integrated_lister__with_fixed_options(Application_Links *app, char *query_
lister_first_init(app, &state->lister, user_data, user_data_size);
for (i32 i = 0; i < option_count; i += 1){
char *shortcut_chars = options[i].shortcut_chars;
i32 shortcut_chars_length = str_size(shortcut_chars);
umem shortcut_chars_length = cstring_length(shortcut_chars);
void *extra = lister_add_item(&state->lister,
make_string_slowly(options[i].string),
make_string_slowly(options[i].status),
SCu8(options[i].string),
SCu8(options[i].status),
options[i].user_data,
shortcut_chars_length + 1);
memcpy(extra, shortcut_chars, shortcut_chars_length + 1);
}
lister_set_query_string(&state->lister.data, query_string);
lister_set_query(&state->lister, query_string);
state->lister.data.handlers = handlers;
state->lister.data.handlers.refresh = 0;
lister_update_ui(app, scratch, view, state);
lister_update_ui(app, view, state);
}
static void
@ -437,7 +428,6 @@ begin_integrated_lister__theme_list(Application_Links *app, char *query_string,
Lister_UI_Option *options, i32 option_count,
i32 estimated_string_space_size,
View_ID view){
Partition *scratch = &global_part;
Heap *heap = &global_heap;
view_begin_ui_mode(app, view);
view_set_setting(app, view, ViewSetting_UICommandMap, default_lister_ui_map);
@ -447,14 +437,14 @@ begin_integrated_lister__theme_list(Application_Links *app, char *query_string,
state->lister.data.theme_list = true;
for (i32 i = 0; i < option_count; i += 1){
lister_add_theme_item(&state->lister,
make_string_slowly(options[i].string),
SCu8(options[i].string),
options[i].index,
options[i].user_data, 0);
}
lister_set_query_string(&state->lister.data, query_string);
lister_set_query(&state->lister, query_string);
state->lister.data.handlers = handlers;
state->lister.data.handlers.refresh = 0;
lister_update_ui(app, scratch, view, state);
lister_update_ui(app, view, state);
}
static void
@ -479,36 +469,22 @@ static void
generate_all_buffers_list__output_buffer(Application_Links *app, Lister *lister, Buffer_ID buffer){
Dirty_State dirty = 0;
buffer_get_dirty_state(app, buffer, &dirty);
String status = {};
String_Const_u8 status = {};
switch (dirty){
case DirtyState_UnsavedChanges: status = make_lit_string("*"); break;
case DirtyState_UnloadedChanges: status = make_lit_string("!"); break;
case DirtyState_UnsavedChangesAndUnloadedChanges: status = make_lit_string("*!"); break;
case DirtyState_UnsavedChanges: status = string_u8_litexpr("*"); break;
case DirtyState_UnloadedChanges: status = string_u8_litexpr("!"); break;
case DirtyState_UnsavedChangesAndUnloadedChanges: status = string_u8_litexpr("*!"); break;
}
Arena *scratch = context_get_arena(app);
Temp_Memory_Arena temp = begin_temp_memory(scratch);
String buffer_name = buffer_push_unique_buffer_name(app, buffer, scratch);
Temp_Memory temp = begin_temp(scratch);
String_Const_u8 buffer_name = buffer_push_unique_buffer_name(app, buffer, scratch);
lister_add_item(lister, buffer_name, status, IntAsPtr(buffer), 0);
end_temp_memory(temp);
end_temp(temp);
}
static void
generate_all_buffers_list(Application_Links *app, Lister *lister){
i32 buffer_count = get_buffer_count(app);
i32 memory_size = 0;
memory_size += buffer_count*(sizeof(Lister_Node) + 3);
{
Buffer_ID buffer = 0;
for (get_buffer_next(app, 0, AccessAll, &buffer);
buffer != 0;
get_buffer_next(app, buffer, AccessAll, &buffer)){
i32 name_length = 0;
buffer_get_unique_buffer_name(app, buffer, 0, &name_length);
memory_size += name_length;
}
}
lister_begin_new_item_set(app, lister, memory_size);
lister_begin_new_item_set(app, lister);
Buffer_ID buffers_currently_being_viewed[16];
i32 currently_viewed_buffer_count = 0;
@ -573,44 +549,32 @@ generate_all_buffers_list(Application_Links *app, Lister *lister){
static void
generate_hot_directory_file_list(Application_Links *app, Lister *lister){
Temp_Memory_Arena temp = begin_temp_memory(&lister->arena);
String hot = get_hot_directory(app, &lister->arena);
if (hot.size > 0 && hot.str[hot.size - 1] != '/' && hot.str[hot.size - 1] != '\\'){
if (push_array(&lister->arena, char, 1) != 0){
hot.memory_size += 1;
append_s_char(&hot, '/');
}
Temp_Memory temp = begin_temp(&lister->arena);
String_Const_u8 hot = push_hot_directory(app, &lister->arena);
if (!character_is_slash(string_get_character(hot, hot.size - 1))){
hot = string_u8_pushf(&lister->arena, "%.*s/", string_expand(hot));
}
lister_set_text_field_string(&lister->data, hot);
lister_set_key_string(&lister->data, front_of_directory(hot));
lister_set_text_field(lister, hot);
lister_set_key(lister, string_front_of_path(hot));
File_List file_list = get_file_list(app, hot.str, hot.size);
end_temp_memory(temp);
File_List file_list = {};
get_file_list(app, hot, &file_list);
end_temp(temp);
File_Info *one_past_last = file_list.infos + file_list.count;
i32 memory_requirement = 0;
memory_requirement += lister->data.user_data_size;
memory_requirement += file_list.count*(sizeof(Lister_Node) + 10);
memory_requirement += hot.size + 2;
for (File_Info *info = file_list.infos;
info < one_past_last;
info += 1){
memory_requirement += info->filename_len;
}
lister_begin_new_item_set(app, lister);
lister_begin_new_item_set(app, lister, memory_requirement);
hot = get_hot_directory(app, &lister->arena);
hot = push_hot_directory(app, &lister->arena);
push_align(&lister->arena, 8);
if (hot.str != 0){
String empty_string = make_lit_string("");
Lister_Prealloced_String empty_string_prealloced = {empty_string};
String_Const_u8 empty_string = string_u8_litexpr("");
Lister_Prealloced_String empty_string_prealloced = lister_prealloced(empty_string);
for (File_Info *info = file_list.infos;
info < one_past_last;
info += 1){
if (!info->folder) continue;
String file_name = string_push_f(&lister->arena, "%.*s/", info->filename_len, info->filename);
String_Const_u8 file_name = string_u8_pushf(&lister->arena, "%.*s/", info->filename_len, info->filename);
lister_add_item(lister, lister_prealloced(file_name), empty_string_prealloced, file_name.str, 0);
}
@ -618,7 +582,7 @@ generate_hot_directory_file_list(Application_Links *app, Lister *lister){
info < one_past_last;
info += 1){
if (info->folder) continue;
String file_name = string_push_copy(&lister->arena, make_string(info->filename, info->filename_len));
String_Const_u8 file_name = string_copy(&lister->arena, SCu8(info->filename, info->filename_len));
char *is_loaded = "";
char *status_flag = "";
@ -626,19 +590,14 @@ generate_hot_directory_file_list(Application_Links *app, Lister *lister){
Buffer_ID buffer = {};
{
Temp_Memory_Arena path_temp = begin_temp_memory(&lister->arena);
String full_file_path = {};
full_file_path.size = 0;
full_file_path.memory_size = hot.size + 1 + info->filename_len + 1;
full_file_path.str = push_array(&lister->arena, char, full_file_path.memory_size);
append(&full_file_path, hot);
if (full_file_path.size == 0 ||
char_is_slash(full_file_path.str[full_file_path.size - 1])){
append(&full_file_path, "/");
}
append(&full_file_path, make_string(info->filename, info->filename_len));
Temp_Memory path_temp = begin_temp(&lister->arena);
List_String_Const_u8 list = {};
string_list_push(&lister->arena, &list, hot);
string_list_push_overlap(&lister->arena, &list, '/',
SCu8(info->filename, info->filename_len));
String_Const_u8 full_file_path = string_list_flatten(&lister->arena, list);
get_buffer_by_file_name(app, full_file_path, AccessAll, &buffer);
end_temp_memory(path_temp);
end_temp(path_temp);
}
if (buffer != 0){
@ -651,7 +610,7 @@ generate_hot_directory_file_list(Application_Links *app, Lister *lister){
case DirtyState_UnsavedChangesAndUnloadedChanges: status_flag = " *!"; break;
}
}
String status = string_push_f(&lister->arena, "%s%s", is_loaded, status_flag);
String_Const_u8 status = string_u8_pushf(&lister->arena, "%s%s", is_loaded, status_flag);
lister_add_item(lister, lister_prealloced(file_name), lister_prealloced(status), file_name.str, 0);
}
}
@ -689,8 +648,7 @@ enum{
};
static void
activate_confirm_kill(Application_Links *app, Partition *scratch, Heap *heap, View_ID view, Lister_State *state,
String text_field, void *user_data, b32 clicked){
activate_confirm_kill(Application_Links *app, Heap *heap, View_ID view, Lister_State *state, String_Const_u8 text_field, void *user_data, b32 clicked){
i32 behavior = (i32)PtrAsInt(user_data);
Buffer_ID buffer_id = *(Buffer_ID*)(state->lister.data.user_data);
switch (behavior){
@ -699,31 +657,28 @@ activate_confirm_kill(Application_Links *app, Partition *scratch, Heap *heap, Vi
case SureToKill_Yes:
{
kill_buffer(app, buffer_identifier(buffer_id), BufferKill_AlwaysKill);
Buffer_Kill_Result ignore = 0;
buffer_kill(app, buffer_id, BufferKill_AlwaysKill, &ignore);
}break;
case SureToKill_Save:
{
Arena *scratch_arena = context_get_arena(app);
Temp_Memory_Arena temp = begin_temp_memory(scratch_arena);
String file_name = buffer_push_file_name(app, buffer_id, scratch_arena);
Arena *scratch = context_get_arena(app);
Temp_Memory temp = begin_temp(scratch);
String_Const_u8 file_name = buffer_push_file_name(app, buffer_id, scratch);
if (buffer_save(app, buffer_id, file_name, BufferSave_IgnoreDirtyFlag)){
buffer_kill(app, buffer_id, BufferKill_AlwaysKill, 0);
}
else{
char space[256];
String str = make_fixed_width_string(space);
append(&str, "Did not close '");
append(&str, file_name);
append(&str, "' because it did not successfully save.\n");
print_message(app, str.str, str.size);
String_Const_u8 str = string_u8_pushf(scratch, "Did not close '%.*s' because it did not successfully save.",
string_expand(file_name));
print_message(app, str);
}
end_temp_memory(temp);
end_temp(temp);
}break;
}
lister_default(app, scratch, heap, view, state, ListerActivation_Finished);
lister_default(app, heap, view, state, ListerActivation_Finished);
}
static void
@ -741,9 +696,9 @@ do_gui_sure_to_kill(Application_Links *app, Buffer_ID buffer, View_ID view){
}
static void
activate_confirm_close_4coder(Application_Links *app, Partition *scratch, Heap *heap,
activate_confirm_close_4coder(Application_Links *app, Heap *heap,
View_ID view, Lister_State *state,
String text_field, void *user_data, b32 clicked){
String_Const_u8 text_field, void *user_data, b32 clicked){
i32 behavior = (i32)PtrAsInt(user_data);
switch (behavior){
case SureToKill_No:
@ -762,8 +717,7 @@ activate_confirm_close_4coder(Application_Links *app, Partition *scratch, Heap *
send_exit_signal(app);
}break;
}
lister_default(app, scratch, heap, view, state, ListerActivation_Finished);
lister_default(app, heap, view, state, ListerActivation_Finished);
}
static void
@ -783,14 +737,14 @@ do_gui_sure_to_close_4coder(Application_Links *app, View_ID view){
////////////////////////////////
static void
activate_switch_buffer(Application_Links *app, Partition *scratch, Heap *heap,
activate_switch_buffer(Application_Links *app, Heap *heap,
View_ID view, Lister_State *state,
String text_field, void *user_data, b32 activated_by_mouse){
String_Const_u8 text_field, void *user_data, b32 activated_by_mouse){
if (user_data != 0){
Buffer_ID buffer_id = (Buffer_ID)(PtrAsInt(user_data));
view_set_buffer(app, view, buffer_id, SetBuffer_KeepOriginalGUI);
}
lister_default(app, scratch, heap, view, state, ListerActivation_Finished);
lister_default(app, heap, view, state, ListerActivation_Finished);
}
CUSTOM_COMMAND_SIG(interactive_switch_buffer)
@ -803,10 +757,10 @@ CUSTOM_DOC("Interactively switch to an open buffer.")
}
static void
activate_kill_buffer(Application_Links *app, Partition *scratch, Heap *heap,
activate_kill_buffer(Application_Links *app, Heap *heap,
View_ID view, struct Lister_State *state,
String text_field, void *user_data, b32 activated_by_mouse){
lister_default(app, scratch, heap, view, state, ListerActivation_Finished);
String_Const_u8 text_field, void *user_data, b32 activated_by_mouse){
lister_default(app, heap, view, state, ListerActivation_Finished);
if (user_data != 0){
Buffer_ID buffer_id = (Buffer_ID)(PtrAsInt(user_data));
kill_buffer(app, buffer_identifier(buffer_id), view, 0);
@ -823,27 +777,27 @@ CUSTOM_DOC("Interactively kill an open buffer.")
}
static Lister_Activation_Code
activate_open_or_new__generic(Application_Links *app, Partition *scratch, View_ID view,
String path, String file_name, b32 is_folder,
activate_open_or_new__generic(Application_Links *app, View_ID view,
String_Const_u8 path, String_Const_u8 file_name, b32 is_folder,
Buffer_Create_Flag flags){
Lister_Activation_Code result = 0;
if (file_name.size == 0){
char msg[] = "Zero length file_name passed to activate_open_or_new__generic\n";
print_message(app, msg, sizeof(msg) - 1);
#define M "Zero length file_name passed to activate_open_or_new__generic\n"
print_message(app, string_u8_litexpr(M));
#undef M
result = ListerActivation_Finished;
}
else{
Temp_Memory temp = begin_temp_memory(scratch);
String full_file_name = {};
if (path.size == 0 || !char_is_slash(path.str[path.size - 1])){
full_file_name = string_push_f(scratch, "%.*s/%.*s", path.size, path.str, file_name.size, file_name.str);
}
else{
full_file_name = string_push_f(scratch, "%.*s%.*s", path.size, path.str, file_name.size, file_name.str);
Arena *scratch = context_get_arena(app);
Temp_Memory temp = begin_temp(scratch);
String_Const_u8 full_file_name = {};
if (character_is_slash(string_get_character(path, path.size - 1))){
path = string_chop(path, 1);
}
full_file_name = string_u8_pushf(scratch, "%.*s/%.*s", string_expand(path), string_expand(file_name));
if (is_folder){
directory_set_hot(app, full_file_name.str, full_file_name.size);
set_hot_directory(app, full_file_name);
result = ListerActivation_ContinueAndRefresh;
}
else{
@ -854,37 +808,38 @@ activate_open_or_new__generic(Application_Links *app, Partition *scratch, View_I
}
result = ListerActivation_Finished;
}
end_temp_memory(temp);
end_temp(temp);
}
return(result);
}
static void
activate_open_or_new(Application_Links *app, Partition *scratch, Heap *heap,
activate_open_or_new(Application_Links *app, Heap *heap,
View_ID view, struct Lister_State *state,
String text_field, void *user_data, b32 clicked){
String_Const_u8 text_field, void *user_data, b32 clicked){
Lister_Activation_Code result = 0;
String file_name = {};
String_Const_u8 file_name = {};
if (user_data == 0){
file_name = front_of_directory(text_field);
file_name = string_front_of_path(text_field);
}
else{
file_name = make_string_slowly((char*)user_data);
file_name = SCu8((u8*)user_data);
}
if (file_name.size == 0){
result = ListerActivation_Finished;
}
else{
String path = state->lister.data.text_field;
if (path.size > 0 && !char_is_slash(path.str[path.size - 1])){
path = path_of_directory(path);
String_Const_u8 path = state->lister.data.text_field.string;
if (!character_is_slash(string_get_character(path, path.size - 1))){
path = string_remove_last_folder(path);
}
b32 is_folder = (file_name.str[file_name.size - 1] == '/' && user_data != 0);
b32 is_folder = (character_is_slash(string_get_character(file_name, file_name.size - 1)) &&
user_data != 0);
Buffer_Create_Flag flags = 0;
result = activate_open_or_new__generic(app, scratch, view, path, file_name, is_folder, flags);
result = activate_open_or_new__generic(app, view, path, file_name, is_folder, flags);
}
lister_default(app, scratch, heap, view, state, result);
lister_default(app, heap, view, state, result);
}
CUSTOM_COMMAND_SIG(interactive_open_or_new)
@ -897,13 +852,13 @@ CUSTOM_DOC("Interactively open a file out of the file system.")
}
static void
activate_new(Application_Links *app, Partition *scratch, Heap *heap,
activate_new(Application_Links *app, Heap *heap,
View_ID view, struct Lister_State *state,
String text_field, void *user_data, b32 clicked){
String_Const_u8 text_field, void *user_data, b32 clicked){
Lister_Activation_Code result = 0;
String file_name = front_of_directory(text_field);
String_Const_u8 file_name = string_front_of_path(text_field);
if (user_data != 0){
String item_name = make_string_slowly((char*)user_data);
String_Const_u8 item_name = SCu8((u8*)user_data);
if (item_name.str[item_name.size - 1] == '/'){
file_name = item_name;
}
@ -915,15 +870,16 @@ activate_new(Application_Links *app, Partition *scratch, Heap *heap,
result = ListerActivation_Finished;
}
else{
String path = state->lister.data.text_field;
if (path.size > 0 && !char_is_slash(path.str[path.size - 1])){
path = path_of_directory(path);
String_Const_u8 path = state->lister.data.text_field.string;
if (character_is_slash(string_get_character(path, path.size - 1))){
path = string_remove_last_folder(path);
}
b32 is_folder = (file_name.str[file_name.size - 1] == '/' && user_data != 0);
b32 is_folder = (character_is_slash(string_get_character(file_name, file_name.size - 1)) &&
user_data != 0);
Buffer_Create_Flag flags = BufferCreate_AlwaysNew;
result = activate_open_or_new__generic(app, scratch, view, path, file_name, is_folder, flags);
result = activate_open_or_new__generic(app, view, path, file_name, is_folder, flags);
}
lister_default(app, scratch, heap, view, state, result);
lister_default(app, heap, view, state, result);
}
CUSTOM_COMMAND_SIG(interactive_new)
@ -936,27 +892,28 @@ CUSTOM_DOC("Interactively creates a new file.")
}
static void
activate_open(Application_Links *app, Partition *scratch, Heap *heap,
activate_open(Application_Links *app, Heap *heap,
View_ID view, struct Lister_State *state,
String text_field, void *user_data, b32 clicked){
String_Const_u8 text_field, void *user_data, b32 clicked){
Lister_Activation_Code result = 0;
String file_name = {};
String_Const_u8 file_name = {};
if (user_data != 0){
file_name = make_string_slowly((char*)user_data);
file_name = SCu8((u8*)user_data);
}
if (file_name.size == 0){
result = ListerActivation_Finished;
}
else{
String path = state->lister.data.text_field;
if (path.size > 0 && !char_is_slash(path.str[path.size - 1])){
path = path_of_directory(path);
String_Const_u8 path = state->lister.data.text_field.string;
if (!character_is_slash(string_get_character(path, path.size - 1))){
path = string_remove_last_folder(path);
}
b32 is_folder = (file_name.str[file_name.size - 1] == '/' && user_data != 0);
b32 is_folder = (character_is_slash(string_get_character(file_name, file_name.size - 1)) &&
user_data != 0);
Buffer_Create_Flag flags = BufferCreate_NeverNew;
result = activate_open_or_new__generic(app, scratch, view, path, file_name, is_folder, flags);
result = activate_open_or_new__generic(app, view, path, file_name, is_folder, flags);
}
lister_default(app, scratch, heap, view, state, result);
lister_default(app, heap, view, state, result);
}
CUSTOM_COMMAND_SIG(interactive_open)
@ -972,7 +929,7 @@ CUSTOM_DOC("Interactively opens a file.")
static void
activate_select_theme(Application_Links *app, Partition *scratch, Heap *heap,
View_ID view, struct Lister_State *state,
String text_field, void *user_data, b32 clicked){
String_Const_u8 text_field, void *user_data, b32 clicked){
change_theme_by_index(app, (i32)PtrAsInt(user_data));
lister_default(app, scratch, heap, view, state, ListerActivation_Finished);
}
@ -1008,10 +965,10 @@ CUSTOM_DOC("Opens the 4coder theme selector list.")
////////////////////////////////
static void
activate_command(Application_Links *app, Partition *scratch, Heap *heap,
activate_command(Application_Links *app, Heap *heap,
View_ID view, Lister_State *state,
String text_field, void *user_data, b32 activated_by_mouse){
lister_default(app, scratch, heap, view, state, ListerActivation_Finished);
String_Const_u8 text_field, void *user_data, b32 activated_by_mouse){
lister_default(app, heap, view, state, ListerActivation_Finished);
if (user_data != 0){
Custom_Command_Function *command = (Custom_Command_Function*)user_data;
command(app);
@ -1024,24 +981,24 @@ launch_custom_command_lister(Application_Links *app, i32 *command_ids, i32 comma
command_id_count = command_one_past_last_id;
}
Partition *arena = &global_part;
Arena *scratch = context_get_arena(app);
View_ID view = 0;
get_active_view(app, AccessAll, &view);
view_end_ui_mode(app, view);
Temp_Memory temp = begin_temp_memory(arena);
Lister_Option *options = push_array(arena, Lister_Option, command_id_count);
Temp_Memory temp = begin_temp(scratch);
Lister_Option *options = push_array(scratch, Lister_Option, command_id_count);
for (i32 i = 0; i < command_id_count; i += 1){
i32 j = i;
if (command_ids != 0){
j = command_ids[i];
}
j = clamp(0, j, command_one_past_last_id);
options[i].string = make_string_slowly(fcoder_metacmd_table[j].name);
options[i].status = make_string_slowly(fcoder_metacmd_table[j].description);
options[i].string = SCu8(fcoder_metacmd_table[j].name);
options[i].status = SCu8(fcoder_metacmd_table[j].description);
options[i].user_data = (void*)fcoder_metacmd_table[j].proc;
}
begin_integrated_lister__basic_list(app, "Command:", activate_command, 0, 0, options, command_id_count, 0, view);
end_temp_memory(temp);
end_temp(temp);
}
CUSTOM_COMMAND_SIG(command_lister)

View File

@ -0,0 +1,48 @@
/*
* 4coder malloc base allocator
*/
// TOP
#include <stdlib.h>
#include <malloc.h>
internal void*
base_reserve__malloc(void *user_data, umem size, umem *size_out){
*size_out = size;
return(malloc(size));
}
internal void
base_free__malloc(void *user_data, void *ptr){
free(ptr);
}
internal Base_Allocator
make_malloc_base_allocator(void){
return(make_base_allocator(base_reserve__malloc, 0, 0,
base_free__malloc, 0, 0));
}
global Base_Allocator malloc_base_allocator = {};
internal Arena
make_arena_malloc(umem chunk_size, umem align){
if (malloc_base_allocator.reserve == 0){
malloc_base_allocator = make_malloc_base_allocator();
}
return(make_arena(&malloc_base_allocator, chunk_size, align));
}
internal Arena
make_arena_malloc(umem chunk_size){
return(make_arena_malloc(chunk_size, 8));
}
internal Arena
make_arena_malloc(void){
return(make_arena_malloc(KB(16), 8));
}
// BOTTOM

View File

@ -6,6 +6,14 @@
#define COMMAND_METADATA_OUT "4coder_generated/command_metadata.h"
#include "4coder_base_types.h"
#include "4coder_lib/4coder_string.h"
#include "4coder_base_types.cpp"
#include "4coder_stringf.cpp"
#include "4coder_malloc_allocator.cpp"
#include "4coder_file.h"
#include "4coder_lib/4cpp_lexer.h"
@ -14,8 +22,8 @@
#include <stdlib.h>
#include <stdint.h>
#define str_to_l_c(s) ((s).size), ((s).str)
#define str_to_c_l(s) ((s).str), ((s).size)
#define str_to_l_c(s) ((i32)(s).size), ((s).str)
#define str_to_c_l(s) ((s).str), ((i32)(s).size)
///////////////////////////////
@ -25,12 +33,12 @@ struct Line_Column_Coordinates{
};
static Line_Column_Coordinates
line_column_coordinates(String text, int32_t pos){
line_column_coordinates(String_Const_char text, int32_t pos){
if (pos < 0){
pos = 0;
}
if (pos > text.size){
pos = text.size;
pos = (i32)text.size;
}
Line_Column_Coordinates coords = {};
@ -51,13 +59,13 @@ line_column_coordinates(String text, int32_t pos){
}
static int32_t
line_number(String text, int32_t pos){
line_number(String_Const_char text, int32_t pos){
Line_Column_Coordinates coords = line_column_coordinates(text, pos);
return(coords.line);
}
static void
error(char *source_name, String text, int32_t pos, char *msg){
error(char *source_name, String_Const_char text, int32_t pos, char *msg){
Line_Column_Coordinates coords = line_column_coordinates(text, pos);
fprintf(stdout, "%s:%d:%d: %s\n", source_name, coords.line, coords.column, msg);
fflush(stdout);
@ -66,8 +74,9 @@ error(char *source_name, String text, int32_t pos, char *msg){
///////////////////////////////
struct Reader{
Arena *error_arena;
char *source_name;
String text;
String_Const_char text;
Cpp_Token_Array tokens;
Cpp_Token *ptr;
};
@ -78,7 +87,7 @@ struct Temp_Read{
};
static Reader
make_reader(Cpp_Token_Array array, char *source_name, String text){
make_reader(Cpp_Token_Array array, char *source_name, String_Const_char text){
Reader reader = {};
reader.tokens = array;
reader.ptr = array.tokens;
@ -130,7 +139,7 @@ get_token(Reader *reader){
else{
reader->ptr = reader->tokens.tokens + reader->tokens.count;
memset(&result, 0, sizeof(result));
result.start = reader->text.size;
result.start = (i32)reader->text.size;
break;
}
@ -151,7 +160,7 @@ peek_token(Reader *reader){
}
if (reader->ptr >= reader->tokens.tokens + reader->tokens.count){
result.start = reader->text.size;
result.start = (i32)reader->text.size;
}
else{
result = *reader->ptr;
@ -192,18 +201,14 @@ end_temp_read(Temp_Read temp){
///////////////////////////////
static String
token_str(String text, Cpp_Token token){
String str = substr(text, token.start, token.size);
static String_Const_char
token_str(String_Const_char text, Cpp_Token token){
String_Const_char str = string_prefix(string_skip(text, token.start), token.size);
return(str);
}
///////////////////////////////
#define sll_push(f,l,n) if((f)==0){(f)=(l)=(n);}else{(l)->next=(n);(l)=(n);}(n)->next=0
///////////////////////////////
typedef uint32_t Meta_Command_Entry_Type;
enum{
MetaCommandEntry_DocString,
@ -212,15 +217,15 @@ enum{
struct Meta_Command_Entry{
Meta_Command_Entry *next;
String name;
String_Const_char name;
char *source_name;
int32_t line_number;
union{
struct{
String doc;
String_Const_char doc;
} docstring;
struct{
String potential;
String_Const_char potential;
} alias;
};
};
@ -237,15 +242,13 @@ struct Meta_Command_Entry_Arrays{
///////////////////////////////
#define Swap(T,a,b) {T t=a; a=b; b=t;}
static int32_t
quick_sort_part(Meta_Command_Entry **entries, int32_t first, int32_t one_past_last){
int32_t pivot = one_past_last - 1;
String pivot_key = entries[pivot]->name;
String_Const_char pivot_key = entries[pivot]->name;
int32_t j = first;
for (int32_t i = first; i < pivot; ++i){
if (compare(entries[i]->name, pivot_key) < 0){
if (string_compare(entries[i]->name, pivot_key) < 0){
Swap(Meta_Command_Entry*, entries[i], entries[j]);
++j;
}
@ -264,8 +267,8 @@ quick_sort(Meta_Command_Entry **entries, int32_t first, int32_t one_past_last){
}
static Meta_Command_Entry**
get_sorted_meta_commands(Partition *part, Meta_Command_Entry *first, int32_t count){
Meta_Command_Entry **entries = push_array(part, Meta_Command_Entry*, count);
get_sorted_meta_commands(Arena *arena, Meta_Command_Entry *first, int32_t count){
Meta_Command_Entry **entries = push_array(arena, Meta_Command_Entry*, count);
int32_t i = 0;
for (Meta_Command_Entry *entry = first;
@ -282,13 +285,13 @@ get_sorted_meta_commands(Partition *part, Meta_Command_Entry *first, int32_t cou
///////////////////////////////
static bool32
has_duplicate_entry(Meta_Command_Entry *first, String name){
bool32 has_duplicate = false;
static b32
has_duplicate_entry(Meta_Command_Entry *first, String_Const_char name){
b32 has_duplicate = false;
for (Meta_Command_Entry *entry = first;
entry != 0;
entry = entry->next){
if (match(name, entry->name)){
if (string_match(name, entry->name)){
has_duplicate = true;
}
}
@ -297,14 +300,16 @@ has_duplicate_entry(Meta_Command_Entry *first, String name){
///////////////////////////////
static bool32
static b32
require_key_identifier(Reader *reader, char *str, int32_t *opt_pos_out = 0){
bool32 success = false;
b32 success = false;
String_Const_char string = SCchar(str);
Cpp_Token token = get_token(reader);
if (token.type == CPP_TOKEN_IDENTIFIER){
String lexeme = token_str(reader->text, token);
if (match(lexeme, str)){
String_Const_char lexeme = token_str(reader->text, token);
if (string_match(lexeme, string)){
success = true;
if (opt_pos_out != 0){
*opt_pos_out = token.start;
@ -313,21 +318,18 @@ require_key_identifier(Reader *reader, char *str, int32_t *opt_pos_out = 0){
}
if (!success){
char space[1024];
String s = make_fixed_width_string(space);
copy(&s, "expected to find '");
append(&s, str);
append(&s, "'");
terminate_with_null(&s);
error(reader, token.start, s.str);
Temp_Memory temp = begin_temp(reader->error_arena);
String_Const_char error_string = string_pushf(reader->error_arena, "expected to find '%s'", str);
error(reader, token.start, error_string.str);
end_temp(temp);
}
return(success);
}
static bool32
static b32
require_open_parenthese(Reader *reader, int32_t *opt_pos_out = 0){
bool32 success = false;
b32 success = false;
Cpp_Token token = get_token(reader);
if (token.type == CPP_TOKEN_PARENTHESE_OPEN){
@ -344,9 +346,9 @@ require_open_parenthese(Reader *reader, int32_t *opt_pos_out = 0){
return(success);
}
static bool32
static b32
require_close_parenthese(Reader *reader, int32_t *opt_pos_out = 0){
bool32 success = false;
b32 success = false;
Cpp_Token token = get_token(reader);
if (token.type == CPP_TOKEN_PARENTHESE_CLOSE){
@ -363,9 +365,9 @@ require_close_parenthese(Reader *reader, int32_t *opt_pos_out = 0){
return(success);
}
static bool32
static b32
require_comma(Reader *reader, int32_t *opt_pos_out = 0){
bool32 success = false;
b32 success = false;
Cpp_Token token = get_token(reader);
if (token.type == CPP_TOKEN_COMMA){
@ -382,9 +384,9 @@ require_comma(Reader *reader, int32_t *opt_pos_out = 0){
return(success);
}
static bool32
static b32
require_define(Reader *reader, int32_t *opt_pos_out = 0){
bool32 success = false;
b32 success = false;
Cpp_Token token = get_token(reader);
if (token.type == CPP_PP_DEFINE){
@ -401,13 +403,13 @@ require_define(Reader *reader, int32_t *opt_pos_out = 0){
return(success);
}
static bool32
extract_identifier(Reader *reader, String *str_out, int32_t *opt_pos_out = 0){
bool32 success = false;
static b32
extract_identifier(Reader *reader, String_Const_char *str_out, int32_t *opt_pos_out = 0){
b32 success = false;
Cpp_Token token = get_token(reader);
if (token.type == CPP_TOKEN_IDENTIFIER){
String lexeme = token_str(reader->text, token);
String_Const_char lexeme = token_str(reader->text, token);
*str_out = lexeme;
success = true;
if (opt_pos_out != 0){
@ -422,13 +424,13 @@ extract_identifier(Reader *reader, String *str_out, int32_t *opt_pos_out = 0){
return(success);
}
static bool32
extract_integer(Reader *reader, String *str_out, int32_t *opt_pos_out = 0){
bool32 success = false;
static b32
extract_integer(Reader *reader, String_Const_char *str_out, int32_t *opt_pos_out = 0){
b32 success = false;
Cpp_Token token = get_token(reader);
if (token.type == CPP_TOKEN_INTEGER_CONSTANT){
String lexeme = token_str(reader->text, token);
String_Const_char lexeme = token_str(reader->text, token);
*str_out = lexeme;
success = true;
if (opt_pos_out != 0){
@ -443,13 +445,13 @@ extract_integer(Reader *reader, String *str_out, int32_t *opt_pos_out = 0){
return(success);
}
static bool32
extract_string(Reader *reader, String *str_out, int32_t *opt_pos_out = 0){
bool32 success = false;
static b32
extract_string(Reader *reader, String_Const_char *str_out, int32_t *opt_pos_out = 0){
b32 success = false;
Cpp_Token token = get_token(reader);
if (token.type == CPP_TOKEN_STRING_CONSTANT){
String lexeme = token_str(reader->text, token);
String_Const_char lexeme = token_str(reader->text, token);
*str_out = lexeme;
success = true;
if (opt_pos_out != 0){
@ -464,12 +466,12 @@ extract_string(Reader *reader, String *str_out, int32_t *opt_pos_out = 0){
return(success);
}
static bool32
parse_documented_command(Partition *part, Meta_Command_Entry_Arrays *arrays, Reader *reader){
String name = {};
String file_name = {};
String line_number = {};
String doc = {};
static b32
parse_documented_command(Arena *arena, Meta_Command_Entry_Arrays *arrays, Reader *reader){
String_Const_char name = {};
String_Const_char file_name = {};
String_Const_char line_number = {};
String_Const_char doc = {};
// Getting the command's name
int32_t start_pos = 0;
@ -533,27 +535,26 @@ parse_documented_command(Partition *part, Meta_Command_Entry_Arrays *arrays, Rea
return(false);
}
doc = substr(doc, 1, doc.size - 2);
doc = string_chop(string_skip(doc, 1), 1);
char *source_name = push_array(part, char, file_name.size + 1);
push_align(part, 8);
string_interpret_escapes(substr(file_name, 1, file_name.size - 2), source_name);
String_Const_char file_name_unquoted = string_chop(string_skip(file_name, 1), 1);
String_Const_char source_name = string_interpret_escapes(arena, file_name_unquoted);
Meta_Command_Entry *new_entry = push_array(part, Meta_Command_Entry, 1);
Meta_Command_Entry *new_entry = push_array(arena, Meta_Command_Entry, 1);
new_entry->name = name;
new_entry->source_name = source_name;
new_entry->line_number = str_to_int(line_number);
new_entry->source_name = source_name.str;
new_entry->line_number = (i32)string_to_integer(line_number, 10);
new_entry->docstring.doc = doc;
sll_push(arrays->first_doc_string, arrays->last_doc_string, new_entry);
sll_queue_push(arrays->first_doc_string, arrays->last_doc_string, new_entry);
++arrays->doc_string_count;
return(true);
}
static bool32
parse_alias(Partition *part, Meta_Command_Entry_Arrays *arrays, Reader *reader){
String name = {};
String potential = {};
static b32
parse_alias(Arena *arena, Meta_Command_Entry_Arrays *arrays, Reader *reader){
String_Const_char name = {};
String_Const_char potential = {};
// Getting the alias's name
int32_t start_pos = 0;
@ -582,12 +583,12 @@ parse_alias(Partition *part, Meta_Command_Entry_Arrays *arrays, Reader *reader){
return(false);
}
Meta_Command_Entry *new_entry = push_array(part, Meta_Command_Entry, 1);
Meta_Command_Entry *new_entry = push_array(arena, Meta_Command_Entry, 1);
new_entry->name = name;
new_entry->source_name = reader->source_name;
new_entry->line_number = line_number(reader, start_pos);
new_entry->alias.potential = potential;
sll_push(arrays->first_alias, arrays->last_alias, new_entry);
sll_queue_push(arrays->first_alias, arrays->last_alias, new_entry);
++arrays->alias_count;
return(true);
@ -596,9 +597,9 @@ parse_alias(Partition *part, Meta_Command_Entry_Arrays *arrays, Reader *reader){
///////////////////////////////
static void
parse_text(Partition *part, Meta_Command_Entry_Arrays *entry_arrays, char *source_name, String text){
parse_text(Arena *arena, Meta_Command_Entry_Arrays *entry_arrays, char *source_name, String_Const_char text){
Cpp_Token_Array array = cpp_make_token_array(1024);
cpp_lex_file(text.str, text.size, &array);
cpp_lex_file(text.str, (i32)text.size, &array);
Reader reader_ = make_reader(array, source_name, text);
Reader *reader = &reader_;
@ -607,19 +608,19 @@ parse_text(Partition *part, Meta_Command_Entry_Arrays *entry_arrays, char *sourc
Cpp_Token token = get_token(reader);
if (token.type == CPP_TOKEN_IDENTIFIER){
String lexeme = token_str(text, token);
String_Const_char lexeme = token_str(text, token);
bool32 in_preproc_body = ((token.flags & CPP_TFLAG_PP_BODY) != 0);
b32 in_preproc_body = ((token.flags & CPP_TFLAG_PP_BODY) != 0);
if (!in_preproc_body && match(lexeme, "CUSTOM_DOC")){
if (!in_preproc_body && string_match(lexeme, string_litexpr("CUSTOM_DOC"))){
Temp_Read temp_read = begin_temp_read(reader);
bool32 found_start_pos = false;
b32 found_start_pos = false;
for (int32_t R = 0; R < 10; ++R){
Cpp_Token p_token = prev_token(reader);
if (p_token.type == CPP_TOKEN_IDENTIFIER){
String p_lexeme = token_str(text, p_token);
if (match(p_lexeme, "CUSTOM_COMMAND_SIG")){
String_Const_char p_lexeme = token_str(text, p_token);
if (string_match(p_lexeme, string_litexpr("CUSTOM_COMMAND_SIG"))){
found_start_pos = true;
break;
}
@ -633,15 +634,15 @@ parse_text(Partition *part, Meta_Command_Entry_Arrays *entry_arrays, char *sourc
end_temp_read(temp_read);
}
else{
if (!parse_documented_command(part, entry_arrays, reader)){
if (!parse_documented_command(arena, entry_arrays, reader)){
end_temp_read(temp_read);
}
}
}
else if (match(lexeme, "CUSTOM_ALIAS")){
else if (string_match(lexeme, string_litexpr("CUSTOM_ALIAS"))){
Temp_Read temp_read = begin_temp_read(reader);
bool32 found_start_pos = false;
b32 found_start_pos = false;
for (int32_t R = 0; R < 3; ++R){
Cpp_Token p_token = prev_token(reader);
if (p_token.type == CPP_PP_DEFINE){
@ -659,7 +660,7 @@ parse_text(Partition *part, Meta_Command_Entry_Arrays *entry_arrays, char *sourc
end_temp_read(temp_read);
}
else{
if (!parse_alias(part, entry_arrays, reader)){
if (!parse_alias(arena, entry_arrays, reader)){
end_temp_read(temp_read);
}
}
@ -675,8 +676,8 @@ parse_text(Partition *part, Meta_Command_Entry_Arrays *entry_arrays, char *sourc
}
static void
parse_file(Partition *part, Meta_Command_Entry_Arrays *entry_arrays, Filename_Character *name_, int32_t len){
char *name = unencode(part, name_, len);
parse_file(Arena *arena, Meta_Command_Entry_Arrays *entry_arrays, Filename_Character *name_, int32_t len){
char *name = unencode(arena, name_, len);
if (name == 0){
if (sizeof(*name_) == 2){
fprintf(stdout, "warning: could not unencode file name %ls - file skipped\n", (wchar_t*)name_);
@ -687,17 +688,23 @@ parse_file(Partition *part, Meta_Command_Entry_Arrays *entry_arrays, Filename_Ch
return;
}
String text = file_dump(part, name);
parse_text(part, entry_arrays, name, text);
String_Const_char text = file_dump(arena, name);
parse_text(arena, entry_arrays, name, text);
}
static void
parse_files_by_pattern(Partition *part, Meta_Command_Entry_Arrays *entry_arrays, Filename_Character *pattern, bool32 recursive){
Cross_Platform_File_List list = get_file_list(part, pattern, filter_all);
parse_files_by_pattern(Arena *arena, Meta_Command_Entry_Arrays *entry_arrays, Filename_Character *pattern, b32 recursive){
Cross_Platform_File_List list = get_file_list(arena, pattern, filter_all);
for (int32_t i = 0; i < list.count; ++i){
Cross_Platform_File_Info *info = &list.info[i];
if (info->is_folder && match(make_string(info->name, info->len), "4coder_generated")){
String_Const_Any info_name = SCany(info->name, info->len);
Temp_Memory temp = begin_temp(arena);
String_Const_char info_name_ascii = string_char_from_any(arena, info_name);
b32 is_generated = string_match(info_name_ascii, string_litexpr("4coder_generated"));
end_temp(temp);
if (info->is_folder && is_generated){
continue;
}
if (!recursive && info->is_folder){
@ -708,8 +715,7 @@ parse_files_by_pattern(Partition *part, Meta_Command_Entry_Arrays *entry_arrays,
if (info->is_folder){
full_name_len += 2;
}
Filename_Character *full_name = push_array(part, Filename_Character, full_name_len + 1);
push_align(part, 8);
Filename_Character *full_name = push_array(arena, Filename_Character, full_name_len + 1);
if (full_name == 0){
fprintf(stdout, "fatal error: not enough memory to recurse to sub directory\n");
@ -722,12 +728,12 @@ parse_files_by_pattern(Partition *part, Meta_Command_Entry_Arrays *entry_arrays,
full_name[full_name_len] = 0;
if (!info->is_folder){
parse_file(part, entry_arrays, full_name, full_name_len);
parse_file(arena, entry_arrays, full_name, full_name_len);
}
else{
full_name[full_name_len - 2] = SLASH;
full_name[full_name_len - 1] = '*';
parse_files_by_pattern(part, entry_arrays, full_name, true);
parse_files_by_pattern(arena, entry_arrays, full_name, true);
}
}
}
@ -748,15 +754,13 @@ main(int argc, char **argv){
show_usage(argc, argv);
}
bool32 recursive = match(argv[1], "-R");
b32 recursive = string_match(SCchar(argv[1]), string_litexpr("-R"));
if (recursive && argc < 4){
show_usage(argc, argv);
}
int32_t size = (256 << 20);
void *mem = malloc(size);
Partition part_ = make_part(mem, size);
Partition *part = &part_;
Arena arena_ = make_arena_malloc(MB(1), 8);
Arena *arena = &arena_;
char *out_directory = argv[2];
@ -767,24 +771,24 @@ main(int argc, char **argv){
Meta_Command_Entry_Arrays entry_arrays = {};
for (int32_t i = start_i; i < argc; ++i){
Filename_Character *pattern_name = encode(part, argv[i]);
parse_files_by_pattern(part, &entry_arrays, pattern_name, recursive);
Filename_Character *pattern_name = encode(arena, argv[i]);
parse_files_by_pattern(arena, &entry_arrays, pattern_name, recursive);
}
int32_t out_dir_len = str_size(out_directory);
umem out_dir_len = cstring_length(out_directory);
if (out_directory[0] == '"'){
out_directory += 1;
out_dir_len -= 2;
}
{
String str = make_string(out_directory, out_dir_len);
str = skip_chop_whitespace(str);
String_Const_char str = SCchar(out_directory, out_dir_len);
str = string_skip_chop_whitespace(str);
out_directory = str.str;
out_dir_len = str.size;
}
int32_t len = out_dir_len + 1 + sizeof(COMMAND_METADATA_OUT) - 1;
umem len = out_dir_len + 1 + sizeof(COMMAND_METADATA_OUT) - 1;
char *out_file_name = (char*)malloc(len + 1);
memcpy(out_file_name, out_directory, out_dir_len);
memcpy(out_file_name + out_dir_len, "/", 1);
@ -794,7 +798,7 @@ main(int argc, char **argv){
if (out != 0){
int32_t entry_count = entry_arrays.doc_string_count;
Meta_Command_Entry **entries = get_sorted_meta_commands(part, entry_arrays.first_doc_string, entry_count);
Meta_Command_Entry **entries = get_sorted_meta_commands(arena, entry_arrays.first_doc_string, entry_count);
fprintf(out, "#if !defined(META_PASS)\n");
fprintf(out, "#define command_id(c) (fcoder_metacmd_ID_##c)\n");
@ -832,26 +836,23 @@ main(int argc, char **argv){
for (int32_t i = 0; i < entry_count; ++i){
Meta_Command_Entry *entry = entries[i];
Temp_Memory temp = begin_temp_memory(part);
Temp_Memory temp = begin_temp(arena);
// HACK(allen): We could just get these at the HEAD END of the process,
// then we only have to do it once per file, and pass the lengths through.
int32_t source_name_len = str_size(entry->source_name);
char *fixed_name = push_array(part, char, source_name_len*2 + 1);
String s = make_string_cap(fixed_name, 0, source_name_len*2 + 1);
copy(&s, entry->source_name);
int32_t unescaped_size = s.size;
replace_str(&s, "\\", "\\\\");
terminate_with_null(&s);
//umem source_name_len = cstring_length(entry->source_name);
String_Const_char source_name = SCchar(entry->source_name);
String_Const_char printable = string_replace(arena, source_name,
SCchar("\\"), SCchar("\\\\"),
StringFill_NullTerminate);
fprintf(out,
"{ PROC_LINKS(%.*s, 0), \"%.*s\", %d, \"%.*s\", %d, \"%s\", %d, %d },\n",
str_to_l_c(entry->name),
str_to_l_c(entry->name), entry->name.size,
str_to_l_c(entry->docstring.doc), entry->docstring.doc.size,
s.str, unescaped_size, entry->line_number);
end_temp_memory(temp);
str_to_l_c(entry->name), (i32)entry->name.size,
str_to_l_c(entry->docstring.doc), (i32)entry->docstring.doc.size,
printable.str, (i32)source_name.size, entry->line_number);
end_temp(temp);
}
fprintf(out, "};\n");

View File

@ -5,29 +5,23 @@ and decrementing various forms of number as numerical objects despite being enco
// TOP
static i32
get_numeric_string_at_cursor(Application_Links *app, Buffer_ID buffer, i32 start_pos, i32 *numeric_start, i32 *numeric_end){
i32 result = 0;
static Range
get_numeric_string_at_cursor(Application_Links *app, Buffer_ID buffer, i32 start_pos){
Range result = {};
char current = buffer_get_char(app, buffer, start_pos);
if (char_is_numeric(current)){
if (character_is_base10(current)){
char chunk[1024];
i32 chunk_size = sizeof(chunk);
Stream_Chunk stream = {};
i32 pos = start_pos;
i32 pos1 = 0;
i32 pos2 = 0;
if (init_stream_chunk(&stream, app, buffer, start_pos, chunk, chunk_size)){
b32 still_looping = true;
for (;still_looping;){
for (; pos >= stream.start; --pos){
char at_pos = stream.data[pos];
if (!char_is_numeric(at_pos)){
if (!character_is_base10(at_pos)){
++pos;
goto double_break_1;
}
@ -35,25 +29,23 @@ get_numeric_string_at_cursor(Application_Links *app, Buffer_ID buffer, i32 start
still_looping = backward_stream_chunk(&stream);
}
double_break_1:;
pos1 = pos;
i32 pos1 = pos;
if (init_stream_chunk(&stream, app, buffer, start_pos, chunk, chunk_size)){
still_looping = 1;
still_looping = true;
while (still_looping){
for (; pos < stream.end; ++pos){
char at_pos = stream.data[pos];
if (!char_is_numeric(at_pos)){
if (!character_is_base10(at_pos)){
goto double_break_2;
}
}
still_looping = forward_stream_chunk(&stream);
}
double_break_2:;
pos2 = pos;
i32 pos2 = pos;
result = 1;
*numeric_start = pos1;
*numeric_end = pos2;
result = make_range(pos1, pos2);
}
}
}
@ -61,6 +53,19 @@ get_numeric_string_at_cursor(Application_Links *app, Buffer_ID buffer, i32 start
return(result);
}
#if 0
static b32
get_numeric_string_at_cursor(Application_Links *app, Buffer_ID buffer, i32 start_pos, i32 *numeric_start, i32 *numeric_end){
Range range = get_numeric_string_at_cursor(app, buffer, start_pos);
b32 result = (range_size(range) > 0);
if (result){
*numeric_start = range.start;
*numeric_end = range.end;
}
return(result);
}
#endif
struct Miblo_Number_Info{
union{
Range range;
@ -70,27 +75,20 @@ struct Miblo_Number_Info{
i32 x;
};
static i32
static b32
get_numeric_at_cursor(Application_Links *app, Buffer_ID buffer, i32 pos, Miblo_Number_Info *info){
i32 result = 0;
i32 numeric_start = 0, numeric_end = 0;
if (get_numeric_string_at_cursor(app, buffer, pos, &numeric_start, &numeric_end)){
char numeric_string[1024];
String str = make_string(numeric_string, numeric_end - numeric_start, sizeof(numeric_string));
if (str.size < str.memory_size){
buffer_read_range(app, buffer, numeric_start, numeric_end, numeric_string);
i32 x = str_to_int(str);
int_to_str(&str, x+1);
info->start = numeric_start;
info->end = numeric_end;
b32 result = false;
Range range = get_numeric_string_at_cursor(app, buffer, pos);
if (range_size(range) > 0){
Scratch_Block scratch(app);
String_Const_u8 str = scratch_read(app, scratch, buffer, range);
if (str.size > 0){
i32 x = (i32)string_to_integer(str, 10);
info->range = range;
info->x = x;
result = 1;
result = true;
}
}
return(result);
}
@ -105,11 +103,10 @@ CUSTOM_DOC("Increment an integer under the cursor by one.")
view_get_cursor_pos(app, view, &pos);
Miblo_Number_Info number = {};
if (get_numeric_at_cursor(app, buffer, pos, &number)){
char str_space[1024];
String str = make_fixed_width_string(str_space);
int_to_str(&str, number.x + 1);
Scratch_Block scratch(app);
String_Const_u8 str = string_u8_pushf(scratch, "%d", number.x + 1);
buffer_replace_range(app, buffer, number.range, str);
view_set_cursor(app, view, seek_pos(number.start + str.size - 1), true);
view_set_cursor(app, view, seek_pos(number.start + (i32)str.size - 1), true);
}
}
@ -124,24 +121,23 @@ CUSTOM_DOC("Decrement an integer under the cursor by one.")
view_get_cursor_pos(app, view, &pos);
Miblo_Number_Info number = {};
if (get_numeric_at_cursor(app, buffer, pos, &number)){
char str_space[1024];
String str = make_fixed_width_string(str_space);
int_to_str(&str, number.x - 1);
Scratch_Block scratch(app);
String_Const_u8 str = string_u8_pushf(scratch, "%d", number.x - 1);
buffer_replace_range(app, buffer, number.range, str);
view_set_cursor(app, view, seek_pos(number.start + str.size - 1), true);
view_set_cursor(app, view, seek_pos(number.start + (i32)str.size - 1), true);
}
}
// NOTE(allen): miblo time stamp format
// (h+:)?m?m:ss
static i32
get_timestamp_string_at_cursor(Application_Links *app, Buffer_ID buffer, i32 start_pos, i32 *timestamp_start, i32 *timestamp_end){
i32 result = 0;
static Range
get_timestamp_string_at_cursor(Application_Links *app, Buffer_ID buffer, i32 start_pos){
Range result = {};
char current = buffer_get_char(app, buffer, start_pos);
if (char_is_numeric(current) || current == ':'){
if (character_is_base10(current) || current == ':'){
char chunk[1024];
i32 chunk_size = sizeof(chunk);
Stream_Chunk stream = {};
@ -152,12 +148,11 @@ get_timestamp_string_at_cursor(Application_Links *app, Buffer_ID buffer, i32 sta
i32 pos2 = 0;
if (init_stream_chunk(&stream, app, buffer, start_pos, chunk, chunk_size)){
i32 still_looping = 1;
b32 still_looping = true;
while (still_looping){
for (; pos >= stream.start; --pos){
char at_pos = stream.data[pos];
if (!(char_is_numeric(at_pos) || at_pos == ':')){
if (!(character_is_base10(at_pos) || at_pos == ':')){
++pos;
goto double_break_1;
}
@ -168,12 +163,11 @@ get_timestamp_string_at_cursor(Application_Links *app, Buffer_ID buffer, i32 sta
pos1 = pos;
if (init_stream_chunk(&stream, app, buffer, start_pos, chunk, chunk_size)){
still_looping = 1;
still_looping = true;
while (still_looping){
for (; pos < stream.end; ++pos){
char at_pos = stream.data[pos];
if (!(char_is_numeric(at_pos) || at_pos == ':')){
if (!(character_is_base10(at_pos) || at_pos == ':')){
goto double_break_2;
}
}
@ -182,9 +176,7 @@ get_timestamp_string_at_cursor(Application_Links *app, Buffer_ID buffer, i32 sta
double_break_2:;
pos2 = pos;
result = 1;
*timestamp_start = pos1;
*timestamp_end = pos2;
result = make_range(pos1, pos2);
}
}
}
@ -192,6 +184,16 @@ get_timestamp_string_at_cursor(Application_Links *app, Buffer_ID buffer, i32 sta
return(result);
}
#if 0
static b32
get_timestamp_string_at_cursor(Application_Links *app, Buffer_ID buffer, i32 start_pos, i32 *timestamp_start, i32 *timestamp_end){
Range range = get_timestamp_string_at_cursor(app, buffer, start_pos);
*timestamp_start = range.start;
*timestamp_end = range.end;
return(range_size(range) > 0);
}
#endif
struct Miblo_Timestamp{
i32 second;
i32 minute;
@ -253,34 +255,18 @@ increment_timestamp(Miblo_Timestamp t, i32 type, i32 amt){
return(r);
}
static void
timestamp_to_str(String *dest, Miblo_Timestamp t){
dest->size = 0;
static String_Const_u8
timestamp_to_string(Arena *arena, Miblo_Timestamp t){
List_String_Const_u8 list = {};
if (t.hour > 0){
append_int_to_str(dest, t.hour);
append(dest, ":");
}
if (t.minute >= 10){
append_int_to_str(dest, t.minute);
}
else if (t.hour > 0){
append(dest, "0");
append_int_to_str(dest, t.minute);
}
else{
append_int_to_str(dest, t.minute);
}
append(dest, ":");
if (t.second >= 10){
append_int_to_str(dest, t.second);
}
else{
append(dest, "0");
append_int_to_str(dest, t.second);
string_list_pushf(arena, &list, "%d:", t.hour);
}
i32 minute = clamp_bot(0, t.minute);
string_list_pushf(arena, &list, "%02d:", minute);
i32 second = clamp_bot(0, t.second);
string_list_pushf(arena, &list, "%02d", second);
String_Const_u8 str = string_list_flatten(arena, list);
return(str);
}
struct Miblo_Timestamp_Info{
@ -292,76 +278,81 @@ struct Miblo_Timestamp_Info{
Miblo_Timestamp time;
};
static i32
static b32
get_timestamp_at_cursor(Application_Links *app, Buffer_ID buffer, i32 pos, Miblo_Timestamp_Info *info){
i32 result = 0;
b32 result = false;
i32 timestamp_start = 0, timestamp_end = 0;
if (get_timestamp_string_at_cursor(app, buffer, pos, &timestamp_start, &timestamp_end)){
char timestamp_string[1024];
String str = make_string(timestamp_string, timestamp_end - timestamp_start, sizeof(timestamp_string));
if (str.size < str.memory_size){
buffer_read_range(app, buffer, timestamp_start, timestamp_end, timestamp_string);
Scratch_Block scratch(app);
Range time_stamp_range = get_timestamp_string_at_cursor(app, buffer, pos);
if (range_size(time_stamp_range) > 0){
String_Const_u8 string = scratch_read(app, scratch, buffer, time_stamp_range);
if (string.size > 0){
i32 count_colons = 0;
for (i32 i = 0; i < str.size; ++i){
if (str.str[i] == ':'){
++count_colons;
for (umem i = 0; i < string.size; ++i){
if (string.str[i] == ':'){
count_colons += 1;
}
}
if (count_colons == 1 || count_colons == 2){
Miblo_Timestamp t = {};
i32 success = 0;
b32 success = false;
i32 i = 0;
i32 number_start[3], number_end[3];
umem i = 0;
umem number_start[3];
umem number_end[3];
for (i32 k = 0; k < 3; ++k){
number_start[k] = i;
for (; i <= str.size; ++i){
if (i == str.size || str.str[i] == ':'){
for (; i <= string.size; ++i){
if (i == string.size || string.str[i] == ':'){
number_end[k] = i;
break;
}
}
++i;
if (i >= timestamp_end){
if (i >= time_stamp_range.one_past_last){
break;
}
}
if (count_colons == 2){
t.hour = str_to_int(make_string(str.str + number_start[0], number_end[0] - number_start[0]));
String_Const_u8 hour_str = SCu8(string.str + number_start[0],
string.str + number_end[0]);
t.hour = (i32)string_to_integer(hour_str, 10);
if (number_end[1] - number_start[1] == 2){
t.minute = str_to_int(make_string(str.str + number_start[1], number_end[1] - number_start[1]));
String_Const_u8 minute_str = SCu8(string.str + number_start[1],
string.str + number_end[1]);
t.minute = (i32)string_to_integer(minute_str, 10);
if (number_end[2] - number_start[2] == 2){
t.second = str_to_int(make_string(str.str + number_start[2], number_end[2] - number_start[2]));
success = 1;
String_Const_u8 second_str = SCu8(string.str + number_start[2],
string.str + number_end[2]);
t.second = (i32)string_to_integer(second_str, 10);
success = true;
}
}
}
else{
if (number_end[0] - number_start[0] == 2 || number_end[0] - number_start[0] == 1){
t.minute = str_to_int(make_string(str.str + number_start[0], number_end[0] - number_start[0]));
String_Const_u8 minute_str = SCu8(string.str + number_start[0],
string.str + number_end[0]);
t.minute = (i32)string_to_integer(minute_str, 10);
if (number_end[1] - number_start[1] == 2){
t.second = str_to_int(make_string(str.str + number_start[1], number_end[1] - number_start[1]));
success = 1;
String_Const_u8 second_str = SCu8(string.str + number_start[2],
string.str + number_end[2]);
t.second = (i32)string_to_integer(second_str, 10);
success = true;
}
}
}
if (success){
info->start = timestamp_start;
info->end = timestamp_end;
info->range = time_stamp_range;
info->time = t;
result = 1;
result = true;
}
}
}
@ -381,13 +372,11 @@ miblo_time_stamp_alter(Application_Links *app, i32 unit_type, i32 amt){
Miblo_Timestamp_Info timestamp = {};
if (get_timestamp_at_cursor(app, buffer, pos, &timestamp)){
char str_space[1024];
String str = make_fixed_width_string(str_space);
Scratch_Block scratch(app);
Miblo_Timestamp inc_timestamp = increment_timestamp(timestamp.time, unit_type, amt);
timestamp_to_str(&str, inc_timestamp);
String_Const_u8 str = timestamp_to_string(scratch, inc_timestamp);
buffer_replace_range(app, buffer, timestamp.range, str);
view_set_cursor(app, view, seek_pos(timestamp.start + str.size - 1), true);
view_set_cursor(app, view, seek_pos(timestamp.start + (i32)str.size - 1), true);
}
}

View File

@ -1,62 +0,0 @@
/*
* Mr. 4th Dimention - Allen Webster
*
* 31.03.2017
*
* OS & Compiler cracking for 4coder
*
*/
// TOP
#if !defined(FCODER_OS_COMP_CRACKING_H)
#define FCODER_OS_COMP_CRACKING_H
#if defined(_MSC_VER) /* COMPILER */
# define IS_CL
// NOTE(allen): I suspect snprintf is defined in VS 2015 (I test on 2017)
#if _MSC_VER <= 1800
# define snprintf _snprintf
#endif
# if defined(_WIN32) /* OS */
# define IS_WINDOWS
# pragma comment(lib, "Kernel32.lib")
# else
# error This compiler/platform combo is not supported yet
# endif
# if defined(_M_AMD64) /* Architecture */
# define CALL_CONVENTION
# define BUILD_X64
# elif defined(_M_IX86)
# define CALL_CONVENTION __stdcall
# define BUILD_X86
# else
# error architecture not supported yet
# endif
#elif defined(__GNUC__) || defined(__GNUG__)
# define IS_GCC /* COMPILER */
# if defined(__gnu_linux__) /* OS */
# define IS_LINUX
# define CALL_CONVENTION
# elif defined(__APPLE__) && defined(__MACH__) /* OS */
# define IS_MAC
# define CALL_CONVENTION
#else
# error This compiler/platform combo is not supported yet
# endif
#else
# error This compiler is not supported yet
#endif
#endif
// BOTTOM

File diff suppressed because it is too large Load Diff

View File

@ -14,7 +14,7 @@ enum{
///////////////////////////////
struct Project_File_Pattern{
Absolutes absolutes;
List_String_Const_u8 absolutes;
};
struct Project_File_Pattern_Array{
@ -23,7 +23,7 @@ struct Project_File_Pattern_Array{
};
struct Project_File_Load_Path{
String path;
String_Const_u8 path;
b32 recursive;
b32 relative;
};
@ -34,9 +34,9 @@ struct Project_File_Load_Path_Array{
};
struct Project_Command{
String name;
String cmd;
String out;
String_Const_u8 name;
String_Const_u8 cmd;
String_Const_u8 out;
b32 footer_panel;
b32 save_dirty_files;
b32 cursor_at_end;
@ -50,8 +50,8 @@ struct Project_Command_Array{
struct Project{
b32 loaded;
String dir;
String name;
String_Const_u8 dir;
String_Const_u8 name;
Project_File_Pattern_Array pattern_array;
Project_File_Pattern_Array blacklist_pattern_array;
@ -84,10 +84,10 @@ struct Project_Setup_Status{
struct Project_Key_Strings{
b32 success;
String script_file;
String code_file;
String output_dir;
String binary_file;
String_Const_u8 script_file;
String_Const_u8 code_file;
String_Const_u8 output_dir;
String_Const_u8 binary_file;
};
#endif

View File

@ -30,60 +30,50 @@ mac_default_keys(Bind_Helper *context){
//
static Bind_Helper
get_context_on_global_part(void){
get_context_on_arena(Arena *arena){
Bind_Helper result = {};
i32 size = (1 << 20);
for (;;){
void *data = push_array(&global_part, char, size);
if (data != 0){
result = begin_bind_helper(data, size);
break;
}
size = (size >> 1);
}
result = begin_bind_helper(push_array(arena, char, MB(1)), MB(1));
return(result);
}
CUSTOM_COMMAND_SIG(set_bindings_choose)
CUSTOM_DOC("Remap keybindings using the 'choose' mapping rule.")
{
#if defined(IS_WINDOWS) || defined(IS_LINUX)
#if OS_WINDOWS || OS_LINUX
set_bindings_default(app);
#elif defined(IS_MAC)
#elif OS_MAC
set_bindings_mac_default(app);
#endif
}
CUSTOM_COMMAND_SIG(set_bindings_default)
CUSTOM_DOC("Remap keybindings using the 'default' mapping rule.")
{
Temp_Memory temp = begin_temp_memory(&global_part);
Arena *scratch = context_get_arena(app);
Temp_Memory temp = begin_temp(scratch);
Bind_Helper context = get_context_on_global_part();
Bind_Helper context = get_context_on_arena(scratch);
set_all_default_hooks(&context);
default_keys(&context);
Bind_Buffer result = end_bind_helper_get_buffer(&context);
global_set_mapping(app, result.data, result.size);
end_temp_memory(temp);
end_temp(temp);
}
CUSTOM_COMMAND_SIG(set_bindings_mac_default)
CUSTOM_DOC("Remap keybindings using the 'mac-default' mapping rule.")
{
Temp_Memory temp = begin_temp_memory(&global_part);
Arena *scratch = context_get_arena(app);
Temp_Memory temp = begin_temp(scratch);
Bind_Helper context = get_context_on_global_part();
Bind_Helper context = get_context_on_arena(scratch);
set_all_default_hooks(&context);
mac_default_keys(&context);
Bind_Buffer result = end_bind_helper_get_buffer(&context);
global_set_mapping(app, result.data, result.size);
end_temp_memory(temp);
end_temp(temp);
}
#endif

View File

@ -399,7 +399,7 @@ CUSTOM_DOC("Finds the first scope started by '{' before the cursor and puts the
}
static void
place_begin_and_end_on_own_lines(Application_Links *app, Partition *scratch, char *begin, char *end){
place_begin_and_end_on_own_lines(Application_Links *app, char *begin, char *end){
View_ID view = 0;
get_active_view(app, AccessOpen, &view);
Buffer_ID buffer = 0;
@ -412,82 +412,73 @@ place_begin_and_end_on_own_lines(Application_Links *app, Partition *scratch, cha
range.min = buffer_get_line_start(app, buffer, lines.min);
range.max = buffer_get_line_end(app, buffer, lines.max);
b32 do_full = (lines.min < lines.max) || (!buffer_line_is_blank(app, buffer, lines.min));
Arena *scratch = context_get_arena(app);
Temp_Memory temp = begin_temp(scratch);
Temp_Memory temp = begin_temp_memory(scratch);
i32 begin_len = str_size(begin);
i32 end_len = str_size(end);
b32 min_line_blank = buffer_line_is_blank(app, buffer, lines.min);
b32 max_line_blank = buffer_line_is_blank(app, buffer, lines.max);
i32 str_size = begin_len + end_len + 2;
char *str = push_array(scratch, char, str_size);
String builder = make_string_cap(str, 0, str_size);
append(&builder, begin);
append(&builder, "\n");
append(&builder, "\n");
append(&builder, end);
if (do_full){
Buffer_Edit edits[2];
if ((lines.min < lines.max) || (!min_line_blank)){
String_Const_u8 begin_str = {};
String_Const_u8 end_str = {};
i32 min_adjustment = 0;
i32 max_adjustment = 4;
umem min_adjustment = 0;
umem max_adjustment = 0;
if (buffer_line_is_blank(app, buffer, lines.min)){
memmove(str + 1, str, begin_len);
str[0] = '\n';
++min_adjustment;
if (min_line_blank){
begin_str = string_u8_pushf(scratch, "\n%s", begin);
min_adjustment += 1;
}
else{
begin_str = string_u8_pushf(scratch, "%s\n", begin);
}
if (max_line_blank){
end_str = string_u8_pushf(scratch, "%s\n", end);
}
else{
end_str = string_u8_pushf(scratch, "\n%s", end);
max_adjustment += 1;
}
if (buffer_line_is_blank(app, buffer, lines.max)){
memmove(str + begin_len + 1, str + begin_len + 2, end_len);
str[begin_len + end_len + 1] = '\n';
--max_adjustment;
max_adjustment += begin_str.size;
Range new_pos = make_range(range.min + (i32)min_adjustment, range.max + (i32)max_adjustment);
i32 cursor_pos = 0;
i32 mark_pos = 0;
view_get_cursor_pos(app, view, &cursor_pos);
if (cursor_pos == range.min){
cursor_pos = new_pos.min;
mark_pos = new_pos.max;
}
else{
cursor_pos = new_pos.max;
mark_pos = new_pos.min;
}
i32 min_pos = range.min + min_adjustment;
i32 max_pos = range.max + max_adjustment;
i32 cursor_pos = min_pos;
i32 mark_pos = max_pos;
i32 view_cursor_pos = 0;
view_get_cursor_pos(app, view, &view_cursor_pos);
i32 view_mark_pos = 0;
view_get_mark_pos(app, view, &view_mark_pos);
if (view_cursor_pos > view_mark_pos){
cursor_pos = max_pos;
mark_pos = min_pos;
}
edits[0].str_start = 0;
edits[0].len = begin_len + 1;
edits[0].start = range.min;
edits[0].end = range.min;
edits[1].str_start = begin_len + 1;
edits[1].len = end_len + 1;
edits[1].start = range.max;
edits[1].end = range.max;
buffer_batch_edit(app, buffer, str, edits, 2);
History_Group group = begin_history_group(app, buffer);
buffer_replace_range(app, buffer, make_range(range.min), begin_str);
buffer_replace_range(app, buffer, make_range(range.max + (i32)begin_str.size), end_str);
end_history_group(group);
view_set_cursor(app, view, seek_pos(cursor_pos), true);
view_set_mark(app, view, seek_pos(mark_pos));
}
else{
buffer_replace_range(app, buffer, range, make_string(str, str_size));
i32 center_pos = range.min + begin_len + 1;
String_Const_u8 str = string_u8_pushf(scratch, "%s\n\n%s", begin, end);
buffer_replace_range(app, buffer, range, str);
i32 center_pos = range.min + (i32)cstring_length(begin) + 1;
view_set_cursor(app, view, seek_pos(center_pos), true);
view_set_mark(app, view, seek_pos(center_pos));
}
end_temp_memory(temp);
end_temp(temp);
}
CUSTOM_COMMAND_SIG(place_in_scope)
CUSTOM_DOC("Wraps the code contained in the range between cursor and mark with a new curly brace scope.")
{
place_begin_and_end_on_own_lines(app, &global_part, "{", "}");
place_begin_and_end_on_own_lines(app, "{", "}");
}
CUSTOM_COMMAND_SIG(delete_current_scope)
@ -548,7 +539,7 @@ parse_for_down(Application_Links *app, Statement_Parser *parser, Cpp_Token *toke
Cpp_Token *token = parser_next_token(parser);
i32 paren_level = 0;
while (token != 0){
for (;token != 0;){
if (!(token->flags & CPP_TFLAG_PP_BODY)){
switch (token->type){
case CPP_TOKEN_PARENTHESE_OPEN:
@ -570,7 +561,6 @@ parse_for_down(Application_Links *app, Statement_Parser *parser, Cpp_Token *toke
}break;
}
}
token = parser_next_token(parser);
}
@ -582,21 +572,15 @@ static b32
parse_if_down(Application_Links *app, Statement_Parser *parser, Cpp_Token *token_out){
b32 success = false;
Cpp_Token *token = parser_next_token(parser);
if (token != 0){
success = parse_statement_down(app, parser, token_out);
if (success){
token = parser_next_token(parser);
if (token != 0 && cpp_token_category_from_type(token->type) == CPP_TOKEN_CAT_CONTROL_FLOW){
char lexeme[32];
token_get_lexeme(app, parser->buffer, token, lexeme, sizeof(lexeme));
if (match(lexeme, "else")){
success = parse_statement_down(app, parser, token_out);
}
if (token != 0 && token->type == CPP_TOKEN_ELSE){
success = parse_statement_down(app, parser, token_out);
}
}
}
return(success);
}
@ -753,20 +737,15 @@ CUSTOM_DOC("If a scope is currently selected, and a statement or block statement
bottom = x;
}
Partition *part = &global_part;
Temp_Memory temp = begin_temp_memory(part);
if (buffer_get_char(app, buffer, top) == '{' && buffer_get_char(app, buffer, bottom - 1) == '}'){
Scratch_Block scratch(app);
Range range = {};
if (find_whole_statement_down(app, buffer, bottom, &range.start, &range.end)){
char *string_space = push_array(part, char, range.end - range.start);
buffer_read_range(app, buffer, range.start, range.end, string_space);
String string = make_string(string_space, range.end - range.start);
string = skip_chop_whitespace(string);
String_Const_u8 base_string = scratch_read(app, scratch, buffer, range);
String_Const_u8 string = string_skip_chop_whitespace(base_string);
i32 newline_count = 0;
for (char *ptr = string_space; ptr < string.str; ++ptr){
for (u8 *ptr = base_string.str; ptr < string.str; ++ptr){
if (*ptr == '\n'){
++newline_count;
}
@ -777,37 +756,26 @@ CUSTOM_DOC("If a scope is currently selected, and a statement or block statement
extra_newline = true;
}
i32 edit_len = string.size + 1;
String_Const_u8 edit_str = {};
if (extra_newline){
edit_len += 1;
}
char *edit_str = push_array(part, char, edit_len);
if (extra_newline){
edit_str[0] = '\n';
copy_fast_unsafe(edit_str+1, string);
edit_str[edit_len-1] = '\n';
edit_str = string_u8_pushf(scratch, "\n%.*s\n", string_expand(string));
}
else{
copy_fast_unsafe(edit_str, string);
edit_str[edit_len-1] = '\n';
edit_str = string_u8_pushf(scratch, "%.*s\n", string_expand(string));
}
Buffer_Edit edits[2];
edits[0].str_start = 0;
edits[0].len = edit_len;
edits[0].start = bottom-1;
edits[0].end = bottom-1;
edits[0].len = (i32)edit_str.size;
edits[0].start = bottom - 1;
edits[0].end = bottom - 1;
edits[1].str_start = 0;
edits[1].len = 0;
edits[1].start = range.start;
edits[1].end = range.end;
buffer_batch_edit(app, buffer, edit_str, edits, 2);
buffer_batch_edit(app, buffer, (char*)edit_str.str, edits, 2);
}
}
end_temp_memory(temp);
no_mark_snap_to_cursor(app, view);
}

View File

@ -10,14 +10,12 @@ and list all locations.
//
static void
search_key_alloc(Heap *heap, Search_Key *key, int32_t *size, int32_t count){
if (count > ArrayCount(key->words)){
count = ArrayCount(key->words);
}
search_key_alloc(Heap *heap, Search_Key *key, umem *size, i32 count){
count = clamp_top(count, ArrayCount(key->words));
int32_t min_size = 0x7FFFFFFF;
int32_t total_size = 0;
for (int32_t i = 0; i < count; ++i){
umem min_size = 0x7FFFFFFF;
umem total_size = 0;
for (i32 i = 0; i < count; ++i){
total_size += size[i];
if (min_size > size[i]){
min_size = size[i];
@ -25,22 +23,26 @@ search_key_alloc(Heap *heap, Search_Key *key, int32_t *size, int32_t count){
}
if (key->base == 0){
int32_t max_base_size = total_size*2;
key->base = heap_array(heap, char, max_base_size);
umem max_base_size = total_size*2;
key->base = heap_array(heap, u8, (i32)max_base_size);
key->base_size = max_base_size;
}
else if (key->base_size < total_size){
int32_t max_base_size = total_size*2;
umem max_base_size = total_size*2;
heap_free(heap, key->base);
key->base = heap_array(heap, char, max_base_size);
key->base = heap_array(heap, u8, (i32)max_base_size);
key->base_size = max_base_size;
}
char *char_ptr = key->base;
for (int32_t i = 0; i < count; ++i){
u8 *char_ptr = key->base;
for (i32 i = 0; i < count; ++i){
key->words[i].str = char_ptr;
key->words[i].size = 0;
#if 0
key->words[i].str = char_ptr;
key->words[i].size = 0;
key->words[i].memory_size = size[i];
#endif
char_ptr += size[i];
}
@ -56,14 +58,14 @@ search_iter_init(Search_Iter *iter, Search_Key key){
}
static void
search_set_init(Heap *heap, Search_Set *set, int32_t range_count){
search_set_init(Heap *heap, Search_Set *set, i32 range_count){
if (set->ranges == 0){
int32_t max = range_count*2;
i32 max = range_count*2;
set->ranges = heap_array(heap, Search_Range, max);
set->max = max;
}
else if (set->max < range_count){
int32_t max = range_count*2;
i32 max = range_count*2;
heap_free(heap, set->ranges);
set->ranges = heap_array(heap, Search_Range, max);
set->max = max;
@ -72,9 +74,9 @@ search_set_init(Heap *heap, Search_Set *set, int32_t range_count){
}
static void
search_hits_table_alloc(Heap *heap, Table *hits, int32_t table_size){
search_hits_table_alloc(Heap *heap, Table *hits, i32 table_size){
void *mem = 0;
int32_t mem_size = table_required_mem_size(table_size, sizeof(Offset_String));
i32 mem_size = table_required_mem_size(table_size, sizeof(Offset_String));
if (hits->hash_array == 0){
mem = heap_allocate(heap, mem_size);
}
@ -86,12 +88,12 @@ search_hits_table_alloc(Heap *heap, Table *hits, int32_t table_size){
}
static void
search_hits_init(Heap *heap, Table *hits, String_Space *str, int32_t table_size, int32_t str_size){
search_hits_init(Heap *heap, Table *hits, String_Space *str, i32 table_size, i32 str_size){
if (hits->hash_array == 0){
search_hits_table_alloc(heap, hits, table_size);
}
else{
int32_t mem_size = table_required_mem_size(table_size, sizeof(Offset_String));
i32 mem_size = table_required_mem_size(table_size, sizeof(Offset_String));
heap_free(heap, hits->hash_array);
void *mem = heap_allocate(heap, mem_size);
table_init_memory(hits, mem, table_size, sizeof(Offset_String));
@ -115,15 +117,13 @@ search_hits_init(Heap *heap, Table *hits, String_Space *str, int32_t table_size,
// Table Operations
//
static int32_t
search_hit_add(Heap *heap, Table *hits, String_Space *space, char *str, int32_t len){
int32_t result = false;
static b32
search_hit_add(Heap *heap, Table *hits, String_Space *space, char *str, i32 len){
b32 result = false;
Assert(len != 0);
Offset_String ostring = strspace_append(space, str, len);
if (ostring.size == 0){
int32_t new_size = space->max*2;
i32 new_size = space->max*2;
if (new_size < space->max + len){
new_size = space->max + len;
}
@ -156,12 +156,17 @@ search_hit_add(Heap *heap, Table *hits, String_Space *space, char *str, int32_t
return(result);
}
static b32
search_hit_add(Heap *heap, Table *hits, String_Space *space, String_Const_u8 string){
return(search_hit_add(heap, hits, space, (char*)string.str, (i32)string.size));
}
//
// Search Key Checking
//
static void
seek_potential_match(Application_Links *app, Search_Range *range, Search_Key key, Search_Match *result, Seek_Potential_Match_Direction direction, int32_t start_pos, int32_t end_pos){
seek_potential_match(Application_Links *app, Search_Range *range, Search_Key key, Search_Match *result, Seek_Potential_Match_Direction direction, i32 start_pos, i32 end_pos){
b32 case_insensitive = ((range->flags & SearchFlag_CaseInsensitive) != 0);
b32 forward = (direction == SeekPotentialMatch_Forward);
#define OptFlag(b,f) ((b)?(f):(0))
@ -170,15 +175,15 @@ seek_potential_match(Application_Links *app, Search_Range *range, Search_Key key
| OptFlag(!forward, BufferSeekString_Backward);
result->buffer = range->buffer;
int32_t best_pos = -1;
i32 best_pos = -1;
if (forward){
best_pos = end_pos;
}
for (int32_t i = 0; i < key.count; ++i){
String word = key.words[i];
int32_t new_pos = -1;
buffer_seek_string(app, result->buffer, start_pos, end_pos, range->start, word.str, word.size, &new_pos, flags);
for (i32 i = 0; i < key.count; ++i){
String_Const_u8 word = key.words[i];
i32 new_pos = -1;
buffer_seek_string(app, result->buffer, start_pos, end_pos, range->start, word, &new_pos, flags);
if (new_pos >= 0){
if (forward){
@ -198,15 +203,15 @@ seek_potential_match(Application_Links *app, Search_Range *range, Search_Key key
}
static i32
buffer_seek_alpha_numeric_end(Application_Links *app, Buffer_ID buffer_id, int32_t pos){
buffer_seek_alpha_numeric_end(Application_Links *app, Buffer_ID buffer_id, i32 pos){
char space[1024];
Stream_Chunk chunk = {};
if (init_stream_chunk(&chunk, app, buffer_id, pos, space, sizeof(space))){
int32_t still_looping = true;
i32 still_looping = true;
do{
for (; pos < chunk.end; ++pos){
u8 at_pos = (u8)chunk.data[pos];
if (!char_is_alpha_numeric_utf8(at_pos)) goto double_break;
if (!character_is_alpha_numeric_unicode(at_pos)) goto double_break;
}
still_looping = forward_stream_chunk(&chunk);
}while(still_looping);
@ -215,37 +220,37 @@ buffer_seek_alpha_numeric_end(Application_Links *app, Buffer_ID buffer_id, int32
return(pos);
}
static int32_t
match_check(Application_Links *app, Search_Range *range, int32_t *pos, Search_Match *result_ptr, Search_Key key){
int32_t result_code = FindResult_None;
static i32
match_check(Application_Links *app, Search_Range *range, i32 *pos, Search_Match *result_ptr, Search_Key key){
i32 result_code = FindResult_None;
Search_Match result = *result_ptr;
int32_t end_pos = range->start + range->size;
i32 end_pos = range->start + range->size;
int32_t type = (range->flags & SearchFlag_MatchMask);
i32 type = (range->flags & SearchFlag_MatchMask);
result.match_word_index = -1;
for (int32_t i = 0; i < key.count; ++i){
String word = key.words[i];
for (i32 i = 0; i < key.count; ++i){
String_Const_u8 word = key.words[i];
int32_t found_match = FindResult_None;
i32 found_match = FindResult_None;
switch (type){
case SearchFlag_MatchWholeWord:
{
char prev = ' ';
if (char_is_alpha_numeric_utf8(word.str[0])){
u8 prev = ' ';
if (character_is_alpha_numeric(string_get_character(word, 0))){
prev = buffer_get_char(app, result.buffer, result.start - 1);
}
if (!char_is_alpha_numeric_utf8(prev)){
result.end = result.start + word.size;
if (!character_is_alpha_numeric(prev)){
result.end = result.start + (i32)word.size;
if (result.end <= end_pos){
char next = ' ';
if (char_is_alpha_numeric_utf8(word.str[word.size-1])){
u8 next = ' ';
if (character_is_alpha_numeric_unicode(string_get_character(word, word.size - 1))){
next = buffer_get_char(app, result.buffer, result.end);
}
if (!char_is_alpha_numeric_utf8(next)){
if (!character_is_alpha_numeric_unicode(next)){
result.found_match = true;
found_match = FindResult_FoundMatch;
}
@ -258,8 +263,8 @@ match_check(Application_Links *app, Search_Range *range, int32_t *pos, Search_Ma
case SearchFlag_MatchWordPrefix:
{
char prev = buffer_get_char(app, result.buffer, result.start - 1);
if (!char_is_alpha_numeric_utf8(prev)){
u8 prev = buffer_get_char(app, result.buffer, result.start - 1);
if (!character_is_alpha_numeric_unicode(prev)){
result.end = buffer_seek_alpha_numeric_end(app, result.buffer, result.start);
if (result.end <= end_pos){
result.found_match = true;
@ -273,7 +278,7 @@ match_check(Application_Links *app, Search_Range *range, int32_t *pos, Search_Ma
case SearchFlag_MatchSubstring:
{
result.end = result.start + word.size;
result.end = result.start + (i32)word.size;
if (result.end <= end_pos){
result.found_match = true;
found_match = FindResult_FoundMatch;
@ -303,15 +308,15 @@ match_check(Application_Links *app, Search_Range *range, int32_t *pos, Search_Ma
// Find Next Match
//
static int32_t
search_front_to_back(Application_Links *app, Search_Range *range, Search_Key key, int32_t *pos, Search_Match *result){
int32_t found_match = FindResult_None;
static i32
search_front_to_back(Application_Links *app, Search_Range *range, Search_Key key, i32 *pos, Search_Match *result){
i32 found_match = FindResult_None;
for (;found_match == FindResult_None;){
found_match = FindResult_None;
int32_t end_pos = range->start + range->size;
i32 end_pos = range->start + range->size;
if (*pos + key.min_size < end_pos){
int32_t start_pos = *pos;
i32 start_pos = *pos;
if (start_pos < range->start){
start_pos = range->start;
}
@ -338,13 +343,13 @@ search_front_to_back(Application_Links *app, Search_Range *range, Search_Key key
return(found_match);
}
static int32_t
search_back_to_front(Application_Links *app, Search_Range *range, Search_Key key, int32_t *pos, Search_Match *result){
int32_t found_match = FindResult_None;
static i32
search_back_to_front(Application_Links *app, Search_Range *range, Search_Key key, i32 *pos, Search_Match *result){
i32 found_match = FindResult_None;
for (;found_match == FindResult_None;){
found_match = FindResult_None;
if (*pos > range->start){
int32_t start_pos = *pos;
i32 start_pos = *pos;
seek_potential_match(app, range, key, result, SeekPotentialMatch_Backward, start_pos, 0);
@ -352,7 +357,7 @@ search_back_to_front(Application_Links *app, Search_Range *range, Search_Key key
*pos = result->start - 1;
found_match = match_check(app, range, pos, result, key);
if (found_match == FindResult_FoundMatch){
*pos = result->start - key.words[result->match_word_index].size;
*pos = result->start - (i32)key.words[result->match_word_index].size;
}
}
else{
@ -379,11 +384,11 @@ search_next_match(Application_Links *app, Search_Set *set, Search_Iter *it_ptr){
Search_Match result = {};
Search_Iter iter = *it_ptr;
int32_t count = set->count;
i32 count = set->count;
for (;iter.i < count;){
Search_Range *range = set->ranges + iter.i;
int32_t find_result = FindResult_None;
i32 find_result = FindResult_None;
if (!iter.range_initialized){
iter.range_initialized = true;
@ -417,8 +422,8 @@ search_next_match(Application_Links *app, Search_Set *set, Search_Iter *it_ptr){
Search_Match forward_match = {};
Search_Match backward_match = {};
int32_t forward_result = FindResult_PastEnd;
int32_t backward_result = FindResult_PastEnd;
i32 forward_result = FindResult_PastEnd;
i32 backward_result = FindResult_PastEnd;
if (iter.pos < range->start + range->size){
forward_result = search_front_to_back(app, range, iter.key, &iter.pos, &forward_match);
@ -432,9 +437,9 @@ search_next_match(Application_Links *app, Search_Set *set, Search_Iter *it_ptr){
if (backward_result == FindResult_FoundMatch){
find_result = FindResult_FoundMatch;
int32_t forward_start = range->mid_start + range->mid_size;
int32_t forward_distance = (forward_match.start - forward_start);
int32_t backward_distance = (range->mid_start - backward_match.end);
i32 forward_start = range->mid_start + range->mid_size;
i32 forward_distance = (forward_match.start - forward_start);
i32 backward_distance = (range->mid_start - backward_match.end);
if (backward_distance < forward_distance){
iter.pos = forward_match.start;
@ -482,25 +487,23 @@ search_next_match(Application_Links *app, Search_Set *set, Search_Iter *it_ptr){
//
static void
initialize_generic_search_all_buffers(Application_Links *app, Heap *heap, String *strings, i32 count, Search_Range_Flag match_flags, Buffer_ID *skip_buffers, i32 skip_buffer_count, Search_Set *set, Search_Iter *iter){
memset(set, 0, sizeof(*set));
memset(iter, 0, sizeof(*iter));
initialize_generic_search_all_buffers(Application_Links *app, Heap *heap, String_Const_u8 *strings, i32 count, Search_Range_Flag match_flags, Buffer_ID *skip_buffers, i32 skip_buffer_count, Search_Set *set, Search_Iter *iter){
block_zero_struct(set);
block_zero_struct(iter);
Search_Key key = {};
i32 sizes[ArrayCount(key.words)];
memset(sizes, 0, sizeof(sizes));
if (count > ArrayCount(key.words)){
count = ArrayCount(key.words);
}
umem sizes[ArrayCount(key.words)] = {};
count = clamp_top(count, ArrayCount(key.words));
for (i32 i = 0; i < count; ++i){
sizes[i] = strings[i].size;
}
// TODO(allen): Why on earth am I allocating these separately in this case? Upgrade to just use the string array on the stack!
// NOTE(allen): ?? What did that TODO mean!?
search_key_alloc(heap, &key, sizes, count);
for (i32 i = 0; i < count; ++i){
copy(&key.words[i], strings[i]);
key.words[i].size = strings[i].size;
block_copy(key.words[i].str, strings[i].str, strings[i].size);
}
search_iter_init(iter, key);
@ -568,63 +571,14 @@ initialize_generic_search_all_buffers(Application_Links *app, Heap *heap, String
////////////////////////////////
static String search_name = make_lit_string("*search*");
// TODO(allen): can this get merged with the insertion stuff???
struct Buffered_Printing{
Partition *part;
Temp_Memory temp;
Buffer_ID buffer;
i32 pos;
};
static Buffered_Printing
make_buffered_print(Application_Links *app, Partition *part, Buffer_ID buffer){
Buffered_Printing buffered_print = {};
buffered_print.part = part;
buffered_print.temp = begin_temp_memory(part);
buffered_print.buffer = buffer;
buffer_get_size(app, buffer, &buffered_print.pos);
return(buffered_print);
}
static String_Const_u8 search_name = string_u8_litexpr("*search*");
static void
buffered_print_flush(Application_Links *app, Buffered_Printing *out){
i32 write_size = out->part->pos - out->temp.pos;
char *str = out->part->base + out->temp.pos;
buffer_replace_range(app, out->buffer, make_range(out->pos), make_string(str, write_size));
out->pos += write_size;
end_temp_memory(out->temp);
}
static char*
buffered_memory_reserve(Application_Links *app, Buffered_Printing *out, i32 length, b32 *did_flush){
char *mem = push_array(out->part, char, length);
*did_flush = false;
if (mem == 0){
buffered_print_flush(app, out);
mem = push_array(out->part, char, length);
*did_flush = true;
}
Assert(mem != 0);
return(mem);
}
static char*
buffered_memory_reserve(Application_Links *app, Buffered_Printing *out, i32 length){
b32 ignore;
return(buffered_memory_reserve(app, out, length, &ignore));
}
static i32
buffered_print_buffer_length(Buffered_Printing *out){
return(out->part->pos - out->temp.pos);
}
static void
list__parameters_buffer(Application_Links *app, Heap *heap, Partition *scratch,
String *strings, i32 count, Search_Range_Flag match_flags,
list__parameters_buffer(Application_Links *app, Heap *heap,
String_Const_u8 *strings, i32 count, Search_Range_Flag match_flags,
Buffer_ID search_buffer_id){
Arena *scratch = context_get_arena(app);
// Setup the search buffer for 'init' mode
buffer_set_setting(app, search_buffer_id, BufferSetting_ReadOnly, true);
buffer_set_setting(app, search_buffer_id, BufferSetting_RecordsHistory, false);
@ -635,11 +589,12 @@ list__parameters_buffer(Application_Links *app, Heap *heap, Partition *scratch,
initialize_generic_search_all_buffers(app, heap, strings, count, match_flags, &search_buffer_id, 1, &set, &iter);
// List all locations into search buffer
Temp_Memory all_temp = begin_temp_memory(scratch);
Partition line_part = part_sub_part(scratch, (4 << 10));
Temp_Memory all_temp = begin_temp(scratch);
// Setup buffered output
Buffered_Printing out = make_buffered_print(app, scratch, search_buffer_id);
Cursor buffering_cursor = make_cursor(push_array(scratch, u8, KB(64)), KB(64));
Buffer_Insertion out = begin_buffer_insertion_at_buffered(app, search_buffer_id, 0, &buffering_cursor);
Buffer_ID prev_match_id = 0;
b32 no_matches = true;
@ -650,71 +605,46 @@ list__parameters_buffer(Application_Links *app, Heap *heap, Partition *scratch,
if (buffer_compute_cursor(app, match.buffer, seek_pos(match.start), &word_pos)){
if (prev_match_id != match.buffer){
if (prev_match_id != 0){
char *newline = buffered_memory_reserve(app, &out, 1);
*newline = '\n';
insertc(&out, '\n');
}
prev_match_id = match.buffer;
}
char file_name_space[256];
String file_name = make_fixed_width_string(file_name_space);
buffer_get_file_name(app, match.buffer, &file_name, 0);
i32 line_num_len = int_to_str_size(word_pos.line);
i32 column_num_len = int_to_str_size(word_pos.character);
Temp_Memory line_temp = begin_temp_memory(&line_part);
Partial_Cursor line_start_cursor = {};
Partial_Cursor line_one_past_last_cursor = {};
String full_line_str = {};
if (read_line(app, &line_part, match.buffer, word_pos.line, &full_line_str, &line_start_cursor, &line_one_past_last_cursor)){
String line_str = skip_chop_whitespace(full_line_str);
i32 str_len = file_name.size + 1 + line_num_len + 1 + column_num_len + 1 + 1 + line_str.size + 1;
char *spare = buffered_memory_reserve(app, &out, str_len);
String out_line = make_string_cap(spare, 0, str_len);
append_ss(&out_line, file_name);
append_s_char(&out_line, ':');
append_int_to_str(&out_line, word_pos.line);
append_s_char(&out_line, ':');
append_int_to_str(&out_line, word_pos.character);
append_s_char(&out_line, ':');
append_s_char(&out_line, ' ');
append_ss(&out_line, line_str);
append_s_char(&out_line, '\n');
Assert(out_line.size == str_len);
Temp_Memory line_temp = begin_temp(scratch);
String_Const_u8 file_name = buffer_push_file_name(app, match.buffer, scratch);
String_Const_u8 full_line_str = scratch_read_line(app, scratch, match.buffer, word_pos.line);
if (full_line_str.size > 0){
String_Const_u8 line_str = string_skip_chop_whitespace(full_line_str);
insertf(&out, "%.*s:%d:%d: %.*s\n", string_expand(file_name), word_pos.line, word_pos.character, string_expand(line_str));
}
end_temp_memory(line_temp);
end_temp(line_temp);
no_matches = false;
}
}
if (no_matches){
char no_matches_message[] = "no matches\n";
i32 no_matches_message_length = sizeof(no_matches_message) - 1;
char *no_matches_message_out = buffered_memory_reserve(app, &out, no_matches_message_length);
memcpy(no_matches_message_out, no_matches_message, no_matches_message_length);
insert_string(&out, string_u8_litexpr("no matches\n"));
}
buffered_print_flush(app, &out);
end_buffer_insertion(&out);
end_temp_memory(all_temp);
end_temp(all_temp);
// Lock *search* as the jump buffer
lock_jump_buffer(search_name.str, search_name.size);
lock_jump_buffer(search_name);
}
static void
list__parameters(Application_Links *app, Heap *heap, Partition *scratch, String *strings, i32 count, Search_Range_Flag match_flags, View_ID default_target_view){
list__parameters(Application_Links *app, Heap *heap, String_Const_u8 *strings, i32 count, Search_Range_Flag match_flags, View_ID default_target_view){
// Open the search buffer
Buffer_ID search_buffer_id = create_or_switch_to_buffer_by_name(app, search_name, default_target_view);
list__parameters_buffer(app, heap, scratch, strings, count, match_flags, search_buffer_id);
Buffer_ID search_buffer_id = create_or_switch_to_buffer_and_clear_by_name(app, search_name, default_target_view);
list__parameters_buffer(app, heap, strings, count, match_flags, search_buffer_id);
}
static void
list_single__parameters(Application_Links *app, Heap *heap, Partition *scratch, String str, b32 substrings, b32 case_insensitive, View_ID default_target_view){
list_single__parameters(Application_Links *app, Heap *heap, String_Const_u8 str, b32 substrings, b32 case_insensitive, View_ID default_target_view){
Search_Range_Flag flags = 0;
if (substrings){
flags |= SearchFlag_MatchSubstring;
@ -725,20 +655,20 @@ list_single__parameters(Application_Links *app, Heap *heap, Partition *scratch,
if (case_insensitive){
flags |= SearchFlag_CaseInsensitive;
}
list__parameters(app, heap, scratch, &str, 1, flags, default_target_view);
list__parameters(app, heap, &str, 1, flags, default_target_view);
}
static void
list_query__parameters(Application_Links *app, Heap *heap, Partition *scratch, b32 substrings, b32 case_insensitive, View_ID default_target_view){
list_query__parameters(Application_Links *app, Heap *heap, b32 substrings, b32 case_insensitive, View_ID default_target_view){
char space[1024];
String str = get_query_string(app, "List Locations For: ", space, sizeof(space));
String_Const_u8 str = get_query_string(app, "List Locations For: ", space, sizeof(space));
if (str.size > 0){
list_single__parameters(app, heap, scratch, str, substrings, case_insensitive, default_target_view);
list_single__parameters(app, heap, str, substrings, case_insensitive, default_target_view);
}
}
static void
list_identifier__parameters(Application_Links *app, Heap *heap, Partition *scratch, b32 substrings, b32 case_insensitive, View_ID default_target_view){
list_identifier__parameters(Application_Links *app, Heap *heap, b32 substrings, b32 case_insensitive, View_ID default_target_view){
View_ID view = 0;
get_active_view(app, AccessProtected, &view);
Buffer_ID buffer = 0;
@ -746,45 +676,47 @@ list_identifier__parameters(Application_Links *app, Heap *heap, Partition *scrat
if (buffer != 0){
i32 pos = 0;
view_get_cursor_pos(app, view, &pos);
char space[512];
String str = get_token_or_word_under_pos(app, buffer, pos, space, sizeof(space));
Scratch_Block scratch(app);
String_Const_u8 str = get_token_or_word_under_pos(app, scratch, buffer, pos);
if (str.size > 0){
list_single__parameters(app, heap, scratch, str, substrings, case_insensitive, default_target_view);
list_single__parameters(app, heap, str, substrings, case_insensitive, default_target_view);
}
}
}
static void
list_selected_range__parameters(Application_Links *app, Heap *heap, Partition *scratch, b32 substrings, b32 case_insensitive, View_ID default_target_view){
list_selected_range__parameters(Application_Links *app, Heap *heap, b32 substrings, b32 case_insensitive, View_ID default_target_view){
View_ID view = 0;
get_active_view(app, AccessProtected, &view);
Temp_Memory temp = begin_temp_memory(scratch);
String str = get_string_in_view_range(app, scratch, view);
Arena *scratch = context_get_arena(app);
Temp_Memory temp = begin_temp(scratch);
String_Const_u8 str = get_string_in_view_range(app, scratch, view);
if (str.size > 0){
list_single__parameters(app, heap, scratch, str, substrings, case_insensitive, default_target_view);
list_single__parameters(app, heap, str, substrings, case_insensitive, default_target_view);
}
end_temp_memory(temp);
end_temp(temp);
}
static void
list_type_definition__parameters(Application_Links *app, Heap *heap, Partition *scratch, String str, View_ID default_target_view){
Temp_Memory temp = begin_temp_memory(scratch);
list_type_definition__parameters(Application_Links *app, Heap *heap, String_Const_u8 str, View_ID default_target_view){
Arena *scratch = context_get_arena(app);
Temp_Memory temp = begin_temp(scratch);
String match_strings[9];
String_Const_u8 match_strings[9];
i32 i = 0;
match_strings[i++] = string_push_f(scratch, "struct %.*s{" , str.size, str.str);
match_strings[i++] = string_push_f(scratch, "struct %.*s\n{", str.size, str.str);
match_strings[i++] = string_push_f(scratch, "struct %.*s {" , str.size, str.str);
match_strings[i++] = string_push_f(scratch, "union %.*s{" , str.size, str.str);
match_strings[i++] = string_push_f(scratch, "union %.*s\n{" , str.size, str.str);
match_strings[i++] = string_push_f(scratch, "union %.*s {" , str.size, str.str);
match_strings[i++] = string_push_f(scratch, "enum %.*s{" , str.size, str.str);
match_strings[i++] = string_push_f(scratch, "enum %.*s\n{" , str.size, str.str);
match_strings[i++] = string_push_f(scratch, "enum %.*s {" , str.size, str.str);
match_strings[i++] = (string_u8_pushf(scratch, "struct %.*s{" , string_expand(str)));
match_strings[i++] = (string_u8_pushf(scratch, "struct %.*s\n{", string_expand(str)));
match_strings[i++] = (string_u8_pushf(scratch, "struct %.*s {" , string_expand(str)));
match_strings[i++] = (string_u8_pushf(scratch, "union %.*s{" , string_expand(str)));
match_strings[i++] = (string_u8_pushf(scratch, "union %.*s\n{" , string_expand(str)));
match_strings[i++] = (string_u8_pushf(scratch, "union %.*s {" , string_expand(str)));
match_strings[i++] = (string_u8_pushf(scratch, "enum %.*s{" , string_expand(str)));
match_strings[i++] = (string_u8_pushf(scratch, "enum %.*s\n{" , string_expand(str)));
match_strings[i++] = (string_u8_pushf(scratch, "enum %.*s {" , string_expand(str)));
list__parameters(app, heap, scratch, match_strings, ArrayCount(match_strings), 0, default_target_view);
list__parameters(app, heap, match_strings, ArrayCount(match_strings), 0, default_target_view);
end_temp_memory(temp);
end_temp(temp);
}
////////////////////////////////
@ -793,66 +725,66 @@ CUSTOM_COMMAND_SIG(list_all_locations)
CUSTOM_DOC("Queries the user for a string and lists all exact case-sensitive matches found in all open buffers.")
{
View_ID target_view = get_next_view_after_active(app, AccessAll);
list_query__parameters(app, &global_heap, &global_part, false, false, target_view);
list_query__parameters(app, &global_heap, false, false, target_view);
}
CUSTOM_COMMAND_SIG(list_all_substring_locations)
CUSTOM_DOC("Queries the user for a string and lists all case-sensitive substring matches found in all open buffers.")
{
View_ID target_view = get_next_view_after_active(app, AccessAll);
list_query__parameters(app, &global_heap, &global_part, true, false, target_view);
list_query__parameters(app, &global_heap, true, false, target_view);
}
CUSTOM_COMMAND_SIG(list_all_locations_case_insensitive)
CUSTOM_DOC("Queries the user for a string and lists all exact case-insensitive matches found in all open buffers.")
{
View_ID target_view = get_next_view_after_active(app, AccessAll);
list_query__parameters(app, &global_heap, &global_part, false, true, target_view);
list_query__parameters(app, &global_heap, false, true, target_view);
}
CUSTOM_COMMAND_SIG(list_all_substring_locations_case_insensitive)
CUSTOM_DOC("Queries the user for a string and lists all case-insensitive substring matches found in all open buffers.")
{
View_ID target_view = get_next_view_after_active(app, AccessAll);
list_query__parameters(app, &global_heap, &global_part, true, true, target_view);
list_query__parameters(app, &global_heap, true, true, target_view);
}
CUSTOM_COMMAND_SIG(list_all_locations_of_identifier)
CUSTOM_DOC("Reads a token or word under the cursor and lists all exact case-sensitive mathces in all open buffers.")
{
View_ID target_view = get_next_view_after_active(app, AccessAll);
list_identifier__parameters(app, &global_heap, &global_part, false, false, target_view);
list_identifier__parameters(app, &global_heap, false, false, target_view);
}
CUSTOM_COMMAND_SIG(list_all_locations_of_identifier_case_insensitive)
CUSTOM_DOC("Reads a token or word under the cursor and lists all exact case-insensitive mathces in all open buffers.")
{
View_ID target_view = get_next_view_after_active(app, AccessAll);
list_identifier__parameters(app, &global_heap, &global_part, false, true, target_view);
list_identifier__parameters(app, &global_heap, false, true, target_view);
}
CUSTOM_COMMAND_SIG(list_all_locations_of_selection)
CUSTOM_DOC("Reads the string in the selected range and lists all exact case-sensitive mathces in all open buffers.")
{
View_ID target_view = get_next_view_after_active(app, AccessAll);
list_selected_range__parameters(app, &global_heap, &global_part, false, false, target_view);
list_selected_range__parameters(app, &global_heap, false, false, target_view);
}
CUSTOM_COMMAND_SIG(list_all_locations_of_selection_case_insensitive)
CUSTOM_DOC("Reads the string in the selected range and lists all exact case-insensitive mathces in all open buffers.")
{
View_ID target_view = get_next_view_after_active(app, AccessAll);
list_selected_range__parameters(app, &global_heap, &global_part, false, true, target_view);
list_selected_range__parameters(app, &global_heap, false, true, target_view);
}
CUSTOM_COMMAND_SIG(list_all_locations_of_type_definition)
CUSTOM_DOC("Queries user for string, lists all locations of strings that appear to define a type whose name matches the input string.")
{
char space[1024];
String str = get_query_string(app, "List Definitions For: ", space, sizeof(space));
String_Const_u8 str = get_query_string(app, "List Definitions For: ", space, sizeof(space));
if (str.size > 0){
View_ID target_view = get_next_view_after_active(app, AccessAll);
list_type_definition__parameters(app, &global_heap, &global_part, str, target_view);
list_type_definition__parameters(app, &global_heap, str, target_view);
}
}
@ -865,11 +797,11 @@ CUSTOM_DOC("Reads a token or word under the cursor and lists all locations of st
view_get_buffer(app, target_view, AccessProtected, &buffer);
i32 pos = 0;
view_get_cursor_pos(app, target_view, &pos);
char space[512];
String str = get_token_or_word_under_pos(app, buffer, pos, space, sizeof(space) - 1);
Scratch_Block scratch(app);
String_Const_u8 str = get_token_or_word_under_pos(app, scratch, buffer, pos);
if (str.size > 0){
target_view = get_next_view_after_active(app, AccessAll);
list_type_definition__parameters(app, &global_heap, &global_part, str, target_view);
list_type_definition__parameters(app, &global_heap, str, target_view);
}
}
@ -889,7 +821,8 @@ CUSTOM_DOC("Iteratively tries completing the word to the left of the cursor with
if (view_get_buffer(app, view, AccessOpen, &buffer)){
i32 do_init = false;
Managed_Scope scope = view_get_managed_scope(app, view);
Managed_Scope scope = 0;
view_get_managed_scope(app, view, &scope);
u64 rewrite = 0;
managed_variable_get(app, scope, view_rewrite_loc, &rewrite);
@ -904,7 +837,7 @@ CUSTOM_DOC("Iteratively tries completing the word to the left of the cursor with
i32 word_end = 0;
i32 word_start = 0;
i32 cursor_pos = 0;
i32 size = 0;
umem size = 0;
if (do_init){
// NOTE(allen): Get the range where the
@ -920,11 +853,11 @@ CUSTOM_DOC("Iteratively tries completing the word to the left of the cursor with
i32 still_looping = true;
do{
for (; cursor_pos >= chunk.start; --cursor_pos){
char c = chunk.data[cursor_pos];
if (char_is_alpha_utf8(c)){
u8 c = chunk.data[cursor_pos];
if (character_is_alpha_unicode(c)){
word_start = cursor_pos;
}
else if (!char_is_numeric(c)){
else if (!character_is_base10(c)){
goto double_break;
}
}
@ -944,7 +877,7 @@ CUSTOM_DOC("Iteratively tries completing the word to the left of the cursor with
complete_state.initialized = true;
Search_Key key = {};
search_key_alloc(&global_heap, &key, &size, 1);
buffer_read_range(app, buffer, word_start, word_end, key.words[0].str);
buffer_read_range(app, buffer, word_start, word_end, (char*)key.words[0].str);
key.words[0].size = size;
search_iter_init(&complete_state.iter, key);
@ -960,7 +893,7 @@ CUSTOM_DOC("Iteratively tries completing the word to the left of the cursor with
ranges[0].start = 0;
buffer_get_size(app, buffer, &ranges[0].size);
ranges[0].mid_start = word_start;
ranges[0].mid_size = size;
ranges[0].mid_size = (i32)size;
Buffer_ID buffer_it = 0;
@ -981,8 +914,8 @@ CUSTOM_DOC("Iteratively tries completing the word to the left of the cursor with
// NOTE(allen): Initialize the search hit table.
search_hits_init(&global_heap, &complete_state.hits, &complete_state.str, 100, (4 << 10));
String word = complete_state.iter.key.words[0];
search_hit_add(&global_heap, &complete_state.hits, &complete_state.str, word.str, word.size);
String_Const_u8 word = complete_state.iter.key.words[0];
search_hit_add(&global_heap, &complete_state.hits, &complete_state.str, word);
complete_state.word_start = word_start;
complete_state.word_end = word_end;
@ -990,7 +923,7 @@ CUSTOM_DOC("Iteratively tries completing the word to the left of the cursor with
else{
word_start = complete_state.word_start;
word_end = complete_state.word_end;
size = complete_state.iter.key.words[0].size;
size = (i32)complete_state.iter.key.words[0].size;
}
// NOTE(allen): Iterate through matches.
@ -1001,33 +934,31 @@ CUSTOM_DOC("Iteratively tries completing the word to the left of the cursor with
if (match.found_match){
match_size = match.end - match.start;
Temp_Memory temp = begin_temp_memory(&global_part);
char *spare = push_array(&global_part, char, match_size);
Arena *scratch = context_get_arena(app);
Scratch_Block temp_auto_closer(scratch);
char *spare = push_array(scratch, char, match_size);
buffer_read_range(app, match.buffer, match.start, match.end, spare);
if (search_hit_add(&global_heap, &complete_state.hits, &complete_state.str, spare, match_size)){
buffer_replace_range(app, buffer, make_range(word_start, word_end), make_string(spare, match_size));
buffer_replace_range(app, buffer, make_range(word_start, word_end), SCu8(spare, match_size));
view_set_cursor(app, view, seek_pos(word_start + match_size), true);
complete_state.word_end = word_start + match_size;
complete_state.set.ranges[0].mid_size = match_size;
end_temp_memory(temp);
break;
}
end_temp_memory(temp);
}
else{
complete_state.iter.pos = 0;
complete_state.iter.i = 0;
search_hits_init(&global_heap, &complete_state.hits, &complete_state.str, 100, (4 << 10));
String word = complete_state.iter.key.words[0];
search_hit_add(&global_heap, &complete_state.hits, &complete_state.str, word.str, word.size);
String_Const_u8 word = complete_state.iter.key.words[0];
search_hit_add(&global_heap, &complete_state.hits, &complete_state.str, word);
match_size = word.size;
char *str = word.str;
buffer_replace_range(app, buffer, make_range(word_start, word_end), make_string(str, match_size));
match_size = (i32)word.size;
buffer_replace_range(app, buffer, make_range(word_start, word_end), word);
view_set_cursor(app, view, seek_pos(word_start + match_size), true);
complete_state.word_end = word_start + match_size;

View File

@ -52,11 +52,11 @@ struct Search_Set{
};
struct Search_Key{
char *base;
i32 base_size;
String words[16];
u8 *base;
umem base_size;
umem min_size;
String_Const_u8 words[16];
i32 count;
i32 min_size;
};
struct Search_Iter{

View File

@ -74,7 +74,7 @@ move_past_lead_whitespace(Application_Links *app, View_ID view, Buffer_ID buffer
do{
for (; i < chunk.end; ++i){
char at_pos = chunk.data[i];
if (at_pos == '\n' || !char_is_whitespace(at_pos)){
if (at_pos == '\n' || !character_is_whitespace(at_pos)){
goto break2;
}
}
@ -103,7 +103,7 @@ buffer_seek_whitespace_up(Application_Links *app, Buffer_ID buffer_id, i32 pos){
for (;still_looping;){
for (; pos >= stream.start; --pos){
char at_pos = stream.data[pos];
if (!char_is_whitespace(at_pos)){
if (!character_is_whitespace(at_pos)){
goto double_break_1;
}
}
@ -128,7 +128,7 @@ buffer_seek_whitespace_up(Application_Links *app, Buffer_ID buffer_id, i32 pos){
no_hard = true;
}
}
else if (!char_is_whitespace(at_pos)){
else if (!character_is_whitespace(at_pos)){
no_hard = false;
}
}
@ -160,7 +160,7 @@ buffer_seek_whitespace_down(Application_Links *app, Buffer_ID buffer_id, i32 pos
do{
for (; pos < stream.end; ++pos){
char at_pos = stream.data[pos];
if (!char_is_whitespace(at_pos)){
if (!character_is_whitespace(at_pos)){
goto double_break_1;
}
}
@ -187,7 +187,7 @@ buffer_seek_whitespace_down(Application_Links *app, Buffer_ID buffer_id, i32 pos
prev_endline = pos;
}
}
else if (!char_is_whitespace(at_pos)){
else if (!character_is_whitespace(at_pos)){
no_hard = false;
}
}
@ -221,13 +221,13 @@ buffer_seek_whitespace_right(Application_Links *app, Buffer_ID buffer_id, i32 po
stream.add_null = true;
if (init_stream_chunk(&stream, app, buffer_id, pos, data_chunk, sizeof(data_chunk))){
b32 still_looping = true;
b32 is_whitespace_1 = char_is_whitespace(buffer_get_char(app, buffer_id, pos - 1));
b32 is_whitespace_1 = character_is_whitespace(buffer_get_char(app, buffer_id, pos - 1));
do{
for (; pos < stream.end; ++pos){
char c2 = stream.data[pos];
b32 is_whitespace_2 = true;
if (c2 != 0){
is_whitespace_2 = char_is_whitespace(c2);
is_whitespace_2 = character_is_whitespace(c2);
}
if (!is_whitespace_1 && is_whitespace_2){
result = pos;
@ -258,11 +258,11 @@ buffer_seek_whitespace_left(Application_Links *app, Buffer_ID buffer_id, i32 pos
Stream_Chunk stream = {};
if (init_stream_chunk(&stream, app, buffer_id, pos, data_chunk, sizeof(data_chunk))){
b32 still_looping = true;
b32 is_whitespace_2 = char_is_whitespace(buffer_get_char(app, buffer_id, pos + 1));
b32 is_whitespace_2 = character_is_whitespace(buffer_get_char(app, buffer_id, pos + 1));
do{
for (; pos >= stream.start; --pos){
char c1 = stream.data[pos];
b32 is_whitespace_1 = char_is_whitespace(c1);
b32 is_whitespace_1 = character_is_whitespace(c1);
if (is_whitespace_1 && !is_whitespace_2){
result = pos + 1;
goto double_break;
@ -275,7 +275,7 @@ buffer_seek_whitespace_left(Application_Links *app, Buffer_ID buffer_id, i32 pos
}
}
if (pos == -1){
if (!char_is_whitespace(buffer_get_char(app, buffer_id, 0))){
if (!character_is_whitespace(buffer_get_char(app, buffer_id, 0))){
result = 0;
}
}
@ -290,7 +290,8 @@ buffer_seek_alphanumeric_right(Application_Links *app, Buffer_ID buffer_id, i32
b32 still_looping = true;
do{
for (; pos < stream.end; ++pos){
if (char_is_alpha_numeric_true_utf8(stream.data[pos])){
u8 c = stream.data[pos];
if (c != '_' && character_is_alpha_numeric_unicode(c)){
goto double_break1;
}
}
@ -300,7 +301,8 @@ buffer_seek_alphanumeric_right(Application_Links *app, Buffer_ID buffer_id, i32
still_looping = true;
do{
for (; pos < stream.end; ++pos){
if (!char_is_alpha_numeric_true_utf8(stream.data[pos])){
u8 c = stream.data[pos];
if (!(c != '_' && character_is_alpha_numeric_unicode(c))){
goto double_break2;
}
}
@ -321,7 +323,8 @@ buffer_seek_alphanumeric_left(Application_Links *app, Buffer_ID buffer_id, i32 p
b32 still_looping = true;
do{
for (; pos >= stream.start; --pos){
if (char_is_alpha_numeric_true_utf8(stream.data[pos])){
u8 c = stream.data[pos];
if (c != '_' && character_is_alpha_numeric_unicode(c)){
goto double_break1;
}
}
@ -331,7 +334,8 @@ buffer_seek_alphanumeric_left(Application_Links *app, Buffer_ID buffer_id, i32 p
still_looping = true;
do{
for (; pos >= stream.start; --pos){
if (!char_is_alpha_numeric_true_utf8(stream.data[pos])){
u8 c = stream.data[pos];
if (!(c != '_' && character_is_alpha_numeric_unicode(c))){
++pos;
goto double_break2;
}
@ -355,7 +359,8 @@ buffer_seek_alphanumeric_or_underscore_right(Application_Links *app, Buffer_ID b
b32 still_looping = true;
do{
for (; pos < stream.end; ++pos){
if (char_is_alpha_numeric_utf8(stream.data[pos])){
u8 c = stream.data[pos];
if (character_is_alpha_numeric_unicode(c)){
goto double_break1;
}
}
@ -365,7 +370,8 @@ buffer_seek_alphanumeric_or_underscore_right(Application_Links *app, Buffer_ID b
still_looping = true;
do{
for (; pos < stream.end; ++pos){
if (!char_is_alpha_numeric_utf8(stream.data[pos])){
u8 c = stream.data[pos];
if (!character_is_alpha_numeric_unicode(c)){
goto double_break2;
}
}
@ -386,7 +392,8 @@ buffer_seek_alphanumeric_or_underscore_left(Application_Links *app, Buffer_ID bu
b32 still_looping = true;
do{
for (; pos >= stream.start; --pos){
if (char_is_alpha_numeric_utf8(stream.data[pos])){
u8 c = stream.data[pos];
if (character_is_alpha_numeric_unicode(c)){
goto double_break1;
}
}
@ -396,7 +403,8 @@ buffer_seek_alphanumeric_or_underscore_left(Application_Links *app, Buffer_ID bu
still_looping = true;
do{
for (; pos >= stream.start; --pos){
if (!char_is_alpha_numeric_utf8(stream.data[pos])){
u8 c = stream.data[pos];
if (!character_is_alpha_numeric_unicode(c)){
++pos;
goto double_break2;
}
@ -420,13 +428,14 @@ buffer_seek_range_camel_right(Application_Links *app, Buffer_ID buffer_id, i32 p
if (pos < an_pos){
stream.max_end = an_pos;
if (init_stream_chunk(&stream, app, buffer_id, pos, data_chunk, sizeof(data_chunk))){
u8 c = 0, pc = stream.data[pos];
u8 c = 0;
u8 pc = stream.data[pos];
++pos;
b32 still_looping = false;
do{
for (; pos < stream.end; ++pos){
c = stream.data[pos];
if (char_is_upper(c) && char_is_lower_utf8(pc)){
if (character_is_upper(c) && character_is_lower_unicode(pc)){
goto double_break1;
}
pc = c;
@ -450,12 +459,13 @@ buffer_seek_range_camel_left(Application_Links *app, Buffer_ID buffer_id, i32 po
if (pos > 0){
stream.min_start = an_pos+1;
if (init_stream_chunk(&stream, app, buffer_id, pos, data_chunk, sizeof(data_chunk))){
char c = 0, pc = stream.data[pos];
u8 c = 0;
u8 pc = stream.data[pos];
b32 still_looping = false;
do{
for (; pos >= stream.start; --pos){
c = stream.data[pos];
if (char_is_upper(c) && char_is_lower_utf8(pc)){
if (character_is_upper(c) && character_is_lower_unicode(pc)){
goto double_break1;
}
pc = c;
@ -514,27 +524,28 @@ seek_token_right(Cpp_Token_Array *tokens, i32 pos, i32 buffer_end){
}
static Cpp_Token_Array
buffer_get_all_tokens(Application_Links *app, Partition *part, Buffer_ID buffer_id){
buffer_get_all_tokens(Application_Links *app, Arena *arena, Buffer_ID buffer_id){
Cpp_Token_Array array = {};
if (buffer_exists(app, buffer_id)){
b32 is_lexed = false;
if (buffer_get_setting(app, buffer_id, BufferSetting_Lex, &is_lexed) &&
is_lexed){
buffer_token_count(app, buffer_id, &array.count);
array.max_count = array.count;
array.tokens = push_array(part, Cpp_Token, array.count);
buffer_read_tokens(app, buffer_id, 0, array.count, array.tokens);
if (buffer_get_setting(app, buffer_id, BufferSetting_Lex, &is_lexed)){
if (is_lexed){
buffer_token_count(app, buffer_id, &array.count);
array.max_count = array.count;
array.tokens = push_array(arena, Cpp_Token, array.count);
buffer_read_tokens(app, buffer_id, 0, array.count, array.tokens);
}
}
}
return(array);
}
static i32
buffer_boundary_seek(Application_Links *app, Buffer_ID buffer_id, Partition *part, i32 start_pos, b32 seek_forward, Seek_Boundary_Flag flags){
buffer_boundary_seek(Application_Links *app, Buffer_ID buffer_id, Arena *scratch, i32 start_pos, b32 seek_forward, Seek_Boundary_Flag flags){
i32 result = 0;
// TODO(allen): reduce duplication?
Temp_Memory temp = begin_temp_memory(part);
Temp_Memory temp = begin_temp(scratch);
if (buffer_exists(app, buffer_id)){
i32 pos[4];
i32 size = 0;
@ -559,7 +570,7 @@ buffer_boundary_seek(Application_Links *app, Buffer_ID buffer_id, Partition *par
if (flags & BoundaryToken){
if (buffer_tokens_are_ready(app, buffer_id)){
Cpp_Token_Array array = buffer_get_all_tokens(app, part, buffer_id);
Cpp_Token_Array array = buffer_get_all_tokens(app, scratch, buffer_id);
pos[1] = seek_token_right(&array, start_pos, size);
}
else{
@ -597,7 +608,7 @@ buffer_boundary_seek(Application_Links *app, Buffer_ID buffer_id, Partition *par
if (flags & BoundaryToken){
if (buffer_tokens_are_ready(app, buffer_id)){
Cpp_Token_Array array = buffer_get_all_tokens(app, part, buffer_id);
Cpp_Token_Array array = buffer_get_all_tokens(app, scratch, buffer_id);
pos[1] = seek_token_left(&array, start_pos);
}
else{
@ -626,7 +637,7 @@ buffer_boundary_seek(Application_Links *app, Buffer_ID buffer_id, Partition *par
}
result = new_pos;
}
end_temp_memory(temp);
end_temp(temp);
return(result);
}
@ -681,11 +692,8 @@ buffer_seek_delimiter_backward(Application_Links *app, Buffer_ID buffer_id, i32
finished:;
}
// NOTE(allen): This is limitted to a string size of 512.
// You can push it up or do something more clever by just
// replacing char read_buffer[512]; with more memory.
static void
buffer_seek_string_forward(Application_Links *app, Buffer_ID buffer_id, i32 pos, i32 end, char *str, i32 size, i32 *result){
buffer_seek_string_forward(Application_Links *app, Buffer_ID buffer_id, i32 pos, i32 end, String_Const_u8 needle_string, i32 *result){
i32 buffer_size = 0;
buffer_get_size(app, buffer_id, &buffer_size);
if (buffer_size > end){
@ -695,14 +703,13 @@ buffer_seek_string_forward(Application_Links *app, Buffer_ID buffer_id, i32 pos,
*result = end;
}
char read_buffer[512];
if (size > 0 && size <= sizeof(read_buffer)){
Scratch_Block scratch(app);
if (0 < needle_string.size){
if (buffer_exists(app, buffer_id)){
String read_str = make_fixed_width_string(read_buffer);
String needle_str = make_string(str, size);
char first_char = str[0];
u8 first_char = string_get_character(needle_string, 0);
read_str.size = size;
u8 *read_buffer = push_array(scratch, u8, needle_string.size);
String_Const_u8 read_str = SCu8(read_buffer, needle_string.size);
char chunk[1024];
Stream_Chunk stream = {};
@ -712,10 +719,10 @@ buffer_seek_string_forward(Application_Links *app, Buffer_ID buffer_id, i32 pos,
b32 still_looping = true;
do{
for(; pos < stream.end; ++pos){
char at_pos = stream.data[pos];
u8 at_pos = stream.data[pos];
if (at_pos == first_char){
buffer_read_range(app, buffer_id, pos, pos+size, read_buffer);
if (match_ss(needle_str, read_str)){
buffer_read_range(app, buffer_id, pos, (i32)(pos + needle_string.size), (char*)read_buffer);
if (string_match(needle_string, read_str)){
*result = pos;
goto finished;
}
@ -737,29 +744,28 @@ buffer_seek_string_forward(Application_Links *app, Buffer_ID buffer_id, i32 pos,
}
}
// NOTE(allen): This is limitted to a string size of 512.
// You can push it up or do something more clever by just
// replacing char read_buffer[512]; with more memory.
static void
buffer_seek_string_backward(Application_Links *app, Buffer_ID buffer_id, i32 pos, i32 min, char *str, i32 size, i32 *result){
char read_buffer[512];
buffer_seek_string_backward(Application_Links *app, Buffer_ID buffer_id, i32 pos, i32 min, String_Const_u8 needle_string, i32 *result){
Scratch_Block scratch(app);
*result = min - 1;
if (size > 0 && size <= sizeof(read_buffer) && buffer_exists(app, buffer_id)){
String read_str = make_fixed_width_string(read_buffer);
String needle_str = make_string(str, size);
char first_char = str[0];
read_str.size = size;
if (0 < needle_string.size && buffer_exists(app, buffer_id)){
u8 first_char = string_get_character(needle_string, 0);
u8 *read_buffer = push_array(scratch, u8, needle_string.size);
String_Const_u8 read_str = SCu8(read_buffer, needle_string.size);
char chunk[1024];
Stream_Chunk stream = {};
stream.min_start = min;
if (init_stream_chunk(&stream, app, buffer_id, pos, chunk, sizeof(chunk))){
i32 still_looping = 1;
b32 still_looping = true;
do{
for(; pos >= stream.start; --pos){
char at_pos = stream.data[pos];
u8 at_pos = stream.data[pos];
if (at_pos == first_char){
buffer_read_range(app, buffer_id, pos, pos+size, read_buffer);
if (match_ss(needle_str, read_str)){
buffer_read_range(app, buffer_id, pos, (i32)(pos + needle_string.size), (char*)read_buffer);
if (string_match(needle_string, read_str)){
*result = pos;
goto finished;
}
@ -772,11 +778,8 @@ buffer_seek_string_backward(Application_Links *app, Buffer_ID buffer_id, i32 pos
}
}
// NOTE(allen): This is limitted to a string size of 512.
// You can push it up or do something more clever by just
// replacing char read_buffer[512]; with more memory.
static void
buffer_seek_string_insensitive_forward(Application_Links *app, Buffer_ID buffer_id, i32 pos, i32 end, char *str, i32 size, i32 *result){
buffer_seek_string_insensitive_forward(Application_Links *app, Buffer_ID buffer_id, i32 pos, i32 end, String_Const_u8 needle_string, i32 *result){
i32 buffer_size = 0;
buffer_get_size(app, buffer_id, &buffer_size);
if (buffer_size > end){
@ -785,24 +788,26 @@ buffer_seek_string_insensitive_forward(Application_Links *app, Buffer_ID buffer_
else{
*result = end;
}
char read_buffer[512];
char chunk[1024];
i32 chunk_size = sizeof(chunk);
Stream_Chunk stream = {};
stream.max_end = end;
if (size > 0 && size <= sizeof(read_buffer) && buffer_exists(app, buffer_id)){
String read_str = make_fixed_width_string(read_buffer);
String needle_str = make_string(str, size);
char first_char = char_to_upper(str[0]);
read_str.size = size;
if (init_stream_chunk(&stream, app, buffer_id, pos, chunk, chunk_size)){
i32 still_looping = 1;
Scratch_Block scratch(app);
if (0 < needle_string.size && buffer_exists(app, buffer_id)){
u8 first_char = character_to_upper(string_get_character(needle_string, 0));
u8 *read_buffer = push_array(scratch, u8, needle_string.size);
String_Const_u8 read_str = SCu8(read_buffer, needle_string.size);
char chunk[1024];
Stream_Chunk stream = {};
stream.max_end = end;
if (init_stream_chunk(&stream, app, buffer_id, pos, chunk, sizeof(chunk))){
b32 still_looping = true;
do{
for(; pos < stream.end; ++pos){
char at_pos = char_to_upper(stream.data[pos]);
u8 at_pos = character_to_upper(stream.data[pos]);
if (at_pos == first_char){
buffer_read_range(app, buffer_id, pos, pos+size, read_buffer);
if (match_insensitive_ss(needle_str, read_str)){
buffer_read_range(app, buffer_id, pos, (i32)(pos + needle_string.size), (char*)read_buffer);
if (string_match_insensitive(needle_string, read_str)){
*result = pos;
goto finished;
}
@ -815,31 +820,28 @@ buffer_seek_string_insensitive_forward(Application_Links *app, Buffer_ID buffer_
}
}
// NOTE(allen): This is limitted to a string size of 512.
// You can push it up or do something more clever by just
// replacing char read_buffer[512]; with more memory.
static void
buffer_seek_string_insensitive_backward(Application_Links *app, Buffer_ID buffer_id, i32 pos, i32 min, char *str, i32 size, i32 *result){
char read_buffer[512];
char chunk[1024];
i32 chunk_size = sizeof(chunk);
Stream_Chunk stream = {};
stream.min_start = min;
buffer_seek_string_insensitive_backward(Application_Links *app, Buffer_ID buffer_id, i32 pos, i32 min, String_Const_u8 needle_string, i32 *result){
Scratch_Block scratch(app);
*result = min - 1;
if (size > 0 && size <= sizeof(read_buffer) && buffer_exists(app, buffer_id)){
String read_str = make_fixed_width_string(read_buffer);
String needle_str = make_string(str, size);
char first_char = char_to_upper(str[0]);
read_str.size = size;
if (init_stream_chunk(&stream, app, buffer_id, pos, chunk, chunk_size)){
i32 still_looping = 1;
if (0 < needle_string.size && buffer_exists(app, buffer_id)){
u8 first_char = character_to_upper(string_get_character(needle_string, 0));
u8 *read_buffer = push_array(scratch, u8, needle_string.size);
String_Const_u8 read_str = SCu8(read_buffer, needle_string.size);
char chunk[1024];
Stream_Chunk stream = {};
stream.min_start = min;
if (init_stream_chunk(&stream, app, buffer_id, pos, chunk, sizeof(chunk))){
b32 still_looping = true;
do{
for(; pos >= stream.start; --pos){
char at_pos = char_to_upper(stream.data[pos]);
u8 at_pos = character_to_upper(stream.data[pos]);
if (at_pos == first_char){
buffer_read_range(app, buffer_id, pos, pos+size, read_buffer);
if (match_insensitive_ss(needle_str, read_str)){
buffer_read_range(app, buffer_id, pos, (i32)(pos + needle_string.size), (char*)read_buffer);
if (string_match_insensitive(needle_string, read_str)){
*result = pos;
goto finished;
}
@ -855,26 +857,26 @@ buffer_seek_string_insensitive_backward(Application_Links *app, Buffer_ID buffer
////////////////////////////////
static void
buffer_seek_string(Application_Links *app, Buffer_ID buffer_id, i32 pos, i32 end, i32 min, char *str, i32 size, i32 *result, Buffer_Seek_String_Flags flags){
buffer_seek_string(Application_Links *app, Buffer_ID buffer_id, i32 pos, i32 end, i32 min, String_Const_u8 str, i32 *result, Buffer_Seek_String_Flags flags){
switch (flags & 3){
case 0:
{
buffer_seek_string_forward(app, buffer_id, pos, end, str, size, result);
buffer_seek_string_forward(app, buffer_id, pos, end, str, result);
}break;
case BufferSeekString_Backward:
{
buffer_seek_string_backward(app, buffer_id, pos, min, str, size, result);
buffer_seek_string_backward(app, buffer_id, pos, min, str, result);
}break;
case BufferSeekString_CaseInsensitive:
{
buffer_seek_string_insensitive_forward(app, buffer_id, pos, end, str, size, result);
buffer_seek_string_insensitive_forward(app, buffer_id, pos, end, str, result);
}break;
case BufferSeekString_Backward|BufferSeekString_CaseInsensitive:
{
buffer_seek_string_insensitive_backward(app, buffer_id, pos, min, str, size, result);
buffer_seek_string_insensitive_backward(app, buffer_id, pos, min, str, result);
}break;
}
}
@ -904,7 +906,7 @@ buffer_line_is_blank(Application_Links *app, Buffer_ID buffer_id, i32 line){
do{
for (;i < stream.end; ++i){
char c = stream.data[i];
if (!char_is_whitespace(c)){
if (!character_is_whitespace(c)){
result = false;
goto double_break;
}
@ -917,9 +919,9 @@ buffer_line_is_blank(Application_Links *app, Buffer_ID buffer_id, i32 line){
return(result);
}
static String
read_identifier_at_pos(Application_Links *app, Buffer_ID buffer_id, i32 pos, char *space, i32 max, Range *range_out){
String query = {};
static String_Const_u8
read_identifier_at_pos(Application_Links *app, Arena *arena, Buffer_ID buffer_id, i32 pos, Range *range_out){
String_Const_u8 result = {};
i32 start = buffer_seek_alphanumeric_or_underscore_left(app, buffer_id, pos);
i32 end = buffer_seek_alphanumeric_or_underscore_right(app, buffer_id, start);
@ -930,17 +932,13 @@ read_identifier_at_pos(Application_Links *app, Buffer_ID buffer_id, i32 pos, cha
}
if (start <= pos && pos < end){
i32 size = end - start;
if (size <= max){
if (range_out != 0){
*range_out = make_range(start, end);
}
buffer_read_range(app, buffer_id, start, end, space);
query = make_string_cap(space, size, max);
if (range_out != 0){
*range_out = make_range(start, end);
}
result = scratch_read(app, arena, buffer_id, start, end);
}
return(query);
return(result);
}
////////////////////////////////
@ -959,14 +957,16 @@ flip_dir(i32 dir){
static i32
buffer_boundary_seek(Application_Links *app, Buffer_ID buffer_id, i32 start_pos, i32 dir, Seek_Boundary_Flag flags){
b32 forward = (dir != DirLeft);
return(buffer_boundary_seek(app, buffer_id, &global_part, start_pos, forward, flags));
Arena *scratch = context_get_arena(app);
return(buffer_boundary_seek(app, buffer_id, scratch, start_pos, forward, flags));
}
static void
view_buffer_boundary_seek_set_pos(Application_Links *app, View_ID view, Buffer_ID buffer_id, i32 dir, u32 flags){
i32 cursor_pos = 0;
view_get_cursor_pos(app, view, &cursor_pos);
i32 pos = buffer_boundary_seek(app, buffer_id, &global_part, cursor_pos, dir, flags);
Arena *scratch = context_get_arena(app);
i32 pos = buffer_boundary_seek(app, buffer_id, scratch, cursor_pos, dir, flags);
view_set_cursor(app, view, seek_pos(pos), true);
no_mark_snap_to_cursor_if_shift(app, view);
}
@ -1005,7 +1005,7 @@ view_buffer_snipe_range(Application_Links *app, View_ID view, Buffer_ID buffer_i
i32 pos2 = buffer_boundary_seek(app, buffer_id, pos1, flip_dir(dir), flags);
if (0 <= pos2 && pos2 <= buffer_size){
if (dir == DirLeft){
pos2 = clamp_bottom(pos2, pos0);
pos2 = clamp_bot(pos2, pos0);
}
else{
pos2 = clamp_top(pos2, pos0);
@ -1023,7 +1023,7 @@ current_view_boundary_delete(Application_Links *app, i32 dir, u32 flags){
Buffer_ID buffer_id = 0;
view_get_buffer(app, view, AccessOpen, &buffer_id);
Range range = view_buffer_boundary_range(app, view, buffer_id, dir, flags);
buffer_replace_range(app, buffer_id, range, make_lit_string(""));
buffer_replace_range(app, buffer_id, range, string_u8_litexpr(""));
}
static void
@ -1033,7 +1033,7 @@ current_view_snipe_delete(Application_Links *app, i32 dir, u32 flags){
Buffer_ID buffer_id = 0;
view_get_buffer(app, view, AccessOpen, &buffer_id);
Range range = view_buffer_snipe_range(app, view, buffer_id, dir, flags);
buffer_replace_range(app, buffer_id, range, make_lit_string(""));
buffer_replace_range(app, buffer_id, range, string_u8_litexpr(""));
}
////////////////////////////////

72
4coder_stringf.cpp Normal file
View File

@ -0,0 +1,72 @@
/*
* Printf style operations for strings and what-not
*/
// TOP
#include <stdarg.h>
#include <stdio.h>
static String_Const_char
string_pushfv(Arena *arena, char *format, va_list args){
i32 size = vsnprintf(0, 0, format, args);
String_Const_char result = string_const_char_push(arena, size + 1);
vsnprintf(result.str, result.size, format, args);
result.size -= 1;
result.str[result.size] = 0;
return(result);
}
static String_Const_char
string_pushf(Arena *arena, char *format, ...){
va_list args;
va_start(args, format);
String_Const_char result = string_pushfv(arena, format, args);
va_end(args);
return(result);
}
static String_Const_u8
string_u8_pushfv(Arena *arena, char *format, va_list args){
return(SCu8(string_pushfv(arena, format, args)));
}
static String_Const_u8
string_u8_pushf(Arena *arena, char *format, ...){
va_list args;
va_start(args, format);
String_Const_u8 result = SCu8(string_pushfv(arena, format, args));
va_end(args);
return(result);
}
static void
string_list_pushfv(Arena *arena, List_String_Const_char *list, char *format, va_list args){
String_Const_char string = string_pushfv(arena, format, args);
if (arena->alignment < sizeof(umem)){
push_align(arena, sizeof(umem));
}
string_list_push(arena, list, string);
}
static void
string_list_pushf(Arena *arena, List_String_Const_char *list, char *format, ...){
va_list args;
va_start(args, format);
string_list_pushfv(arena, list, format, args);
va_end(args);
}
static void
string_list_pushfv(Arena *arena, List_String_Const_u8 *list, char *format, va_list args){
String_Const_u8 string = string_u8_pushfv(arena, format, args);
if (arena->alignment < sizeof(umem)){
push_align(arena, sizeof(umem));
}
string_list_push(arena, list, string);
}
static void
string_list_pushf(Arena *arena, List_String_Const_u8 *list, char *format, ...){
va_list args;
va_start(args, format);
string_list_pushfv(arena, list, format, args);
va_end(args);
}
// BOTTOM

View File

@ -7,32 +7,41 @@
CUSTOM_COMMAND_SIG(execute_previous_cli)
CUSTOM_DOC("If the command execute_any_cli has already been used, this will execute a CLI reusing the most recent buffer name and command.")
{
String out_buffer = make_string_slowly(out_buffer_space);
String cmd = make_string_slowly(command_space);
String hot_directory = make_string_slowly(hot_directory_space);
String_Const_u8 out_buffer = SCu8(out_buffer_space);
String_Const_u8 cmd = SCu8(command_space);
String_Const_u8 hot_directory = SCu8(hot_directory_space);
if (out_buffer.size > 0 && cmd.size > 0 && hot_directory.size > 0){
View_ID view = 0;
get_active_view(app, AccessAll, &view);
exec_system_command(app, view, buffer_identifier(out_buffer.str, out_buffer.size), hot_directory.str, hot_directory.size, cmd.str, cmd.size, CLI_OverlapWithConflict|CLI_CursorAtEnd|CLI_SendEndSignal);
Buffer_Identifier id = buffer_identifier(out_buffer);
exec_system_command(app, view, id, hot_directory, cmd, CLI_OverlapWithConflict|CLI_CursorAtEnd|CLI_SendEndSignal);
lock_jump_buffer(out_buffer);
}
}
CUSTOM_COMMAND_SIG(execute_any_cli)
CUSTOM_DOC("Queries for an output buffer name and system command, runs the system command as a CLI and prints the output to the specified buffer."){
Query_Bar bar_out = {};
Query_Bar bar_cmd = {};
Scratch_Block scratch(app);
bar_out.prompt = make_lit_string("Output Buffer: ");
bar_out.string = make_fixed_width_string(out_buffer_space);
Query_Bar bar_out = {};
bar_out.prompt = string_u8_litexpr("Output Buffer: ");
bar_out.string = SCu8(out_buffer_space, (umem)0);
bar_out.string_capacity = sizeof(out_buffer_space);
if (!query_user_string(app, &bar_out)) return;
bar_cmd.prompt = make_lit_string("Command: ");
bar_cmd.string = make_fixed_width_string(command_space);
Query_Bar bar_cmd = {};
bar_cmd.prompt = string_u8_litexpr("Command: ");
bar_cmd.string = SCu8(command_space, (umem)0);
bar_cmd.string_capacity = sizeof(command_space);
if (!query_user_string(app, &bar_cmd)) return;
directory_get_hot(app, hot_directory_space, sizeof(hot_directory_space));
String_Const_u8 hot = push_hot_directory(app, scratch);
{
umem size = clamp_top(hot.size, sizeof(hot_directory_space));
block_copy(hot_directory_space, hot.str, size);
hot_directory_space[hot.size] = 0;
}
execute_previous_cli(app);
}

View File

@ -31,7 +31,7 @@ view_get_ui_data(Application_Links *app, View_ID view_id, View_Get_UI_Flags flag
storage.data = ui_data;
storage.arena = arena;
storage.arena_object = arena_object;
storage.temp = begin_temp_memory(arena);
storage.temp = begin_temp(arena);
if (managed_object_store_data(app, new_ui_data_object, 0, 1, &storage)){
if (managed_variable_set(app, scope, view_ui_data, new_ui_data_object)){
ui_data_object = new_ui_data_object;
@ -45,7 +45,7 @@ view_get_ui_data(Application_Links *app, View_ID view_id, View_Get_UI_Flags flag
*ui_data_out = storage.data;
*ui_arena_out = storage.arena;
if ((flags & ViewGetUIFlag_ClearData) != 0){
end_temp_memory(storage.temp);
end_temp(storage.temp);
}
result = true;
}
@ -297,8 +297,6 @@ init_lister_state(Application_Links *app, Lister_State *state, Heap *heap){
state->item_index = 0;
state->set_view_vertical_focus_to_item = false;
state->item_count_after_filter = 0;
arena_release_all(&state->lister.arena);
memset(&state->lister, 0, sizeof(state->lister));
}
UI_QUIT_FUNCTION(lister_quit_function){
@ -308,9 +306,8 @@ UI_QUIT_FUNCTION(lister_quit_function){
}
static UI_Item
lister_get_clicked_item(Application_Links *app, View_ID view_id, Partition *scratch){
lister_get_clicked_item(Application_Links *app, View_ID view_id){
UI_Item result = {};
Temp_Memory temp = begin_temp_memory(scratch);
UI_Data *ui_data = 0;
Arena *ui_arena = 0;
if (view_get_ui_data(app, view_id, ViewGetUIFlag_KeepDataAsIs, &ui_data, &ui_arena)){
@ -327,7 +324,6 @@ lister_get_clicked_item(Application_Links *app, View_ID view_id, Partition *scra
result = *clicked;
}
}
end_temp_memory(temp);
return(result);
}
@ -349,7 +345,7 @@ lister_get_block_height(f32 line_height, b32 is_theme_list){
}
static void
lister_update_ui(Application_Links *app, Partition *scratch, View_ID view, Lister_State *state){
lister_update_ui(Application_Links *app, View_ID view, Lister_State *state){
b32 is_theme_list = state->lister.data.theme_list;
Rect_f32 screen_rect = {};
@ -369,7 +365,8 @@ lister_update_ui(Application_Links *app, Partition *scratch, View_ID view, Liste
f32 block_height = lister_get_block_height(line_height, is_theme_list);
f32 text_field_height = lister_get_text_field_height(metrics.line_height);
Temp_Memory full_temp = begin_temp_memory(scratch);
Arena *scratch = context_get_arena(app);
Temp_Memory full_temp = begin_temp(scratch);
// TODO(allen): switch to float
Rect_i32 buffer_region = {};
@ -388,21 +385,25 @@ lister_update_ui(Application_Links *app, Partition *scratch, View_ID view, Liste
Lister_Node_Ptr_Array substring_matches = {};
substring_matches.node_ptrs = push_array(scratch, Lister_Node*, node_count);
String key = state->lister.data.key_string;
Absolutes absolutes = {};
get_absolutes(key, &absolutes, true, true);
b32 has_wildcard = (absolutes.count > 3);
String_Const_u8 key = state->lister.data.key_string.string;
List_String_Const_u8 absolutes = {};
string_list_push(scratch, &absolutes, string_u8_litexpr(""));
List_String_Const_u8 splits = string_split(scratch, key, (u8*)"*", 1);
b32 has_wildcard = (splits.node_count > 1);
string_list_push(&absolutes, &splits);
string_list_push(scratch, &absolutes, string_u8_litexpr(""));
for (Lister_Node *node = state->lister.data.options.first;
node != 0;
node = node->next){
if (key.size == 0 ||
wildcard_match_s(&absolutes, node->string, false)){
if (match_insensitive(node->string, key) && exact_matches.count == 0){
string_wildcard_match_insensitive(absolutes, node->string)){
String_Const_u8 node_string = node->string;
if (string_match_insensitive(node_string, key) && exact_matches.count == 0){
exact_matches.node_ptrs[exact_matches.count++] = node;
}
else if (!has_wildcard &&
match_part_insensitive(node->string, key) &&
string_match_insensitive(string_prefix(node_string, key.size), key) &&
node->string.size > key.size &&
node->string.str[key.size] == '.'){
before_extension_matches.node_ptrs[before_extension_matches.count++] = node;
@ -458,7 +459,7 @@ lister_update_ui(Application_Links *app, Partition *scratch, View_ID view, Liste
else{
//i32 style_index = node->index;
String name = make_lit_string("name");
String_Const_u8 name = string_u8_litexpr("name");
item.lines[0] = fancy_string_list_single(push_fancy_string(ui_arena, fancy_id(Stag_Default), name));
Fancy_String_List list = {};
@ -531,9 +532,9 @@ lister_update_ui(Application_Links *app, Partition *scratch, View_ID view, Liste
item.inner_margin = 0;
{
Fancy_String_List list = {};
push_fancy_string (ui_arena, &list, fancy_id(Stag_Pop1 ), state->lister.data.query);
push_fancy_string (ui_arena, &list, fancy_id(Stag_Pop1 ), state->lister.data.query.string);
push_fancy_stringf(ui_arena, &list, fancy_id(Stag_Pop1 ), " ");
push_fancy_string (ui_arena, &list, fancy_id(Stag_Default), state->lister.data.text_field);
push_fancy_string (ui_arena, &list, fancy_id(Stag_Default), state->lister.data.text_field.string);
item.lines[0] = list;
item.line_count = 1;
}
@ -550,11 +551,11 @@ lister_update_ui(Application_Links *app, Partition *scratch, View_ID view, Liste
view_set_quit_ui_handler(app, view, lister_quit_function);
}
end_temp_memory(full_temp);
end_temp(full_temp);
}
static Lister_Prealloced_String
lister_prealloced(String string){
lister_prealloced(String_Const_u8 string){
Lister_Prealloced_String result = {};
result.string = string;
return(result);
@ -562,11 +563,16 @@ lister_prealloced(String string){
static void
lister_first_init(Application_Links *app, Lister *lister, void *user_data, i32 user_data_size){
memset(lister, 0, sizeof(*lister));
lister->arena = make_arena(app, (16 << 10));
lister->data.query = make_fixed_width_string(lister->data.query_space);
lister->data.text_field = make_fixed_width_string(lister->data.text_field_space);
lister->data.key_string = make_fixed_width_string(lister->data.key_string_space);
if (lister->arena.base_allocator == 0) {
lister->arena = make_arena_app_links(app, KB(16));
}
else{
linalloc_clear(&lister->arena);
}
block_zero_struct(&lister->data);
lister->data.query = Su8(lister->data.query_space, 0, sizeof(lister->data.query_space));
lister->data.text_field = Su8(lister->data.text_field_space, 0, sizeof(lister->data.text_field_space));
lister->data.key_string = Su8(lister->data.key_string_space, 0, sizeof(lister->data.key_string_space));
lister->data.user_data = push_array(&lister->arena, char, user_data_size);
lister->data.user_data_size = user_data_size;
push_align(&lister->arena, 8);
@ -576,45 +582,45 @@ lister_first_init(Application_Links *app, Lister *lister, void *user_data, i32 u
}
static void
lister_begin_new_item_set(Application_Links *app, Lister *lister, i32 list_memory_size){
arena_release_all(&lister->arena);
memset(&lister->data.options, 0, sizeof(lister->data.options));
lister_begin_new_item_set(Application_Links *app, Lister *lister){
linalloc_clear(&lister->arena);
block_zero_struct(&lister->data.options);
}
static void*
lister_add_item(Lister *lister, Lister_Prealloced_String string, Lister_Prealloced_String status,
void *user_data, i32 extra_space){
Lister_Node *node = push_array(&lister->arena, Lister_Node, 1);
void *user_data, umem extra_space){
void *base_memory = push_array(&lister->arena, u8, sizeof(Lister_Node) + extra_space);
Lister_Node *node = (Lister_Node*)base_memory;
node->string = string.string;
node->status = status.string;
node->user_data = user_data;
node->raw_index = lister->data.options.count;
zdll_push_back(lister->data.options.first, lister->data.options.last, node);
lister->data.options.count += 1;
void *result = push_array(&lister->arena, char, extra_space);
push_align(&lister->arena, 8);
void *result = (node + 1);
return(result);
}
static void*
lister_add_item(Lister *lister, Lister_Prealloced_String string, String status,
void *user_data, i32 extra_space){
return(lister_add_item(lister, string, lister_prealloced(string_push_copy(&lister->arena, status)),
lister_add_item(Lister *lister, Lister_Prealloced_String string, String_Const_u8 status,
void *user_data, umem extra_space){
return(lister_add_item(lister, string, lister_prealloced(string_copy(&lister->arena, status)),
user_data, extra_space));
}
static void*
lister_add_item(Lister *lister, String string, Lister_Prealloced_String status,
void *user_data, i32 extra_space){
return(lister_add_item(lister, lister_prealloced(string_push_copy(&lister->arena, string)), status,
lister_add_item(Lister *lister, String_Const_u8 string, Lister_Prealloced_String status,
void *user_data, umem extra_space){
return(lister_add_item(lister, lister_prealloced(string_copy(&lister->arena, string)), status,
user_data, extra_space));
}
static void*
lister_add_item(Lister *lister, String string, String status, void *user_data, i32 extra_space){
lister_add_item(Lister *lister, String_Const_u8 string, String_Const_u8 status, void *user_data, umem extra_space){
return(lister_add_item(lister,
lister_prealloced(string_push_copy(&lister->arena, string)),
lister_prealloced(string_push_copy(&lister->arena, status)),
lister_prealloced(string_copy(&lister->arena, string)),
lister_prealloced(string_copy(&lister->arena, status)),
user_data, extra_space));
}
@ -635,9 +641,9 @@ lister_add_theme_item(Lister *lister,
}
static void*
lister_add_theme_item(Lister *lister, String string, i32 index,
lister_add_theme_item(Lister *lister, String_Const_u8 string, i32 index,
void *user_data, i32 extra_space){
return(lister_add_theme_item(lister, lister_prealloced(string_push_copy(&lister->arena, string)), index,
return(lister_add_theme_item(lister, lister_prealloced(string_copy(&lister->arena, string)), index,
user_data, extra_space));
}
@ -666,13 +672,13 @@ lister_call_refresh_handler(Application_Links *app, Lister *lister){
}
static void
lister_default(Application_Links *app, Partition *scratch, Heap *heap, View_ID view, Lister_State *state, Lister_Activation_Code code){
lister_default(Application_Links *app, Heap *heap, View_ID view, Lister_State *state, Lister_Activation_Code code){
switch (code){
case ListerActivation_Finished:
{
view_end_ui_mode(app, view);
state->initialized = false;
arena_release_all(&state->lister.arena);
linalloc_clear(&state->lister.arena);
}break;
case ListerActivation_Continue:
@ -685,50 +691,130 @@ lister_default(Application_Links *app, Partition *scratch, Heap *heap, View_ID v
view_begin_ui_mode(app, view);
state->item_index = 0;
lister_call_refresh_handler(app, &state->lister);
lister_update_ui(app, scratch, view, state);
lister_update_ui(app, view, state);
}break;
}
}
static void
lister_call_activate_handler(Application_Links *app, Partition *scratch, Heap *heap, View_ID view, Lister_State *state, void *user_data, b32 activated_by_mouse){
lister_call_activate_handler(Application_Links *app, Heap *heap, View_ID view, Lister_State *state, void *user_data, b32 activated_by_mouse){
Lister_Data *lister = &state->lister.data;
if (lister->handlers.activate != 0){
lister->handlers.activate(app, scratch, heap, view, state, lister->text_field, user_data, activated_by_mouse);
lister->handlers.activate(app, heap, view, state, lister->text_field.string, user_data, activated_by_mouse);
}
else{
lister_default(app, scratch, heap, view, state, ListerActivation_Finished);
lister_default(app, heap, view, state, ListerActivation_Finished);
}
}
static void
lister_set_query_string(Lister_Data *lister, char *string){
copy(&lister->query, string);
lister_set_string(String_Const_u8 string, String_u8 *target){
target->size = 0;
string_append(target, string);
}
static void
lister_append_string(String_Const_u8 string, String_u8 *target){
string_append(target, string);
}
static void
lister_set_query_string(Lister_Data *lister, String string){
copy(&lister->query, string);
lister_set_query(Lister_Data *lister, String_Const_u8 string){
lister_set_string(string, &lister->query);
}
static void
lister_set_query(Lister_Data *lister, char *string){
lister_set_string(SCu8(string), &lister->query);
}
static void
lister_set_text_field(Lister_Data *lister, String_Const_u8 string){
lister_set_string(string, &lister->text_field);
}
static void
lister_set_text_field(Lister_Data *lister, char *string){
lister_set_string(SCu8(string), &lister->text_field);
}
static void
lister_set_key(Lister_Data *lister, String_Const_u8 string){
lister_set_string(string, &lister->key_string);
}
static void
lister_set_key(Lister_Data *lister, char *string){
lister_set_string(SCu8(string), &lister->key_string);
}
static void
lister_set_text_field_string(Lister_Data *lister, char *string){
copy(&lister->text_field, string);
lister_set_query(Lister *lister, String_Const_u8 string){
lister_set_query(&lister->data, string);
}
static void
lister_set_query(Lister *lister, char *string){
lister_set_query(&lister->data, string);
}
static void
lister_set_text_field(Lister *lister, String_Const_u8 string){
lister_set_text_field(&lister->data, string);
}
static void
lister_set_text_field(Lister *lister, char *string){
lister_set_text_field(&lister->data, string);
}
static void
lister_set_key(Lister *lister, String_Const_u8 string){
lister_set_key(&lister->data, string);
}
static void
lister_set_key(Lister *lister, char *string){
lister_set_key(&lister->data, string);
}
static void
lister_set_text_field_string(Lister_Data *lister, String string){
copy(&lister->text_field, string);
lister_append_query(Lister_Data *lister, String_Const_u8 string){
lister_append_string(string, &lister->query);
}
static void
lister_append_query(Lister_Data *lister, char *string){
lister_append_string(SCu8(string), &lister->query);
}
static void
lister_append_text_field(Lister_Data *lister, String_Const_u8 string){
lister_append_string(string, &lister->text_field);
}
static void
lister_append_text_field(Lister_Data *lister, char *string){
lister_append_string(SCu8(string), &lister->text_field);
}
static void
lister_append_key(Lister_Data *lister, String_Const_u8 string){
lister_append_string(string, &lister->key_string);
}
static void
lister_append_key(Lister_Data *lister, char *string){
lister_append_string(SCu8(string), &lister->key_string);
}
static void
lister_set_key_string(Lister_Data *lister, char *string){
copy(&lister->key_string, string);
lister_append_query(Lister *lister, String_Const_u8 string){
lister_append_query(&lister->data, string);
}
static void
lister_set_key_string(Lister_Data *lister, String string){
copy(&lister->key_string, string);
lister_append_query(Lister *lister, char *string){
lister_append_query(&lister->data, string);
}
static void
lister_append_text_field(Lister *lister, String_Const_u8 string){
lister_append_text_field(&lister->data, string);
}
static void
lister_append_text_field(Lister *lister, char *string){
lister_append_text_field(&lister->data, string);
}
static void
lister_append_key(Lister *lister, String_Const_u8 string){
lister_append_key(&lister->data, string);
}
static void
lister_append_key(Lister *lister, char *string){
lister_append_key(&lister->data, string);
}
// BOTTOM

View File

@ -48,7 +48,7 @@ struct UI_Storage{
UI_Data *data;
Arena *arena;
Managed_Object arena_object;
Temp_Memory_Arena temp;
Temp_Memory temp;
};
////////////////////////////////
@ -60,18 +60,18 @@ enum{
ListerActivation_ContinueAndRefresh = 2,
};
typedef void Lister_Activation_Function_Type(Application_Links *app, Partition *scratch, Heap *heap,
typedef void Lister_Activation_Function_Type(Application_Links *app, Heap *heap,
View_ID view, struct Lister_State *state,
String text_field, void *user_data, b32 activated_by_mouse);
String_Const_u8 text_field, void *user_data, b32 activated_by_mouse);
typedef void Lister_Regenerate_List_Function_Type(Application_Links *app, struct Lister *lister);
struct Lister_Node{
Lister_Node *next;
Lister_Node *prev;
String string;
String_Const_u8 string;
union{
String status;
String_Const_u8 status;
i32 index;
};
void *user_data;
@ -105,12 +105,12 @@ struct Lister_Data{
// List Data
void *user_data;
i32 user_data_size;
char query_space[256];
String query;
char text_field_space[256];
String text_field;
char key_string_space[256];
String key_string;
u8 query_space[256];
u8 text_field_space[256];
u8 key_string_space[256];
String_u8 query;
String_u8 text_field;
String_u8 key_string;
Lister_Option_List options;
b32 theme_list;
};
@ -137,14 +137,14 @@ struct Lister_State{
};
struct Lister_Prealloced_String{
String string;
String_Const_u8 string;
};
////////////////////////////////
struct Lister_Option{
String string;
String status;
String_Const_u8 string;
String_Const_u8 status;
void *user_data;
};

208
4ed.cpp
View File

@ -119,8 +119,8 @@ SCROLL_RULE_SIG(fallback_scroll_rule){
#define DEFAULT_UI_MAP_SIZE 32
internal void
setup_ui_commands(Command_Map *commands, Partition *part, i32 parent){
map_init(commands, part, DEFAULT_UI_MAP_SIZE, parent);
setup_ui_commands(Command_Map *commands, Cursor *cursor, i32 parent){
map_init(commands, cursor, DEFAULT_UI_MAP_SIZE, parent);
// TODO(allen): do(fix the weird built-in-ness of the ui map)
u8 mdfr_array[] = {MDFR_NONE, MDFR_SHIFT, MDFR_CTRL, MDFR_SHIFT | MDFR_CTRL};
for (i32 i = 0; i < 4; ++i){
@ -134,24 +134,23 @@ setup_ui_commands(Command_Map *commands, Partition *part, i32 parent){
}
internal void
setup_file_commands(Command_Map *commands, Partition *part, i32 parent){
map_init(commands, part, DEFAULT_MAP_SIZE, parent);
setup_file_commands(Command_Map *commands, Cursor *cursor, i32 parent){
map_init(commands, cursor, DEFAULT_MAP_SIZE, parent);
}
internal void
setup_top_commands(Command_Map *commands, Partition *part, i32 parent){
map_init(commands, part, DEFAULT_MAP_SIZE, parent);
setup_top_commands(Command_Map *commands, Cursor *cursor, i32 parent){
map_init(commands, cursor, DEFAULT_MAP_SIZE, parent);
}
// TODO(allen): REWRITE REWRITE REWRITE!
internal b32
interpret_binding_buffer(Models *models, void *buffer, i32 size){
b32 result = true;
Heap *gen = &models->mem.heap;
Partition *part = &models->mem.part;
Temp_Memory temp = begin_temp_memory(part);
Partition local_part = {};
Arena *scratch = &models->mem.arena;
Temp_Memory temp = begin_temp(scratch);
Mapping new_mapping = {};
@ -179,10 +178,10 @@ interpret_binding_buffer(Models *models, void *buffer, i32 size){
new_mapping.user_map_count = user_map_count;
// Initialize Table and User Maps in Temp Buffer
new_mapping.map_id_table = push_array(part, i32, user_map_count);
new_mapping.map_id_table = push_array(scratch, i32, user_map_count);
memset(new_mapping.map_id_table, -1, user_map_count*sizeof(i32));
new_mapping.user_maps = push_array(part, Command_Map, user_map_count);
new_mapping.user_maps = push_array(scratch, Command_Map, user_map_count);
memset(new_mapping.user_maps, 0, user_map_count*sizeof(Command_Map));
// Find the Size of Each Map
@ -227,12 +226,12 @@ interpret_binding_buffer(Models *models, void *buffer, i32 size){
// Add up the Map Counts
i32 count_global = DEFAULT_MAP_SIZE;
if (did_top){
count_global = clamp_bottom(6, new_mapping.map_top.count*3/2);
count_global = clamp_bot(6, new_mapping.map_top.count*3/2);
}
i32 count_file = DEFAULT_MAP_SIZE;
if (did_file){
count_file = clamp_bottom(6, new_mapping.map_file.count*3/2);
count_file = clamp_bot(6, new_mapping.map_file.count*3/2);
}
i32 count_ui = DEFAULT_UI_MAP_SIZE;
@ -240,7 +239,7 @@ interpret_binding_buffer(Models *models, void *buffer, i32 size){
i32 count_user = 0;
for (i32 i = 0; i < user_map_count; ++i){
Command_Map *map = &new_mapping.user_maps[i];
count_user += clamp_bottom(6, map->max*3/2);
count_user += clamp_bot(6, map->max*3/2);
}
i32 binding_memsize = (count_global + count_file + count_ui + count_user)*sizeof(Command_Binding);
@ -249,23 +248,23 @@ interpret_binding_buffer(Models *models, void *buffer, i32 size){
i32 map_id_table_memsize = user_map_count*sizeof(i32);
i32 user_maps_memsize = user_map_count*sizeof(Command_Map);
i32 map_id_table_rounded_memsize = l_round_up_i32(map_id_table_memsize, 8);
i32 user_maps_rounded_memsize = l_round_up_i32(user_maps_memsize, 8);
i32 map_id_table_rounded_memsize = round_up_i32(map_id_table_memsize, 8);
i32 user_maps_rounded_memsize = round_up_i32(user_maps_memsize, 8);
i32 binding_rounded_memsize = l_round_up_i32(binding_memsize, 8);
i32 binding_rounded_memsize = round_up_i32(binding_memsize, 8);
i32 needed_memsize = map_id_table_rounded_memsize + user_maps_rounded_memsize + binding_rounded_memsize;
new_mapping.memory = heap_allocate(gen, needed_memsize);
local_part = make_part(new_mapping.memory, needed_memsize);
Cursor local_cursor = make_cursor(new_mapping.memory, needed_memsize);
// Move ID Table Memory and Pointer
i32 *old_table = new_mapping.map_id_table;
new_mapping.map_id_table = push_array(&local_part, i32, user_map_count);
new_mapping.map_id_table = push_array(&local_cursor, i32, user_map_count);
memmove(new_mapping.map_id_table, old_table, map_id_table_memsize);
// Move User Maps Memory and Pointer
Command_Map *old_maps = new_mapping.user_maps;
new_mapping.user_maps = push_array(&local_part, Command_Map, user_map_count);
new_mapping.user_maps = push_array(&local_cursor, Command_Map, user_map_count);
memmove(new_mapping.user_maps, old_maps, user_maps_memsize);
// Fill in Command Maps
@ -304,8 +303,8 @@ interpret_binding_buffer(Models *models, void *buffer, i32 size){
// NOTE(allen): Map can begin multiple times, only alloc and clear when we first see it.
if (map_ptr->commands == 0){
i32 count = map->max;
i32 table_max = clamp_bottom(6, count*3/2);
map_init(map_ptr, &local_part, table_max, mapid_global);
i32 table_max = clamp_bot(6, count*3/2);
map_init(map_ptr, &local_cursor, table_max, mapid_global);
}
}
}break;
@ -424,17 +423,17 @@ interpret_binding_buffer(Models *models, void *buffer, i32 size){
}
if (!did_top){
setup_top_commands(&new_mapping.map_top, &local_part, mapid_global);
setup_top_commands(&new_mapping.map_top, &local_cursor, mapid_global);
}
if (!did_file){
setup_file_commands(&new_mapping.map_file, &local_part, mapid_global);
setup_file_commands(&new_mapping.map_file, &local_cursor, mapid_global);
}
setup_ui_commands(&new_mapping.map_ui, &local_part, mapid_global);
setup_ui_commands(&new_mapping.map_ui, &local_cursor, mapid_global);
}
else{
// TODO(allen): do(Error report: bad binding units map.)
// TODO(allen): do(no bindings set recovery plan.)
InvalidCodePath;
InvalidPath;
}
Mapping old_mapping = models->mapping;
@ -443,7 +442,7 @@ interpret_binding_buffer(Models *models, void *buffer, i32 size){
}
models->mapping = new_mapping;
end_temp_memory(temp);
end_temp(temp);
return(result);
}
@ -528,10 +527,10 @@ fill_hardcode_default_style(Color_Table color_table){
internal void
app_hardcode_default_style(Models *models){
Partition *part = &models->mem.part;
Arena *arena = &models->mem.arena;
Color_Table color_table = {};
color_table.vals = push_array(part, u32, Stag_COUNT);
color_table.count = Stag_COUNT;
color_table.vals = push_array(arena, u32, color_table.count);
fill_hardcode_default_style(color_table);
models->fallback_color_table = color_table;
}
@ -704,13 +703,59 @@ init_command_line_settings(App_Settings *settings, Plat_Settings *plat_settings,
}
}
////////////////////////////////
internal void*
base_reserve__system(void *user_data, umem size, umem *size_out){
System_Functions *system = (System_Functions*)user_data;
umem extra_size = 128;
umem increased_size = size + extra_size;
size = round_up_umem(increased_size, KB(4));
*size_out = size - extra_size;
void *ptr = system->memory_allocate(size);
*(umem*)ptr = size;
ptr = (u8*)ptr + extra_size;
return(ptr);
}
internal void
base_free__system(void *user_data, void *ptr){
System_Functions *system = (System_Functions*)user_data;
umem extra_size = 128;
ptr = (u8*)ptr - extra_size;
umem size = *(umem*)ptr;
system->memory_free(ptr, size);
}
internal Base_Allocator
make_base_allocator_system(System_Functions *system){
return(make_base_allocator(base_reserve__system, 0, 0,
base_free__system, 0, system));
}
internal Arena
make_arena_models(Models *models, umem chunk_size, umem align){
return(make_arena(&models->allocator, chunk_size, align));
}
internal Arena
make_arena_models(Models *models, umem chunk_size){
return(make_arena(&models->allocator, chunk_size, 8));
}
internal Arena
make_arena_models(Models *models){
return(make_arena(&models->allocator, KB(16), 8));
}
////////////////////////////////
internal App_Vars*
app_setup_memory(System_Functions *system, Application_Memory *memory){
Partition _partition = make_part(memory->vars_memory, memory->vars_memory_size);
App_Vars *vars = push_array(&_partition, App_Vars, 1);
Assert(vars != 0);
memset(vars, 0, sizeof(*vars));
vars->models.mem.part = _partition;
Cursor cursor = make_cursor(memory->vars_memory, memory->vars_memory_size);
App_Vars *vars = push_array_zero(&cursor, App_Vars, 1);
vars->models.allocator = make_base_allocator_system(system);
vars->models.mem.arena = make_arena(&vars->models.allocator);
heap_init(&vars->models.mem.heap);
heap_extend(&vars->models.mem.heap, memory->target_memory, memory->target_memory_size);
return(vars);
@ -813,18 +858,18 @@ App_Init_Sig(app_init){
models->keep_playing = true;
app_links_init(system, &models->app_links, memory->user_memory, memory->user_memory_size);
models->custom_layer_arena = make_arena(&models->app_links);
models->custom_layer_arena = make_arena_models(models);
models->config_api = api;
models->app_links.cmd_context = models;
Partition *part = &models->mem.part;
Arena *arena = &models->mem.arena;
// NOTE(allen): live set
{
models->live_set.count = 0;
models->live_set.max = MAX_VIEWS;
models->live_set.views = push_array(part, View, models->live_set.max);
models->live_set.views = push_array(arena, View, models->live_set.max);
//dll_init_sentinel
models->live_set.free_sentinel.next = &models->live_set.free_sentinel;
@ -843,7 +888,7 @@ App_Init_Sig(app_init){
{
umem memsize = KB(8);
void *mem = push_array(part, u8, (i32)memsize);
void *mem = push_array(arena, u8, (i32)memsize);
parse_context_init_memory(&models->parse_context_memory, mem, memsize);
parse_context_add_default(&models->parse_context_memory, &models->mem.heap);
}
@ -860,7 +905,7 @@ App_Init_Sig(app_init){
dynamic_workspace_init(&models->mem.heap, &models->lifetime_allocator, DynamicWorkspace_Global, 0, &models->dynamic_workspace);
// NOTE(allen): file setup
working_set_init(system, &models->working_set, part, &vars->models.mem.heap);
working_set_init(system, &models->working_set, arena, &vars->models.mem.heap);
models->working_set.default_display_width = DEFAULT_DISPLAY_WIDTH;
models->working_set.default_minimum_base_display_width = DEFAULT_MINIMUM_BASE_DISPLAY_WIDTH;
@ -876,8 +921,8 @@ App_Init_Sig(app_init){
// TODO(allen): do(better clipboard allocation)
if (clipboard.str != 0){
String *dest = working_set_next_clipboard_string(&models->mem.heap, &models->working_set, clipboard.size);
copy(dest, make_string((char*)clipboard.str, clipboard.size));
String_Const_u8 *dest = working_set_next_clipboard_string(&models->mem.heap, &models->working_set, clipboard.size);
block_copy(dest->str, clipboard.str, clipboard.size);
}
// NOTE(allen): style setup
@ -887,7 +932,7 @@ App_Init_Sig(app_init){
// NOTE(allen): title space
models->has_new_title = true;
models->title_capacity = KB(4);
models->title_space = push_array(part, char, models->title_capacity);
models->title_space = push_array(arena, char, models->title_capacity);
{
String builder = make_string_cap(models->title_space, 0, models->title_capacity);
append(&builder, WINDOW_NAME);
@ -900,21 +945,21 @@ App_Init_Sig(app_init){
// NOTE(allen): init baked in buffers
File_Init init_files[] = {
{ make_lit_string("*messages*"), &models->message_buffer, true , },
{ make_lit_string("*scratch*"), &models->scratch_buffer, false, },
{ string_u8_litinit("*messages*"), &models->message_buffer, true , },
{ string_u8_litinit("*scratch*"), &models->scratch_buffer, false, },
};
Heap *heap = &models->mem.heap;
for (i32 i = 0; i < ArrayCount(init_files); ++i){
Editing_File *file = working_set_alloc_always(&models->working_set, heap, &models->lifetime_allocator);
buffer_bind_name(models, heap, part, &models->working_set, file, init_files[i].name);
buffer_bind_name(models, heap, arena, &models->working_set, file, init_files[i].name);
if (init_files[i].ptr != 0){
*init_files[i].ptr = file;
}
File_Attributes attributes = {};
file_create_from_string(system, models, file, make_lit_string(""), attributes);
file_create_from_string(system, models, file, SCu8(), attributes);
if (init_files[i].read_only){
file->settings.read_only = true;
history_free(&models->mem.heap, &file->state.history);
@ -927,7 +972,7 @@ App_Init_Sig(app_init){
// NOTE(allen): setup first panel
{
Panel *panel = layout_initialize(part, &models->layout);
Panel *panel = layout_initialize(arena, &models->layout);
View *new_view = live_set_alloc_view(&models->mem.heap, &models->lifetime_allocator, &models->live_set, panel);
view_set_file(system, models, new_view, models->scratch_buffer);
}
@ -953,10 +998,10 @@ App_Step_Sig(app_step){
models->input = input;
// NOTE(allen): OS clipboard event handling
String clipboard = input->clipboard;
String_Const_u8 clipboard = input->clipboard;
if (clipboard.str != 0){
String *dest = working_set_next_clipboard_string(&models->mem.heap, &models->working_set, clipboard.size);
dest->size = eol_convert_in(dest->str, clipboard.str, clipboard.size);
String_Const_u8 *dest = working_set_next_clipboard_string(&models->mem.heap, &models->working_set, clipboard.size);
dest->size = eol_convert_in((char*)dest->str, (char*)clipboard.str, (i32)clipboard.size);
if (input->clipboard_changed && models->clipboard_change != 0){
models->clipboard_change(&models->app_links, *dest, ClipboardFlag_FromOS);
}
@ -968,20 +1013,20 @@ App_Step_Sig(app_step){
i32 size = 0;
i32 buffer_size = KB(32);
Partition *part = &models->mem.part;
Temp_Memory temp = begin_temp_memory(part);
char *buffer = push_array(part, char, buffer_size);
Arena *scratch = &models->mem.arena;
Temp_Memory temp = begin_temp(scratch);
char *buffer = push_array(scratch, char, buffer_size);
u32 unmark_top = 0;
u32 unmark_max = (8 << 10);
Editing_File **unmark = (Editing_File**)push_array(part, Editing_File*, unmark_max);
u32 unmark_max = Thousand(8);
Editing_File **unmark = (Editing_File**)push_array(scratch, Editing_File*, unmark_max);
Working_Set *working_set = &models->working_set;
for (;system->get_file_change(buffer, buffer_size, &mem_too_small, &size);){
Assert(!mem_too_small);
Editing_File_Name canon = {};
if (get_canon_name(system, make_string(buffer, size), &canon)){
Editing_File *file = working_set_contains_canon(working_set, canon.name);
if (get_canon_name(system, SCu8(buffer, size), &canon)){
Editing_File *file = working_set_contains_canon(working_set, string_from_file_name(&canon));
if (file != 0){
if (file->state.ignore_behind_os == 0){
file_add_dirty_flag(file, DirtyState_UnloadedChanges);
@ -1001,7 +1046,7 @@ App_Step_Sig(app_step){
unmark[i]->state.ignore_behind_os = 0;
}
end_temp_memory(temp);
end_temp(temp);
}
// NOTE(allen): reorganizing panels on screen
@ -1012,10 +1057,10 @@ App_Step_Sig(app_step){
// NOTE(allen): update child processes
f32 dt = input->dt;
if (dt > 0){
Partition *scratch = &models->mem.part;
Arena *scratch = &models->mem.arena;
Child_Process_Container *child_processes = &models->child_processes;
Temp_Memory temp = begin_temp_memory(scratch);
Temp_Memory temp = begin_temp(scratch);
Child_Process **processes_to_free = push_array(scratch, Child_Process*, child_processes->active_child_process_count);
i32 processes_to_free_count = 0;
@ -1065,7 +1110,7 @@ App_Step_Sig(app_step){
child_process_free(child_processes, processes_to_free[i]->id);
}
end_temp_memory(temp);
end_temp(temp);
}
// NOTE(allen): input filter and simulated events
@ -1361,7 +1406,9 @@ App_Step_Sig(app_step){
File_Edit_Finished_Function *hook_file_edit_finished = models->hook_file_edit_finished;
if (hook_file_edit_finished != 0){
Working_Set *working_set = &models->working_set;
if (working_set->edit_finished_list.next != &working_set->edit_finished_list){
if (working_set->edit_finished_count > 0){
Assert(working_set->edit_finished_list_first != 0);
Assert(working_set->edit_finished_list_last != 0);
b32 trigger_hook = false;
u32 elapse_time = models->edit_finished_hook_repeat_speed;
@ -1381,24 +1428,21 @@ App_Step_Sig(app_step){
trigger_hook = true;
}
if (trigger_hook){
Partition *scratch = &models->mem.part;
Arena *scratch = &models->mem.arena;
Temp_Memory temp = begin_temp(scratch);
Node *first = working_set->edit_finished_list_first;
Temp_Memory temp = begin_temp_memory(scratch);
Node *first = working_set->edit_finished_list.next;
Node *stop = &working_set->edit_finished_list;
Editing_File **file_ptrs = push_array(scratch, Editing_File*, 0);
i32 max_id_count = working_set->edit_finished_count;
Editing_File **file_ptrs = push_array(scratch, Editing_File*, max_id_count);
Buffer_ID *ids = push_array(scratch, Buffer_ID, max_id_count);
i32 id_count = 0;
for (Node *node = first;
node != stop;
node != 0;
node = node->next){
Editing_File **file_ptr = push_array(scratch, Editing_File*, 1);
*file_ptr = CastFromMember(Editing_File, edit_finished_mark_node, node);
}
i32 id_count = (i32)(push_array(scratch, Editing_File*, 0) - file_ptrs);
Buffer_ID *ids = push_array(scratch, Buffer_ID, id_count);
for (i32 i = 0; i < id_count; i += 1){
ids[i] = file_ptrs[i]->id.id;
Editing_File *file_ptr = CastFromMember(Editing_File, edit_finished_mark_node, node);
file_ptrs[id_count] = file_ptr;
ids[id_count] = file_ptr->id.id;
id_count += 1;
}
working_set->do_not_mark_edits = true;
@ -1406,13 +1450,15 @@ App_Step_Sig(app_step){
working_set->do_not_mark_edits = false;
for (i32 i = 0; i < id_count; i += 1){
block_zero_struct(&file_ptrs[i]->edit_finished_mark_node);
file_ptrs[i]->edit_finished_marked = false;
}
dll_init_sentinel(&working_set->edit_finished_list);
working_set->edit_finished_list_first = 0;
working_set->edit_finished_list_last = 0;
working_set->edit_finished_count = 0;
working_set->time_of_next_edit_finished_signal = 0;
end_temp_memory(temp);
end_temp(temp);
}
}
}

7
4ed.h
View File

@ -14,6 +14,7 @@
#define MAX_VIEWS 16
// TODO(allen): This is DONE! GET RID OF IT NAO!
struct Application_Memory{
void *vars_memory;
i32 vars_memory_size;
@ -66,7 +67,7 @@ struct Plat_Settings{
};
#define App_Read_Command_Line_Sig(name) \
i32 name(System_Functions *system, Application_Memory *memory, String current_directory, Plat_Settings *plat_settings, char ***files, i32 **file_count, i32 argc, char **argv)
i32 name(System_Functions *system, Application_Memory *memory, String_Const_u8 current_directory, Plat_Settings *plat_settings, char ***files, i32 **file_count, i32 argc, char **argv)
typedef App_Read_Command_Line_Sig(App_Read_Command_Line);
@ -76,7 +77,7 @@ struct Custom_API{
};
#define App_Init_Sig(name) \
void name(System_Functions *system, Render_Target *target, Application_Memory *memory, String clipboard, String current_directory, Custom_API api)
void name(System_Functions *system, Render_Target *target, Application_Memory *memory, String_Const_u8 clipboard, String_Const_u8 current_directory, Custom_API api)
typedef App_Init_Sig(App_Init);
@ -96,7 +97,7 @@ struct Application_Step_Input{
f32 dt;
Key_Input_Data keys;
Mouse_State mouse;
String clipboard;
String_Const_u8 clipboard;
b32 clipboard_changed;
b32 trying_to_kill;
u32 debug_number;

View File

@ -9,25 +9,11 @@
// TOP
#define API_EXPORT
internal b32
access_test(u32 lock_flags, u32 access_flags){
return((lock_flags & ~access_flags) == 0);
}
internal b32
api_string_out(String val, String *out, i32 *required_size_out){
b32 result = false;
if (required_size_out != 0){
*required_size_out = val.size;
}
if (out != 0){
result = append_partial(out, val);
}
return(result);
}
internal b32
api_check_panel(Panel *panel){
b32 result = false;
@ -111,8 +97,14 @@ Context_Get_Arena(Application_Links *app){
return(&models->custom_layer_arena);
}
API_EXPORT Base_Allocator*
Context_Get_Base_Allocator(Application_Links *app){
Models *models = (Models*)app->cmd_context;
return(&models->allocator);
}
API_EXPORT b32
Create_Child_Process(Application_Links *app, String path, String command, Child_Process_ID *child_process_id_out){
Create_Child_Process(Application_Links *app, String_Const_u8 path, String_Const_u8 command, Child_Process_ID *child_process_id_out){
Models *models = (Models*)app->cmd_context;
System_Functions *system = models->system;
return(child_process_call(models, system, path, command, child_process_id_out));
@ -176,7 +168,7 @@ Child_Process_Get_State(Application_Links *app, Child_Process_ID child_process_i
// TODO(allen): redocument
API_EXPORT b32
Clipboard_Post(Application_Links *app, i32 clipboard_id, String string)
Clipboard_Post(Application_Links *app, i32 clipboard_id, String_Const_u8 string)
/*
DOC_PARAM(clipboard_id, This parameter is set up to prepare for future features, it should always be 0 for now.)
DOC_PARAM(str, The str parameter specifies the string to be posted to the clipboard, it need not be null terminated.)
@ -185,8 +177,8 @@ DOC(Stores the string str in the clipboard initially with index 0. Also reports
DOC_SEE(The_4coder_Clipboard)
*/{
Models *models = (Models*)app->cmd_context;
String *dest = working_set_next_clipboard_string(&models->mem.heap, &models->working_set, string.size);
copy(dest, string);
String_Const_u8 *dest = working_set_next_clipboard_string(&models->mem.heap, &models->working_set, (i32)string.size);
block_copy(dest->str, string.str, string.size);
models->system->post_clipboard(*dest);
return(true);
}
@ -205,8 +197,9 @@ DOC_SEE(The_4coder_Clipboard)
return(true);
}
// TODO(allen): redocument
API_EXPORT b32
Clipboard_Index(Application_Links *app, i32 clipboard_id, i32 item_index, String *string_out, i32 *required_size_out)
Clipboard_Index(Application_Links *app, i32 clipboard_id, i32 item_index, Arena *out, String_Const_u8 *string_out)
/*
DOC_PARAM(clipboard_id, This parameter is set up to prepare for future features, it should always be 0 for now.)
DOC_PARAM(item_index, This parameter specifies which item to read, 0 is the most recent copy, 1 is the second most recent copy, etc.)
@ -220,11 +213,11 @@ it is filled with the first len character of the clipboard contents. The output
DOC_SEE(The_4coder_Clipboard)
*/{
Models *models = (Models*)app->cmd_context;
*required_size_out = 0;
String *str = working_set_clipboard_index(&models->working_set, item_index);
String_Const_u8 *str = working_set_clipboard_index(&models->working_set, item_index);
b32 result = false;
if (str != 0){
result = api_string_out(*str, string_out, required_size_out);
*string_out = string_copy(out, *str);
result = true;
}
return(result);
}
@ -290,7 +283,7 @@ DOC_SEE(get_buffer_first)
// TODO(allen): redocument
API_EXPORT b32
Get_Buffer_By_Name(Application_Links *app, String name, Access_Flag access, Buffer_ID *buffer_id_out)
Get_Buffer_By_Name(Application_Links *app, String_Const_u8 name, Access_Flag access, Buffer_ID *buffer_id_out)
/*
DOC_PARAM(name, The name parameter specifies the buffer name to try to get. The string need not be null terminated.)
DOC_PARAM(len, The len parameter specifies the length of the name string.)
@ -315,7 +308,7 @@ DOC_SEE(Access_Flag)
// TODO(allen): redocument
API_EXPORT b32
Get_Buffer_By_File_Name(Application_Links *app, String file_name, Access_Flag access, Buffer_ID *buffer_id_out)
Get_Buffer_By_File_Name(Application_Links *app, String_Const_u8 file_name, Access_Flag access, Buffer_ID *buffer_id_out)
/*
DOC_PARAM(name, The name parameter specifies the buffer name to try to get. The string need not be null terminated.)
DOC_PARAM(len, The len parameter specifies the length of the name string.)
@ -334,7 +327,7 @@ DOC_SEE(Access_Flag)
Editing_File_Name canon = {};
b32 result = false;
if (get_canon_name(system, file_name, &canon)){
Editing_File *file = working_set_contains_canon(working_set, canon.name);
Editing_File *file = working_set_contains_canon(working_set, string_from_file_name(&canon));
if (api_check_buffer(file, access)){
*buffer_id_out = file->id.id;
result = true;
@ -372,7 +365,7 @@ DOC_SEE(4coder_Buffer_Positioning_System)
// TODO(allen): redocument
API_EXPORT b32
Buffer_Replace_Range(Application_Links *app, Buffer_ID buffer_id, Range range, String string)
Buffer_Replace_Range(Application_Links *app, Buffer_ID buffer_id, Range range, String_Const_u8 string)
/*
DOC_PARAM(buffer, This parameter specifies the buffer to edit.)
DOC_PARAM(start, This parameter specifies absolute position of the first character in the replace range.)
@ -395,7 +388,7 @@ DOC_SEE(4coder_Buffer_Positioning_System)
size = buffer_size(&file->state.buffer);
if (0 <= range.first && range.first <= range.one_past_last && range.one_past_last <= size){
Edit_Behaviors behaviors = {};
edit_single(models->system, models, file, range, string, behaviors);
edit_single(models->system, models, file, range, string_old_from_new(string), behaviors);
result = true;
}
}
@ -512,34 +505,37 @@ Buffer_Get_Line_Count(Application_Links *app, Buffer_ID buffer_id, i32 *line_cou
}
API_EXPORT b32
Buffer_Get_Base_Buffer_Name(Application_Links *app, Buffer_ID buffer_id, String *name_out, i32 *required_size_out){
Buffer_Get_Base_Buffer_Name(Application_Links *app, Buffer_ID buffer_id, Arena *out, String_Const_u8 *name_out){
Models *models = (Models*)app->cmd_context;
Editing_File *file = imp_get_file(models, buffer_id);
b32 result = false;
if (api_check_buffer(file)){
result = api_string_out(file->base_name.name, name_out, required_size_out);
*name_out = string_copy(out, string_from_file_name(&file->base_name));
result = true;
}
return(result);
}
API_EXPORT b32
Buffer_Get_Unique_Buffer_Name(Application_Links *app, Buffer_ID buffer_id, String *name_out, i32 *required_size_out){
Buffer_Get_Unique_Buffer_Name(Application_Links *app, Buffer_ID buffer_id, Arena *out, String_Const_u8 *name_out){
Models *models = (Models*)app->cmd_context;
Editing_File *file = imp_get_file(models, buffer_id);
b32 result = false;
if (api_check_buffer(file)){
result = api_string_out(file->unique_name.name, name_out, required_size_out);
*name_out = string_copy(out, string_from_file_name(&file->unique_name));
result = true;
}
return(result);
}
API_EXPORT b32
Buffer_Get_File_Name(Application_Links *app, Buffer_ID buffer_id, String *name_out, i32 *required_size_out){
Buffer_Get_File_Name(Application_Links *app, Buffer_ID buffer_id, Arena *out, String_Const_u8 *name_out){
Models *models = (Models*)app->cmd_context;
Editing_File *file = imp_get_file(models, buffer_id);
b32 result = false;
if (api_check_buffer(file)){
result = api_string_out(file->canon.name, name_out, required_size_out);
*name_out = string_copy(out, string_from_file_name(&file->canon));
result = true;
}
return(result);
}
@ -989,7 +985,7 @@ This is useful in cases such as clearing a buffer and refilling it with new cont
// TODO(allen): redocument
API_EXPORT b32
Create_Buffer(Application_Links *app, String file_name, Buffer_Create_Flag flags, Buffer_ID *new_buffer_id_out)
Create_Buffer(Application_Links *app, String_Const_u8 file_name, Buffer_Create_Flag flags, Buffer_ID *new_buffer_id_out)
/*
DOC_PARAM(filename, The name of the file to associate to the new buffer.)
DOC_PARAM(filename_len, The length of the filename string.)
@ -1013,7 +1009,7 @@ DOC_SEE(Buffer_Create_Flag)
// TODO(allen): redocument
API_EXPORT b32
Buffer_Save(Application_Links *app, Buffer_ID buffer_id, String file_name, u32 flags)
Buffer_Save(Application_Links *app, Buffer_ID buffer_id, String_Const_u8 file_name, u32 flags)
/*
DOC_PARAM(buffer, The buffer parameter specifies the buffer to save to a file.)
DOC_PARAM(file_name, The file_name parameter specifies the name of the file to write with the contents of the buffer; it need not be null terminated.)
@ -1037,11 +1033,11 @@ DOC_SEE(Buffer_Save_Flag)
}
if (!skip_save){
Partition *part = &models->mem.part;
Temp_Memory temp = begin_temp_memory(part);
String name = push_string(part, file_name);
Arena *scratch = &models->mem.arena;
Temp_Memory temp = begin_temp(scratch);
String_Const_u8 name = string_copy(scratch, file_name);
save_file_to_name(system, models, file, name.str);
end_temp_memory(temp);
end_temp(temp);
result = true;
}
}
@ -1079,10 +1075,10 @@ DOC_SEE(Buffer_Identifier)
}
buffer_unbind_name_low_level(working_set, file);
if (file->canon.name.size != 0){
if (file->canon.name_size != 0){
buffer_unbind_file(system, working_set, file);
}
file_free(system, &models->mem.heap, &models->lifetime_allocator, file);
file_free(system, &models->mem.heap, &models->lifetime_allocator, working_set, file);
working_set_free_file(&models->mem.heap, working_set, file);
Layout *layout = &models->layout;
@ -1132,14 +1128,14 @@ Buffer_Reopen(Application_Links *app, Buffer_ID buffer_id, Buffer_Reopen_Flag fl
Editing_File *file = imp_get_file(models, buffer_id);
Buffer_Reopen_Result result = BufferReopenResult_Failed;
if (api_check_buffer(file)){
if (file->canon.name.str != 0 && file->canon.name.size != 0){
if (file->canon.name_size > 0){
Plat_Handle handle = {};
if (system->load_handle(file->canon.name.str, &handle)){
if (system->load_handle((char*)file->canon.name_space, &handle)){
File_Attributes attributes = system->load_attributes(handle);
Partition *part = &models->mem.part;
Temp_Memory temp = begin_temp_memory(part);
char *file_memory = push_array(part, char, (i32)attributes.size);
Arena *arena = &models->mem.arena;
Temp_Memory temp = begin_temp(arena);
char *file_memory = push_array(arena, char, (i32)attributes.size);
if (file_memory != 0){
if (system->load_file(handle, file_memory, (i32)attributes.size)){
@ -1157,21 +1153,21 @@ Buffer_Reopen(Application_Links *app, Buffer_ID buffer_id, Buffer_Reopen_Flag fl
panel != 0;
panel = layout_get_next_open_panel(layout, panel)){
View *view_it = panel->view;
if (view_it->file != file){
continue;
if (view_it->file == file){
vptrs[vptr_count] = view_it;
File_Edit_Positions edit_pos = view_get_edit_pos(view_it);
Full_Cursor cursor = file_compute_cursor(system, view_it->file, seek_pos(edit_pos.cursor_pos));
line_numbers[vptr_count] = cursor.line;
column_numbers[vptr_count] = cursor.character;
view_it->file = models->scratch_buffer;
++vptr_count;
}
vptrs[vptr_count] = view_it;
File_Edit_Positions edit_pos = view_get_edit_pos(view_it);
Full_Cursor cursor = file_compute_cursor(system, view_it->file, seek_pos(edit_pos.cursor_pos));
line_numbers[vptr_count] = cursor.line;
column_numbers[vptr_count] = cursor.character;
view_it->file = models->scratch_buffer;
++vptr_count;
}
file_free(system, &models->mem.heap, &models->lifetime_allocator, file);
working_set_file_default_settings(&models->working_set, file);
file_create_from_string(system, models, file, make_string(file_memory, (i32)attributes.size), attributes);
Working_Set *working_set = &models->working_set;
file_free(system, &models->mem.heap, &models->lifetime_allocator, working_set, file);
working_set_file_default_settings(working_set, file);
file_create_from_string(system, models, file, SCu8(file_memory, attributes.size), attributes);
for (i32 i = 0; i < vptr_count; ++i){
view_set_file(system, models, vptrs[i], file);
@ -1191,7 +1187,7 @@ Buffer_Reopen(Application_Links *app, Buffer_ID buffer_id, Buffer_Reopen_Flag fl
system->load_close(handle);
}
end_temp_memory(temp);
end_temp(temp);
}
}
}
@ -1515,7 +1511,7 @@ Panel_Set_Split(Application_Links *app, Panel_ID panel_id, Panel_Split_Kind kind
default:
{
print_message(app, make_lit_string("Invalid split kind passed to panel_set_split, no change made to view layout"));
print_message(app, string_u8_litexpr("Invalid split kind passed to panel_set_split, no change made to view layout"));
}break;
}
layout_propogate_sizes_down_from_node(layout, panel);
@ -2170,7 +2166,7 @@ get_lifetime_object_from_workspace(Dynamic_Workspace *workspace){
}break;
default:
{
InvalidCodePath;
InvalidPath;
}break;
}
return(result);
@ -2188,12 +2184,21 @@ https://4coder.handmade.network/blogs/p/3412-new_features_p3__memory_management_
{
Models *models = (Models*)app->cmd_context;
Lifetime_Allocator *lifetime_allocator = &models->lifetime_allocator;
Partition *scratch = &models->mem.part;
Arena *scratch = &models->mem.arena;
Temp_Memory temp = begin_temp_memory(scratch);
Temp_Memory temp = begin_temp(scratch);
// TODO(allen): revisit this
struct Node_Ptr{
Node_Ptr *next;
Lifetime_Object *object_ptr;
};
Node_Ptr *first = 0;
Node_Ptr *last = 0;
i32 member_count = 0;
b32 filled_array = true;
Lifetime_Object **object_ptr_array = push_array(scratch, Lifetime_Object*, 0);
for (i32 i = 0; i < count; i += 1){
Dynamic_Workspace *workspace = get_dynamic_workspace(models, scopes[i]);
if (workspace == 0){
@ -2213,40 +2218,51 @@ https://4coder.handmade.network/blogs/p/3412-new_features_p3__memory_management_
{
Lifetime_Object *object = get_lifetime_object_from_workspace(workspace);
Assert(object != 0);
Lifetime_Object **new_object_ptr = push_array(scratch, Lifetime_Object*, 1);
*new_object_ptr = object;
Node_Ptr *new_node = push_array(scratch, Node_Ptr, 1);
sll_queue_push(first, last, new_node);
new_node->object_ptr = object;
member_count += 1;
}break;
case DynamicWorkspace_Intersected:
{
Lifetime_Key *key = (Lifetime_Key*)workspace->user_back_ptr;
if (lifetime_key_check(lifetime_allocator, key)){
i32 member_count = key->count;
i32 key_member_count = key->count;
Lifetime_Object **key_member_ptr = key->members;
for (i32 j = 0; j < member_count; j += 1, key_member_ptr += 1){
Lifetime_Object **new_object_ptr = push_array(scratch, Lifetime_Object*, 1);
*new_object_ptr = *key_member_ptr;
for (i32 j = 0; j < key_member_count; j += 1, key_member_ptr += 1){
Node_Ptr *new_node = push_array(scratch, Node_Ptr, 1);
sll_queue_push(first, last, new_node);
new_node->object_ptr = *key_member_ptr;
member_count += 1;
}
}
}break;
default:
{
InvalidCodePath;
InvalidPath;
}break;
}
}
Managed_Scope result = 0;
if (filled_array){
i32 member_count = (i32)(push_array(scratch, Lifetime_Object*, 0) - object_ptr_array);
Lifetime_Object **object_ptr_array = push_array(scratch, Lifetime_Object*, member_count);
i32 index = 0;
for (Node_Ptr *node = first;
node != 0;
node = node->next){
object_ptr_array[index] = node->object_ptr;
index += 1;
}
member_count = lifetime_sort_and_dedup_object_set(object_ptr_array, member_count);
Heap *heap = &models->mem.heap;
Lifetime_Key *key = lifetime_get_or_create_intersection_key(heap, lifetime_allocator, object_ptr_array, member_count);
result = (Managed_Scope)key->dynamic_workspace.scope_id;
}
end_temp_memory(temp);
end_temp(temp);
return(result);
}
@ -2303,10 +2319,9 @@ DOC_SEE(managed_variable_create_or_get_id)
*/
{
Models *models = (Models*)app->cmd_context;
String name = make_string_slowly(null_terminated_name);
Heap *heap = &models->mem.heap;
Dynamic_Variable_Layout *layout = &models->variable_layout;
return(dynamic_variables_create(heap, layout, name, default_value));
return(dynamic_variables_create(heap, layout, SCu8(null_terminated_name), default_value));
}
API_EXPORT Managed_Variable_ID
@ -2319,9 +2334,8 @@ DOC_SEE(managed_variable_create_or_get_id)
*/
{
Models *models = (Models*)app->cmd_context;
String name = make_string_slowly(null_terminated_name);
Dynamic_Variable_Layout *layout = &models->variable_layout;
return(dynamic_variables_lookup(layout, name));
return(dynamic_variables_lookup(layout, SCu8(null_terminated_name)));
}
API_EXPORT Managed_Variable_ID
@ -2336,10 +2350,9 @@ DOC_SEE(managed_variable_get_id)
*/
{
Models *models = (Models*)app->cmd_context;
String name = make_string_slowly(null_terminated_name);
Heap *heap = &models->mem.heap;
Dynamic_Variable_Layout *layout = &models->variable_layout;
return(dynamic_variables_lookup_or_create(heap, layout, name, default_value));
return(dynamic_variables_lookup_or_create(heap, layout, SCu8(null_terminated_name), default_value));
}
internal b32
@ -2551,9 +2564,9 @@ DOC_SEE(Marker_Visual_Take_Rule)
b32 result = false;
if (data != 0){
Assert(take_rule.take_count_per_step != 0);
take_rule.first_index = clamp_bottom(0, take_rule.first_index);
take_rule.take_count_per_step = clamp_bottom(1, take_rule.take_count_per_step);
take_rule.step_stride_in_marker_count = clamp_bottom(take_rule.take_count_per_step, take_rule.step_stride_in_marker_count);
take_rule.first_index = clamp_bot(0, take_rule.first_index);
take_rule.take_count_per_step = clamp_bot(1, take_rule.take_count_per_step);
take_rule.step_stride_in_marker_count = clamp_bot(take_rule.take_count_per_step, take_rule.step_stride_in_marker_count);
data->take_rule = take_rule;
if (data->take_rule.maximum_number_of_markers != 0){
i32 whole_steps = take_rule.maximum_number_of_markers/take_rule.take_count_per_step;
@ -2652,8 +2665,9 @@ DOC_RETURN(Returns the number of marker visuals that are currently attached to t
return(result);
}
// TODO(allen): redocument
API_EXPORT Marker_Visual*
Buffer_Markers_Get_Attached_Visual(Application_Links *app, Partition *part, Managed_Object object)
Buffer_Markers_Get_Attached_Visual(Application_Links *app, Arena *arena, Managed_Object object)
/*
DOC_PARAM(part, The arena to be used to allocate the returned array.)
DOC_PARAM(object, The handle to the marker object to be queried.)
@ -2665,7 +2679,7 @@ DOC_RETURN(Pushes an array onto part containing the handle to every marker visua
if (object_ptrs.header != 0 && object_ptrs.header->type == ManagedObjectType_Markers){
Managed_Buffer_Markers_Header *markers = (Managed_Buffer_Markers_Header*)object_ptrs.header;
i32 count = markers->visual_count;
Marker_Visual *visual = push_array(part, Marker_Visual, count);
Marker_Visual *visual = push_array(arena, Marker_Visual, count);
if (visual != 0){
Marker_Visual *v = visual;
Managed_Scope scope = object_ptrs.workspace->scope_id;
@ -2958,7 +2972,7 @@ DOC(Stops showing the particular query bar specified by the bar parameter.)
}
API_EXPORT b32
Print_Message(Application_Links *app, String message)
Print_Message(Application_Links *app, String_Const_u8 message)
/*
DOC_PARAM(str, The str parameter specifies the string to post to *messages*; it need not be null terminated.)
DOC_PARAM(len, The len parameter specifies the length of the str string.)
@ -2968,130 +2982,13 @@ DOC(This call posts a string to the *messages* buffer.)
Editing_File *file = models->message_buffer;
b32 result = false;
if (file != 0){
output_file_append(models->system, models, file, message);
output_file_append(models->system, models, file, string_old_from_new(message));
file_cursor_to_end(models->system, models, file);
result = true;
}
return(result);
}
#if 0
//API_EXPORT i32
Get_Theme_Count(Application_Links *app)
/*
DOC_RETURN(Returns the number of themes that currently exist in the core.)
*/
{
Models *models = (Models*)app->cmd_context;
return(models->styles.count);
}
//API_EXPORT String
Get_Theme_Name(Application_Links *app, struct Partition *arena, i32 index)
/*
DOC_PARAM(arena, The arena which will be used to allocate the returned string.)
DOC_PARAM(index, The index of the theme to query. Index zero always refers to the active theme, all other indices refer to the static copies of available themes.)
DOC_RETURN(On success this call returns a string allocated on arena that is the name of the queried theme, on failure a null string is returned. This call fails when index is not less than the total number of themes, and when there is not enough space in arena to allocate the return string.)
*/
{
Models *models = (Models*)app->cmd_context;
Style_Library *library = &models->styles;
String str = {};
if (0 <= index && index < library->count){
Style *style = &library->styles[index];
char *mem = push_array(arena, char, style->name.size + 1);
if (mem != 0){
str.str = mem;
str.size = style->name.size;
str.memory_size = str.size + 1;
memcpy(str.str, style->name.str, str.size);
str.str[str.size] = 0;
}
}
return(str);
}
// TODO(allen): redocument
//API_EXPORT b32
Create_Theme(Application_Links *app, Theme *theme, String theme_name)
/*
DOC_PARAM(theme, The color data of the new theme.)
DOC_PARAM(name, The name of the new theme. This string need not be null terminated.)
DOC_PARAM(len, The length of the name string.)
DOC(This call creates a new theme. If the given name is already the name of a string, the old string will be replaced with the new one. This call does not set the current theme.)
*/{
Models *models = (Models*)app->cmd_context;
Style_Library *library = &models->styles;
i32 count = library->count;
Style *destination_style = 0;
Style *style = library->styles + 1;
for (i32 i = 1; i < count; ++i, ++style){
if (match(style->name, theme_name)){
destination_style = style;
break;
}
}
if (destination_style == 0 && library->count < library->max){
destination_style = &library->styles[library->count++];
destination_style->name = make_fixed_width_string(destination_style->name_);
copy(&destination_style->name, theme_name);
terminate_with_null(&destination_style->name);
}
b32 result = false;
if (destination_style != 0){
block_copy(&destination_style->theme, theme, sizeof(*theme));
result = true;
}
return(result);
}
// TODO(allen): redocument
//API_EXPORT b32
Change_Theme(Application_Links *app, String theme_name)
/*
DOC_PARAM(name, The name parameter specifies the name of the theme to begin using; it need not be null terminated.)
DOC_PARAM(len, The len parameter specifies the length of the name string.)
DOC(This call changes 4coder's color pallet to one of the built in themes.)
*/{
Models *models = (Models*)app->cmd_context;
Style_Library *styles = &models->styles;
i32 count = styles->count;
b32 result = false;
Style *s = styles->styles + 1;
for (i32 i = 1; i < count; ++i, ++s){
if (match(s->name, theme_name)){
styles->styles[0] = *s;
styles->styles[0].name.str = styles->styles[0].name_;
result = true;
break;
}
}
return(result);
}
//API_EXPORT b32
Change_Theme_By_Index(Application_Links *app, i32 index)
/*
DOC_PARAM(index, The index parameter specifies the index of theme to begin using.)
DOC_RETURN(Returns non-zero on success and zero on failure. This call fails when index is not less than the total number of themes.)
*/
{
Models *models = (Models*)app->cmd_context;
Style_Library *styles = &models->styles;
i32 count = styles->count;
b32 result = false;
if (0 <= index && index < count){
styles->styles[0] = styles->styles[index];
styles->styles[0].name.str = styles->styles[0].name_;
result = true;
}
return(result);
}
#endif
API_EXPORT Face_ID
Get_Largest_Face_ID(Application_Links *app)
/*
@ -3151,8 +3048,8 @@ buffer_history__fill_record_info(Record *record, Record_Info *out){
switch (out->kind){
case RecordKind_Single:
{
out->single.string_forward = make_string(record->single.str_forward , record->single.length_forward );
out->single.string_backward = make_string(record->single.str_backward, record->single.length_backward);
out->single.string_forward = SCu8(record->single.str_forward , record->single.length_forward );
out->single.string_backward = SCu8(record->single.str_backward, record->single.length_backward);
out->single.first = record->single.first;
}break;
case RecordKind_Group:
@ -3161,7 +3058,7 @@ buffer_history__fill_record_info(Record *record, Record_Info *out){
}break;
default:
{
InvalidCodePath;
InvalidPath;
}break;
}
}
@ -3214,9 +3111,14 @@ Buffer_History_Get_Group_Sub_Record(Application_Links *app, Buffer_ID buffer_id,
if (0 < index){
Record *record = history_get_record(history, index);
if (record->kind == RecordKind_Group){
record = history_get_sub_record(record, sub_index);
buffer_history__fill_record_info(record, record_out);
result = true;
record = history_get_sub_record(record, sub_index + 1);
if (record != 0){
buffer_history__fill_record_info(record, record_out);
result = true;
}
else{
record_out->error = RecordError_SubIndexOutOfBounds;
}
}
else{
record_out->error = RecordError_WrongRecordTypeAtIndex;
@ -3276,12 +3178,12 @@ Buffer_History_Merge_Record_Range(Application_Links *app, Buffer_ID buffer_id, H
if (file != 0 && history_is_activated(&file->state.history)){
History *history = &file->state.history;
i32 max_index = history_get_record_count(history);
first_index = clamp_bottom(1, first_index);
first_index = clamp_bot(1, first_index);
if (first_index <= last_index && last_index <= max_index){
i32 current_index = file->state.current_record_index;
if (first_index <= current_index && current_index < last_index){
System_Functions *system = models->system;
u32 in_range_handler = flags & (bit_0 | bit_1);
u32 in_range_handler = flags & bitmask_2;
switch (in_range_handler){
case RecordMergeFlag_StateInRange_MoveStateForward:
{
@ -3302,7 +3204,7 @@ Buffer_History_Merge_Record_Range(Application_Links *app, Buffer_ID buffer_id, H
}
}
if (first_index < last_index){
history_merge_records(&models->mem.part, &models->mem.heap, history, first_index, last_index);
history_merge_records(&models->mem.arena, &models->mem.heap, history, first_index, last_index);
}
if (current_index >= last_index){
current_index -= (last_index - first_index);
@ -3641,7 +3543,7 @@ Finalize_Color(Application_Links *app, int_color color){
// TODO(allen): redocument
API_EXPORT b32
Get_Hot_Directory(Application_Links *app, String *out, i32 *required_size_out)
Get_Hot_Directory(Application_Links *app, Arena *out, String_Const_u8 *out_directory)
/*
DOC_PARAM(out, On success this character buffer is filled with the 4coder 'hot directory'.)
DOC_PARAM(capacity, Specifies the capacity in bytes of the of the out buffer.)
@ -3652,12 +3554,13 @@ DOC_SEE(directory_set_hot)
Models *models = (Models*)app->cmd_context;
Hot_Directory *hot = &models->hot_directory;
hot_directory_clean_end(hot);
return(api_string_out(hot->string, out, required_size_out));
*out_directory = string_copy(out, SCu8(hot->string_space, hot->string_size));
return(true);
}
// TODO(allen): redocument
API_EXPORT b32
Set_Hot_Directory(Application_Links *app, String string)
Set_Hot_Directory(Application_Links *app, String_Const_u8 string)
/*
DOC_PARAM(str, The new value of the hot directory. This does not need to be a null terminated string.)
DOC_PARAM(len, The length of str in bytes.)
@ -3668,7 +3571,7 @@ DOC_SEE(directory_get_hot)
Models *models = (Models*)app->cmd_context;
Hot_Directory *hot = &models->hot_directory;
b32 success = false;
if (string.size < hot->string.memory_size){
if (string.size < sizeof(hot->string_space)){
hot_directory_set(models->system, hot, string);
success = true;
}
@ -3677,7 +3580,7 @@ DOC_SEE(directory_get_hot)
// TODO(allen): redocument
API_EXPORT b32
Get_File_List(Application_Links *app, String directory, File_List *list_out)
Get_File_List(Application_Links *app, String_Const_u8 directory, File_List *list_out)
/*
DOC_PARAM(dir, This parameter specifies the directory whose files will be enumerated in the returned list; it need not be null terminated.)
DOC_PARAM(len, This parameter the length of the dir string.)
@ -3686,15 +3589,23 @@ DOC_SEE(File_List)
*/{
Models *models = (Models*)app->cmd_context;
System_Functions *system = models->system;
Partition *part = &models->mem.part;
block_zero_struct(list_out);
Editing_File_Name canon = {};
b32 result = false;
if (get_canon_name(system, directory, &canon)){
Temp_Memory temp = begin_temp_memory(part);
String str = push_string(part, canon.name.str, canon.name.size);
system->set_file_list(list_out, str.str, 0, 0, 0);
end_temp_memory(temp);
Arena *scratch = &models->mem.arena;
Temp_Memory temp = begin_temp(scratch);
char *str = 0;
if (canon.name_size < sizeof(canon.name_space)){
canon.name_space[canon.name_size] = 0;
str = (char*)canon.name_space;
}
else{
String_Const_u8 s = string_copy(scratch, string_from_file_name(&canon));
str = (char*)s.str;
}
system->set_file_list(list_out, str, 0, 0, 0);
end_temp(temp);
result = true;
}
return(result);
@ -3767,17 +3678,26 @@ DOC_SEE(memory_allocate)
}
API_EXPORT b32
File_Get_Attributes(Application_Links *app, String file_name, File_Attributes *attributes_out)
File_Get_Attributes(Application_Links *app, String_Const_u8 file_name, File_Attributes *attributes_out)
{
Models *models = (Models*)app->cmd_context;
*attributes_out = models->system->quick_file_attributes(file_name);
return(attributes_out->last_write_time > 0);
}
// TODO(allen): remove this nonsense and make a real API here instead.
// TODO(allen): remove this nonsense and make a real API here instead.
// TODO(allen): remove this nonsense and make a real API here instead.
// TODO(allen): remove this nonsense and make a real API here instead.
// TODO(allen): remove this nonsense and make a real API here instead.
// TODO(allen): remove this nonsense and make a real API here instead.
// TODO(allen): remove this nonsense and make a real API here instead.
// TODO(allen): remove this nonsense and make a real API here instead.
// TODO(allen): remove this nonsense and make a real API here instead.
// TODO(allen): remove this nonsense and make a real API here instead.
// TODO(allen): redocument
API_EXPORT b32
Directory_CD(Application_Links *app, String *directory, String relative_path)
Directory_CD(Application_Links *app, String_Const_u8 directory, String_Const_u8 relative_path, Arena *out, String_Const_u8 *directory_out)
/*
DOC_PARAM(dir, This parameter provides a character buffer that stores a directory; it need not be null terminated.)
DOC_PARAM(len, This parameter specifies the length of the dir string.)
@ -3791,13 +3711,19 @@ This call succeeds if the new directory exists and it fits inside the dir buffer
For instance if dir contains "C:/Users/MySelf" and rel is "Documents" the buffer will contain "C:/Users/MySelf/Documents" and len will contain the length of that string. This call can also be used with rel set to ".." to traverse to parent folders.
)*/{
Models *models = (Models*)app->cmd_context;
return(models->system->directory_cd(directory->str, &directory->size, directory->memory_size,
relative_path.str,relative_path.size));
i32 memory_size = (i32)(directory.size + relative_path.size + 2);
char *memory = push_array(out, char, memory_size);
i32 size = (i32)directory.size;
block_copy(memory, directory.str, directory.size);
b32 result = models->system->directory_cd(memory, &size, memory_size,
(char*)relative_path.str, (i32)relative_path.size);
*directory_out = SCu8(memory, size);
return(result);
}
// TODO(allen): redocument
API_EXPORT b32
Get_4ed_Path(Application_Links *app, String *path_out, i32 *required_size_out)
Get_4ed_Path(Application_Links *app, Arena *out, String_Const_u8 *path_out)
/*
DOC_PARAM(out, This parameter provides a character buffer that receives the path to the 4ed executable file.)
DOC_PARAM(capacity, This parameter specifies the maximum capacity of the out buffer.)
@ -3807,15 +3733,10 @@ DOC_RETURN(This call returns non-zero on success.)
System_Functions *system = models->system;
// TODO(allen): rewrite this with a better OS layer API
i32 required_size = system->get_4ed_path(0, 0);
*required_size_out = required_size;
i32 remaining_size = path_out->memory_size - path_out->size;
b32 result = false;
if (required_size <= remaining_size){
*required_size_out = system->get_4ed_path(path_out->str + path_out->size, remaining_size);
path_out->size += required_size;
result = true;
}
return(result);
char *memory = push_array(out, char, required_size + 1);
required_size = system->get_4ed_path(memory, required_size);
*path_out = SCu8(memory, required_size);
return(true);
}
// TODO(allen): do(add a "shown but auto-hides on timer" setting for cursor show type)
@ -3845,7 +3766,7 @@ DOC(This call tells 4coder to set the full_screen mode. The change to full scre
Models *models = (Models*)app->cmd_context;
b32 success = models->system->set_fullscreen(full_screen);
if (!success){
print_message(app, make_lit_string("ERROR: Failed to go fullscreen.\n"));
print_message(app, string_u8_litexpr("ERROR: Failed to go fullscreen.\n"));
}
return(success);
}
@ -3875,20 +3796,18 @@ To make send_exit_signal exit no matter what, setup your hook in such a way that
// TODO(allen): redocument
API_EXPORT b32
Set_Window_Title(Application_Links *app, String title)
Set_Window_Title(Application_Links *app, String_Const_u8 title)
/*
DOC_PARAM(title, A null terminated string indicating the new title for the 4coder window.)
DOC(Sets 4coder's window title to the specified title string.)
*/{
Models *models = (Models*)app->cmd_context;
models->has_new_title = true;
String dst = make_string_cap(models->title_space, 0, models->title_capacity);
b32 result = false;
if (append(&dst, title)){
terminate_with_null(&dst);
result = true;
}
return(result);
umem cap_before_null = (umem)(models->title_capacity - 1);
umem copy_size = clamp_top(title.size, cap_before_null);
block_copy(models->title_space, title.str, copy_size);
models->title_space[copy_size] = 0;
return(true);
}
API_EXPORT Microsecond_Time_Stamp
@ -3971,7 +3890,7 @@ draw_helper__screen_space_to_view_space(View *view, f32_Rect rect){
// To make text scroll with the buffer users should read the view's scroll position and subtract it first.
API_EXPORT Vec2
Draw_String(Application_Links *app, Face_ID font_id, String str, Vec2 point, int_color color, u32 flags, Vec2 delta)
Draw_String(Application_Links *app, Face_ID font_id, String_Const_u8 str, Vec2 point, int_color color, u32 flags, Vec2 delta)
{
Vec2 result = point;
Models *models = (Models*)app->cmd_context;
@ -3990,7 +3909,7 @@ Draw_String(Application_Links *app, Face_ID font_id, String str, Vec2 point, int
}
API_EXPORT f32
Get_String_Advance(Application_Links *app, Face_ID font_id, String str)
Get_String_Advance(Application_Links *app, Face_ID font_id, String_Const_u8 str)
{
Models *models = (Models*)app->cmd_context;
return(font_string_width(models->system, models->target, font_id, str));
@ -4160,11 +4079,11 @@ Compute_Render_Layout(Application_Links *app, View_ID view_id, Buffer_ID buffer_
f32 smallest_char_width = 6.f;
f32 smallest_char_height = 8.f;
i32 max = (i32)(layout_dim.x*layout_dim.y/(smallest_char_width*smallest_char_height))*2;
if (view->layout_arena.app == 0){
view->layout_arena = make_arena(app);
if (view->layout_arena.base_allocator == 0){
view->layout_arena = make_arena_app_links(app);
}
else{
arena_release_all(&view->layout_arena);
linalloc_clear(&view->layout_arena);
}
Buffer_Render_Item *items = push_array(&view->layout_arena, Buffer_Render_Item, max);
@ -4172,13 +4091,6 @@ Compute_Render_Layout(Application_Links *app, View_ID view_id, Buffer_ID buffer_
Face_ID font_id = file->settings.font_id;
Font_Pointers font = system->font.get_pointers_by_id(font_id);
#if 0
File_Edit_Positions edit_pos = view_get_edit_pos(view);
f32 scroll_x = edit_pos.scroll.scroll_x;
f32 scroll_y = edit_pos.scroll.scroll_y;
Full_Cursor render_cursor = view_get_render_cursor(system, view);
#else
Full_Cursor intermediate_cursor = file_compute_cursor(system, file, seek_line_char(buffer_point.line_number, 1));
f32 scroll_x = buffer_point.pixel_shift.x;
f32 scroll_y = intermediate_cursor.wrapped_y;
@ -4187,7 +4099,6 @@ Compute_Render_Layout(Application_Links *app, View_ID view_id, Buffer_ID buffer_
}
scroll_y += buffer_point.pixel_shift.y;
Full_Cursor render_cursor = file_get_render_cursor(system, file, scroll_y);
#endif
i32 item_count = 0;
i32 end_pos = 0;
@ -4288,7 +4199,7 @@ Draw_Render_Layout(Application_Links *app, View_ID view_id){
render_loaded_file_in_view__inner(models, models->target, view, view->render.buffer_rect,
view->render.cursor, view->render.range,
view->render.items, view->render.item_count);
arena_release_all(&view->layout_arena);
linalloc_clear(&view->layout_arena);
}
}
@ -4322,7 +4233,7 @@ Animate_In_N_Milliseconds(Application_Links *app, u32 n)
// TODO(casey): Allen, this routine is very intricate and needs to be tested thoroughly before mainlining. I've only done cursory testing on it and have probably missed bugs that only occur in highly segmented buffers.
// TODO(casey): I think this routine could potentially be simplified by making it into something that always works with a partial match list, where the partial matches have 0 characters matched, and they just get moved forward as they go. This would solve the duplicate code problem the routine currently has where it does the same thing in its two halves, but slightly differently.
API_EXPORT Found_String_List
Find_All_In_Range_Insensitive(Application_Links *app, Buffer_ID buffer_id, i32 start, i32 end, String key, Partition *memory)
Find_All_In_Range_Insensitive(Application_Links *app, Buffer_ID buffer_id, i32 start, i32 end, String_Const_u8 key, Arena *arena)
{
Found_String_List result = {};
@ -4354,7 +4265,7 @@ Find_All_In_Range_Insensitive(Application_Links *app, Buffer_ID buffer_id, i32 s
while(*partial)
{
Found_String *check = *partial;
i32 trailing_char_at = ((check->location.start + key.size) - check->location.end);
i32 trailing_char_at = ((check->location.start + (i32)key.size) - check->location.end);
i32 remaining = trailing_char_at;
b32 valid = true;
b32 full = true;
@ -4428,7 +4339,7 @@ Find_All_In_Range_Insensitive(Application_Links *app, Buffer_ID buffer_id, i32 s
if(remaining >= key.size)
{
full = true;
remaining = key.size;
remaining = (i32)key.size;
}
u32 exact_matched = FoundString_Sensitive;
@ -4461,7 +4372,7 @@ Find_All_In_Range_Insensitive(Application_Links *app, Buffer_ID buffer_id, i32 s
}
else
{
found = push_array(memory, Found_String, 1);
found = push_array(arena, Found_String, 1);
}
if(found)
@ -4475,7 +4386,7 @@ Find_All_In_Range_Insensitive(Application_Links *app, Buffer_ID buffer_id, i32 s
// NOTE(casey): Although technically "full matches" are full, we haven't yet checked the trailing edge for tokenization,
// so we need to shunt to partial in the cases where we _can't_ check the overhanging character.
i32 trailing_char_at = (at + key.size);
i32 trailing_char_at = (at + (i32)key.size);
full = full && (trailing_char_at < size);
if(full)

View File

@ -28,6 +28,7 @@ struct App_Settings{
};
struct Models{
Base_Allocator allocator;
Mem_Options mem;
App_Settings settings;
@ -168,6 +169,7 @@ struct Consumption_Record{
char consumer[32];
};
// TODO(allen): GET RID OF IT!
struct App_Vars{
Models models;
App_State state;
@ -188,7 +190,7 @@ struct Command_In{
};
struct File_Init{
String name;
String_Const_u8 name;
Editing_File **ptr;
b32 read_only;
};

View File

@ -9,17 +9,19 @@
// TOP
//#define REMOVE_OLD_STRING
// TODO(allen): get away from string.h
#include <string.h>
#include "4coder_API/4coder_custom.h"
#include "4ed_defines.h"
//#include "4ed_math.h"
#include "4coder_base_types.h"
#include "4ed_font.h"
#include "4ed_system.h"
#define PREFERRED_ALIGNMENT 8
#include "4coder_base_types.cpp"
#include "4coder_app_links_allocator.cpp"
#include "4coder_lib/4coder_arena.cpp"
#include "4coder_lib/4coder_heap.cpp"
@ -28,8 +30,9 @@
#include "4coder_lib/4coder_table.h"
#include "4coder_lib/4coder_utf8.h"
// TODO(allen): stop this nonsense
struct Mem_Options{
Partition part;
Arena arena;
Heap heap;
};

View File

@ -290,25 +290,22 @@ buffer_size(Gap_Buffer *buffer){
}
internal Gap_Buffer_Init
buffer_begin_init(Gap_Buffer *buffer, char *data, i32 size){
buffer_begin_init(Gap_Buffer *buffer, u8 *data, umem size){
Gap_Buffer_Init init;
init.buffer = buffer;
init.data = data;
init.size = size;
init.data = (char*)data;
init.size = (i32)size;
return(init);
}
internal i32
internal b32
buffer_init_need_more(Gap_Buffer_Init *init){
i32 result = 1;
if (init->buffer->data) result = 0;
return(result);
return(init->buffer->data == 0);
}
internal i32
buffer_init_page_size(Gap_Buffer_Init *init){
i32 result = init->size * 2;
return(result);
return(init->size * 2);
}
internal void
@ -319,13 +316,13 @@ buffer_init_provide_page(Gap_Buffer_Init *init, void *page, i32 page_size){
}
internal b32
buffer_end_init(Gap_Buffer_Init *init, void *scratch, i32 scratch_size){
buffer_end_init(Gap_Buffer_Init *init){
Gap_Buffer *buffer = init->buffer;
b32 result = false;
if (buffer->data && buffer->max >= init->size){
if (buffer->data != 0 && buffer->max >= init->size){
i32 size = init->size;
i32 size2 = size >> 1;
i32 size2 = (size >> 1);
i32 osize1 = size - size2;
i32 size1 = osize1;
@ -423,12 +420,11 @@ buffer_replace_range_compute_shift(i32 start, i32 end, i32 len){
return(len - (end - start));
}
internal 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){
internal b32
buffer_replace_range(Gap_Buffer *buffer, i32 start, i32 end, char *str, i32 len, i32 shift_amount, i32 *request_amount){
char *data = buffer->data;
i32 size = buffer_size(buffer);
i32 result = false;
b32 result = false;
i32 move_size = 0;
Assert(0 <= start);
@ -458,22 +454,15 @@ buffer_replace_range(Gap_Buffer *buffer, i32 start, i32 end, char *str, i32 len,
Assert(buffer->size1 + buffer->gap_size + buffer->size2 == buffer->max);
}
else{
*request_amount = l_round_up_i32(2*(shift_amount + size), 4 << 10);
*request_amount = round_up_i32(2*(shift_amount + size), KB(4));
result = true;
}
return(result);
}
// TODO(allen): do(optimize Gap_Buffer batch edit)
// Now that we are just using Gap_Buffer we could afford to improve
// this for the Gap_Buffer's behavior.
// TODO(allen): This now relies on Edit and Edit_Array from 4ed_edit.h even though we sort of think of that
// as cheating... gotta rethink the separation of buffer from everything else moving forward or something.
internal b32
buffer_batch_edit_step(Buffer_Batch_State *state, Gap_Buffer *buffer, Edit_Array sorted_edits, void *scratch, i32 scratch_size, i32 *request_amount){
buffer_batch_edit_step(Buffer_Batch_State *state, Gap_Buffer *buffer, Edit_Array sorted_edits, i32 *request_amount){
b32 result = false;
i32 shift_total = state->shift_total;
@ -486,7 +475,7 @@ buffer_batch_edit_step(Buffer_Batch_State *state, Gap_Buffer *buffer, Edit_Array
i32 start = edit->range.first + shift_total;
i32 end = edit->range.one_past_last + shift_total;
i32 shift_amount = buffer_replace_range_compute_shift(start, end, length);
result = buffer_replace_range(buffer, start, end, str, length, shift_amount, scratch, scratch_size, request_amount);
result = buffer_replace_range(buffer, start, end, str, length, shift_amount, request_amount);
if (result){
break;
}
@ -521,22 +510,31 @@ buffer_edit_provide_memory(Gap_Buffer *buffer, void *new_data, i32 new_max){
// High level buffer operations
//
internal String_Array
buffer_get_chunks(Partition *part, Gap_Buffer *buffer){
String_Array result = {};
result.vals = push_array(part, String, 0);
internal String_Const_u8_Array
buffer_get_chunks(Cursor *cursor, Gap_Buffer *buffer, Buffer_Get_Chunk_Mode mode){
i32 total_count = (buffer->size1 > 0) + (buffer->size2 > 0) + (mode == BufferGetChunk_ZeroTerminated);
String_Const_u8_Array result = {};
result.vals = push_array(cursor, String_Const_u8, total_count);
if (buffer->size1 > 0){
String *s = push_array(part, String, 1);
*s = make_string(buffer->data, buffer->size1);
result.vals[result.count] = SCu8(buffer->data, buffer->size1);
result.count += 1;
}
if (buffer->size2 > 0){
String *s = push_array(part, String, 1);
*s = make_string(buffer->data + buffer->size1 + buffer->gap_size, buffer->size2);
result.vals[result.count] = SCu8(buffer->data + buffer->size1 + buffer->gap_size, buffer->size2);
result.count += 1;
}
if (mode == BufferGetChunk_ZeroTerminated){
result.vals[result.count] = SCu8();
result.count += 1;
}
result.count = (i32)(push_array(part, String, 0) - result.vals);
return(result);
}
internal String_Const_u8_Array
buffer_get_chunks(Cursor *cursor, Gap_Buffer *buffer){
return(buffer_get_chunks(cursor, buffer, BufferGetChunk_Basic));
}
internal void
buffer_stringify(Gap_Buffer *buffer, i32 start, i32 end, char *out){
Gap_Buffer_Stream stream = {};
@ -1278,13 +1276,13 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa
case buffer_seek_line_char:
{
line_index = params.seek.line - 1;
line_index = clamp_bottom(0, line_index);
line_index = clamp_bot(0, line_index);
}break;
case buffer_seek_unwrapped_xy:
{
line_index = (i32)(params.seek.y / S.font_height);
line_index = clamp_bottom(0, line_index);
line_index = clamp_bot(0, line_index);
}break;
case buffer_seek_wrapped_xy:
@ -1292,7 +1290,7 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa
line_index = buffer_get_line_index_from_wrapped_y(params.wrap_line_index, params.seek.y, S.font_height, 0, params.buffer->line_count);
}break;
default: InvalidCodePath;
default: InvalidPath;
}
i32 safe_line_index = line_index;
@ -1341,7 +1339,7 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa
S.still_looping = buffer_stringify_next(&S.stream);
}while(S.still_looping);
}
InvalidCodePath;
InvalidPath;
double_break_vwhite:;
}
@ -1548,7 +1546,7 @@ buffer_cursor_seek(Buffer_Cursor_Seek_State *S_ptr, Buffer_Cursor_Seek_Params pa
}while(S.still_looping);
}
InvalidCodePath;
InvalidPath;
buffer_cursor_seek_end:;
*params.cursor_out = S.this_cursor;

View File

@ -12,9 +12,10 @@
#if !defined(FRED_BUFFER_H)
#define FRED_BUFFER_H
struct String_Array{
String *vals;
i32 count;
typedef i32 Buffer_Get_Chunk_Mode;
enum{
BufferGetChunk_Basic,
BufferGetChunk_ZeroTerminated,
};
struct Cursor_With_Index{

View File

@ -11,7 +11,7 @@
internal void
child_process_container_init(Child_Process_Container *container, Models *models){
container->arena = make_arena(&models->app_links);
container->arena = make_arena_app_links(&models->app_links);
dll_init_sentinel(&container->child_process_active_list);
dll_init_sentinel(&container->child_process_free_list);
container->child_process_id_counter = 0;
@ -20,7 +20,7 @@ child_process_container_init(Child_Process_Container *container, Models *models)
internal void
child_process_container_release(Child_Process_Container *container, Models *models){
arena_release_all(&container->arena);
linalloc_clear(&container->arena);
heap_free(&models->mem.heap, container->id_to_ptr_table.mem);
block_zero_struct(container);
}
@ -92,26 +92,13 @@ child_process_lookup_return_code(Child_Process_Container *container, Child_Proce
////////////////////////////////
internal b32
child_process_call(Models *models, System_Functions *system, String path, String command, Child_Process_ID *id_out){
child_process_call(Models *models, System_Functions *system, String_Const_u8 path, String_Const_u8 command, Child_Process_ID *id_out){
b32 result = false;
char *path_cstr = 0;
char *command_cstr = 0;
if (terminate_with_null(&path)){
path_cstr = path.str;
}
else{
String s = string_push_copy(&models->mem.part, path);
path_cstr = s.str;
}
if (terminate_with_null(&command)){
command_cstr = command.str;
}
else{
String s = string_push_copy(&models->mem.part, command);
command_cstr = s.str;
}
Scratch_Block scratch(&models->app_links);
String_Const_u8 path_n = string_copy(scratch, path);
String_Const_u8 command_n = string_copy(scratch, command);
CLI_Handles cli_handles = {};
if (system->cli_call(path_cstr, command_cstr, &cli_handles)){
if (system->cli_call((char*)path_n.str, (char*)command_n.str, &cli_handles)){
Child_Process_And_ID new_process = child_process_alloc_new(models, &models->child_processes);
*id_out = new_process.id;
new_process.process->cli = cli_handles;

View File

@ -110,7 +110,7 @@ wrap_state_consume_token(System_Functions *system, Font_Pointers font, Code_Wrap
end = fixed_end_point;
}
i = clamp_bottom(line_start, i);
i = clamp_bot(line_start, i);
if (i == line_start){
skipping_whitespace = true;
}
@ -434,16 +434,16 @@ get_current_shift(Code_Wrap_State *wrap_state, i32 next_line_start){
}
}
result.shift = clamp_bottom(0.f, result.shift);
result.shift = clamp_bot(0.f, result.shift);
return(result);
}
internal void
file_measure_wraps(System_Functions *system, Mem_Options *mem, Editing_File *file, Font_Pointers font){
Heap *heap = &mem->heap;
Partition *part = &mem->part;
Arena *scratch = &mem->arena;
Temp_Memory temp = begin_temp_memory(part);
Temp_Memory temp = begin_temp(scratch);
file_allocate_wraps_as_needed(heap, file);
file_allocate_indents_as_needed(heap, file, file->state.buffer.line_count);
@ -478,18 +478,18 @@ file_measure_wraps(System_Functions *system, Mem_Options *mem, Editing_File *fil
b32 use_tokens = false;
// TODO(allen): REWRITE REWRITE REWRITE
Wrap_Indent_Pair *wrap_indent_marks = 0;
Potential_Wrap_Indent_Pair *potential_marks = 0;
i32 max_wrap_indent_mark = 0;
i32 max_wrap_indent_mark = Million(1);
if (params.virtual_white && file->state.tokens_complete && !file->state.still_lexing){
wrap_state_init(system, &wrap_state, file, font);
use_tokens = true;
potential_marks = push_array(part, Potential_Wrap_Indent_Pair, floor32(width));
potential_marks = push_array(scratch, Potential_Wrap_Indent_Pair, floor32(width));
max_wrap_indent_mark = part_remaining(part)/sizeof(Wrap_Indent_Pair);
wrap_indent_marks = push_array(part, Wrap_Indent_Pair, max_wrap_indent_mark);
wrap_indent_marks = push_array(scratch, Wrap_Indent_Pair, max_wrap_indent_mark);
}
i32 real_count = 0;
@ -910,7 +910,7 @@ file_measure_wraps(System_Functions *system, Mem_Options *mem, Editing_File *fil
++stage;
}
current_line_shift = clamp_bottom(0.f, current_line_shift);
current_line_shift = clamp_bot(0.f, current_line_shift);
}
else{
current_line_shift = 0.f;
@ -934,7 +934,7 @@ file_measure_wraps(System_Functions *system, Mem_Options *mem, Editing_File *fil
file->state.wrap_positions[wrap_position_index++] = size;
file->state.wrap_position_count = wrap_position_index;
end_temp_memory(temp);
end_temp(temp);
}
// BOTTOM

View File

@ -157,11 +157,11 @@ map_drop(Command_Map *map, Key_Code event_code, u8 modifiers){
}
internal void
map_init(Command_Map *map, Partition *part, i32 max, i32 parent){
map_init(Command_Map *map, Cursor *cursor, i32 max, i32 parent){
Assert(max >= 6);
Assert(map->commands == 0);
map->parent = parent;
map->commands = push_array(part, Command_Binding, max);
map->commands = push_array(cursor, Command_Binding, max);
map->count = 0;
map->max = max;

View File

@ -1,31 +0,0 @@
/*
* Mr. 4th Dimention - Allen Webster
*
* 21.01.2017
*
* Standard defines across 4coder code base.
*
*/
// TOP
#if !defined(FTECH_DEFINES)
#define FTECH_DEFINES
#define internal static
#define local_persist static
#define global static
#define local_const static const
#define global_const static const
#define external extern "C"
#define FixSize(s) struct{ u8 __size_fixer__[s]; }
#define DrCase(PC) case PC: goto resumespot_##PC
#define DrYield(PC, n) { *S_ptr = S; S_ptr->__pc__ = PC; return(n); resumespot_##PC:; }
#define DrReturn(n) { *S_ptr = S; S_ptr->__pc__ = -1; return(n); }
#endif
// BOTTOM

View File

@ -16,11 +16,11 @@ dynamic_variables_init(Dynamic_Variable_Layout *layout){
}
internal Managed_Variable_ID
dynamic_variables_lookup(Dynamic_Variable_Layout *layout, String name){
dynamic_variables_lookup(Dynamic_Variable_Layout *layout, String_Const_u8 name){
for (Dynamic_Variable_Slot *slot = layout->sentinel.next;
slot != &layout->sentinel;
slot = slot->next){
if (match(slot->name, name)){
if (string_match(slot->name, name)){
return(slot->location);
}
}
@ -28,35 +28,35 @@ dynamic_variables_lookup(Dynamic_Variable_Layout *layout, String name){
}
internal Managed_Variable_ID
dynamic_variables_create__always(Heap *heap, Dynamic_Variable_Layout *layout, String name, u64 default_value){
i32 alloc_size = name.size + 1 + sizeof(Dynamic_Variable_Slot);
dynamic_variables_create__always(Heap *heap, Dynamic_Variable_Layout *layout, String_Const_u8 name, u64 default_value){
i32 alloc_size = (i32)(name.size + 1 + sizeof(Dynamic_Variable_Slot));
void *ptr = heap_allocate(heap, alloc_size);
Managed_Variable_ID result = ManagedVariableIndex_ERROR;
if (ptr != 0){
Dynamic_Variable_Slot *new_slot = (Dynamic_Variable_Slot*)ptr;
char *c_str = (char*)(new_slot + 1);
String str = make_string_cap(c_str, 0, name.size + 1);
copy(&str, name);
terminate_with_null(&str);
new_slot->name = str;
block_copy(c_str, name.str, name.size);
c_str[name.size] = 0;
new_slot->name = SCu8(c_str, name.size);
new_slot->default_value = default_value;
new_slot->location = layout->location_counter++;
dll_insert_back(&layout->sentinel, new_slot);
return(new_slot->location);
result = new_slot->location;
}
return(ManagedVariableIndex_ERROR);
return(result);
}
internal Managed_Variable_ID
dynamic_variables_lookup_or_create(Heap *heap, Dynamic_Variable_Layout *layout, String name, u64 default_value){
dynamic_variables_lookup_or_create(Heap *heap, Dynamic_Variable_Layout *layout, String_Const_u8 name, u64 default_value){
Managed_Variable_ID lookup_id = dynamic_variables_lookup(layout, name);
if (lookup_id != ManagedVariableIndex_ERROR){
return(lookup_id);
if (lookup_id == ManagedVariableIndex_ERROR){
lookup_id = dynamic_variables_create__always(heap, layout, name, default_value);
}
return(dynamic_variables_create__always(heap, layout, name, default_value));
return(lookup_id);
}
internal i32
dynamic_variables_create(Heap *heap, Dynamic_Variable_Layout *layout, String name, u64 default_value){
dynamic_variables_create(Heap *heap, Dynamic_Variable_Layout *layout, String_Const_u8 name, u64 default_value){
Managed_Variable_ID lookup_id = dynamic_variables_lookup(layout, name);
if (lookup_id == ManagedVariableIndex_ERROR){
return(dynamic_variables_create__always(heap, layout, name, default_value));
@ -130,14 +130,12 @@ insert_u32_Ptr_table(Heap *heap, Memory_Bank *mem_bank, u32_Ptr_Table *table, u3
if (table->mem != 0){
b32 result = move_u32_Ptr_table(&new_table, table);
Assert(result);
AllowLocal(result);
memory_bank_free(mem_bank, table->mem);
}
*table = new_table;
}
b32 result = insert_u32_Ptr_table(table, &key, &val);
Assert(result);
AllowLocal(result);
}
////////////////////////////////
@ -151,7 +149,7 @@ internal Marker_Visual_Data*
dynamic_workspace_alloc_visual(Heap *heap, Memory_Bank *mem_bank, Dynamic_Workspace *workspace){
Marker_Visual_Allocator *allocator = &workspace->visual_allocator;
if (allocator->free_count == 0){
i32 new_slots_count = clamp_bottom(16, allocator->total_visual_count);
i32 new_slots_count = clamp_bot(16, allocator->total_visual_count);
i32 memsize = new_slots_count*sizeof(Marker_Visual_Data);
void *new_slots_memory = memory_bank_allocate(heap, mem_bank, memsize);
memset(new_slots_memory, 0, memsize);
@ -400,8 +398,8 @@ lifetime__key_table_erase(Lifetime_Key_Table *table, Lifetime_Key *erase_key){
internal Lifetime_Key_Table
lifetime__key_table_copy(Heap *heap, Lifetime_Key_Table table, u32 new_max){
Lifetime_Key_Table new_table = {};
new_table.max = clamp_bottom(table.max, new_max);
new_table.max = clamp_bottom(307, new_table.max);
new_table.max = clamp_bot(table.max, new_max);
new_table.max = clamp_bot(307, new_table.max);
i32 item_size = sizeof(*new_table.hashes) + sizeof(*new_table.keys);
new_table.mem_ptr = heap_allocate(heap, item_size*new_table.max);
memset(new_table.mem_ptr, 0, item_size*new_table.max);
@ -746,7 +744,7 @@ managed_object_alloc_managed_arena_in_scope(Heap *heap, Dynamic_Workspace *works
header->std_header.item_size = sizeof(Arena*);
header->std_header.count = 1;
zdll_push_back(workspace->arena_list.first, workspace->arena_list.last, header);
header->arena = make_arena(app, page_size);
header->arena = make_arena_app_links(app, page_size);
if (arena_out != 0){
*arena_out = &header->arena;
}
@ -776,7 +774,7 @@ managed_object_free(Dynamic_Workspace *workspace, Managed_Object object){
case ManagedObjectType_Arena:
{
Managed_Arena_Header *header = (Managed_Arena_Header*)object_ptr;
arena_release_all(&header->arena);
linalloc_clear(&header->arena);
zdll_remove(workspace->arena_list.first, workspace->arena_list.last, header);
}break;
}

View File

@ -94,7 +94,7 @@ struct Managed_Arena_Header_List{
struct Dynamic_Variable_Slot{
Dynamic_Variable_Slot *next;
Dynamic_Variable_Slot *prev;
String name;
String_Const_u8 name;
u64 default_value;
i32 location;
};

View File

@ -20,7 +20,7 @@ edit_pre_state_change(System_Functions *system, Heap *heap, Models *models, Edit
file->state.still_lexing = 0;
}
file_add_dirty_flag(file, DirtyState_UnsavedChanges);
file_unmark_edit_finished(file);
file_unmark_edit_finished(&models->working_set, file);
Layout *layout = &models->layout;
for (Panel *panel = layout_get_first_open_panel(layout);
panel != 0;
@ -79,7 +79,7 @@ edit_fix_markers__read_workspace_markers(Dynamic_Workspace *workspace, Buffer_ID
internal f32
edit_fix_markers__compute_scroll_y(i32 line_height, f32 old_y_val, f32 new_y_val_aligned){
f32 y_offset = MOD(old_y_val, line_height);
f32 y_offset = mod_f32(old_y_val, line_height);
f32 y_position = new_y_val_aligned + y_offset;
return(y_position);
}
@ -91,11 +91,8 @@ edit_fix_markers__compute_scroll_y(i32 line_height, i32 old_y_val, f32 new_y_val
internal void
edit_fix_markers(System_Functions *system, Models *models, Editing_File *file, Edit edit){
Partition *part = &models->mem.part;
Layout *layout = &models->layout;
Temp_Memory cursor_temp = begin_temp_memory(part);
Lifetime_Object *file_lifetime_object = file->lifetime_object;
Buffer_ID file_id = file->id.id;
Assert(file_lifetime_object != 0);
@ -118,10 +115,12 @@ edit_fix_markers(System_Functions *system, Models *models, Editing_File *file, E
key_index += count;
}
}
cursor_max += total_marker_count;
Cursor_With_Index *cursors = push_array(part, Cursor_With_Index, cursor_max);
Cursor_With_Index *r_cursors = push_array(part, Cursor_With_Index, cursor_max);
Arena *scratch = &models->mem.arena;
Temp_Memory cursor_temp = begin_temp(scratch);
Cursor_With_Index *cursors = push_array(scratch, Cursor_With_Index, cursor_max);
Cursor_With_Index *r_cursors = push_array(scratch, Cursor_With_Index, cursor_max);
i32 cursor_count = 0;
i32 r_cursor_count = 0;
Assert(cursors != 0);
@ -226,7 +225,7 @@ edit_fix_markers(System_Functions *system, Models *models, Editing_File *file, E
}
}
end_temp_memory(cursor_temp);
end_temp(cursor_temp);
}
internal void
@ -236,15 +235,14 @@ edit_single(System_Functions *system, Models *models, Editing_File *file, Range
edit.length = string.size;
edit.range = range;
Mem_Options *mem = &models->mem;
Heap *heap = &mem->heap;
Partition *part = &mem->part;
Gap_Buffer *buffer = &file->state.buffer;
Assert(0 <= edit.range.first);
Assert(edit.range.first <= edit.range.one_past_last);
Assert(edit.range.one_past_last <= buffer_size(buffer));
Heap *heap = &models->mem.heap;
// NOTE(allen): history update
if (!behaviors.do_not_post_to_history){
// TODO(allen): if the edit number counter is not updated, maybe auto-merge edits? Wouldn't that just work?
@ -258,18 +256,15 @@ edit_single(System_Functions *system, Models *models, Editing_File *file, Range
// NOTE(allen): edit range hook
if (models->hook_file_edit_range != 0){
models->hook_file_edit_range(&models->app_links, file->id.id, edit.range, make_string(edit.str, edit.length));
models->hook_file_edit_range(&models->app_links, file->id.id, edit.range, SCu8(edit.str, edit.length));
}
// NOTE(allen): expand spec, compute shift
i32 shift_amount = buffer_replace_range_compute_shift(edit.range.first, edit.range.one_past_last, edit.length);
// NOTE(allen): actual text replacement
i32 scratch_size = part_remaining(part);
Assert(scratch_size > 0);
i32 request_amount = 0;
for (;buffer_replace_range(buffer, edit.range.first, edit.range.one_past_last, edit.str, edit.length,
shift_amount, part->base + part->pos, scratch_size, &request_amount);){
for (;buffer_replace_range(buffer, edit.range.first, edit.range.one_past_last, edit.str, edit.length, shift_amount, &request_amount);){
void *new_data = 0;
if (request_amount > 0){
new_data = heap_allocate(heap, request_amount);
@ -302,7 +297,7 @@ edit_single(System_Functions *system, Models *models, Editing_File *file, Range
}
// NOTE(allen): wrap meta data
file_measure_wraps(system, mem, file, font);
file_measure_wraps(system, &models->mem, file, font);
// NOTE(allen): cursor fixing
edit_fix_markers(system, models, file, edit);
@ -385,7 +380,7 @@ edit__apply_record_forward(System_Functions *system, Models *models, Editing_Fil
default:
{
InvalidCodePath;
InvalidPath;
}break;
}
}
@ -416,7 +411,7 @@ edit__apply_record_backward(System_Functions *system, Models *models, Editing_Fi
default:
{
InvalidCodePath;
InvalidPath;
}break;
}
}
@ -459,16 +454,16 @@ edit_change_current_history_state(System_Functions *system, Models *models, Edit
////////////////////////////////
internal Editing_File*
create_file(Models *models, String file_name, Buffer_Create_Flag flags){
create_file(Models *models, String_Const_u8 file_name, Buffer_Create_Flag flags){
Editing_File *result = 0;
if (file_name.size > 0){
System_Functions *system = models->system;
Working_Set *working_set = &models->working_set;
Heap *heap = &models->mem.heap;
Partition *part = &models->mem.part;
Temp_Memory temp = begin_temp_memory(part);
Arena *scratch = &models->mem.arena;
Temp_Memory temp = begin_temp(scratch);
Editing_File *file = 0;
b32 do_empty_buffer = false;
@ -477,10 +472,10 @@ create_file(Models *models, String file_name, Buffer_Create_Flag flags){
b32 buffer_is_for_new_file = false;
// NOTE(allen): Try to get the file by canon name.
if ((flags & BufferCreate_NeverAttachToFile) == 0){
if (HasFlag(flags, BufferCreate_NeverAttachToFile) == 0){
if (get_canon_name(system, file_name, &canon)){
has_canon_name = true;
file = working_set_contains_canon(working_set, canon.name);
file = working_set_contains_canon(working_set, string_from_file_name(&canon));
}
else{
do_empty_buffer = true;
@ -504,7 +499,7 @@ create_file(Models *models, String file_name, Buffer_Create_Flag flags){
do_empty_buffer = true;
}
else{
if (!system->load_handle(canon.name.str, &handle)){
if (!system->load_handle((char*)canon.name_space, &handle)){
do_empty_buffer = true;
}
}
@ -518,11 +513,12 @@ create_file(Models *models, String file_name, Buffer_Create_Flag flags){
file = working_set_alloc_always(working_set, heap, &models->lifetime_allocator);
if (file != 0){
if (has_canon_name){
file_bind_file_name(system, heap, working_set, file, canon.name);
file_bind_file_name(system, heap, working_set, file, string_from_file_name(&canon));
}
buffer_bind_name(models, heap, part, working_set, file, front_of_directory(file_name));
String_Const_u8 front = string_front_of_path(file_name);
buffer_bind_name(models, heap, scratch, working_set, file, front);
File_Attributes attributes = {};
file_create_from_string(system, models, file, make_lit_string(""), attributes);
file_create_from_string(system, models, file, SCu8(""), attributes);
result = file;
}
}
@ -530,7 +526,7 @@ create_file(Models *models, String file_name, Buffer_Create_Flag flags){
else{
File_Attributes attributes = system->load_attributes(handle);
b32 in_heap_mem = false;
char *buffer = push_array(part, char, (i32)attributes.size);
char *buffer = push_array(scratch, char, (i32)attributes.size);
if (buffer == 0){
buffer = heap_array(heap, char, (i32)attributes.size);
@ -542,9 +538,10 @@ create_file(Models *models, String file_name, Buffer_Create_Flag flags){
system->load_close(handle);
file = working_set_alloc_always(working_set, heap, &models->lifetime_allocator);
if (file != 0){
file_bind_file_name(system, heap, working_set, file, canon.name);
buffer_bind_name(models, heap, part, working_set, file, front_of_directory(file_name));
file_create_from_string(system, models, file, make_string(buffer, (i32)attributes.size), attributes);
file_bind_file_name(system, heap, working_set, file, string_from_file_name(&canon));
String_Const_u8 front = string_front_of_path(file_name);
buffer_bind_name(models, heap, scratch, working_set, file, front);
file_create_from_string(system, models, file, SCu8(buffer, (i32)attributes.size), attributes);
result = file;
}
}
@ -580,7 +577,7 @@ create_file(Models *models, String file_name, Buffer_Create_Flag flags){
models->hook_new_file(&models->app_links, file->id.id);
}
end_temp_memory(temp);
end_temp(temp);
}
return(result);

View File

@ -16,6 +16,11 @@ to_file_id(i32 id){
return(result);
}
internal String_Const_u8
string_from_file_name(Editing_File_Name *name){
return(SCu8(name->name_space, name->name_size));
}
////////////////////////////////
internal void
@ -123,14 +128,24 @@ file_clear_dirty_flags(Editing_File *file){
////////////////////////////////
internal void
file_name_terminate(Editing_File_Name *name){
umem size = name->name_size;
size = clamp_top(size, sizeof(name->name_space) - 1);
name->name_space[size] = 0;
name->name_size = size;
}
////////////////////////////////
internal b32
save_file_to_name(System_Functions *system, Models *models, Editing_File *file, char *file_name){
save_file_to_name(System_Functions *system, Models *models, Editing_File *file, u8 *file_name){
b32 result = false;
b32 using_actual_file_name = false;
if (file_name == 0){
terminate_with_null(&file->canon.name);
file_name = file->canon.name.str;
file_name_terminate(&file->canon);
file_name = file->canon.name_space;
using_actual_file_name = true;
}
@ -151,19 +166,15 @@ save_file_to_name(System_Functions *system, Models *models, Editing_File *file,
max = buffer_size(buffer);
}
b32 used_heap = 0;
Temp_Memory temp = begin_temp_memory(&mem->part);
Arena *scratch = &mem->arena;
Temp_Memory temp = begin_temp(scratch);
char empty = 0;
char *data = 0;
if (max == 0){
data = &empty;
}
else{
data = (char*)push_array(&mem->part, char, max);
if (!data){
used_heap = 1;
data = heap_array(&mem->heap, char, max);
}
data = (char*)push_array(scratch, char, max);
}
Assert(data != 0);
@ -176,18 +187,16 @@ save_file_to_name(System_Functions *system, Models *models, Editing_File *file,
buffer_stringify(buffer, 0, size, data);
}
if (!using_actual_file_name && file->canon.name.str != 0){
if (!using_actual_file_name){
char space[512];
u32 length = str_size(file_name);
system->get_canonical(file_name, length, space, sizeof(space));
char *source_path = file->canon.name.str;
if (match(space, source_path)){
umem length = cstring_length(file_name);
system->get_canonical((char*)file_name, (u32)length, space, sizeof(space));
if (string_match(SCu8(space), string_from_file_name(&file->canon))){
using_actual_file_name = true;
}
}
File_Attributes new_attributes = system->save_file(file_name, data, size);
File_Attributes new_attributes = system->save_file((char*)file_name, data, size);
if (new_attributes.last_write_time > 0){
if (using_actual_file_name){
file->state.ignore_behind_os = 1;
@ -196,12 +205,7 @@ save_file_to_name(System_Functions *system, Models *models, Editing_File *file,
}
file_clear_dirty_flags(file);
if (used_heap){
heap_free(&mem->heap, data);
}
end_temp_memory(temp);
end_temp(temp);
}
return(result);
@ -331,7 +335,7 @@ file_grow_starts_as_needed(Heap *heap, Gap_Buffer *buffer, i32 additional_lines)
i32 count = buffer->line_count;
i32 target_lines = count + additional_lines;
if (target_lines > max || max == 0){
max = l_round_up_i32(target_lines + max, KB(1));
max = round_up_i32(target_lines + max, KB(1));
i32 *new_lines = heap_array(heap, i32, max);
if (new_lines != 0){
result = GROW_SUCCESS;
@ -371,14 +375,14 @@ file_measure_starts(Heap *heap, Gap_Buffer *buffer){
internal void
file_allocate_metadata_as_needed(Heap *heap, Gap_Buffer *buffer, void **mem, i32 *mem_max_count, i32 count, i32 item_size){
if (*mem == 0){
i32 max = l_round_up_i32(((count + 1)*2), KB(1));
i32 max = round_up_i32(((count + 1)*2), KB(1));
*mem = heap_allocate(heap, max*item_size);
*mem_max_count = max;
Assert(*mem != 0);
}
else if (*mem_max_count < count){
i32 old_max = *mem_max_count;
i32 max = l_round_up_i32(((count + 1)*2), KB(1));
i32 max = round_up_i32(((count + 1)*2), KB(1));
void *new_mem = heap_allocate(heap, item_size*max);
memcpy(new_mem, *mem, item_size*old_max);
heap_free(heap, *mem);
@ -421,16 +425,16 @@ file_allocate_wrap_positions_as_needed(Heap *heap, Editing_File *file, i32 min_l
////////////////////////////////
internal void
file_create_from_string(System_Functions *system, Models *models, Editing_File *file, String val, File_Attributes attributes){
file_create_from_string(System_Functions *system, Models *models, Editing_File *file, String_Const_u8 val, File_Attributes attributes){
Heap *heap = &models->mem.heap;
Partition *part = &models->mem.part;
Arena *scratch = &models->mem.arena;
Application_Links *app_links = &models->app_links;
block_zero_struct(&file->state);
Gap_Buffer_Init init = buffer_begin_init(&file->state.buffer, val.str, val.size);
for (;buffer_init_need_more(&init);){
i32 page_size = buffer_init_page_size(&init);
page_size = l_round_up_i32(page_size, KB(4));
page_size = round_up_i32(page_size, KB(4));
if (page_size < KB(4)){
page_size = KB(4);
}
@ -438,10 +442,8 @@ file_create_from_string(System_Functions *system, Models *models, Editing_File *
buffer_init_provide_page(&init, data, page_size);
}
i32 scratch_size = part_remaining(part);
Assert(scratch_size > 0);
b32 init_success = buffer_end_init(&init, part->base + part->pos, scratch_size);
AllowLocal(init_success); Assert(init_success);
b32 init_success = buffer_end_init(&init);
Assert(init_success);
if (buffer_size(&file->state.buffer) < val.size){
file->settings.dos_write_mode = true;
@ -488,7 +490,7 @@ file_create_from_string(System_Functions *system, Models *models, Editing_File *
}
internal void
file_free(System_Functions *system, Heap *heap, Lifetime_Allocator *lifetime_allocator, Editing_File *file){
file_free(System_Functions *system, Heap *heap, Lifetime_Allocator *lifetime_allocator, Working_Set *working_set, Editing_File *file){
if (file->state.still_lexing){
system->cancel_job(BACKGROUND_THREADS, file->state.lex_job);
if (file->state.swap_array.tokens){
@ -514,7 +516,7 @@ file_free(System_Functions *system, Heap *heap, Lifetime_Allocator *lifetime_all
history_free(heap, &file->state.history);
file_unmark_edit_finished(file);
file_unmark_edit_finished(working_set, file);
}
////////////////////////////////

View File

@ -97,8 +97,8 @@ struct Editing_File_State{
};
struct Editing_File_Name{
char name_[256];
String name;
u8 name_space[256];
umem name_size;
};
struct Editing_File{
@ -113,6 +113,7 @@ struct Editing_File{
Editing_File_Name unique_name;
Editing_File_Name canon;
Node main_chain_node;
b32 edit_finished_marked;
Node edit_finished_mark_node;
};

View File

@ -9,19 +9,7 @@
// TOP
internal String_Array
file_lex_chunks(Partition *part, Gap_Buffer *buffer){
String_Array result = {};
result.vals = push_array(part, String, 0);
buffer_get_chunks(part, buffer);
{
String *s = push_array(part, String, 1);
block_zero(s, sizeof(*s));
}
result.count = (i32)(push_array(part, String, 0) - result.vals);
return(result);
}
// TODO(allen): this needs a rewrite _BAD_
internal void
job_full_lex(System_Functions *system, Thread_Context *thread, Thread_Memory *memory, void *data[4]){
Editing_File *file = (Editing_File*)data[0];
@ -58,17 +46,17 @@ job_full_lex(System_Functions *system, Thread_Context *thread, Thread_Memory *me
Cpp_Lex_Data lex = cpp_lex_data_init(file->settings.tokens_without_strings, parse_context.kw_table, parse_context.pp_table);
String chunk_space[3];
Partition chunk_part = make_part(chunk_space, sizeof(chunk_space));
String_Array chunks = file_lex_chunks(&chunk_part, buffer);
String_Const_u8 chunk_space[3];
Cursor chunk_cursor = make_cursor(chunk_space, sizeof(chunk_space));
String_Const_u8_Array chunks = buffer_get_chunks(&chunk_cursor, buffer);
i32 chunk_index = 0;
do{
char *chunk = chunks.vals[chunk_index].str;
i32 chunk_size = chunks.vals[chunk_index].size;
u8 *chunk = chunks.vals[chunk_index].str;
umem chunk_size = chunks.vals[chunk_index].size;
i32 result = cpp_lex_step(&lex, chunk, chunk_size, text_size, &tokens, 2048);
i32 result = cpp_lex_step(&lex, (char*)chunk, (i32)chunk_size, text_size, &tokens, 2048);
switch (result){
case LexResult_NeedChunk:
{
@ -108,7 +96,7 @@ job_full_lex(System_Functions *system, Thread_Context *thread, Thread_Memory *me
}
}while(still_lexing);
i32 new_max = l_round_up_i32(tokens.count+1, KB(1));
i32 new_max = round_up_i32(tokens.count + 1, KB(1));
system->acquire_lock(FRAME_LOCK);
{
@ -179,7 +167,7 @@ file_first_lex_parallel(System_Functions *system, Models *models, Editing_File *
internal void
file_first_lex_serial(System_Functions *system, Models *models, Editing_File *file){
Mem_Options *mem = &models->mem;
Partition *part = &mem->part;
Arena *scratch = &mem->arena;
Heap *heap = &mem->heap;
file->settings.tokens_exist = true;
@ -188,39 +176,37 @@ file_first_lex_serial(System_Functions *system, Models *models, Editing_File *fi
if (file->is_loading == 0){
Assert(file->state.token_array.tokens == 0);
Temp_Memory temp = begin_temp_memory(part);
Temp_Memory temp = begin_temp(scratch);
Parse_Context parse_context = parse_context_get(&models->parse_context_memory, file->settings.parse_context_id, push_array(part, u8, 0), part_remaining(part));
Parse_Context parse_context = parse_context_get(scratch, &models->parse_context_memory, file->settings.parse_context_id);
Assert(parse_context.valid);
push_array(part, char, (i32)parse_context.memory_size);
Gap_Buffer *buffer = &file->state.buffer;
i32 text_size = buffer_size(buffer);
i32 mem_size = part_remaining(part);
Cpp_Token_Array new_tokens;
new_tokens.max_count = mem_size/sizeof(Cpp_Token);
// TODO(allen): REWRITE REWRITE REWRITE
Cpp_Token_Array new_tokens = {};
new_tokens.max_count = Million(1);
new_tokens.count = 0;
new_tokens.tokens = push_array(part, Cpp_Token, new_tokens.max_count);
new_tokens.tokens = push_array(scratch, Cpp_Token, new_tokens.max_count);
b32 still_lexing = true;
Cpp_Lex_Data lex = cpp_lex_data_init(file->settings.tokens_without_strings, parse_context.kw_table, parse_context.pp_table);
String chunk_space[3];
Partition chunk_part = make_part(chunk_space, sizeof(chunk_space));
String_Array chunks = file_lex_chunks(&chunk_part, buffer);
String_Const_u8_Array chunk_space[3];
Cursor chunk_cursor = make_cursor(chunk_space, sizeof(chunk_space));
String_Const_u8_Array chunks = buffer_get_chunks(&chunk_cursor, buffer, BufferGetChunk_ZeroTerminated);
i32 chunk_index = 0;
Cpp_Token_Array *swap_array = &file->state.swap_array;
do{
char *chunk = chunks.vals[chunk_index].str;
i32 chunk_size = chunks.vals[chunk_index].size;
u8 *chunk = chunks.vals[chunk_index].str;
umem chunk_size = chunks.vals[chunk_index].size;
i32 result = cpp_lex_step(&lex, chunk, chunk_size, text_size, &new_tokens, NO_OUT_LIMIT);
i32 result = cpp_lex_step(&lex, (char*)chunk, (i32)chunk_size, text_size, &new_tokens, NO_OUT_LIMIT);
switch (result){
case LexResult_NeedChunk:
@ -232,7 +218,7 @@ file_first_lex_serial(System_Functions *system, Models *models, Editing_File *fi
case LexResult_Finished:
case LexResult_NeedTokenMemory:
{
u32 new_max = l_round_up_u32(swap_array->count + new_tokens.count + 1, KB(1));
u32 new_max = round_up_u32(swap_array->count + new_tokens.count + 1, KB(1));
if (swap_array->tokens == 0){
swap_array->tokens = heap_array(heap, Cpp_Token, new_max);
}
@ -255,7 +241,7 @@ file_first_lex_serial(System_Functions *system, Models *models, Editing_File *fi
}
}break;
case LexResult_HitTokenLimit: InvalidCodePath;
case LexResult_HitTokenLimit: InvalidPath;
}
} while (still_lexing);
@ -274,7 +260,7 @@ file_first_lex_serial(System_Functions *system, Models *models, Editing_File *fi
file->state.tokens_complete = true;
file->state.still_lexing = false;
end_temp_memory(temp);
end_temp(temp);
file->state.tokens_complete = true;
file_mark_edit_finished(&models->working_set, file);
@ -284,58 +270,176 @@ file_first_lex_serial(System_Functions *system, Models *models, Editing_File *fi
internal b32
file_relex_parallel(System_Functions *system, Models *models, Editing_File *file, i32 start_i, i32 end_i, i32 shift_amount){
Mem_Options *mem = &models->mem;
Arena *scratch = &mem->arena;
Heap *heap = &mem->heap;
Partition *part = &mem->part;
if (file->state.token_array.tokens == 0){
file_first_lex_parallel(system, models, file);
return(true);
}
b32 result = true;
b32 internal_lex = !file->state.still_lexing;
if (internal_lex){
if (file->state.token_array.tokens == 0){
file_first_lex_parallel(system, models, file);
}
else{
b32 internal_lex = !file->state.still_lexing;
if (internal_lex){
Gap_Buffer *buffer = &file->state.buffer;
i32 extra_tolerance = 100;
Cpp_Token_Array *array = &file->state.token_array;
Cpp_Relex_Range relex_range = cpp_get_relex_range(array, start_i, end_i);
i32 relex_space_size = relex_range.end_token_index - relex_range.start_token_index + extra_tolerance;
Temp_Memory temp = begin_temp(scratch);
Parse_Context parse_context = parse_context_get(scratch, &models->parse_context_memory, file->settings.parse_context_id);
Assert(parse_context.valid);
Cpp_Token_Array relex_array;
relex_array.count = 0;
relex_array.max_count = relex_space_size;
relex_array.tokens = push_array(scratch, Cpp_Token, relex_array.max_count);
i32 size = buffer_size(buffer);
Cpp_Relex_Data state = cpp_relex_init(array, start_i, end_i, shift_amount, file->settings.tokens_without_strings, parse_context.kw_table, parse_context.pp_table);
String_Const_u8_Array chunk_space[3];
Cursor chunk_cursor = make_cursor(chunk_space, sizeof(chunk_space));
String_Const_u8_Array chunks = buffer_get_chunks(&chunk_cursor, buffer, BufferGetChunk_ZeroTerminated);
i32 chunk_index = 0;
u8 *chunk = chunks.vals[chunk_index].str;
umem chunk_size = chunks.vals[chunk_index].size;
for (;!cpp_relex_is_start_chunk(&state, (char*)chunk, (i32)chunk_size);){
++chunk_index;
Assert(chunk_index < chunks.count);
chunk = chunks.vals[chunk_index].str;
chunk_size = chunks.vals[chunk_index].size;
}
for (;;){
Cpp_Lex_Result lex_result =
cpp_relex_step(&state, (char*)chunk, (i32)chunk_size, size, array, &relex_array);
switch (lex_result){
case LexResult_NeedChunk:
{
++chunk_index;
Assert(chunk_index < chunks.count);
chunk = chunks.vals[chunk_index].str;
chunk_size = chunks.vals[chunk_index].size;
}break;
case LexResult_NeedTokenMemory:
{
internal_lex = false;
}goto doublebreak;
case LexResult_Finished: goto doublebreak;
}
}
doublebreak:;
if (internal_lex){
i32 new_count = cpp_relex_get_new_count(&state, array->count, &relex_array);
if (new_count > array->max_count){
i32 new_max = round_up_i32(new_count, KB(1));
void *memory = heap_allocate(heap, new_max*sizeof(Cpp_Token));
memcpy(memory, array->tokens, array->count*sizeof(Cpp_Token));
heap_free(heap, array->tokens);
array->tokens = (Cpp_Token*)memory;
array->max_count = new_max;
}
cpp_relex_complete(&state, array, &relex_array);
file_mark_edit_finished(&models->working_set, file);
}
else{
cpp_relex_abort(&state, array);
}
end_temp(temp);
}
if (!internal_lex){
Cpp_Token_Array *array = &file->state.token_array;
Cpp_Get_Token_Result get_token_result = cpp_get_token(*array, end_i);
i32 end_token_i = get_token_result.token_index;
if (end_token_i < 0){
end_token_i = 0;
}
else if (end_i > array->tokens[end_token_i].start){
++end_token_i;
}
cpp_shift_token_starts(array, end_token_i, shift_amount);
--end_token_i;
if (end_token_i >= 0){
Cpp_Token *token = array->tokens + end_token_i;
if (token->start < end_i && token->start + token->size > end_i){
token->size += shift_amount;
}
}
file->state.still_lexing = true;
Job_Data job = {};
job.callback = job_full_lex;
job.data[0] = file;
job.data[1] = heap;
job.data[2] = models;
file->state.lex_job = system->post_job(BACKGROUND_THREADS, job);
result = false;
}
}
return(result);
}
internal b32
file_relex_serial(System_Functions *system, Models *models, Editing_File *file, i32 start_i, i32 end_i, i32 shift_amount){
Mem_Options *mem = &models->mem;
Arena *scratch = &mem->arena;
Heap *heap = &mem->heap;
if (file->state.token_array.tokens == 0){
file_first_lex_serial(system, models, file);
}
else{
Assert(!file->state.still_lexing);
Gap_Buffer *buffer = &file->state.buffer;
i32 extra_tolerance = 100;
Cpp_Token_Array *array = &file->state.token_array;
Cpp_Relex_Range relex_range = cpp_get_relex_range(array, start_i, end_i);
i32 relex_space_size =
relex_range.end_token_index - relex_range.start_token_index + extra_tolerance;
Temp_Memory temp = begin_temp_memory(part);
Parse_Context parse_context = parse_context_get(&models->parse_context_memory, file->settings.parse_context_id, push_array(part, u8, 0), part_remaining(part));
Temp_Memory temp = begin_temp(scratch);
Parse_Context parse_context = parse_context_get(scratch, &models->parse_context_memory, file->settings.parse_context_id);
Assert(parse_context.valid);
push_array(part, char, (i32)parse_context.memory_size);
Cpp_Token_Array relex_array;
Cpp_Token_Array relex_array = {};
relex_array.count = 0;
relex_array.max_count = relex_space_size;
relex_array.tokens = push_array(part, Cpp_Token, relex_array.max_count);
relex_array.max_count = Million(1);
relex_array.tokens = push_array(scratch, Cpp_Token, relex_array.max_count);
i32 size = buffer_size(buffer);
Cpp_Relex_Data state = cpp_relex_init(array, start_i, end_i, shift_amount, file->settings.tokens_without_strings, parse_context.kw_table, parse_context.pp_table);
String chunk_space[3];
Partition chunk_part = make_part(chunk_space, sizeof(chunk_space));
String_Array chunks = file_lex_chunks(&chunk_part, buffer);
String_Const_u8_Array chunk_space[3];
Cursor chunk_cursor = make_cursor(chunk_space, sizeof(chunk_space));
String_Const_u8_Array chunks = buffer_get_chunks(&chunk_cursor, buffer, BufferGetChunk_ZeroTerminated);
i32 chunk_index = 0;
char *chunk = chunks.vals[chunk_index].str;
i32 chunk_size = chunks.vals[chunk_index].size;
u8 *chunk = chunks.vals[chunk_index].str;
umem chunk_size = chunks.vals[chunk_index].size;
for (;!cpp_relex_is_start_chunk(&state, chunk, chunk_size);){
for (;!cpp_relex_is_start_chunk(&state, (char*)chunk, (i32)chunk_size);){
++chunk_index;
Assert(chunk_index < chunks.count);
chunk = chunks.vals[chunk_index].str;
chunk_size = chunks.vals[chunk_index].size;
}
for (;;){
Cpp_Lex_Result lex_result =
cpp_relex_step(&state, chunk, chunk_size, size, array, &relex_array);
for(;;){
Cpp_Lex_Result lex_result = cpp_relex_step(&state, (char*)chunk, (i32)chunk_size, size, array, &relex_array);
switch (lex_result){
case LexResult_NeedChunk:
@ -346,150 +450,28 @@ file_relex_parallel(System_Functions *system, Models *models, Editing_File *file
chunk_size = chunks.vals[chunk_index].size;
}break;
case LexResult_NeedTokenMemory:
{
internal_lex = false;
}goto doublebreak;
case LexResult_NeedTokenMemory: InvalidPath;
case LexResult_Finished: goto doublebreak;
}
}
doublebreak:;
if (internal_lex){
i32 new_count = cpp_relex_get_new_count(&state, array->count, &relex_array);
if (new_count > array->max_count){
i32 new_max = l_round_up_i32(new_count, KB(1));
void *memory = heap_allocate(heap, new_max*sizeof(Cpp_Token));
memcpy(memory, array->tokens, array->count*sizeof(Cpp_Token));
heap_free(heap, array->tokens);
array->tokens = (Cpp_Token*)memory;
array->max_count = new_max;
}
cpp_relex_complete(&state, array, &relex_array);
file_mark_edit_finished(&models->working_set, file);
}
else{
cpp_relex_abort(&state, array);
i32 new_count = cpp_relex_get_new_count(&state, array->count, &relex_array);
if (new_count > array->max_count){
i32 new_max = round_up_i32(new_count, KB(1));
Cpp_Token *new_tokens = heap_array(heap, Cpp_Token, new_max);
memcpy(new_tokens, array->tokens, array->count*sizeof(Cpp_Token));
heap_free(heap, array->tokens);
array->tokens = new_tokens;
array->max_count = new_max;
}
end_temp_memory(temp);
}
if (!internal_lex){
Cpp_Token_Array *array = &file->state.token_array;
Cpp_Get_Token_Result get_token_result = cpp_get_token(*array, end_i);
i32 end_token_i = get_token_result.token_index;
cpp_relex_complete(&state, array, &relex_array);
if (end_token_i < 0){
end_token_i = 0;
}
else if (end_i > array->tokens[end_token_i].start){
++end_token_i;
}
cpp_shift_token_starts(array, end_token_i, shift_amount);
--end_token_i;
if (end_token_i >= 0){
Cpp_Token *token = array->tokens + end_token_i;
if (token->start < end_i && token->start + token->size > end_i){
token->size += shift_amount;
}
}
file->state.still_lexing = true;
Job_Data job = {};
job.callback = job_full_lex;
job.data[0] = file;
job.data[1] = heap;
job.data[2] = models;
file->state.lex_job = system->post_job(BACKGROUND_THREADS, job);
result = false;
end_temp(temp);
}
return(result);
}
internal b32
file_relex_serial(System_Functions *system, Models *models, Editing_File *file, i32 start_i, i32 end_i, i32 shift_amount){
Mem_Options *mem = &models->mem;
Heap *heap = &mem->heap;
Partition *part = &mem->part;
if (file->state.token_array.tokens == 0){
file_first_lex_serial(system, models, file);
return(true);
}
Assert(!file->state.still_lexing);
Gap_Buffer *buffer = &file->state.buffer;
Cpp_Token_Array *array = &file->state.token_array;
Temp_Memory temp = begin_temp_memory(part);
Parse_Context parse_context = parse_context_get(&models->parse_context_memory, file->settings.parse_context_id, push_array(part, u8, 0), part_remaining(part));
Assert(parse_context.valid);
push_array(part, char, (i32)parse_context.memory_size);
Cpp_Token_Array relex_array;
relex_array.count = 0;
relex_array.max_count = part_remaining(part) / sizeof(Cpp_Token);
relex_array.tokens = push_array(part, Cpp_Token, relex_array.max_count);
i32 size = buffer_size(buffer);
Cpp_Relex_Data state = cpp_relex_init(array, start_i, end_i, shift_amount, file->settings.tokens_without_strings, parse_context.kw_table, parse_context.pp_table);
String chunk_space[3];
Partition chunk_part = make_part(chunk_space, sizeof(chunk_space));
String_Array chunks = file_lex_chunks(&chunk_part, buffer);
i32 chunk_index = 0;
char *chunk = chunks.vals[chunk_index].str;
i32 chunk_size = chunks.vals[chunk_index].size;
for (;!cpp_relex_is_start_chunk(&state, chunk, chunk_size);){
++chunk_index;
Assert(chunk_index < chunks.count);
chunk = chunks.vals[chunk_index].str;
chunk_size = chunks.vals[chunk_index].size;
}
for(;;){
Cpp_Lex_Result lex_result = cpp_relex_step(&state, chunk, chunk_size, size, array, &relex_array);
switch (lex_result){
case LexResult_NeedChunk:
{
++chunk_index;
Assert(chunk_index < chunks.count);
chunk = chunks.vals[chunk_index].str;
chunk_size = chunks.vals[chunk_index].size;
}break;
case LexResult_NeedTokenMemory: InvalidCodePath;
case LexResult_Finished: goto doublebreak;
}
}
doublebreak:;
i32 new_count = cpp_relex_get_new_count(&state, array->count, &relex_array);
if (new_count > array->max_count){
i32 new_max = l_round_up_i32(new_count, KB(1));
Cpp_Token *new_tokens = heap_array(heap, Cpp_Token, new_max);
memcpy(new_tokens, array->tokens, array->count*sizeof(Cpp_Token));
heap_free(heap, array->tokens);
array->tokens = new_tokens;
array->max_count = new_max;
}
cpp_relex_complete(&state, array, &relex_array);
end_temp_memory(temp);
return(true);
}

View File

@ -10,15 +10,15 @@
// TOP
internal Face_ID
font_get_id_by_name(System_Functions *system, String name){
font_get_id_by_name(System_Functions *system, String_Const_u8 name){
Face_ID id = 0;
u32 count = system->font.get_count();
for (Face_ID id_it = 1; id_it <= count; ++id_it){
char str[256];
i32 str_len = system->font.get_name_by_id(id_it, str, sizeof(str));
if (str_len > 0){
String font_name = make_string(str, str_len);
if (match_ss(font_name, name)){
String_Const_u8 font_name = SCu8(str, str_len);
if (string_match(font_name, name)){
id = id_it;
break;
}

View File

@ -58,7 +58,6 @@ font_ft_get_face(FT_Library ft, Font_Loadable_Stub *stub, Font_Parameters *param
else{
success = false;
}
end_temp_memory(path.temp);
}break;
case SystemFontMethod_RawData:
@ -75,7 +74,6 @@ font_ft_get_face(FT_Library ft, Font_Loadable_Stub *stub, Font_Parameters *param
else{
success = false;
}
end_temp_memory(data.temp);
}break;
}
}
@ -116,6 +114,8 @@ font_load_page_layout(Font_Settings *settings, Font_Metrics *metrics, Glyph_Page
u32 pt_size = settings->parameters.pt_size;
b32 use_hinting = settings->parameters.use_hinting;
Temp_Memory temp = begin_temp(&shared_vars.font_scratch);
// TODO(allen): Stop redoing all this init for each call.
FT_Library ft;
FT_Init_FreeType(&ft);
@ -197,11 +197,13 @@ font_load_page_layout(Font_Settings *settings, Font_Metrics *metrics, Glyph_Page
FT_Done_FreeType(ft);
end_temp(temp);
return(has_a_good_face);
}
internal u32*
font_load_page_pixels(Partition *part, Font_Settings *settings, Glyph_Page *page, u32 page_number, i32 *tex_width_out, i32 *tex_height_out){
font_load_page_pixels(Arena *arena, Font_Settings *settings, Glyph_Page *page, u32 page_number, i32 *tex_width_out, i32 *tex_height_out){
Assert(page != 0);
Assert(page->has_layout);
Assert(page->page_number == page_number);
@ -213,10 +215,10 @@ font_load_page_pixels(Partition *part, Font_Settings *settings, Glyph_Page *page
FT_Library ft;
FT_Init_FreeType(&ft);
FT_Face face;
b32 has_a_good_face = font_ft_get_face(ft, &settings->stub, &settings->parameters, &face);
u32 *pixels = 0;
FT_Face face;
b32 has_a_good_face = font_ft_get_face(ft, &settings->stub, &settings->parameters, &face);
if (has_a_good_face){
FT_Size_RequestRec_ size = {};
size.type = FT_SIZE_REQUEST_TYPE_NOMINAL;
@ -229,7 +231,7 @@ font_load_page_pixels(Partition *part, Font_Settings *settings, Glyph_Page *page
i32 tex_width = page->tex_width;
i32 tex_height = page->tex_height;
pixels = (u32*)sysshared_push_block(part, tex_width*tex_height*sizeof(u32));
pixels = push_array(arena, u32, tex_width*tex_height);
if (pixels != 0){
memset(pixels, 0, tex_width*tex_height*sizeof(u32));
@ -304,7 +306,7 @@ font_release_pages(System_Functions *system, Font_Page_Storage *storage){
Render_Pseudo_Command_Free_Texture *c = push_array(&target.buffer, Render_Pseudo_Command_Free_Texture, 1);
c->header.size = sizeof(*c);
c->free_texture_node.tex_id = this_page->gpu_tex;
sll_push(target.free_texture_first, target.free_texture_last, &c->free_texture_node);
sll_queue_push(target.free_texture_first, target.free_texture_last, &c->free_texture_node);
}
system->font.free(this_page);
}
@ -360,7 +362,7 @@ font_load(System_Functions *system, Font_Settings *settings, Font_Metrics *metri
f32 relative_thickness = notional_to_real_ratio*face->underline_thickness;
f32 center = (f32)floor32(metrics->ascent + relative_center);
f32 thickness = clamp_bottom(1.f, relative_thickness);
f32 thickness = clamp_bot(1.f, relative_thickness);
metrics->underline_yoff1 = center - thickness*0.5f;
metrics->underline_yoff2 = center + thickness*0.5f;
@ -458,7 +460,7 @@ Sys_Font_Face_Allocate_And_Init_Sig(system_font_face_allocate_and_init, new_sett
Assert(fontvars.used_slot_count <= slot_max);
if (fontvars.used_slot_count == slot_max){
i32 memsize = l_round_up_i32(SLOT_PAGE_SIZE, KB(4));
i32 memsize = round_up_i32(SLOT_PAGE_SIZE, KB(4));
i32 page_count = memsize/SLOT_PAGE_SIZE;
void *ptr = system_font_allocate(memsize);
memset(ptr, 0, memsize);
@ -724,11 +726,11 @@ Sys_Font_Load_Page_Sig(system_font_load_page, settings, metrics, page, page_numb
////////////////////////////////
internal Font_Setup_List
system_font_get_local_stubs(Partition *part){
system_font_get_local_stubs(Arena *arena){
Font_Setup_List list = {};
u32 dir_max = KB(32);
u8 *directory = push_array(part, u8, dir_max);
u8 *directory = push_array(arena, u8, dir_max);
String dir_str = make_string_cap(directory, 0, dir_max);
u32 dir_len = dir_str.size = system_get_4ed_path(dir_str.str, dir_str.memory_size);
Assert(dir_len < dir_max);
@ -737,8 +739,7 @@ system_font_get_local_stubs(Partition *part){
terminate_with_null(&dir_str);
dir_len = dir_str.size;
part_reduce(part, dir_max - dir_len - 1);
push_align(part, 8);
pop_array(arena, u8, dir_max - dir_len - 1);
File_List file_list = {};
system_set_file_list(&file_list, (char*)directory, 0, 0, 0);
@ -751,12 +752,8 @@ system_font_get_local_stubs(Partition *part){
for (;filename[len];++len);
if (dir_len + len + 1 <= sizeof(list.first->stub.name)){
Font_Setup *setup = push_array(part, Font_Setup, 1);
memset(setup, 0, sizeof(*setup));
part_align(part, 8);
sll_push(list.first, list.last, setup);
Font_Setup *setup = push_array_zero(arena, Font_Setup, 1);
sll_queue_push(list.first, list.last, setup);
setup->stub.load_from_path = true;
setup->stub.in_font_folder = true;
memcpy(&setup->stub.name[0], directory, dir_len);

View File

@ -77,14 +77,12 @@ struct Font_Setup_List{
// NOTE(allen): Procedures to be implemented per-OS for the freetype font provider.
struct Font_Path{
Temp_Memory temp;
char *name;
i32 len;
b32 used_base_file;
};
struct Font_Raw_Data{
Temp_Memory temp;
u8 *data;
i32 size;
b32 used_base_file;

View File

@ -27,7 +27,7 @@ history__to_node(Node *sentinel, i32 index){
internal void
history__push_back_record_ptr(Heap *heap, Record_Ptr_Lookup_Table *lookup, Record *record){
if (lookup->records == 0 || lookup->count == lookup->max){
i32 new_max = clamp_bottom(1024, lookup->max*2);
i32 new_max = clamp_bot(1024, lookup->max*2);
Record **new_records = (Record**)heap_allocate(heap, sizeof(Record*)*new_max);
block_copy(new_records, lookup->records, sizeof(*new_records)*lookup->count);
if (lookup->records != 0){
@ -120,7 +120,7 @@ global_history_get_edit_number(Global_History *global_history){
internal void
global_history_adjust_edit_grouping_counter(Global_History *global_history, i32 adjustment){
i32 original = global_history->edit_grouping_counter;
global_history->edit_grouping_counter = clamp_bottom(0, global_history->edit_grouping_counter + adjustment);
global_history->edit_grouping_counter = clamp_bot(0, global_history->edit_grouping_counter + adjustment);
if (global_history->edit_grouping_counter == 0 && original > 0){
global_history->edit_number_counter += 1;
}
@ -129,7 +129,7 @@ global_history_adjust_edit_grouping_counter(Global_History *global_history, i32
internal void
history_init(Application_Links *app, History *history){
history->activated = true;
history->arena = make_arena(app, KB(32));
history->arena = make_arena_app_links(app, KB(32));
memory_bank_init(&history->bank);
dll_init_sentinel(&history->free_records);
dll_init_sentinel(&history->records);
@ -145,7 +145,7 @@ history_is_activated(History *history){
internal void
history_free(Heap *heap, History *history){
if (history->activated){
arena_release_all(&history->arena);
linalloc_clear(&history->arena);
memory_bank_free_all(heap, &history->bank);
block_zero_struct(history);
}
@ -173,11 +173,11 @@ history_get_record(History *history, i32 index){
}
internal Record*
history_get_sub_record(Record *record, i32 sub_index){
history_get_sub_record(Record *record, i32 sub_index_one_based){
Record *result = 0;
if (record->kind == RecordKind_Group){
if (0 <= sub_index && sub_index <= record->group.count){
Node *node = history__to_node(&record->group.children, sub_index);
if (0 < sub_index_one_based && sub_index_one_based <= record->group.count){
Node *node = history__to_node(&record->group.children, sub_index_one_based);
if (node != 0){
result = CastFromMember(Record, node, node);
}
@ -245,7 +245,7 @@ history_record_edit(Heap *heap, Global_History *global_history, History *history
Record *new_record = history__allocate_record(heap, history);
history__stash_record(heap, history, new_record);
new_record->restore_point = temp_memory_light(begin_temp_memory(&history->arena));
new_record->restore_point = begin_temp(&history->arena);
new_record->edit_number = global_history_get_edit_number(global_history);
new_record->kind = RecordKind_Single;
@ -280,7 +280,7 @@ history_dump_records_after_index(History *history, i32 index){
Assert(first_node_to_clear != sentinel);
Record *first_record_to_clear = CastFromMember(Record, node, first_node_to_clear);
end_temp_memory(&history->arena, first_record_to_clear->restore_point);
end_temp(first_record_to_clear->restore_point);
Node *last_node_to_clear = sentinel->prev;
@ -292,7 +292,7 @@ history_dump_records_after_index(History *history, i32 index){
}
internal void
history__optimize_group(Partition *scratch, History *history, Record *record){
history__optimize_group(Arena *scratch, History *history, Record *record){
Assert(record->kind == RecordKind_Group);
for (;;){
Record *right = CastFromMember(Record, node, record->group.children.prev);
@ -312,7 +312,7 @@ history__optimize_group(Partition *scratch, History *history, Record *record){
if (right->kind == RecordKind_Single && left->kind == RecordKind_Single){
b32 do_merge = false;
Temp_Memory temp = begin_temp_memory(scratch);
Temp_Memory temp = begin_temp(scratch);
i32 new_length_forward = left->single.length_forward + right->single.length_forward ;
i32 new_length_backward = left->single.length_backward + right->single.length_backward;
@ -342,7 +342,7 @@ history__optimize_group(Partition *scratch, History *history, Record *record){
}
if (do_merge){
end_temp_memory(&history->arena, left->restore_point);
end_temp(left->restore_point);
char *new_str_forward = push_array(&history->arena, char, new_length_forward );
char *new_str_backward = push_array(&history->arena, char, new_length_backward);
@ -360,7 +360,7 @@ history__optimize_group(Partition *scratch, History *history, Record *record){
record->group.count -= 1;
}
end_temp_memory(temp);
end_temp(temp);
}
else{
break;
@ -369,7 +369,7 @@ history__optimize_group(Partition *scratch, History *history, Record *record){
}
internal void
history_merge_records(Partition *scratch, Heap *heap, History *history, i32 first_index, i32 last_index){
history_merge_records(Arena *scratch, Heap *heap, History *history, i32 first_index, i32 last_index){
if (history->activated){
Assert(history->record_lookup.count == history->record_count);
Assert(first_index < last_index);
@ -380,17 +380,14 @@ history_merge_records(Partition *scratch, Heap *heap, History *history, i32 firs
Record *new_record = history__allocate_record(heap, history);
Node *left = first_node->prev;
Node *right = last_node->next;
left->next = &new_record->node;
new_record->node.prev = left;
right->prev = &new_record->node;
new_record->node.next = right;
// NOTE(allen): here we remove (last_index - first_index + 1) nodes, and insert 1 node
// which simplifies to this:
history->record_count -= last_index - first_index;
Node *left = first_node->prev;
dll_remove_multiple(first_node, last_node);
dll_insert(left, &new_record->node);
Record *first_record = CastFromMember(Record, node, first_node);
Record *last_record = CastFromMember(Record, node, last_node);
@ -401,10 +398,9 @@ history_merge_records(Partition *scratch, Heap *heap, History *history, i32 firs
Node *new_sentinel = &new_record->group.children;
dll_init_sentinel(new_sentinel);
Node *one_past_last_node = last_node->next;
i32 count = 0;
for (Node *node = first_node, *next = 0;
node != one_past_last_node;
node != 0;
node = next){
next = node->next;
Record *record = CastFromMember(Record, node, node);
@ -422,18 +418,15 @@ history_merge_records(Partition *scratch, Heap *heap, History *history, i32 firs
Assert(first != &record->group.children);
Assert(last != &record->group.children);
Node *sub_right = new_sentinel;
Node *sub_left = new_sentinel->prev;
sub_left->next = first;
first->prev = sub_left;
last->next = sub_right;
sub_right->prev = last;
dll_insert_multiple_back(new_sentinel, first, last);
count += record->group.count;
// TODO(allen): free the record for the old group!?
}break;
default:
{
InvalidCodePath;
InvalidPath;
}break;
}
}

View File

@ -20,7 +20,7 @@ struct Record_Batch_Slot{
struct Record{
Node node;
Temp_Memory_Arena_Light restore_point;
Temp_Memory restore_point;
i32 edit_number;
Record_Kind kind;
union{

View File

@ -11,10 +11,10 @@
internal void
hot_directory_clean_end(Hot_Directory *hot_directory){
String *str = &hot_directory->string;
if (str->size != 0 && str->str[str->size-1] != '/'){
str->size = reverse_seek_slash(*str) + 1;
str->str[str->size] = 0;
String_Const_u8 str = SCu8(hot_directory->string_space, hot_directory->string_size);
if (!character_is_slash(string_get_character(str, str.size - 1))){
str = string_remove_last_folder(str);
str.str[str.size] = 0;
}
}
@ -23,10 +23,10 @@ hot_directory_quick_partition(File_Info *infos, i32 start, i32 pivot){
File_Info *p = infos + pivot;
File_Info *a = infos + start;
for (i32 i = start; i < pivot; ++i, ++a){
i32 comp = 0;
comp = p->folder - a->folder;
i32 comp = p->folder - a->folder;
if (comp == 0){
comp = compare_cc(a->filename, p->filename);
comp = string_compare(SCu8(a->filename, a->filename_len),
SCu8(p->filename, p->filename_len));
}
if (comp < 0){
Swap(File_Info, *a, infos[start]);
@ -53,28 +53,32 @@ hot_directory_fixup(Hot_Directory *hot_directory){
}
internal void
hot_directory_set(System_Functions *system, Hot_Directory *hot_directory, String str){
copy_checked_ss(&hot_directory->string, str);
b32 success = terminate_with_null(&hot_directory->string);
hot_directory_set(System_Functions *system, Hot_Directory *hot_directory, String_Const_u8 str){
b32 success = (str.size < sizeof(hot_directory->string_space));
if (success){
block_copy(hot_directory->string_space, str.str, str.size);
hot_directory->string_space[str.size] = 0;
hot_directory->string_size = str.size;
if (str.size > 0){
u32 canon_max = hot_directory->canon_dir.memory_size;
u32 canon_max = sizeof(hot_directory->canon_dir_space);
u8 *canon_str = hot_directory->canon_dir_space;
u32 canon_length = 0;
char *canon_str = hot_directory->canon_dir.str;
system->set_file_list(&hot_directory->file_list, hot_directory->string.str, canon_str, &canon_length, canon_max);
system->set_file_list(&hot_directory->file_list, (char*)hot_directory->string_space, (char*)canon_str, &canon_length, canon_max);
if (canon_length > 0){
hot_directory->canon_dir.size = canon_length;
if (!char_is_slash(hot_directory->canon_dir.str[canon_length-1])){
append_s_char(&hot_directory->canon_dir, '/');
hot_directory->canon_dir_size = canon_length;
if (!character_is_slash(hot_directory->canon_dir_space[canon_length - 1])){
hot_directory->canon_dir_space[hot_directory->canon_dir_size] = '/';
hot_directory->canon_dir_size += 1;
hot_directory->canon_dir_space[hot_directory->canon_dir_size] = 0;
}
}
else{
hot_directory->canon_dir.size = 0;
hot_directory->canon_dir_size = 0;
}
}
else{
system->set_file_list(&hot_directory->file_list, 0, 0, 0, 0);
hot_directory->canon_dir.size = 0;
hot_directory->canon_dir_size = 0;
}
}
hot_directory_fixup(hot_directory);
@ -82,19 +86,22 @@ hot_directory_set(System_Functions *system, Hot_Directory *hot_directory, String
internal void
hot_directory_reload(System_Functions *system, Hot_Directory *hot_directory){
hot_directory_set(system, hot_directory, hot_directory->string);
String_Const_u8 string = SCu8(hot_directory->string_space, hot_directory->string_size);
hot_directory_set(system, hot_directory, string);
}
internal void
hot_directory_init(Hot_Directory *hot_directory, String dir){
hot_directory->string = make_fixed_width_string(hot_directory->string_space);
hot_directory->canon_dir = make_fixed_width_string(hot_directory->canon_dir_space);
hot_directory->string.str[255] = 0;
hot_directory->string.size = 0;
copy_ss(&hot_directory->string, dir);
if (hot_directory->string.str[hot_directory->string.size-1] != '/'){
append_s_char(&hot_directory->string, '/');
hot_directory_init(Hot_Directory *hot_directory, String_Const_u8 dir){
hot_directory->string_size = 0;
umem size = clamp_top(dir.size, sizeof(hot_directory->string_space));
block_copy(hot_directory->string_space, dir.str, size);
if (dir.size < sizeof(hot_directory->string_space)){
if (hot_directory->string_space[size - 1] != '/'){
hot_directory->string_space[size] = '/';
size = clamp_top(size + 1, sizeof(hot_directory->string_space));
hot_directory->string_space[size] = 0;
hot_directory->string_size = size;
}
}
}

View File

@ -13,10 +13,10 @@
#define FRED_HOT_DIRECTORY_H
struct Hot_Directory{
char string_space[256];
char canon_dir_space[256];
String string;
String canon_dir;
u8 string_space[256];
umem string_size;
u8 canon_dir_space[256];
umem canon_dir_size;
File_List file_list;
};

View File

@ -74,7 +74,7 @@ layout__evaluate_split(Panel_Split split, i32 v0, i32 v1){
}break;
case PanelSplitKind_FixedPixels_Max:
{
v = clamp_bottom(v0, v1 - split.v_i32);
v = clamp_bot(v0, v1 - split.v_i32);
}break;
}
return(v);
@ -255,9 +255,9 @@ layout_close_panel(Layout *layout, Panel *panel){
}
internal Panel*
layout_initialize(Partition *part, Layout *layout){
layout_initialize(Arena *arena, Layout *layout){
i32 panel_alloc_count = MAX_VIEWS*2 - 1;
Panel *panels = push_array(part, Panel, panel_alloc_count);
Panel *panels = push_array(arena, Panel, panel_alloc_count);
block_zero(panels, sizeof(*panels)*panel_alloc_count);
layout->panel_first = panels;

View File

@ -10,73 +10,68 @@
// TODO(allen): Make these as fast as possible
#if 0
internal void
block_zero(void *a, umem_4tech size){
for (u8_4tech *ptr = (u8_4tech*)a, *e = ptr + size; ptr < e; ptr += 1){
block_zero(void *a, umem size){
for (u8 *ptr = (u8*)a, *e = ptr + size; ptr < e; ptr += 1){
*ptr = 0;
}
}
#define block_zero_struct(s) block_zero((s), sizeof(*(s)))
internal void
block_fill_ones(void *a, umem_4tech size){
for (u8_4tech *ptr = (u8_4tech*)a, *e = ptr + size; ptr < e; ptr += 1){
block_fill_ones(void *a, umem size){
for (u8 *ptr = (u8*)a, *e = ptr + size; ptr < e; ptr += 1){
*ptr = 0xFF;
}
}
internal void
block_copy(void *dst, void *src, umem_4tech size){
for (u8_4tech *d = (u8_4tech*)dst, *s = (u8_4tech*)src, *e = s + size; s < e; d += 1, s += 1){
block_copy(void *dst, void *src, umem size){
for (u8 *d = (u8*)dst, *s = (u8*)src, *e = s + size; s < e; d += 1, s += 1){
*d = *s;
}
}
internal i32_4tech
block_compare(void *a, void *b, umem_4tech size){
for (u8_4tech *aptr = (u8_4tech*)a, *bptr = (u8_4tech*)b, *e = bptr + size; bptr < e; aptr += 1, bptr += 1){
i32_4tech dif = (i32_4tech)*aptr - (i32_4tech)*bptr;
internal i32
block_compare(void *a, void *b, umem size){
for (u8 *aptr = (u8*)a, *bptr = (u8*)b, *e = bptr + size; bptr < e; aptr += 1, bptr += 1){
i32 dif = (i32)*aptr - (i32)*bptr;
if (dif != 0){
return(dif > 0?1:-1);
}
}
return(0);
}
internal void
block_fill_u8_4tech(void *a, umem_4tech size, u8_4tech val){
for (u8_4tech *ptr = (u8_4tech*)a, *e = ptr + size; ptr < e; ptr += 1){
block_fill_u8(void *a, umem size, u8 val){
for (u8 *ptr = (u8*)a, *e = ptr + size; ptr < e; ptr += 1){
*ptr = val;
}
}
internal void
block_fill_u16(void *a, umem size, u16 val){
Assert(size%sizeof(u16) == 0);
umem count = size/sizeof(u16);
for (u16 *ptr = (u16*)a, *e = ptr + count; ptr < e; ptr += 1){
*ptr = val;
}
}
internal void
block_fill_u32(void *a, umem size, u32 val){
Assert(size%sizeof(u32) == 0);
umem count = size/sizeof(u32);
for (u32 *ptr = (u32*)a, *e = ptr + count; ptr < e; ptr += 1){
*ptr = val;
}
}
internal void
block_fill_u64(void *a, umem size, u64 val){
Assert(size%sizeof(u64) == 0);
umem count = size/sizeof(u64);
for (u64 *ptr = (u64*)a, *e = ptr + count; ptr < e; ptr += 1){
*ptr = val;
}
}
internal void
block_fill_u16(void *a, umem_4tech size, u16_4tech val){
Assert(size%sizeof(u16_4tech) == 0);
umem_4tech count = size/sizeof(u16_4tech);
for (u16_4tech *ptr = (u16_4tech*)a, *e = ptr + count; ptr < e; ptr += 1){
*ptr = val;
}
}
internal void
block_fill_u32(void *a, umem_4tech size, u32_4tech val){
Assert(size%sizeof(u32_4tech) == 0);
umem_4tech count = size/sizeof(u32_4tech);
for (u32_4tech *ptr = (u32_4tech*)a, *e = ptr + count; ptr < e; ptr += 1){
*ptr = val;
}
}
internal void
block_fill_u64(void *a, umem_4tech size, u64_4tech val){
Assert(size%sizeof(u64_4tech) == 0);
umem_4tech count = size/sizeof(u64_4tech);
for (u64_4tech *ptr = (u64_4tech*)a, *e = ptr + count; ptr < e; ptr += 1){
*ptr = val;
}
}
#define block_zero_struct(s) block_zero((s), sizeof(*(s)))
#endif
// BOTTOM

View File

@ -21,11 +21,11 @@ internal void*
memory_bank_allocate(Heap *heap, Memory_Bank *mem_bank, i32 size){
void *ptr = heap_allocate(&mem_bank->heap, size);
if (ptr == 0){
i32 alloc_size = clamp_bottom(4096, size*4 + sizeof(Memory_Header));
i32 alloc_size = clamp_bot(4096, size*4 + sizeof(Memory_Header));
void *new_block = heap_allocate(heap, alloc_size);
if (new_block != 0){
Memory_Header *header = (Memory_Header*)new_block;
sll_push(mem_bank->first, mem_bank->last, header);
sll_queue_push(mem_bank->first, mem_bank->last, header);
mem_bank->total_memory_size += alloc_size;
heap_extend(&mem_bank->heap, header + 1, alloc_size - sizeof(*header));
ptr = heap_allocate(&mem_bank->heap, size);

View File

@ -11,11 +11,11 @@
internal void
parse_context_init_memory(Parse_Context_Memory *parse_mem, void *mem, umem memsize){
sll_init_sentinel(&parse_mem->free_sentinel);
parse_mem->free_list = 0;
parse_mem->parse_context_array = (Stored_Parse_Context_Slot*)mem;
parse_mem->parse_context_counter = 0;
parse_mem->parse_context_max = (u32)(memsize / sizeof(*parse_mem->parse_context_array));
parse_mem->parse_context_max = (u32)(memsize/sizeof(*parse_mem->parse_context_array));
}
internal Parse_Context_ID
@ -30,9 +30,9 @@ parse_context_valid_id(Parse_Context_Memory *parse_mem, Parse_Context_ID id){
internal Parse_Context_ID
parse_context_add(Parse_Context_Memory *parse_mem, Heap *heap, Parser_String_And_Type *kw_sats, u32 kw_count, Parser_String_And_Type *pp_sats, u32 pp_count){
Stored_Parse_Context_Slot *slot = 0;
if (parse_mem->free_sentinel.next != &parse_mem->free_sentinel){
slot = parse_mem->free_sentinel.next;
sll_remove(&parse_mem->free_sentinel, slot);
if (parse_mem->free_list != 0){
slot = parse_mem->free_list;
sll_stack_pop(parse_mem->free_list);
}
else if (parse_mem->parse_context_counter < parse_mem->parse_context_max){
slot = &parse_mem->parse_context_array[parse_mem->parse_context_counter++];
@ -72,9 +72,9 @@ parse_context_add(Parse_Context_Memory *parse_mem, Heap *heap, Parser_String_And
internal u32
parse_context_add_default(Parse_Context_Memory *parse_mem, Heap *heap){
Stored_Parse_Context_Slot *slot = 0;
if (parse_mem->free_sentinel.next != &parse_mem->free_sentinel){
slot = parse_mem->free_sentinel.next;
sll_remove(&parse_mem->free_sentinel, slot);
if (parse_mem->free_list != 0){
slot = parse_mem->free_list;
sll_stack_pop(parse_mem->free_list);
}
else if (parse_mem->parse_context_counter < parse_mem->parse_context_max){
slot = &parse_mem->parse_context_array[parse_mem->parse_context_counter++];
@ -109,10 +109,8 @@ parse_context_add_default(Parse_Context_Memory *parse_mem, Heap *heap){
return(result);
}
internal Parse_Context
parse_context_get(Parse_Context_Memory *parse_mem, Parse_Context_ID id, void *mem, umem memsize){
Parse_Context result = {};
internal Stored_Parse_Context_Slot*
parse_context_get_slot(Parse_Context_Memory *parse_mem, Parse_Context_ID id){
Stored_Parse_Context_Slot *slot = 0;
if (id == 0){
// do nothing
@ -120,14 +118,19 @@ parse_context_get(Parse_Context_Memory *parse_mem, Parse_Context_ID id, void *me
else{
id -= parse_mem->parse_context_max;
}
if (id < parse_mem->parse_context_counter){
slot = &parse_mem->parse_context_array[id];
if (slot->freed){
slot = 0;
}
}
return(slot);
}
internal Parse_Context
parse_context_get(Parse_Context_Memory *parse_mem, Parse_Context_ID id, void *mem, umem memsize){
Stored_Parse_Context_Slot *slot = parse_context_get_slot(parse_mem, id);
Parse_Context result = {};
if (slot != 0){
Stored_Parse_Context *context = slot->context;
if (context->memsize < memsize){
@ -143,7 +146,19 @@ parse_context_get(Parse_Context_Memory *parse_mem, Parse_Context_ID id, void *me
memcpy(mem, context, context->memsize);
}
}
return(result);
}
internal Parse_Context
parse_context_get(Arena *arena, Parse_Context_Memory *parse_mem, Parse_Context_ID id){
Stored_Parse_Context_Slot *slot = parse_context_get_slot(parse_mem, id);
Parse_Context result = {};
if (slot != 0){
Stored_Parse_Context *context = slot->context;
umem memsize = context->memsize + 1;
u8 *mem = push_array(arena, u8, memsize);
result = parse_context_get(parse_mem, id, mem, memsize);
}
return(result);
}

View File

@ -12,6 +12,8 @@
#if !defined(FRED_PARSE_CONTEXT_H)
#define FRED_PARSE_CONTEXT_H
// TODO(allen): this needs a rewrite
struct Stored_Parse_Context{
umem memsize;
u64 *kw_keywords;
@ -33,7 +35,7 @@ struct Parse_Context_Memory{
u32 parse_context_counter;
u32 parse_context_max;
Stored_Parse_Context_Slot free_sentinel;
Stored_Parse_Context_Slot *free_list;
};
struct Parse_Context{

View File

@ -159,14 +159,12 @@ insert_Ptr_table(Heap *heap, Ptr_Table *table, void* key){
if (table->mem != 0){
b32 result = move_Ptr_table(&new_table, table);
Assert(result);
AllowLocal(result);
heap_free(heap, table->mem);
}
*table = new_table;
}
b32 result = insert_Ptr_table(table, &key);
Assert(result);
AllowLocal(result);
}
////////////////////////////////
@ -351,14 +349,12 @@ insert_u32_Ptr_table(Heap *heap, u32_Ptr_Table *table, u32 key, void* val){
if (table->mem != 0){
b32 result = move_u32_Ptr_table(&new_table, table);
Assert(result);
AllowLocal(result);
heap_free(heap, table->mem);
}
*table = new_table;
}
b32 result = insert_u32_Ptr_table(table, &key, &val);
Assert(result);
AllowLocal(result);
}
// BOTTOM

View File

@ -135,8 +135,7 @@ snap_point_to_boundary(Vec2 point){
}
internal f32
draw_string(System_Functions *system, Render_Target *target, Face_ID font_id, String string, Vec2 point,
u32 color, u32 flags, Vec2 delta){
draw_string(System_Functions *system, Render_Target *target, Face_ID font_id, String_Const_u8 string, Vec2 point, u32 color, u32 flags, Vec2 delta){
f32 total_delta = 0.f;
Font_Pointers font = system->font.get_pointers_by_id(font_id);
@ -153,7 +152,7 @@ draw_string(System_Functions *system, Render_Target *target, Face_ID font_id, St
Translation_Emits emits = {};
for (u32 i = 0; str < str_end; ++str, ++i){
translating_fully_process_byte(system, font, &tran, *str, i, string.size, &emits);
translating_fully_process_byte(system, font, &tran, *str, i, (i32)string.size, &emits);
for (TRANSLATION_DECL_EMIT_LOOP(J, emits)){
TRANSLATION_DECL_GET_STEP(step, behavior, J, emits);
@ -190,31 +189,30 @@ draw_string(System_Functions *system, Render_Target *target, Face_ID font_id, St
}
internal f32
draw_string(System_Functions *system, Render_Target *target, Face_ID font_id, String string, Vec2 point,
u32 color){
draw_string(System_Functions *system, Render_Target *target, Face_ID font_id, String_Const_u8 string, Vec2 point, u32 color){
return(draw_string(system, target, font_id, string, point, color, 0, V2(1.f, 0.f)));
}
internal f32
draw_string(System_Functions *system, Render_Target *target, Face_ID font_id, char *str, Vec2 point,
draw_string(System_Functions *system, Render_Target *target, Face_ID font_id, u8 *str, Vec2 point,
u32 color, u32 flags, Vec2 delta){
return(draw_string(system, target, font_id, make_string_slowly(str), point, color, flags, delta));
return(draw_string(system, target, font_id, SCu8(str), point, color, flags, delta));
}
internal f32
draw_string(System_Functions *system, Render_Target *target, Face_ID font_id, char *str, Vec2 point,
draw_string(System_Functions *system, Render_Target *target, Face_ID font_id, u8 *str, Vec2 point,
u32 color){
return(draw_string(system, target, font_id, make_string_slowly(str), point, color, 0, V2(1.f, 0.f)));
return(draw_string(system, target, font_id, SCu8(str), point, color, 0, V2(1.f, 0.f)));
}
internal f32
font_string_width(System_Functions *system, Render_Target *target, Face_ID font_id, String str){
font_string_width(System_Functions *system, Render_Target *target, Face_ID font_id, String_Const_u8 str){
return(draw_string(system, target, font_id, str, V2(0, 0), 0, 0, V2(0, 0)));
}
internal f32
font_string_width(System_Functions *system, Render_Target *target, Face_ID font_id, char *str){
return(draw_string(system, target, font_id, make_string_slowly(str), V2(0, 0), 0, 0, V2(0, 0)));
font_string_width(System_Functions *system, Render_Target *target, Face_ID font_id, u8 *str){
return(draw_string(system, target, font_id, SCu8(str), V2(0, 0), 0, 0, V2(0, 0)));
}
// BOTTOM

View File

@ -34,7 +34,8 @@ struct Render_Target{
Render_Free_Texture *free_texture_first;
Render_Free_Texture *free_texture_last;
Partition buffer;
// TODO(allen): rewrite render system to work on an arena
Cursor buffer;
};
#endif

View File

@ -9,6 +9,8 @@
// TOP
// TODO(allen): rewrite using new arenas and strings!!!!! rewrite rewrite rewrite rewrite rewrite
#if !defined(FCODER_SYSTEM_INTERFACE_H)
#define FCODER_SYSTEM_INTERFACE_H
@ -31,7 +33,7 @@ typedef Sys_Set_File_List_Sig(System_Set_File_List);
typedef Sys_Get_Canonical_Sig(System_Get_Canonical);
// file load/save
#define Sys_Quick_File_Attributes_Sig(name) File_Attributes name(String file_name)
#define Sys_Quick_File_Attributes_Sig(name) File_Attributes name(String_Const_u8 file_name)
typedef Sys_Quick_File_Attributes_Sig(System_Quick_File_Attributes);
#define Sys_Load_Handle_Sig(name) b32 name(char *filename, Plat_Handle *handle_out)
@ -76,7 +78,7 @@ typedef Sys_Wake_Up_Timer_Set_Sig(System_Wake_Up_Timer_Set);
typedef Sys_Wake_Up_Timer_Check_Sig(System_Wake_Up_Timer_Check);
// clipboard
#define Sys_Post_Clipboard_Sig(name) void name(String str)
#define Sys_Post_Clipboard_Sig(name) void name(String_Const_u8 str)
typedef Sys_Post_Clipboard_Sig(System_Post_Clipboard);
// cli

View File

@ -9,10 +9,11 @@
// TOP
// TODO(allen): REWRITE REWRITE REWRITE!!!
internal void
text_layout_init(Application_Links *app, Text_Layout_Container *container){
block_zero_struct(container);
container->node_arena = make_arena(app);
container->node_arena = make_arena_app_links(app);
}
internal Text_Layout*

Some files were not shown because too many files have changed in this diff Show More