diff options
Diffstat (limited to 'src/main.c')
| -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; |
