From 959bdcd8cffe858336b8f7718e862735bc3984fe Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Sun, 7 Feb 2016 10:19:18 -0500 Subject: [PATCH] command line ready, more linux shit done --- 4coder_config.h | 168 +++++++++++++++++++++++---------------------- 4ed.cpp | 78 +++++++++++++-------- 4ed_app_target.cpp | 102 +++++++++++++-------------- 4ed_file_view.cpp | 36 ++++++---- 4ed_meta.h | 5 -- 4ed_system.h | 1 + linux_4ed.cpp | 127 +++++++++++++++++++++++++++++++--- vc120.pdb | Bin 102400 -> 102400 bytes win32_4ed.cpp | 27 ++++++-- 9 files changed, 349 insertions(+), 195 deletions(-) diff --git a/4coder_config.h b/4coder_config.h index 3bf91fcc..9784c343 100644 --- a/4coder_config.h +++ b/4coder_config.h @@ -1,81 +1,87 @@ -/* "4cpp" Open C++ Parser v0.1: Config - no warranty implied; use at your own risk - -NOTES ON USE: - This file is used to configure 4cpp options at the begining of 4cpp files. - It is not meant to be used directly. -*/ - -#ifdef FCPP_NO_CRT -# ifndef FCPP_NO_MALLOC -# define FCPP_NO_MALLOC -# endif -# ifndef FCPP_NO_ASSERT -# define FCPP_NO_ASSERT -# endif -# ifndef FCPP_NO_STRING -# define FCPP_NO_STRING -# endif -#endif - -#ifdef FCPP_FORBID_MALLOC -# define FCPP_NO_MALLOC -#endif - -#ifndef FCPP_NO_MALLOC -# include -#endif - -#ifndef FCPP_NO_ASSERT -# include -#endif - -#ifndef FCPP_NO_STRING -# include -#endif - -#ifndef FCPP_NO_MALLOC -# ifndef FCPP_GET_MEMORY -# define FCPP_GET_MEMORY malloc -# endif -# ifndef FCPP_FREE_MEMORY -# define FCPP_FREE_MEMORY free -# endif -#else -# ifndef FCPP_FORBID_MALLOC -# ifndef FCPP_GET_MEMORY -# error Missing definition for FCPP_GET_MEMORY -# endif -# ifndef FCPP_FREE_MEMORY -# error Missing definition for FCPP_FREE_MEMORY -# endif -# endif -#endif - -#ifndef FCPP_NO_ASSERT -# ifndef FCPP_ASSERT -# define FCPP_ASSERT assert -# endif -#else -# ifndef FCPP_ASSERT -# define FCPP_ASSERT(x) -# endif -#endif - -#ifndef FCPP_NO_STRING -# ifndef FCPP_MEM_COPY -# define FCPP_MEM_COPY memcpy -# endif -# ifndef FCPP_MEM_MOVE -# define FCPP_MEM_MOVE memmove -# endif -#endif - -#ifndef FCPP_LINK -# ifdef FCPP_EXTERN -# define FCPP_LINK extern -# else -# define FCPP_LINK static -# endif -#endif - +/* "4cpp" Open C++ Parser v0.1: Config + no warranty implied; use at your own risk + +NOTES ON USE: + This file is used to configure 4cpp options at the begining of 4cpp files. + It is not meant to be used directly. +*/ + +#ifdef FCPP_NO_CRT +# ifndef FCPP_NO_MALLOC +# define FCPP_NO_MALLOC +# endif +# ifndef FCPP_NO_ASSERT +# define FCPP_NO_ASSERT +# endif +# ifndef FCPP_NO_STRING +# define FCPP_NO_STRING +# endif +#endif + +#ifdef FCPP_FORBID_MALLOC +# define FCPP_NO_MALLOC +#endif + +#ifndef FCPP_NO_MALLOC +# include +#endif + +#ifndef FCPP_NO_ASSERT +# include +#endif + +#ifndef FCPP_NO_STRING +# include +#endif + +#ifndef FCPP_NO_MALLOC +# ifndef FCPP_GET_MEMORY +# define FCPP_GET_MEMORY malloc +# endif +# ifndef FCPP_FREE_MEMORY +# define FCPP_FREE_MEMORY free +# endif +#else +# ifndef FCPP_FORBID_MALLOC +# ifndef FCPP_GET_MEMORY +# error Missing definition for FCPP_GET_MEMORY +# endif +# ifndef FCPP_FREE_MEMORY +# error Missing definition for FCPP_FREE_MEMORY +# endif +# endif +#endif + +#ifndef FCPP_NO_ASSERT +# ifndef FCPP_ASSERT +# define FCPP_ASSERT assert +# endif +#else +# ifndef FCPP_ASSERT +# define FCPP_ASSERT(x) +# endif +#endif + +#ifndef FCPP_NO_STRING +# ifndef FCPP_MEM_COPY +# define FCPP_MEM_COPY memcpy +# endif +# ifndef FCPP_MEM_MOVE +# define FCPP_MEM_MOVE memmove +# endif +#endif + +#ifndef FCPP_LINK +# ifdef FCPP_EXTERN +# define FCPP_LINK extern +# else +# define FCPP_LINK static +# endif +#endif + +#ifndef DrBegin +#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); } +#endif \ No newline at end of file diff --git a/4ed.cpp b/4ed.cpp index ce0d4fde..2afc6993 100644 --- a/4ed.cpp +++ b/4ed.cpp @@ -844,7 +844,6 @@ app_open_file(System_Functions *system, App_Vars *vars, Exchange *exchange, return(result); } - COMMAND_DECL(interactive_open){ ProfileMomentFunction(); USE_VARS(vars); @@ -2594,16 +2593,34 @@ app_setup_memory(Application_Memory *memory){ return(vars); } +internal i32 +execute_special_tool(void *memory, i32 size, Command_Line_Parameters clparams){ + char message[] = "Hell World!"; + i32 result = sizeof(message) - 1; + memcpy(memory, message, result); + return(result); +} + App_Read_Command_Line_Sig(app_read_command_line){ - i32 output_size = 0; - - 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); + App_Vars *vars; + i32 out_size = 0; + + if (clparams.argc > 1 && match(clparams.argv[1], "-T")){ + out_size = execute_special_tool(memory->target_memory, memory->target_memory_size, clparams); + } + else{ + vars = app_setup_memory(memory); + if (clparams.argc > 1){ + init_command_line_settings(&vars->settings, plat_settings, clparams); + *files = vars->settings.init_files; + *file_count = &vars->settings.init_files_count; + } + else{ + vars->settings = {}; + } + } + + return(out_size); } App_Init_Sig(app_init){ @@ -3289,16 +3306,23 @@ App_Step_Sig(app_step){ i32 i; String file_name; + File_View *fview; + Editing_File *file; 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, + fview = app_open_file(system, vars, exchange, &vars->live_set, &vars->working_set, panel, &command_data, file_name); if (i == 0){ - + if (fview){ + file = fview->file; + if (file){ + file->preload.start_line = vars->settings.initial_line; + } + } } } else{ @@ -3620,10 +3644,14 @@ App_Step_Sig(app_step){ byte *data; i32 size, max; + Editing_File *ed_file; + Editing_File_Preload preload_settings; + char *filename; if (exchange_file_ready(exchange, binding->sys_id, &data, &size, &max)){ - Editing_File *ed_file = vars->working_set.files + binding->app_id; - char *filename = exchange_file_filename(exchange, binding->sys_id); + ed_file = vars->working_set.files + binding->app_id; + filename = exchange_file_filename(exchange, binding->sys_id); + preload_settings = ed_file->preload; if (data){ String val = make_string((char*)data, size); file_create_from_string(system, &vars->mem, ed_file, filename, @@ -3631,25 +3659,17 @@ App_Step_Sig(app_step){ if (ed_file->settings.tokens_exist) file_first_lex_parallel(system, &vars->mem.general, ed_file); - - for (File_View_Iter iter = file_view_iter_init(&vars->layout, ed_file, 0); - file_view_iter_good(iter); - iter = file_view_iter_next(iter)){ - view_file_loaded_init(system, iter.view, 0); - } } 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); - } - } + } + + for (File_View_Iter iter = file_view_iter_init(&vars->layout, ed_file, 0); + file_view_iter_good(iter); + iter = file_view_iter_next(iter)){ + view_file_loaded_init(system, iter.view, 0); + view_cursor_move(iter.view, preload_settings.start_line, 0); } exchange_free_file(exchange, binding->sys_id); diff --git a/4ed_app_target.cpp b/4ed_app_target.cpp index a27b3d6b..b994054a 100644 --- a/4ed_app_target.cpp +++ b/4ed_app_target.cpp @@ -1,51 +1,51 @@ -/* - * Mr. 4th Dimention - Allen Webster - * - * 13.11.2015 - * - * Application layer build target - * - */ - -// TOP - -#include "4ed_config.h" - -#define BUFFER_EXPERIMENT_SCALPEL 0 - -#include "4ed_meta.h" - -#include "4cpp_types.h" -#define FCPP_STRING_IMPLEMENTATION -#include "4coder_string.h" - -#include "4ed_mem.cpp" -#include "4ed_math.cpp" - -#include "4coder_custom.h" -#include "4ed_system.h" -#include "4ed_rendering.h" -#include "4ed.h" - -#include "4ed_internal.h" - -#define FCPP_LEXER_IMPLEMENTATION -#include "4cpp_lexer.h" - -#include "4ed_exchange.cpp" -#include "4ed_font_set.cpp" -#include "4ed_rendering_helper.cpp" -#include "4ed_command.cpp" -#include "4ed_layout.cpp" -#include "4ed_style.cpp" -#include "4ed_file_view.cpp" -#include "4ed_color_view.cpp" -#include "4ed_interactive_view.cpp" -#include "4ed_menu_view.cpp" -#include "4ed_app_settings.h" -#include "4ed_config_view.cpp" -#include "4ed_debug_view.cpp" -#include "4ed.cpp" - -// BOTTOM - +/* + * Mr. 4th Dimention - Allen Webster + * + * 13.11.2015 + * + * Application layer build target + * + */ + +// TOP + +#include "4ed_config.h" + +#define BUFFER_EXPERIMENT_SCALPEL 0 + +#include "4ed_meta.h" + +#include "4cpp_types.h" +#define FCPP_STRING_IMPLEMENTATION +#include "4coder_string.h" + +#include "4ed_mem.cpp" +#include "4ed_math.cpp" + +#include "4coder_custom.h" +#include "4ed_system.h" +#include "4ed_rendering.h" +#include "4ed.h" + +#include "4ed_internal.h" + +#define FCPP_LEXER_IMPLEMENTATION +#include "4cpp_lexer.h" + +#include "4ed_exchange.cpp" +#include "4ed_font_set.cpp" +#include "4ed_rendering_helper.cpp" +#include "4ed_command.cpp" +#include "4ed_layout.cpp" +#include "4ed_style.cpp" +#include "4ed_file_view.cpp" +#include "4ed_color_view.cpp" +#include "4ed_interactive_view.cpp" +#include "4ed_menu_view.cpp" +#include "4ed_app_settings.h" +#include "4ed_config_view.cpp" +#include "4ed_debug_view.cpp" +#include "4ed.cpp" + +// BOTTOM + diff --git a/4ed_file_view.cpp b/4ed_file_view.cpp index a981436b..e05a10d4 100644 --- a/4ed_file_view.cpp +++ b/4ed_file_view.cpp @@ -132,6 +132,10 @@ struct Editing_File_State{ u64 last_sys_write_time; }; +struct Editing_File_Preload{ + i32 start_line; +}; + struct Editing_File_Name{ char live_name_[256]; String live_name; @@ -144,7 +148,10 @@ struct Editing_File_Name{ struct Editing_File{ Editing_File_Settings settings; - Editing_File_State state; + union{ + Editing_File_State state; + Editing_File_Preload preload; + }; Editing_File_Name name; }; @@ -1494,22 +1501,26 @@ file_create_from_string(System_Functions *system, Mem_Options *mem, Editing_File *file, char *filename, Font_Set *set, i16 font_id, String val, b8 super_locked = 0){ - file->state = {}; General_Memory *general = &mem->general; + Partition *part = &mem->part; + Buffer_Init_Type init; + i32 page_size, scratch_size, init_success; + + file->state = {}; + #if BUFFER_EXPERIMENT_SCALPEL <= 3 - Buffer_Init_Type init = buffer_begin_init(&file->state.buffer, val.str, val.size); + init = buffer_begin_init(&file->state.buffer, val.str, val.size); for (; buffer_init_need_more(&init); ){ - i32 page_size = buffer_init_page_size(&init); + page_size = buffer_init_page_size(&init); page_size = LargeRoundUp(page_size, Kbytes(4)); if (page_size < Kbytes(4)) page_size = Kbytes(4); void *data = general_memory_allocate(general, page_size, BUBBLE_BUFFER); buffer_init_provide_page(&init, data, page_size); } - Partition *part = &mem->part; - i32 scratch_size = partition_remaining(part); + scratch_size = partition_remaining(part); Assert(scratch_size > 0); - i32 init_success = buffer_end_init(&init, part->base + part->pos, scratch_size); + init_success = buffer_end_init(&init, part->base + part->pos, scratch_size); AllowLocal(init_success); Assert(init_success); #endif @@ -1517,11 +1528,10 @@ file_create_from_string(System_Functions *system, Mem_Options *mem, file_init_strings(file); file_set_name(file, (char*)filename); - //file->settings.base_map_id = mapid_file; file->state.font_id = font_id; file_synchronize_times(system, file, filename); - + Render_Font *font = get_font_info(set, font_id)->font; float *advance_data = 0; if (font) advance_data = font->advance_data; @@ -1534,22 +1544,22 @@ file_create_from_string(System_Functions *system, Mem_Options *mem, file->state.undo.undo.strings = (u8*)general_memory_allocate(general, request_size, BUBBLE_UNDO_STRING); file->state.undo.undo.edit_max = request_size / sizeof(Edit_Step); file->state.undo.undo.edits = (Edit_Step*)general_memory_allocate(general, request_size, BUBBLE_UNDO); - + file->state.undo.redo.max = request_size; file->state.undo.redo.strings = (u8*)general_memory_allocate(general, request_size, BUBBLE_UNDO_STRING); file->state.undo.redo.edit_max = request_size / sizeof(Edit_Step); file->state.undo.redo.edits = (Edit_Step*)general_memory_allocate(general, request_size, BUBBLE_UNDO); - + file->state.undo.history.max = request_size; file->state.undo.history.strings = (u8*)general_memory_allocate(general, request_size, BUBBLE_UNDO_STRING); file->state.undo.history.edit_max = request_size / sizeof(Edit_Step); file->state.undo.history.edits = (Edit_Step*)general_memory_allocate(general, request_size, BUBBLE_UNDO); - + file->state.undo.children.max = request_size; file->state.undo.children.strings = (u8*)general_memory_allocate(general, request_size, BUBBLE_UNDO_STRING); file->state.undo.children.edit_max = request_size / sizeof(Buffer_Edit); file->state.undo.children.edits = (Buffer_Edit*)general_memory_allocate(general, request_size, BUBBLE_UNDO); - + file->state.undo.history_block_count = 1; file->state.undo.history_head_block = 0; file->state.undo.current_block_normal = 1; diff --git a/4ed_meta.h b/4ed_meta.h index 572f8e30..97939246 100644 --- a/4ed_meta.h +++ b/4ed_meta.h @@ -47,11 +47,6 @@ 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); } diff --git a/4ed_system.h b/4ed_system.h index 7d63a6ea..8044d23a 100644 --- a/4ed_system.h +++ b/4ed_system.h @@ -27,6 +27,7 @@ struct File_List{ #define Sys_File_Time_Stamp_Sig(name) u64 name(char *filename) typedef Sys_File_Time_Stamp_Sig(System_File_Time_Stamp); +// TODO(allen): make directory a char* to signal that it must be null terminated #define Sys_Set_File_List_Sig(name) void name(File_List *file_list, String directory) typedef Sys_Set_File_List_Sig(System_Set_File_List); diff --git a/linux_4ed.cpp b/linux_4ed.cpp index 7da52ffc..c0979dd8 100644 --- a/linux_4ed.cpp +++ b/linux_4ed.cpp @@ -32,6 +32,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -39,20 +42,126 @@ #include #include #include +#include #include "4ed_internal.h" #include "4ed_linux_keyboard.cpp" +#include + +void* +LinuxGetMemory(i32 size){ + // TODO(allen): Implement without stdlib.h + return (malloc(size)); +} + +void +LinuxFreeMemory(void *block){ + // TODO(allen): Implement without stdlib.h + free(block); +} + +#if (defined(_BSD_SOURCE) || defined(_SVID_SOURCE)) +#define TimeBySt +#endif +#if (_POSIX_C_SOURCE >= 200809L || _XOPEN_SOURCE >= 700) +#define TimeBySt +#endif + +#ifdef TimeBySt +#define nano_mtime_field st_mtim.tv_nsec +#undef TimeBySt +#else +#define nano_mtime_field st_mtimensec +#endif + +Sys_File_Time_Stamp_Sig(system_file_time_stamp){ + struct stat info; + i64 nanosecond_timestamp; + u64 result; + + stat(filename, &info); + nanosecond_timestamp = info.nano_mtime_field; + if (nanosecond_timestamp != 0){ + result = (u64)(nanosecond_timestamp / 1000); + } + else{ + result = (u64)(info.st_mtime * 1000000); + } + + return(result); +} + +Sys_Time_Sig(system_time){ + struct timespec spec; + u64 result; + + clock_gettime(CLOCK_MONOTONIC, &spec); + result = (spec.tv_sec * 1000000) + (spec.tv_nsec / 1000); + + return(result); +} + +Sys_Set_File_List_Sig(system_set_file_list){ + DIR *d; + struct dirent *entry; + char *fname, *cursor, *cursor_start; + File_Info *info_ptr; + i32 count, file_count, size, required_size; + + terminate_with_null(&directory); + d = opendir(directory.str); + if (d){ + count = 0; + for (entry = readdir(d); + entry != 0; + entry = readdir(d)){ + fname = entry->d_name; + ++file_count; + for (size = 0; fname[size]; ++size); + count += size + 1; + } + closedir(d); + + required_size = count + file_count * sizeof(File_Info); + if (file_list->block_size < required_size){ + if (file_list->block){ + LinuxFreeMemory(file_list->block); + } + file_list->block = LinuxGetMemory(required_size); + } + + file_list->infos = (File_Info*)file_list->block; + cursor = (char*)(file_list->infos + file_count); + + d = opendir(directory.str); + if (d){ + info_ptr = file_list->infos; + for (entry = readdir(d); + entry != 0; + entry = readdir(d), ++info_ptr){ + fname = entry->d_name; + cursor_start = cursor; + for (; *fname; ) *cursor++ = *fname++; + *cursor++ = 0; + + info_ptr->folder = 0; + info_ptr->filename.str = cursor_start; + info_ptr->filename.size = (i32)(cursor - cursor_start); + info_ptr->filename.memory_size = info_ptr->filename.size + 1; + } + } + closedir(d); + } + closedir(d); +} + +Sys_Post_Clipboard_Sig(system_post_clipboard){ + // TODO(allen): Implement + AllowLocal(str); +} + // NOTE(allen): Thanks to Casey for providing the linux OpenGL launcher. -/* TODO(allen): - - 1. get 4coder rendering it's blank self - 2. get input working - (release linux version) - 3. add in extra stuff as it is completed in windows - - */ - static bool ctxErrorOccurred = false; static int XInput2OpCode = 0; internal int diff --git a/vc120.pdb b/vc120.pdb index 6be3fa46faa4b3cb0e76e780c927a5a947a57e6f..ab801a0d8dfbf76a0929fbd19035e2847a3ad31d 100644 GIT binary patch delta 122 zcmZozz}B#UZG#E7`gs!uh93;hObkE(qZ6Qf7|o#Iyg8bC84Htz$Yw!-_xzI;1o)U4 z9A3jYn+!M<7`r!f1}Fm)GhY>r6S@SZVaJ7)l+vcP1W1fA_60gNm7mlZH7003S? B9j^cY diff --git a/win32_4ed.cpp b/win32_4ed.cpp index fbd63966..d9781cff 100644 --- a/win32_4ed.cpp +++ b/win32_4ed.cpp @@ -317,8 +317,8 @@ system_save_file(char *filename, void *data, i32 size){ 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); + file = CreateFile((char*)filename, FILE_APPEND_DATA, 0, 0, + OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); if (!file || file == INVALID_HANDLE_VALUE){ return 0; @@ -414,7 +414,7 @@ Sys_Set_File_List_Sig(system_set_file_list){ char *name_base = name; i32 i = 0; for(;find_data.cFileName[i];++i) *name++ = find_data.cFileName[i]; - info->filename.size = (i32)(name - name_base); + info->filename.size = i; info->filename.memory_size = info->filename.size + 1; *name++ = 0; ++info; @@ -1499,11 +1499,18 @@ UpdateLoop(LPVOID param){ return(0); } +#if 0 int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){ +#else +int +main(int argc, char **argv){ +#endif + HINSTANCE hInstance = GetModuleHandle(0); + win32vars = {}; exchange_vars = {}; @@ -1560,12 +1567,15 @@ WinMain(HINSTANCE hInstance, terminate_with_null(¤t_directory); Command_Line_Parameters clparams; - clparams.argv = __argv; - clparams.argc = __argc; + clparams.argv = argv; + clparams.argc = argc; char **files; i32 *file_count; + files = 0; + file_count = 0; + i32 output_size = win32vars.app.read_command_line(system, &memory_vars, @@ -1577,10 +1587,13 @@ WinMain(HINSTANCE hInstance, if (output_size > 0){ // TODO + printf("%.*s", output_size, memory_vars.target_memory); + } if (output_size != 0) return 0; + FreeConsole(); - { + if (files){ i32 i, j; i32 end = *file_count; for (i = 0, j = 0; i < end; ++i){ @@ -1623,7 +1636,7 @@ WinMain(HINSTANCE hInstance, GetProcAddress(win32vars.custom, "get_bindings"); } #endif - + Thread_Context background[4]; memset(background, 0, sizeof(background)); win32vars.groups[BACKGROUND_THREADS].threads = background;