stest: restore stream testing 6b1d658d
Connor Lane Smith · 2011-12-09 11:49 2 file(s) · +10 −2
stest.1 +2 −1
13 13
.B stest
14 14
takes a list of files and filters by the files' properties, analogous to
15 15
.IR test (1).
16 -
Files which pass all tests are printed to stdout.
16 +
Files which pass all tests are printed to stdout. If no files are given, stest
17 +
reads files from stdin.
17 18
.SH OPTIONS
18 19
.TP
19 20
.B \-a
stest.c +8 −1
3 3
#include <stdbool.h>
4 4
#include <stdio.h>
5 5
#include <stdlib.h>
6 +
#include <string.h>
6 7
#include <unistd.h>
7 8
#include <sys/stat.h>
8 9
17 18
int
18 19
main(int argc, char *argv[]) {
19 20
	struct dirent *d;
20 -
	char buf[BUFSIZ];
21 +
	char buf[BUFSIZ], *p;
21 22
	DIR *dir;
22 23
	int opt;
23 24
34 35
		case '?': /* error: unknown flag */
35 36
			fprintf(stderr, "usage: %s [-abcdefghlpqrsuwx] [-n file] [-o file] [file...]\n", argv[0]);
36 37
			exit(2);
38 +
		}
39 +
	if(optind == argc)
40 +
		while(fgets(buf, sizeof buf, stdin)) {
41 +
			if((p = strchr(buf, '\n')))
42 +
				*p = '\0';
43 +
			test(buf, buf);
37 44
		}
38 45
	for(; optind < argc; optind++)
39 46
		if(FLAG('l') && (dir = opendir(argv[optind]))) {