Implemented system_get_path.

master
Yuval Dolev 2019-12-25 03:17:12 +02:00
parent e3e5f857ea
commit 57c0707284
5 changed files with 140 additions and 39 deletions

View File

@ -36,6 +36,11 @@
#include "4ed_search_list.cpp" #include "4ed_search_list.cpp"
#include "mac_objective_c_to_cpp_links.h"
#include <stdlib.h>
#include <unistd.h>
//////////////////////////////// ////////////////////////////////
#define SLASH '\\' #define SLASH '\\'
@ -54,12 +59,14 @@ struct Mac_Vars {
Thread_Context *tctx; Thread_Context *tctx;
Arena* frame_arena; Arena* frame_arena;
String_Const_u8 binary_path;
}; };
//////////////////////////////// ////////////////////////////////
Mac_Vars global_mac_vars; Mac_Vars mac_vars;
global Render_Target global_target; global Render_Target target;
//////////////////////////////// ////////////////////////////////
@ -75,8 +82,8 @@ mac_init() {
get_base_allocator_system(), get_base_allocator_system(),
get_base_allocator_system()); get_base_allocator_system());
block_zero_struct(&global_mac_vars); block_zero_struct(&mac_vars);
global_mac_vars.tctx = &_tctx; mac_vars.tctx = &_tctx;
API_VTable_system system_vtable = {}; API_VTable_system system_vtable = {};
system_api_fill_vtable(&system_vtable); system_api_fill_vtable(&system_vtable);
@ -88,6 +95,14 @@ mac_init() {
font_api_fill_vtable(&font_vtable); font_api_fill_vtable(&font_vtable);
// NOTE(yuval): Memory // NOTE(yuval): Memory
global_mac_vars.frame_arena = reserve_arena(global_mac_vars.tctx); mac_vars.frame_arena = reserve_arena(mac_vars.tctx);
global_target.arena = make_arena_system(KB(256)); target.arena = make_arena_system(KB(256));
#if 0
mac_vars.cursor_show = MouseCursorShow_Always;
mac_vars.prev_cursor_show = MouseCursorShow_Always;
dll_init_sentinel(&mac_vars.free_mac_objects);
dll_init_sentinel(&mac_vars.timer_objects);
#endif
} }

View File

