Fixing user prompt parsing
This commit is contained in:
@@ -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
|
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
|
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
|
||||||
|
|||||||
@@ -365,22 +365,12 @@ int main(int argc, char **argv) {
|
|||||||
char folders[64][MAX_PATHLEN]; // up to 64 input folders
|
char folders[64][MAX_PATHLEN]; // up to 64 input folders
|
||||||
int folder_count = 0;
|
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
|
// Parse arguments
|
||||||
// -------------------------------
|
// -------------------------------
|
||||||
for (int i = 1; i < argc; ++i) {
|
for (int i = 1; i < argc; ++i) {
|
||||||
if (folder_count < 64) {
|
if (folder_count < 64) {
|
||||||
|
normalize_path(argv[i]);
|
||||||
strncpy(folders[folder_count], argv[i], MAX_PATHLEN - 1);
|
strncpy(folders[folder_count], argv[i], MAX_PATHLEN - 1);
|
||||||
folders[folder_count][MAX_PATHLEN - 1] = 0;
|
folders[folder_count][MAX_PATHLEN - 1] = 0;
|
||||||
folder_count++;
|
folder_count++;
|
||||||
@@ -391,20 +381,64 @@ int main(int argc, char **argv) {
|
|||||||
// Ask user if no folders provided
|
// Ask user if no folders provided
|
||||||
// -------------------------------
|
// -------------------------------
|
||||||
if (folder_count == 0) {
|
if (folder_count == 0) {
|
||||||
printf("Enter folder to process (Enter = current folder): ");
|
printf("Enter folders to process (Enter = current folder): ");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
||||||
char buf[MAX_PATHLEN];
|
char buf[1024]; // Larger buffer for multiple paths
|
||||||
if (!fgets(buf, sizeof(buf), stdin))
|
if (!fgets(buf, sizeof(buf), stdin))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
// Remove trailing newline
|
||||||
buf[strcspn(buf, "\r\n")] = 0;
|
buf[strcspn(buf, "\r\n")] = 0;
|
||||||
|
|
||||||
if (buf[0] == 0)
|
// Skip if empty input
|
||||||
|
if (buf[0] == 0) {
|
||||||
strcpy(folders[0], ".");
|
strcpy(folders[0], ".");
|
||||||
else
|
|
||||||
strncpy(folders[0], buf, MAX_PATHLEN - 1);
|
|
||||||
|
|
||||||
folder_count = 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;
|
||||||
|
|
||||||
|
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
|
// Display selected folders
|
||||||
@@ -413,6 +447,17 @@ int main(int argc, char **argv) {
|
|||||||
printf(" - %s\n", folders[i]);
|
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
|
// Creating a general purpose arena
|
||||||
// -------------------------------
|
// -------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user