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