xref: /original-bsd/old/eqn/checkeq/checkeq.c (revision bbb96de4)
1 /*
2  * Copyright (c) 1987 Regents of the University of California.
3  * All rights reserved.  The Berkeley software License Agreement
4  * specifies the terms and conditions for redistribution.
5  */
6 
7 #ifndef lint
8 char copyright[] =
9 "@(#) Copyright (c) 1987 Regents of the University of California.\n\
10  All rights reserved.\n";
11 #endif /* not lint */
12 
13 #ifndef lint
14 static char sccsid[] = "@(#)checkeq.c	4.3 (Berkeley) 12/02/87";
15 #endif /* not lint */
16 
17 #include <stdio.h>
18 FILE	*fin;
19 int	delim	= '$';
20 
21 main(argc, argv) char **argv; {
22 
23 	if (argc <= 1)
24 		check(stdin);
25 	else
26 		while (--argc > 0) {
27 			if ((fin = fopen(*++argv, "r")) == NULL) {
28 				perror(*argv);
29 				exit(1);
30 			}
31 			printf("%s:\n", *argv);
32 			check(fin);
33 			fclose(fin);
34 		}
35 	exit(0);
36 }
37 
38 check(f)
39 FILE	*f;
40 {
41 	int start, line, eq, ndel, totdel;
42 	char in[600], *p;
43 
44 	start = eq = line = ndel = totdel = 0;
45 	while (fgets(in, 600, f) != NULL) {
46 		line++;
47 		ndel = 0;
48 		for (p = in; *p; p++)
49 			if (*p == delim)
50 				ndel++;
51 		if (*in=='.' && *(in+1)=='E' && *(in+2)=='Q') {
52 			if (eq++)
53 				printf("   Spurious EQ, line %d\n", line);
54 			if (totdel)
55 				printf("   EQ in %c%c, line %d\n", delim, delim, line);
56 		} else if (*in=='.' && *(in+1)=='E' && *(in+2)=='N') {
57 			if (eq==0)
58 				printf("   Spurious EN, line %d\n", line);
59 			else
60 				eq = 0;
61 			if (totdel > 0)
62 				printf("   EN in %c%c, line %d\n", delim, delim, line);
63 			start = 0;
64 		} else if (eq && *in=='d' && *(in+1)=='e' && *(in+2)=='l' && *(in+3)=='i' && *(in+4)=='m') {
65 			for (p=in+5; *p; p++)
66 				if (*p != ' ') {
67 					if (*p == 'o' && *(p+1) == 'f')
68 						delim = 0;
69 					else
70 						delim = *p;
71 					break;
72 				}
73 			if (delim == 0)
74 				printf("   Delim off, line %d\n", line);
75 			else
76 				printf("   New delims %c%c, line %d\n", delim, delim, line);
77 		}
78 		if (ndel > 0 && eq > 0)
79 			printf("   %c%c in EQ, line %d\n", delim, delim, line);
80 		if (ndel == 0)
81 			continue;
82 		totdel += ndel;
83 		if (totdel%2) {
84 			if (start == 0)
85 				start = line;
86 			else {
87 				printf("   %d line %c%c, lines %d-%d\n", line-start+1, delim, delim, start, line);
88 				start = line;
89 			}
90 		} else {
91 			if (start > 0) {
92 				printf("   %d line %c%c, lines %d-%d\n", line-start+1, delim, delim, start, line);
93 				start = 0;
94 			}
95 			totdel = 0;
96 		}
97 	}
98 	if (totdel)
99 		printf("   Unfinished %c%c\n", delim, delim);
100 	if (eq)
101 		printf("   Unfinished EQ\n");
102 }
103