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