1 
2 /*
3  *	I n t e r n a l   D e f i n i t i o n s    f o r   C P P
4  *
5  * In general, definitions in this file should not be changed.
6  *
7  *
8  * $Id: cpp.h,v 1.6 2016-03-29 11:44:18 dom Exp $
9  *
10  */
11 
12 #include <stdint.h>
13 
14 #ifndef	TRUE
15 #define	TRUE		1
16 #define	FALSE		0
17 #endif
18 #ifndef	EOS
19 /*
20  * This is predefined in Decus C
21  */
22 #define	EOS		'\0'		/* End of string		*/
23 #endif
24 #define	EOF_CHAR	0		/* Returned by get() on eof	*/
25 #define NULLST		((char *) NULL)	/* Pointer to nowhere (linted)	*/
26 #define	DEF_NOARGS	(-1)		/* #define foo vs #define foo()	*/
27 
28 /*
29  * The following may need to change if the host system doesn't use ASCII.
30  */
31 #define DBL_QUOTE	0x1B		/* This is a virtual "		*/
32 #define TOK_QUOTE	0x1C		/* Token quotation		*/
33 #define	DEF_MAGIC	0x1D		/* Magic for #defines		*/
34 #define	TOK_SEP		0x1E		/* Token concatenation delim.	*/
35 #define COM_SEP		0x1F		/* Magic comment separator	*/
36 
37 /*
38  * Note -- in Ascii, the following will map macro formals onto DEL + the
39  * C1 control character region (decimal 128 .. (128 + PAR_MAC)) which will
40  * be ok as long as PAR_MAC is less than 33).  Note that the last PAR_MAC
41  * value is reserved for string substitution.
42  */
43 
44 #define	MAC_PARM	0x7F		/* Macro formals start here	*/
45 #if PAR_MAC >= 33
46 #error "assertion fails -- PAR_MAC isn't less than 33"
47 #endif
48 #define	LASTPARM	(PAR_MAC - 1)
49 
50 /*
51  * Character type codes.
52  */
53 
54 #define	INV		0		/* Invalid, must be zero	*/
55 #define	OP_EOE		INV		/* End of expression		*/
56 #define	DIG		1		/* Digit			*/
57 #define	LET		2		/* Identifier start		*/
58 #define	FIRST_BINOP	OP_ADD
59 #define	OP_ADD		3
60 #define	OP_SUB		4
61 #define	OP_MUL		5
62 #define	OP_DIV		6
63 #define	OP_MOD		7
64 #define	OP_ASL		8
65 #define	OP_ASR		9
66 #define	OP_AND		10		/* &, not &&			*/
67 #define	OP_OR		11		/* |, not ||			*/
68 #define	OP_XOR		12
69 #define	OP_EQ		13
70 #define	OP_NE		14
71 #define	OP_LT		15
72 #define	OP_LE		16
73 #define	OP_GE		17
74 #define	OP_GT		18
75 #define	OP_ANA		19		/* &&				*/
76 #define	OP_ORO		20		/* ||				*/
77 #define	OP_QUE		21		/* ?				*/
78 #define	OP_COL		22		/* :				*/
79 #define	OP_CMA		23		/* , (relevant?)		*/
80 #define	LAST_BINOP	OP_CMA		/* Last binary operand		*/
81 /*
82  * The following are unary.
83  */
84 #define	FIRST_UNOP	OP_PLU		/* First Unary operand		*/
85 #define	OP_PLU		24		/* + (draft ANSI standard)	*/
86 #define	OP_NEG		25		/* -				*/
87 #define	OP_COM		26		/* ~				*/
88 #define	OP_NOT		27		/* !				*/
89 #define	LAST_UNOP	OP_NOT
90 #define	OP_LPA		28		/* (				*/
91 #define	OP_RPA		29		/* )				*/
92 #define	OP_END		30		/* End of expression marker	*/
93 #define	OP_MAX		(OP_END + 1)	/* Number of operators		*/
94 #define	OP_FAIL		(OP_END + 1)	/* For error returns		*/
95 
96 /*
97  * The following are for lexical scanning only.
98  */
99 
100 #define	QUO		65		/* Both flavors of quotation	*/
101 #define	DOT		66		/* . might start a number	*/
102 #define	SPA		67		/* Space and tab		*/
103 #define	BSH		68		/* Just a backslash		*/
104 #define	END		69		/* EOF				*/
105 
106 /*
107  * These bits are set in ifstack[]
108  */
109 #define	WAS_COMPILING	1		/* TRUE if compile set at entry	*/
110 #define	ELSE_SEEN	2		/* TRUE when #else processed	*/
111 #define	TRUE_SEEN	4		/* TRUE when #if TRUE processed	*/
112 
113 /*
114  * Define bits for the basic types and their adjectives
115  */
116 
117 #define	T_CHAR		  1
118 #define	T_INT		  2
119 #define	T_FLOAT		  4
120 #define	T_DOUBLE	  8
121 #define	T_SHORT		 16
122 #define	T_LONG		 32
123 #define	T_SIGNED	 64
124 #define	T_UNSIGNED	128
125 #define	T_PTR		256		/* Pointer			*/
126 #define	T_FPTR		512		/* Pointer to functions		*/
127 
128 /*
129  * The DEFBUF structure stores information about #defined
130  * macros.  Note that the defbuf->repl information is always
131  * in malloc storage.
132  */
133 
134 typedef struct defbuf {
135 	struct defbuf	*link;	/* Next define in chain	*/
136 	char		*repl;		/* -> replacement	*/
137 	int		hash;			/* Symbol table hash	*/
138 	int		nargs;			/* For define(args)	*/
139 	char		name[1];	/* #define name		*/
140 } DEFBUF;
141 
142 /*
143  * The FILEINFO structure stores information about open files
144  * and macros being expanded.
145  */
146 
147 typedef struct fileinfo {
148 	char		*bptr;			/* Buffer pointer	*/
149 	int		line;				/* for include or macro	*/
150 	FILE		*fp;			/* File if non-null	*/
151 	struct fileinfo	*parent;	/* Link to includer	*/
152 	char		*filename;		/* File/macro name	*/
153 	char		*progname;		/* From #line statement	*/
154 	unsigned int	unrecur;	/* For macro recursion	*/
155 	char		buffer[1];		/* current input line	*/
156 } FILEINFO;
157 
158 /*
159  * The SIZES structure is used to store the values for #if sizeof
160  */
161 
162 typedef struct sizes {
163     short	bits;			/* If this bit is set,		*/
164     short	size;			/* this is the datum size value	*/
165     short	psize;			/* this is the pointer size	*/
166 } SIZES;
167 /*
168  * nomacarg is a built-in #define on Decus C.
169  */
170 
171 #define	cput		output		/* cput concatenates tokens	*/
172 
173 #ifndef	nomacarg
174 #define	streq(s1, s2)	(strcmp(s1, s2) == 0)
175 #endif
176 
177 /*
178  * Error codes.  VMS uses system definitions.
179  * Decus C codes are defined in stdio.h.
180  * Others are cooked to order.
181  */
182 
183 #if HOST == SYS_VMS
184 #include		<ssdef.h>
185 #include		<stsdef.h>
186 #define	IO_NORMAL	(SS$_NORMAL | STS$M_INHIB_MSG)
187 #define	IO_ERROR	SS$_ABORT
188 #endif
189 /*
190  * Note: IO_NORMAL and IO_ERROR are defined in the Decus C stdio.h file
191  */
192 #ifndef	IO_NORMAL
193 #define	IO_NORMAL	0
194 #endif
195 #ifndef	IO_ERROR
196 #define	IO_ERROR	1
197 #endif
198 
199 /*
200  * Externs
201  */
202 
203 extern int	line;				/* Current line number		*/
204 extern int	wrongline;			/* Force #line to cc pass 1	*/
205 extern char	type[];				/* Character classifier		*/
206 extern char	token[IDMAX + 1];	/* Current input token		*/
207 extern int	instring;			/* TRUE if scanning string	*/
208 extern int	inmacro;			/* TRUE if scanning #define	*/
209 extern int	errors;				/* Error counter		*/
210 extern int	recursion;			/* Macro depth counter		*/
211 extern char	ifstack[BLK_NEST];	/* #if information		*/
212 #define	compiling ifstack[0]
213 extern char	*ifptr;				/* -> current ifstack item	*/
214 extern char *quotedir[NINCLUDE];
215 extern char **quoteend;
216 extern char *systemdir[NINCLUDE];
217 extern char **systemend;
218 extern char	*incdir[NINCLUDE];	/* -i directories		*/
219 extern char	**incend;			/* -> active end of incdir	*/
220 extern int	cflag;				/* -C option (keep comments)	*/
221 extern int	eflag;				/* -E option (ignore errors)	*/
222 extern int	nflag;				/* -N option (no pre-defines)	*/
223 extern int	pflag;				/* -P option (no #line lines)	*/
224 extern int	rec_recover;		/* unwind recursive macros	*/
225 extern char	*preset[];			/* Standard predefined symbols	*/
226 extern char	*magic[];			/* Magic predefined symbols	*/
227 extern FILEINFO	*infile;		/* Current input file		*/
228 extern char	work[NWORK + 1];	/* #define scratch		*/
229 extern char	*workp;				/* Free space in work		*/
230 #if	DEBUG
231 extern int	debug;				/* Debug level			*/
232 #endif
233 extern int	keepcomments;		/* Don't remove comments if set	*/
234 extern SIZES	size_table[];	/* For #if sizeof sizes		*/
235 extern char	*getmem();			/* Get memory or die.		*/
236 extern DEFBUF	*lookid();		/* Look for a #define'd thing	*/
237 extern DEFBUF	*defendel();	/* Symbol table enter/delete	*/
238 extern char	*savestring();		/* Stuff string in malloc mem.	*/
239 
240 void addfile(FILE *fp, char *filename);
241 void textput(char *text);
242 void output(int c);				/* Output one character	*/
243 
244 
245 /* Error message handling */
246 void cierror(char *format, int narg);
247 void cerror(char *format, char *sarg);
248 void cfatal(char *format, char *sarg);
249 void cwarn(char *format, char *sarg);
250 void ciwarn(char *format, int narg);
251 void domsg(char *severity, char *format, intptr_t arg);
252 
253 void save(register int  c);
254 int dooptions(int argc, char *argv[]);
255 void initdefines();
256 void setincdirs();
257 
258 int control(int counter);
259 int skipws();
260 int get();
261 void expand(register DEFBUF *tokenp);
262 int cget();
263 int catenate();
264 int macroid(register int c);
265 void unget();
266 void skipnl();
267 void ungetstring(char		*text);
268 void dodefine();
269 void doundef();
270 void scanid(register int c);
271 int scanstring(register int delim, void (*outfun)(int));
272 void scannumber(register int c, register void (*outfun)(int));
273 int openfile(char *filename);
274 int eval();
275