summaryrefslogtreecommitdiff
path: root/rsc/source/rscpp/cpp.h
blob: 8ec451ab9d3d181ff1933f7a985a4135e20e9353 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2000, 2010 Oracle and/or its affiliates.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/


#ifndef TRUE
#define TRUE            1
#define FALSE           0
#endif

/* in cpp1.c: file-pointer auf stdout oder file */
extern FILE *pCppOut;                                   /* BP */
#define PUTCHAR( d )   fprintf( pCppOut, "%c", (d) )    /* BP */
#if OSL_DEBUG_LEVEL > 1
extern FILE *pDefOut;                                   /* ER */
#ifdef EVALDEFS
#define NEVALBUF        2048
#endif
#endif

/* limit for reading commandfiles */
#define PARALIMIT       100

#ifndef EOS
/*
 * This is predefined in Decus C
 */
#define EOS             '\0'            /* End of string                */
#endif
#define EOF_CHAR        0               /* Returned by get() on eof     */
#define NULLST          ((char *) NULL) /* Pointer to nowhere (linted)  */
#define DEF_NOARGS      (-1)            /* #define foo vs #define foo() */

/*
 * The following may need to change if the host system doesn't use ASCII.
 */
#define DEF_MAGIC       0x1D            /* Magic for #defines           */
#define TOK_SEP         0x1E            /* Token concatenation delim.   */
#define COM_SEP         0x1F            /* Magic comment separator      */

#ifdef  EBCDIC
#define HT              0x05            /* horizontal tab               */
#define NL              0x15            /* new line                     */
#define CR              0x0D            /* carriage return              */
#define DEL             0x07
#else
#define HT              0x09            /* horizontal tab               */
#define NL              0x0A            /* new line                     */
#define CR              0x0D            /* carriage return              */
#define DEL             0x7F
#endif


#ifdef  SOLAR
#define MAC_PARM        0x01            /* Macro formals start here     */
#else
/*
 * Note -- in Ascii, the following will map macro formals onto DEL + the
 * C1 control character region (decimal 128 .. (128 + PAR_MAC)) which will
 * be ok as long as PAR_MAC is less than 33).  Note that the last PAR_MAC
 * value is reserved for string substitution.
 */

#define MAC_PARM        DEL             /* Macro formals start here     */
#if PAR_MAC >= 33
        assertion fails -- PAR_MAC is not less than 33
#endif
#endif
#define LASTPARM        (PAR_MAC - 1)

/*
 * Character type codes.
 */

#define INV             0               /* Invalid, must be zero        */
#define OP_EOE          INV             /* End of expression            */
#define DIG             1               /* Digit                        */
#define LET             2               /* Identifier start             */
#define FIRST_BINOP     OP_ADD
#define OP_ADD          3
#define OP_SUB          4
#define OP_MUL          5
#define OP_DIV          6
#define OP_MOD          7
#define OP_ASL          8
#define OP_ASR          9
#define OP_AND          10              /* &, not &&                    */
#define OP_OR           11              /* |, not ||                    */
#define OP_XOR          12
#define OP_EQ           13
#define OP_NE           14
#define OP_LT           15
#define OP_LE           16
#define OP_GE           17
#define OP_GT           18
#define OP_ANA          19              /* &&                           */
#define OP_ORO          20              /* ||                           */
#define OP_QUE          21              /* ?                            */
#define OP_COL          22              /* :                            */
#define OP_CMA          23              /* , (relevant?)                */
#define LAST_BINOP      OP_CMA          /* Last binary operand          */
/*
 * The following are unary.
 */
#define FIRST_UNOP      OP_PLU          /* First Unary operand          */
#define OP_PLU          24              /* + (draft ANSI standard)      */
#define OP_NEG          25              /* -                            */
#define OP_COM          26              /* ~                            */
#define OP_NOT          27              /* !                            */
#define LAST_UNOP       OP_NOT
#define OP_LPA          28              /* (                            */
#define OP_RPA          29              /* )                            */
#define OP_END          30              /* End of expression marker     */
#define OP_MAX          (OP_END + 1)    /* Number of operators          */
#define OP_FAIL         (OP_END + 1)    /* For error returns            */

/*
 * The following are for lexical scanning only.
 */

