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