mirror of
https://gitlab.freedesktop.org/uchardet/uchardet.git
synced 2025-12-06 16:56:40 +08:00
Merge pull request #5 from llloic11/master
Multple filename in command line
This commit is contained in:
commit
47316bb194
@ -40,6 +40,7 @@
|
||||
#include <cstdlib>
|
||||
#include <getopt.h>
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
|
||||
#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);
|
||||
|
||||
fclose(f);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return error_seen;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user