mirror of
https://gitlab.freedesktop.org/uchardet/uchardet.git
synced 2025-12-07 09:16:42 +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 <cstdlib>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#ifndef VERSION
|
#ifndef VERSION
|
||||||
#define VERSION "Unknown"
|
#define VERSION "Unknown"
|
||||||
@ -88,7 +89,7 @@ void show_usage()
|
|||||||
{
|
{
|
||||||
show_version();
|
show_version();
|
||||||
printf("Usage:\n");
|
printf("Usage:\n");
|
||||||
printf(" uchardet [Options] [File]\n");
|
printf(" uchardet [Options] [File]...\n");
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf("Options:\n");
|
printf("Options:\n");
|
||||||
printf(" -v, --version Print version and build information.\n");
|
printf(" -v, --version Print version and build information.\n");
|
||||||
@ -123,19 +124,28 @@ int main(int argc, char ** argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
FILE * f = stdin;
|
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)
|
if (f == NULL)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Cannot open file.\n");
|
perror(filename);
|
||||||
return 1;
|
error_seen = 1;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
if (argc > 2)
|
||||||
|
{
|
||||||
|
printf("%s: ", filename);
|
||||||
|
}
|
||||||
|
detect(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
detect(f);
|
return error_seen;
|
||||||
|
|
||||||
fclose(f);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user