summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJehan <jehan@girinstud.io>2020-04-22 21:11:23 +0200
committerJehan <jehan@girinstud.io>2020-04-22 21:11:23 +0200
commitef0313046b7a92b9249e3b75c90a221dc3958bba (patch)
tree010fe31a0b2d32aa69165549323a2033a82a6e44
parent4a37dfdf1c709520f99e3d408e418c3446673af3 (diff)
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.
-rw-r--r--src/tools/uchardet.cpp6
1 files changed, 5 insertions, 1 deletions
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)