14887Schin /***********************************************************************
24887Schin * *
34887Schin * This software is part of the ast package *
4*10898Sroland.mainz@nrubsig.org * Copyright (c) 1986-2009 AT&T Intellectual Property *
54887Schin * and is licensed under the *
64887Schin * Common Public License, Version 1.0 *
78462SApril.Chin@Sun.COM * by AT&T Intellectual Property *
84887Schin * *
94887Schin * A copy of the License is available at *
104887Schin * http://www.opensource.org/licenses/cpl1.0.txt *
114887Schin * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
124887Schin * *
134887Schin * Information and Software Systems Research *
144887Schin * AT&T Research *
154887Schin * Florham Park NJ *
164887Schin * *
174887Schin * Glenn Fowler <gsf@research.att.com> *
184887Schin * *
194887Schin ***********************************************************************/
204887Schin #pragma prototyped
214887Schin /*
224887Schin * cpp predefined symbol detection support
234887Schin *
244887Schin * with no args stdin is treated as an a.out for
254887Schin * a Reiser derived cpp -- all strings that may
264887Schin * be identifiers are listed on fd 3 (1 if no 3)
274887Schin *
284887Schin * with args the -D argument values are listed on fd 3 (1 if no 3)
294887Schin */
304887Schin
314887Schin #include <ast.h>
324887Schin #include <ctype.h>
334887Schin
344887Schin int
main(int argc,char ** argv)354887Schin main(int argc, char** argv)
364887Schin {
374887Schin register int state;
384887Schin register int c;
394887Schin register char* s;
404887Schin Sfio_t* out;
414887Schin
424887Schin NoP(argc);
434887Schin if (dup(3) < 0 || !(out = sfnew(NiL, NiL, -1, 3, SF_WRITE)))
444887Schin out = sfstdout;
454887Schin if (*++argv)
464887Schin {
474887Schin while (s = *argv++)
484887Schin if (*s++ == '-' && *s++ == 'D' && isalpha(*s))
494887Schin {
504887Schin while (*s && *s != '=') sfputc(out, *s++);
514887Schin sfputc(out, '\n');
524887Schin }
534887Schin return 0;
544887Schin }
554887Schin state = 0;
564887Schin for (;;)
574887Schin {
584887Schin switch (c = sfgetc(sfstdin))
594887Schin {
604887Schin case EOF:
614887Schin break;
624887Schin case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
634887Schin case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
644887Schin case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
654887Schin case 's': case 't': case 'u': case 'v': case 'w': case 'x':
664887Schin case 'y': case 'z': case '_':
674887Schin case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
684887Schin case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
694887Schin case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
704887Schin case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
714887Schin case 'Y': case 'Z':
724887Schin state++;
734887Schin sfputc(out, c);
744887Schin continue;
754887Schin case '0': case '1': case '2': case '3': case '4': case '5':
764887Schin case '6': case '7': case '8': case '9':
774887Schin if (state)
784887Schin {
794887Schin sfputc(out, c);
804887Schin continue;
814887Schin }
824887Schin /*FALLTHROUGH*/
834887Schin default:
844887Schin if (state)
854887Schin {
864887Schin sfputc(out, '\n');
874887Schin state = 0;
884887Schin }
894887Schin continue;
904887Schin }
914887Schin break;
924887Schin }
934887Schin return 0;
944887Schin }
95