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  * Glenn Fowler
23*4887Schin  * AT&T Research
24*4887Schin  *
25*4887Schin  * preprocessor data
26*4887Schin  *
27*4887Schin  * intended to be a conforming implementation of the translation phases
28*4887Schin  * (2.1.1.2) 1,2,3,4 and 6 of the "American National Standard for
29*4887Schin  * Information Systems -- Programming Language -- C", ANSI X3.159-1989.
30*4887Schin  *
31*4887Schin  * STANDARD INTERPRETATION:
32*4887Schin  *
33*4887Schin  *	include files are forced to preserve #if nesting levels
34*4887Schin  *	support for this is found in the recursive description for
35*4887Schin  *	include file processing in the translation phases
36*4887Schin  *
37*4887Schin  *	ID"..." produces two tokens: {ID}{"..."}
38*4887Schin  *	ID'...' produces two tokens: {ID}{'...'}
39*4887Schin  *
40*4887Schin  * COMPATIBILITY:
41*4887Schin  *
42*4887Schin  *	only sane Reiser compatibility is implemented
43*4887Schin  *
44*4887Schin  *	strange handling of `\newline', especially in directives,
45*4887Schin  *	is not implemented
46*4887Schin  *
47*4887Schin  *	dissappearing comments used as concatenation operators work
48*4887Schin  *	only within macro bodies
49*4887Schin  */
50*4887Schin 
51*4887Schin static const char id[] = "\n@(#)$Id: libpp (AT&T Research) 2006-11-23 $\0\n";
52*4887Schin 
53*4887Schin #include "pplib.h"
54*4887Schin 
55*4887Schin #ifndef IDNAME
56*4887Schin #define IDNAME	"pp"
57*4887Schin #endif
58*4887Schin 
59*4887Schin static char	addbuf[MAXTOKEN+1];	/* ADD buffer			*/
60*4887Schin static char	argsbuf[MAXTOKEN+1];	/* predicate args		*/
61*4887Schin static char	catbuf[MAXTOKEN+1];	/* catenation buffer		*/
62*4887Schin static char	hidebuf[MAXTOKEN+1];	/* pp:hide buffer		*/
63*4887Schin static char	outbuf[2*(PPBUFSIZ+MAXTOKEN)];/* output buffer		*/
64*4887Schin static char	pathbuf[MAXTOKEN+1];	/* full path of last #include	*/
65*4887Schin static char	tmpbuf[MAXTOKEN+1];	/* very temporary buffer	*/
66*4887Schin static char	tokbuf[2*MAXTOKEN+1];	/* token buffer			*/
67*4887Schin static char	valbuf[MAXTOKEN+1];	/* builtin macro value buffer	*/
68*4887Schin 
69*4887Schin static char	optflags[X_last_option+1];/* OPT_* flags indexed by X_*	*/
70*4887Schin 
71*4887Schin static char	null[1];
72*4887Schin 
73*4887Schin static struct ppinstk	instack =	/* input stream stack		*/
74*4887Schin {
75*4887Schin 	&null[0]			/* nextchr			*/
76*4887Schin };
77*4887Schin 
78*4887Schin static struct ppdirs	stddir =	/* standard include directory	*/
79*4887Schin {
80*4887Schin 	PPSTANDARD,	0,		1, INC_STANDARD, TYPE_INCLUDE|TYPE_DIRECTORY|TYPE_HOSTED
81*4887Schin };
82*4887Schin 
83*4887Schin static struct ppdirs	firstdir =	/* first include directory	*/
84*4887Schin {
85*4887Schin 	"",		&stddir,	0, INC_PREFIX, TYPE_INCLUDE|TYPE_DIRECTORY
86*4887Schin };
87*4887Schin 
88*4887Schin struct ppglobals pp =
89*4887Schin {
90*4887Schin 	/* public globals */
91*4887Schin 
92*4887Schin 	&id[10],			/* version			*/
93*4887Schin 	"",				/* lineid			*/
94*4887Schin 	"/dev/stdout",			/* outfile			*/
95*4887Schin 	IDNAME,				/* pass				*/
96*4887Schin 	&tokbuf[0],			/* token			*/
97*4887Schin 	0,				/* symbol			*/
98*4887Schin 
99*4887Schin 	/* exposed for the output macros */
100*4887Schin 
101*4887Schin 	&outbuf[0],			/* outb				*/
102*4887Schin 	&outbuf[0],			/* outbuf			*/
103*4887Schin 	&outbuf[0],			/* outp				*/
104*4887Schin 	&outbuf[PPBUFSIZ],		/* oute				*/
105*4887Schin 	0,				/* offset			*/
106*4887Schin 
107*4887Schin 	/* public context */
108*4887Schin 
109*4887Schin 	&firstdir,			/* lcldirs			*/
110*4887Schin 	&firstdir,			/* stddirs			*/
111*4887Schin 	0,				/* flags			*/
112*4887Schin 	0,				/* symtab			*/
113*4887Schin 
114*4887Schin 	/* private context */
115*4887Schin 
116*4887Schin 	0,				/* context			*/
117*4887Schin 	0,				/* state			*/
118*4887Schin 	ALLMULTIPLE|CATLITERAL,		/* mode				*/
119*4887Schin 	PREFIX,				/* option			*/
120*4887Schin 	0,				/* test				*/
121*4887Schin 	0,				/* filedeps.sp			*/
122*4887Schin 	0,				/* filedeps.flags		*/
123*4887Schin 	&firstdir,			/* firstdir			*/
124*4887Schin 	&firstdir,			/* lastdir			*/
125*4887Schin 	0,				/* hide				*/
126*4887Schin 	0,				/* column			*/
127*4887Schin 	-1,				/* pending			*/
128*4887Schin 	0,				/* firstfile			*/
129*4887Schin 	0,				/* lastfile			*/
130*4887Schin 	0,				/* ignore			*/
131*4887Schin 	0,				/* probe			*/
132*4887Schin 	0,				/* filtab			*/
133*4887Schin 	0,				/* prdtab			*/
134*4887Schin 	0,				/* date				*/
135*4887Schin 	0,				/* time				*/
136*4887Schin 	0,				/* maps				*/
137*4887Schin 	0,				/* ro_state			*/
138*4887Schin 	0,				/* ro_mode			*/
139*4887Schin 	0,				/* ro_option			*/
140*4887Schin 	{0},				/* cdir				*/
141*4887Schin 	{0},				/* hostdir			*/
142*4887Schin 	0,				/* ppdefault			*/
143*4887Schin 	0,				/* firstindex			*/
144*4887Schin 	0,				/* lastindex			*/
145*4887Schin 	0,				/* firstop			*/
146*4887Schin 	0,				/* lastop			*/
147*4887Schin 	0,				/* firsttx			*/
148*4887Schin 	0,				/* lasttx			*/
149*4887Schin 	0,				/* arg_file			*/
150*4887Schin 	0,				/* arg_mode			*/
151*4887Schin 	0,				/* arg_style			*/
152*4887Schin 	0,				/* c				*/
153*4887Schin 	0,				/* hosted			*/
154*4887Schin 	0,				/* ignoresrc			*/
155*4887Schin 	0,				/* initialized			*/
156*4887Schin 	0,				/* standalone			*/
157*4887Schin 	0,				/* spare_1			*/
158*4887Schin 
159*4887Schin 	/* library private globals */
160*4887Schin 
161*4887Schin 	"\"08/11/94\"",			/* checkpoint (with quotes!)	*/
162*4887Schin 	128,				/* constack			*/
163*4887Schin 	&instack,			/* in				*/
164*4887Schin 	&addbuf[0],			/* addp				*/
165*4887Schin 	&argsbuf[0],			/* args				*/
166*4887Schin 	&addbuf[0],			/* addbuf			*/
167*4887Schin 	&catbuf[0],			/* catbuf			*/
168*4887Schin 	0,				/* hdrbuf			*/
169*4887Schin 	&hidebuf[0],			/* hidebuf			*/
170*4887Schin 	&pathbuf[0],			/* path				*/
171*4887Schin 	&tmpbuf[0],			/* tmpbuf			*/
172*4887Schin 	&valbuf[0],			/* valbuf			*/
173*4887Schin 	&optflags[0],			/* optflags			*/
174*4887Schin 	'\n',				/* lastout			*/
175*4887Schin 
176*4887Schin 	/* the rest are implicitly initialized */
177*4887Schin };
178*4887Schin 
179*4887Schin char	ppctype[UCHAR_MAX];
180