diff --git a/binaries/changelog.txt b/binaries/changelog.txt index 5141be6..2f24deb 100644 --- a/binaries/changelog.txt +++ b/binaries/changelog.txt @@ -43,3 +43,5 @@ Making the MPMC queue support when producers are consumers at the same time by a Replacing DirQueue, a queue growable with realloc with the MPMC queue 4.1: Using xxhash xxh_x86dispatch to select the best SIMD instruction set at runtime, this dispatcher can not be added in a unity build and we must remove AVX2 or AVX512 compilation flags, link xxh_x86dispatch.c in the compilation command. The compilaiton throws two warnings about function with internal linkage but not defined, they are defined in xxh_x86dispatch.c so it's harmless warnings + +Fixing user prompt parsing diff --git a/platform_windows.c b/platform_windows.c index 6ef0060..36323df 100644 --- a/platform_windows.c +++ b/platform_windows.c @@ -1,3 +1,4 @@ +#include "base.h" #include "platform.h" // ----------------------------- Globals ------------------------------------ @@ -36,7 +37,7 @@ const char *get_xxhash_instruction_set(void) { } } -// ----------------------------- Normalize path -------------- +// -------------------- Path parsing ------------------- static void normalize_path(char *p) { char *src = p; char *dst = p; @@ -59,6 +60,52 @@ static void normalize_path(char *p) { *dst = '\0'; } +static int parse_paths(char *line, char folders[][MAX_PATHLEN], + int max_folders) { + int count = 0; + char *p = line; + + while (*p && count < max_folders) { + + while (*p && isspace((unsigned char)*p)) + p++; + + if (!*p) + break; + + char *start; + char quote = 0; + + if (*p == '"' || *p == '\'') { + quote = *p++; + start = p; + + while (*p && *p != quote) + p++; + } else { + start = p; + + while (*p && !isspace((unsigned char)*p)) + p++; + } + + size_t len = p - start; + if (len >= MAX_PATHLEN) + len = MAX_PATHLEN - 1; + + memcpy(folders[count], start, len); + folders[count][len] = 0; + + normalize_path(folders[count]); + + count++; + + if (quote && *p == quote) + p++; + } + return count; +} + // ----------------------------- Convert filetime to epoch -------------- static uint64_t filetime_to_epoch(const FILETIME *ft) { ULARGE_INTEGER ull; @@ -365,22 +412,12 @@ int main(int argc, char **argv) { char folders[64][MAX_PATHLEN]; // up to 64 input folders int folder_count = 0; - // ------------------------------- - // Scanning and total timer init - // ------------------------------- - timer_init(); - - HiResTimer total_timer; - HiResTimer scan_timer; - - timer_start(&total_timer); - timer_start(&scan_timer); - // ------------------------------- // Parse arguments // ------------------------------- for (int i = 1; i < argc; ++i) { if (folder_count < 64) { + normalize_path(argv[i]); strncpy(folders[folder_count], argv[i], MAX_PATHLEN - 1); folders[folder_count][MAX_PATHLEN - 1] = 0; folder_count++; @@ -391,20 +428,22 @@ int main(int argc, char **argv) { // Ask user if no folders provided // ------------------------------- if (folder_count == 0) { - printf("Enter folder to process (Enter = current folder): "); + printf("Enter folders to process (Enter = current folder): "); fflush(stdout); - char buf[MAX_PATHLEN]; + char buf[KiB(32)]; + if (!fgets(buf, sizeof(buf), stdin)) return 1; + buf[strcspn(buf, "\r\n")] = 0; - if (buf[0] == 0) + if (buf[0] == 0) { strcpy(folders[0], "."); - else - strncpy(folders[0], buf, MAX_PATHLEN - 1); - - folder_count = 1; + folder_count = 1; + } else { + folder_count = parse_paths(buf, folders, 64); + } } // Display selected folders @@ -413,6 +452,17 @@ int main(int argc, char **argv) { printf(" - %s\n", folders[i]); } + // ------------------------------- + // Scanning and total timer init + // ------------------------------- + timer_init(); + + HiResTimer total_timer; + HiResTimer scan_timer; + + timer_start(&total_timer); + timer_start(&scan_timer); + // ------------------------------- // Creating a general purpose arena // -------------------------------