Work on system_get_file_list. File attribute retrieval now works.

master
Yuval Dolev 2019-12-26 17:54:06 +02:00
parent 3131e45c12
commit ea29a6e13e
4 changed files with 58 additions and 7 deletions

View File

@ -38,8 +38,13 @@
#include "mac_objective_c_to_cpp_links.h" #include "mac_objective_c_to_cpp_links.h"
#include <errno.h>
#include <string.h>
#include <unistd.h> // NOTE(yuval): Used for getcwd #include <unistd.h> // NOTE(yuval): Used for getcwd
#include <dirent.h> // NOTE(yuval): Used for opendir, readdir #include <dirent.h> // NOTE(yuval): Used for opendir, readdir
#include <sys/types.h> // NOTE(yuval): Used for struct stat
#include <sys/stat.h> // NOTE(yuval): Used for stat
#include <stdlib.h> // NOTE(yuval): Used for free #include <stdlib.h> // NOTE(yuval): Used for free
@ -95,6 +100,7 @@ mac_init(){
system_get_file_list(&test_arena, system_get_file_list(&test_arena,
string_u8_litexpr("/Users/yuvaldolev/Desktop")); string_u8_litexpr("/Users/yuvaldolev/Desktop"));
#if 0
// NOTE(yuval): Context Setup // NOTE(yuval): Context Setup
Thread_Context _tctx = {}; Thread_Context _tctx = {};
thread_ctx_init(&_tctx, ThreadKind_Main, thread_ctx_init(&_tctx, ThreadKind_Main,
@ -117,7 +123,6 @@ mac_init(){
mac_vars.frame_arena = reserve_arena(mac_vars.tctx); mac_vars.frame_arena = reserve_arena(mac_vars.tctx);
target.arena = make_arena_system(KB(256)); target.arena = make_arena_system(KB(256));
#if 0
mac_vars.cursor_show = MouseCursorShow_Always; mac_vars.cursor_show = MouseCursorShow_Always;
mac_vars.prev_cursor_show = MouseCursorShow_Always; mac_vars.prev_cursor_show = MouseCursorShow_Always;

View File

@ -2,9 +2,11 @@
#include "4coder_base_types.h" #include "4coder_base_types.h"
#if 0
#include "4coder_table.h" #include "4coder_table.h"
#include "4coder_events.h" #include "4coder_events.h"
#include "4coder_types.h" #include "4coder_types.h"
#endif
#include "mac_objective_c_to_cpp_links.h" #include "mac_objective_c_to_cpp_links.h"
@ -45,6 +47,7 @@
} }
@end @end
#if 0
external File_List external File_List
mac_get_file_list(Arena* arena, String_Const_u8 directory){ mac_get_file_list(Arena* arena, String_Const_u8 directory){
File_List result = {}; File_List result = {};
@ -58,11 +61,12 @@ mac_get_file_list(Arena* arena, String_Const_u8 directory){
NSString *filename; NSString *filename;
while ((filename = [dirEnum nextObject])){ while ((filename = [dirEnum nextObject])){
NSLog(filename); NSLog(@"%@", filename);
} }
[directory_ns_string release]; [directory_ns_string release];
} }
#endif
external String_Const_u8 external String_Const_u8
mac_standardize_path(Arena* arena, String_Const_u8 path){ mac_standardize_path(Arena* arena, String_Const_u8 path){

View File

@ -69,6 +69,7 @@ system_get_file_list_sig(){
entry = readdir(dir)){ entry = readdir(dir)){
char *c_file_name = entry->d_name; char *c_file_name = entry->d_name;
String_Const_u8 file_name = SCu8(c_file_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(".."))){ if (string_match(file_name, string_u8_litexpr(".")) || string_match(file_name, string_u8_litexpr(".."))){
continue; continue;
} }
@ -78,12 +79,53 @@ system_get_file_list_sig(){
count += 1; count += 1;
info->file_name = push_string_copy(arena, file_name); 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; /*++file_count;
i32 size = 0; i32 size = 0;
for (; fname[size]; ++size); for (; fname[size]; ++size);
character_count += size + 1;*/ character_count += size + 1;*/
} }
#if 0 #if 0