summaryrefslogtreecommitdiff
path: root/db/test/scr005/chk.nl
blob: 876be2f9464dc7fe7160a18306f009522303dc4b (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/sh -
#
# Id: chk.nl,v 1.5 2001/10/12 17:55:33 bostic Exp 
#
# Check to make sure that there are no trailing newlines in __db_err calls.

d=../..

[ -f $d/README ] || {
	echo "FAIL: chk.nl can't find the source directory."
	exit 1
}

cat << END_OF_CODE > t.c
#include <sys/types.h>

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

int chk(FILE *, char *);

int
main(argc, argv)
	int argc;
	char *argv[];
{
	FILE *fp;
	int exitv;

	for (exitv = 0; *++argv != NULL;) {
		if ((fp = fopen(*argv, "r")) == NULL) {
			fprintf(stderr, "%s: %s\n", *argv, strerror(errno));
			return (1);
		}
		if (chk(fp, *argv))
			exitv = 1;
		(void)fclose(fp);
	}
	return (exitv);
}

int
chk(fp, name)
	FILE *fp;
	char *name;
{
	int ch, exitv, line, q;

	exitv = 0;
	for (ch = 'a', line = 1;;) {
		if ((ch = getc(fp)) == EOF)
			return (exitv);
		if (ch == '\n') {
			++line;
			continue;
		}
		if (ch != '_') continue;
		if ((ch = getc(fp)) != '_') continue;
		if ((ch = getc(fp)) != 'd') continue;
		if ((ch = getc(fp)) != 'b') continue;
		if ((ch = getc(fp)) != '_') continue;
		if ((ch = getc(fp)) != 'e') continue;
		if ((ch = getc(fp)) != 'r') continue;
		if ((ch = getc(fp)) != 'r') continue;
		while ((ch = getc(fp)) != '"') {
			if (ch == EOF)
				return (exitv);
			if (ch == '\n')
				++line;
		}
		while ((ch = getc(fp)) != '"') {
			if (ch == EOF)
				return (exitv);
			if (ch == '\n')
				++line;
			if (ch == '\\\\')
				if ((ch = getc(fp)) != 'n')
					ungetc(ch, fp);
				else if ((ch = getc(fp)) != '"')
					ungetc(ch, fp);
				else {
					fprintf(stderr,
				    "%s: <newline> at line %d\n", name, line);
					exitv = 1;
				}
		}
	}
	return (exitv);
}
END_OF_CODE

cc t.c -o t
if ./t $d/*/*.[ch] $d/*/*.cpp $d/*/*.in ; then
	:
else
	echo "FAIL: found __db_err calls with newline strings."
	exit 1
fi

exit 0