xref: /titanic_51/usr/src/contrib/ast/src/lib/libpp/ppsym.c (revision b4dd7d09880f14016feece03929a224eca1cf39a)
1*b4dd7d09SAndy Fiddaman /***********************************************************************
2*b4dd7d09SAndy Fiddaman *                                                                      *
3*b4dd7d09SAndy Fiddaman *               This software is part of the ast package               *
4*b4dd7d09SAndy Fiddaman *          Copyright (c) 1986-2011 AT&T Intellectual Property          *
5*b4dd7d09SAndy Fiddaman *                      and is licensed under the                       *
6*b4dd7d09SAndy Fiddaman *                 Eclipse Public License, Version 1.0                  *
7*b4dd7d09SAndy Fiddaman *                    by AT&T Intellectual Property                     *
8*b4dd7d09SAndy Fiddaman *                                                                      *
9*b4dd7d09SAndy Fiddaman *                A copy of the License is available at                 *
10*b4dd7d09SAndy Fiddaman *          http://www.eclipse.org/org/documents/epl-v10.html           *
11*b4dd7d09SAndy Fiddaman *         (with md5 checksum b35adb5213ca9657e911e9befb180842)         *
12*b4dd7d09SAndy Fiddaman *                                                                      *
13*b4dd7d09SAndy Fiddaman *              Information and Software Systems Research               *
14*b4dd7d09SAndy Fiddaman *                            AT&T Research                             *
15*b4dd7d09SAndy Fiddaman *                           Florham Park NJ                            *
16*b4dd7d09SAndy Fiddaman *                                                                      *
17*b4dd7d09SAndy Fiddaman *                 Glenn Fowler <gsf@research.att.com>                  *
18*b4dd7d09SAndy Fiddaman *                                                                      *
19*b4dd7d09SAndy Fiddaman ***********************************************************************/
20*b4dd7d09SAndy Fiddaman #pragma prototyped
21*b4dd7d09SAndy Fiddaman /*
22*b4dd7d09SAndy Fiddaman  * cpp predefined symbol detection support
23*b4dd7d09SAndy Fiddaman  *
24*b4dd7d09SAndy Fiddaman  * with no args stdin is treated as an a.out for
25*b4dd7d09SAndy Fiddaman  * a Reiser derived cpp -- all strings that may
26*b4dd7d09SAndy Fiddaman  * be identifiers are listed on fd 3 (1 if no 3)
27*b4dd7d09SAndy Fiddaman  *
28*b4dd7d09SAndy Fiddaman  * with args the -D argument values are listed on fd 3 (1 if no 3)
29*b4dd7d09SAndy Fiddaman  */
30*b4dd7d09SAndy Fiddaman 
31*b4dd7d09SAndy Fiddaman #include <ast.h>
32*b4dd7d09SAndy Fiddaman #include <ctype.h>
33*b4dd7d09SAndy Fiddaman 
34*b4dd7d09SAndy Fiddaman int
35*b4dd7d09SAndy Fiddaman main(int argc, char** argv)
36*b4dd7d09SAndy Fiddaman {
37*b4dd7d09SAndy Fiddaman 	register int	state;
38*b4dd7d09SAndy Fiddaman 	register int	c;
39*b4dd7d09SAndy Fiddaman 	register char*	s;
40*b4dd7d09SAndy Fiddaman 	Sfio_t*		out;
41*b4dd7d09SAndy Fiddaman 
42*b4dd7d09SAndy Fiddaman 	NoP(argc);
43*b4dd7d09SAndy Fiddaman 	if (dup(3) < 0 || !(out = sfnew(NiL, NiL, -1, 3, SF_WRITE)))
44*b4dd7d09SAndy Fiddaman 		out = sfstdout;
45*b4dd7d09SAndy Fiddaman 	if (*++argv)
46*b4dd7d09SAndy Fiddaman 	{
47*b4dd7d09SAndy Fiddaman 		while (s = *argv++)
48*b4dd7d09SAndy Fiddaman 			if (*s++ == '-' && *s++ == 'D' && isalpha(*s))
49*b4dd7d09SAndy Fiddaman 			{
50*b4dd7d09SAndy Fiddaman 				while (*s && *s != '=') sfputc(out, *s++);
51*b4dd7d09SAndy Fiddaman 				sfputc(out, '\n');
52*b4dd7d09SAndy Fiddaman 			}
53*b4dd7d09SAndy Fiddaman 		return 0;
54*b4dd7d09SAndy Fiddaman 	}
55*b4dd7d09SAndy Fiddaman 	state = 0;
56*b4dd7d09SAndy Fiddaman 	for (;;)
57*b4dd7d09SAndy Fiddaman 	{
58*b4dd7d09SAndy Fiddaman 		switch (c = sfgetc(sfstdin))
59*b4dd7d09SAndy Fiddaman 		{
60*b4dd7d09SAndy Fiddaman 		case EOF:
61*b4dd7d09SAndy Fiddaman 			break;
62*b4dd7d09SAndy Fiddaman 		case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
63*b4dd7d09SAndy Fiddaman 		case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
64*b4dd7d09SAndy Fiddaman 		case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
65*b4dd7d09SAndy Fiddaman 		case 's': case 't': case 'u': case 'v': case 'w': case 'x':
66*b4dd7d09SAndy Fiddaman 		case 'y': case 'z': case '_':
67*b4dd7d09SAndy Fiddaman 		case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
68*b4dd7d09SAndy Fiddaman 		case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
69*b4dd7d09SAndy Fiddaman 		case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
70*b4dd7d09SAndy Fiddaman 		case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
71*b4dd7d09SAndy Fiddaman 		case 'Y': case 'Z':
72*b4dd7d09SAndy Fiddaman 			state++;
73*b4dd7d09SAndy Fiddaman 			sfputc(out, c);
74*b4dd7d09SAndy Fiddaman 			continue;
75*b4dd7d09SAndy Fiddaman 		case '0': case '1': case '2': case '3': case '4': case '5':
76*b4dd7d09SAndy Fiddaman 		case '6': case '7': case '8': case '9':
77*b4dd7d09SAndy Fiddaman 			if (state)
78*b4dd7d09SAndy Fiddaman 			{
79*b4dd7d09SAndy Fiddaman 				sfputc(out, c);
80*b4dd7d09SAndy Fiddaman 				continue;
81*b4dd7d09SAndy Fiddaman 			}
82*b4dd7d09SAndy Fiddaman 			/*FALLTHROUGH*/
83*b4dd7d09SAndy Fiddaman 		default:
84*b4dd7d09SAndy Fiddaman 			if (state)
85*b4dd7d09SAndy Fiddaman 			{
86*b4dd7d09SAndy Fiddaman 				sfputc(out, '\n');
87*b4dd7d09SAndy Fiddaman 				state = 0;
88*b4dd7d09SAndy Fiddaman 			}
89*b4dd7d09SAndy Fiddaman 			continue;
90*b4dd7d09SAndy Fiddaman 		}
91*b4dd7d09SAndy Fiddaman 		break;
92*b4dd7d09SAndy Fiddaman 	}
93*b4dd7d09SAndy Fiddaman 	return 0;
94*b4dd7d09SAndy Fiddaman }
95