conversion of platform layer

master
Allen Webster 2016-08-22 19:54:20 -04:00
parent 993d962a8b
commit 904f72a065
7 changed files with 324 additions and 102 deletions

View File

@ -24,6 +24,7 @@
struct Global_Settings{ struct Global_Settings{
int generate_docs; int generate_docs;
int generate_string;
}; };
static Global_Settings global_settings; static Global_Settings global_settings;
@ -2908,6 +2909,7 @@ int main(int argc, char **argv){
memset(&global_settings, 0, sizeof(global_settings)); memset(&global_settings, 0, sizeof(global_settings));
global_settings.generate_docs = true; global_settings.generate_docs = true;
global_settings.generate_string = false;
filename = generate_keycode_enum(); filename = generate_keycode_enum();
filename = generate_style(); filename = generate_style();

View File

@ -35,43 +35,44 @@ uhash_equal(Unique_Hash a, Unique_Hash b){
return(result); return(result);
} }
// NOTE(allen): These two time functions should return values
// in the same time space. There is no requirement about
// resolution but the higher the better. These functions
// should not be used for profiling purposes.
#define Sys_File_Time_Stamp_Sig(name) u64 name(char *filename)
typedef Sys_File_Time_Stamp_Sig(System_File_Time_Stamp);
#define Sys_Now_Time_Stamp_Sig(name) u64 name()
typedef Sys_Now_Time_Stamp_Sig(System_Now_Time_Stamp);
// TODO(allen): make directory a char* to signal that it must be null terminated // 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) #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); typedef Sys_Set_File_List_Sig(System_Set_File_List);
#define Sys_File_Unique_Hash_Sig(name) Unique_Hash name(String filename, b32 *success) enum{
typedef Sys_File_Unique_Hash_Sig(System_File_Unique_Hash); TrackFileFlag_ExistingOrFail = 0x0,
TrackFileFlag_NewOrFail = 0x1,
#define Sys_File_Track_Sig(name) void name(String filename) TrackFileFlag_NewAlways = 0x2,
typedef Sys_File_Track_Sig(System_File_Track); TrackFileFlag_ExistingOrNew = 0x3,
#define Sys_File_Untrack_Sig(name) void name(String filename)
typedef Sys_File_Untrack_Sig(System_File_Untrack);
struct File_Loading{
Plat_Handle handle;
i32 size;
b32 exists;
}; };
#define Sys_File_Load_Begin_Sig(name) File_Loading name(char *filename) #define Sys_Track_File_Sig(name) Unique_Hash name(char *filename, u32 flags)
typedef Sys_File_Load_Begin_Sig(System_File_Load_Begin); typedef Sys_Track_File_Sig(System_Track_File);
#define Sys_File_Load_End_Sig(name) b32 name(File_Loading loading, char *buffer) #define Sys_Untrack_File_Sig(name) i32 name(Unique_Hash index)
typedef Sys_File_Load_End_Sig(System_File_Load_End); typedef Sys_Untrack_File_Sig(System_Untrack_File);
#define Sys_Get_File_Index_Sig(name) i32 name(char *filename, Unique_Hash *index)
typedef Sys_Get_File_Index_Sig(System_Get_File_Index);
#define Sys_Get_File_Time_Sig(name) i32 name(Unique_Hash index, u64 *time)
typedef Sys_Get_File_Time_Sig(System_Get_File_Time);
#define Sys_Now_File_Time_Sig(name) void name(u64 *time)
typedef Sys_Now_File_Time_Sig(System_Now_File_Time);
#define Sys_Get_Changed_File_Sig(name) i32 name(Unique_Hash *index)
typedef Sys_Get_Changed_File_Sig(System_Get_Changed_File);
#define Sys_File_Size_Sig(name) u32 name(Unique_Hash index)
typedef Sys_File_Size_Sig(System_File_Size);
#define Sys_Load_File_Sig(name) i32 name(Unique_Hash index, char *buffer, i32 size)
typedef Sys_Load_File_Sig(System_Load_File);
#define Sys_Save_File_Sig(name) i32 name(Unique_Hash index, char *buffer, i32 size)
typedef Sys_Save_File_Sig(System_Save_File);
#define Sys_File_Save_Sig(name) b32 name(char *filename, char *buffer, i32 size)
typedef Sys_File_Save_Sig(System_File_Save);
#define Sys_Post_Clipboard_Sig(name) void name(String str) #define Sys_Post_Clipboard_Sig(name) void name(String str)
typedef Sys_Post_Clipboard_Sig(System_Post_Clipboard); typedef Sys_Post_Clipboard_Sig(System_Post_Clipboard);
@ -223,16 +224,18 @@ typedef INTERNAL_Sys_Get_Thread_States_Sig(INTERNAL_System_Get_Thread_States);
typedef INTERNAL_Sys_Debug_Message_Sig(INTERNAL_System_Debug_Message); typedef INTERNAL_Sys_Debug_Message_Sig(INTERNAL_System_Debug_Message);
struct System_Functions{ struct System_Functions{
// files: 9
System_File_Time_Stamp *file_time_stamp; // files (tracked api): 10
System_Now_Time_Stamp *now_time_stamp;
System_Set_File_List *set_file_list; System_Set_File_List *set_file_list;
System_File_Unique_Hash *file_unique_hash; System_Track_File *track_file;
System_File_Track *file_track; System_Untrack_File *untrack_file;
System_File_Untrack *file_untrack; System_Get_File_Index *get_file_index;
System_File_Load_Begin *file_load_begin; System_Get_File_Time *get_file_time;
System_File_Load_End *file_load_end; System_Now_File_Time *now_file_time;
System_File_Save *file_save; System_Get_Changed_File *get_changed_file;
System_File_Size *file_size;
System_Load_File *load_file;
System_Save_File *save_file;
// 4coder_custom.h: 7 // 4coder_custom.h: 7
Memory_Allocate_Function *memory_allocate; Memory_Allocate_Function *memory_allocate;

View File

@ -12,12 +12,12 @@ set DEFINES=
set FirstError=0 set FirstError=0
pushd ..\meta pushd ..\meta
cl %OPTS% ..\code\4ed_metagen.cpp %* /Femetagen REM cl %OPTS% ..\code\4ed_metagen.cpp %* /Femetagen
if %ERRORLEVEL% neq 0 (set FirstError=1) if %ERRORLEVEL% neq 0 (set FirstError=1)
popd popd
pushd ..\code pushd ..\code
"..\meta\metagen" REM "..\meta\metagen"
if %ERRORLEVEL% neq 0 (set FirstError=1) if %ERRORLEVEL% neq 0 (set FirstError=1)
set CODE_DIR=%CD% set CODE_DIR=%CD%
@ -26,7 +26,7 @@ popd
pushd ..\build pushd ..\build
REM call "%CODE_DIR%\buildsuper.bat" ..\code\4coder_default_bindings.cpp REM call "%CODE_DIR%\buildsuper.bat" ..\code\4coder_default_bindings.cpp
call "%CODE_DIR%\buildsuper.bat" ..\code\internal_4coder_tests.cpp REM call "%CODE_DIR%\buildsuper.bat" ..\code\internal_4coder_tests.cpp
REM call "%CODE_DIR%\buildsuper.bat" ..\code\power\4coder_casey.cpp REM call "%CODE_DIR%\buildsuper.bat" ..\code\power\4coder_casey.cpp
REM call "%CODE_DIR%\buildsuper.bat" ..\4vim\4coder_chronal.cpp REM call "%CODE_DIR%\buildsuper.bat" ..\4vim\4coder_chronal.cpp
if %ERRORLEVEL% neq 0 (set FirstError=1) if %ERRORLEVEL% neq 0 (set FirstError=1)

View File

@ -75,6 +75,9 @@ count_tracked_files(File_Track_System *system, int32_t *count);
File_Track_Result File_Track_Result
get_tracked_file_time(File_Track_System *system, File_Index index, File_Time *time); get_tracked_file_time(File_Track_System *system, File_Index index, File_Time *time);
File_Track_Result
get_file_time_now(File_Time *time);
File_Track_Result File_Track_Result
move_track_system(File_Track_System *system, void *mem, int32_t size); move_track_system(File_Track_System *system, void *mem, int32_t size);

View File

@ -17,10 +17,17 @@ Created on: 20.07.2016
#include <Windows.h> #include <Windows.h>
#ifndef Assert
# define Assert(c) do { if (!(c)) { *((int*)0) = 0xA11E; } } while (0) # define Assert(c) do { if (!(c)) { *((int*)0) = 0xA11E; } } while (0)
#define ZeroStruct(s) for (int32_t i = 0; i < sizeof(s); ++i) { ((char*)(&(s)))[i] = 0; } #endif
#ifndef ZeroStruct
# define ZeroStruct(s) for (int32_t i = 0; i < sizeof(s); ++i) { ((char*)(&(s)))[i] = 0; }
#endif
#ifndef NotImplemented
# define NotImplemented Assert(!"not implemented") # define NotImplemented Assert(!"not implemented")
#endif
typedef uint32_t rptr32; typedef uint32_t rptr32;
@ -252,7 +259,8 @@ directory_watching(LPVOID ptr){
EnterCriticalSection(&vars->table_lock); EnterCriticalSection(&vars->table_lock);
File_Track_Tables *tables = to_tables(vars); File_Track_Tables *tables = to_tables(vars);
File_Change_Record *records = to_ptr(tables, tables->change_queue); File_Change_Record *records = (File_Change_Record*)
to_ptr(tables, tables->change_queue);
char *buffer = listener.result; char *buffer = listener.result;
DWORD offset = 0; DWORD offset = 0;
@ -764,6 +772,21 @@ get_tracked_file_time(File_Track_System *system, File_Index index, File_Time *ti
return(result); return(result);
} }
File_Track_Result
get_file_time_now(File_Time *time){
File_Track_Result result = FileTrack_Good;
FILETIME file_time;
SYSTEMTIME system_time;
GetSystemTime(&system_time);
SystemTimeToFileTime(&system_time, &file_time);
*time = (((uint64_t)file_time.dwHighDateTime << 32) |
(file_time.dwLowDateTime));
return(result);
}
File_Track_Result File_Track_Result
move_track_system(File_Track_System *system, void *mem, int32_t size){ move_track_system(File_Track_System *system, void *mem, int32_t size){
File_Track_Result result = FileTrack_Good; File_Track_Result result = FileTrack_Good;

View File

@ -1,10 +0,0 @@
@echo off
set WARNINGOPS=/W4 /wd4310 /wd4100 /wd4201 /wd4505 /wd4996 /wd4127 /wd4510 /wd4512 /wd4610 /wd4390 /WX
set WARNINGOPS=%WARNINGOPS% /GR- /EHa- /nologo /FC
set WIN_LIBS=user32.lib winmm.lib gdi32.lib
pushd w:\filetrack\build
cl %WARNINGOPS% ..\code\filetrack_test.c /Fefile_rewriter /Zi %*
cl %WARNINGOPS% ..\code\filetrack_main.c /Fefiletrack /Zi %*
popd

View File

@ -26,6 +26,9 @@
#include <GL/gl.h> #include <GL/gl.h>
#include <GL/glext.h> #include <GL/glext.h>
#include "filetrack/4tech_file_track.h"
#include "filetrack/4tech_file_track_win32.c"
#include "system_shared.h" #include "system_shared.h"
#define SUPPORT_DPI 1 #define SUPPORT_DPI 1
@ -189,6 +192,10 @@ struct Win32_Vars{
b32 first; b32 first;
i32 running_cli; i32 running_cli;
File_Track_System track;
void *track_table;
u32 track_table_size;
u32 track_node_size;
#if FRED_INTERNAL #if FRED_INTERNAL
CRITICAL_SECTION DEBUG_sysmem_lock; CRITICAL_SECTION DEBUG_sysmem_lock;
@ -773,8 +780,14 @@ Sys_File_Can_Be_Made_Sig(system_file_can_be_made){
return(1); return(1);
} }
internal struct File_Loading{
Sys_File_Load_Begin_Sig(system_file_load_begin){ Plat_Handle handle;
i32 size;
b32 exists;
};
internal File_Loading
system_file_load_begin(char *filename){
File_Loading loading = {0}; File_Loading loading = {0};
HANDLE file = 0; HANDLE file = 0;
@ -808,8 +821,8 @@ Sys_File_Load_Begin_Sig(system_file_load_begin){
return(loading); return(loading);
} }
internal internal b32
Sys_File_Load_End_Sig(system_file_load_end){ system_file_load_end(File_Loading loading, char *buffer){
b32 success = 0; b32 success = 0;
HANDLE file = Win32Handle(loading.handle); HANDLE file = Win32Handle(loading.handle);
@ -832,8 +845,8 @@ Sys_File_Load_End_Sig(system_file_load_end){
return(success); return(success);
} }
internal internal b32
Sys_File_Save_Sig(system_file_save){ system_file_save(char *filename, char *buffer, i32 size){
b32 success = false; b32 success = false;
HANDLE file = HANDLE file =
@ -861,6 +874,7 @@ Sys_File_Save_Sig(system_file_save){
return(success); return(success);
} }
#if 0
internal internal
Sys_File_Time_Stamp_Sig(system_file_time_stamp){ Sys_File_Time_Stamp_Sig(system_file_time_stamp){
u64 result = 0; u64 result = 0;
@ -885,6 +899,40 @@ Sys_Now_Time_Stamp_Sig(system_now_time_stamp){
return(result); return(result);
} }
internal
Sys_File_Unique_Hash_Sig(system_file_unique_hash){
Unique_Hash hash = {0};
BY_HANDLE_FILE_INFORMATION info;
HANDLE handle;
char space[1024];
String str;
if (filename.size < sizeof(space)){
str = make_fixed_width_string(space);
copy(&str, filename);
terminate_with_null(&str);
handle = CreateFile(str.str, GENERIC_READ, 0, 0,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
*success = 0;
if (handle && handle != INVALID_HANDLE_VALUE){
if (GetFileInformationByHandle(handle, &info)){
hash.d[2] = info.dwVolumeSerialNumber;
hash.d[1] = info.nFileIndexHigh;
hash.d[0] = info.nFileIndexLow;
*success = 1;
}
CloseHandle(handle);
}
}
return(hash);
}
#endif
internal internal
Sys_Set_File_List_Sig(system_set_file_list){ Sys_Set_File_List_Sig(system_set_file_list){
if (directory.size > 0){ if (directory.size > 0){
@ -973,42 +1021,174 @@ Sys_Set_File_List_Sig(system_set_file_list){
} }
} }
internal inline Unique_Hash
Sys_File_Track_Sig(system_file_track){} to_uhash(File_Index index){
Unique_Hash r;
internal *(File_Index*)(&r) = index;
Sys_File_Untrack_Sig(system_file_untrack){} return(r);
internal
Sys_File_Unique_Hash_Sig(system_file_unique_hash){
Unique_Hash hash = {0};
BY_HANDLE_FILE_INFORMATION info;
HANDLE handle;
char space[1024];
String str;
if (filename.size < sizeof(space)){
str = make_fixed_width_string(space);
copy(&str, filename);
terminate_with_null(&str);
handle = CreateFile(str.str, GENERIC_READ, 0, 0,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
*success = 0;
if (handle && handle != INVALID_HANDLE_VALUE){
if (GetFileInformationByHandle(handle, &info)){
hash.d[2] = info.dwVolumeSerialNumber;
hash.d[1] = info.nFileIndexHigh;
hash.d[0] = info.nFileIndexLow;
*success = 1;
} }
CloseHandle(handle); inline File_Index
} to_findex(Unique_Hash index){
File_Index r;
*(Unique_Hash*)(&r) = index;
return(r);
} }
return(hash); internal
Sys_Track_File_Sig(system_track_file){
Unique_Hash index = {0};
switch (flags){
case TrackFileFlag_ExistingOrFail:
{
File_Index get_index = {0};
File_Time time = 0;
i32 result = begin_tracking_file(&win32vars.track, filename, &get_index, &time);
if (result == FileTrack_Good){
index = to_uhash(get_index);
}
}break;
// TODO(allen): provide the functions used here in the file track system
case TrackFileFlag_NewOrFail:
{
#if 0
File_Index get_index = {0};
File_Time time = 0;
File_Temp_Handle handle = {0};
i32 result = get_file_temp_handle(filename, &handle);
if (result == FileTrack_FileNotFound){
result = begin_tracking_new_file(&win32vars.track, filename, &get_index, &time);
if (result == FileTrack_Good){
index = to_uhash(get_index);
}
}
else{
finish_with_temp_handle(handle);
}
#endif
}break;
case TrackFileFlag_NewAlways:
{
#if 0
File_Index get_index = {0};
File_Time time = 0;
result = begin_tracking_new_file(&win32vars.track, filename, &get_index, &time);
if (result == FileTrack_Good){
index = to_uhash(get_index);
}
#endif
}break;
case TrackFileFlag_ExistingOrNew:
{
#if 0
File_Index get_index = {0};
File_Time time = 0;
File_Temp_Handle handle = {0};
i32 result = get_file_temp_handle(filename, &handle);
if (result == FileTrack_FileNotFound){
result = begin_tracking_new_file(&win32vars.track, filename, &get_index, &time);
}
else{
result = begin_tracking_from_handle(&win32vars.track, filename, handle, , &get_index, &time);
}
if (result == FileTrack_Good){
index = to_uhash(get_index);
}
#endif
}break;
}
return(index);
}
internal
Sys_Untrack_File_Sig(system_untrack_file){
i32 result = 0;
i32 track_result = stop_tracking_file(&win32vars.track, to_findex(index));
if (track_result == FileTrack_Good){
result = 1;
}
return(result);
}
internal
Sys_Get_File_Index_Sig(system_get_file_index){
i32 result = 0;
File_Index get_index = {0};
i32 track_result = get_tracked_file_index(&win32vars.track, filename, &get_index);
if (track_result == FileTrack_Good){
*index = to_uhash(get_index);
result = 1;
}
return(result);
}
internal
Sys_Get_File_Time_Sig(system_get_file_time){
i32 result = 0;
u64 get_time = 0;
File_Index findex = to_findex(index);
i32 track_result = get_tracked_file_time(&win32vars.track, findex, &get_time);
if (track_result == FileTrack_Good){
*time = get_time;
result = 1;
}
return(result);
}
internal
Sys_Now_File_Time_Sig(system_now_file_time){
get_file_time_now(time);
}
internal
Sys_Get_Changed_File_Sig(system_get_changed_file){
i32 result = 0;
File_Index get_index = {0};
i32 track_result = get_change_event(&win32vars.track, &get_index);
if (track_result == FileTrack_Good){
*index = to_uhash(get_index);
result = 1;
}
return(result);
}
internal
Sys_File_Size_Sig(system_file_size){
u32 size = 0;
File_Index findex = to_findex(index);
i32 track_result = get_tracked_file_size(&win32vars.track, findex, &size);
if (track_result != FileTrack_Good){
size = 0;
}
return(size);
}
internal
Sys_Load_File_Sig(system_load_file){
i32 result = 0;
File_Index findex = to_findex(index);
i32 track_result = get_tracked_file_data(&win32vars.track, findex, buffer, size);
if (track_result == FileTrack_Good){
result = 1;
}
return(result);
}
internal
Sys_Save_File_Sig(system_save_file){
i32 result = 0;
File_Index findex = to_findex(index);
File_Time time = 0;
i32 track_result = rewrite_tracked_file(&win32vars.track, findex, buffer, size, &time);
if (track_result == FileTrack_Good){
result = 1;
}
return(result);
} }
b32 Win32DirectoryExists(char *path){ b32 Win32DirectoryExists(char *path){
@ -1360,15 +1540,16 @@ Win32LoadAppCode(){
internal void internal void
Win32LoadSystemCode(){ Win32LoadSystemCode(){
win32vars.system.file_time_stamp = system_file_time_stamp;
win32vars.system.now_time_stamp = system_now_time_stamp;
win32vars.system.file_unique_hash = system_file_unique_hash;
win32vars.system.set_file_list = system_set_file_list; win32vars.system.set_file_list = system_set_file_list;
win32vars.system.file_track = system_file_track; win32vars.system.track_file = system_track_file;
win32vars.system.file_untrack = system_file_untrack; win32vars.system.untrack_file = system_untrack_file;
win32vars.system.file_load_begin = system_file_load_begin; win32vars.system.get_file_index = system_get_file_index;
win32vars.system.file_load_end = system_file_load_end; win32vars.system.get_file_time = system_get_file_time;
win32vars.system.file_save = system_file_save; win32vars.system.now_file_time = system_now_file_time;
win32vars.system.get_changed_file = system_get_changed_file;
win32vars.system.file_size = system_file_size;
win32vars.system.load_file = system_load_file;
win32vars.system.save_file = system_save_file;
win32vars.system.memory_allocate = Memory_Allocate; win32vars.system.memory_allocate = Memory_Allocate;
win32vars.system.file_exists = File_Exists; win32vars.system.file_exists = File_Exists;
@ -1944,6 +2125,26 @@ WinMain(HINSTANCE hInstance,
Win32LoadRenderCode(); Win32LoadRenderCode();
//
// File Track System
//
win32vars.track_table_size = (16 << 10);
win32vars.track_table = system_get_memory(win32vars.track_table_size);
win32vars.track_node_size = (16 << 10);
void *track_nodes = system_get_memory(win32vars.track_node_size);
i32 track_result =
init_track_system(&win32vars.track,
win32vars.track_table, win32vars.track_table_size,
track_nodes, win32vars.track_node_size);
if (track_result != FileTrack_Good){
exit(1);
}
// //
// Read Command Line // Read Command Line
// //