Fixing user prompt parsing

This commit is contained in:
2026-03-13 17:56:29 +01:00
parent d35858df01
commit 104cdc2b5e
2 changed files with 65 additions and 17 deletions

View File

@@ -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

View File

@@ -1,3 +1,4 @@
#include "base.h"
#include "platform.h"
// ----------------------------- Globals ------------------------------------
@@ -365,22 +366,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 +382,64 @@ 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(4)];
if (!fgets(buf, sizeof(buf), stdin))
return 1;
// Remove trailing newline
buf[strcspn(buf, "\r\n")] = 0;
if (buf[0] == 0)
// Skip if empty input
if (buf[0] == 0) {
strcpy(folders[0], ".");
else
strncpy(folders[0], buf, MAX_PATHLEN - 1);
folder_count = 1;
} else {
// Parse the input line with support for quoted strings
char *p = buf;
while (*p && folder_count < 64) {
// Skip whitespace
while (*p == ' ' || *p == '\t')
p++;
if (*p == 0)
break;
folder_count = 1;
char *start;
char quote_char = 0;
// Check for quoted string
if (*p == '"' || *p == '\'') {
quote_char = *p;
p++; // Skip opening quote
start = p;
// Find closing quote
while (*p && *p != quote_char)
p++;
} else {
start = p;
// Find end of unquoted token
while (*p && *p != ' ' && *p != '\t')
p++;
}
// Extract the path
int len = p - start;
if (len > 0 && len < MAX_PATHLEN) {
normalize_path(start);
strncpy(folders[folder_count], start, len);
folders[folder_count][len] = 0;
folder_count++;
}
// If we stopped at a closing quote, skip it
if (quote_char && *p == quote_char) {
p++;
}
}
}
}
// Display selected folders
@@ -413,6 +448,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
// -------------------------------