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