From 268758a21be25f9e0f3cf0c75fa83625d547ce91 Mon Sep 17 00:00:00 2001 From: Laan Tungir Date: Sun, 10 Aug 2025 14:57:51 -0400 Subject: [PATCH] Version v0.2.17 - Fix pad selection logic - allow flexible hex prefix matching instead of restrictive number selection --- .clinerules/workspace_rules.md | 4 ++ debug | Bin 0 -> 16008 bytes debug.c | 1 + otp.c | 77 +++++++++++++++++++++++---------- 4 files changed, 60 insertions(+), 22 deletions(-) create mode 100644 .clinerules/workspace_rules.md create mode 100755 debug create mode 100644 debug.c diff --git a/.clinerules/workspace_rules.md b/.clinerules/workspace_rules.md new file mode 100644 index 0000000..d84c98c --- /dev/null +++ b/.clinerules/workspace_rules.md @@ -0,0 +1,4 @@ + +When building, use build.sh, not make. + +Use it as follows: build.sh -m "useful comment on changes being made" \ No newline at end of file diff --git a/debug b/debug new file mode 100755 index 0000000000000000000000000000000000000000..0c48976f5d059b8ae7f10b26455e44e8d0c7b4b8 GIT binary patch literal 16008 zcmeHOYitzP6~4Q?Oas^uNO-icO_QpSdf2rWV?zlGwqYF^aE(zEDKN}>X6>!^;qJ~h zHcC@hG*vBvls?pl)K;q0Dt#c;KdOpUMKz_R=~M6z)c&AVkwB#l&?Y6V%J!T)=Uc|p zHIbtH=#RP5?03(1&v);gGk3;!JokR0w|`GG5>ZI=)Dw!W$rg`ENx`cfk|9W`PPLSN zH>mY$A=&da=ar{Cpi(bgiq6I+;pY*uZZ&5b;JZCq0ntN7*3FfUa)&4Zm7E9b7I1;s zL3~9T0HVC!UW~<*V*0m^L!txvb=;NdR?mNW$80<*aTyhaj!o9hh;Bx7z?;$@5b@-g z@X;yp3}T$hI01vYQPBml$CD`_x54S)Ro8wy?G1>|jp=Gs5R)FQfN1Z-q?1c49`^@a z=0Rz1uIn%$@drwH)#iLI(~;bqw_EeMVs*TAytAXVBWYAhMw@P!`xT>u$JE~ahZI#a z!<>XsMJGKQ^>NusDQEx7Pi%T>``2$g_nRZP-uTGKn@?VyIr~rc;eNA*eK>J_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oH0u9c z=k5yk6JEk|JC*T2>ff5X|(=(2?eAPA0s{n zu@8@Eo}MNtA4%B{5#OTL)Z>iOZsJ!&mn%Gn!1pl^!-vmEJ;C~O#K(Mo$c_`gJi10< z9D{#>d2T^O@|aRzAijmh!|D_~JH_iI0hoA1)BD{~_fkDgPJZS48Ql9vJ89;BeVZ7$sV|Ze?<&YmF!(DsDBKHHOu_ zW$vb1Fo$`edxbphk~xwuWvskuyQOl)w5sE3xKtR+JFa6J@x~s!20v$7<+3$lIz_iU zp|WNAXP#+S3xx@i_$-q=-C3@-lc|nShfH(N;I4hWX7BzUlh)VwJiUL{zP@gvX`h4H zo0iga&!95*_8-{2tKU4ZXV1ajA#-Tg?*3j<1egD(u*#oS_RCIyI>ihB@4MRHu`Sn9 z`ov`Wz-+C_<=$=pYI*k70Mo9N%u%ao^R|J$1LS4rie|Oq*owkKKW3&<5v|^*V4Aem z04L6S5E^bQn7!R$c6T_cN*R@jf@@_6-Li+H$k7G}r#z;NV##%kkz&;tE0@NcvOD3U zGSwVyX35z??b_Yf%7aF`k6M*cW!Mu%YQjUe?3H}XDOYl(;w;0Yva*x6SRlEvysHe| zO@p$=NQq3&RGeXDxXw74Jc`J>q(g5wqcUzrZK@5HSBE!%JO%R9lvT)4WuBZutPC2t z1safn8|H1AJP)E!hPw#;T>B#7A8h~k0sXgQo+t1Wgo45LuM$to zPW3&=E|}k9-(=7qHt-f{ntgiAr%$(XZTH5jXWg@*{|^=L*p=6U`aBo=V6oqo?>|n^ z;W~bgIF29mcz>MU%-%{3cu@a^9=MRie!WVGYurP$g9@O7>pG&_3pUEus(lb6ftj zT-q1+dJ*)G*BLJZy&o}l{H`gfa9ld}9x7Zx2l|8O?_%Q6cfbBLzfe)Sg@!y+$4asq Rc>3E&|D7$K*V?zx{}+YD9B2Rl literal 0 HcmV?d00001 diff --git a/debug.c b/debug.c new file mode 100644 index 0000000..7231826 --- /dev/null +++ b/debug.c @@ -0,0 +1 @@ +int main() { printf("Testing direct filename: %d\n", strncmp("97d9d82b5414a9439102f3811fb90ab1d6368a00d33229a18b306476f9d04f82.pad", "97", 2)); return 0; } diff --git a/otp.c b/otp.c index 01fc1a0..d0663ff 100644 --- a/otp.c +++ b/otp.c @@ -365,41 +365,53 @@ uint64_t parse_size_string(const char* size_str) { char* find_pad_by_prefix(const char* prefix) { DIR* dir = opendir(PADS_DIR); - if (!dir) return NULL; + if (!dir) { + printf("Error: Cannot open pads directory\n"); + return NULL; + } struct dirent* entry; char* matches[100]; // Store up to 100 matches int match_count = 0; // Check if it's a number (for interactive menu selection) + // Only treat as number if it's a single digit (1-9) to avoid conflicts with hex prefixes char* endptr; int selection = strtol(prefix, &endptr, 10); - if (*endptr == '\0' && selection > 0) { + if (*endptr == '\0' && selection > 0 && selection <= 9 && strlen(prefix) == 1) { // It's a number, find the nth pad int current = 0; rewinddir(dir); while ((entry = readdir(dir)) != NULL && match_count == 0) { - if (strstr(entry->d_name, ".pad") && strlen(entry->d_name) == 68) { // 64 char chksum + ".pad" - current++; - if (current == selection) { - matches[match_count] = malloc(65); - strncpy(matches[match_count], entry->d_name, 64); - matches[match_count][64] = '\0'; - match_count = 1; - } + // Skip . and .. entries, and only process .pad files + if (entry->d_name[0] == '.') continue; + if (!strstr(entry->d_name, ".pad")) continue; + if (strlen(entry->d_name) != 68) continue; // 64 char chksum + ".pad" + + current++; + if (current == selection) { + matches[match_count] = malloc(65); + strncpy(matches[match_count], entry->d_name, 64); + matches[match_count][64] = '\0'; + match_count = 1; + break; } } } else { // Find pads that start with the prefix size_t prefix_len = strlen(prefix); while ((entry = readdir(dir)) != NULL && match_count < 100) { - if (strstr(entry->d_name, ".pad") && strlen(entry->d_name) == 68) { - if (strncmp(entry->d_name, prefix, prefix_len) == 0) { - matches[match_count] = malloc(65); - strncpy(matches[match_count], entry->d_name, 64); - matches[match_count][64] = '\0'; - match_count++; - } + // Skip . and .. entries, and only process .pad files + if (entry->d_name[0] == '.') continue; + if (!strstr(entry->d_name, ".pad")) continue; + if (strlen(entry->d_name) != 68) continue; // 64 char chksum + ".pad" + + // Compare prefix with the filename (checksum part) + if (strncmp(entry->d_name, prefix, prefix_len) == 0) { + matches[match_count] = malloc(65); + strncpy(matches[match_count], entry->d_name, 64); + matches[match_count][64] = '\0'; + match_count++; } } } @@ -418,14 +430,35 @@ char* find_pad_by_prefix(const char* prefix) { printf("Multiple matches found for '%s':\n", prefix); for (int i = 0; i < match_count; i++) { printf("%d. %.16s...\n", i + 1, matches[i]); - if (i > 0) free(matches[i]); } - printf("Please be more specific.\n"); - char* result = matches[0]; - for (int i = 1; i < match_count; i++) { + printf("Please be more specific or enter a number (1-%d): ", match_count); + fflush(stdout); + + char choice_input[64]; + if (fgets(choice_input, sizeof(choice_input), stdin)) { + choice_input[strcspn(choice_input, "\n")] = 0; + + // Check if it's a number + char* endptr; + int choice = strtol(choice_input, &endptr, 10); + if (*endptr == '\0' && choice >= 1 && choice <= match_count) { + // Valid choice, return selected pad + char* result = matches[choice - 1]; + // Free the others + for (int i = 0; i < match_count; i++) { + if (i != choice - 1) { + free(matches[i]); + } + } + return result; + } + } + + // Invalid choice or no input, free all and return NULL + for (int i = 0; i < match_count; i++) { free(matches[i]); } - return result; + return NULL; } }