From 3f74beefdc8bd60c0cac4c4b532cb47dd0f12e5a Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Fri, 5 Jul 2024 15:00:50 +0900 Subject: [PATCH] WIP Windows impl. --- src/parser.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/parser.c b/src/parser.c index c14f2aa..9419f4c 100644 --- a/src/parser.c +++ b/src/parser.c @@ -31,6 +31,10 @@ #include #include #include +#elif SIMPLE_ARCHIVER_PLATFORM == SIMPLE_ARCHIVER_PLATFORM_WINDOWS +#include +#include +#include #endif #include "data_structures/hash_map.h" @@ -61,7 +65,11 @@ unsigned int simple_archiver_parser_internal_filename_idx( } else if ((flags & 3) == 1) { if (filename[idx] == 0) { return known_good_idx; +#if SIMPLE_ARCHIVER_PLATFORM != SIMPLE_ARCHIVER_PLATFORM_WINDOWS } else if (filename[idx] == '/') { +#else + } else if (filename[idx] == '\\') { +#endif flags |= 2; } else { return idx - 1; @@ -69,7 +77,11 @@ unsigned int simple_archiver_parser_internal_filename_idx( } else if ((flags & 3) == 3) { if (filename[idx] == 0) { return known_good_idx; +#if SIMPLE_ARCHIVER_PLATFORM != SIMPLE_ARCHIVER_PLATFORM_WINDOWS } else if (filename[idx] == '/') { +#else + } else if (filename[idx] == '\\') { +#endif continue; } else if (filename[idx] == '.') { flags &= 0xFFFFFFFC; @@ -103,6 +115,34 @@ void simple_archiver_parser_internal_remove_end_slash(char *filename) { } } +char *simple_archiver_internal_forward_to_backward_slash(const char *string) { + unsigned int len = strlen(string) + 1; + char *backward_slash_string = malloc(len); + strncpy(backward_slash_string, string, len); + + for (unsigned int idx = 0; idx < len; ++idx) { + if (backward_slash_string[idx] == '/') { + backward_slash_string[idx] = '\\'; + } + } + + return backward_slash_string; +} + +char *simple_archiver_internal_backward_to_forward_slash(const char *string) { + unsigned int len = strlen(string) + 1; + char *forward_slash_string = malloc(len); + strncpy(forward_slash_string, string, len); + + for (unsigned int idx = 0; idx < len; ++idx) { + if (forward_slash_string[idx] == '\\') { + forward_slash_string[idx] = '/'; + } + } + + return forward_slash_string; +} + void simple_archiver_internal_free_file_info_fn(void *data) { SDArchiverFileInfo *file_info = data; if (file_info) { @@ -418,6 +458,8 @@ SDArchiverLinkedList *simple_archiver_parsed_to_filenames( // Unhandled type. TODO handle this. } } +#elif SIMPLE_ARCHIVER_PLATFORM == SIMPLE_ARCHIVER_PLATFORM_WINDOWS +/* DWORD file_stats = GetFileAttributesA(*/ #endif // Remove leading "./" entries from files_list.