got 4coder_casey.cpp working with API updates.

master
Allen Webster 2016-06-13 14:54:26 -04:00
parent 33c8339c92
commit 6ec67c0913
8 changed files with 1260 additions and 1122 deletions

View File

@ -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;\

View File

@ -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]));
}
}

1049
4ed.cpp

File diff suppressed because it is too large Load Diff

1101
4ed_api_implementation.cpp Normal file

File diff suppressed because it is too large Load Diff

View File

@ -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){
char end = parse.str[parse.size - 1];
int valid = true;
switch (end){
case ')':
sig->args = parse;
sig->valid = 1;
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);

View File

@ -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);

View File

@ -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,10 +512,15 @@ 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);
@ -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);
@ -1296,11 +1342,17 @@ HOOK_SIG(casey_file_settings)
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)
{