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