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