command line ready, more linux shit done

This commit is contained in:
Allen Webster 2016-02-07 10:19:18 -05:00
parent 164a18c4a9
commit 959bdcd8cf
9 changed files with 349 additions and 195 deletions

View File

@ -79,3 +79,9 @@ NOTES ON USE:
# 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

66
4ed.cpp
View File

@ -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;
i32 out_size = 0;
App_Vars *vars = app_setup_memory(memory);
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(output_size);
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);
}
else{
file_create_empty(system, &vars->mem, ed_file, filename,
vars->font_set, vars->style.font_id);
}
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);
}
}
view_cursor_move(iter.view, preload_settings.start_line, 0);
}
exchange_free_file(exchange, binding->sys_id);

View File

@ -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;
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,7 +1528,6 @@ 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);

View File

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

View File

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

View File

@ -32,6 +32,9 @@
#include <math.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <stdio.h>
#include <X11/Xlib.h>
#include <GL/glx.h>
@ -39,20 +42,126 @@
#include <linux/fs.h>
#include <X11/extensions/XInput2.h>
#include <linux/input.h>
#include <time.h>
#include "4ed_internal.h"
#include "4ed_linux_keyboard.cpp"
#include <stdlib.h>
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

BIN
vc120.pdb

Binary file not shown.

View File

@ -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(&current_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){