diff --git a/4coder_custom_api.h b/4coder_custom_api.h index 26763c67..4ea68146 100644 --- a/4coder_custom_api.h +++ b/4coder_custom_api.h @@ -16,6 +16,7 @@ #define BUFFER_REPLACE_RANGE_SIG(n) int n(Application_Links *app, Buffer_Summary *buffer, int start, int end, char *str, int len) #define BUFFER_SEEK_SIG(n) int n(Application_Links *app, Buffer_Summary *buffer, int start_pos, int seek_forward, unsigned int flags) #define BUFFER_SET_SETTING_SIG(n) int n(Application_Links *app, Buffer_Summary *buffer, int setting, int value) +#define BUFFER_SAVE_SIG(n) int n(Application_Links *app, Buffer_Summary *buffer, char *filename, int filename_len) #define GET_VIEW_FIRST_SIG(n) View_Summary n(Application_Links *app) #define GET_VIEW_NEXT_SIG(n) void n(Application_Links *app, View_Summary *view) #define GET_VIEW_SIG(n) View_Summary n(Application_Links *app, int index) @@ -28,7 +29,7 @@ #define VIEW_SET_HIGHLIGHT_SIG(n) int n(Application_Links *app, View_Summary *view, int start, int end, int turn_on) #define VIEW_SET_BUFFER_SIG(n) int n(Application_Links *app, View_Summary *view, int buffer_id) #define VIEW_OPEN_FILE_SIG(n) int n(Application_Links *app, View_Summary *view, char *filename, int filename_len, int do_in_background) -#define VIEW_KILL_FILE_SIG(n) int n(Application_Links *app, View_Summary *view, Buffer_Identifier buffer) +#define VIEW_KILL_BUFFER_SIG(n) int n(Application_Links *app, View_Summary *view, Buffer_Identifier buffer) #define GET_USER_INPUT_SIG(n) User_Input n(Application_Links *app, unsigned int get_type, unsigned int abort_type) #define GET_COMMAND_INPUT_SIG(n) User_Input n(Application_Links *app) #define GET_EVENT_MESSAGE_SIG(n) Event_Message n(Application_Links *app) @@ -58,6 +59,7 @@ extern "C"{ typedef BUFFER_REPLACE_RANGE_SIG(Buffer_Replace_Range_Function); typedef BUFFER_SEEK_SIG(Buffer_Seek_Function); typedef BUFFER_SET_SETTING_SIG(Buffer_Set_Setting_Function); + typedef BUFFER_SAVE_SIG(Buffer_Save_Function); typedef GET_VIEW_FIRST_SIG(Get_View_First_Function); typedef GET_VIEW_NEXT_SIG(Get_View_Next_Function); typedef GET_VIEW_SIG(Get_View_Function); @@ -70,7 +72,7 @@ extern "C"{ typedef VIEW_SET_HIGHLIGHT_SIG(View_Set_Highlight_Function); typedef VIEW_SET_BUFFER_SIG(View_Set_Buffer_Function); typedef VIEW_OPEN_FILE_SIG(View_Open_File_Function); - typedef VIEW_KILL_FILE_SIG(View_Kill_File_Function); + typedef VIEW_KILL_BUFFER_SIG(View_Kill_Buffer_Function); typedef GET_USER_INPUT_SIG(Get_User_Input_Function); typedef GET_COMMAND_INPUT_SIG(Get_Command_Input_Function); typedef GET_EVENT_MESSAGE_SIG(Get_Event_Message_Function); @@ -103,6 +105,7 @@ struct Application_Links{ Buffer_Replace_Range_Function *buffer_replace_range; Buffer_Seek_Function *buffer_seek; Buffer_Set_Setting_Function *buffer_set_setting; + Buffer_Save_Function *buffer_save; Get_View_First_Function *get_view_first; Get_View_Next_Function *get_view_next; Get_View_Function *get_view; @@ -115,7 +118,7 @@ struct Application_Links{ View_Set_Highlight_Function *view_set_highlight; View_Set_Buffer_Function *view_set_buffer; View_Open_File_Function *view_open_file; - View_Kill_File_Function *view_kill_file; + View_Kill_Buffer_Function *view_kill_buffer; Get_User_Input_Function *get_user_input; Get_Command_Input_Function *get_command_input; Get_Event_Message_Function *get_event_message; @@ -150,6 +153,7 @@ app_links->buffer_read_range = external_buffer_read_range;\ app_links->buffer_replace_range = external_buffer_replace_range;\ app_links->buffer_seek = external_buffer_seek;\ app_links->buffer_set_setting = external_buffer_set_setting;\ +app_links->buffer_save = external_buffer_save;\ app_links->get_view_first = external_get_view_first;\ app_links->get_view_next = external_get_view_next;\ app_links->get_view = external_get_view;\ @@ -162,7 +166,7 @@ app_links->view_set_mark = external_view_set_mark;\ app_links->view_set_highlight = external_view_set_highlight;\ app_links->view_set_buffer = external_view_set_buffer;\ app_links->view_open_file = external_view_open_file;\ -app_links->view_kill_file = external_view_kill_file;\ +app_links->view_kill_buffer = external_view_kill_buffer;\ app_links->get_user_input = external_get_user_input;\ app_links->get_command_input = external_get_command_input;\ app_links->get_event_message = external_get_event_message;\ diff --git a/4coder_default_include.cpp b/4coder_default_include.cpp index 2307e9bd..b306a6a8 100644 --- a/4coder_default_include.cpp +++ b/4coder_default_include.cpp @@ -928,7 +928,7 @@ CUSTOM_COMMAND_SIG(close_all_code){ View_Summary view = app->get_active_view(app); for (int i = 0; i < buffers_to_close_count; ++i){ - app->view_kill_file(app, &view, buffer_identifier(buffers_to_close[i])); + app->view_kill_buffer(app, &view, buffer_identifier(buffers_to_close[i])); } } diff --git a/4ed.cpp b/4ed.cpp index ff6a974b..606931a8 100644 --- a/4ed.cpp +++ b/4ed.cpp @@ -1079,1051 +1079,8 @@ update_command_data(App_Vars *vars, Command_Data *cmd){ globalvar Command_Function command_table[cmdid_count]; -internal void -fill_buffer_summary(Buffer_Summary *buffer, Editing_File *file, Working_Set *working_set){ - *buffer = buffer_summary_zero(); - if (!file->is_dummy){ - buffer->exists = 1; - buffer->ready = file_is_ready(file); - - buffer->is_lexed = file->settings.tokens_exist; - buffer->buffer_id = file->id.id; - buffer->size = file->state.buffer.size; - buffer->buffer_cursor_pos = file->state.cursor_pos; - - buffer->file_name_len = file->name.source_path.size; - buffer->buffer_name_len = file->name.live_name.size; - buffer->file_name = file->name.source_path.str; - buffer->buffer_name = file->name.live_name.str; - - buffer->map_id = file->settings.base_map_id; - } -} - -internal void -fill_view_summary(View_Summary *view, View *vptr, Live_Views *live_set, Working_Set *working_set){ - i32 lock_level; - int buffer_id; - *view = view_summary_zero(); - - if (vptr->in_use){ - view->exists = 1; - view->view_id = (int)(vptr - live_set->views) + 1; - view->line_height = (float)(vptr->line_height); - view->unwrapped_lines = vptr->file_data.unwrapped_lines; - view->show_whitespace = vptr->file_data.show_whitespace; - - - if (vptr->file_data.file){ - lock_level = view_lock_level(vptr); - buffer_id = vptr->file_data.file->id.id; - - if (lock_level <= 0){ - view->buffer_id = buffer_id; - } - else{ - view->buffer_id = 0; - } - - if (lock_level <= 1){ - view->locked_buffer_id = buffer_id; - } - else{ - view->locked_buffer_id = 0; - } - - if (lock_level <= 2){ - view->hidden_buffer_id = buffer_id; - } - else{ - view->hidden_buffer_id = 0; - } - - view->mark = view_compute_cursor_from_pos(vptr, vptr->recent->mark); - view->cursor = vptr->recent->cursor; - view->preferred_x = vptr->recent->preferred_x; - - view->file_region = vptr->file_region; - view->scroll_vars = *vptr->current_scroll; - } - } -} - -internal Editing_File* -get_file_from_identifier(System_Functions *system, Working_Set *working_set, Buffer_Identifier buffer){ - i32 buffer_id = buffer.id; - i32 buffer_name_len = buffer.name_len; - char *buffer_name = buffer.name; - - Editing_File *file = 0; - - if (buffer_id){ - file = working_set_get_active_file(working_set, buffer_id); - } - else if (buffer_name){ - file = working_set_contains(system, working_set, make_string(buffer_name, buffer_name_len)); - } - - return(file); -} - extern "C"{ - EXEC_COMMAND_SIG(external_exec_command){ - Command_Data *cmd = (Command_Data*)app->cmd_context; - Command_Function function = command_table[command_id]; - Command_Binding binding = {}; - binding.function = function; - if (function) function(cmd->system, cmd, binding); - - update_command_data(cmd->vars, cmd); - } - - EXEC_SYSTEM_COMMAND_SIG(external_exec_system_command){ - Command_Data *cmd = (Command_Data*)app->cmd_context; - System_Functions *system = cmd->system; - App_Vars *vars = cmd->vars; - Models *models = cmd->models; - - char feedback_space[256]; - String feedback_str = make_fixed_width_string(feedback_space); - - Working_Set *working_set = &models->working_set; - CLI_Process *procs = vars->cli_processes.procs, *proc = 0; - Editing_File *file = 0; - b32 bind_to_new_view = true; - General_Memory *general = &models->mem.general; - - View *vptr = 0; - - if (view->exists){ - Live_Views *live_set = cmd->live_set; - i32 view_id = view->view_id - 1; - if (view_id >= 0 && view_id < live_set->max){ - vptr = live_set->views + view_id; - } - } - - if (vptr == 0){ - return(0); - } - - if (vars->cli_processes.count < vars->cli_processes.max){ - file = get_file_from_identifier(system, working_set, buffer); - if (file){ - if (file->settings.read_only == 0){ - append(&feedback_str, "ERROR: "); - append(&feedback_str, file->name.live_name); - append(&feedback_str, " is not a read-only buffer\n"); - do_feedback_message(system, models, feedback_str); - return(0); - } - if (file->settings.never_kill){ - append(&feedback_str, "The buffer "); - append(&feedback_str, file->name.live_name); - append(&feedback_str, " is not killable"); - do_feedback_message(system, models, feedback_str); - return(0); - } - } - else if (buffer.name){ - file = working_set_alloc_always(working_set, general); - if (file == 0){ - append(&feedback_str, "ERROR: unable to allocate a new buffer\n"); - do_feedback_message(system, models, feedback_str); - return(0); - } - file_create_read_only(system, models, file, buffer.name); - working_set_add(system, working_set, file, general); - } - - if (file){ - i32 proc_count = vars->cli_processes.count; - View_Iter iter; - i32 i; - - for (i = 0; i < proc_count; ++i){ - if (procs[i].out_file == file){ - if (flags & CLI_OverlapWithConflict){ - procs[i].out_file = 0; - } - else{ - file = 0; - } - break; - } - } - - if (file){ - file_clear(system, models, file, 1); - file->settings.unimportant = 1; - - if (!(flags & CLI_AlwaysBindToView)){ - iter = file_view_iter_init(&models->layout, file, 0); - if (file_view_iter_good(iter)){ - bind_to_new_view = 0; - } - } - } - else{ - append(&feedback_str, "did not begin command-line command because the target buffer is already in use\n"); - do_feedback_message(system, models, feedback_str); - return(0); - } - } - - if (!path){ - path = models->hot_directory.string.str; - terminate_with_null(&models->hot_directory.string); - } - - { - Range range; - Editing_File *file2; - i32 size; - - Partition *part = &models->mem.part; - Temp_Memory temp = begin_temp_memory(part); - if (!command){ - file2 = vptr->file_data.file; - if (file2){ - range = make_range(vptr->recent->cursor.pos, vptr->recent->mark); - size = range.end - range.start; - command = push_array(part, char, size + 1); - buffer_stringify(&file2->state.buffer, range.start, range.end, command); - command[size] = 0; - command_len = size; - } - else{ -#define NO_SCRIPT " echo no script specified" - command = NO_SCRIPT; - command_len = sizeof(NO_SCRIPT)-1; -#undef NO_SCRIPT - } - } - - if (bind_to_new_view){ - view_set_file(vptr, file, models); - view_show_file(vptr); - } - - proc = procs + vars->cli_processes.count++; - proc->out_file = file; - - if (!system->cli_call(path, command, &proc->cli)){ - --vars->cli_processes.count; - } - end_temp_memory(temp); - } - } - else{ - append(&feedback_str, "ERROR: no available process slot\n"); - do_feedback_message(system, models, feedback_str); - return(0); - } - - return(1); - } - - DIRECTORY_GET_HOT_SIG(external_directory_get_hot){ - Command_Data *cmd = (Command_Data*)app->cmd_context; - Hot_Directory *hot = &cmd->models->hot_directory; - i32 copy_max = capacity - 1; - hot_directory_clean_end(hot); - if (copy_max > hot->string.size) - copy_max = hot->string.size; - memcpy(out, hot->string.str, copy_max); - out[copy_max] = 0; - return(hot->string.size); - } - - GET_FILE_LIST_SIG(external_get_file_list){ - Command_Data *cmd = (Command_Data*)app->cmd_context; - System_Functions *system = cmd->system; - File_List result = {}; - system->set_file_list(&result, make_string(dir, len)); - return(result); - } - - FREE_FILE_LIST_SIG(external_free_file_list){ - Command_Data *cmd = (Command_Data*)app->cmd_context; - System_Functions *system = cmd->system; - system->set_file_list(&list, make_string(0, 0)); - } - - GET_BUFFER_FIRST_SIG(external_get_buffer_first){ - Command_Data *cmd = (Command_Data*)app->cmd_context; - Working_Set *working_set = &cmd->models->working_set; - Buffer_Summary result = {}; - if (working_set->file_count > 0){ - fill_buffer_summary(&result, (Editing_File*)working_set->used_sentinel.next, working_set); - } - return(result); - } - - GET_BUFFER_NEXT_SIG(external_get_buffer_next){ - Command_Data *cmd = (Command_Data*)app->cmd_context; - Working_Set *working_set = &cmd->models->working_set; - Editing_File *file; - - file = working_set_get_active_file(working_set, buffer->buffer_id); - if (file){ - file = (Editing_File*)file->node.next; - fill_buffer_summary(buffer, file, working_set); - } - else{ - *buffer = buffer_summary_zero(); - } - } - - GET_BUFFER_SIG(external_get_buffer){ - Command_Data *cmd = (Command_Data*)app->cmd_context; - Working_Set *working_set = &cmd->models->working_set; - Buffer_Summary buffer = {}; - Editing_File *file; - - file = working_set_get_active_file(working_set, index); - if (file){ - fill_buffer_summary(&buffer, file, working_set); - } - - return(buffer); - } - - GET_PARAMETER_BUFFER_SIG(external_get_parameter_buffer){ - Command_Data *cmd = (Command_Data*)app->cmd_context; - Models *models = cmd->models; - Buffer_Summary buffer = {}; - - if (param_index >= 0 && param_index < models->buffer_param_count){ - buffer = external_get_buffer(app, models->buffer_param_indices[param_index]); - } - - return(buffer); - } - - GET_BUFFER_BY_NAME_SIG(external_get_buffer_by_name){ - Command_Data *cmd = (Command_Data*)app->cmd_context; - Buffer_Summary buffer = {}; - Editing_File *file; - Working_Set *working_set = &cmd->models->working_set; - - file = working_set_contains(cmd->system, working_set, make_string(filename, len)); - if (file && !file->is_dummy){ - fill_buffer_summary(&buffer, file, working_set); - } - - return(buffer); - } - - REFRESH_BUFFER_SIG(external_refresh_buffer){ - int result; - *buffer = external_get_buffer(app, buffer->buffer_id); - result = buffer->exists; - return(result); - } - - BUFFER_SEEK_SIG(external_buffer_seek){ - Command_Data *cmd = (Command_Data*)app->cmd_context; - Editing_File *file; - Working_Set *working_set; - int result = 0; - - if (buffer->exists){ - working_set = &cmd->models->working_set; - file = working_set_get_active_file(working_set, buffer->buffer_id); - if (file && file_is_ready(file)){ - // TODO(allen): reduce duplication? - { - i32 size = buffer_size(&file->state.buffer); - i32 pos[4] = {0}; - i32 new_pos = 0; - - if (start_pos < 0){ - start_pos = 0; - } - else if (start_pos > size){ - start_pos = size; - } - - if (seek_forward){ - for (i32 i = 0; i < ArrayCount(pos); ++i) pos[i] = size; - - if (flags & (1)){ - pos[0] = buffer_seek_whitespace_right(&file->state.buffer, start_pos); - } - - if (flags & (1 << 1)){ - if (file->state.tokens_complete){ - pos[1] = seek_token_right(&file->state.token_stack, start_pos); - } - else{ - pos[1] = buffer_seek_whitespace_right(&file->state.buffer, start_pos); - } - } - - if (flags & (1 << 2)){ - pos[2] = buffer_seek_alphanumeric_right(&file->state.buffer, start_pos); - if (flags & (1 << 3)){ - pos[3] = buffer_seek_range_camel_right(&file->state.buffer, start_pos, pos[2]); - } - } - else{ - if (flags & (1 << 3)){ - pos[3] = buffer_seek_alphanumeric_or_camel_right(&file->state.buffer, start_pos); - } - } - - new_pos = size; - for (i32 i = 0; i < ArrayCount(pos); ++i){ - if (pos[i] < new_pos) new_pos = pos[i]; - } - } - else{ - if (flags & (1)){ - pos[0] = buffer_seek_whitespace_left(&file->state.buffer, start_pos); - } - - if (flags & (1 << 1)){ - if (file->state.tokens_complete){ - pos[1] = seek_token_left(&file->state.token_stack, start_pos); - } - else{ - pos[1] = buffer_seek_whitespace_left(&file->state.buffer, start_pos); - } - } - - if (flags & (1 << 2)){ - pos[2] = buffer_seek_alphanumeric_left(&file->state.buffer, start_pos); - if (flags & (1 << 3)){ - pos[3] = buffer_seek_range_camel_left(&file->state.buffer, start_pos, pos[2]); - } - } - else{ - if (flags & (1 << 3)){ - pos[3] = buffer_seek_alphanumeric_or_camel_left(&file->state.buffer, start_pos); - } - } - - new_pos = 0; - for (i32 i = 0; i < ArrayCount(pos); ++i){ - if (pos[i] > new_pos) new_pos = pos[i]; - } - } - result = new_pos; - } - - fill_buffer_summary(buffer, file, working_set); - } - } - - return(result); - } - - BUFFER_READ_RANGE_SIG(external_buffer_read_range){ - Command_Data *cmd = (Command_Data*)app->cmd_context; - Editing_File *file; - Working_Set *working_set; - int result = 0; - int size; - - if (buffer->exists){ - working_set = &cmd->models->working_set; - file = working_set_get_active_file(working_set, buffer->buffer_id); - if (file && file_is_ready(file)){ - size = buffer_size(&file->state.buffer); - if (0 <= start && start <= end && end <= size){ - result = 1; - buffer_stringify(&file->state.buffer, start, end, out); - } - fill_buffer_summary(buffer, file, working_set); - } - } - - return(result); - } - - BUFFER_REPLACE_RANGE_SIG(external_buffer_replace_range){ - Command_Data *cmd = (Command_Data*)app->cmd_context; - Editing_File *file; - Working_Set *working_set; - - Models *models; - - int result = 0; - int size; - int next_cursor, pos; - - if (buffer->exists){ - models = cmd->models; - working_set = &models->working_set; - file = working_set_get_active_file(working_set, buffer->buffer_id); - if (file && file_is_ready(file)){ - size = buffer_size(&file->state.buffer); - if (0 <= start && start <= end && end <= size){ - result = 1; - - pos = file->state.cursor_pos; - if (pos < start) next_cursor = pos; - else if (pos < end) next_cursor = start; - else next_cursor = pos + end - start - len; - - file_replace_range(cmd->system, models, file, start, end, str, len, next_cursor); - } - fill_buffer_summary(buffer, file, working_set); - } - } - - return(result); - } - -#if 0 - BUFFER_SET_POS_SIG(external_buffer_set_pos){ - Command_Data *cmd = (Command_Data*)app->cmd_context; - Editing_File *file; - Working_Set *working_set; - - int result = 0; - int size; - - if (buffer->exists){ - working_set = &cmd->models->working_set; - file = working_set_get_active_file(working_set, buffer->buffer_id); - if (file && file_is_ready(file)){ - result = 1; - size = buffer_size(&file->state.buffer); - if (pos < 0) pos = 0; - if (pos > size) pos = size; - file->state.cursor_pos = pos; - fill_buffer_summary(buffer, file, working_set); - } - } - - return(result); - } -#endif - - BUFFER_SET_SETTING_SIG(external_buffer_set_setting){ - Command_Data *cmd = (Command_Data*)app->cmd_context; - System_Functions *system = cmd->system; - Models *models = cmd->models; - - Editing_File *file; - Working_Set *working_set; - - int result = false; - - i32 new_mapid = 0; - - if (buffer->exists){ - working_set = &models->working_set; - file = working_set_get_active_file(working_set, buffer->buffer_id); - if (file && file_is_ready(file)){ - result = true; - switch (setting){ - case BufferSetting_Lex: - { -#if BUFFER_EXPERIMENT_SCALPEL <= 0 - if (file->settings.tokens_exist){ - if (!value){ - file_kill_tokens(system, &models->mem.general, file); - } - } - else{ - if (value){ - file_first_lex_parallel(system, &models->mem.general, file); - } - } -#endif - }break; - - case BufferSetting_WrapLine: - { - file->settings.unwrapped_lines = !value; - }break; - - case BufferSetting_MapID: - { - if (value == mapid_global){ - file->settings.base_map_id = mapid_global; - } - else if (value == mapid_file){ - file->settings.base_map_id = mapid_file; - } - else if (value < mapid_global){ - new_mapid = get_map_index(models, value); - if (new_mapid < models->user_map_count){ - file->settings.base_map_id = value; - } - else{ - file->settings.base_map_id = mapid_file; - } - } - - for (View_Iter iter = file_view_iter_init(&models->layout, file, 0); - file_view_iter_good(iter); - iter = file_view_iter_next(iter)){ - iter.view->map = get_map(models, file->settings.base_map_id); - } - }break; - } - } - - fill_buffer_summary(buffer, file, working_set); - } - - return(result); - } - - GET_VIEW_FIRST_SIG(external_get_view_first){ - Command_Data *cmd = (Command_Data*)app->cmd_context; - Editing_Layout *layout = &cmd->models->layout; - View_Summary view = {}; - - Panel *panel = layout->used_sentinel.next; - - Assert(panel != &layout->used_sentinel); - fill_view_summary(&view, panel->view, &cmd->vars->live_set, &cmd->models->working_set); - - return(view); - } - - GET_VIEW_NEXT_SIG(external_get_view_next){ - Command_Data *cmd = (Command_Data*)app->cmd_context; - Editing_Layout *layout = &cmd->models->layout; - Live_Views *live_set = &cmd->vars->live_set; - View *vptr; - Panel *panel; - int index = view->view_id - 1; - - if (index >= 0 && index < live_set->max){ - vptr = live_set->views + index; - panel = vptr->panel; - if (panel) panel = panel->next; - if (panel && panel != &layout->used_sentinel){ - fill_view_summary(view, panel->view, &cmd->vars->live_set, &cmd->models->working_set); - } - else{ - *view = view_summary_zero(); - } - } - else{ - *view = view_summary_zero(); - } - } - - GET_VIEW_SIG(external_get_view){ - Command_Data *cmd = (Command_Data*)app->cmd_context; - View_Summary view = {}; - Live_Views *live_set = cmd->live_set; - int max = live_set->max; - View *vptr; - - index -= 1; - if (index >= 0 && index < max){ - vptr = live_set->views + index; - fill_view_summary(&view, vptr, live_set, &cmd->models->working_set); - } - - return(view); - } - - GET_ACTIVE_VIEW_SIG(external_get_active_view){ - Command_Data *cmd = (Command_Data*)app->cmd_context; - View_Summary view = {}; - fill_view_summary(&view, cmd->view, &cmd->vars->live_set, &cmd->models->working_set); - return(view); - } - - REFRESH_VIEW_SIG(external_refresh_view){ - int result; - *view = external_get_view(app, view->view_id); - result = view->exists; - return(result); - } - - VIEW_AUTO_TAB_SIG(external_view_auto_tab){ - Command_Data *cmd = (Command_Data*)app->cmd_context; - System_Functions *system = cmd->system; - Models *models = cmd->models; - - int result = false; - - Live_Views *live_set; - Editing_File *file; - View *vptr; - int view_id; - - if (view->exists){ - live_set = cmd->live_set; - view_id = view->view_id - 1; - if (view_id >= 0 && view_id < live_set->max){ - vptr = live_set->views + view_id; - file = vptr->file_data.file; - - if (file && file->state.token_stack.tokens && - file->state.tokens_complete && !file->state.still_lexing){ - result = true; - - Indent_Options opts; - opts.empty_blank_lines = (flags & AutoTab_ClearLine); - opts.use_tabs = (flags & AutoTab_UseTab); - opts.tab_width = tab_width; - - view_auto_tab_tokens(system, models, vptr, start, end, opts); - } - } - } - - return(result); - } - - VIEW_COMPUTE_CURSOR_SIG(external_view_compute_cursor){ - Command_Data *cmd = (Command_Data*)app->cmd_context; - Live_Views *live_set; - View *vptr; - Editing_File *file; - Full_Cursor result = {0}; - int view_id; - - if (view->exists){ - live_set = cmd->live_set; - view_id = view->view_id - 1; - if (view_id >= 0 && view_id < live_set->max){ - vptr = live_set->views + view_id; - file = vptr->file_data.file; - if (file && !file->is_loading){ - if (seek.type == buffer_seek_line_char && seek.character <= 0){ - seek.character = 1; - } - result = view_compute_cursor(vptr, seek); - fill_view_summary(view, vptr, live_set, &cmd->models->working_set); - } - } - } - - return(result); - } - - VIEW_SET_CURSOR_SIG(external_view_set_cursor){ - Command_Data *cmd = (Command_Data*)app->cmd_context; - Live_Views *live_set; - View *vptr; - Editing_File *file; - int result = 0; - int view_id; - - if (view->exists){ - live_set = cmd->live_set; - view_id = view->view_id - 1; - if (view_id >= 0 && view_id < live_set->max){ - vptr = live_set->views + view_id; - file = vptr->file_data.file; - if (file && !file->is_loading){ - result = 1; - if (seek.type == buffer_seek_line_char && seek.character <= 0){ - seek.character = 1; - } - vptr->recent->cursor = view_compute_cursor(vptr, seek); - if (set_preferred_x){ - vptr->recent->preferred_x = view_get_cursor_x(vptr); - } - fill_view_summary(view, vptr, live_set, &cmd->models->working_set); - file->state.cursor_pos = vptr->recent->cursor.pos; - } - } - } - - return(result); - } - - VIEW_SET_MARK_SIG(external_view_set_mark){ - Command_Data *cmd = (Command_Data*)app->cmd_context; - Live_Views *live_set; - View *vptr; - Full_Cursor cursor; - int result = 0; - int view_id; - - if (view->exists){ - live_set = cmd->live_set; - view_id = view->view_id - 1; - if (view_id >= 0 && view_id < live_set->max){ - vptr = live_set->views + view_id; - result = 1; - if (seek.type != buffer_seek_pos){ - cursor = view_compute_cursor(vptr, seek); - vptr->recent->mark = cursor.pos; - } - else{ - vptr->recent->mark = seek.pos; - } - fill_view_summary(view, vptr, live_set, &cmd->models->working_set); - } - } - - return(result); - } - - VIEW_SET_HIGHLIGHT_SIG(external_view_set_highlight){ - Command_Data *cmd = (Command_Data*)app->cmd_context; - Live_Views *live_set; - View *vptr; - int result = 0; - int view_id; - - if (view->exists){ - live_set = cmd->live_set; - view_id = view->view_id - 1; - if (view_id >= 0 && view_id < live_set->max){ - vptr = live_set->views + view_id; - result = 1; - if (turn_on){ - view_set_temp_highlight(vptr, start, end); - } - else{ - vptr->file_data.show_temp_highlight = 0; - } - fill_view_summary(view, vptr, live_set, &cmd->models->working_set); - } - } - - return(result); - } - - VIEW_SET_BUFFER_SIG(external_view_set_buffer){ - Command_Data *cmd = (Command_Data*)app->cmd_context; - Live_Views *live_set; - View *vptr; - Editing_File *file; - Working_Set *working_set; - Models *models; - int result = 0; - int view_id; - - if (view->exists){ - models = cmd->models; - live_set = cmd->live_set; - view_id = view->view_id - 1; - if (view_id >= 0 && view_id < live_set->max){ - vptr = live_set->views + view_id; - working_set = &models->working_set; - file = working_set_get_active_file(working_set, buffer_id); - - if (file){ - result = 1; - if (file != vptr->file_data.file){ - view_set_file(vptr, file, models); - view_show_file(vptr); - } - } - - fill_view_summary(view, vptr, live_set, working_set); - } - } - - return(result); - } - - VIEW_OPEN_FILE_SIG(external_view_open_file){ - Command_Data *cmd = (Command_Data*)app->cmd_context; - - System_Functions *system = cmd->system; - Models *models = cmd->models; - - Working_Set *working_set = &models->working_set; - - Live_Views *live_set = cmd->live_set; - - int result = false; - - // TODO(allen): do in background option - - if (do_in_background){ - result = true; - view_open_file(system, models, 0, - make_string(filename, filename_len)); - } - else if (view){ - View *vptr = 0; - int view_id = view->view_id - 1; - if (view_id >= 0 && view_id < live_set->max){ - vptr = live_set->views + view_id; - result = true; - - view_open_file(system, models, 0, - make_string(filename, filename_len)); - - fill_view_summary(view, vptr, live_set, working_set); - } - } - - return(result); - } - - VIEW_KILL_FILE_SIG(external_view_kill_file){ - Command_Data *cmd = (Command_Data*)app->cmd_context; - System_Functions *system = cmd->system; - Live_Views *live_set; - View *vptr; - Editing_File *file; - Working_Set *working_set; - Models *models; - int result = false; - int view_id; - - if (view->exists){ - models = cmd->models; - live_set = cmd->live_set; - view_id = view->view_id - 1; - if (view_id >= 0 && view_id < live_set->max){ - vptr = live_set->views + view_id; - working_set = &models->working_set; - file = get_file_from_identifier(system, working_set, buffer); - - if (file){ - result = true; - try_kill_file(system, models, file, vptr, string_zero()); - fill_view_summary(view, vptr, live_set, working_set); - } - } - } - - return(result); - } - - GET_USER_INPUT_SIG(external_get_user_input){ - Command_Data *cmd = (Command_Data*)app->cmd_context; - System_Functions *system = cmd->system; - Coroutine *coroutine = (Coroutine*)app->current_coroutine; - User_Input result = {0}; - - if (app->type_coroutine == Co_Command){ - Assert(coroutine); - *((u32*)coroutine->out+0) = get_type; - *((u32*)coroutine->out+1) = abort_type; - system->yield_coroutine(coroutine); - result = *(User_Input*)coroutine->in; - } - - return(result); - } - - GET_COMMAND_INPUT_SIG(external_get_command_input){ - Command_Data *cmd = (Command_Data*)app->cmd_context; - User_Input result; - - result.type = UserInputKey; - result.abort = 0; - result.key = cmd->key; - result.command = 0; - - return(result); - } - - GET_MOUSE_STATE_SIG(external_get_mouse_state){ - Command_Data *cmd = (Command_Data*)app->cmd_context; - App_Vars *vars = cmd->vars; - Mouse_State mouse = direct_get_mouse_state(&vars->available_input); - return(mouse); - } - - GET_EVENT_MESSAGE_SIG(external_get_event_message){ - Event_Message message = {0}; - System_Functions *system = (System_Functions*)app->system_links; - Coroutine *coroutine = (Coroutine*)app->current_coroutine; - - if (app->type_coroutine == Co_View){ - Assert(coroutine); - system->yield_coroutine(coroutine); - message = *(Event_Message*)coroutine->in; - } - - return(message); - } - - START_QUERY_BAR_SIG(external_start_query_bar){ - Command_Data *cmd = (Command_Data*)app->cmd_context; - Query_Slot *slot = 0; - View *vptr; - - vptr = cmd->view; - - slot = alloc_query_slot(&vptr->query_set); - slot->query_bar = bar; - - return(slot != 0); - } - - END_QUERY_BAR_SIG(external_end_query_bar){ - Command_Data *cmd = (Command_Data*)app->cmd_context; - View *vptr; - vptr = cmd->view; - free_query_slot(&vptr->query_set, bar); - } - - PRINT_MESSAGE_SIG(external_print_message){ - Command_Data *cmd = (Command_Data*)app->cmd_context; - Models *models = cmd->models; - do_feedback_message(cmd->system, models, make_string(string, len)); - } - -#if 0 - GET_GUI_FUNCTIONS_SIG(external_get_gui_functions){ - GUI_Functions *guifn = 0; - NotImplemented; - return(guifn); - } - - GET_GUI_SIG(external_get_gui){ - GUI *gui = 0; - NotImplemented; - return(gui); - } -#endif - - CHANGE_THEME_SIG(external_change_theme){ - Command_Data *cmd = (Command_Data*)app->cmd_context; - Style_Library *styles = &cmd->models->styles; - String theme_name = make_string(name, len); - Style *s; - i32 i, count; - - count = styles->count; - s = styles->styles; - for (i = 0; i < count; ++i, ++s){ - if (match(s->name, theme_name)){ - style_copy(main_style(cmd->models), s); - break; - } - } - } - - CHANGE_FONT_SIG(external_change_font){ - Command_Data *cmd = (Command_Data*)app->cmd_context; - Font_Set *set = cmd->models->font_set; - Style_Font *global_font = &cmd->models->global_font; - String font_name = make_string(name, len); - i16 font_id; - - if (font_set_extract(set, font_name, &font_id)){ - global_font->font_id = font_id; - global_font->font_changed = 1; - } - } - - SET_THEME_COLORS_SIG(external_set_theme_colors){ - Command_Data *cmd = (Command_Data*)app->cmd_context; - Style *style = main_style(cmd->models); - Theme_Color *theme_color; - u32 *color; - i32 i; - - theme_color = colors; - for (i = 0; i < count; ++i, ++theme_color){ - color = style_index_by_tag(&style->main, theme_color->tag); - if (color) *color = theme_color->color | 0xFF000000; - } - } +#include "4ed_api_implementation.cpp" } struct Command_In{ @@ -2156,10 +1113,6 @@ app_links_init(System_Functions *system, Application_Links *app_links, void *dat app_links->memory = data; app_links->memory_size = size; -#define external_get_4ed_path system->get_4ed_path -#define external_file_exists system->file_exists -#define external_directory_cd system->directory_cd - FillAppLinksAPI(app_links); app_links->current_coroutine = 0; diff --git a/4ed_api_implementation.cpp b/4ed_api_implementation.cpp new file mode 100644 index 00000000..d4bf2b09 --- /dev/null +++ b/4ed_api_implementation.cpp @@ -0,0 +1,1101 @@ +/* +The implementation for the custom API +*/ + +// TOP + +internal void +fill_buffer_summary(Buffer_Summary *buffer, Editing_File *file, Working_Set *working_set){ + *buffer = buffer_summary_zero(); + if (!file->is_dummy){ + buffer->exists = 1; + buffer->ready = file_is_ready(file); + + buffer->is_lexed = file->settings.tokens_exist; + buffer->buffer_id = file->id.id; + buffer->size = file->state.buffer.size; + buffer->buffer_cursor_pos = file->state.cursor_pos; + + buffer->file_name_len = file->name.source_path.size; + buffer->buffer_name_len = file->name.live_name.size; + buffer->file_name = file->name.source_path.str; + buffer->buffer_name = file->name.live_name.str; + + buffer->map_id = file->settings.base_map_id; + } +} + +internal void +fill_view_summary(View_Summary *view, View *vptr, Live_Views *live_set, Working_Set *working_set){ + i32 lock_level; + int buffer_id; + *view = view_summary_zero(); + + if (vptr->in_use){ + view->exists = 1; + view->view_id = (int)(vptr - live_set->views) + 1; + view->line_height = (float)(vptr->line_height); + view->unwrapped_lines = vptr->file_data.unwrapped_lines; + view->show_whitespace = vptr->file_data.show_whitespace; + + + if (vptr->file_data.file){ + lock_level = view_lock_level(vptr); + buffer_id = vptr->file_data.file->id.id; + + if (lock_level <= 0){ + view->buffer_id = buffer_id; + } + else{ + view->buffer_id = 0; + } + + if (lock_level <= 1){ + view->locked_buffer_id = buffer_id; + } + else{ + view->locked_buffer_id = 0; + } + + if (lock_level <= 2){ + view->hidden_buffer_id = buffer_id; + } + else{ + view->hidden_buffer_id = 0; + } + + view->mark = view_compute_cursor_from_pos(vptr, vptr->recent->mark); + view->cursor = vptr->recent->cursor; + view->preferred_x = vptr->recent->preferred_x; + + view->file_region = vptr->file_region; + view->scroll_vars = *vptr->current_scroll; + } + } +} + +internal Editing_File* +get_file_from_identifier(System_Functions *system, Working_Set *working_set, Buffer_Identifier buffer){ + i32 buffer_id = buffer.id; + i32 buffer_name_len = buffer.name_len; + char *buffer_name = buffer.name; + + Editing_File *file = 0; + + if (buffer_id){ + file = working_set_get_active_file(working_set, buffer_id); + } + else if (buffer_name){ + file = working_set_contains(system, working_set, make_string(buffer_name, buffer_name_len)); + } + + return(file); +} + +String +make_string_terminated(Partition *part, char *str, int len){ + char *space = (char*)push_array(part, char, len + 1); + String string = make_string(str, len, len+1); + copy_fast_unsafe(space, string); + string.str = space; + terminate_with_null(&string); + return(string); +} + +EXEC_COMMAND_SIG(external_exec_command){ + Command_Data *cmd = (Command_Data*)app->cmd_context; + Command_Function function = command_table[command_id]; + Command_Binding binding = {}; + binding.function = function; + if (function) function(cmd->system, cmd, binding); + + update_command_data(cmd->vars, cmd); +} + +// TODO(allen): This is a bit of a mess and needs to be fixed soon +EXEC_SYSTEM_COMMAND_SIG(external_exec_system_command){ + Command_Data *cmd = (Command_Data*)app->cmd_context; + System_Functions *system = cmd->system; + App_Vars *vars = cmd->vars; + Models *models = cmd->models; + + char feedback_space[256]; + String feedback_str = make_fixed_width_string(feedback_space); + + Working_Set *working_set = &models->working_set; + CLI_Process *procs = vars->cli_processes.procs, *proc = 0; + Editing_File *file = 0; + b32 bind_to_new_view = true; + General_Memory *general = &models->mem.general; + + Partition *part = &models->mem.part; + Temp_Memory temp = begin_temp_memory(part); + + View *vptr = 0; + + int result = true; + + if (view->exists){ + Live_Views *live_set = cmd->live_set; + i32 view_id = view->view_id - 1; + if (view_id >= 0 && view_id < live_set->max){ + vptr = live_set->views + view_id; + } + } + + if (vptr == 0){ + result = false; + goto done; + } + + if (vars->cli_processes.count < vars->cli_processes.max){ + file = get_file_from_identifier(system, working_set, buffer); + if (file){ + if (file->settings.read_only == 0){ + append(&feedback_str, "ERROR: "); + append(&feedback_str, file->name.live_name); + append(&feedback_str, " is not a read-only buffer\n"); + do_feedback_message(system, models, feedback_str); + result = false; + goto done; + } + if (file->settings.never_kill){ + append(&feedback_str, "The buffer "); + append(&feedback_str, file->name.live_name); + append(&feedback_str, " is not killable"); + do_feedback_message(system, models, feedback_str); + result = false; + goto done; + } + } + else if (buffer.name){ + file = working_set_alloc_always(working_set, general); + if (file == 0){ + append(&feedback_str, "ERROR: unable to allocate a new buffer\n"); + do_feedback_message(system, models, feedback_str); + result = false; + goto done; + } + file_create_read_only(system, models, file, buffer.name); + working_set_add(system, working_set, file, general); + } + + if (file){ + i32 proc_count = vars->cli_processes.count; + View_Iter iter; + i32 i; + + for (i = 0; i < proc_count; ++i){ + if (procs[i].out_file == file){ + if (flags & CLI_OverlapWithConflict){ + procs[i].out_file = 0; + } + else{ + file = 0; + } + break; + } + } + + if (file){ + file_clear(system, models, file, 1); + file->settings.unimportant = 1; + + if (!(flags & CLI_AlwaysBindToView)){ + iter = file_view_iter_init(&models->layout, file, 0); + if (file_view_iter_good(iter)){ + bind_to_new_view = 0; + } + } + } + else{ + append(&feedback_str, "did not begin command-line command because the target buffer is already in use\n"); + do_feedback_message(system, models, feedback_str); + result = false; + goto done; + } + } + + String path_string = {0}; + if (!path){ + terminate_with_null(&models->hot_directory.string); + path_string = models->hot_directory.string; + } + else{ + path_string = make_string_terminated(part, path, path_len); + } + + { + String command_string = {0}; + + if (!command){ +#define NO_SCRIPT " echo no script specified" + command_string.str = NO_SCRIPT; + command_string.size = sizeof(NO_SCRIPT)-1; +#undef NO_SCRIPT + } + else{ + command_string = make_string_terminated(part, command, command_len); + } + + if (bind_to_new_view){ + view_set_file(vptr, file, models); + view_show_file(vptr); + } + + proc = procs + vars->cli_processes.count++; + proc->out_file = file; + + if (!system->cli_call(path_string.str, command_string.str, &proc->cli)){ + --vars->cli_processes.count; + } + } + } + else{ + append(&feedback_str, "ERROR: no available process slot\n"); + do_feedback_message(system, models, feedback_str); + result = false; + goto done; + } + + done: + end_temp_memory(temp); + return(result); +} + +DIRECTORY_GET_HOT_SIG(external_directory_get_hot){ + Command_Data *cmd = (Command_Data*)app->cmd_context; + Hot_Directory *hot = &cmd->models->hot_directory; + i32 copy_max = capacity - 1; + hot_directory_clean_end(hot); + if (copy_max > hot->string.size) + copy_max = hot->string.size; + memcpy(out, hot->string.str, copy_max); + out[copy_max] = 0; + return(hot->string.size); +} + +#define external_get_4ed_path system->get_4ed_path + +#define external_file_exists system->file_exists + +#define external_directory_cd system->directory_cd + +GET_FILE_LIST_SIG(external_get_file_list){ + Command_Data *cmd = (Command_Data*)app->cmd_context; + System_Functions *system = cmd->system; + File_List result = {}; + system->set_file_list(&result, make_string(dir, len)); + return(result); +} + +FREE_FILE_LIST_SIG(external_free_file_list){ + Command_Data *cmd = (Command_Data*)app->cmd_context; + System_Functions *system = cmd->system; + system->set_file_list(&list, make_string(0, 0)); +} + +GET_BUFFER_FIRST_SIG(external_get_buffer_first){ + Command_Data *cmd = (Command_Data*)app->cmd_context; + Working_Set *working_set = &cmd->models->working_set; + Buffer_Summary result = {}; + if (working_set->file_count > 0){ + fill_buffer_summary(&result, (Editing_File*)working_set->used_sentinel.next, working_set); + } + return(result); +} + +GET_BUFFER_NEXT_SIG(external_get_buffer_next){ + Command_Data *cmd = (Command_Data*)app->cmd_context; + Working_Set *working_set = &cmd->models->working_set; + Editing_File *file; + + file = working_set_get_active_file(working_set, buffer->buffer_id); + if (file){ + file = (Editing_File*)file->node.next; + fill_buffer_summary(buffer, file, working_set); + } + else{ + *buffer = buffer_summary_zero(); + } +} + +GET_BUFFER_SIG(external_get_buffer){ + Command_Data *cmd = (Command_Data*)app->cmd_context; + Working_Set *working_set = &cmd->models->working_set; + Buffer_Summary buffer = {}; + Editing_File *file; + + file = working_set_get_active_file(working_set, index); + if (file){ + fill_buffer_summary(&buffer, file, working_set); + } + + return(buffer); +} + +GET_PARAMETER_BUFFER_SIG(external_get_parameter_buffer){ + Command_Data *cmd = (Command_Data*)app->cmd_context; + Models *models = cmd->models; + Buffer_Summary buffer = {}; + + if (param_index >= 0 && param_index < models->buffer_param_count){ + buffer = external_get_buffer(app, models->buffer_param_indices[param_index]); + } + + return(buffer); +} + +GET_BUFFER_BY_NAME_SIG(external_get_buffer_by_name){ + Command_Data *cmd = (Command_Data*)app->cmd_context; + Buffer_Summary buffer = {}; + Editing_File *file; + Working_Set *working_set = &cmd->models->working_set; + + file = working_set_contains(cmd->system, working_set, make_string(filename, len)); + if (file && !file->is_dummy){ + fill_buffer_summary(&buffer, file, working_set); + } + + return(buffer); +} + +REFRESH_BUFFER_SIG(external_refresh_buffer){ + int result; + *buffer = external_get_buffer(app, buffer->buffer_id); + result = buffer->exists; + return(result); +} + +BUFFER_SEEK_SIG(external_buffer_seek){ + Command_Data *cmd = (Command_Data*)app->cmd_context; + Editing_File *file; + Working_Set *working_set; + int result = 0; + + if (buffer->exists){ + working_set = &cmd->models->working_set; + file = working_set_get_active_file(working_set, buffer->buffer_id); + if (file && file_is_ready(file)){ + // TODO(allen): reduce duplication? + { + i32 size = buffer_size(&file->state.buffer); + i32 pos[4] = {0}; + i32 new_pos = 0; + + if (start_pos < 0){ + start_pos = 0; + } + else if (start_pos > size){ + start_pos = size; + } + + if (seek_forward){ + for (i32 i = 0; i < ArrayCount(pos); ++i) pos[i] = size; + + if (flags & (1)){ + pos[0] = buffer_seek_whitespace_right(&file->state.buffer, start_pos); + } + + if (flags & (1 << 1)){ + if (file->state.tokens_complete){ + pos[1] = seek_token_right(&file->state.token_stack, start_pos); + } + else{ + pos[1] = buffer_seek_whitespace_right(&file->state.buffer, start_pos); + } + } + + if (flags & (1 << 2)){ + pos[2] = buffer_seek_alphanumeric_right(&file->state.buffer, start_pos); + if (flags & (1 << 3)){ + pos[3] = buffer_seek_range_camel_right(&file->state.buffer, start_pos, pos[2]); + } + } + else{ + if (flags & (1 << 3)){ + pos[3] = buffer_seek_alphanumeric_or_camel_right(&file->state.buffer, start_pos); + } + } + + new_pos = size; + for (i32 i = 0; i < ArrayCount(pos); ++i){ + if (pos[i] < new_pos) new_pos = pos[i]; + } + } + else{ + if (flags & (1)){ + pos[0] = buffer_seek_whitespace_left(&file->state.buffer, start_pos); + } + + if (flags & (1 << 1)){ + if (file->state.tokens_complete){ + pos[1] = seek_token_left(&file->state.token_stack, start_pos); + } + else{ + pos[1] = buffer_seek_whitespace_left(&file->state.buffer, start_pos); + } + } + + if (flags & (1 << 2)){ + pos[2] = buffer_seek_alphanumeric_left(&file->state.buffer, start_pos); + if (flags & (1 << 3)){ + pos[3] = buffer_seek_range_camel_left(&file->state.buffer, start_pos, pos[2]); + } + } + else{ + if (flags & (1 << 3)){ + pos[3] = buffer_seek_alphanumeric_or_camel_left(&file->state.buffer, start_pos); + } + } + + new_pos = 0; + for (i32 i = 0; i < ArrayCount(pos); ++i){ + if (pos[i] > new_pos) new_pos = pos[i]; + } + } + result = new_pos; + } + + fill_buffer_summary(buffer, file, working_set); + } + } + + return(result); +} + +BUFFER_READ_RANGE_SIG(external_buffer_read_range){ + Command_Data *cmd = (Command_Data*)app->cmd_context; + Editing_File *file; + Working_Set *working_set; + int result = 0; + int size; + + if (buffer->exists){ + working_set = &cmd->models->working_set; + file = working_set_get_active_file(working_set, buffer->buffer_id); + if (file && file_is_ready(file)){ + size = buffer_size(&file->state.buffer); + if (0 <= start && start <= end && end <= size){ + result = 1; + buffer_stringify(&file->state.buffer, start, end, out); + } + fill_buffer_summary(buffer, file, working_set); + } + } + + return(result); +} + +BUFFER_REPLACE_RANGE_SIG(external_buffer_replace_range){ + Command_Data *cmd = (Command_Data*)app->cmd_context; + Editing_File *file; + Working_Set *working_set; + + Models *models; + + int result = 0; + int size; + int next_cursor, pos; + + if (buffer->exists){ + models = cmd->models; + working_set = &models->working_set; + file = working_set_get_active_file(working_set, buffer->buffer_id); + if (file && file_is_ready(file)){ + size = buffer_size(&file->state.buffer); + if (0 <= start && start <= end && end <= size){ + result = 1; + + pos = file->state.cursor_pos; + if (pos < start) next_cursor = pos; + else if (pos < end) next_cursor = start; + else next_cursor = pos + end - start - len; + + file_replace_range(cmd->system, models, file, start, end, str, len, next_cursor); + } + fill_buffer_summary(buffer, file, working_set); + } + } + + return(result); +} + +#if 0 +BUFFER_SET_POS_SIG(external_buffer_set_pos){ + Command_Data *cmd = (Command_Data*)app->cmd_context; + Editing_File *file; + Working_Set *working_set; + + int result = 0; + int size; + + if (buffer->exists){ + working_set = &cmd->models->working_set; + file = working_set_get_active_file(working_set, buffer->buffer_id); + if (file && file_is_ready(file)){ + result = 1; + size = buffer_size(&file->state.buffer); + if (pos < 0) pos = 0; + if (pos > size) pos = size; + file->state.cursor_pos = pos; + fill_buffer_summary(buffer, file, working_set); + } + } + + return(result); +} +#endif + +BUFFER_SET_SETTING_SIG(external_buffer_set_setting){ + Command_Data *cmd = (Command_Data*)app->cmd_context; + System_Functions *system = cmd->system; + Models *models = cmd->models; + + Editing_File *file; + Working_Set *working_set; + + int result = false; + + i32 new_mapid = 0; + + if (buffer->exists){ + working_set = &models->working_set; + file = working_set_get_active_file(working_set, buffer->buffer_id); + if (file && file_is_ready(file)){ + result = true; + switch (setting){ + case BufferSetting_Lex: + { +#if BUFFER_EXPERIMENT_SCALPEL <= 0 + if (file->settings.tokens_exist){ + if (!value){ + file_kill_tokens(system, &models->mem.general, file); + } + } + else{ + if (value){ + file_first_lex_parallel(system, &models->mem.general, file); + } + } +#endif + }break; + + case BufferSetting_WrapLine: + { + file->settings.unwrapped_lines = !value; + }break; + + case BufferSetting_MapID: + { + if (value == mapid_global){ + file->settings.base_map_id = mapid_global; + } + else if (value == mapid_file){ + file->settings.base_map_id = mapid_file; + } + else if (value < mapid_global){ + new_mapid = get_map_index(models, value); + if (new_mapid < models->user_map_count){ + file->settings.base_map_id = value; + } + else{ + file->settings.base_map_id = mapid_file; + } + } + + for (View_Iter iter = file_view_iter_init(&models->layout, file, 0); + file_view_iter_good(iter); + iter = file_view_iter_next(iter)){ + iter.view->map = get_map(models, file->settings.base_map_id); + } + }break; + } + } + + fill_buffer_summary(buffer, file, working_set); + } + + return(result); +} + +BUFFER_SAVE_SIG(external_buffer_save){ + Command_Data *cmd = (Command_Data*)app->cmd_context; + System_Functions *system = cmd->system; + Models *models = cmd->models; + + Editing_File *file; + Working_Set *working_set; + + int result = false; + + if (buffer->exists){ + working_set = &models->working_set; + file = working_set_get_active_file(working_set, buffer->buffer_id); + if (file && !file->is_dummy && file_is_ready(file)){ + result = true; + String name = make_string(filename, filename_len); + view_save_file(system, models, file, 0, name, 0); + } + } + + return(result); +} + +GET_VIEW_FIRST_SIG(external_get_view_first){ + Command_Data *cmd = (Command_Data*)app->cmd_context; + Editing_Layout *layout = &cmd->models->layout; + View_Summary view = {}; + + Panel *panel = layout->used_sentinel.next; + + Assert(panel != &layout->used_sentinel); + fill_view_summary(&view, panel->view, &cmd->vars->live_set, &cmd->models->working_set); + + return(view); +} + +GET_VIEW_NEXT_SIG(external_get_view_next){ + Command_Data *cmd = (Command_Data*)app->cmd_context; + Editing_Layout *layout = &cmd->models->layout; + Live_Views *live_set = &cmd->vars->live_set; + View *vptr; + Panel *panel; + int index = view->view_id - 1; + + if (index >= 0 && index < live_set->max){ + vptr = live_set->views + index; + panel = vptr->panel; + if (panel) panel = panel->next; + if (panel && panel != &layout->used_sentinel){ + fill_view_summary(view, panel->view, &cmd->vars->live_set, &cmd->models->working_set); + } + else{ + *view = view_summary_zero(); + } + } + else{ + *view = view_summary_zero(); + } +} + +GET_VIEW_SIG(external_get_view){ + Command_Data *cmd = (Command_Data*)app->cmd_context; + View_Summary view = {}; + Live_Views *live_set = cmd->live_set; + int max = live_set->max; + View *vptr; + + index -= 1; + if (index >= 0 && index < max){ + vptr = live_set->views + index; + fill_view_summary(&view, vptr, live_set, &cmd->models->working_set); + } + + return(view); +} + +GET_ACTIVE_VIEW_SIG(external_get_active_view){ + Command_Data *cmd = (Command_Data*)app->cmd_context; + View_Summary view = {}; + fill_view_summary(&view, cmd->view, &cmd->vars->live_set, &cmd->models->working_set); + return(view); +} + +REFRESH_VIEW_SIG(external_refresh_view){ + int result; + *view = external_get_view(app, view->view_id); + result = view->exists; + return(result); +} + +VIEW_AUTO_TAB_SIG(external_view_auto_tab){ + Command_Data *cmd = (Command_Data*)app->cmd_context; + System_Functions *system = cmd->system; + Models *models = cmd->models; + + int result = false; + + Live_Views *live_set; + Editing_File *file; + View *vptr; + int view_id; + + if (view->exists){ + live_set = cmd->live_set; + view_id = view->view_id - 1; + if (view_id >= 0 && view_id < live_set->max){ + vptr = live_set->views + view_id; + file = vptr->file_data.file; + + if (file && file->state.token_stack.tokens && + file->state.tokens_complete && !file->state.still_lexing){ + result = true; + + Indent_Options opts; + opts.empty_blank_lines = (flags & AutoTab_ClearLine); + opts.use_tabs = (flags & AutoTab_UseTab); + opts.tab_width = tab_width; + + view_auto_tab_tokens(system, models, vptr, start, end, opts); + } + } + } + + return(result); +} + +VIEW_COMPUTE_CURSOR_SIG(external_view_compute_cursor){ + Command_Data *cmd = (Command_Data*)app->cmd_context; + Live_Views *live_set; + View *vptr; + Editing_File *file; + Full_Cursor result = {0}; + int view_id; + + if (view->exists){ + live_set = cmd->live_set; + view_id = view->view_id - 1; + if (view_id >= 0 && view_id < live_set->max){ + vptr = live_set->views + view_id; + file = vptr->file_data.file; + if (file && !file->is_loading){ + if (seek.type == buffer_seek_line_char && seek.character <= 0){ + seek.character = 1; + } + result = view_compute_cursor(vptr, seek); + fill_view_summary(view, vptr, live_set, &cmd->models->working_set); + } + } + } + + return(result); +} + +VIEW_SET_CURSOR_SIG(external_view_set_cursor){ + Command_Data *cmd = (Command_Data*)app->cmd_context; + Live_Views *live_set; + View *vptr; + Editing_File *file; + int result = 0; + int view_id; + + if (view->exists){ + live_set = cmd->live_set; + view_id = view->view_id - 1; + if (view_id >= 0 && view_id < live_set->max){ + vptr = live_set->views + view_id; + file = vptr->file_data.file; + if (file && !file->is_loading){ + result = 1; + if (seek.type == buffer_seek_line_char && seek.character <= 0){ + seek.character = 1; + } + vptr->recent->cursor = view_compute_cursor(vptr, seek); + if (set_preferred_x){ + vptr->recent->preferred_x = view_get_cursor_x(vptr); + } + fill_view_summary(view, vptr, live_set, &cmd->models->working_set); + file->state.cursor_pos = vptr->recent->cursor.pos; + } + } + } + + return(result); +} + +VIEW_SET_MARK_SIG(external_view_set_mark){ + Command_Data *cmd = (Command_Data*)app->cmd_context; + Live_Views *live_set; + View *vptr; + Full_Cursor cursor; + int result = 0; + int view_id; + + if (view->exists){ + live_set = cmd->live_set; + view_id = view->view_id - 1; + if (view_id >= 0 && view_id < live_set->max){ + vptr = live_set->views + view_id; + result = 1; + if (seek.type != buffer_seek_pos){ + cursor = view_compute_cursor(vptr, seek); + vptr->recent->mark = cursor.pos; + } + else{ + vptr->recent->mark = seek.pos; + } + fill_view_summary(view, vptr, live_set, &cmd->models->working_set); + } + } + + return(result); +} + +VIEW_SET_HIGHLIGHT_SIG(external_view_set_highlight){ + Command_Data *cmd = (Command_Data*)app->cmd_context; + Live_Views *live_set; + View *vptr; + int result = 0; + int view_id; + + if (view->exists){ + live_set = cmd->live_set; + view_id = view->view_id - 1; + if (view_id >= 0 && view_id < live_set->max){ + vptr = live_set->views + view_id; + result = 1; + if (turn_on){ + view_set_temp_highlight(vptr, start, end); + } + else{ + vptr->file_data.show_temp_highlight = 0; + } + fill_view_summary(view, vptr, live_set, &cmd->models->working_set); + } + } + + return(result); +} + +VIEW_SET_BUFFER_SIG(external_view_set_buffer){ + Command_Data *cmd = (Command_Data*)app->cmd_context; + Live_Views *live_set; + View *vptr; + Editing_File *file; + Working_Set *working_set; + Models *models; + int result = 0; + int view_id; + + if (view->exists){ + models = cmd->models; + live_set = cmd->live_set; + view_id = view->view_id - 1; + if (view_id >= 0 && view_id < live_set->max){ + vptr = live_set->views + view_id; + working_set = &models->working_set; + file = working_set_get_active_file(working_set, buffer_id); + + if (file){ + result = 1; + if (file != vptr->file_data.file){ + view_set_file(vptr, file, models); + view_show_file(vptr); + } + } + + fill_view_summary(view, vptr, live_set, working_set); + } + } + + return(result); +} + +VIEW_OPEN_FILE_SIG(external_view_open_file){ + Command_Data *cmd = (Command_Data*)app->cmd_context; + + System_Functions *system = cmd->system; + Models *models = cmd->models; + + Working_Set *working_set = &models->working_set; + + Live_Views *live_set = cmd->live_set; + + int result = false; + + // TODO(allen): do in background option + + Partition *part = &models->mem.part; + Temp_Memory temp = begin_temp_memory(part); + String string = make_string_terminated(part, filename, filename_len); + + if (do_in_background){ + result = true; + view_open_file(system, models, 0, string); + } + else if (view){ + View *vptr = 0; + int view_id = view->view_id - 1; + if (view_id >= 0 && view_id < live_set->max){ + vptr = live_set->views + view_id; + result = true; + + view_open_file(system, models, 0, string); + + fill_view_summary(view, vptr, live_set, working_set); + } + } + + end_temp_memory(temp); + + return(result); +} + +VIEW_KILL_BUFFER_SIG(external_view_kill_buffer){ + Command_Data *cmd = (Command_Data*)app->cmd_context; + System_Functions *system = cmd->system; + Live_Views *live_set; + View *vptr; + Editing_File *file; + Working_Set *working_set; + Models *models; + int result = false; + int view_id; + + if (view->exists){ + models = cmd->models; + live_set = cmd->live_set; + view_id = view->view_id - 1; + if (view_id >= 0 && view_id < live_set->max){ + vptr = live_set->views + view_id; + working_set = &models->working_set; + file = get_file_from_identifier(system, working_set, buffer); + + if (file){ + result = true; + try_kill_file(system, models, file, vptr, string_zero()); + fill_view_summary(view, vptr, live_set, working_set); + } + } + } + + return(result); +} + +GET_USER_INPUT_SIG(external_get_user_input){ + Command_Data *cmd = (Command_Data*)app->cmd_context; + System_Functions *system = cmd->system; + Coroutine *coroutine = (Coroutine*)app->current_coroutine; + User_Input result = {0}; + + if (app->type_coroutine == Co_Command){ + Assert(coroutine); + *((u32*)coroutine->out+0) = get_type; + *((u32*)coroutine->out+1) = abort_type; + system->yield_coroutine(coroutine); + result = *(User_Input*)coroutine->in; + } + + return(result); +} + +GET_COMMAND_INPUT_SIG(external_get_command_input){ + Command_Data *cmd = (Command_Data*)app->cmd_context; + User_Input result; + + result.type = UserInputKey; + result.abort = 0; + result.key = cmd->key; + result.command = 0; + + return(result); +} + +GET_MOUSE_STATE_SIG(external_get_mouse_state){ + Command_Data *cmd = (Command_Data*)app->cmd_context; + App_Vars *vars = cmd->vars; + Mouse_State mouse = direct_get_mouse_state(&vars->available_input); + return(mouse); +} + +GET_EVENT_MESSAGE_SIG(external_get_event_message){ + Event_Message message = {0}; + System_Functions *system = (System_Functions*)app->system_links; + Coroutine *coroutine = (Coroutine*)app->current_coroutine; + + if (app->type_coroutine == Co_View){ + Assert(coroutine); + system->yield_coroutine(coroutine); + message = *(Event_Message*)coroutine->in; + } + + return(message); +} + +START_QUERY_BAR_SIG(external_start_query_bar){ + Command_Data *cmd = (Command_Data*)app->cmd_context; + Query_Slot *slot = 0; + View *vptr; + + vptr = cmd->view; + + slot = alloc_query_slot(&vptr->query_set); + slot->query_bar = bar; + + return(slot != 0); +} + +END_QUERY_BAR_SIG(external_end_query_bar){ + Command_Data *cmd = (Command_Data*)app->cmd_context; + View *vptr; + vptr = cmd->view; + free_query_slot(&vptr->query_set, bar); +} + +PRINT_MESSAGE_SIG(external_print_message){ + Command_Data *cmd = (Command_Data*)app->cmd_context; + Models *models = cmd->models; + do_feedback_message(cmd->system, models, make_string(string, len)); +} + +#if 0 +GET_GUI_FUNCTIONS_SIG(external_get_gui_functions){ + GUI_Functions *guifn = 0; + NotImplemented; + return(guifn); +} + +GET_GUI_SIG(external_get_gui){ + GUI *gui = 0; + NotImplemented; + return(gui); +} +#endif + +CHANGE_THEME_SIG(external_change_theme){ + Command_Data *cmd = (Command_Data*)app->cmd_context; + Style_Library *styles = &cmd->models->styles; + String theme_name = make_string(name, len); + Style *s; + i32 i, count; + + count = styles->count; + s = styles->styles; + for (i = 0; i < count; ++i, ++s){ + if (match(s->name, theme_name)){ + style_copy(main_style(cmd->models), s); + break; + } + } +} + +CHANGE_FONT_SIG(external_change_font){ + Command_Data *cmd = (Command_Data*)app->cmd_context; + Font_Set *set = cmd->models->font_set; + Style_Font *global_font = &cmd->models->global_font; + String font_name = make_string(name, len); + i16 font_id; + + if (font_set_extract(set, font_name, &font_id)){ + global_font->font_id = font_id; + global_font->font_changed = 1; + } +} + +SET_THEME_COLORS_SIG(external_set_theme_colors){ + Command_Data *cmd = (Command_Data*)app->cmd_context; + Style *style = main_style(cmd->models); + Theme_Color *theme_color; + u32 *color; + i32 i; + + theme_color = colors; + for (i = 0; i < count; ++i, ++theme_color){ + color = style_index_by_tag(&style->main, theme_color->tag); + if (color) *color = theme_color->color | 0xFF000000; + } +} + +// BOTTOM + diff --git a/4ed_file_view.cpp b/4ed_file_view.cpp index 5274e0a5..8511cc63 100644 --- a/4ed_file_view.cpp +++ b/4ed_file_view.cpp @@ -5171,17 +5171,17 @@ do_step_file_view(System_Functions *system, activation_key = char_to_upper(activation_key); if (activation_key != 0){ - count = keys->count; - for (i = 0; i < count; ++i){ - key = get_single_key(keys, i); - if (char_to_upper(key.character) == activation_key){ - target->active = b->id; - result.is_animating = true; - break; - } + count = keys->count; + for (i = 0; i < count; ++i){ + key = get_single_key(keys, i); + if (char_to_upper(key.character) == activation_key){ + target->active = b->id; + result.is_animating = true; + break; } } } + } }break; case guicom_scrollable_slider: diff --git a/4ed_metagen.cpp b/4ed_metagen.cpp index 4a0ffcdb..b2aa3916 100644 --- a/4ed_metagen.cpp +++ b/4ed_metagen.cpp @@ -370,6 +370,15 @@ skip_whitespace(String str){ return(result); } +String +chop_whitespace(String str){ + String result = {0}; + int i = str.size; + for (; i > 0 && char_is_whitespace(str.str[i-1]); --i); + result = substr(str, 0, i); + return(result); +} + int is_comment(String str){ int result = 0; @@ -385,7 +394,7 @@ is_comment(String str){ char* generate_custom_headers(){ char *filename = "4coder_custom_api.h"; - String data = file_dump("custom_api_spec.txt"); + String data = file_dump("custom_api_spec.cpp"); int line_count = 0; String line = {0}; @@ -409,10 +418,11 @@ generate_custom_headers(){ String parse = line; parse = skip_whitespace(parse); + parse = chop_whitespace(parse); if (parse.size > 0){ if (!is_comment(parse)){ Function_Signature *sig = sigs + sig_count; - memset(sig, 0, sizeof(Function_Signature)); + memset(sig, 0, sizeof(*sig)); ++sig_count; @@ -427,8 +437,24 @@ generate_custom_headers(){ parse = substr(parse, pos); if (parse.size > 0){ - sig->args = parse; - sig->valid = 1; + char end = parse.str[parse.size - 1]; + int valid = true; + + switch (end){ + case ')': + sig->args = parse; + break; + + case ';': + --parse.size; + sig->args = parse; + break; + + default: + valid = false; + break; + } + sig->valid = valid; if (max_name_size < sig->name.size){ max_name_size = sig->name.size; @@ -437,7 +463,7 @@ generate_custom_headers(){ } if (!sig->valid){ - printf("custom_api_spec.txt(%d) : generator warning : invalid function signature\n", + printf("custom_api_spec.cpp(%d) : generator warning : invalid function signature\n", line_count); } } @@ -500,8 +526,7 @@ generate_custom_headers(){ ); fprintf(file, "};\n"); - fprintf(file, - "#define FillAppLinksAPI(app_links) do{"); + fprintf(file, "#define FillAppLinksAPI(app_links) do{"); for (int i = 0; i < sig_count; ++i){ Function_Signature *sig = sigs + i; @@ -515,7 +540,7 @@ generate_custom_headers(){ name_buffer, name_buffer ); } - fprintf(file," } while(false)\n"); + fprintf(file, " } while(false)\n"); fclose(file); diff --git a/custom_api_spec.txt b/custom_api_spec.cpp similarity index 51% rename from custom_api_spec.txt rename to custom_api_spec.cpp index c0028671..e4ff62c9 100644 --- a/custom_api_spec.txt +++ b/custom_api_spec.cpp @@ -1,67 +1,70 @@ // Command exectuion -void Exec_Command(Application_Links *app, int command_id) -int Exec_System_Command(Application_Links *app, View_Summary *view, Buffer_Identifier buffer, char *path, int path_len, char *command, int command_len, unsigned int flags) +void Exec_Command(Application_Links *app, int command_id); +int Exec_System_Command(Application_Links *app, View_Summary *view, Buffer_Identifier buffer, char *path, int path_len, char *command, int command_len, unsigned int flags); // File system navigation -int Directory_Get_Hot(Application_Links *app, char *out, int capacity) -int Get_4ed_Path(Application_Links *app, char *out, int capacity) -int File_Exists(Application_Links *app, char *filename, int len) -int Directory_CD(Application_Links *app, char *dir, int *len, int capacity, char *rel_path, int rel_len) -File_List Get_File_List(Application_Links *app, char *dir, int len) -void Free_File_List(Application_Links *app, File_List list) +int Directory_Get_Hot(Application_Links *app, char *out, int capacity); +int Get_4ed_Path(Application_Links *app, char *out, int capacity); +int File_Exists(Application_Links *app, char *filename, int len); +int Directory_CD(Application_Links *app, char *dir, int *len, int capacity, char *rel_path, int rel_len); +File_List Get_File_List(Application_Links *app, char *dir, int len); +void Free_File_List(Application_Links *app, File_List list); // Direct buffer manipulation -Buffer_Summary Get_Buffer_First(Application_Links *app) -void Get_Buffer_Next(Application_Links *app, Buffer_Summary *buffer) +Buffer_Summary Get_Buffer_First(Application_Links *app); +void Get_Buffer_Next(Application_Links *app, Buffer_Summary *buffer); -Buffer_Summary Get_Buffer(Application_Links *app, int index) -Buffer_Summary Get_Parameter_Buffer(Application_Links *app, int param_index) -Buffer_Summary Get_Buffer_By_Name(Application_Links *app, char *filename, int len) +Buffer_Summary Get_Buffer(Application_Links *app, int index); +Buffer_Summary Get_Parameter_Buffer(Application_Links *app, int param_index); +Buffer_Summary Get_Buffer_By_Name(Application_Links *app, char *filename, int len); -int Refresh_Buffer(Application_Links *app, Buffer_Summary *buffer) -int Buffer_Read_Range(Application_Links *app, Buffer_Summary *buffer, int start, int end, char *out) -int Buffer_Replace_Range(Application_Links *app, Buffer_Summary *buffer, int start, int end, char *str, int len) -//int Buffer_Set_Pos(Application_Links *app, Buffer_Summary *buffer, int pos) +int Refresh_Buffer(Application_Links *app, Buffer_Summary *buffer); +int Buffer_Read_Range(Application_Links *app, Buffer_Summary *buffer, int start, int end, char *out); +int Buffer_Replace_Range(Application_Links *app, Buffer_Summary *buffer, int start, int end, char *str, int len); +//int Buffer_Set_Pos(Application_Links *app, Buffer_Summary *buffer, int pos); -int Buffer_Seek(Application_Links *app, Buffer_Summary *buffer, int start_pos, int seek_forward, unsigned int flags) -int Buffer_Set_Setting(Application_Links *app, Buffer_Summary *buffer, int setting, int value) +int Buffer_Seek(Application_Links *app, Buffer_Summary *buffer, int start_pos, int seek_forward, unsigned int flags); +int Buffer_Set_Setting(Application_Links *app, Buffer_Summary *buffer, int setting, int value); + +int Buffer_Save(Application_Links *app, Buffer_Summary *buffer, char *filename, int filename_len); // View manipulation -View_Summary Get_View_First(Application_Links *app) -void Get_View_Next(Application_Links *app, View_Summary *view) +View_Summary Get_View_First(Application_Links *app); +void Get_View_Next(Application_Links *app, View_Summary *view); -View_Summary Get_View(Application_Links *app, int index) -View_Summary Get_Active_View(Application_Links *app) +View_Summary Get_View(Application_Links *app, int index); +View_Summary Get_Active_View(Application_Links *app); -int Refresh_View(Application_Links *app, View_Summary *view) +int Refresh_View(Application_Links *app, View_Summary *view); -int View_Auto_Tab(Application_Links *app, View_Summary *view, int start, int end, int tab_width, unsigned int flags) -Full_Cursor View_Compute_Cursor(Application_Links *app, View_Summary *view, Buffer_Seek seek) -int View_Set_Cursor(Application_Links *app, View_Summary *view, Buffer_Seek seek, int set_preferred_x) -int View_Set_Mark(Application_Links *app, View_Summary *view, Buffer_Seek seek) -int View_Set_Highlight(Application_Links *app, View_Summary *view, int start, int end, int turn_on) -int View_Set_Buffer(Application_Links *app, View_Summary *view, int buffer_id) +int View_Auto_Tab(Application_Links *app, View_Summary *view, int start, int end, int tab_width, unsigned int flags); +Full_Cursor View_Compute_Cursor(Application_Links *app, View_Summary *view, Buffer_Seek seek); +int View_Set_Cursor(Application_Links *app, View_Summary *view, Buffer_Seek seek, int set_preferred_x); +int View_Set_Mark(Application_Links *app, View_Summary *view, Buffer_Seek seek); +int View_Set_Highlight(Application_Links *app, View_Summary *view, int start, int end, int turn_on); +int View_Set_Buffer(Application_Links *app, View_Summary *view, int buffer_id); -int View_Open_File(Application_Links *app, View_Summary *view, char *filename, int filename_len, int do_in_background) -int View_Kill_File(Application_Links *app, View_Summary *view, Buffer_Identifier buffer) +// TODO(allen): Make sure this is just right. +int View_Open_File(Application_Links *app, View_Summary *view, char *filename, int filename_len, int do_in_background); +int View_Kill_Buffer(Application_Links *app, View_Summary *view, Buffer_Identifier buffer); // Directly get user input -User_Input Get_User_Input(Application_Links *app, unsigned int get_type, unsigned int abort_type) -User_Input Get_Command_Input(Application_Links *app) -Event_Message Get_Event_Message(Application_Links *app) -Mouse_State Get_Mouse_State(Application_Links *app) +User_Input Get_User_Input(Application_Links *app, unsigned int get_type, unsigned int abort_type); +User_Input Get_Command_Input(Application_Links *app); +Event_Message Get_Event_Message(Application_Links *app); +Mouse_State Get_Mouse_State(Application_Links *app); // Queries and information display -int Start_Query_Bar(Application_Links *app, Query_Bar *bar, unsigned int flags) -void End_Query_Bar(Application_Links *app, Query_Bar *bar, unsigned int flags) -void Print_Message(Application_Links *app, char *string, int len) -//GUI_Functions* Get_GUI_Functions(Application_Links *app) -//GUI* Get_GUI(Application_Links *app, int view_id) +int Start_Query_Bar(Application_Links *app, Query_Bar *bar, unsigned int flags); +void End_Query_Bar(Application_Links *app, Query_Bar *bar, unsigned int flags); +void Print_Message(Application_Links *app, char *string, int len); +//GUI_Functions* Get_GUI_Functions(Application_Links *app); +//GUI* Get_GUI(Application_Links *app, int view_id); // Color settings -void Change_Theme(Application_Links *app, char *name, int len) -void Change_Font(Application_Links *app, char *name, int len) -void Set_Theme_Colors(Application_Links *app, Theme_Color *colors, int count) +void Change_Theme(Application_Links *app, char *name, int len); +void Change_Font(Application_Links *app, char *name, int len); +void Set_Theme_Colors(Application_Links *app, Theme_Color *colors, int count); diff --git a/power/4coder_casey.cpp b/power/4coder_casey.cpp index 23a0ebb4..e994b5bd 100644 --- a/power/4coder_casey.cpp +++ b/power/4coder_casey.cpp @@ -452,10 +452,8 @@ CUSTOM_COMMAND_SIG(casey_kill_to_end_of_line) CUSTOM_COMMAND_SIG(casey_paste_and_tab) { - // NOTE(allen): Paste puts the mark at the beginning and the cursor at - // the end of the pasted chunk, so it is all set for cmdid_auto_tab_range exec_command(app, cmdid_paste); - exec_command(app, cmdid_auto_tab_range); + exec_command(app, auto_tab_range); } CUSTOM_COMMAND_SIG(casey_seek_beginning_of_line_and_tab) @@ -514,13 +512,18 @@ SwitchToOrLoadFile(struct Application_Links *app, String FileName, bool CreateIf { if(app->file_exists(app, FileName.str, FileName.size) || CreateIfNotFound) { +#if 0 push_parameter(app, par_name, expand_str(FileName)); // TODO(casey): Do I have to check for existence, or can I pass a parameter // to interactive open to tell it to fail if the file isn't there? exec_command(app, cmdid_interactive_open); - +#endif + + // NOTE(allen): This opens the file and puts it in &view + app->view_open_file(app, &view, expand_str(FileName), false); + Result.buffer = app->get_buffer_by_name(app, FileName.str, FileName.size); - + Result.Loaded = true; Result.Switched = true; } @@ -607,7 +610,7 @@ CUSTOM_COMMAND_SIG(casey_find_corresponding_file) int MaxExtensionLength = 3; int Space = (int)(buffer.file_name_len + MaxExtensionLength); String FileNameStem = make_string(buffer.file_name, (int)(extension.str - buffer.file_name), 0); - String TestFileName = make_string(app->push_memory(app, Space), 0, Space); + String TestFileName = make_string(app->memory, 0, Space); for(int ExtensionIndex = 0; ExtensionCount; ++ExtensionIndex) @@ -646,11 +649,16 @@ CUSTOM_COMMAND_SIG(casey_save_and_make_without_asking) buffer.exists; app->get_buffer_next(app, &buffer)) { +#if 0 push_parameter(app, par_name, buffer.file_name, buffer.file_name_len); push_parameter(app, par_buffer_id, buffer.buffer_id); exec_command(app, cmdid_save); +#endif + + app->buffer_save(app, &buffer, buffer.file_name, buffer.file_name_len); } +#if 0 String dir = make_string(app->memory, 0, app->memory_size); append(&dir, BuildDirectory); for(int At = 0; @@ -677,6 +685,40 @@ CUSTOM_COMMAND_SIG(casey_save_and_make_without_asking) else{ app->clear_parameters(app); } +#endif + + // NOTE(allen): The parameter pushing made it a little easier + // to deal with this particular pattern where two similar strings + // were both used. Now both strings need to exist at the same + // time on the users side. + + int size = app->memory_size/2; + String dir = make_string(app->memory, 0, size); + String command = make_string((char*)app->memory + size, 0, size); + + append(&dir, BuildDirectory); + for(int At = 0; + At < dir.size; + ++At) + { + if(dir.str[At] == '/') + { + dir.str[At] = '\\'; + } + } + + append(&command, dir); + + if(append(&command, "build.bat")) + { + View_Summary view = app->get_active_view(app); + app->exec_system_command(app, &view, + buffer_identifier(GlobalCompilationBufferName, (int)strlen(GlobalCompilationBufferName)), + dir.str, dir.size, + command.str, command.size, + CLI_OverlapWithConflict); + } + exec_command(app, cmdid_change_active_panel); } internal bool @@ -1105,9 +1147,13 @@ OpenProject(Application_Links *app, char *ProjectFileName) // was originally, so that new appends overwrite old ones. dir.size = dir_size; append(&dir, info->filename); +#if 0 push_parameter(app, par_name, dir.str, dir.size); push_parameter(app, par_do_in_background, 1); exec_command(app, cmdid_interactive_open); +#endif + + app->view_open_file(app, 0, dir.str, dir.size, true); ++TotalOpenAttempts; } } @@ -1233,7 +1279,7 @@ DEFINE_MODAL_KEY(modal_d, casey_kill_to_end_of_line); DEFINE_MODAL_KEY(modal_e, write_character); // TODO(casey): Available DEFINE_MODAL_KEY(modal_f, casey_paste_and_tab); DEFINE_MODAL_KEY(modal_g, goto_line); -DEFINE_MODAL_KEY(modal_h, cmdid_auto_tab_range); +DEFINE_MODAL_KEY(modal_h, auto_tab_range); DEFINE_MODAL_KEY(modal_i, move_up); DEFINE_MODAL_KEY(modal_j, seek_white_or_token_left); DEFINE_MODAL_KEY(modal_k, move_down); @@ -1295,13 +1341,19 @@ HOOK_SIG(casey_file_settings) treat_as_code = IsCode(ext); treat_as_project = match(ext, make_lit_string("prj")); } - + +#if 0 push_parameter(app, par_buffer_id, buffer.buffer_id); push_parameter(app, par_lex_as_cpp_file, treat_as_code); push_parameter(app, par_wrap_lines, !treat_as_code); push_parameter(app, par_key_mapid, mapid_file); exec_command(app, cmdid_set_settings); - +#endif + + app->buffer_set_setting(app, &buffer, BufferSetting_Lex, treat_as_code); + app->buffer_set_setting(app, &buffer, BufferSetting_WrapLine, !treat_as_code); + app->buffer_set_setting(app, &buffer, BufferSetting_MapID, mapid_file); + if(treat_as_project) { OpenProject(app, buffer.file_name);