xref: /illumos-gate/usr/src/cmd/checkeq/checkeq.c (revision 8119dad84d6416f13557b0ba8e2aaf9064cbcfd3)
1 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
2 /*	  All Rights Reserved  	*/
3 
4 
5 /*
6  * Copyright (c) 1980 Regents of the University of California.
7  * All rights reserved. The Berkeley software License Agreement
8  * specifies the terms and conditions for redistribution.
9  */
10 
11 /*
12  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
13  * Use is subject to license terms.
14  */
15 
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <locale.h>
19 
20 static void check(FILE *);
21 
22 static	FILE	*fin;
23 static	int	delim	= '$';
24 
25 int
26 main(int argc, char **argv)
27 {
28 	(void) setlocale(LC_ALL, "");
29 #if !defined(TEXT_DOMAIN)
30 #define	TEXT_DOMAIN	"SYS_TEST"
31 #endif
32 	(void) textdomain(TEXT_DOMAIN);
33 	if (argc <= 1)
34 		check(stdin);
35 	else
36 		while (--argc > 0) {
37 			if ((fin = fopen(*++argv, "r")) == NULL) {
38 				perror(*argv);
39 				exit(1);
40 			}
41 			(void) printf("%s:\n", *argv);
42 			check(fin);
43 			(void) fclose(fin);
44 		}
45 	return (0);
46 }
47 
48 static void
49 check(FILE *f)
50 {
51 	int start, line, eq, ndel, totdel;
52 	char in[600], *p;
53 
54 	start = eq = line = ndel = totdel = 0;
55 	while (fgets(in, 600, f) != NULL) {
56 		line++;
57 		ndel = 0;
58 		for (p = in; *p; p++)
59 			if (*p == delim)
60 				ndel++;
61 		if (*in == '.' && *(in+1) == 'E' && *(in+2) == 'Q') {
62 			if (eq++)
63 				(void) printf(
64 				    gettext("   Spurious EQ, line %d\n"),
65 				    line);
66 			if (totdel)
67 				(void) printf(
68 				    gettext("   EQ in %c%c, line %d\n"),
69 				    delim, delim, line);
70 		} else if (*in == '.' && *(in+1) == 'E' && *(in+2) == 'N') {
71 			if (eq == 0)
72 				(void) printf(
73 				    gettext("   Spurious EN, line %d\n"),
74 				    line);
75 			else
76 				eq = 0;
77 			if (totdel > 0)
78 				(void) printf(
79 				    gettext("   EN in %c%c, line %d\n"),
80 				    delim, delim, line);
81 			start = 0;
82 		} else if (eq && *in == 'd' && *(in+1) == 'e' &&
83 		    *(in+2) == 'l' && *(in+3) == 'i' && *(in+4) == 'm') {
84 			for (p = in+5; *p; p++)
85 				if (*p != ' ') {
86 					if (*p == 'o' && *(p+1) == 'f')
87 						delim = 0;
88 					else
89 						delim = *p;
90 					break;
91 				}
92 			if (delim == 0)
93 				(void) printf(
94 				    gettext("   Delim off, line %d\n"),
95 				    line);
96 			else
97 				(void) printf(
98 				    gettext("   New delims %c%c, line %d\n"),
99 				    delim, delim, line);
100 		}
101 		if (ndel > 0 && eq > 0)
102 			(void) printf(
103 			    gettext("   %c%c in EQ, line %d\n"), delim,
104 			    delim, line);
105 		if (ndel == 0)
106 			continue;
107 		totdel += ndel;
108 		if (totdel%2) {
109 			if (start == 0)
110 				start = line;
111 			else {
112 				(void) printf(
113 				    gettext("   %d line %c%c, lines %d-%d\n"),
114 				    line-start+1, delim, delim, start, line);
115 				start = line;
116 			}
117 		} else {
118 			if (start > 0) {
119 				(void) printf(
120 				    gettext("   %d line %c%c, lines %d-%d\n"),
121 				    line-start+1, delim, delim, start, line);
122 				start = 0;
123 			}
124 			totdel = 0;
125 		}
126 	}
127 	if (totdel)
128 		(void) printf(gettext("   Unfinished %c%c\n"), delim, delim);
129 	if (eq)
130 		(void) printf(gettext("   Unfinished EQ\n"));
131 }
132