Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 268758a21b |
4
.clinerules/workspace_rules.md
Normal file
4
.clinerules/workspace_rules.md
Normal file
@@ -0,0 +1,4 @@
|
||||
|
||||
When building, use build.sh, not make.
|
||||
|
||||
Use it as follows: build.sh -m "useful comment on changes being made"
|
||||
1
debug.c
Normal file
1
debug.c
Normal file
@@ -0,0 +1 @@
|
||||
int main() { printf("Testing direct filename: %d\n", strncmp("97d9d82b5414a9439102f3811fb90ab1d6368a00d33229a18b306476f9d04f82.pad", "97", 2)); return 0; }
|
||||
53
otp.c
53
otp.c
@@ -365,35 +365,48 @@ 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"
|
||||
// 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) {
|
||||
// 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);
|
||||
@@ -402,7 +415,6 @@ char* find_pad_by_prefix(const char* prefix) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
closedir(dir);
|
||||
|
||||
@@ -418,17 +430,38 @@ 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 NULL;
|
||||
}
|
||||
}
|
||||
|
||||
int list_available_pads(void) {
|
||||
DIR* dir = opendir(PADS_DIR);
|
||||
if (!dir) {
|
||||
|
||||
Reference in New Issue
Block a user