#define QUO             65              /* Both flavors of quotation    */
#define DOT             66              /* . might start a number       */
#define SPA             67              /* Space and tab                */
#define BSH             68              /* Just a backslash             */
#define END             69              /* EOF                          */

/*
 * These bits are set in ifstack[]
 */
#define WAS_COMPILING   1               /* TRUE if compile set at entry */
#define ELSE_SEEN       2               /* TRUE when #else processed    */
#define TRUE_SEEN       4               /* TRUE when #if TRUE processed */

/*
 * Define bits for the basic types and their adjectives
 */

#define T_CHAR            1
#define T_INT             2
#define T_FLOAT           4
#define T_DOUBLE          8
#define T_SHORT          16
#define T_LONG           32
#define T_SIGNED         64
#define T_UNSIGNED      128
#define T_PTR           256             /* Pointer                      */
#define T_FPTR          512             /* Pointer to functions         */

/*
 * The DEFBUF structure stores information about #defined
 * macros.  Note that the defbuf->repl information is always
 * in malloc storage.
 */

typedef struct defbuf {
        struct defbuf   *link;          /* Next define in chain */
        char            *repl;          /* -> replacement       */
        int             hash;           /* Symbol table hash    */
        int             nargs;          /* For define(args)     */
        char            name[1];        /* #define name         */
} DEFBUF;

/*
 * The FILEINFO structure stores information about open files
 * and macros being expanded.
 */

typedef struct fileinfo {
        char            *bptr;          /* Buffer pointer       */
        int             line;           /* for include or macro */
        FILE            *fp;            /* File if non-null     */
        struct fileinfo *parent;        /* Link to includer     */
        char            *filename;      /* File/macro name      */
        char            *progname;      /* From #line statement */
        unsigned int    unrecur;        /* For macro recursion  */
        char            buffer[1];      /* current input line   */
} FILEINFO;

/*
 * The SIZES structure is used to store the values for #if sizeof
 */

typedef struct sizes {
    short       bits;                   /* If this bit is set,          */
    int         size;                   /* this is the datum size value */
    int         psize;                  /* this is the pointer size     */
} SIZES;
/*
 * nomacarg is a built-in #define on Decus C.
 */

#ifdef  nomacarg
#define cput            output          /* cput concatenates tokens     */
#else
#if COMMENT_INVISIBLE
#define cput(c)         { if (c != TOK_SEP && c != COM_SEP) PUTCHAR(c); }
#else
#define cput(c)         { if (c != TOK_SEP) PUTCHAR(c); }
#endif
#endif

#ifndef nomacarg
#define streq(s1, s2)   (strcmp(s1, s2) == 0)
#endif

/*
 * Error codes.  VMS uses system definitions.
 * Decus C codes are defined in stdio.h.
 * Others are cooked to order.
 */

#if HOST == SYS_VMS
#include                <ssdef.h>
#include                <stsdef.h>
#define IO_NORMAL       (SS$_NORMAL | STS$M_INHIB_MSG)
#define IO_ERROR        SS$_ABORT
#endif
/*
 * Note: IO_NORMAL and IO_ERROR are defined in the Decus C stdio.h file
 */
#ifndef IO_NORMAL
#define IO_NORMAL       0
#endif
#ifndef IO_ERROR
#define IO_ERROR        1
#endif

/*
 * Externs
 */

