diff --git a/src/tools/uchardet.cpp b/src/tools/uchardet.cpp index b2b6bea..6ea5131 100644 --- a/src/tools/uchardet.cpp +++ b/src/tools/uchardet.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #ifndef VERSION #define VERSION "Unknown" @@ -88,7 +89,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"); @@ -123,19 +124,28 @@ int main(int argc, char ** argv) } FILE * f = stdin; - if (argc == 2) + int error_seen = 0; + if (argc < 2) { - f = fopen(argv[1], "r"); + // No file arg, use stdin by default + detect(f); + } + for (int i = 1; i < argc; i++) + { + const char *filename = argv[i]; + f = fopen(filename, "r"); if (f == NULL) { - fprintf(stderr, "Cannot open file.\n"); - return 1; + perror(filename); + error_seen = 1; + continue; } + if (argc > 2) + { + printf("%s: ", filename); + } + detect(f); } - detect(f); - - fclose(f); - - return 0; + return error_seen; }