-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilter.c
More file actions
38 lines (35 loc) · 1.01 KB
/
filter.c
File metadata and controls
38 lines (35 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
* filter.c
*
* This is a main program for any one of a number of simple utilities
* that each work as a filter, i.e. a programs that can be in a pipe,
* or take one or more files as parameters and output to stdout.
*/
#include <string.h>
#include <stdio.h>
int main(int argc, char **argv) {
int status = 0;
const char *progname, *filename, *ptr;
FILE *fp;
if (argc == 1)
filter(stdin, stdout);
else {
progname = *++argv;
if ((ptr = strrchr(progname, '.')))
progname = ptr+1;
while (--argc) {
filename = *argv++;
if (filename[0] == '-' && filename[1] == '\0')
filter(stdin, stdout);
else if ((fp = fopen(filename, "rb"))) {
filter(fp, stdout);
fclose(fp);
} else {
fprintf(stderr, "%s: unable to open %s for reading: %m\n",
progname, filename);
status++;
}
}
}
return status;
}