LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / soltools / cpp / cpp.h
blobab5a89fc99eb7dc615b42fecb4d975b47b048ec7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include <stdlib.h>
21 #include <string.h>
23 #define INS 327680 /* input buffer */
24 #define OBS 8092 /* output buffer */
25 #define NARG 32 /* Max number arguments to a macro */
26 #define NINCLUDE 48 /* Max number of include directories (-I) */
27 #define NIF 64 /* depth of nesting of #if */
28 #define NINC 32 /* depth of nesting of #include */
30 #ifndef EOF
31 #define EOF (-1)
32 #endif
34 #ifndef NULL
35 #define NULL 0
36 #endif
38 typedef unsigned char uchar;
40 enum toktype
42 END, UNCLASS, NAME, NUMBER, STRING, CCON, NL, WS, DSHARP,
43 EQ, NEQ, LEQ, GEQ, LSH, RSH, LAND, LOR, PPLUS, MMINUS,
44 ARROW, SBRA, SKET, LP, RP, DOT, AND, STAR, PLUS, MINUS,
45 TILDE, NOT, SLASH, PCT, LT, GT, CIRC, OR, QUEST,
46 COLON, ASGN, COMMA, SHARP, SEMIC, CBRA, CKET,
47 ASPLUS, ASMINUS, ASSTAR, ASSLASH, ASPCT, ASCIRC, ASLSH,
48 ASRSH, ASOR, ASAND, ELLIPS,
49 DSHARP1, NAME1, NAME2, DEFINED, UMINUS, ARCHITECTURE,
50 COMMENT
53 enum kwtype
55 KIF, KIFDEF, KIFNDEF, KELIF, KELSE, KENDIF, KINCLUDE, KINCLUDENEXT,
56 KIMPORT, KDEFINE, KUNDEF, KLINE, KERROR, KPRAGMA, KIDENT, KDEFINED,
57 KMACHINE, KLINENO, KFILE, KDATE, KTIME, KSTDC, KEVAL
60 extern void setup_kwtab(void);
62 #define ISDEFINED 0x01 /* has #defined value */
63 #define ISKW 0x02 /* is PP keyword */
64 #define ISUNCHANGE 0x04 /* can't be #defined in PP */
65 #define ISMAC 0x08 /* builtin macro, e.g. __LINE__ */
66 #define ISARCHITECTURE 0x10 /* architecture */
67 #define ISACTIVE 0x80 /* is macro currently expanded */
69 #define EOB 0xFE /* sentinel for end of input buffer */
70 #define EOFC 0xFD /* sentinel for end of input file */
71 #define XPWS 1 /* token flag: white space to assure token sep. */
72 #define XTWS 2
74 typedef struct token
76 unsigned char type;
77 size_t wslen;
78 size_t len;
79 uchar *t;
80 unsigned int identifier; /* used from macro processor to identify where a macro becomes valid again. */
81 } Token;
83 typedef struct tokenrow
85 Token *tp; /* current one to scan */
86 Token *bp; /* base (allocated value) */
87 Token *lp; /* last+1 token used */
88 size_t max; /* number allocated */
89 } Tokenrow;
91 typedef struct source
93 char *filename; /* name of file of the source */
94 int line; /* current line number */
95 int lineinc; /* adjustment for \\n lines */
96 uchar *inb; /* input buffer */
97 uchar *inp; /* input pointer */
98 uchar *inl; /* end of input */
99 int fd; /* input source */
100 int ifdepth; /* conditional nesting in include */
101 int pathdepth;
102 int wrap;
103 struct source *next; /* stack for #include */
104 } Source;
106 typedef struct nlist
108 struct nlist *next;
109 uchar *name;
110 size_t len;
111 Tokenrow *vp; /* value as macro */
112 Tokenrow *ap; /* list of argument names, if any */
113 char val; /* value as preprocessor name */
114 char flag; /* is defined, is pp name */
115 uchar *loc; /* location of definition */
116 } Nlist;
118 typedef struct includelist
120 char deleted;
121 char always;
122 char *file;
123 } Includelist;
125 typedef struct wraplist
127 char *file;
128 } Wraplist;
130 #define new(t) (t *)domalloc(sizeof(t))
131 #define quicklook(a,b) (namebit[(a)&077] & (1U<<((b)&037)))
132 #define quickset(a,b) namebit[(a)&077] |= (1U<<((b)&037))
133 extern unsigned long namebit[077 + 1];
135 enum errtype
137 INFO, WARNING, ERROR, FATAL
141 typedef struct macroValidator
143 Nlist * pMacro;
144 unsigned int nTokenWhereMacroBecomesValid;
145 struct macroValidator *
146 pNext;
147 } MacroValidator;
148 typedef struct mvl
150 MacroValidator * pFirst;
151 unsigned int nextFreeIdentifier;
152 } MacroValidatorList;
154 void mvl_init(
155 MacroValidatorList *
156 out_pValidators);
157 void mvl_destruct(
158 MacroValidatorList *
159 out_pValidators);
160 /* Adds MacroValidator to the list.
162 void mvl_add(
163 MacroValidatorList *
164 inout_pValidators,
165 Nlist * in_pMacro,
166 Token * in_pTokenWhereMacroBecomesValid);
168 /* Checks if one of the validators within the list points to
169 the token in_pTokenToCheck. If so, the macro is set valid and
170 the validator is removed.
172 void mvl_check(
173 MacroValidatorList *
174 inout_pValidators,
175 Token const * inout_pTokenToCheck);
177 void tokenrow_zeroTokenIdentifiers(Tokenrow* trp);
179 void expandlex(void);
180 void fixlex(void);
181 void setup(int, char **);
182 int gettokens(Tokenrow *, int);
183 int comparetokens(Tokenrow *, Tokenrow *);
184 Source *setsource(char *, int, int, char const *, int);
185 void unsetsource(void);
186 void puttokens(Tokenrow *);
187 void process(Tokenrow *);
188 void *domalloc(size_t);
189 void dofree(void *);
190 void error(enum errtype, char *,...);
191 void flushout(void);
192 int fillbuf(Source *);
193 int trigraph(Source *);
194 int foldline(Source *);
195 Nlist *lookup(Token *, int);
196 void control(Tokenrow *);
197 void dodefine(Tokenrow *);
198 void doadefine(Tokenrow *, int);
199 void doinclude(Tokenrow *, int, int);
200 void expand(Tokenrow *, Nlist *, MacroValidatorList *);
201 void builtin(Tokenrow *, int);
202 int gatherargs(Tokenrow *, Tokenrow **, int *);
203 void substargs(Nlist *, Tokenrow *, Tokenrow **);
204 void expandrow(Tokenrow *, char *);
205 void maketokenrow(int, Tokenrow *);
206 Tokenrow *copytokenrow(Tokenrow *, Tokenrow const *);
207 Token *growtokenrow(Tokenrow *);
208 Tokenrow *normtokenrow(Tokenrow *);
209 void adjustrow(Tokenrow *, int);
210 void movetokenrow(Tokenrow *, Tokenrow const *);
211 void insertrow(Tokenrow *, int, Tokenrow const *);
212 void peektokens(Tokenrow *, char *);
213 void doconcat(Tokenrow *);
214 Tokenrow *stringify(Tokenrow *);
215 int lookuparg(Nlist *, Token const *);
216 long eval(Tokenrow *, int);
217 void genline(void);
218 void genimport(char const *, int, char const *, int);
219 void genwrap(int);
220 void setempty(Tokenrow *);
221 void makespace(Tokenrow *, Token const *);
222 char *outnum(char *, int);
223 int digit(int);
224 uchar *newstring(uchar const *, size_t, size_t);
226 #define rowlen(tokrow) ((tokrow)->lp - (tokrow)->bp)
228 extern char *outptr;
229 extern Token nltoken;
230 extern Source *cursource;
231 extern char *curtime;
232 extern int incdepth;
233 extern int ifdepth;
234 extern int ifsatisfied[NIF];
235 extern int Mflag;
236 extern int Iflag;
237 extern int Pflag;
238 extern int Aflag;
239 extern int Lflag;
240 extern int Xflag;
241 extern int Vflag;
242 extern int Cflag;
243 extern int Dflag;
244 extern int Cplusplus;
245 extern int skipping;
246 extern Nlist *kwdefined;
247 extern Includelist includelist[NINCLUDE];
248 extern Wraplist wraplist[NINCLUDE];
249 extern char wd[];
251 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */