clparams almost done

This commit is contained in:
Allen Webster 2016-02-04 12:00:58 -05:00
parent 8195020bfd
commit 164a18c4a9
7 changed files with 5301 additions and 5205 deletions

146
4ed.cpp
View File

@ -770,32 +770,28 @@ app_push_file_binding(App_Vars *vars, int sys_id, int app_id){
vars->sys_app_bindings[vars->sys_app_count++] = binding;
}
internal File_View*
app_open_file(System_Functions *system, App_Vars *vars, Exchange *exchange,
Live_Views *live_set, Working_Set *working_set, Panel *panel,
Command_Data *command_data, char *filename, int len){
String filename_str;
struct App_Open_File_Result{
Editing_File *file;
b32 is_new;
};
internal App_Open_File_Result
app_open_file_background(App_Vars *vars, Exchange *exchange, Working_Set *working_set, String filename){
Get_File_Result file;
i32 file_id;
File_View *result;
Mem_Options *mem;
Editing_File *target_file = 0;
b32 created_file = 0;
App_Open_File_Result result = {};
filename_str = make_string(filename, len);
mem = &vars->mem;
result = 0;
target_file = working_set_contains(working_set, filename_str);
if (!target_file){
Get_File_Result file = working_set_get_available_file(working_set);
result.file = working_set_contains(working_set, filename);
if (result.file == 0){
file = working_set_get_available_file(working_set);
if (file.file){
file_id = exchange_request_file(exchange, filename, len);
file_id = exchange_request_file(exchange, filename.str, filename.size);
if (file_id){
created_file = 1;
target_file = file.file;
file_set_name(target_file, filename);
file_set_to_loading(target_file);
table_add(&working_set->table, target_file->name.source_path, file.index);
result.is_new = 1;
result.file = file.file;
file_set_name(result.file, filename.str);
file_set_to_loading(result.file);
table_add(&working_set->table, result.file->name.source_path, file.index);
app_push_file_binding(vars, file_id, file.index);
}
@ -805,7 +801,20 @@ app_open_file(System_Functions *system, App_Vars *vars, Exchange *exchange,
}
}
if (target_file){
return(result);
}
internal File_View*
app_open_file(System_Functions *system, App_Vars *vars, Exchange *exchange,
Live_Views *live_set, Working_Set *working_set, Panel *panel,
Command_Data *command_data, String filename){
App_Open_File_Result file;
Mem_Options *mem = &vars->mem;
File_View *result = 0;
file = app_open_file_background(vars, exchange, working_set, filename);
if (file.file){
Style *style = command_data->style;
View *new_view = live_set_alloc_view(live_set, mem);
@ -821,7 +830,7 @@ app_open_file(System_Functions *system, App_Vars *vars, Exchange *exchange,
Temp_Memory temp = begin_temp_memory(&mem->part);
command_data->part = partition_sub_part(&mem->part, Kbytes(16));
view_set_file(system, file_view, target_file, vars->font_set,
view_set_file(system, file_view, file.file, vars->font_set,
style, vars->hooks[hook_open_file], command_data,
&app_links);
@ -829,7 +838,7 @@ app_open_file(System_Functions *system, App_Vars *vars, Exchange *exchange,
end_temp_memory(temp);
command_data->view = old_view;
new_view->map = app_get_map(vars, target_file->settings.base_map_id);
new_view->map = app_get_map(vars, file.file->settings.base_map_id);
}
return(result);
@ -867,7 +876,7 @@ COMMAND_DECL(interactive_open){
String string = make_string(filename, filename_len);
app_open_file(system, vars, exchange,
live_set, working_set, panel,
command, string.str, string.size);
command, string);
}
else{
View *new_view = live_set_alloc_view(live_set, mem);
@ -909,49 +918,6 @@ COMMAND_DECL(reopen){
else{
// TODO(allen): feedback message
}
#if 0
ProfileMomentFunction();
REQ_FILE_VIEW(view);
REQ_FILE(file, view);
USE_STYLE(style);
USE_LAYOUT(layout);
USE_MEM(mem);
USE_VARS(vars);
Editing_File temp_file;
if (file_create(system, mem, &temp_file, make_c_str(file->source_path), style->font)){
file_close(system, &mem->general, file);
*file = temp_file;
file->source_path.str = file->source_path_;
file->live_name.str = file->live_name_;
#if BUFFER_EXPERIMENT_SCALPEL <= 0
if (file->tokens_exist)
file_first_lex_parallel(system, &mem->general, file);
#endif
Partition old_part = command->part;
Temp_Memory temp = begin_temp_memory(&vars->mem.part);
command->part = partition_sub_part(&vars->mem.part, 16 << 10);
view_set_file(system, view, file, style,
vars->hooks[hook_open_file], command, app_links);
command->part = old_part;
end_temp_memory(temp);
i32 panel_count = layout->panel_count;
Panel *panels = layout->panels;
for (i32 i = 0; i < panel_count; ++i){
Panel *current_panel = panels + i;
View *current_view_ = current_panel->view;
File_View *current_view = view_to_file_view(current_view_);
if (current_view && current_view != view && current_view->file == file){
view_set_file(system, current_view, current_view->file, style, 0, command, app_links);
}
}
}
#endif
}
COMMAND_DECL(save){
@ -2540,7 +2506,7 @@ init_command_line_settings(App_Settings *settings, Plat_Settings *plat_settings,
case 'd': action = CLAct_CustomDLL; strict = 0; break;
case 'D': action = CLAct_CustomDLL; strict = 1; break;
case 'l': action = CLAct_InitialFilePosition; break;
case 'i': action = CLAct_InitialFilePosition; break;
case 'w': action = CLAct_WindowSize; break;
case 'W': action = CLAct_WindowMaximize; break;
@ -2634,6 +2600,9 @@ App_Read_Command_Line_Sig(app_read_command_line){
App_Vars *vars = app_setup_memory(memory);
init_command_line_settings(&vars->settings, plat_settings, clparams);
*files = vars->settings.init_files;
*file_count = &vars->settings.init_files_count;
return(output_size);
}
@ -3318,12 +3287,23 @@ App_Step_Sig(app_step){
command_data.part.pos = 0;
}
char *file_name;
i32 i;
for (i = 0; i < vars->settings.init_file_count; ++i){
file_name = vars->settings.init_files[i];
// TODO(allen): open files, do not attach to view
//app_open_file(system, vars, exchange,live_set, working_set, panel,command, string.str, string.size);
String file_name;
Panel *panel = vars->layout.panels;
for (i = 0; i < vars->settings.init_files_count; ++i, ++panel){
file_name = make_string_slowly(vars->settings.init_files[i]);
if (i < vars->layout.panel_count){
app_open_file(system, vars, exchange, &vars->live_set, &vars->working_set, panel,
&command_data, file_name);
if (i == 0){
}
}
else{
app_open_file_background(vars, exchange, &vars->working_set, file_name);
}
}
}
@ -3445,7 +3425,7 @@ App_Step_Sig(app_step){
command_data.view = (View*)
app_open_file(system, vars, exchange,
live_set, working_set, panel,
&command_data, string->str, string->size);
&command_data, *string);
}break;
case DACT_SAVE_AS:
@ -3635,6 +3615,7 @@ App_Step_Sig(app_step){
for (i32 i = 0; i < vars->sys_app_count; ++i){
Sys_App_Binding *binding;
b32 remove = 0;
b32 failed = 0;
binding = vars->sys_app_bindings + i;
byte *data;
@ -3660,13 +3641,22 @@ App_Step_Sig(app_step){
else{
file_create_empty(system, &vars->mem, ed_file, filename,
vars->font_set, vars->style.font_id);
//
i32 panel_count = vars->layout.panel_count;
Panel *current_panel = vars->layout.panels;
for (i32 i = 0; i < panel_count; ++i, ++current_panel){
File_View *current_view = view_to_file_view(current_panel->view);
if (current_view && current_view->file == ed_file){
view_measure_wraps(system, &vars->mem.general, current_view);
}
}
}
exchange_free_file(exchange, binding->sys_id);
remove = 1;
}
if (exchange_file_save_complete(exchange, binding->sys_id, &data, &size, &max)){
if (exchange_file_save_complete(exchange, binding->sys_id, &data, &size, &max, &failed)){
Assert(remove == 0);
if (data){
@ -3681,6 +3671,8 @@ App_Step_Sig(app_step){
exchange_free_file(exchange, binding->sys_id);
remove = 1;
// if (failed) { TODO(allen): saving error, now what? }
}
if (remove){

4
4ed.h
View File

@ -106,7 +106,8 @@ enum File_Exchange_Flag{
FEx_Ready = 0x2,
FEx_Not_Exist = 0x4,
FEx_Save = 0x8,
FEx_Save_Complete = 0x10
FEx_Save_Complete = 0x10,
FEx_Save_Failed = 0x20
};
struct File_Exchange{
@ -140,6 +141,7 @@ struct Plat_Settings{
Application_Memory *memory, \
String current_directory, \
Plat_Settings *plat_settings, \
char ***files, i32 **file_count, \
Command_Line_Parameters clparams \
)

View File

@ -116,6 +116,22 @@ exchange_file_ready(Exchange *exchange, i32 file_id, byte **data, int *size, int
return result;
}
internal b32
exchange_file_does_not_exist(Exchange *exchange, i32 file_id){
File_Exchange *files = &exchange->file;
b32 result = 1;
File_Slot *slot;
if (file_id > 0 && file_id <= files->max){
slot = files->files + file_id - 1;
if (!(slot->flags & FEx_Not_Exist)){
result = 0;
}
}
return result;
}
internal i32
exchange_save_file(Exchange *exchange, char *filename, int len,
byte *data, int size, int max){
@ -140,17 +156,19 @@ exchange_save_file(Exchange *exchange, char *filename, int len,
}
internal b32
exchange_file_save_complete(Exchange *exchange, i32 file_id, byte **data, int *size, int *max){
exchange_file_save_complete(Exchange *exchange, i32 file_id, byte **data, int *size, int *max, int *failed){
File_Exchange *files = &exchange->file;
b32 result = 0;
if (file_id > 0 && file_id <= files->max){
File_Slot *file = files->files + file_id - 1;
if (file->flags & FEx_Save_Complete){
if (file->flags & FEx_Save_Complete || file->flags & FEx_Save_Failed){
*data = file->data;
*size = file->size;
*max = file->max;
result = 1;
*failed = (file->flags & FEx_Save_Complete)?(1):(0);
}
}

View File

@ -415,6 +415,8 @@ hot_directory_first_match(Hot_Directory *hot_directory,
return result;
}
// Single line input
struct Single_Line_Input_Step{
b8 hit_newline;
b8 hit_ctrl_newline;
@ -580,6 +582,8 @@ app_single_number_input_step(System_Functions *system, Key_Codes *codes,
return result;
}
// UI stuff (this shouldn't be here!)
struct Widget_ID{
i32 id;
i32 sub_id0;
@ -1061,6 +1065,8 @@ do_text_field(Widget_ID wid, UI_State *state, UI_Layout *layout,
return result;
}
// Widget
enum File_View_Widget_Type{
FWIDG_NONE,
FWIDG_SEARCH,
@ -1652,6 +1658,15 @@ file_set_to_loading(Editing_File *file){
file->state.is_loading = 1;
}
inline b32
file_is_ready(Editing_File *file){
b32 result = 0;
if (file && file->state.is_loading == 0){
result = 1;
}
return(result);
}
struct Shift_Information{
i32 start, end, amount;
};
@ -2185,8 +2200,9 @@ view_compute_cursor_from_unwrapped_xy(File_View *view, f32 seek_x, f32 seek_y,
Full_Cursor result = {};
if (font){
real32 max_width = view_compute_width(view);
result = buffer_cursor_from_unwrapped_xy(&file->state.buffer, seek_x, seek_y, round_down, view->line_wrap_y,
f32 max_width = view_compute_width(view);
result = buffer_cursor_from_unwrapped_xy(&file->state.buffer, seek_x, seek_y,
round_down, view->line_wrap_y,
max_width, (f32)view->font_height, font->advance_data);
}
@ -2208,7 +2224,8 @@ view_compute_cursor_from_wrapped_xy(File_View *view, f32 seek_x, f32 seek_y,
Full_Cursor result = {};
if (font){
f32 max_width = view_compute_width(view);
result = buffer_cursor_from_wrapped_xy(&file->state.buffer, seek_x, seek_y, round_down, view->line_wrap_y,
result = buffer_cursor_from_wrapped_xy(&file->state.buffer, seek_x, seek_y,
round_down, view->line_wrap_y,
max_width, (f32)view->font_height, font->advance_data);
}
@ -2219,6 +2236,27 @@ view_compute_cursor_from_wrapped_xy(File_View *view, f32 seek_x, f32 seek_y,
#endif
}
inline Full_Cursor
view_compute_cursor_from_line_pos(File_View *view, i32 line, i32 pos){
#if BUFFER_EXPERIMENT_SCALPEL <= 3
Editing_File *file = view->file;
Style *style = view->style;
Render_Font *font = get_font_info(view->font_set, style->font_id)->font;
Full_Cursor result = {};
if (font){
f32 max_width = view_compute_width(view);
result = buffer_cursor_from_line_character(&file->state.buffer, line, pos,
view->line_wrap_y, max_width, (f32)view->font_height, font->advance_data);
}
return result;
#else
return view->cursor;
#endif
}
inline Full_Cursor
view_compute_cursor_from_xy(File_View *view, f32 seek_x, f32 seek_y){
Full_Cursor result;
@ -2383,23 +2421,26 @@ view_cursor_move(File_View *view, Full_Cursor cursor){
inline void
view_cursor_move(File_View *view, i32 pos){
view->cursor = view_compute_cursor_from_pos(view, pos);
view->preferred_x = view_get_cursor_x(view);
view->file->state.cursor_pos = view->cursor.pos;
view->show_temp_highlight = 0;
Full_Cursor cursor = view_compute_cursor_from_pos(view, pos);
view_cursor_move(view, cursor);
}
inline void
view_cursor_move(File_View *view, real32 x, real32 y, bool32 round_down = 0){
view_cursor_move(File_View *view, f32 x, f32 y, b32 round_down = 0){
Full_Cursor cursor;
if (view->unwrapped_lines){
view->cursor = view_compute_cursor_from_unwrapped_xy(view, x, y, round_down);
cursor = view_compute_cursor_from_unwrapped_xy(view, x, y, round_down);
}
else{
view->cursor = view_compute_cursor_from_wrapped_xy(view, x, y, round_down);
cursor = view_compute_cursor_from_wrapped_xy(view, x, y, round_down);
}
view->preferred_x = view_get_cursor_x(view);
view->file->state.cursor_pos = view->cursor.pos;
view->show_temp_highlight = 0;
view_cursor_move(view, cursor);
}
inline void
view_cursor_move(File_View *view, i32 line, i32 pos){
Full_Cursor cursor = view_compute_cursor_from_line_pos(view, line, pos);
view_cursor_move(view, cursor);
}
inline void
@ -2679,8 +2720,8 @@ file_edit_cursor_fix(System_Functions *system,
i32 cursor_max = layout->panel_max_count * 2;
Cursor_With_Index *cursors = push_array(part, Cursor_With_Index, cursor_max);
i32 panel_count = layout->panel_count;
i32 cursor_count = 0;
i32 panel_count = layout->panel_count;
Panel *current_panel = layout->panels;
for (i32 i = 0; i < panel_count; ++i, ++current_panel){
File_View *current_view = view_to_file_view(current_panel->view);
@ -3664,13 +3705,16 @@ view_compute_max_target_y(File_View *view){
internal void
remeasure_file_view(System_Functions *system, View *view_, i32_Rect rect){
File_View *view = (File_View*)view_;
if (file_is_ready(view->file)){
Relative_Scrolling relative = view_get_relative_scrolling(view);
view_measure_wraps(system, &view->view_base.mem->general, view);
view_cursor_move(view, view->cursor.pos);
view->preferred_x = view_get_cursor_x(view);
view_set_relative_scrolling(view, relative);
}
}
// MORE UI STUFF GOD DAMN IT!!!
internal b32
do_button(i32 id, UI_State *state, UI_Layout *layout, char *text, i32 height_mult,
b32 is_toggle = 0, b32 on = 0){

View File

@ -47,6 +47,11 @@ struct Data{
#define globalconst static const
#define DrBegin() switch (s.__pc__){ case 0:;
#define DrEnd() default: Assert(!"Invalid __pc__"); }
#define DrYield(pc, n) { s.__pc__ = pc; *state = s; return(n); case pc:; }
#define DrReturn(n) { s.__pc__ = -1; return(n); }
inline i32
raw_ptr_dif(void *a, void *b) { return (i32)((u8*)a - (u8*)b); }

BIN
vc120.pdb

Binary file not shown.

View File

@ -314,6 +314,21 @@ system_save_file(char *filename, void *data, i32 size){
return 1;
}
internal b32
system_file_can_be_made(char *filename){
HANDLE file;
file = CreateFile((char*)filename, GENERIC_WRITE, 0, 0,
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
if (!file || file == INVALID_HANDLE_VALUE){
return 0;
}
CloseHandle(file);
return 1;
}
internal
Sys_File_Time_Stamp_Sig(system_file_time_stamp){
u64 result;
@ -1423,9 +1438,13 @@ UpdateLoop(LPVOID param){
if (file->flags & FEx_Save){
Assert((file->flags & FEx_Request) == 0);
file->flags &= (~FEx_Save);
system_save_file(file->filename, file->data, file->size);
if (system_save_file(file->filename, file->data, file->size)){
file->flags |= FEx_Save_Complete;
}
else{
file->flags |= FEx_Save_Failed;
}
}
if (file->flags & FEx_Request){
Assert((file->flags & FEx_Save) == 0);
@ -1544,11 +1563,15 @@ WinMain(HINSTANCE hInstance,
clparams.argv = __argv;
clparams.argc = __argc;
char **files;
i32 *file_count;
i32 output_size =
win32vars.app.read_command_line(system,
&memory_vars,
current_directory,
&win32vars.settings,
&files, &file_count,
clparams);
//
@ -1557,6 +1580,18 @@ WinMain(HINSTANCE hInstance,
}
if (output_size != 0) return 0;
{
i32 i, j;
i32 end = *file_count;
for (i = 0, j = 0; i < end; ++i){
if (system_file_can_be_made(files[i])){
files[j] = files[i];
++j;
}
}
*file_count = j;
}
LARGE_INTEGER lpf;
QueryPerformanceFrequency(&lpf);
win32vars.performance_frequency = lpf.QuadPart;