From 972d061e902983c524e126455994ef2b6edf8ab3 Mon Sep 17 00:00:00 2001 From: Loic Le Loarer Date: Thu, 16 Jul 2015 00:59:58 +0200 Subject: [PATCH] Allow multiple filename in the command line --- src/tools/uchardet.cpp | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/tools/uchardet.cpp b/src/tools/uchardet.cpp index b2b6bea..efa589b 100644 --- a/src/tools/uchardet.cpp +++ b/src/tools/uchardet.cpp @@ -88,7 +88,7 @@ void show_usage() { show_version(); printf("Usage:\n"); - printf(" uchardet [Options] [File]\n"); + printf(" uchardet [Options] [File]...\n"); printf("\n"); printf("Options:\n"); printf(" -v, --version Print version and build information.\n"); @@ -122,20 +122,24 @@ int main(int argc, char ** argv) } } - FILE * f = stdin; - if (argc == 2) + FILE * f = NULL; + int error_seen = 0; + for (int i = 1; i < argc; i++) { - f = fopen(argv[1], "r"); + char *filename = argv[i]; + f = fopen(filename, "r"); if (f == NULL) { - fprintf(stderr, "Cannot open file.\n"); - return 1; + fprintf(stderr, "Cannot open file '%s'\n", filename); + error_seen = 1; + continue; } + if (argc > 2) { + printf("%s: ", filename); + } + detect(f); + fclose(f); } - detect(f); - - fclose(f); - - return 0; + return error_seen; }