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