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