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 .
26 /* in cpp1.c: file-pointer auf stdout oder file */
27 extern FILE *pCppOut
; /* BP */
28 #define PUTCHAR( d ) fprintf( pCppOut, "%c", (d) ) /* BP */
29 #if OSL_DEBUG_LEVEL > 1
30 extern FILE *pDefOut
; /* ER */
36 /* limit for reading commandfiles */
41 * This is predefined in Decus C
43 #define EOS '\0' /* End of string */
45 #define EOF_CHAR 0 /* Returned by get() on eof */
46 #define NULLST ((char *) NULL) /* Pointer to nowhere (linted) */
47 #define DEF_NOARGS (-1) /* #define foo vs #define foo() */
50 * The following may need to change if the host system doesn't use ASCII.
52 #define DEF_MAGIC 0x1D /* Magic for #defines */
53 #define TOK_SEP 0x1E /* Token concatenation delim. */
54 #define COM_SEP 0x1F /* Magic comment separator */
57 #define HT 0x05 /* horizontal tab */
58 #define NL 0x15 /* new line */
59 #define CR 0x0D /* carriage return */
62 #define HT 0x09 /* horizontal tab */
63 #define NL 0x0A /* new line */
64 #define CR 0x0D /* carriage return */
70 #define MAC_PARM 0x01 /* Macro formals start here */
73 * Note -- in Ascii, the following will map macro formals onto DEL + the
74 * C1 control character region (decimal 128 .. (128 + PAR_MAC)) which will
75 * be ok as long as PAR_MAC is less than 33). Note that the last PAR_MAC
76 * value is reserved for string substitution.
79 #define MAC_PARM DEL /* Macro formals start here */
81 assertion fails
-- PAR_MAC is
not less than
33
84 #define LASTPARM (PAR_MAC - 1)
87 * Character type codes.
90 #define INV 0 /* Invalid, must be zero */
91 #define OP_EOE INV /* End of expression */
92 #define DIG 1 /* Digit */
93 #define LET 2 /* Identifier start */
94 #define FIRST_BINOP OP_ADD
102 #define OP_AND 10 /* &, not && */
103 #define OP_OR 11 /* |, not || */
111 #define OP_ANA 19 /* && */
112 #define OP_ORO 20 /* || */
113 #define OP_QUE 21 /* ? */
114 #define OP_COL 22 /* : */
115 #define OP_CMA 23 /* , (relevant?) */
116 #define LAST_BINOP OP_CMA /* Last binary operand */
118 * The following are unary.
120 #define FIRST_UNOP OP_PLU /* First Unary operand */
121 #define OP_PLU 24 /* + (draft ANSI standard) */
122 #define OP_NEG 25 /* - */
123 #define OP_COM 26 /* ~ */
124 #define OP_NOT 27 /* ! */
125 #define LAST_UNOP OP_NOT
126 #define OP_LPA 28 /* ( */
127 #define OP_RPA 29 /* ) */
128 #define OP_END 30 /* End of expression marker */
129 #define OP_MAX (OP_END + 1) /* Number of operators */
130 #define OP_FAIL (OP_END + 1) /* For error returns */
133 * The following are for lexical scanning only.
136 #define QUO 65 /* Both flavors of quotation */
137 #define DOT 66 /* . might start a number */
138 #define SPA 67 /* Space and tab */
139 #define BSH 68 /* Just a backslash */
140 #define END 69 /* EOF */
143 * These bits are set in ifstack[]
145 #define WAS_COMPILING 1 /* TRUE if compile set at entry */
146 #define ELSE_SEEN 2 /* TRUE when #else processed */
147 #define TRUE_SEEN 4 /* TRUE when #if TRUE processed */
150 * Define bits for the basic types and their adjectives
160 #define T_UNSIGNED 128
161 #define T_PTR 256 /* Pointer */
162 #define T_FPTR 512 /* Pointer to functions */
165 * The DEFBUF structure stores information about #defined
166 * macros. Note that the defbuf->repl information is always
170 typedef struct defbuf
{
171 struct defbuf
*link
; /* Next define in chain */
172 char *repl
; /* -> replacement */
173 int hash
; /* Symbol table hash */
174 int nargs
; /* For define(args) */
175 char name
[1]; /* #define name */
179 * The FILEINFO structure stores information about open files
180 * and macros being expanded.
183 typedef struct fileinfo
{
184 char *bptr
; /* Buffer pointer */
185 int line
; /* for include or macro */
186 FILE *fp
; /* File if non-null */
187 struct fileinfo
*parent
; /* Link to includer */
188 char *filename
; /* File/macro name */
189 char *progname
; /* From #line statement */
190 unsigned int unrecur
; /* For macro recursion */
191 char buffer
[1]; /* current input line */
195 * The SIZES structure is used to store the values for #if sizeof
198 typedef struct sizes
{
199 short bits
; /* If this bit is set, */
200 int size
; /* this is the datum size value */
201 int psize
; /* this is the pointer size */
204 * nomacarg is a built-in #define on Decus C.
208 #define cput output /* cput concatenates tokens */
210 #if COMMENT_INVISIBLE
211 #define cput(c) { if (c != TOK_SEP && c != COM_SEP) PUTCHAR(c); }
213 #define cput(c) { if (c != TOK_SEP) PUTCHAR(c); }
218 #define streq(s1, s2) (strcmp(s1, s2) == 0)
222 * Error codes. VMS uses system definitions.
223 * Decus C codes are defined in stdio.h.
224 * Others are cooked to order.
230 #define IO_NORMAL (SS$_NORMAL | STS$M_INHIB_MSG)
231 #define IO_ERROR SS$_ABORT
234 * Note: IO_NORMAL and IO_ERROR are defined in the Decus C stdio.h file
247 extern int line
; /* Current line number */
248 extern int wrongline
; /* Force #line to cc pass 1 */
249 extern char type
[]; /* Character classifier */
250 extern char token
[IDMAX
+ 1]; /* Current input token */
251 extern int instring
; /* TRUE if scanning string */
252 extern int inmacro
; /* TRUE if scanning #define */
253 extern int errors
; /* Error counter */
254 extern int recursion
; /* Macro depth counter */
255 extern char ifstack
[BLK_NEST
]; /* #if information */
256 #define compiling ifstack[0]
257 extern char *ifptr
; /* -> current ifstack item */
258 extern char *incdir
[NINCLUDE
]; /* -i directories */
259 extern char **incend
; /* -> active end of incdir */
260 extern int cflag
; /* -C option (keep comments) */
261 extern int eflag
; /* -E option (ignore errors) */
262 extern int nflag
; /* -N option (no pre-defines) */
263 extern int rec_recover
; /* unwind recursive macros */
264 extern char *preset
[]; /* Standard predefined symbols */
265 extern char *magic
[]; /* Magic predefined symbols */
266 extern FILEINFO
*infile
; /* Current input file */
267 extern char work
[NWORK
+ 1]; /* #define scratch */
268 extern char *workp
; /* Free space in work */
269 #if OSL_DEBUG_LEVEL > 1
270 extern int debug
; /* Debug level */
271 /* ER dump & evaluate #define's */
272 extern int bDumpDefs
; /* TRUE if #define's dump req. */
273 extern int bIsInEval
; /* TRUE if #define dumping now */
275 extern char EvalBuf
[NEVALBUF
+ 1]; /* evaluation buffer */
276 extern int nEvalOff
; /* offset to free buffer pos */
279 extern int keepcomments
; /* Don't remove comments if set */
280 extern SIZES size_table
[]; /* For #if sizeof sizes */
282 #ifdef NOMAIN /* BP */
284 int rscpp_main( int argc
, char **argv
);
286 #define MAIN rscpp_main /* fuer die cpp.lib muss main() geandert werden */
289 #define MAIN __cdecl main
303 #define HELLO() fprintf( stderr, "[Hello at %s, %d] ", __FILE__, __LINE__ )
310 void output( int c
);
313 #if OSL_DEBUG_LEVEL > 1
315 int outputEval( int c
);
321 int control( int counter
);
324 void doif( int hash
);
325 int openinclude( char *, int );
326 int hasdirectory(char *, char * );
327 int openfile( char * );
330 int openfiles( char *filename
);
331 void addfile( FILE *fp
, char *filename
);
333 int AddInclude( char *pIncStr
);
334 int getredirection( int argc
, char **argv
);
335 void zap_uc( char *ap
);
338 int dooptions( int argc
, char *argv
[] );
339 int readoptions(char* filename
, char*** pfargv
);
343 void checkparm( int c
, DEFBUF
*dp
);
345 void expstuff( DEFBUF
*dp
);
348 void stparmscan( int delim
, DEFBUF
*dp
);
350 void stparmscan( int delim
);
352 #if OSL_DEBUG_LEVEL > 1
353 void dumpparm( char *why
);
357 void textput( char *text
);
358 void charput( int c
);
359 void expand( DEFBUF
*tokenp
);
364 int *evaleval(int *, int, int );
367 int evalnum( int c
);
374 void scanid( int c
);
375 int macroid( int c
);
377 int scanstring( int c
, void (*outfun
)( int c
) );
378 void scannumber( int c
, void (*outfun
)( int c
) );
380 char *savestring( char *text
);
381 FILEINFO
*getfile( int bufsize
, char *name
);
382 char *getmem( int size
);
383 DEFBUF
*lookid( int c
);
384 DEFBUF
*defendel( char *name
, int delete );
385 void dunpdef( char *why
);
386 void dumpadef( char *why
, DEFBUF
*dp
);
390 void ungetstring( char *text
);
391 void cerror( char *format
, char *sarg
);
392 void cwarn( char *format
, char *sarg
);
393 void cfatal( char *format
, char *sarg
);
394 void cierror( char *format
, int n
);
395 void ciwarn( char *format
, int n
);
396 #if OSL_DEBUG_LEVEL > 1
397 void dumpdef( char *why
);
398 void dumpadef( char *why
, DEFBUF
*dp
);
401 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */