From ea29a6e13ee7c4400989d778440c31f0ab2d5702 Mon Sep 17 00:00:00 2001 From: Yuval Dolev Date: Thu, 26 Dec 2019 17:54:06 +0200 Subject: [PATCH] Work on system_get_file_list. File attribute retrieval now works. --- platform_mac/mac_4ed.cpp | 7 +++- platform_mac/mac_4ed.mm | 6 +++- platform_mac/mac_4ed_functions.cpp | 50 +++++++++++++++++++++++++--- platform_unix/unix_4ed_functions.cpp | 2 +- 4 files changed, 58 insertions(+), 7 deletions(-) diff --git a/platform_mac/mac_4ed.cpp b/platform_mac/mac_4ed.cpp index f9f57fb6..f3c188d7 100644 --- a/platform_mac/mac_4ed.cpp +++ b/platform_mac/mac_4ed.cpp @@ -38,8 +38,13 @@ #include "mac_objective_c_to_cpp_links.h" +#include +#include + #include // NOTE(yuval): Used for getcwd #include // NOTE(yuval): Used for opendir, readdir +#include // NOTE(yuval): Used for struct stat +#include // NOTE(yuval): Used for stat #include // NOTE(yuval): Used for free @@ -95,6 +100,7 @@ mac_init(){ system_get_file_list(&test_arena, string_u8_litexpr("/Users/yuvaldolev/Desktop")); +#if 0 // NOTE(yuval): Context Setup Thread_Context _tctx = {}; thread_ctx_init(&_tctx, ThreadKind_Main, @@ -117,7 +123,6 @@ mac_init(){ mac_vars.frame_arena = reserve_arena(mac_vars.tctx); target.arena = make_arena_system(KB(256)); -#if 0 mac_vars.cursor_show = MouseCursorShow_Always; mac_vars.prev_cursor_show = MouseCursorShow_Always; diff --git a/platform_mac/mac_4ed.mm b/platform_mac/mac_4ed.mm index badc89e2..0e3e9485 100644 --- a/platform_mac/mac_4ed.mm +++ b/platform_mac/mac_4ed.mm @@ -2,9 +2,11 @@ #include "4coder_base_types.h" +#if 0 #include "4coder_table.h" #include "4coder_events.h" #include "4coder_types.h" +#endif #include "mac_objective_c_to_cpp_links.h" @@ -45,6 +47,7 @@ } @end +#if 0 external File_List mac_get_file_list(Arena* arena, String_Const_u8 directory){ File_List result = {}; @@ -58,11 +61,12 @@ mac_get_file_list(Arena* arena, String_Const_u8 directory){ NSString *filename; while ((filename = [dirEnum nextObject])){ - NSLog(filename); + NSLog(@"%@", filename); } [directory_ns_string release]; } +#endif external String_Const_u8 mac_standardize_path(Arena* arena, String_Const_u8 path){ diff --git a/platform_mac/mac_4ed_functions.cpp b/platform_mac/mac_4ed_functions.cpp index 1790e857..a61bca38 100644 --- a/platform_mac/mac_4ed_functions.cpp +++ b/platform_mac/mac_4ed_functions.cpp @@ -69,6 +69,7 @@ system_get_file_list_sig(){ entry = readdir(dir)){ char *c_file_name = entry->d_name; String_Const_u8 file_name = SCu8(c_file_name); + if (string_match(file_name, string_u8_litexpr(".")) || string_match(file_name, string_u8_litexpr(".."))){ continue; } @@ -78,12 +79,53 @@ system_get_file_list_sig(){ count += 1; info->file_name = push_string_copy(arena, file_name); - //info->attributes.size = + + // NOTE(yuval): Get file attributes + { + Temp_Memory temp = begin_temp(arena); + + b32 append_slash = false; + u64 file_path_size = directory.size + file_name.size; + if (string_get_character(directory, directory.size - 1) != '/') { + append_slash = true; + file_path_size += 1; + } + + char* file_path = push_array(arena, char, file_path_size + 1); + char* file_path_at = file_path; + + block_copy(file_path_at, directory.str, directory.size); + file_path_at += directory.size; + + if (append_slash) { + *file_path_at = '/'; + file_path_at += 1; + } + + block_copy(file_path_at, file_name.str, file_name.size); + file_path_at += file_name.size; + + *file_path_at = 0; + + printf("File Path: %s ", file_path); + + struct stat file_stat; + if (stat(file_path, &file_stat) == 0){ + info->attributes.size = file_stat.st_size; + info->attributes.last_write_time = ; + info->attributes.flags = ; + } else { + char* error_message = strerror(errno); + printf("ERROR: stat failed with error message '%s'!\n", error_message); + } + + end_temp(temp); + } /*++file_count; - i32 size = 0; - for (; fname[size]; ++size); - character_count += size + 1;*/ +i32 size = 0; +for (; fname[size]; ++size); +character_count += size + 1;*/ } #if 0 diff --git a/platform_unix/unix_4ed_functions.cpp b/platform_unix/unix_4ed_functions.cpp index 75e121fb..d6fe65b7 100644 --- a/platform_unix/unix_4ed_functions.cpp +++ b/platform_unix/unix_4ed_functions.cpp @@ -64,7 +64,7 @@ Sys_Memory_Allocate_Sig(system_memory_allocate){ return(result); } -internal +internal Sys_Memory_Set_Protection_Sig(system_memory_set_protection){ bool32 result = true;