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 * Glenn Fowler 234887Schin * AT&T Research 244887Schin * 254887Schin * preprocessor data 264887Schin * 274887Schin * intended to be a conforming implementation of the translation phases 284887Schin * (2.1.1.2) 1,2,3,4 and 6 of the "American National Standard for 294887Schin * Information Systems -- Programming Language -- C", ANSI X3.159-1989. 304887Schin * 314887Schin * STANDARD INTERPRETATION: 324887Schin * 334887Schin * include files are forced to preserve #if nesting levels 344887Schin * support for this is found in the recursive description for 354887Schin * include file processing in the translation phases 364887Schin * 374887Schin * ID"..." produces two tokens: {ID}{"..."} 384887Schin * ID'...' produces two tokens: {ID}{'...'} 394887Schin * 404887Schin * COMPATIBILITY: 414887Schin * 424887Schin * only sane Reiser compatibility is implemented 434887Schin * 444887Schin * strange handling of `\newline', especially in directives, 454887Schin * is not implemented 464887Schin * 474887Schin * dissappearing comments used as concatenation operators work 484887Schin * only within macro bodies 494887Schin */ 504887Schin 51*10898Sroland.mainz@nrubsig.org static const char id[] = "\n@(#)$Id: libpp (AT&T Research) 2009-02-02 $\0\n"; 524887Schin 534887Schin #include "pplib.h" 544887Schin 554887Schin #ifndef IDNAME 564887Schin #define IDNAME "pp" 574887Schin #endif 584887Schin 594887Schin static char addbuf[MAXTOKEN+1]; /* ADD buffer */ 604887Schin static char argsbuf[MAXTOKEN+1]; /* predicate args */ 614887Schin static char catbuf[MAXTOKEN+1]; /* catenation buffer */ 624887Schin static char hidebuf[MAXTOKEN+1]; /* pp:hide buffer */ 634887Schin static char outbuf[2*(PPBUFSIZ+MAXTOKEN)];/* output buffer */ 644887Schin static char pathbuf[MAXTOKEN+1]; /* full path of last #include */ 654887Schin static char tmpbuf[MAXTOKEN+1]; /* very temporary buffer */ 664887Schin static char tokbuf[2*MAXTOKEN+1]; /* token buffer */ 674887Schin static char valbuf[MAXTOKEN+1]; /* builtin macro value buffer */ 684887Schin 694887Schin static char optflags[X_last_option+1];/* OPT_* flags indexed by X_* */ 704887Schin 714887Schin static char null[1]; 724887Schin 734887Schin static struct ppinstk instack = /* input stream stack */ 744887Schin { 754887Schin &null[0] /* nextchr */ 764887Schin }; 774887Schin 784887Schin static struct ppdirs stddir = /* standard include directory */ 794887Schin { 804887Schin PPSTANDARD, 0, 1, INC_STANDARD, TYPE_INCLUDE|TYPE_DIRECTORY|TYPE_HOSTED 814887Schin }; 824887Schin 834887Schin static struct ppdirs firstdir = /* first include directory */ 844887Schin { 854887Schin "", &stddir, 0, INC_PREFIX, TYPE_INCLUDE|TYPE_DIRECTORY 864887Schin }; 874887Schin 884887Schin struct ppglobals pp = 894887Schin { 904887Schin /* public globals */ 914887Schin 924887Schin &id[10], /* version */ 934887Schin "", /* lineid */ 944887Schin "/dev/stdout", /* outfile */ 954887Schin IDNAME, /* pass */ 964887Schin &tokbuf[0], /* token */ 974887Schin 0, /* symbol */ 984887Schin 994887Schin /* exposed for the output macros */ 1004887Schin 1014887Schin &outbuf[0], /* outb */ 1024887Schin &outbuf[0], /* outbuf */ 1034887Schin &outbuf[0], /* outp */ 1044887Schin &outbuf[PPBUFSIZ], /* oute */ 1054887Schin 0, /* offset */ 1064887Schin 1074887Schin /* public context */ 1084887Schin 1094887Schin &firstdir, /* lcldirs */ 1104887Schin &firstdir, /* stddirs */ 1114887Schin 0, /* flags */ 1124887Schin 0, /* symtab */ 1134887Schin 1144887Schin /* private context */ 1154887Schin 1164887Schin 0, /* context */ 1174887Schin 0, /* state */ 1184887Schin ALLMULTIPLE|CATLITERAL, /* mode */ 1194887Schin PREFIX, /* option */ 1204887Schin 0, /* test */ 1214887Schin 0, /* filedeps.sp */ 1224887Schin 0, /* filedeps.flags */ 1234887Schin &firstdir, /* firstdir */ 1244887Schin &firstdir, /* lastdir */ 1254887Schin 0, /* hide */ 1264887Schin 0, /* column */ 1274887Schin -1, /* pending */ 1284887Schin 0, /* firstfile */ 1294887Schin 0, /* lastfile */ 1304887Schin 0, /* ignore */ 1314887Schin 0, /* probe */ 1324887Schin 0, /* filtab */ 1334887Schin 0, /* prdtab */ 1344887Schin 0, /* date */ 1354887Schin 0, /* time */ 1364887Schin 0, /* maps */ 1374887Schin 0, /* ro_state */ 1384887Schin 0, /* ro_mode */ 1394887Schin 0, /* ro_option */ 1404887Schin {0}, /* cdir */ 1414887Schin {0}, /* hostdir */ 1424887Schin 0, /* ppdefault */ 1434887Schin 0, /* firstindex */ 1444887Schin 0, /* lastindex */ 1454887Schin 0, /* firstop */ 1464887Schin 0, /* lastop */ 1474887Schin 0, /* firsttx */ 1484887Schin 0, /* lasttx */ 1494887Schin 0, /* arg_file */ 1504887Schin 0, /* arg_mode */ 1514887Schin 0, /* arg_style */ 1524887Schin 0, /* c */ 1534887Schin 0, /* hosted */ 1544887Schin 0, /* ignoresrc */ 1554887Schin 0, /* initialized */ 1564887Schin 0, /* standalone */ 1574887Schin 0, /* spare_1 */ 1584887Schin 1594887Schin /* library private globals */ 1604887Schin 1614887Schin "\"08/11/94\"", /* checkpoint (with quotes!) */ 1624887Schin 128, /* constack */ 1634887Schin &instack, /* in */ 1644887Schin &addbuf[0], /* addp */ 1654887Schin &argsbuf[0], /* args */ 1664887Schin &addbuf[0], /* addbuf */ 1674887Schin &catbuf[0], /* catbuf */ 1684887Schin 0, /* hdrbuf */ 1694887Schin &hidebuf[0], /* hidebuf */ 1704887Schin &pathbuf[0], /* path */ 1714887Schin &tmpbuf[0], /* tmpbuf */ 1724887Schin &valbuf[0], /* valbuf */ 1734887Schin &optflags[0], /* optflags */ 1744887Schin '\n', /* lastout */ 1754887Schin 1764887Schin /* the rest are implicitly initialized */ 1774887Schin }; 1784887Schin 179*10898Sroland.mainz@nrubsig.org char ppctype[UCHAR_MAX+1]; 180