From ef0313046b7a92b9249e3b75c90a221dc3958bba Mon Sep 17 00:00:00 2001 From: Jehan Date: Wed, 22 Apr 2020 21:11:23 +0200 Subject: [PATCH] Also allow uchardet tool to detect encoding of a file named "--". My previous commit was good except for the very special case of wanting to analyze a file named "--". This file would be ignored. With this change, only the first "--" option will be ignored as meaning "end of option arguments", but any remaining value (another "--" included) will be considered as a file path. --- src/tools/uchardet.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/tools/uchardet.cpp b/src/tools/uchardet.cpp index e8fface..c6bf5f4 100644 --- a/src/tools/uchardet.cpp +++ b/src/tools/uchardet.cpp @@ -106,6 +106,7 @@ int main(int argc, char ** argv) { "help", no_argument, NULL, 'h' }, { 0, 0, 0, 0 }, }; + bool end_options = false; static int oc; while((oc = getopt_long(argc, argv, "vh", longopts, NULL)) != -1) @@ -136,8 +137,11 @@ int main(int argc, char ** argv) { const char *filename = argv[i]; - if (strcmp(filename, "--") == 0) + if (! end_options && strcmp(filename, "--") == 0) + { + end_options = true; continue; + } f = fopen(filename, "r"); if (f == NULL)