1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
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 ************************************************************************/
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 */
47 /* limit for reading commandfiles */
52 * This is predefined in Decus C
54 #define EOS '\0' /* End of string */
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 */
68 #define HT 0x05 /* horizontal tab */
69 #define NL 0x15 /* new line */
70 #define CR 0x0D /* carriage return */
73 #define HT 0x09 /* horizontal tab */
74 #define NL 0x0A /* new line */
75 #define CR 0x0D /* carriage return */
81 #define MAC_PARM 0x01 /* Macro formals start here */
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 */
92 assertion fails
-- PAR_MAC is
not less than
33
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
113 #define OP_AND 10 /* &, not && */
114 #define OP_OR 11 /* |, not || */
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
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
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 */
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 */
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 */
215 * nomacarg is a built-in #define on Decus C.
219 #define cput output /* cput concatenates tokens */
221 #if COMMENT_INVISIBLE
222 #define cput(c) { if (c != TOK_SEP && c != COM_SEP) PUTCHAR(c); }
224 #define cput(c) { if (c != TOK_SEP) PUTCHAR(c); }
229 #define streq(s1, s2) (strcmp(s1, s2) == 0)
233 * Error codes. VMS uses system definitions.
234 * Decus C codes are defined in stdio.h.
235 * Others are cooked to order.
241 #define IO_NORMAL (SS$_NORMAL | STS$M_INHIB_MSG)
242 #define IO_ERROR SS$_ABORT
245 * Note: IO_NORMAL and IO_ERROR are defined in the Decus C stdio.h file
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 */
286 extern char EvalBuf
[NEVALBUF
+ 1]; /* evaluation buffer */
287 extern int nEvalOff
; /* offset to free buffer pos */
290 extern int keepcomments
; /* Don't remove comments if set */
291 extern SIZES size_table
[]; /* For #if sizeof sizes */
293 #ifdef NOMAIN /* BP */
295 int start_cpp( int argc
, char *argv
[] );
297 #define MAIN start_cpp /* fuer die cpp.lib muss main() geandert werden */
300 #define MAIN __cdecl main
314 #define HELLO() fprintf( stderr, "[Hello at %s, %d] ", __FILE__, __LINE__ )
329 void output( int c
);
332 #if OSL_DEBUG_LEVEL > 1
334 int outputEval( int c
);
340 int control( int counter
);
343 void doif( int hash
);
344 int openinclude( char *, int );
345 int hasdirectory(char *, char * );
346 int openfile( char * );
349 int openfiles( char *filename
);
350 void addfile( FILE *fp
, char *filename
);
352 int AddInclude( char *pIncStr
);
353 int getredirection( int argc
, char **argv
);
354 void zap_uc( char *ap
);
357 int dooptions( int argc
, char *argv
[] );
358 int readoptions(char* filename
, char*** pfargv
);
362 void checkparm( int c
, DEFBUF
*dp
);
364 void expstuff( DEFBUF
*dp
);
367 void stparmscan( int delim
, DEFBUF
*dp
);
369 void stparmscan( int delim
);
371 #if OSL_DEBUG_LEVEL > 1
372 void dumpparm( char *why
);
376 void textput( char *text
);
377 void charput( int c
);
378 void expand( DEFBUF
*tokenp
);
383 int *evaleval(int *, int, int );
386 int evalnum( int c
);
393 void scanid( int c
);
394 int macroid( int c
);
396 int scanstring( int c
, void (*outfun
)( int c
) );
397 void scannumber( int c
, void (*outfun
)( 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
);
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
);