From 8039df673923235d5bdc5e921e48c6453f4c09fd Mon Sep 17 00:00:00 2001 From: NRK Date: Fri, 2 Dec 2022 04:08:21 +0600 Subject: [PATCH] fix argument ambiguity by using double-dash since it's valid for filenames to begin with a dash, there's an ambiguity on weather something like `-i` refers to the cli flag or a file named `-i`. the convention is to use a double-dash "--" as a way to mark the end of cli options so that everything that comes after it can be treated as arguments. Closes: https://github.com/mwh/dragon/issues/59 --- dragon.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/dragon.c b/dragon.c index 2e1e635..cdd46d8 100644 --- a/dragon.c +++ b/dragon.c @@ -516,6 +516,8 @@ int main (int argc, char **argv) { exit(1); } argv[i][0] = '\0'; + } else if (strcmp(argv[i], "--") == 0) { // "--" stops option processing + break; } else if (argv[i][0] == '-') { fprintf(stderr, "%s: error: unknown option `%s'.\n", progname, argv[i]); @@ -566,8 +568,10 @@ int main (int argc, char **argv) { else if (drag_all) uri_collection = malloc(sizeof(char*) * ((argc > MAX_SIZE ? argc : MAX_SIZE) + 1)); - for (int i=1; i