1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
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 */
38 /* limit for reading commandfiles */
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 */
61 #define MAC_PARM 0x01 /* Macro formals start here */
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 */
72 assertion fails
-- PAR_MAC is
not less than
33
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
93 #define OP_AND 10 /* &, not && */
94 #define OP_OR 11 /* |, not || */
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
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
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 */
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 */
186 * The SIZES structure is used to store the values for #if sizeof
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 */
196 #define cput(c) { if (c != TOK_SEP) PUTCHAR(c); }
197 #define streq(s1, s2) (strcmp(s1, s2) == 0)
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 */
237 extern char EvalBuf
[NEVALBUF
+ 1]; /* evaluation buffer */
238 extern int nEvalOff
; /* offset to free buffer pos */
241 extern int keepcomments
; /* Don't remove comments if set */
242 extern SIZES size_table
[]; /* For #if sizeof sizes */
244 #ifdef NOMAIN /* BP */
246 int rscpp_main( int argc
, char **argv
);
248 #define MAIN rscpp_main /* fuer die cpp.lib muss main() geandert werden */
251 #define MAIN __cdecl main
258 void InitCpp1( void );
259 void InitCpp4( void );
260 void InitCpp6( void );
262 #define HELLO() fprintf( stderr, "[Hello at %s, %d] ", __FILE__, __LINE__ )
269 void output( int c
);
271 void cppmain( void );
272 #if OSL_DEBUG_LEVEL > 1
274 int outputEval( int 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* );
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
);
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
);
311 void doundef( void );
312 void textput( char* text
);
313 void charput( int c
);
314 void expand( DEFBUF
* tokenp
);
319 int *evaleval( int*, int, int );
321 int dosizeof( void );
322 int evalnum( int c
);
329 void scanid( int c
);
330 int macroid( int c
);
332 int scanstring( int c
, void (*outfun
)( int c
) );
333 void scannumber( int c
, void (*outfun
)( 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
);
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
);
356 #endif // INCLUDED_RSC_SOURCE_RSCPP_CPP_H
358 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */