update dev300-m58
[ooovba.git] / rsc / source / rscpp / cpp.h
blobf138c1949b6280fb58a769e45071332c9aaff732
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: cpp.h,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 #ifndef TRUE
33 #define TRUE 1
34 #define FALSE 0
35 #endif
37 /* in cpp1.c: file-pointer auf stdout oder file */
38 extern FILE *pCppOut; /* BP */
39 #define PUTCHAR( d ) fprintf( pCppOut, "%c", (d) ) /* BP */
40 #if OSL_DEBUG_LEVEL > 1
41 extern FILE *pDefOut; /* ER */
42 #ifdef EVALDEFS
43 #define NEVALBUF 2048
44 #endif
45 #endif
47 /* limit for reading commandfiles */
48 #define PARALIMIT 100
50 #ifndef EOS
52 * This is predefined in Decus C
54 #define EOS '\0' /* End of string */
55 #endif
56 #define EOF_CHAR 0 /* Returned by get() on eof */
57 #define NULLST ((char *) NULL) /* Pointer to nowhere (linted) */
58 #define DEF_NOARGS (-1) /* #define foo vs #define foo() */
61 * The following may need to change if the host system doesn't use ASCII.
63 #define DEF_MAGIC 0x1D /* Magic for #defines */
64 #define TOK_SEP 0x1E /* Token concatenation delim. */
65 #define COM_SEP 0x1F /* Magic comment separator */
67 #ifdef EBCDIC
68 #define HT 0x05 /* horizontal tab */
69 #define NL 0x15 /* new line */
70 #define CR 0x0D /* carriage return */
71 #define DEL 0x07
72 #else
73 #define HT 0x09 /* horizontal tab */
74 #define NL 0x0A /* new line */
75 #define CR 0x0D /* carriage return */
76 #define DEL 0x7F
77 #endif
80 #ifdef SOLAR
81 #define MAC_PARM 0x01 /* Macro formals start here */
82 #else
84 * Note -- in Ascii, the following will map macro formals onto DEL + the
85 * C1 control character region (decimal 128 .. (128 + PAR_MAC)) which will
86 * be ok as long as PAR_MAC is less than 33). Note that the last PAR_MAC
87 * value is reserved for string substitution.
90 #define MAC_PARM DEL /* Macro formals start here */
91 #if PAR_MAC >= 33
92 assertion fails -- PAR_MAC is not less than 33
93 #endif
94 #endif
95 #define LASTPARM (PAR_MAC - 1)
98 * Character type codes.
101 #define INV 0 /* Invalid, must be zero */
102 #define OP_EOE INV /* End of expression */
103 #define DIG 1 /* Digit */
104 #define LET 2 /* Identifier start */
105 #define FIRST_BINOP OP_ADD
106 #define OP_ADD 3
107 #define OP_SUB 4
108 #define OP_MUL 5
109 #define OP_DIV 6
110 #define OP_MOD 7
111 #define OP_ASL 8
112 #define OP_ASR 9
113 #define OP_AND 10 /* &, not && */
114 #define OP_OR 11 /* |, not || */
115 #define OP_XOR 12
116 #define OP_EQ 13
117 #define OP_NE 14
118 #define OP_LT 15
119 #define OP_LE 16
120 #define OP_GE 17
121 #define OP_GT 18
122 #define OP_ANA 19 /* && */
123 #define OP_ORO 20 /* || */
124 #define OP_QUE 21 /* ? */
125 #define OP_COL 22 /* : */
126 #define OP_CMA 23 /* , (relevant?) */
127 #define LAST_BINOP OP_CMA /* Last binary operand */
129 * The following are unary.
131 #define FIRST_UNOP OP_PLU /* First Unary operand */
132 #define OP_PLU 24 /* + (draft ANSI standard) */
133 #define OP_NEG 25 /* - */
134 #define OP_COM 26 /* ~ */
135 #define OP_NOT 27 /* ! */
136 #define LAST_UNOP OP_NOT
137 #define OP_LPA 28 /* ( */
138 #define OP_RPA 29 /* ) */
139 #define OP_END 30 /* End of expression marker */
140 #define OP_MAX (OP_END + 1) /* Number of operators */
141 #define OP_FAIL (OP_END + 1) /* For error returns */
144 * The following are for lexical scanning only.
147 #define QUO 65 /* Both flavors of quotation */
148 #define DOT 66 /* . might start a number */
149 #define SPA 67 /* Space and tab */
150 #define BSH 68 /* Just a backslash */
151 #define END 69 /* EOF */
154 * These bits are set in ifstack[]
156 #define WAS_COMPILING 1 /* TRUE if compile set at entry */
157 #define ELSE_SEEN 2 /* TRUE when #else processed */
158 #define TRUE_SEEN 4 /* TRUE when #if TRUE processed */
161 * Define bits for the basic types and their adjectives
164 #define T_CHAR 1
165 #define T_INT 2
166 #define T_FLOAT 4
167 #define T_DOUBLE 8
168 #define T_SHORT 16
169 #define T_LONG 32
170 #define T_SIGNED 64
171 #define T_UNSIGNED 128
172 #define T_PTR 256 /* Pointer */
173 #define T_FPTR 512 /* Pointer to functions */
176 * The DEFBUF structure stores information about #defined
177 * macros. Note that the defbuf->repl information is always
178 * in malloc storage.
181 typedef struct defbuf {
182 struct defbuf *link; /* Next define in chain */
183 char *repl; /* -> replacement */
184 int hash; /* Symbol table hash */
185 int nargs; /* For define(args) */
186 char name[1]; /* #define name */
187 } DEFBUF;
190 * The FILEINFO structure stores information about open files
191 * and macros being expanded.
194 typedef struct fileinfo {
195 char *bptr; /* Buffer pointer */
196 int line; /* for include or macro */
197 FILE *fp; /* File if non-null */
198 struct fileinfo *parent; /* Link to includer */
199 char *filename; /* File/macro name */
200 char *progname; /* From #line statement */
201 unsigned int unrecur; /* For macro recursion */
202 char buffer[1]; /* current input line */
203 } FILEINFO;
206 * The SIZES structure is used to store the values for #if sizeof
209 typedef struct sizes {
210 short bits; /* If this bit is set, */
211 int size; /* this is the datum size value */
212 int psize; /* this is the pointer size */
213 } SIZES;
215 * nomacarg is a built-in #define on Decus C.
218 #ifdef nomacarg
219 #define cput output /* cput concatenates tokens */
220 #else
221 #if COMMENT_INVISIBLE
222 #define cput(c) { if (c != TOK_SEP && c != COM_SEP) PUTCHAR(c); }
223 #else
224 #define cput(c) { if (c != TOK_SEP) PUTCHAR(c); }
225 #endif
226 #endif
228 #ifndef nomacarg
229 #define streq(s1, s2) (strcmp(s1, s2) == 0)
230 #endif
233 * Error codes. VMS uses system definitions.
234 * Decus C codes are defined in stdio.h.
235 * Others are cooked to order.
238 #if HOST == SYS_VMS
239 #include <ssdef.h>
240 #include <stsdef.h>
241 #define IO_NORMAL (SS$_NORMAL | STS$M_INHIB_MSG)
242 #define IO_ERROR SS$_ABORT
243 #endif
245 * Note: IO_NORMAL and IO_ERROR are defined in the Decus C stdio.h file
247 #ifndef IO_NORMAL
248 #define IO_NORMAL 0
249 #endif
250 #ifndef IO_ERROR
251 #define IO_ERROR 1
252 #endif
255 * Externs
258 extern int line; /* Current line number */
259 extern int wrongline; /* Force #line to cc pass 1 */
260 extern char type[]; /* Character classifier */
261 extern char token[IDMAX + 1]; /* Current input token */
262 extern int instring; /* TRUE if scanning string */
263 extern int inmacro; /* TRUE if scanning #define */
264 extern int errors; /* Error counter */
265 extern int recursion; /* Macro depth counter */
266 extern char ifstack[BLK_NEST]; /* #if information */
267 #define compiling ifstack[0]
268 extern char *ifptr; /* -> current ifstack item */
269 extern char *incdir[NINCLUDE]; /* -i directories */
270 extern char **incend; /* -> active end of incdir */
271 extern int cflag; /* -C option (keep comments) */
272 extern int eflag; /* -E option (ignore errors) */
273 extern int nflag; /* -N option (no pre-defines) */
274 extern int rec_recover; /* unwind recursive macros */
275 extern char *preset[]; /* Standard predefined symbols */
276 extern char *magic[]; /* Magic predefined symbols */
277 extern FILEINFO *infile; /* Current input file */
278 extern char work[NWORK + 1]; /* #define scratch */
279 extern char *workp; /* Free space in work */
280 #if OSL_DEBUG_LEVEL > 1
281 extern int debug; /* Debug level */
282 /* ER dump & evaluate #define's */
283 extern int bDumpDefs; /* TRUE if #define's dump req. */
284 extern int bIsInEval; /* TRUE if #define dumping now */
285 #ifdef EVALDEFS
286 extern char EvalBuf[NEVALBUF + 1]; /* evaluation buffer */
287 extern int nEvalOff; /* offset to free buffer pos */
288 #endif
289 #endif
290 extern int keepcomments; /* Don't remove comments if set */
291 extern SIZES size_table[]; /* For #if sizeof sizes */
293 #ifdef NOMAIN /* BP */
294 #ifndef _NO_PROTO
295 int start_cpp( int argc, char *argv[] );
296 #endif
297 #define MAIN start_cpp /* fuer die cpp.lib muss main() geandert werden */
298 #else
299 #ifdef WNT
300 #define MAIN __cdecl main
301 #else
302 #define MAIN main
303 #endif
304 #endif
307 void InitCpp1();
308 void InitCpp2();
309 void InitCpp3();
310 void InitCpp4();
311 void InitCpp5();
312 void InitCpp6();
314 #define HELLO() fprintf( stderr, "[Hello at %s, %d] ", __FILE__, __LINE__ )
316 #ifndef _STDIO_H
317 #include <stdio.h>
318 #endif
320 #ifndef _STDLIB_H
321 #include <stdlib.h>
322 #endif
324 #ifndef _STRING_H
325 #include <string.h>
326 #endif
328 /* cpp1.c */
329 void output( int c );
330 void sharp();
331 void cppmain();
332 #if OSL_DEBUG_LEVEL > 1
333 #ifdef EVALDEFS
334 int outputEval( int c );
335 #endif
336 #endif
339 /* cpp2.c */
340 int control( int counter );
341 void doinclude();
342 void dodefine();
343 void doif( int hash );
344 int openinclude( char *, int );
345 int hasdirectory(char *, char * );
346 int openfile( char * );
348 /* cpp3.c */
349 int openfiles( char *filename );
350 void addfile( FILE *fp, char *filename );
351 void setincdirs();
352 int AddInclude( char *pIncStr );
353 int getredirection( int argc, char **argv );
354 void zap_uc( char *ap );
356 void initdefines();
357 int dooptions( int argc, char *argv[] );
358 int readoptions(char* filename, char*** pfargv);
360 /* cpp4.c */
361 void dodefines();
362 void checkparm( int c, DEFBUF *dp );
363 int expcollect();
364 void expstuff( DEFBUF *dp );
366 #if STRING_FORMAL
367 void stparmscan( int delim, DEFBUF *dp);
368 #else
369 void stparmscan( int delim);
370 #endif
371 #if OSL_DEBUG_LEVEL > 1
372 void dumpparm( char *why );
373 #endif
375 void doundef();
376 void textput( char *text );
377 void charput( int c );
378 void expand( DEFBUF *tokenp );
380 /* cpp5.c */
381 int eval();
382 int evallex(int);
383 int *evaleval(int *, int, int );
384 int evalchar(int);
385 int dosizeof();
386 int evalnum( int c );
387 int bittest( int );
389 /* cpp6.c */
391 void skipnl();
392 int skipws();
393 void scanid( int c );
394 int macroid( int c );
395 int catenate();
396 int scanstring( int c, void (*outfun)( int c ) );
397 void scannumber( int c, void (*outfun)( int c ) );
398 void save( int c );
399 char *savestring( char *text );
400 FILEINFO *getfile( int bufsize, char *name);
401 char *getmem( int size );
402 DEFBUF *lookid( int c );
403 DEFBUF *defendel( char *name, int delete );
404 void dunpdef( char *why );
405 void dumpadef( char *why, DEFBUF *dp);
406 int get();
407 int cget();
408 void unget();
409 void ungetstring( char *text );
410 void cerror( char *format, char *sarg);
411 void cwarn( char *format, char *sarg);
412 void cfatal( char *format, char *sarg);
413 void cierror( char *format, int n);
414 void ciwarn( char *format, int n);
415 #if OSL_DEBUG_LEVEL > 1
416 void dumpdef( char *why );
417 void dumpadef( char *why, DEFBUF *dp );
418 #endif