diff options
| author | Tristan Riehs <tristan.riehs@inria.fr> | 2026-07-12 10:33:18 +0200 |
|---|---|---|
| committer | Tristan Riehs <tristan.riehs@inria.fr> | 2026-07-12 10:33:18 +0200 |
| commit | 809f3ccb18b38e06b054101bde04316f01fc2b44 (patch) | |
| tree | c354f29e1be780eceb2391a6cf6f12ae6f2bfa2c | |
| parent | 2fb55a9582536ee85a1912d76fd4d359fa3c8555 (diff) | |
Use getopt for ftag file add
| -rw-r--r-- | src/main.c | 16 |
1 files changed, 7 insertions, 9 deletions
@@ -502,9 +502,9 @@ static void ftag_file_add(int argc, char **argv) int interactive = 0; int eliminate_duplicates = 1; int encrypt = 1; - /* TODO: use getopt here */ - while ((argc > 0) && (argv[0][0] == '-')) { - switch (argv[0][1]) { + int opt; + while ((opt = getopt(argc, argv, "cfhi")) != -1) { + switch (opt) { case 'c': encrypt = 0; break; @@ -521,11 +521,9 @@ static void ftag_file_add(int argc, char **argv) ftag_file_add_usage(); exit(EXIT_FAILURE); } - argv++; - argc--; } - if (argc == 1) { + if (argc - optind == 1) { ftag_file_add_usage(); exit(EXIT_FAILURE); } @@ -535,7 +533,7 @@ static void ftag_file_add(int argc, char **argv) uint32_t *sums = malloc(argc*sizeof(*sums)); struct stat st; int rc; - for (int i = 1; i < argc; i++) { + for (int i = optind; i < argc; i++) { char *file = argv[i]; rc = stat(file, &st); if (rc == -1) { @@ -571,7 +569,7 @@ static void ftag_file_add(int argc, char **argv) /* step 3: eliminate duplicates with respect to file sum */ - for (int i = 0; i < argc; i++) { + for (int i = optind; i < argc; i++) { const uint32_t original = sums[i]; /* step 3.1: eliminate duplicates found in database */ for (int j = 0; j < file_count; j++) { @@ -598,7 +596,7 @@ static void ftag_file_add(int argc, char **argv) /* step 4: perform addition to database */ step4: - for (int i = 0; i < argc; i++) { + for (int i = optind; i < argc; i++) { char *file = argv[i]; if (file == NULL) continue; |
