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