diff --git a/4coder_API.html b/4coder_API.html
index 7bef8f01..69e0b799 100644
--- a/4coder_API.html
+++ b/4coder_API.html
@@ -22,7 +22,7 @@ ul { list-style: none; padding: 0; margin: 0; }
§1 Introduction
-This is the documentation for alpha 4.0.10 The documentation is still under construction so some of the links are linking to sections that have not been written yet. What is here should be correct and I suspect useful even without some of the other sections.
+This is the documentation for alpha 4.0.10 super! The documentation is still under construction so some of the links are linking to sections that have not been written yet. What is here should be correct and I suspect useful even without some of the other sections.
If you have questions or discover errors please contact editor@4coder.net or to get help from community members you can post on the 4coder forums hosted on handmade.network at 4coder.handmade.network
@@ -34,9 +34,6 @@ Coming Soon
-
-
§3.3.3: memory_alloc
-
void* app->memory_alloc(
-
Application_Links *app,
int32_t size
)
-
-
Description
TODO
-
-
§3.3.4: memory_set_protection
-
int32_t app->memory_set_protection(
-
Application_Links *app,
void *ptr,
int32_t size,
Memory_Protect_Flags flags
)
-
-
Description
TODO
-
-
§3.3.5: memory_free
-
void app->memory_free(
-
Application_Links *app,
void *mem
)
-
-
Description
TODO
-
§3.3.6: clipboard_post
+
§3.3.3: clipboard_post
void app->clipboard_post(
Application_Links *app,
int32_t clipboard_id,
char *str,
int32_t len
)
@@ -225,7 +207,7 @@ If the view parameter is NULL, no view will switch to the output.
-
§3.3.7: clipboard_count
+
§3.3.4: clipboard_count
int32_t app->clipboard_count(
Application_Links *app,
int32_t clipboard_id
)
@@ -235,7 +217,7 @@ be pasted into other applications.
Description
This call returns the number of items in the clipboard.
See Also
-
§3.3.8: clipboard_index
+
§3.3.5: clipboard_index
int32_t app->clipboard_index(
Application_Links *app,
int32_t clipboard_id,
int32_t item_index,
char *out,
int32_t len
)
@@ -259,13 +241,13 @@ be pasted into other applications.
See Also
-
§3.3.9: get_buffer_count
+
§3.3.6: get_buffer_count
int32_t app->get_buffer_count(
Application_Links *app
)
Description
TODO
-
§3.3.10: get_buffer_first
+
§3.3.7: get_buffer_first
Buffer_Summary app->get_buffer_first(
Application_Links *app,
Access_Flag access
)
@@ -278,7 +260,7 @@ first len character of the clipboard contents. The output string is not null te
If the buffer returned does not exist, the loop is finished.
Buffers should not be killed durring a buffer loop.
See Also
-
§3.3.11: get_buffer_next
+
§3.3.8: get_buffer_next
void app->get_buffer_next(
Application_Links *app,
Buffer_Summary *buffer,
Access_Flag access
)
@@ -296,7 +278,7 @@ The global buffer order is kept roughly in the order of most recently used to le
If the buffer outputted does not exist, the loop is finished.
Buffers should not be killed or created durring a buffer loop.
See Also
-
§3.3.12: get_buffer
+
§3.3.9: get_buffer
Buffer_Summary app->get_buffer(
Application_Links *app,
Buffer_ID buffer_id,
Access_Flag access
)
@@ -310,7 +292,7 @@ Buffers should not be killed or created durring a buffer loop.
Return
This call returns a summary that describes the indicated buffer if it exists and is accessible.
See Also
-
§3.3.13: get_buffer_by_name
+
§3.3.10: get_buffer_by_name
Buffer_Summary app->get_buffer_by_name(
Application_Links *app,
char *name,
int32_t len,
Access_Flag access
)
@@ -328,7 +310,7 @@ Buffers should not be killed or created durring a buffer loop.
Return
This call returns a summary that describes the indicated buffer if it exists and is accessible.
See Also
-
§3.3.14: buffer_boundary_seek
+
§3.3.11: buffer_boundary_seek
int32_t app->buffer_boundary_seek(
Application_Links *app,
Buffer_Summary *buffer,
int32_t start_pos,
bool32 seek_forward,
Seek_Boundary_Flag flags
)
@@ -352,7 +334,7 @@ Buffers should not be killed or created durring a buffer loop.
See Also
-
§3.3.15: buffer_read_range
+
§3.3.12: buffer_read_range
bool32 app->buffer_read_range(
Application_Links *app,
Buffer_Summary *buffer,
int32_t start,
int32_t end,
char *out
)
@@ -378,7 +360,7 @@ The output is not null terminated.
This call fails if the buffer does not exist,
or if the read range is not within the bounds of the buffer.
See Also
-
§3.3.16: buffer_replace_range
+
§3.3.13: buffer_replace_range
bool32 app->buffer_replace_range(
Application_Links *app,
Buffer_Summary *buffer,
int32_t start,
int32_t end,
char *str,
int32_t len
)
@@ -411,7 +393,7 @@ from start to end.
This call fails if the buffer does not exist, or if the replace
range is not within the bounds of the buffer.
See Also
-
§3.3.17: buffer_batch_edit
+
§3.3.14: buffer_batch_edit
bool32 app->buffer_batch_edit(
Application_Links *app,
Buffer_Summary *buffer,
char *str,
int32_t str_len,
Buffer_Edit *edits,
int32_t edit_count,
Buffer_Batch_Edit_Type type
)
@@ -437,7 +419,7 @@ range is not within the bounds of the buffer.
Return
This call returns non-zero if the batch edit succeeds.
Description
TODO
See Also
-
§3.3.18: buffer_set_setting
+
§3.3.15: buffer_set_setting
bool32 app->buffer_set_setting(
Application_Links *app,
Buffer_Summary *buffer,
Buffer_Setting_ID setting,
int32_t value
)
@@ -455,7 +437,7 @@ range is not within the bounds of the buffer.
See Also
-
§3.3.19: buffer_auto_indent
+
§3.3.16: buffer_auto_indent
bool32 app->buffer_auto_indent(
Application_Links *app,
Buffer_Summary *buffer,
int32_t start,
int32_t end,
int32_t tab_width,
Auto_Indent_Flag flags
)
@@ -484,7 +466,7 @@ start to end by inserting spaces or tabs at the beginning of the lines.
If the buffer does not have lexing enabled or the lexing job has not
completed this function will fail.
See Also
-
§3.3.20: create_buffer
+
§3.3.17: create_buffer
Buffer_Summary app->create_buffer(
Application_Links *app,
char *filename,
int32_t filename_len,
Buffer_Create_Flag flags
)
@@ -506,7 +488,7 @@ If the buffer does not exist a new buffer is created and named after the given f
the filename corresponds to a file on the disk that file is loaded and put into buffer, if
the filename does not correspond to a file on disk the buffer is created empty.
See Also
-
§3.3.21: save_buffer
+
§3.3.18: save_buffer
bool32 app->save_buffer(
Application_Links *app,
Buffer_Summary *buffer,
char *filename,
int32_t filename_len,
uint32_t flags
)
@@ -528,7 +510,7 @@ the filename does not correspond to a file on disk the buffer is created empty.<
Return
This call returns non-zero on success.
-
§3.3.22: kill_buffer
+
§3.3.19: kill_buffer
bool32 app->kill_buffer(
Application_Links *app,
Buffer_Identifier buffer,
View_ID view_id,
Buffer_Kill_Flag flags
)
@@ -548,7 +530,7 @@ the filename does not correspond to a file on disk the buffer is created empty.<
dialogue needs to be displayed the provided view is used to show the dialogue.
If the view is not open the kill fails.
See Also
-
§3.3.23: get_view_first
+
§3.3.20: get_view_first
View_Summary app->get_view_first(
Application_Links *app,
Access_Flag access
)
@@ -561,7 +543,7 @@ If the view is not open the kill fails.
See Also
-
§3.3.24: get_view_next
+
§3.3.21: get_view_next
void app->get_view_next(
Application_Links *app,
View_Summary *view,
Access_Flag access
)
@@ -578,7 +560,7 @@ Views should not be closed or opened durring a view loop.
See Also
-
§3.3.25: get_view
+
§3.3.22: get_view
View_Summary app->get_view(
Application_Links *app,
View_ID view_id,
Access_Flag access
)
@@ -592,7 +574,7 @@ Views should not be closed or opened durring a view loop.
Return
This call returns a summary that describes the indicated view if it is open and accessible.
See Also
-
§3.3.26: get_active_view
+
§3.3.23: get_active_view
View_Summary app->get_active_view(
Application_Links *app,
Access_Flag access
)
@@ -602,7 +584,7 @@ Views should not be closed or opened durring a view loop.
Return
This call returns a summary that describes the active view.
See Also
-
§3.3.27: open_view
+
§3.3.24: open_view
View_Summary app->open_view(
Application_Links *app,
View_Summary *view_location,
View_Split_Position position
)
@@ -618,7 +600,7 @@ Views should not be closed or opened durring a view loop.
Description
4coder is built with a limit of 16 views. If 16 views are already open when this is called the
call will fail.
See Also
-
§3.3.28: close_view
+
§3.3.25: close_view
bool32 app->close_view(
Application_Links *app,
View_Summary *view
)
@@ -631,7 +613,7 @@ If the given view is the active view, the next active view in the global
order of view will be made active.
If the given view is the last open view in the system, the call will fail.
-
§3.3.29: set_active_view
+
§3.3.26: set_active_view
bool32 app->set_active_view(
Application_Links *app,
View_Summary *view
)
@@ -643,7 +625,7 @@ If the given view is the last open view in the system, the call will fail.
active view, and takes subsequent commands and is returned
from get_active_view.See Also
-
§3.3.30: view_set_setting
+
§3.3.27: view_set_setting
bool32 app->view_set_setting(
Application_Links *app,
View_Summary *view,
View_Setting_ID setting,
int32_t value
)
@@ -661,7 +643,7 @@ from get_active_view.
Return
This call returns non-zero on success.
See Also
-
§3.3.31: view_set_split_proportion
+
§3.3.28: view_set_split_proportion
bool32 app->view_set_split_proportion(
Application_Links *app,
View_Summary *view,
float t
)
@@ -675,7 +657,7 @@ from get_active_view.
Return
This call returns non-zero on success.
-
§3.3.32: view_compute_cursor
+
§3.3.29: view_compute_cursor
bool32 app->view_compute_cursor(
Application_Links *app,
View_Summary *view,
Buffer_Seek seek,
Full_Cursor *cursor_out
)
@@ -693,7 +675,7 @@ from get_active_view.
Return
This call returns non-zero on success.
Description
Computes a Full_Cursor for the given seek position with no side effects.
See Also
-
§3.3.33: view_set_cursor
+
§3.3.30: view_set_cursor
bool32 app->view_set_cursor(
Application_Links *app,
View_Summary *view,
Buffer_Seek seek,
bool32 set_preferred_x
)
@@ -713,7 +695,7 @@ from get_active_view.
See Also
-
§3.3.34: view_set_mark
+
§3.3.31: view_set_mark
bool32 app->view_set_mark(
Application_Links *app,
View_Summary *view,
Buffer_Seek seek
)
@@ -727,7 +709,7 @@ cursor in the same column or x position.
Return
This call returns non-zero on success.
Description
This call sets the the view's mark position.
See Also
-
§3.3.35: view_set_highlight
+
§3.3.32: view_set_highlight
bool32 app->view_set_highlight(
Application_Links *app,
View_Summary *view,
int32_t start,
int32_t end,
bool32 turn_on
)
@@ -752,7 +734,7 @@ is set to true the highlight will be shown and the cursor will be hidden. After
that either setting the with view_set_cursor or calling view_set_highlight and
the turn_on set to false, will switch back to showing the cursor.
-
§3.3.36: view_set_buffer
+
§3.3.33: view_set_buffer
bool32 app->view_set_buffer(
Application_Links *app,
View_Summary *view,
Buffer_ID buffer_id,
Set_Buffer_Flag flags
)
@@ -771,7 +753,7 @@ the turn_on set to false, will switch back to showing the cursor.
ReturnThis call returns non-zero on success.
Description
On success view_set_buffer sets the specified view's current buffer and
cancels and dialogue shown in the view and displays the file.
See Also
-
§3.3.37: view_post_fade
+
§3.3.34: view_post_fade
bool32 app->view_post_fade(
Application_Links *app,
View_Summary *view,
float seconds,
int32_t start,
int32_t end,
int_color color
)
@@ -797,7 +779,7 @@ cancels and dialogue shown in the view and displays the file.
Return
This call returns non-zero on success.
See Also
See Also
-
§3.3.40: get_mouse_state
+
§3.3.37: get_mouse_state
Mouse_State app->get_mouse_state(
Application_Links *app
)
Return
This call returns the current mouse state as of the beginning of the frame.
See Also
-
§3.3.41: start_query_bar
+
§3.3.38: start_query_bar
bool32 app->start_query_bar(
Application_Links *app,
Query_Bar *bar,
uint32_t flags
)
@@ -847,7 +829,7 @@ can be changed after the call to start_query_bar and the query bar shown by 4cod
will reflect the change. Since the bar stops showing when the command exits the
only use for this call is in an interactive command that makes calls to get_user_input.
-
§3.3.42: end_query_bar
+
§3.3.39: end_query_bar
void app->end_query_bar(
Application_Links *app,
Query_Bar *bar,
uint32_t flags
)
@@ -861,7 +843,7 @@ only use for this call is in an interactive command that makes calls to get_user
Description
Stops showing the particular query bar specified by the bar parameter.
-
§3.3.43: print_message
+
§3.3.40: print_message
void app->print_message(
Application_Links *app,
char *str,
int32_t len
)
@@ -875,7 +857,7 @@ only use for this call is in an interactive command that makes calls to get_user
Description
This call posts a string to the *messages* buffer.
-
§3.3.44: change_theme
+
§3.3.41: change_theme
void app->change_theme(
Application_Links *app,
char *name,
int32_t len
)
@@ -889,7 +871,7 @@ only use for this call is in an interactive command that makes calls to get_user
Description
This call changes 4coder's theme to one of the built in themes.
-
§3.3.45: change_font
+
§3.3.42: change_font
void app->change_font(
Application_Links *app,
char *name,
int32_t len
)
@@ -903,7 +885,7 @@ only use for this call is in an interactive command that makes calls to get_user
Description
This call changes 4coder's font to one of the built in fonts.
-
§3.3.46: set_theme_colors
+
§3.3.43: set_theme_colors
void app->set_theme_colors(
Application_Links *app,
Theme_Color *colors,
int32_t count
)
@@ -919,7 +901,7 @@ only use for this call is in an interactive command that makes calls to get_user
struct's tag is set to the color code in the struct. If the tag value is invalid
no change is made to the color pallet.
-
§3.3.47: get_theme_colors
+
§3.3.44: get_theme_colors
void app->get_theme_colors(
Application_Links *app,
Theme_Color *colors,
int32_t count
)
@@ -935,7 +917,7 @@ no change is made to the color pallet.
color from the slot in the main color pallet specified by the tag. If the tag
value is invalid the color is filled with black.
-
§3.3.48: directory_get_hot
+
§3.3.45: directory_get_hot
int32_t app->directory_get_hot(
Application_Links *app,
char *out,
int32_t capacity
)
@@ -953,7 +935,7 @@ accessed in the GUI. Whenever the GUI is opened it shows the hot directory.
In the future this will be deprecated and eliminated in favor of more flexible
directories controlled on the custom side.
-
§3.3.49: get_file_list
+
§3.3.46: get_file_list
File_List app->get_file_list(
Application_Links *app,
char *dir,
int32_t len
)
@@ -969,7 +951,7 @@ directories controlled on the custom side.
the specified directory. The File_List returned should be passed to free_file_list
when it is no longer in use.
-
§3.3.50: free_file_list
+
§3.3.47: free_file_list
void app->free_file_list(
Application_Links *app,
File_List list
)
@@ -978,6 +960,24 @@ when it is no longer in use.
This parameter provides the file list to be freed.
Description
After this call the file list passed in should not be read or written to.
+
+
§3.3.48: memory_allocate
+
void* app->memory_allocate(
+
Application_Links *app,
int32_t size
)
+
+
Description
TODO
+
+
§3.3.49: memory_set_protection
+
bool32 app->memory_set_protection(
+
Application_Links *app,
void *ptr,
int32_t size,
Memory_Protect_Flags flags
)
+
+
Description
TODO
+
+
§3.3.50: memory_free
+
void app->memory_free(
+
Application_Links *app,
void *mem,
int32_t size
)
+
+
Description
TODO
§3.3.51: file_exists
bool32 app->file_exists(
@@ -1373,15 +1373,15 @@ Flags can be combined with bit or to specify a state with multiple modifiers.enum Memory_Protect_Flags;
Description
TODO
Flags
MemProtect_Read = 0x1
-
+
MemProtect_Write = 0x2
-
+
MemProtect_Execute = 0x4
-
+
diff --git a/4coder_custom_api.h b/4coder_custom_api.h
index 9908cb45..81a12a9c 100644
--- a/4coder_custom_api.h
+++ b/4coder_custom_api.h
@@ -1,8 +1,5 @@
#define EXEC_COMMAND_SIG(n) bool32 n(Application_Links *app, Command_ID command_id)
#define EXEC_SYSTEM_COMMAND_SIG(n) bool32 n(Application_Links *app, View_Summary *view, Buffer_Identifier buffer, char *path, int32_t path_len, char *command, int32_t command_len, Command_Line_Input_Flag flags)
-#define MEMORY_ALLOC_SIG(n) void* n(Application_Links *app, int32_t size)
-#define MEMORY_SET_PROTECTION_SIG(n) int32_t n(Application_Links *app, void *ptr, int32_t size, Memory_Protect_Flags flags)
-#define MEMORY_FREE_SIG(n) void n(Application_Links *app, void *mem)
#define CLIPBOARD_POST_SIG(n) void n(Application_Links *app, int32_t clipboard_id, char *str, int32_t len)
#define CLIPBOARD_COUNT_SIG(n) int32_t n(Application_Links *app, int32_t clipboard_id)
#define CLIPBOARD_INDEX_SIG(n) int32_t n(Application_Links *app, int32_t clipboard_id, int32_t item_index, char *out, int32_t len)
@@ -48,6 +45,9 @@
#define DIRECTORY_GET_HOT_SIG(n) int32_t n(Application_Links *app, char *out, int32_t capacity)
#define GET_FILE_LIST_SIG(n) File_List n(Application_Links *app, char *dir, int32_t len)
#define FREE_FILE_LIST_SIG(n) void n(Application_Links *app, File_List list)
+#define MEMORY_ALLOCATE_SIG(n) void* n(Application_Links *app, int32_t size)
+#define MEMORY_SET_PROTECTION_SIG(n) bool32 n(Application_Links *app, void *ptr, int32_t size, Memory_Protect_Flags flags)
+#define MEMORY_FREE_SIG(n) void n(Application_Links *app, void *mem, int32_t size)
#define FILE_EXISTS_SIG(n) bool32 n(Application_Links *app, char *filename, int len)
#define DIRECTORY_CD_SIG(n) bool32 n(Application_Links *app, char *dir, int *len, int capacity, char *rel_path, int rel_len)
#define GET_4ED_PATH_SIG(n) bool32 n(Application_Links *app, char *out, int32_t capacity)
@@ -55,9 +55,6 @@
extern "C"{
typedef EXEC_COMMAND_SIG(Exec_Command_Function);
typedef EXEC_SYSTEM_COMMAND_SIG(Exec_System_Command_Function);
- typedef MEMORY_ALLOC_SIG(Memory_Alloc_Function);
- typedef MEMORY_SET_PROTECTION_SIG(Memory_Set_Protection_Function);
- typedef MEMORY_FREE_SIG(Memory_Free_Function);
typedef CLIPBOARD_POST_SIG(Clipboard_Post_Function);
typedef CLIPBOARD_COUNT_SIG(Clipboard_Count_Function);
typedef CLIPBOARD_INDEX_SIG(Clipboard_Index_Function);
@@ -103,6 +100,9 @@ extern "C"{
typedef DIRECTORY_GET_HOT_SIG(Directory_Get_Hot_Function);
typedef GET_FILE_LIST_SIG(Get_File_List_Function);
typedef FREE_FILE_LIST_SIG(Free_File_List_Function);
+ typedef MEMORY_ALLOCATE_SIG(Memory_Allocate_Function);
+ typedef MEMORY_SET_PROTECTION_SIG(Memory_Set_Protection_Function);
+ typedef MEMORY_FREE_SIG(Memory_Free_Function);
typedef FILE_EXISTS_SIG(File_Exists_Function);
typedef DIRECTORY_CD_SIG(Directory_CD_Function);
typedef GET_4ED_PATH_SIG(Get_4ed_Path_Function);
@@ -113,9 +113,6 @@ struct Application_Links{
int memory_size;
Exec_Command_Function *exec_command;
Exec_System_Command_Function *exec_system_command;
- Memory_Alloc_Function *memory_alloc;
- Memory_Set_Protection_Function *memory_set_protection;
- Memory_Free_Function *memory_free;
Clipboard_Post_Function *clipboard_post;
Clipboard_Count_Function *clipboard_count;
Clipboard_Index_Function *clipboard_index;
@@ -161,6 +158,9 @@ struct Application_Links{
Directory_Get_Hot_Function *directory_get_hot;
Get_File_List_Function *get_file_list;
Free_File_List_Function *free_file_list;
+ Memory_Allocate_Function *memory_allocate;
+ Memory_Set_Protection_Function *memory_set_protection;
+ Memory_Free_Function *memory_free;
File_Exists_Function *file_exists;
Directory_CD_Function *directory_cd;
Get_4ed_Path_Function *get_4ed_path;
@@ -173,9 +173,6 @@ struct Application_Links{
#define FillAppLinksAPI(app_links) do{\
app_links->exec_command = Exec_Command;\
app_links->exec_system_command = Exec_System_Command;\
-app_links->memory_alloc = Memory_Alloc;\
-app_links->memory_set_protection = Memory_Set_Protection;\
-app_links->memory_free = Memory_Free;\
app_links->clipboard_post = Clipboard_Post;\
app_links->clipboard_count = Clipboard_Count;\
app_links->clipboard_index = Clipboard_Index;\
@@ -221,6 +218,9 @@ app_links->get_theme_colors = Get_Theme_Colors;\
app_links->directory_get_hot = Directory_Get_Hot;\
app_links->get_file_list = Get_File_List;\
app_links->free_file_list = Free_File_List;\
+app_links->memory_allocate = Memory_Allocate;\
+app_links->memory_set_protection = Memory_Set_Protection;\
+app_links->memory_free = Memory_Free;\
app_links->file_exists = File_Exists;\
app_links->directory_cd = Directory_CD;\
app_links->get_4ed_path = Get_4ed_Path;\
diff --git a/4coder_default_bindings.cpp b/4coder_default_bindings.cpp
index 364688bd..566f8bc0 100644
--- a/4coder_default_bindings.cpp
+++ b/4coder_default_bindings.cpp
@@ -133,6 +133,8 @@ HOOK_SIG(my_start){
app->change_theme(app, literal("4coder"));
app->change_font(app, literal("Liberation Sans"));
+ init_memory(app);
+
// Theme options:
// "4coder"
// "Handmade Hero"
@@ -291,7 +293,7 @@ default_keys(Bind_Helper *context){
bind(context, ';', MDFR_NONE, write_and_auto_tab);
bind(context, '#', MDFR_NONE, write_and_auto_tab);
- bind(context, '\t', MDFR_NONE, cmdid_word_complete);
+ bind(context, '\t', MDFR_NONE, word_complete);
bind(context, '\t', MDFR_CTRL, auto_tab_range);
bind(context, '\t', MDFR_SHIFT, auto_tab_line_at_cursor);
diff --git a/4coder_default_include.cpp b/4coder_default_include.cpp
index b58cdd1d..bb47be5c 100644
--- a/4coder_default_include.cpp
+++ b/4coder_default_include.cpp
@@ -15,8 +15,21 @@
// Memory
//
-static Partition scratch;
+static Partition part;
+static General_Memory general;
+void
+init_memory(Application_Links *app){
+ int part_size = (1 << 20);
+ int general_size = (1 << 20);
+
+
+ void *part_mem = app->memory_allocate(app, part_size);
+ part = make_part(part_mem, part_size);
+
+ void *general_mem = app->memory_allocate(app, general_size);
+ general_memory_open(&general, general_mem, general_size);
+}
//
// Buffer Streaming
@@ -819,6 +832,7 @@ CUSTOM_COMMAND_SIG(to_uppercase){
mem[i] = char_to_upper(mem[i]);
}
app->buffer_replace_range(app, &buffer, range.min, range.max, mem, size);
+ app->view_set_cursor(app, &view, seek_pos(range.max), true);
}
}
@@ -836,6 +850,7 @@ CUSTOM_COMMAND_SIG(to_lowercase){
mem[i] = char_to_lower(mem[i]);
}
app->buffer_replace_range(app, &buffer, range.min, range.max, mem, size);
+ app->view_set_cursor(app, &view, seek_pos(range.max), true);
}
}
@@ -2192,7 +2207,7 @@ CUSTOM_COMMAND_SIG(word_complete){
if (view_paste_index[view.view_id].rewrite != RewriteWordComplete){
do_init = true;
}
- view_paste_index[view.view_id].next_rewrite != RewriteWordComplete;
+ view_paste_index[view.view_id].next_rewrite = RewriteWordComplete;
if (!complete_state.initialized){
do_init = true;
}
@@ -2297,7 +2312,8 @@ CUSTOM_COMMAND_SIG(word_complete){
if (match.found_match){
int match_size = match.end - match.start;
- char *spare = (char*)GET_MEMORY(match_size);
+ Temp_Memory temp = begin_temp_memory(&part);
+ char *spare = push_array(&part, char, match_size);
app->buffer_read_range(app, &match.buffer,
match.start, match.end, spare);
@@ -2312,10 +2328,10 @@ CUSTOM_COMMAND_SIG(word_complete){
complete_state.word_end = word_start + match_size;
complete_state.set.ranges[0].mid_size = match_size;
- FREE_MEMORY(spare);
+ end_temp_memory(temp);
break;
}
- FREE_MEMORY(spare);
+ end_temp_memory(temp);
}
else{
complete_state.iter.pos = 0;
diff --git a/4coder_search.cpp b/4coder_search.cpp
index 94ec9206..6989ae61 100644
--- a/4coder_search.cpp
+++ b/4coder_search.cpp
@@ -38,24 +38,17 @@ struct Search_Match{
int found_match;
};
-// TODO(allen): HOW DO I WANT TO GET MEMORY CUSTOM SIDE??
-#define GET_MEMORY(a) (void*)(0)
-#define REGET_MEMORY(a,b) (void*)(0)
-#define REGET_NOCOPY_MEMORY(a,b) (void*)(0)
-#define FREE_MEMORY(a) (void)(a)
-
static void
search_iter_init(Application_Links *app, Search_Iter *iter, int size){
int str_max = size*2;
if (iter->word.str == 0){
- iter->word.str = (char*)GET_MEMORY(str_max);
+ iter->word.str = (char*)general_memory_allocate(&general, str_max);
iter->word.memory_size = str_max;
}
else if (iter->word.memory_size < size){
- iter->word.str = (char*)REGET_MEMORY(iter->word.str, str_max);
+ iter->word.str = (char*)general_memory_reallocate_nocopy(&general, iter->word.str, str_max);
iter->word.memory_size = str_max;
}
-
iter->i = 0;
iter->pos = 0;
}
@@ -65,11 +58,12 @@ search_set_init(Application_Links *app, Search_Set *set, int range_count){
int max = range_count*2;
if (set->ranges == 0){
- set->ranges = (Search_Range*)GET_MEMORY(sizeof(Search_Range)*max);
+ set->ranges = (Search_Range*)general_memory_allocate(&general, sizeof(Search_Range)*max);
set->max = max;
}
else if (set->max < range_count){
- set->ranges = (Search_Range*)REGET_MEMORY(set->ranges, sizeof(Search_Range)*max);
+ set->ranges = (Search_Range*)general_memory_reallocate_nocopy(
+ &general, set->ranges, sizeof(Search_Range)*max);
set->max = max;
}
@@ -81,10 +75,10 @@ search_hits_table_alloc(Application_Links *app, Table *hits, int table_size){
void *mem = 0;
int mem_size = table_required_mem_size(table_size, sizeof(Offset_String));
if (hits->hash_array == 0){
- mem = GET_MEMORY(mem_sze);
+ mem = general_memory_allocate(&general, mem_size);
}
else{
- mem = REGET_NOCOPY_MEMORY(hits->hash_array, mem_sze);
+ mem = general_memory_reallocate_nocopy(&general, hits->hash_array, mem_size);
}
table_init_memory(hits, mem, table_size, sizeof(Offset_String));
}
@@ -96,16 +90,16 @@ search_hits_init(Application_Links *app, Table *hits, String_Space *str, int tab
}
else{
int mem_size = table_required_mem_size(table_size, sizeof(Offset_String));
- void *mem = REGET_NOCOPY_MEMORY(mem, mem_size);
+ void *mem = general_memory_reallocate_nocopy(&general, hits->hash_array, mem_size);
table_init_memory(hits, mem, table_size, sizeof(Offset_String));
}
if (str->space == 0){
- str->space = (char*)GET_MEMORY(str_size);
+ str->space = (char*)general_memory_allocate(&general, str_size);
str->max = str_size;
}
else if (str->max < str_size){
- str->space = (char*)REGET_NOCOPY_MEMORY(str->space, str_size);
+ str->space = (char*)general_memory_reallocate_nocopy(&general, str->space, str_size);
str->max = str_size;
}
@@ -125,7 +119,8 @@ search_hit_add(Application_Links *app, Table *hits, String_Space *space, char *s
if (new_size < space->max + len){
new_size = space->max + len;
}
- space->space = (char*)REGET_MEMORY(space->space, new_size);
+ space->space = (char*)general_memory_reallocate(
+ &general, space->space, space->new_pos, new_size);
ostring = strspace_append(space, str, len);
}
@@ -136,7 +131,7 @@ search_hit_add(Application_Links *app, Table *hits, String_Space *space, char *s
search_hits_table_alloc(app, &new_hits, hits->max*2);
table_clear(&new_hits);
table_rehash(hits, &new_hits, space->space, tbl_offset_string_hash, tbl_offset_string_compare);
- FREE_MEMORY(hits->hash_array);
+ general_memory_free(&general, hits->hash_array);
*hits = new_hits;
}
@@ -293,8 +288,6 @@ search_next_match(Application_Links *app, Search_Set *set, Search_Iter *it_ptr){
Search_Match result = {0};
Search_Iter iter = *it_ptr;
- char *spare = (char*)GET_MEMORY(iter.word.size);
-
int count = set->count;
for (; iter.i < count;){
Search_Range *range = set->ranges + iter.i;
@@ -396,8 +389,6 @@ search_next_match(Application_Links *app, Search_Set *set, Search_Iter *it_ptr){
}
double_break:;
- FREE_MEMORY(spare);
-
*it_ptr = iter;
return(result);
diff --git a/4ed_api_implementation.cpp b/4ed_api_implementation.cpp
index ac98f6c8..bada3b39 100644
--- a/4ed_api_implementation.cpp
+++ b/4ed_api_implementation.cpp
@@ -338,28 +338,6 @@ DOC_SEE(Command_Line_Input_Flag)
return(result);
}
-API_EXPORT void*
-Memory_Alloc(Application_Links *app, int32_t size)/*
-DOC(TODO)
-*/{
- void *result = 0;
- return(result);
-}
-
-API_EXPORT int32_t
-Memory_Set_Protection(Application_Links *app, void *ptr, int32_t size, Memory_Protect_Flags flags)/*
-DOC(TODO)
-*/{
- int32_t result = 0;
- return(result);
-}
-
-API_EXPORT void
-Memory_Free(Application_Links *app, void *mem)/*
-DOC(TODO)
-*/{
-}
-
API_EXPORT void
Clipboard_Post(Application_Links *app, int32_t clipboard_id, char *str, int32_t len)/*
DOC_PARAM(clipboard_id, This parameter is set up to prepare for future features, it should always be 0 for now.)
@@ -1941,6 +1919,10 @@ directories controlled on the custom side.
return(hot->string.size);
}
+#define Memory_Allocate system->memory_allocate
+#define Memory_Set_Protection system->memory_set_protection
+#define Memory_Free system->memory_free
+
#define Get_4ed_Path system->get_4ed_path
#define File_Exists system->file_exists
#define Directory_CD system->directory_cd
diff --git a/4ed_file_view.cpp b/4ed_file_view.cpp
index 3702b307..1376751d 100644
--- a/4ed_file_view.cpp
+++ b/4ed_file_view.cpp
@@ -6142,7 +6142,8 @@ search_next_match(Partition *part, Search_Set *set, Search_Iter *iter_){
if (iter.pos + iter.word.size < end_pos){
start_pos = Max(iter.pos, range->start);
- result.start = buffer_find_string(range->buffer, start_pos, end_pos, iter.word.str, iter.word.size, spare);
+ result.start = buffer_find_string(
+ range->buffer, start_pos, end_pos, iter.word.str, iter.word.size, spare);
if (result.start < end_pos){
iter.pos = result.start + 1;
diff --git a/4ed_system.h b/4ed_system.h
index 8f526d73..0ca63e63 100644
--- a/4ed_system.h
+++ b/4ed_system.h
@@ -220,7 +220,7 @@ typedef INTERNAL_Sys_Get_Thread_States_Sig(INTERNAL_System_Get_Thread_States);
typedef INTERNAL_Sys_Debug_Message_Sig(INTERNAL_System_Debug_Message);
struct System_Functions{
- // files: 7
+ // files: 9
System_File_Time_Stamp *file_time_stamp;
System_Now_Time_Stamp *now_time_stamp;
System_Set_File_List *set_file_list;
@@ -231,7 +231,10 @@ struct System_Functions{
System_File_Load_End *file_load_end;
System_File_Save *file_save;
- // 4coder_custom.h: 3
+ // 4coder_custom.h: 7
+ Memory_Allocate_Function *memory_allocate;
+ Memory_Set_Protection_Function *memory_set_protection;
+ Memory_Free_Function *memory_free;
File_Exists_Function *file_exists;
Directory_CD_Function *directory_cd;
Get_4ed_Path_Function *get_4ed_path;
diff --git a/buffer/4coder_shared.cpp b/buffer/4coder_shared.cpp
index ccd8b886..f492b55b 100644
--- a/buffer/4coder_shared.cpp
+++ b/buffer/4coder_shared.cpp
@@ -163,12 +163,9 @@ buffer_unsort_cursors(Cursor_With_Index *positions, int count){
internal_4tech void
buffer_update_cursors(Cursor_With_Index *sorted_positions, int count, int start, int end, int len){
- Cursor_With_Index *position;
- int shift_amount;
+ int shift_amount = (len - (end - start));
+ Cursor_With_Index *position = sorted_positions + count - 1;
- shift_amount = (len - (end - start));
-
- position = sorted_positions + count - 1;
for (; position >= sorted_positions && position->pos > end; --position) position->pos += shift_amount;
for (; position >= sorted_positions && position->pos >= start; --position) position->pos = start;
}
diff --git a/linux_4ed.cpp b/linux_4ed.cpp
index 712e2819..b4811112 100644
--- a/linux_4ed.cpp
+++ b/linux_4ed.cpp
@@ -1,6 +1,6 @@
-
/*
* Mr. 4th Dimention - Allen Webster
+ * (Mostly by insofaras)
*
* 14.11.2015
*
@@ -629,6 +629,68 @@ Sys_File_Save_Sig(system_file_save){
return (size == 0);
}
+//
+// Custom access to OS pages
+//
+
+internal
+MEMORY_ALLOCATE_SIG(system_memory_allocate){
+ // NOTE(allen): This must return the exact base of the vpage.
+ // We will count on the user to keep track of size themselves.
+ void *result = mmap(0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+ if(result == MAP_FAILED){
+ perror("mmap");
+ result = NULL;
+ }
+ return(result);
+}
+
+internal
+MEMORY_SET_PROTECTION_SIG(system_memory_set_protection){
+#if 0
+ // NOTE(allen): Don't know how to do this off the top
+ // of my head. Here is a copy of the windows version.
+ // There is no such thing as "write only" in windows
+ // so I just made write = write + read in all cases.
+ bool32 result = false;
+ DWORD old_protect = 0;
+ DWORD protect = 0;
+
+ flags = flags & 0x7;
+
+ switch (flags){
+ case 0:
+ protect = PAGE_NOACCESS; break;
+
+ case MemProtect_Read:
+ protect = PAGE_READONLY; break;
+
+ case MemProtect_Write:
+ case MemProtect_Read|MemProtect_Write:
+ protect = PAGE_READWRITE; break;
+
+ case MemProtect_Execute:
+ protect = PAGE_EXECUTE; break;
+
+ case MemProtect_Execute|MemProtect_Read:
+ protect = PAGE_EXECUTE_READ; break;
+
+ case MemProtect_Execute|MemProtect_Write:
+ case MemProtect_Execute|MemProtect_Write|MemProtect_Read:
+ protect = PAGE_EXECUTE_READWRITE; break;
+ }
+
+ VirtualProtect(ptr, size, protect, &old_protect);
+ return(result);
+#endif
+}
+
+internal
+MEMORY_FREE_SIG(system_memory_free){
+ // NOTE(allen): This must take the exact base of the vpage.
+ munmap(mem, size);
+}
+
//
// Filesystem navigation
//
diff --git a/power/4coder_experiments.cpp b/power/4coder_experiments.cpp
index 9ed4eae1..f6a86390 100644
--- a/power/4coder_experiments.cpp
+++ b/power/4coder_experiments.cpp
@@ -166,43 +166,6 @@ CUSTOM_COMMAND_SIG(cursor_to_surrounding_scope){
}
}
-// NOTE(allen): Incomplete
-#if 0
-CUSTOM_COMMAND_SIG(complete_word){
- app->print_message(app, literal("complete_word\n"));
-
- View_Summary view = app->get_active_view(app);
- Buffer_Summary buffer = app->get_buffer(app, view.buffer_id);
-
- int start = 0;
- int end = 0;
-
- end = view.cursor.pos;
-
- push_parameter(app, par_flags, BoundryAlphanumeric);
- exec_command(app, cmdid_seek_left);
-
- app->refresh_view(app, &view);
- start = view.cursor.pos;
-
- String complete_string;
- int size = (end - start);
- char complete_space[256];
-
- if (size < sizeof(complete_space) - 1){
- complete_string = make_fixed_width_string(complete_space);
- app->buffer_read_range(app, &buffer, start, end, complete_space);
- complete_string.size = size;
- complete_string.str[size] = 0;
-
- // TODO(allen): Complete this when the heavy duty coroutine stuff
- // and the hash table are available.
-
- app->print_message(app, complete_string.str, complete_string.size);
- }
-}
-#endif
-
// TODO(allen): Query theme settings
#if 0
CUSTOM_COMMAND_SIG(save_theme_settings){
@@ -215,23 +178,15 @@ CUSTOM_COMMAND_SIG(save_theme_settings){
if (file){
replace_char(theme_name, '#', ' ');
replace_char(font_name, '#', ' ');
-
+
fclose(file);
-
+
app->change_theme(app, theme_name, strlen(theme_name));
app->change_font(app, font_name, strlen(font_name));
}
}
#endif
-#if 0
-void experiment_extension(Bind_Helper *context){
- bind(context, 'k', MDFR_ALT, kill_rect);
- bind(context, '/', MDFR_ALT, mark_matching_brace);
- bind(context, '\'', MDFR_ALT, cursor_to_surrounding_scope);
-}
-#endif
-
#include
#define SETTINGS_FILE ".4coder_settings"
diff --git a/win32_4ed.cpp b/win32_4ed.cpp
index aec6a4e9..ca30d250 100644
--- a/win32_4ed.cpp
+++ b/win32_4ed.cpp
@@ -1172,7 +1172,7 @@ Win32LoadAppCode(){
#else
File_Data file = system_load_file("4ed_app.dll");
-
+
if (file.got_file){
i32 error;
DLL_Data dll_data;
@@ -1181,30 +1181,30 @@ Win32LoadAppCode(){
img.size = dll_total_loaded_size(&dll_data);
img.data = (byte*)
VirtualAlloc((LPVOID)Tbytes(3), img.size,
- MEM_COMMIT | MEM_RESERVE,
- PAGE_READWRITE);
-
+ MEM_COMMIT | MEM_RESERVE,
+ PAGE_READWRITE);
+
dll_load(img, &win32vars.app_dll, file.data, &dll_data);
-
+
DWORD extra_;
VirtualProtect(img.data + win32vars.app_dll.text_start,
- win32vars.app_dll.text_size,
- PAGE_EXECUTE_READ,
- &extra_);
-
+ win32vars.app_dll.text_size,
+ PAGE_EXECUTE_READ,
+ &extra_);
+
get_funcs = (App_Get_Functions*)
dll_load_function(&win32vars.app_dll, "app_get_functions", 17);
}
else{
// TODO(allen): file loading error
}
-
+
Win32FreeMemory(file.data.data);
}
else{
// TODO(allen): file loading error
}
-
+
#endif
if (get_funcs){
@@ -1226,37 +1226,38 @@ Win32LoadSystemCode(){
win32vars.system.file_load_begin = system_file_load_begin;
win32vars.system.file_load_end = system_file_load_end;
win32vars.system.file_save = system_file_save;
-
+
+ win32vars.system.memory_allocate = Memory_Allocate;
win32vars.system.file_exists = File_Exists;
win32vars.system.directory_cd = Directory_CD;
win32vars.system.get_4ed_path = Get_4ed_Path;
win32vars.system.show_mouse_cursor = Show_Mouse_Cursor;
-
+
win32vars.system.post_clipboard = system_post_clipboard;
-
+
win32vars.system.create_coroutine = system_create_coroutine;
win32vars.system.launch_coroutine = system_launch_coroutine;
win32vars.system.resume_coroutine = system_resume_coroutine;
win32vars.system.yield_coroutine = system_yield_coroutine;
-
+
win32vars.system.cli_call = system_cli_call;
win32vars.system.cli_begin_update = system_cli_begin_update;
win32vars.system.cli_update_step = system_cli_update_step;
win32vars.system.cli_end_update = system_cli_end_update;
-
+
win32vars.system.post_job = system_post_job;
win32vars.system.cancel_job = system_cancel_job;
win32vars.system.check_cancel = system_check_cancel;
win32vars.system.grow_thread_memory = system_grow_thread_memory;
win32vars.system.acquire_lock = system_acquire_lock;
win32vars.system.release_lock = system_release_lock;
-
+
#if FRED_INTERNAL
win32vars.system.internal_sentinel = INTERNAL_system_sentinel;
win32vars.system.internal_get_thread_states = INTERNAL_get_thread_states;
win32vars.system.internal_debug_message = INTERNAL_system_debug_message;
#endif
-
+
win32vars.system.slash = '/';
}
diff --git a/win32_api_impl.cpp b/win32_api_impl.cpp
index 0ac315fc..713c2805 100644
--- a/win32_api_impl.cpp
+++ b/win32_api_impl.cpp
@@ -11,6 +11,57 @@ as this is the only one that will be used for generating headers and docs.
#define API_EXPORT
+API_EXPORT void*
+Memory_Allocate(Application_Links *app, int32_t size)/*
+DOC(TODO)
+*/{
+ void *result = VirtualAlloc(0, size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
+ return(result);
+}
+
+API_EXPORT bool32
+Memory_Set_Protection(Application_Links *app, void *ptr, int32_t size, Memory_Protect_Flags flags)/*
+DOC(TODO)
+*/{
+ bool32 result = false;
+ DWORD old_protect = 0;
+ DWORD protect = 0;
+
+ flags = flags & 0x7;
+
+ switch (flags){
+ case 0:
+ protect = PAGE_NOACCESS; break;
+
+ case MemProtect_Read:
+ protect = PAGE_READONLY; break;
+
+ case MemProtect_Write:
+ case MemProtect_Read|MemProtect_Write:
+ protect = PAGE_READWRITE; break;
+
+ case MemProtect_Execute:
+ protect = PAGE_EXECUTE; break;
+
+ case MemProtect_Execute|MemProtect_Read:
+ protect = PAGE_EXECUTE_READ; break;
+
+ case MemProtect_Execute|MemProtect_Write:
+ case MemProtect_Execute|MemProtect_Write|MemProtect_Read:
+ protect = PAGE_EXECUTE_READWRITE; break;
+ }
+
+ VirtualProtect(ptr, size, protect, &old_protect);
+ return(result);
+}
+
+API_EXPORT void
+Memory_Free(Application_Links *app, void *mem, int32_t size)/*
+DOC(TODO)
+*/{
+ VirtualFree(mem, 0, MEM_RELEASE);
+}
+
API_EXPORT bool32
File_Exists(Application_Links *app, char *filename, int len)/*
DOC_PARAM(filename, This parameter specifies the full path to a file; it need not be null terminated.)