@ -1,6 +1,7 @@
/* Mac Objective C layer for 4coder */ /* Mac Objective C layer for 4coder */
#include "4coder_base_types.h" #include "4coder_base_types.h"
#include "mac_objective_c_to_cpp_links.h" #include "mac_objective_c_to_cpp_links.h"
#undef function #undef function
@ -9,6 +10,13 @@
#undef external #undef external
#include <Cocoa/Cocoa.h> #include <Cocoa/Cocoa.h>
#include <libproc.h> // NOTE(yuval): Used for proc_pidpath
#include <sys/types.h>
#include <unistd.h> // NOTE(yuval): Used for getpid
#define external extern "C"
@interface App_Delegate : NSObject<NSApplicationDelegate, NSWindowDelegate> @interface App_Delegate : NSObject<NSApplicationDelegate, NSWindowDelegate>
@end @end
@ -33,6 +41,14 @@
} }
@end @end
external i32
mac_get_binary_path(void *buffer, u32 size){
pid_t pid = getpid();
i32 bytes_read = proc_pidpath(pid, buffer, size);
return bytes_read;
}
int int
main(int arg_count, char **args){ main(int arg_count, char **args){
@autoreleasepool{ @autoreleasepool{

View File

@ -1,12 +1,47 @@
/* General macOS Functions */ /* macOS System/Graphics/Font API Implementations */
////////////////////////////////
function function
system_get_path_sig(){ system_get_path_sig(){
String_Const_u8 result = {}; String_Const_u8 result = {};
NotImplemented; switch (path_code){
case SystemPath_CurrentDirectory:
{
char *working_dir = getcwd(NULL, 0);
u64 working_dir_length = cstring_length(working_dir);
return result; // TODO(yuval): Maybe use push_string_copy instead
u8 *out = push_array(arena, u8, working_dir_length);
block_copy(out, working_dir, working_dir_length);
free(working_dir);
result = SCu8(out, working_dir_length);
} break;
case SystemPath_Binary:
{
local_persist b32 has_stashed_4ed_path = false;
if (!has_stashed_4ed_path){
local_const i32 binary_path_capacity = KB(32);
u8 *memory = (u8*)system_memory_allocate(binary_path_capacity, string_u8_litexpr(file_name_line_number));
i32 size = mac_get_binary_path(memory, binary_path_capacity);
Assert(size <= binary_path_capacity - 1);
mac_vars.binary_path = SCu8(memory, size);
mac_vars.binary_path = string_remove_last_folder(mac_vars.binary_path);
mac_vars.binary_path.str[mac_vars.binary_path.size] = 0;
has_stashed_4ed_path = true;
}
result = push_string_copy(arena, mac_vars.binary_path);
} break;
}
return(result);
} }
function function
@ -15,7 +50,7 @@ system_get_canonical_sig(){
NotImplemented; NotImplemented;
return result; return(result);
} }
function function
@ -24,7 +59,7 @@ system_get_file_list_sig(){
NotImplemented; NotImplemented;
return result; return(result);
} }
function function
@ -33,7 +68,7 @@ system_quick_file_attributes_sig(){
NotImplemented; NotImplemented;
return result; return(result);
} }
function function
@ -42,7 +77,7 @@ system_load_handle_sig(){
NotImplemented; NotImplemented;
return result; return(result);
} }
function function
@ -51,7 +86,7 @@ system_load_attributes_sig(){
NotImplemented; NotImplemented;
return result; return(result);
} }
function function
@ -60,7 +95,7 @@ system_load_file_sig(){
NotImplemented; NotImplemented;
return result; return(result);
} }
function function
@ -69,7 +104,7 @@ system_load_close_sig(){
NotImplemented; NotImplemented;
return result; return(result);
} }
function function
@ -78,7 +113,7 @@ system_save_file_sig(){
NotImplemented; NotImplemented;
return result; return(result);
} }
function function
@ -87,7 +122,7 @@ system_load_library_sig(){
NotImplemented; NotImplemented;
return result; return(result);
} }
function function
@ -96,7 +131,7 @@ system_release_library_sig(){
NotImplemented; NotImplemented;
return result; return(result);
} }
function function
@ -105,7 +140,7 @@ system_get_proc_sig(){
NotImplemented; NotImplemented;
return result; return(result);
} }
function function
@ -114,7 +149,7 @@ system_now_time_sig(){
NotImplemented; NotImplemented;
return result; return(result);
} }
function function
@ -123,7 +158,7 @@ system_wake_up_timer_create_sig(){
NotImplemented; NotImplemented;
return result; return(result);
} }
function function
@ -157,7 +192,7 @@ system_cli_call_sig(){
NotImplemented; NotImplemented;
return result; return(result);
} }
function function
@ -171,7 +206,7 @@ system_cli_update_step_sig(){
NotImplemented; NotImplemented;
return result; return(result);
} }
function function
@ -180,7 +215,7 @@ system_cli_end_update_sig(){
NotImplemented; NotImplemented;
return result; return(result);
} }
function function
@ -194,7 +229,7 @@ system_get_screen_scale_factor_sig(){
NotImplemented; NotImplemented;
return result; return(result);
} }
function function
@ -203,7 +238,7 @@ system_thread_launch_sig(){
NotImplemented; NotImplemented;
return result; return(result);
} }
function function
@ -222,7 +257,7 @@ system_thread_get_id_sig(){
NotImplemented; NotImplemented;
return result; return(result);
} }
function function
@ -241,7 +276,7 @@ system_mutex_make_sig(){
NotImplemented; NotImplemented;
return result; return(result);
} }
function function
@ -265,7 +300,7 @@ system_condition_variable_make_sig(){
NotImplemented; NotImplemented;
return result; return(result);
} }
function function
@ -289,7 +324,7 @@ system_memory_allocate_sig(){
NotImplemented; NotImplemented;
return result; return(result);
} }
function function
@ -298,7 +333,7 @@ system_memory_set_protection_sig(){
NotImplemented; NotImplemented;
return result; return(result);
} }
function function
@ -312,7 +347,7 @@ system_memory_annotation_sig(){
NotImplemented; NotImplemented;
return result; return(result);
} }
function function
@ -326,7 +361,7 @@ system_set_fullscreen_sig(){
NotImplemented; NotImplemented;
return result; return(result);
} }
function function
@ -335,7 +370,7 @@ system_is_fullscreen_sig(){
NotImplemented; NotImplemented;
return result; return(result);
} }
function function
@ -344,5 +379,38 @@ system_get_keyboard_modifiers_sig(){
NotImplemented; NotImplemented;
return result; return(result);
} }
////////////////////////////////
function
graphics_get_texture_sig(){
u32 result = 0;
NotImplemented;
return(result);
}
function
graphics_fill_texture_sig(){
b32 result = false;
NotImplemented;
return(result);
}
////////////////////////////////
function
font_make_face_sig(){
Face* result = 0;
NotImplemented;
return(result);
}
////////////////////////////////

View File

@ -4,10 +4,12 @@
#define MAC_OBJECTIVE_C_TO_CPP_LINKS_H #define MAC_OBJECTIVE_C_TO_CPP_LINKS_H
// In C++ layer. // In C++ layer.
external void* external void
mac_init(); mac_init();
// In Objective-C layer. // In Objective-C layer.
external i32
mac_get_binary_path(void* buffer, u32 size);
#endif #endif