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