summaryrefslogtreecommitdiff
path: root/db/test/scr021/t.c
blob: a45865cfe2e4943c0c1d671f15e85b3891adfc9d (plain)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <sys/types.h>

#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <strings.h>

void
chk(f, str)
	char *f, *str;
{
	char *s;
	int ch, l, ok, pc;

	if (freopen(f, "r", stdin) == NULL) {
		fprintf(stderr, "%s: %s\n", f, strerror(errno));
		exit (1);
	}

	for (l = 1, ok = 1, s = str; (ch = getchar()) != EOF;) {
		if (ch == '\n')
			++l;
		if (!ok || ch != *s) {
			s = str;
			ok = !isalpha(ch) && !isdigit(ch) && ch != '_';
			continue;
		}
		if (*++s != '\0')
			continue;

		/* Match. */
		printf("%s: %d: %s", f, l, str);
		for (pc = 1; (ch = getchar()) != EOF;) {
			switch (ch) {
			case '(':
				++pc;
				break;
			case ')':
				--pc;
				break;
			case '\n':
				++l;
				break;
			}
			if (ch == '\n')
				putchar(' ');
			else
				putchar(ch);
			if (pc <= 0) {
				putchar('\n');
				break;
			}
		}
		s = str;
	}
}

int
main(int argc, char *argv[])
{
	int r;

	for (r = 0; *++argv != NULL;) {
		chk(*argv, "F_ISSET(");
		chk(*argv, "F_CLR(");
		chk(*argv, "F_SET(");
	}
	return (0);
}