cat: ARGBEGIN
This commit is contained in:
parent
79e2f3ec19
commit
171ef71c74
18
cat.c
18
cat.c
@ -9,15 +9,19 @@ int
|
|||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
int i;
|
||||||
|
|
||||||
if(getopt(argc, argv, "") != -1)
|
ARGBEGIN {
|
||||||
exit(EXIT_FAILURE);
|
default:
|
||||||
if(optind == argc)
|
eprintf("usage: %s [files...]\n", argv0);
|
||||||
|
} ARGEND;
|
||||||
|
|
||||||
|
if(argc == 0)
|
||||||
concat(stdin, "<stdin>", stdout, "<stdout>");
|
concat(stdin, "<stdin>", stdout, "<stdout>");
|
||||||
else for(; optind < argc; optind++) {
|
else for(i = 0; i < argc; i++) {
|
||||||
if(!(fp = fopen(argv[optind], "r")))
|
if(!(fp = fopen(argv[i], "r")))
|
||||||
eprintf("fopen %s:", argv[optind]);
|
eprintf("fopen %s:", argv[i]);
|
||||||
concat(fp, argv[optind], stdout, "<stdout>");
|
concat(fp, argv[i], stdout, "<stdout>");
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
Loading…
Reference in New Issue
Block a user