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 ************************************************************************/
31 #define INS 32768 /* input buffer */
32 #define OBS 8092 /* outbut buffer */
33 #define NARG 32 /* Max number arguments to a macro */
34 #define NINCLUDE 32 /* Max number of include directories (-I) */
35 #define NIF 64 /* depth of nesting of #if */
36 #define NINC 32 /* depth of nesting of #include */
47 typedef unsigned char uchar
;
53 END
, UNCLASS
, NAME
, NUMBER
, STRING
, CCON
, NL
, WS
, DSHARP
,
54 EQ
, NEQ
, LEQ
, GEQ
, LSH
, RSH
, LAND
, LOR
, PPLUS
, MMINUS
,
55 ARROW
, SBRA
, SKET
, LP
, RP
, DOT
, AND
, STAR
, PLUS
, MINUS
,
56 TILDE
, NOT
, SLASH
, PCT
, LT
, GT
, CIRC
, OR
, QUEST
,
57 COLON
, ASGN
, COMMA
, SHARP
, SEMIC
, CBRA
, CKET
,
58 ASPLUS
, ASMINUS
, ASSTAR
, ASSLASH
, ASPCT
, ASCIRC
, ASLSH
,
59 ASRSH
, ASOR
, ASAND
, ELLIPS
,
60 DSHARP1
, NAME1
, NAME2
, DEFINED
, UMINUS
, ARCHITECTURE
, IDENT
,
66 KIF
, KIFDEF
, KIFNDEF
, KELIF
, KELSE
, KENDIF
, KINCLUDE
, KINCLUDENEXT
,
67 KIMPORT
, KDEFINE
, KUNDEF
, KLINE
, KERROR
, KPRAGMA
, KIDENT
, KDEFINED
,
68 KMACHINE
, KLINENO
, KFILE
, KDATE
, KTIME
, KSTDC
, KEVAL
71 #define ISDEFINED 0x01 /* has #defined value */
72 #define ISKW 0x02 /* is PP keyword */
73 #define ISUNCHANGE 0x04 /* can't be #defined in PP */
74 #define ISMAC 0x08 /* builtin macro, e.g. __LINE__ */
75 #define ISARCHITECTURE 0x10 /* architecture */
76 #define ISACTIVE 0x80 /* is macro currently expanded */
78 #define EOB 0xFE /* sentinel for end of input buffer */
79 #define EOFC 0xFD /* sentinel for end of input file */
80 #define XPWS 1 /* token flag: white space to assure token sep. */
92 typedef struct tokenrow
94 Token
*tp
; /* current one to scan */
95 Token
*bp
; /* base (allocated value) */
96 Token
*lp
; /* last+1 token used */
97 int max
; /* number allocated */
100 typedef struct source
102 char *filename
; /* name of file of the source */
103 int line
; /* current line number */
104 int lineinc
; /* adjustment for \\n lines */
105 uchar
*inb
; /* input buffer */
106 uchar
*inp
; /* input pointer */
107 uchar
*inl
; /* end of input */
108 int fd
; /* input source */
109 int ifdepth
; /* conditional nesting in include */
112 struct source
*next
; /* stack for #include */
120 Tokenrow
*vp
; /* value as macro */
121 Tokenrow
*ap
; /* list of argument names, if any */
122 char val
; /* value as preprocessor name */
123 char flag
; /* is defined, is pp name */
124 uchar
*loc
; /* location of definition */
127 typedef struct includelist
134 typedef struct wraplist
139 #define new(t) (t *)domalloc(sizeof(t))
140 #define quicklook(a,b) (namebit[(a)&077] & (1<<((b)&037)))
141 #define quickset(a,b) namebit[(a)&077] |= (1<<((b)&037))
142 extern unsigned long namebit
[077 + 1];
146 INFO
, WARNING
, ERROR
, FATAL
149 void expandlex(void);
150 void setup(int, char **);
151 int gettokens(Tokenrow
*, int);
152 int comparetokens(Tokenrow
*, Tokenrow
*);
153 Source
*setsource(char *, int, int, char *, int);
154 void unsetsource(void);
155 void puttokens(Tokenrow
*);
156 void process(Tokenrow
*);
159 void error(enum errtype
, char *,...);
161 int fillbuf(Source
*);
162 int trigraph(Source
*);
163 int foldline(Source
*);
164 Nlist
*lookup(Token
*, int);
165 void control(Tokenrow
*);
166 void dodefine(Tokenrow
*);
167 void doadefine(Tokenrow
*, int);
168 void doinclude(Tokenrow
*, int, int);
169 void doif(Tokenrow
*, enum kwtype
);
170 void expand(Tokenrow
*, Nlist
*);
171 void builtin(Tokenrow
*, int);
172 int gatherargs(Tokenrow
*, Tokenrow
**, int *);
173 void substargs(Nlist
*, Tokenrow
*, Tokenrow
**);
174 void expandrow(Tokenrow
*, char *);
175 void maketokenrow(int, Tokenrow
*);
176 Tokenrow
*copytokenrow(Tokenrow
*, Tokenrow
*);
177 Token
*growtokenrow(Tokenrow
*);
178 Tokenrow
*normtokenrow(Tokenrow
*);
179 void adjustrow(Tokenrow
*, int);
180 void movetokenrow(Tokenrow
*, Tokenrow
*);
181 void insertrow(Tokenrow
*, int, Tokenrow
*);
182 void peektokens(Tokenrow
*, char *);
183 void doconcat(Tokenrow
*);
184 Tokenrow
*stringify(Tokenrow
*);
185 int lookuparg(Nlist
*, Token
*);
186 long eval(Tokenrow
*, int);
188 void genimport(char *, int, char *, int);
190 void setempty(Tokenrow
*);
191 void makespace(Tokenrow
*, Token
*);
192 char *outnum(char *, int);
194 uchar
*newstring(uchar
*, int, int);
196 #define rowlen(tokrow) ((tokrow)->lp - (tokrow)->bp)
199 extern Token nltoken
;
200 extern Source
*cursource
;
201 extern char *curtime
;
204 extern int ifsatisfied
[NIF
];
213 extern int Cplusplus
;
215 extern Nlist
*kwdefined
;
216 extern Includelist includelist
[NINCLUDE
];
217 extern Wraplist wraplist
[NINCLUDE
];