bump product version to 5.0.4.1
[LibreOffice.git] / rsc / source / rscpp / cpp.h
blob1f88f7bff819e9778f8c77793cd0ecd042f6f457
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_RSC_SOURCE_RSCPP_CPP_H
21 #define INCLUDED_RSC_SOURCE_RSCPP_CPP_H
23 #ifndef TRUE
24 #define TRUE 1
25 #define FALSE 0
26 #endif
28 /* in cpp1.c: file-pointer auf stdout oder file */
29 extern FILE* pCppOut; /* BP */
30 #define PUTCHAR( d ) fprintf( pCppOut, "%c", (d) ) /* BP */
31 #if OSL_DEBUG_LEVEL > 1
32 extern FILE* pDefOut; /* ER */
33 #ifdef EVALDEFS
34 #define NEVALBUF 2048
35 #endif
36 #endif
38 /* limit for reading commandfiles */
39 #define PARALIMIT 100
41 #define EOS '\0' /* End of string */
42 #define EOF_CHAR 0 /* Returned by get() on eof */
43 #define NULLST ((char *) NULL) /* Pointer to nowhere (linted) */
44 #define DEF_NOARGS (-1) /* #define foo vs #define foo() */
47 * The following may need to change if the host system doesn't use ASCII.
49 #define DEF_MAGIC 0x1D /* Magic for #defines */
50 #define TOK_SEP 0x1E /* Token concatenation delim. */
51 #define COM_SEP 0x1F /* Magic comment separator */
53 #define HT 0x09 /* horizontal tab */
54 #define NL 0x0A /* new line */
55 #define CR 0x0D /* carriage return */
56 #define DEL 0x7F
60 #ifdef SOLAR
61 #define MAC_PARM 0x01 /* Macro formals start here */
62 #else
64 * Note -- in Ascii, the following will map macro formals onto DEL + the
65 * C1 control character region (decimal 128 .. (128 + PAR_MAC)) which will
66 * be ok as long as PAR_MAC is less than 33). Note that the last PAR_MAC
67 * value is reserved for string substitution.
70 #define MAC_PARM DEL /* Macro formals start here */
71 #if PAR_MAC >= 33
72 assertion fails -- PAR_MAC is not less than 33
73 #endif
74 #endif
75 #define LASTPARM (PAR_MAC - 1)
78 * Character type codes.
81 #define INV 0 /* Invalid, must be zero */
82 #define OP_EOE INV /* End of expression */
83 #define DIG 1 /* Digit */
84 #define LET 2 /* Identifier start */
85 #define FIRST_BINOP OP_ADD
86 #define OP_ADD 3
87 #define OP_SUB 4
88 #define OP_MUL 5
89 #define OP_DIV 6
90 #define OP_MOD 7
91 #define OP_ASL 8
92 #define OP_ASR 9
93 #define OP_AND 10 /* &, not && */
94 #define OP_OR 11 /* |, not || */
95 #define OP_XOR 12
96 #define OP_EQ 13
97 #define OP_NE 14
98 #define OP_LT 15
99 #define OP_LE 16
100 #define OP_GE 17
101 #define OP_GT 18
102 #define OP_ANA 19 /* && */
103 #define OP_ORO 20 /* || */
104 #define OP_QUE 21 /* ? */
105 #define OP_COL 22 /* : */
106 #define OP_CMA 23 /* , (relevant?) */
107 #define LAST_BINOP OP_CMA /* Last binary operand */
109 * The following are unary.
111 #define OP_PLU 24 /* + (draft ANSI standard) */
112 #define OP_NEG 25 /* - */
113 #define OP_COM 26 /* ~ */
114 #define OP_NOT 27 /* ! */
115 #define OP_LPA 28 /* ( */
116 #define OP_RPA 29 /* ) */
117 #define OP_END 30 /* End of expression marker */
118 #define OP_MAX (OP_END + 1) /* Number of operators */
119 #define OP_FAIL (OP_END + 1) /* For error returns */
122 * The following are for lexical scanning only.
125 #define QUO 65 /* Both flavors of quotation */
126 #define DOT 66 /* . might start a number */
127 #define SPA 67 /* Space and tab */
128 #define BSH 68 /* Just a backslash */
129 #define END 69 /* EOF */
132 * These bits are set in ifstack[]
134 #define WAS_COMPILING 1 /* TRUE if compile set at entry */
135 #define ELSE_SEEN 2 /* TRUE when #else processed */
136 #define TRUE_SEEN 4 /* TRUE when #if TRUE processed */
139 * Define bits for the basic types and their adjectives
142 #define T_CHAR 1
143 #define T_INT 2
144 #define T_FLOAT 4
145 #define T_DOUBLE 8
146 #define T_SHORT 16
147 #define T_LONG 32
148 #define T_SIGNED 64
149 #define T_UNSIGNED 128
150 #define T_PTR 256 /* Pointer */
151 #define T_FPTR 512 /* Pointer to functions */
154 * The DEFBUF structure stores information about #defined
155 * macros. Note that the defbuf->repl information is always
156 * in malloc storage.
159 typedef struct defbuf
161 struct defbuf* link; /* Next define in chain */
162 char* repl; /* -> replacement */
163 int hash; /* Symbol table hash */
164 int nargs; /* For define(args) */
165 char name[1]; /* #define name */
166 } DEFBUF;
169 * The FILEINFO structure stores information about open files
170 * and macros being expanded.
173 typedef struct fileinfo
175 char* bptr; /* Buffer pointer */
176 int line; /* for include or macro */
177 FILE* fp; /* File if non-null */
178 struct fileinfo* parent; /* Link to includer */
179 char* filename; /* File/macro name */
180 char* progname; /* From #line statement */
181 unsigned int unrecur; /* For macro recursion */
182 char buffer[1]; /* current input line */
183 } FILEINFO;
186 * The SIZES structure is used to store the values for #if sizeof
189 typedef struct sizes
191 short bits; /* If this bit is set, */
192 int size; /* this is the datum size value */
193 int psize; /* this is the pointer size */
194 } SIZES;
196 #define cput(c) { if (c != TOK_SEP) PUTCHAR(c); }
197 #define streq(s1, s2) (strcmp(s1, s2) == 0)
200 * Error codes.
202 #define IO_NORMAL 0
203 #define IO_ERROR 1
206 * Externs
209 extern int line; /* Current line number */
210 extern int wrongline; /* Force #line to cc pass 1 */
211 extern char type[]; /* Character classifier */
212 extern char token[IDMAX + 1]; /* Current input token */
213 extern int instring; /* TRUE if scanning string */
214 extern int inmacro; /* TRUE if scanning #define */
215 extern int errors; /* Error counter */
216 extern int recursion; /* Macro depth counter */
217 extern char ifstack[BLK_NEST]; /* #if information */
218 #define compiling ifstack[0]
219 extern char* ifptr; /* -> current ifstack item */
220 extern char* incdir[NINCLUDE]; /* -i directories */
221 extern char** incend; /* -> active end of incdir */
222 extern int cflag; /* -C option (keep comments) */
223 extern int eflag; /* -E option (ignore errors) */
224 extern int nflag; /* -N option (no pre-defines) */
225 extern int rec_recover; /* unwind recursive macros */
226 extern char* preset[]; /* Standard predefined symbols */
227 extern char* magic[]; /* Magic predefined symbols */
228 extern FILEINFO* infile; /* Current input file */
229 extern char work[NWORK + 1]; /* #define scratch */
230 extern char* workp; /* Free space in work */
231 #if OSL_DEBUG_LEVEL > 1
232 extern int debug; /* Debug level */
233 /* ER dump & evaluate #define's */
234 extern int bDumpDefs; /* TRUE if #define's dump req. */
235 extern int bIsInEval; /* TRUE if #define dumping now */
236 #ifdef EVALDEFS
237 extern char EvalBuf[NEVALBUF + 1]; /* evaluation buffer */
238 extern int nEvalOff; /* offset to free buffer pos */
239 #endif
240 #endif
241 extern int keepcomments; /* Don't remove comments if set */
242 extern SIZES size_table[]; /* For #if sizeof sizes */
244 #ifdef NOMAIN /* BP */
245 #ifndef _NO_PROTO
246 int rscpp_main( int argc, char **argv );
247 #endif
248 #define MAIN rscpp_main /* fuer die cpp.lib muss main() geandert werden */
249 #else
250 #ifdef WNT
251 #define MAIN __cdecl main
252 #else
253 #define MAIN main
254 #endif
255 #endif
258 void InitCpp1( void );
259 void InitCpp4( void );
260 void InitCpp6( void );
262 #define HELLO() fprintf( stderr, "[Hello at %s, %d] ", __FILE__, __LINE__ )
264 #include <stdio.h>
265 #include <stdlib.h>
266 #include <string.h>
268 /* cpp1.c */
269 void output( int c );
270 void sharp( void );
271 void cppmain( void );
272 #if OSL_DEBUG_LEVEL > 1
273 #ifdef EVALDEFS
274 int outputEval( int c );
275 #endif
276 #endif
279 /* cpp2.c */
280 int control( int counter );
281 void doinclude( void );
282 void dodefine( void );
283 void doif( int hash );
284 int openinclude( char*, int );
285 int hasdirectory( char*, char*, int );
286 int openfile( char* );
288 /* cpp3.c */
289 int openfiles( char* filename );
290 void addfile( FILE* fp, char* filename );
291 void setincdirs( void );
292 int AddInclude( char* pIncStr );
293 int getredirection( int argc, char** argv );
294 void zap_uc( char* ap );
296 void initdefines( void );
297 int dooptions( int argc, char* argv[] );
298 int readoptions( char* filename, char*** pfargv );
300 /* cpp4.c */
301 void dodefines( void );
302 void checkparm( int c, DEFBUF* dp );
303 int expcollect( void );
304 void expstuff( DEFBUF* dp );
306 void stparmscan( int delim );
307 #if OSL_DEBUG_LEVEL > 1
308 void dumpparm( char* why );
309 #endif
311 void doundef( void );
312 void textput( char* text );
313 void charput( int c );
314 void expand( DEFBUF* tokenp );
316 /* cpp5.c */
317 int eval( void );
318 int evallex( int );
319 int *evaleval( int*, int, int );
320 int evalchar( int );
321 int dosizeof( void );
322 int evalnum( int c );
323 int bittest( int );
325 /* cpp6.c */
327 void skipnl( void );
328 int skipws( void );
329 void scanid( int c );
330 int macroid( int c );
331 int catenate(void);
332 int scanstring( int c, void (*outfun)( int c ) );
333 void scannumber( int c, void (*outfun)( int c ) );
334 void save( int c );
335 char* savestring( char* text );
336 FILEINFO* getfile( size_t bufsize, char* name );
337 char *getmem( size_t size );
338 DEFBUF* lookid( int c );
339 DEFBUF* defendel( char* name, int delete );
340 void dunpdef( char* why );
341 void dumpadef( char* why, DEFBUF* dp );
342 int get( void );
343 int cget( void );
344 void unget( void );
345 void ungetstring( char* text );
346 void cerror( char* format, char* sarg );
347 void cwarn( char* format, char* sarg );
348 void cfatal( char* format, char* sarg );
349 void cierror( char* format, int n );
350 void ciwarn( char* format, int n );
351 #if OSL_DEBUG_LEVEL > 1
352 void dumpdef( char* why );
353 void dumpadef( char* why, DEFBUF *dp );
354 #endif
356 #endif // INCLUDED_RSC_SOURCE_RSCPP_CPP_H
358 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */