Compare commits

..

1 Commits

3 changed files with 8944 additions and 37 deletions

Binary file not shown.

83
otp.c
View File

@@ -151,6 +151,14 @@ int interactive_mode(void) {
} }
int command_line_mode(int argc, char* argv[]) { int command_line_mode(int argc, char* argv[]) {
// Check for help flags first
if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--h") == 0 ||
strcmp(argv[1], "-help") == 0 || strcmp(argv[1], "--help") == 0 ||
strcmp(argv[1], "help") == 0) {
print_usage(argv[0]);
return 0;
}
if (strcmp(argv[1], "generate") == 0 || strcmp(argv[1], "-g") == 0) { if (strcmp(argv[1], "generate") == 0 || strcmp(argv[1], "-g") == 0) {
if (argc != 3) { if (argc != 3) {
printf("Usage: %s generate|-g <size>\n", argv[0]); printf("Usage: %s generate|-g <size>\n", argv[0]);
@@ -374,44 +382,45 @@ char* find_pad_by_prefix(const char* prefix) {
char* matches[100]; // Store up to 100 matches char* matches[100]; // Store up to 100 matches
int match_count = 0; int match_count = 0;
// Check if it's a number (for interactive menu selection) // Always try hex prefix matching first
// Only treat as number if it's a single digit (1-9) to avoid conflicts with hex prefixes size_t prefix_len = strlen(prefix);
char* endptr; while ((entry = readdir(dir)) != NULL && match_count < 100) {
int selection = strtol(prefix, &endptr, 10); // Skip . and .. entries, and only process .pad files
if (*endptr == '\0' && selection > 0 && selection <= 9 && strlen(prefix) == 1) { if (entry->d_name[0] == '.') continue;
// It's a number, find the nth pad if (!strstr(entry->d_name, ".pad")) continue;
int current = 0; if (strlen(entry->d_name) != 68) continue; // 64 char chksum + ".pad"
rewinddir(dir);
while ((entry = readdir(dir)) != NULL && match_count == 0) { // Compare prefix with the filename (checksum part)
// Skip . and .. entries, and only process .pad files if (strncmp(entry->d_name, prefix, prefix_len) == 0) {
if (entry->d_name[0] == '.') continue; matches[match_count] = malloc(65);
if (!strstr(entry->d_name, ".pad")) continue; strncpy(matches[match_count], entry->d_name, 64);
if (strlen(entry->d_name) != 68) continue; // 64 char chksum + ".pad" matches[match_count][64] = '\0';
match_count++;
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); // If no hex prefix matches and it looks like a small number, try number selection
while ((entry = readdir(dir)) != NULL && match_count < 100) { if (match_count == 0) {
// Skip . and .. entries, and only process .pad files char* endptr;
if (entry->d_name[0] == '.') continue; int selection = strtol(prefix, &endptr, 10);
if (!strstr(entry->d_name, ".pad")) continue; if (*endptr == '\0' && selection > 0 && selection <= 100) {
if (strlen(entry->d_name) != 68) continue; // 64 char chksum + ".pad" // It's a number, find the nth pad
int current = 0;
// Compare prefix with the filename (checksum part) rewinddir(dir);
if (strncmp(entry->d_name, prefix, prefix_len) == 0) { while ((entry = readdir(dir)) != NULL) {
matches[match_count] = malloc(65); // Skip . and .. entries, and only process .pad files
strncpy(matches[match_count], entry->d_name, 64); if (entry->d_name[0] == '.') continue;
matches[match_count][64] = '\0'; if (!strstr(entry->d_name, ".pad")) continue;
match_count++; 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;
}
} }
} }
} }

8898
toc.txt Executable file

File diff suppressed because it is too large Load Diff