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