master
Allen Webster 2016-02-28 15:30:51 -05:00
parent 336ef34e89
commit 8256016707
16 changed files with 1528 additions and 1207 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
vc120.pdb
custom_casey.cpp

View File

@ -201,6 +201,25 @@ dynamic_to_bool(Dynamic *dynamic){
return result;
}
typedef struct File_Info{
String filename;
int folder;
} File_Info;
typedef struct File_List{
// Ignore this, it's for internal stuff.
void *block;
// The list of files and folders.
File_Info *infos;
int count;
// Ignore this, it's for internal stuff.
int block_size;
} File_List;
#endif
// BOTTOM

View File

@ -34,26 +34,6 @@ HOOK_SIG(my_start){
exec_command(app, cmdid_change_active_panel);
}
char *get_extension(const char *filename, int len, int *extension_len){
char *c = (char*)(filename + len - 1);
char *end = c;
while (*c != '.' && c > filename) --c;
*extension_len = (int)(end - c);
return c+1;
}
bool str_match(const char *a, int len_a, const char *b, int len_b){
bool result = 0;
if (len_a == len_b){
char *end = (char*)(a + len_a);
while (a < end && *a == *b){
++a; ++b;
}
if (a == end) result = 1;
}
return result;
}
HOOK_SIG(my_file_settings){
Buffer_Summary buffer = app->get_active_buffer(app);
@ -64,16 +44,15 @@ HOOK_SIG(my_file_settings){
// -The name provided to get_buffer_by_name did not match any of the existing buffers
if (buffer.exists){
int treat_as_code = 0;
if (buffer.file_name && buffer.size < (16 << 20)){
int extension_len;
char *extension = get_extension(buffer.file_name, buffer.file_name_len, &extension_len);
if (str_match(extension, extension_len, literal("cpp"))) treat_as_code = 1;
else if (str_match(extension, extension_len, literal("h"))) treat_as_code = 1;
else if (str_match(extension, extension_len, literal("c"))) treat_as_code = 1;
else if (str_match(extension, extension_len, literal("hpp"))) treat_as_code = 1;
String ext = file_extension(make_string(buffer.file_name, buffer.file_name_len));
if (match(ext, make_lit_string("cpp"))) treat_as_code = 1;
else if (match(ext, make_lit_string("h"))) treat_as_code = 1;
else if (match(ext, make_lit_string("c"))) treat_as_code = 1;
else if (match(ext, make_lit_string("hpp"))) treat_as_code = 1;
}
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, (treat_as_code)?((int)my_code_map):((int)mapid_file));
@ -290,7 +269,7 @@ CUSTOM_COMMAND_SIG(switch_to_file_in_quotes){
app->buffer_read_range(app, &buffer, start, end, short_file_name);
copy(&file_name, make_string(buffer.file_name, buffer.file_name_len));
truncate_to_path_of_directory(&file_name);
remove_last_folder(&file_name);
append(&file_name, make_string(short_file_name, size));
exec_command(app, cmdid_change_active_panel);
@ -467,8 +446,9 @@ CUSTOM_COMMAND_SIG(replace_in_range){
pos = range.min;
app->buffer_seek_string(app, &buffer, pos, r.str, r.size, 1, &new_pos);
while (new_pos < range.end){
while (new_pos + r.size < range.end){
app->buffer_replace_range(app, &buffer, new_pos, new_pos + r.size, w.str, w.size);
range = get_range(&view);
pos = new_pos + w.size;
app->buffer_seek_string(app, &buffer, pos, r.str, r.size, 1, &new_pos);
}
@ -533,6 +513,26 @@ CUSTOM_COMMAND_SIG(query_replace){
app->view_set_cursor(app, &view, seek_pos(pos), 1);
}
CUSTOM_COMMAND_SIG(open_all_cpp_and_h){
String dir = push_directory(app);
File_List list = app->get_file_list(app, dir.str, dir.size);
for (int i = 0; i < list.count; ++i){
File_Info *info = list.infos + i;
if (!info->folder){
String extension = file_extension(info->filename);
if (match(extension, make_lit_string("cpp")) ||
match(extension, make_lit_string("hpp")) ||
match(extension, make_lit_string("c")) ||
match(extension, make_lit_string("h"))){
push_parameter(app, par_name, info->filename.str, info->filename.size);
push_parameter(app, par_do_in_background, 1);
exec_command(app, cmdid_interactive_open);
}
}
}
app->free_file_list(app, list);
}
CUSTOM_COMMAND_SIG(open_in_other){
exec_command(app, cmdid_change_active_panel);
exec_command(app, cmdid_interactive_open);
@ -570,7 +570,7 @@ CUSTOM_COMMAND_SIG(build_at_launch_location){
push_parameter(app, par_name, literal("*compilation*"));
push_parameter(app, par_cli_path, literal("."));
push_parameter(app, par_cli_command, literal("build"));
exec_command(app, cmdid_build);
exec_command(app, cmdid_command_line);
}
CUSTOM_COMMAND_SIG(build_search){
@ -602,18 +602,26 @@ CUSTOM_COMMAND_SIG(build_search){
// Step 3: If the batch file did not exist try to move to the parent directory using
// app->directory_cd. The cd function can also be used to navigate to subdirectories.
// It returns true if it can actually move in the specified direction, and false otherwise.
// This doesn't actually change the hot directory of 4coder, it's only effect is to
// modify the string you passed in to reflect the change in directory.
int keep_going = 1;
int old_size;
String dir = push_directory(app);
while (keep_going){
if (app->directory_has_file(app, dir, "build.bat")){
old_size = dir.size;
append(&dir, "build.bat");
if (app->file_exists(app, dir.str, dir.size)){
dir.size = old_size;
push_parameter(app, par_cli_overlap_with_conflict, 0);
push_parameter(app, par_name, literal("*compilation*"));
push_parameter(app, par_cli_path, dir.str, dir.size);
if (append(&dir, "build")){
push_parameter(app, par_cli_command, dir.str, dir.size);
exec_command(app, cmdid_build);
exec_command(app, cmdid_command_line);
}
else{
app->clear_parameters(app);
@ -621,8 +629,9 @@ CUSTOM_COMMAND_SIG(build_search){
return;
}
dir.size = old_size;
if (app->directory_cd(app, &dir, "..") == 0){
if (app->directory_cd(app, dir.str, &dir.size, dir.memory_size, literal("..")) == 0){
keep_going = 0;
}
}
@ -638,7 +647,7 @@ CUSTOM_COMMAND_SIG(write_and_auto_tab){
extern "C" GET_BINDING_DATA(get_bindings){
Bind_Helper context_actual = begin_bind_helper(data, size);
Bind_Helper *context = &context_actual;
// NOTE(allen|a3.1): Right now hooks have no loyalties to maps, all hooks are
// global and once set they always apply, regardless of what map is active.
set_hook(context, hook_start, my_start);
@ -658,11 +667,14 @@ extern "C" GET_BINDING_DATA(get_bindings){
bind(context, 'x', MDFR_ALT, cmdid_open_menu);
bind(context, 'o', MDFR_ALT, open_in_other);
bind(context, 'm', MDFR_ALT, build_search);
bind(context, 'a', MDFR_ALT, open_all_cpp_and_h);
// NOTE(allen): These callbacks may not actually be useful to you, but
// go look at them and see what they do.
bind(context, 'M', MDFR_ALT | MDFR_CTRL, open_my_files);
bind(context, 'M', MDFR_ALT, build_at_launch_location);
bind(context, 'm', MDFR_ALT, build_search);
end_map(context);
@ -693,9 +705,6 @@ extern "C" GET_BINDING_DATA(get_bindings){
bind(context, '\t', MDFR_NONE, cmdid_word_complete);
bind(context, '\t', MDFR_CTRL, cmdid_auto_tab_range);
bind(context, '\t', MDFR_SHIFT, cmdid_auto_tab_line_at_cursor);
bind(context, '\n', MDFR_SHIFT, write_and_auto_tab);
bind(context, ' ', MDFR_SHIFT, cmdid_write_character);
bind(context, '=', MDFR_CTRL, write_increment);
bind(context, '-', MDFR_CTRL, write_decrement);
@ -773,7 +782,11 @@ extern "C" GET_BINDING_DATA(get_bindings){
bind(context, ',', MDFR_ALT, switch_to_compilation);
bind(context, '\n', MDFR_SHIFT, write_and_auto_tab);
bind(context, ' ', MDFR_SHIFT, cmdid_write_character);
end_map(context);
end_bind_helper(context);
return context->write_total;

View File

@ -22,10 +22,7 @@ enum Command_ID{
cmdid_seek_alphanumeric_right,
cmdid_seek_alphanumeric_or_camel_left,
cmdid_seek_alphanumeric_or_camel_right,
//cmdid_search,
//cmdid_reverse_search,
cmdid_word_complete,
//cmdid_goto_line,
cmdid_set_mark,
cmdid_copy,
cmdid_cut,
@ -75,7 +72,7 @@ enum Command_ID{
cmdid_cursor_mark_swap,
cmdid_open_menu,
cmdid_set_settings,
cmdid_build,
cmdid_command_line,
//
cmdid_count
};
@ -84,6 +81,8 @@ enum Param_ID{
par_range_start,
par_range_end,
par_name,
par_buffer_id,
par_do_in_background,
par_lex_as_cpp_file,
par_wrap_lines,
par_key_mapid,
@ -156,7 +155,6 @@ struct Query_Bar{
};
#define GET_BINDING_DATA(name) int name(void *data, int size)
#define SET_EXTRA_FONT_SIG(name) void name(Extra_Font *font_out)
#define CUSTOM_COMMAND_SIG(name) void name(struct Application_Links *app)
#define HOOK_SIG(name) void name(struct Application_Links *app)
@ -175,9 +173,11 @@ struct Application_Links;
#define CLEAR_PARAMETERS_SIG(name) void name(Application_Links *context)
// File system navigation
#define DIRECTORY_GET_HOT_SIG(name) int name(Application_Links *context, char *buffer, int max)
#define DIRECTORY_HAS_FILE_SIG(name) int name(Application_Links *context, String dir, char *filename)
#define DIRECTORY_CD_SIG(name) int name(Application_Links *context, String *dir, char *rel_path)
#define DIRECTORY_GET_HOT_SIG(name) int name(Application_Links *context, char *out, int capacity)
#define FILE_EXISTS_SIG(name) int name(Application_Links *context, char *filename, int len)
#define DIRECTORY_CD_SIG(name) int name(Application_Links *context, char *dir, int *len, int capacity, char *rel_path, int rel_len)
#define GET_FILE_LIST_SIG(name) File_List name(Application_Links *context, char *dir, int len)
#define FREE_FILE_LIST_SIG(name) void name(Application_Links *context, File_List list)
// Direct buffer manipulation
#define GET_BUFFER_MAX_INDEX_SIG(name) int name(Application_Links *context)
@ -190,7 +190,6 @@ struct Application_Links;
#define BUFFER_SEEK_STRING_SIG(name) int name(Application_Links *context, Buffer_Summary *buffer, int start, char *str, int len, int seek_forward, int *out)
#define BUFFER_READ_RANGE_SIG(name) int name(Application_Links *context, Buffer_Summary *buffer, int start, int end, char *out)
#define BUFFER_REPLACE_RANGE_SIG(name) int name(Application_Links *context, Buffer_Summary *buffer, int start, int end, char *str, int len)
#define BUFFER_SAVE_SIG(name) int name(Application_Links *context, Buffer_Summary *buffer, char *filename, int len)
// File view manipulation
#define GET_VIEW_MAX_INDEX_SIG(name) int name(Application_Links *context)
@ -216,9 +215,6 @@ struct Application_Links;
#define GET_USER_INPUT_SIG(name) User_Input name(Application_Links *context, unsigned int get_type, unsigned int abort_type)
// Queries
#define QueryEffectImmediate 0x0
#define QueryEffectSmooth 0x1
#define START_QUERY_BAR_SIG(name) int name(Application_Links *context, Query_Bar *bar, unsigned int flags)
#define END_QUERY_BAR_SIG(name) void name(Application_Links *context, Query_Bar *bar, unsigned int flags)
@ -230,9 +226,11 @@ extern "C"{
typedef CLEAR_PARAMETERS_SIG(Clear_Parameters_Function);
// File system navigation
typedef DIRECTORY_GET_HOT_SIG(Directory_Get_Hot);
typedef DIRECTORY_HAS_FILE_SIG(Directory_Has_File);
typedef DIRECTORY_CD_SIG(Directory_CD);
typedef DIRECTORY_GET_HOT_SIG(Directory_Get_Hot_Function);
typedef FILE_EXISTS_SIG(File_Exists_Function);
typedef DIRECTORY_CD_SIG(Directory_CD_Function);
typedef GET_FILE_LIST_SIG(Get_File_List_Function);
typedef FREE_FILE_LIST_SIG(Free_File_List_Function);
// Buffer manipulation
typedef GET_BUFFER_MAX_INDEX_SIG(Get_Buffer_Max_Index_Function);
@ -245,7 +243,6 @@ extern "C"{
typedef BUFFER_SEEK_STRING_SIG(Buffer_Seek_String_Function);
typedef BUFFER_READ_RANGE_SIG(Buffer_Read_Range_Function);
typedef BUFFER_REPLACE_RANGE_SIG(Buffer_Replace_Range_Function);
typedef BUFFER_SAVE_SIG(Buffer_Save_Function);
// View manipulation
typedef GET_VIEW_MAX_INDEX_SIG(Get_View_Max_Index_Function);
@ -267,8 +264,9 @@ extern "C"{
}
struct Application_Links{
// Application data ptr
// User data
void *data;
int size;
// Command exectuion
Exec_Command_Function *exec_command_keep_stack;
@ -277,9 +275,11 @@ struct Application_Links{
Clear_Parameters_Function *clear_parameters;
// File system navigation
Directory_Get_Hot *directory_get_hot;
Directory_Has_File *directory_has_file;
Directory_CD *directory_cd;
Directory_Get_Hot_Function *directory_get_hot;
File_Exists_Function *file_exists;
Directory_CD_Function *directory_cd;
Get_File_List_Function *get_file_list;
Free_File_List_Function *free_file_list;
// Buffer manipulation
Get_Buffer_Max_Index_Function *get_buffer_max_index;
@ -292,7 +292,6 @@ struct Application_Links{
Buffer_Seek_String_Function *buffer_seek_string;
Buffer_Read_Range_Function *buffer_read_range;
Buffer_Replace_Range_Function *buffer_replace_range;
Buffer_Save_Function *buffer_save;
// View manipulation
Get_View_Max_Index_Function *get_view_max_index;
@ -311,6 +310,9 @@ struct Application_Links{
// Queries
Start_Query_Bar_Function *start_query_bar;
End_Query_Bar_Function *end_query_bar;
// Internal
void *cmd_context;
};
struct Custom_API{

View File

@ -175,12 +175,13 @@ FCPP_LINK int reverse_seek_slash(String str);
FCPP_LINK int reverse_seek_slash(String str, int start_pos);
inline bool get_front_of_directory(String *dest, String dir) { return append_checked(dest, substr(dir, reverse_seek_slash(dir) + 1)); }
inline bool get_path_of_directory(String *dest, String dir) { return append_checked(dest, substr(dir, 0, reverse_seek_slash(dir) + 1)); }
inline void truncate_to_path_of_directory(String *dir) { dir->size = reverse_seek_slash(*dir) + 1; }
FCPP_LINK bool set_last_folder(String *dir, char *folder_name, char slash);
FCPP_LINK bool set_last_folder(String *dir, String folder_name, char slash);
FCPP_LINK String file_extension(String str);
FCPP_LINK String file_extension_slowly(char *str);
FCPP_LINK char * file_extension_c(String str);
FCPP_LINK bool remove_last_folder(String *str);
FCPP_LINK void replace_char(String str, char replace, char with);
inline String make_string(char *str, int size, int mem_size){
String result;
@ -1043,6 +1044,16 @@ file_extension_slowly(char *str){
return make_string(str+i, s-i);
}
FCPP_LINK char*
file_extension_c(String str){
int i;
for (i = str.size - 1; i >= 0; --i){
if (str.str[i] == '.') break;
}
++i;
return str.str+i;
}
FCPP_LINK bool
remove_last_folder(String *str){
bool result = 0;
@ -1054,11 +1065,21 @@ remove_last_folder(String *str){
return(result);
}
FCPP_LINK void
replace_char(String str, char replace, char with){
char *s = str.str;
int i;
for (i = 0; i < str.size; ++i, ++s){
if (*s == replace) *s = with;
}
}
// NOTE(allen): experimental section, things below here are
// not promoted to public API level yet.
#ifndef ArrayCount
#define ArrayCount(a) ((sizeof(a))/sizeof(a))
#define ArrayCount(a) ((sizeof(a))/sizeof(*a))
#endif
struct Absolutes{

2207
4ed.cpp

File diff suppressed because it is too large Load Diff

2
4ed.h
View File

@ -17,6 +17,8 @@ struct Application_Memory{
i32 vars_memory_size;
void *target_memory;
i32 target_memory_size;
void *user_memory;
i32 user_memory_size;
};
#define KEY_INPUT_BUFFER_SIZE 4

View File

@ -1510,7 +1510,7 @@ do_file_list_box(System_Functions *system, UI_State *state, UI_Layout *layout,
b8 is_folder = (info->folder != 0);
b8 ext_match = (match(file_extension(filename), p4c_extension) != 0);
b8 name_match = (filename_match(front_name, &absolutes, filename, case_sensitive) != 0);
b8 is_loaded = (file != 0);
b8 is_loaded = (file != 0 && file_is_ready(file));
String message = message_nothing;
if (is_loaded){

View File

@ -1,5 +1,7 @@
enum Action_Type{
DACT_OPEN,
DACT_OPEN_BACKGROUND,
DACT_SET_LINE,
DACT_SAVE_AS,
DACT_SAVE,
DACT_NEW,
@ -17,18 +19,33 @@ struct Delayed_Action{
String string;
Panel* panel;
Editing_File* file;
i32 integer;
};
struct Delay{
General_Memory* general;
Delayed_Action* acts;
i32 count;
i32 max;
};
internal String
str_alloc_copy(General_Memory *general, String str){
String result;
result.memory_size = str.memory_size + 1;
result.size = str.size;
result.str = (char*)general_memory_allocate(general, result.memory_size, 0);
memcpy(result.str, str.str, str.size);
result.str[result.size] = 0;
return(result);}
inline Delayed_Action*
delayed_action_(Delay *delay, Action_Type type){
Delayed_Action *result;
Assert(delay->count < delay->max);
if (delay->count == delay->max){
delay->max *= 2;
delay->acts = (Delayed_Action*)general_memory_reallocate(delay->general, delay->acts, delay->count*sizeof(Delayed_Action), delay->max*sizeof(Delayed_Action), 0);
}
result = delay->acts + delay->count++;
*result = {};
result->type = type;
@ -43,11 +60,19 @@ delayed_action_(Delay *delay, Action_Type type, Panel* panel){
return(result);
}
inline Delayed_Action*
delayed_action_(Delay *delay, Action_Type type, String string){
Delayed_Action *result;
result = delayed_action_(delay, type);
result->string = str_alloc_copy(delay->general, string);
return(result);
}
inline Delayed_Action*
delayed_action_(Delay *delay, Action_Type type, String string, Panel* panel){
Delayed_Action *result;
result = delayed_action_(delay, type);
result->string = string;
result->string = str_alloc_copy(delay->general, string);
result->panel = panel;
return(result);
}
@ -56,12 +81,33 @@ inline Delayed_Action*
delayed_action_(Delay *delay, Action_Type type, String string, Editing_File* file){
Delayed_Action *result;
result = delayed_action_(delay, type);
result->string = string;
result->string = str_alloc_copy(delay->general, string);
result->file = file;
return(result);
}
inline Delayed_Action*
delayed_action_(Delay *delay, Action_Type type, Panel* panel, i32 integer){
Delayed_Action *result;
result = delayed_action_(delay, type);
result->panel = panel;
result->integer = integer;
return(result);
}
inline Delayed_Action*
delayed_action_repush(Delay *delay, Delayed_Action *act){
Delayed_Action *new_act = delayed_action_(delay, (Action_Type)0);
*new_act = *act;
if (act->string.str){
new_act->string = str_alloc_copy(delay->general, act->string);
}
return(new_act);
}
#define delayed_open(delay, ...) delayed_action_(delay, DACT_OPEN, __VA_ARGS__)
#define delayed_open_background(delay, ...) delayed_action_(delay, DACT_OPEN_BACKGROUND, __VA_ARGS__)
#define delayed_set_line(delay, ...) delayed_action_(delay, DACT_SET_LINE, __VA_ARGS__)
#define delayed_save_as(delay, ...) delayed_action_(delay, DACT_SAVE_AS, __VA_ARGS__)
#define delayed_save(delay, ...) delayed_action_(delay, DACT_SAVE, __VA_ARGS__)
#define delayed_new(delay, ...) delayed_action_(delay, DACT_NEW, __VA_ARGS__)

View File

@ -198,7 +198,6 @@ exchange_free_file(Exchange *exchange, i32 file_id){
ex__file_remove(file);
ex__file_insert(&files->free_list, file);
ex__check(files);
--files->num_active;
}
}

View File

@ -31,8 +31,8 @@ struct File_View_Widget{
File_View_Widget_Type type;
i32 height;
struct{
bool32 undo_line;
bool32 history_line;
b32 undo_line;
b32 history_line;
} timeline;
};
@ -208,36 +208,33 @@ file_save(System_Functions *system, Exchange *exchange, Mem_Options *mem,
Editing_File *file, char *filename){
i32 result = 0;
#if BUFFER_EXPERIMENT_SCALPEL <= 3
i32 max, size;
byte *data;
b32 dos_write_mode = file->settings.dos_write_mode;
if (dos_write_mode)
max = buffer_size(&file->state.buffer) + file->state.buffer.line_count + 1;
else
max = buffer_size(&file->state.buffer);
char *data;
Buffer_Type *buffer = &file->state.buffer;
data = (byte*)general_memory_allocate(&mem->general, max, 0);
if (dos_write_mode)
max = buffer_size(buffer) + buffer->line_count + 1;
else
max = buffer_size(buffer);
data = (char*)general_memory_allocate(&mem->general, max, 0);
Assert(data);
if (dos_write_mode)
size = buffer_convert_out(&file->state.buffer, (char*)data, max);
size = buffer_convert_out(buffer, data, max);
else
buffer_stringify(&file->state.buffer, 0, size = max, (char*)data);
buffer_stringify(buffer, 0, size = max, data);
i32 filename_len = str_size(filename);
result = exchange_save_file(exchange, filename, filename_len,
data, size, max);
result = exchange_save_file(exchange, filename, str_size(filename), (byte*)data, size, max);
if (result == 0){
general_memory_free(&mem->general, data);
}
file_synchronize_times(system, file, filename);
#endif
return result;
return(result);
}
inline b32
@ -270,28 +267,41 @@ enum File_Bubble_Type{
#define GROW_SUCCESS 2
internal i32
file_grow_starts_as_needed(General_Memory *general, Buffer_Type *buffer, i32 additional_lines){
bool32 result = GROW_NOT_NEEDED;
#if BUFFER_EXPERIMENT_SCALPEL <= 3
file_grow_starts_widths_as_needed(General_Memory *general, Buffer_Type *buffer, i32 additional_lines){
b32 result = GROW_NOT_NEEDED;
i32 max = buffer->line_max;
i32 count = buffer->line_count;
i32 target_lines = count + additional_lines;
Assert(max == buffer->widths_max);
if (target_lines > max || max == 0){
max = LargeRoundUp(target_lines + max, Kbytes(1));
i32 *new_lines = (i32*)
general_memory_reallocate(general, buffer->line_starts,
sizeof(i32)*count, sizeof(i32)*max, BUBBLE_STARTS);
f32 *new_widths = (f32*)general_memory_reallocate(
general, buffer->line_widths,
sizeof(f32)*count, sizeof(f32)*max, BUBBLE_WIDTHS);
i32 *new_lines = (i32*)general_memory_reallocate(
general, buffer->line_starts,
sizeof(i32)*count, sizeof(i32)*max, BUBBLE_STARTS);
if (new_lines){
buffer->line_starts = new_lines;
buffer->line_max = max;
}
if (new_widths){
buffer->line_widths = new_widths;
buffer->widths_max = max;
}
if (new_lines && new_widths){
result = GROW_SUCCESS;
}
else{
result = GROW_FAILED;
}
}
#endif
return result;
return(result);
}
internal void
@ -345,16 +355,14 @@ file_measure_starts_widths(System_Functions *system, General_Memory *general,
}
internal void
file_remeasure_starts(System_Functions *system,
file_remeasure_starts_(System_Functions *system,
General_Memory *general, Buffer_Type *buffer,
i32 line_start, i32 line_end, i32 line_shift,
i32 character_shift){
#if BUFFER_EXPERIMENT_SCALPEL <= 3
ProfileMomentFunction();
Assert(buffer->line_starts);
file_grow_starts_as_needed(general, buffer, line_shift);
file_grow_starts_widths_as_needed(general, buffer, line_shift);
buffer_remeasure_starts(buffer, line_start, line_end, line_shift, character_shift);
#endif
}
struct Opaque_Font_Advance{
@ -370,9 +378,9 @@ get_opaque_font_advance(Render_Font *font){
return result;
}
#if 0
internal void
file_grow_widths_as_needed(General_Memory *general, Buffer_Type *buffer){
#if BUFFER_EXPERIMENT_SCALPEL <= 3
i32 line_count = buffer->line_count;
if (line_count > buffer->widths_max || buffer->widths_max == 0){
i32 new_max = LargeRoundUp(line_count, Kbytes(1));
@ -388,18 +396,16 @@ file_grow_widths_as_needed(General_Memory *general, Buffer_Type *buffer){
}
buffer->widths_max = new_max;
}
#endif
}
#endif
internal void
file_remeasure_widths(System_Functions *system,
file_remeasure_widths_(System_Functions *system,
General_Memory *general, Buffer_Type *buffer, Render_Font *font,
i32 line_start, i32 line_end, i32 line_shift){
#if BUFFER_EXPERIMENT_SCALPEL <= 3
ProfileMomentFunction();
file_grow_widths_as_needed(general, buffer);
file_grow_starts_widths_as_needed(general, buffer, line_shift);
buffer_remeasure_widths(buffer, font->advance_data, line_start, line_end, line_shift);
#endif
}
inline i32
@ -1806,20 +1812,18 @@ file_do_single_edit(System_Functions *system,
if (old_data) general_memory_free(general, old_data);
}
Buffer_Type *buffer = &file->state.buffer;
i32 line_start = buffer_get_line_index(&file->state.buffer, start);
i32 line_end = buffer_get_line_index(&file->state.buffer, end);
i32 replaced_line_count = line_end - line_start;
i32 new_line_count = buffer_count_newlines(&file->state.buffer, start, start+str_len);
i32 line_shift = new_line_count - replaced_line_count;
file_remeasure_starts(system, general, &file->state.buffer,
line_start, line_end, line_shift, shift_amount);
Render_Font *font = get_font_info(file->settings.set, file->state.font_id)->font;
if (font){
file_remeasure_widths(system, general, &file->state.buffer,
font, line_start, line_end, line_shift);
}
file_grow_starts_widths_as_needed(general, buffer, line_shift);
buffer_remeasure_starts(buffer, line_start, line_end, line_shift, shift_amount);
buffer_remeasure_widths(buffer, font->advance_data, line_start, line_end, line_shift);
i32 panel_count = layout->panel_count;
Panel *current_panel = layout->panels;
@ -2276,13 +2280,11 @@ working_set_lookup_file(Working_Set *working_set, String string){
internal void
clipboard_copy(System_Functions *system, General_Memory *general, Working_Set *working, Range range, Editing_File *file){
#if BUFFER_EXPERIMENT_SCALPEL <= 3
i32 size = range.end - range.start;
String *dest = working_set_next_clipboard_string(general, working, size);
buffer_stringify(&file->state.buffer, range.start, range.end, dest->str);
dest->size = size;
system->post_clipboard(*dest);
#endif
}
internal Edit_Spec
@ -2290,7 +2292,6 @@ file_compute_whitespace_edit(Mem_Options *mem, Editing_File *file, i32 cursor_po
Buffer_Edit *edits, char *str_base, i32 str_size,
Buffer_Edit *inverse_array, char *inv_str, i32 inv_max,
i32 edit_count){
#if BUFFER_EXPERIMENT_SCALPEL <= 3
General_Memory *general = &mem->general;
i32 inv_str_pos = 0;
@ -2315,16 +2316,12 @@ file_compute_whitespace_edit(Mem_Options *mem, Editing_File *file, i32 cursor_po
spec.step.inverse_child_count = edit_count;
spec.step.pre_pos = cursor_pos;
spec.step.post_pos = cursor_pos;
#else
Edit_Spec spec = {};
#endif
return spec;
}
internal void
view_clean_whitespace(System_Functions *system, Mem_Options *mem, File_View *view, Editing_Layout *layout){
#if BUFFER_EXPERIMENT_SCALPEL <= 3
Editing_File *file = view->file;
Assert(file && !file->state.is_dummy);
Partition *part = &mem->part;
@ -2378,7 +2375,6 @@ view_clean_whitespace(System_Functions *system, Mem_Options *mem, File_View *vie
}
end_temp_memory(temp);
#endif
}
internal void
@ -3294,7 +3290,8 @@ command_reverse_search(System_Functions*,Command_Data*,Command_Binding);
inline void
free_file_view(View *view){
File_View *fview = (File_View*)view;
general_memory_free(&view->mem->general, fview->line_wrap_y);
if (fview->line_wrap_y)
general_memory_free(&view->mem->general, fview->line_wrap_y);
if (fview->links)
general_memory_free(&view->mem->general, fview->links);
}

View File

@ -34,6 +34,7 @@ struct Interactive_View{
UI_State state;
Interactive_View_Interaction interaction;
Interactive_View_Action action;
int finished;
char query_[256];
String query;
@ -98,8 +99,9 @@ interactive_view_complete(Interactive_View *view){
internal i32
step_draw_int_view(System_Functions *system, Interactive_View *view,
Render_Target *target, i32_Rect rect,
Input_Summary *user_input, b32 input_stage){
Render_Target *target, i32_Rect rect,
Input_Summary *user_input, b32 input_stage){
if (view->finished) return 0;
i32 result = 0;
UI_State state =
@ -182,6 +184,7 @@ step_draw_int_view(System_Functions *system, Interactive_View *view,
}
if (complete){
view->finished = 1;
interactive_view_complete(view);
}
@ -222,6 +225,7 @@ interactive_view_init(System_Functions *system, View *view,
result->working_set = working_set;
result->font_set = font_set;
result->delay = delay;
result->finished = 0;
return result;
}

View File

@ -112,6 +112,8 @@ char* generate_keycode_enum(){
char daction_enum_name[] = "Action_Type";
char *daction_enum[] = {
"OPEN",
"OPEN_BACKGROUND",
"SET_LINE",
"SAVE_AS",
"SAVE",
"NEW",
@ -124,6 +126,18 @@ char *daction_enum[] = {
"KEYBOARD_OPTIONS"
};
char str_alloc_copy[] =
"internal String\n"
"str_alloc_copy(General_Memory *general, String str){\n"
" String result;\n"
" result.memory_size = str.memory_size + 1;\n"
" result.size = str.size;\n"
" result.str = (char*)general_memory_allocate(general, result.memory_size, 0);\n"
" memcpy(result.str, str.str, str.size);\n"
" result.str[result.size] = 0;\n"
" return(result);"
"}\n\n";
char daction_name[] = "Delayed_Action";
Struct_Field daction_fields[] = {
{"Action_Type", "type"},
@ -132,27 +146,31 @@ Struct_Field daction_fields_primary[] = {
{"String", "string"},
{"Panel*", "panel"},
{"Editing_File*", "file"},
{"i32", "integer"},
};
enum Daction_Field_Handle{
dfph_null,
dfph_string,
dfph_panel,
dfph_file,
dfph_integer,
};
Daction_Field_Handle dact_param_sets[] = {
dfph_panel, dfph_null,
dfph_string, dfph_null,
dfph_string, dfph_panel, dfph_null,
dfph_string, dfph_file, dfph_null
dfph_string, dfph_file, dfph_null,
dfph_panel, dfph_integer, dfph_null,
};
char delay_name[] = "Delay";
Struct_Field delay_fields[] = {
{"General_Memory*", "general"},
{"Delayed_Action*", "acts"},
{"i32", "count"},
{"i32", "max"},
};
// TODO(allen): Make delay buffer expandable (general memory probably)
char delayed_action_function_top[] =
"inline Delayed_Action*\n"
"delayed_action_(Delay *delay, Action_Type type";
@ -160,7 +178,11 @@ char delayed_action_function_top[] =
char delayed_action_function_bottom[] =
"){\n"
" Delayed_Action *result;\n"
" Assert(delay->count < delay->max);\n"
" if (delay->count == delay->max){\n"
" delay->max *= 2;\n"
" delay->acts = (Delayed_Action*)general_memory_reallocate("
"delay->general, delay->acts, delay->count*sizeof(Delayed_Action), delay->max*sizeof(Delayed_Action), 0);\n"
" }\n"
" result = delay->acts + delay->count++;\n"
" *result = {};\n"
" result->type = type;\n"
@ -177,6 +199,9 @@ char delayed_action_specialized_middle[] =
char delayed_action_special_line[] =
" result->%s = %s;\n";
char delayed_action_special_string_line[] =
" result->%s = str_alloc_copy(delay->general, %s);\n";
char delayed_action_specialized_bottom[] =
" return(result);\n"
"}\n\n";
@ -184,6 +209,17 @@ char delayed_action_specialized_bottom[] =
char delayed_action_macro[] =
"#define delayed_%s(delay, ...) delayed_action_(delay, DACT_%s, __VA_ARGS__)\n";
char delayed_action_repush_function[] =
"inline Delayed_Action*\n"
"delayed_action_repush(Delay *delay, Delayed_Action *act){\n"
" Delayed_Action *new_act = delayed_action_(delay, (Action_Type)0);\n"
" *new_act = *act;\n"
" if (act->string.str){\n"
" new_act->string = str_alloc_copy(delay->general, act->string);\n"
" }\n"
" return(new_act);\n"
"}\n\n";
char* generate_delayed_action(){
FILE *file;
char *filename = "4ed_delay.cpp";
@ -207,6 +243,7 @@ char* generate_delayed_action(){
struct_fields(file, delay_fields, ArrayCount(delay_fields));
struct_end(file);
fprintf(file, "%s", str_alloc_copy);
fprintf(file, "%s%s", delayed_action_function_top, delayed_action_function_bottom);
for (i = 0; i < ArrayCount(dact_param_sets); ++i){
@ -218,12 +255,20 @@ char* generate_delayed_action(){
}
fprintf(file, "%s", delayed_action_specialized_middle);
for (; dact_param_sets[j] != dfph_null; ++j){
Struct_Field field = daction_fields_primary[dact_param_sets[j] - 1];
fprintf(file, delayed_action_special_line, field.name, field.name);
int handle = (int)(dact_param_sets[j]);
Struct_Field field = daction_fields_primary[handle - 1];
if (handle == dfph_string){
fprintf(file, delayed_action_special_string_line, field.name, field.name);
}
else{
fprintf(file, delayed_action_special_line, field.name, field.name);
}
}
fprintf(file, "%s", delayed_action_specialized_bottom);
}
fprintf(file, "%s", delayed_action_repush_function);
for (i = 0; i < ArrayCount(daction_enum); ++i){
to_lower(daction_enum[i], scratch);
fprintf(file, delayed_action_macro, scratch, daction_enum[i]);

View File

@ -13,17 +13,6 @@ struct Plat_Handle{
u32 d[4];
};
struct File_Info{
String filename;
b32 folder;
};
struct File_List{
void *block;
File_Info *infos;
i32 count, block_size;
};
#define Sys_File_Time_Stamp_Sig(name) u64 name(char *filename)
typedef Sys_File_Time_Stamp_Sig(System_File_Time_Stamp);
@ -187,8 +176,8 @@ struct System_Functions{
System_Set_File_List *set_file_list;
// file system navigation (4coder_custom.h): 2
Directory_Has_File *directory_has_file;
Directory_CD *directory_cd;
File_Exists_Function *file_exists;
Directory_CD_Function *directory_cd;
// clipboard: 1
System_Post_Clipboard *post_clipboard;

View File

@ -120,7 +120,7 @@ buffer_reverse_seek_delimiter(Buffer_Type *buffer, int pos, char delim){
buffer_backify_next(&loop)){
end = loop.size + loop.absolute_pos;
data = loop.data - loop.absolute_pos;
for (; pos > 0; --pos){
for (; pos >= 0; --pos){
if (data[pos] == delim) goto double_break;
}
}

View File

@ -24,6 +24,8 @@
#include "4ed_dll_reader.h"
#include <stdlib.h>
#include "4coder_custom.cpp"
#undef exec_command
@ -261,7 +263,17 @@ internal Data
system_load_file(char *filename){
Data result = {};
HANDLE file;
file = CreateFile((char*)filename, GENERIC_READ, 0, 0,
String fname_str = make_string_slowly(filename);
if (fname_str.size >= 1024) return result;
char fixed_space[1024];
String fixed_str = make_fixed_width_string(fixed_space);
copy(&fixed_str, fname_str);
terminate_with_null(&fixed_str);
replace_char(fixed_str, '/', '\\');
file = CreateFile((char*)fixed_str.str, GENERIC_READ, 0, 0,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
if (!file || file == INVALID_HANDLE_VALUE){
return result;
@ -397,8 +409,9 @@ Sys_Set_File_List_Sig(system_set_file_list){
i32 required_size = count + file_count * sizeof(File_Info);
if (file_list->block_size < required_size){
Win32FreeMemory(file_list->block);
Win32FreeMemory(file_list->block);
file_list->block = Win32GetMemory(required_size);
file_list->block_size = required_size;
}
file_list->infos = (File_Info*)file_list->block;
@ -436,37 +449,32 @@ Sys_Set_File_List_Sig(system_set_file_list){
}
}
}
else{
Win32FreeMemory(file_list->block);
}
}
internal
DIRECTORY_HAS_FILE_SIG(system_directory_has_file){
char *full_filename;
char space[1024];
FILE_EXISTS_SIG(system_file_exists){
char full_filename_space[1024];
String full_filename;
HANDLE file;
b32 result;
i32 len;
full_filename = 0;
len = str_size(filename);
if (dir.memory_size - dir.size - 1 >= len){
full_filename = dir.str;
memcpy(dir.str + dir.size, filename, len + 1);
}
else if (dir.size + len + 1 < 1024){
full_filename = space;
memcpy(full_filename, dir.str, dir.size);
memcpy(full_filename + dir.size, filename, len + 1);
}
result = 0;
if (full_filename){
file = CreateFile((char*)full_filename, GENERIC_READ, 0, 0,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
if (len < sizeof(full_filename_space)){
full_filename = make_fixed_width_string(full_filename_space);
copy(&full_filename, make_string(filename, len));
terminate_with_null(&full_filename);
file = CreateFile(full_filename.str, GENERIC_READ, 0, 0,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
if (file != INVALID_HANDLE_VALUE){
CloseHandle(file);
result = 1;
}
dir.str[dir.size] = 0;
}
return(result);
@ -480,34 +488,35 @@ b32 Win32DirectoryExists(char *path){
internal
DIRECTORY_CD_SIG(system_directory_cd){
String directory = make_string(dir, *len, capacity);
b32 result = 0;
i32 old_size;
i32 len;
if (rel_path[0] != 0){
if (rel_path[0] == '.' && rel_path[1] == 0){
result = 1;
}
else if (rel_path[0] == '.' && rel_path[1] == '.' && rel_path[2] == 0){
result = remove_last_folder(dir);
terminate_with_null(dir);
result = remove_last_folder(&directory);
terminate_with_null(&directory);
}
else{
len = str_size(rel_path);
if (dir->size + len + 1 > dir->memory_size){
old_size = dir->size;
append_partial(dir, rel_path);
append_partial(dir, "\\");
if (Win32DirectoryExists(dir->str)){
if (directory.size + rel_len + 1 > directory.memory_size){
old_size = directory.size;
append_partial(&directory, rel_path);
append_partial(&directory, "\\");
if (Win32DirectoryExists(directory.str)){
result = 1;
}
else{
dir->size = old_size;
directory.size = old_size;
}
}
}
}
*len = directory.size;
return(result);
}
@ -975,7 +984,7 @@ Sys_To_Binary_Path(system_to_binary_path){
i32 size = GetModuleFileName(0, out_filename->str, max);
if (size > 0 && size < max-1){
out_filename->size = size;
truncate_to_path_of_directory(out_filename);
remove_last_folder(out_filename);
if (append(out_filename, filename) && terminate_with_null(out_filename)){
translate_success = 1;
}
@ -1047,7 +1056,7 @@ Win32LoadSystemCode(){
win32vars.system->file_time_stamp = system_file_time_stamp;
win32vars.system->set_file_list = system_set_file_list;
win32vars.system->directory_has_file = system_directory_has_file;
win32vars.system->file_exists = system_file_exists;
win32vars.system->directory_cd = system_directory_cd;
win32vars.system->post_clipboard = system_post_clipboard;
@ -1555,20 +1564,23 @@ UpdateLoop(LPVOID param){
}
}
}
Assert(d == exchange_vars.file.num_active);
int free_list_count = 0;
for (file = exchange_vars.file.free_list.next;
file != &exchange_vars.file.free_list;
file = file->next){
file != &exchange_vars.file.free_list;
file = file->next){
++free_list_count;
if (file->data){
system_free_memory(file->data);
}
}
if (exchange_vars.file.free_list.next != &exchange_vars.file.free_list){
Assert(free_list_count != 0);
ex__insert_range(exchange_vars.file.free_list.next, exchange_vars.file.free_list.prev,
&exchange_vars.file.available);
&exchange_vars.file.available);
exchange_vars.file.num_active -= free_list_count;
}
ex__check(&exchange_vars.file);
@ -1633,19 +1645,19 @@ main(int argc, char **argv){
for (i32 i = 0; i+1 < ArrayCount(win32vars.coroutine_data); ++i){
win32vars.coroutine_data[i].next = win32vars.coroutine_data + i + 1;
}
LPVOID base;
#if FRED_INTERNAL
base = (LPVOID)Tbytes(1);
#else
base = (LPVOID)0;
#endif
memory_vars.vars_memory_size = Mbytes(2);
memory_vars.vars_memory_size = Mbytes(2);
memory_vars.vars_memory = VirtualAlloc(base, memory_vars.vars_memory_size,
MEM_COMMIT | MEM_RESERVE,
PAGE_READWRITE);
MEM_COMMIT | MEM_RESERVE,
PAGE_READWRITE);
#if FRED_INTERNAL
base = (LPVOID)Tbytes(2);
#else
@ -1653,6 +1665,12 @@ main(int argc, char **argv){
#endif
memory_vars.target_memory_size = Mbytes(512);
memory_vars.target_memory = VirtualAlloc(base, memory_vars.target_memory_size,
MEM_COMMIT | MEM_RESERVE,
PAGE_READWRITE);
base = (LPVOID)0;
memory_vars.user_memory_size = Mbytes(2);
memory_vars.user_memory = VirtualAlloc(base, memory_vars.target_memory_size,
MEM_COMMIT | MEM_RESERVE,
PAGE_READWRITE);
//
@ -1905,7 +1923,7 @@ main(int argc, char **argv){
}
File_Slot file_slots[120];
File_Slot file_slots[32];
sysshared_init_file_exchange(&exchange_vars, file_slots, ArrayCount(file_slots), 0);
Font_Load_Parameters params[32];