extern int      line;                   /* Current line number          */
extern int      wrongline;              /* Force #line to cc pass 1     */
extern char     type[];                 /* Character classifier         */
extern char     token[IDMAX + 1];       /* Current input token          */
extern int      instring;               /* TRUE if scanning string      */
extern int      inmacro;                /* TRUE if scanning #define     */
extern int      errors;                 /* Error counter                */
extern int      recursion;              /* Macro depth counter          */
extern char     ifstack[BLK_NEST];      /* #if information              */
#define compiling ifstack[0]
extern char     *ifptr;                 /* -> current ifstack item      */
extern char     *incdir[NINCLUDE];      /* -i directories               */
extern char     **incend;               /* -> active end of incdir      */
extern int      cflag;                  /* -C option (keep comments)    */
extern int      eflag;                  /* -E option (ignore errors)    */
extern int      nflag;                  /* -N option (no pre-defines)   */
extern int      rec_recover;            /* unwind recursive macros      */
extern char     *preset[];              /* Standard predefined symbols  */
extern char     *magic[];               /* Magic predefined symbols     */
extern FILEINFO *infile;                /* Current input file           */
extern char     work[NWORK + 1];        /* #define scratch              */
extern char     *workp;                 /* Free space in work           */
#if OSL_DEBUG_LEVEL > 1
extern int      debug;                  /* Debug level                  */
/* ER dump & evaluate #define's */
extern int      bDumpDefs;              /* TRUE if #define's dump req.  */
extern int      bIsInEval;              /* TRUE if #define dumping now  */
#ifdef EVALDEFS
extern char     EvalBuf[NEVALBUF + 1];  /* evaluation buffer            */
extern int      nEvalOff;               /* offset to free buffer pos    */
#endif
#endif
extern int      keepcomments;           /* Don't remove comments if set */
extern SIZES    size_table[];           /* For #if sizeof sizes         */

#ifdef NOMAIN                /* BP */
#ifndef _NO_PROTO
int start_cpp( int argc, char *argv[] );
#endif
#define MAIN   start_cpp     /* fuer die cpp.lib muss main() geandert werden */
#else
#ifdef WNT
#define MAIN   __cdecl main
#else
#define MAIN   main
#endif
#endif


void InitCpp1();
void InitCpp2();
void InitCpp3();
void InitCpp4();
void InitCpp5();
void InitCpp6();

#define HELLO()   fprintf( stderr, "[Hello at %s, %d] ", __FILE__, __LINE__ )

#ifndef _STDIO_H
#include <stdio.h>
#endif

#ifndef _STDLIB_H
#include <stdlib.h>
#endif

#ifndef _STRING_H
#include <string.h>
#endif

/* cpp1.c */
void output( int c );
void sharp();
void cppmain();
#if OSL_DEBUG_LEVEL > 1
#ifdef EVALDEFS
int outputEval( int c );
#endif
#endif


/* cpp2.c */
int control( int counter );
void doinclude();
void dodefine();
void doif( int hash );
int openinclude( char *, int );
int hasdirectory(char *, char * );
int openfile( char * );

/* cpp3.c */
int openfiles( char *filename );
void addfile( FILE *fp, char *filename );
void setincdirs();
int AddInclude( char *pIncStr );
int getredirection( int argc, char **argv );
void zap_uc( char *ap );

void initdefines();
int dooptions( int argc, char *argv[] );
int readoptions(char* filename, char*** pfargv);

/* cpp4.c */
void dodefines();
void checkparm( int c, DEFBUF *dp );
int expcollect();
void expstuff( DEFBUF *dp );

#if STRING_FORMAL
void stparmscan( int delim, DEFBUF *dp);
#else
void stparmscan( int delim);
#endif
#if OSL_DEBUG_LEVEL > 1
void dumpparm( char *why );
#endif

void doundef();
void textput( char *text );
void charput( int c );
void expand( DEFBUF *tokenp );

/* cpp5.c */
int eval();
int evallex(int);
int *evaleval(int *, int, int );
int evalchar(int);
int dosizeof();
int evalnum( int c );
int bittest( int );

/* cpp6.c */

void skipnl();
int skipws();
void scanid( int c );
int macroid( int c );
int catenate();
int scanstring( int c, void (*outfun)( int c ) );
void scannumber( int c, void (*outfun)( int c ) );
void save( int c );
char *savestring( char *text );
FILEINFO *getfile( int bufsize, char *name);
char *getmem( int size );
DEFBUF *lookid( int c );
DEFBUF *defendel( char *name, int delete );
void dunpdef( char *why );
void dumpadef( char *why, DEFBUF *dp);
int get();
int cget();
void unget();
void ungetstring( char *text );
void cerror( char *format, char *sarg);
void cwarn( char *format, char *sarg);
void cfatal( char *format, char *sarg);
void cierror( char *format, int n);
void ciwarn( char *format, int n);
#if OSL_DEBUG_LEVEL > 1
void dumpdef( char *why );
void dumpadef( char *why, DEFBUF *dp );
#endif

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */