xref: /csrg-svn/old/eqn/checkeq/checkeq.c (revision 48251)
1*48251Sbostic /*-
2*48251Sbostic  * Copyright (c) 1987 The Regents of the University of California.
3*48251Sbostic  * All rights reserved.
4*48251Sbostic  *
5*48251Sbostic  * %sccs.include.proprietary.c%
632743Sbostic  */
732743Sbostic 
832743Sbostic #ifndef lint
932743Sbostic char copyright[] =
10*48251Sbostic "@(#) Copyright (c) 1987 The Regents of the University of California.\n\
1132743Sbostic  All rights reserved.\n";
1232743Sbostic #endif /* not lint */
1332743Sbostic 
1432743Sbostic #ifndef lint
15*48251Sbostic static char sccsid[] = "@(#)checkeq.c	4.4 (Berkeley) 04/17/91";
1632743Sbostic #endif /* not lint */
1732743Sbostic 
18968Sbill #include <stdio.h>
19968Sbill FILE	*fin;
20968Sbill int	delim	= '$';
21968Sbill 
main(argc,argv)22968Sbill main(argc, argv) char **argv; {
23968Sbill 
24968Sbill 	if (argc <= 1)
25968Sbill 		check(stdin);
26968Sbill 	else
27968Sbill 		while (--argc > 0) {
28968Sbill 			if ((fin = fopen(*++argv, "r")) == NULL) {
2912098Smckusick 				perror(*argv);
30968Sbill 				exit(1);
31968Sbill 			}
32968Sbill 			printf("%s:\n", *argv);
33968Sbill 			check(fin);
34968Sbill 			fclose(fin);
35968Sbill 		}
3632743Sbostic 	exit(0);
37968Sbill }
38968Sbill 
check(f)39968Sbill check(f)
40968Sbill FILE	*f;
41968Sbill {
42968Sbill 	int start, line, eq, ndel, totdel;
43968Sbill 	char in[600], *p;
44968Sbill 
45968Sbill 	start = eq = line = ndel = totdel = 0;
46968Sbill 	while (fgets(in, 600, f) != NULL) {
47968Sbill 		line++;
48968Sbill 		ndel = 0;
49968Sbill 		for (p = in; *p; p++)
50968Sbill 			if (*p == delim)
51968Sbill 				ndel++;
52968Sbill 		if (*in=='.' && *(in+1)=='E' && *(in+2)=='Q') {
53968Sbill 			if (eq++)
54968Sbill 				printf("   Spurious EQ, line %d\n", line);
55968Sbill 			if (totdel)
56968Sbill 				printf("   EQ in %c%c, line %d\n", delim, delim, line);
57968Sbill 		} else if (*in=='.' && *(in+1)=='E' && *(in+2)=='N') {
58968Sbill 			if (eq==0)
59968Sbill 				printf("   Spurious EN, line %d\n", line);
60968Sbill 			else
61968Sbill 				eq = 0;
62968Sbill 			if (totdel > 0)
63968Sbill 				printf("   EN in %c%c, line %d\n", delim, delim, line);
64968Sbill 			start = 0;
65968Sbill 		} else if (eq && *in=='d' && *(in+1)=='e' && *(in+2)=='l' && *(in+3)=='i' && *(in+4)=='m') {
66968Sbill 			for (p=in+5; *p; p++)
67968Sbill 				if (*p != ' ') {
68968Sbill 					if (*p == 'o' && *(p+1) == 'f')
69968Sbill 						delim = 0;
70968Sbill 					else
71968Sbill 						delim = *p;
72968Sbill 					break;
73968Sbill 				}
74968Sbill 			if (delim == 0)
75968Sbill 				printf("   Delim off, line %d\n", line);
76968Sbill 			else
77968Sbill 				printf("   New delims %c%c, line %d\n", delim, delim, line);
78968Sbill 		}
79968Sbill 		if (ndel > 0 && eq > 0)
80968Sbill 			printf("   %c%c in EQ, line %d\n", delim, delim, line);
81968Sbill 		if (ndel == 0)
82968Sbill 			continue;
83968Sbill 		totdel += ndel;
84968Sbill 		if (totdel%2) {
85968Sbill 			if (start == 0)
86968Sbill 				start = line;
87968Sbill 			else {
88968Sbill 				printf("   %d line %c%c, lines %d-%d\n", line-start+1, delim, delim, start, line);
89968Sbill 				start = line;
90968Sbill 			}
91968Sbill 		} else {
92968Sbill 			if (start > 0) {
93968Sbill 				printf("   %d line %c%c, lines %d-%d\n", line-start+1, delim, delim, start, line);
94968Sbill 				start = 0;
95968Sbill 			}
96968Sbill 			totdel = 0;
97968Sbill 		}
98968Sbill 	}
99968Sbill 	if (totdel)
100968Sbill 		printf("   Unfinished %c%c\n", delim, delim);
101968Sbill 	if (eq)
102968Sbill 		printf("   Unfinished EQ\n");
103968Sbill }
104