Added regedit unit test, a couple minor changes to regedit.
[wine] / tools / wrc / preproc.h
1 /*
2  * Copyright 1998 Bertho A. Stultiens (BS)
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18
19 #ifndef __WRC_PREPROC_H
20 #define __WRC_PREPROC_H
21
22 struct pp_entry;        /* forward */
23 /*
24  * Include logic
25  * A stack of files which are already included and
26  * are protected in the #ifndef/#endif way.
27  */
28 typedef struct includelogicentry {
29         struct includelogicentry *next;
30         struct includelogicentry *prev;
31         struct pp_entry *ppp;           /* The define which protects the file */
32         char            *filename;      /* The filename of the include */
33 } includelogicentry_t;
34
35 /*
36  * The arguments of a macrodefinition
37  */
38 typedef enum {
39         arg_single,
40         arg_list
41 } def_arg_t;
42
43 typedef struct marg {
44         def_arg_t       type;   /* Normal or ... argument */
45         char            *arg;   /* The textual argument */
46         int             nnl;    /* Number of newlines in the text to subst */
47 } marg_t;
48
49 /*
50  * The expansiontext of a macro
51  */
52 typedef enum {
53         exp_text,       /* Simple text substitution */
54         exp_concat,     /* Concat (##) operator requested */
55         exp_stringize,  /* Stringize (#) operator requested */
56         exp_subst       /* Substitute argument */
57 } def_exp_t;
58
59 typedef struct mtext {
60         struct mtext    *next;
61         struct mtext    *prev;
62         def_exp_t       type;
63         union {
64                 char    *text;
65                 int     argidx;         /* For exp_subst and exp_stringize reference */
66         } subst;
67 } mtext_t;
68
69 /*
70  * The define descriptor
71  */
72 typedef enum {
73         def_none,       /* Not-a-define; used as return value */
74         def_define,     /* Simple defines */
75         def_macro,      /* Macro defines */
76         def_special     /* Special expansions like __LINE__ and __FILE__ */
77 } def_type_t;
78
79 typedef struct pp_entry {
80         struct pp_entry *next;
81         struct pp_entry *prev;
82         def_type_t      type;           /* Define or macro */
83         char            *ident;         /* The key */
84         marg_t          **margs;        /* Macro arguments array or NULL if none */
85         int             nargs;
86         union {
87                 mtext_t *mtext;         /* The substitution sequence or NULL if none */
88                 char    *text;
89         } subst;
90         int             expanding;      /* Set when feeding substitution into the input */
91         char            *filename;      /* Filename where it was defined */
92         int             linenumber;     /* Linenumber where it was defined */
93         includelogicentry_t *iep;       /* Points to the include it protects */
94 } pp_entry_t;
95
96
97 /*
98  * If logic
99  */
100 #define MAXIFSTACK      64      /* If this isn't enough you should alter the source... */
101
102 typedef enum {
103         if_false,
104         if_true,
105         if_elif,
106         if_elsefalse,
107         if_elsetrue,
108         if_ignore
109 } if_state_t;
110
111 /*
112  * I assume that 'long long' exists in the compiler when it has a size
113  * of 8 or bigger. If not, then we revert to a simple 'long' for now.
114  * This should prevent most unexpected things with other compilers than
115  * gcc and egcs for now.
116  * In the future it should be possible to use another way, like a
117  * structure, so that we can emulate the MS compiler.
118  */
119 #if defined(SIZEOF_LONGLONG) && SIZEOF_LONGLONG >= 8
120 typedef long long wrc_sll_t;
121 typedef unsigned long long wrc_ull_t;
122 #else
123 typedef long wrc_sll_t;
124 typedef unsigned long wrc_ull_t;
125 #endif
126
127 #define SIZE_CHAR       1
128 #define SIZE_SHORT      2
129 #define SIZE_INT        3
130 #define SIZE_LONG       4
131 #define SIZE_LONGLONG   5
132 #define SIZE_MASK       0x00ff
133 #define FLAG_SIGNED     0x0100
134
135 typedef enum {
136 #if 0
137         cv_schar  = SIZE_CHAR + FLAG_SIGNED,
138         cv_uchar  = SIZE_CHAR,
139         cv_sshort = SIZE_SHORT + FLAG_SIGNED,
140         cv_ushort = SIZE_SHORT,
141 #endif
142         cv_sint   = SIZE_INT + FLAG_SIGNED,
143         cv_uint   = SIZE_INT,
144         cv_slong  = SIZE_LONG + FLAG_SIGNED,
145         cv_ulong  = SIZE_LONG,
146         cv_sll    = SIZE_LONGLONG + FLAG_SIGNED,
147         cv_ull    = SIZE_LONGLONG
148 } ctype_t;
149
150 typedef struct cval {
151         ctype_t type;
152         union {
153 #if 0
154                 signed char     sc;     /* Explicitely signed because compilers are stupid */
155                 unsigned char   uc;
156                 short           ss;
157                 unsigned short  us;
158 #endif
159                 int             si;
160                 unsigned int    ui;
161                 long            sl;
162                 unsigned long   ul;
163                 wrc_sll_t       sll;
164                 wrc_ull_t       ull;
165         } val;
166 } cval_t;
167
168
169
170 pp_entry_t *pplookup(char *ident);
171 pp_entry_t *add_define(char *def, char *text);
172 pp_entry_t *add_cmdline_define(char *set);
173 pp_entry_t *add_special_define(char *id);
174 pp_entry_t *add_macro(char *ident, marg_t *args[], int nargs, mtext_t *exp);
175 void del_define(char *name);
176 FILE *open_include(const char *name, int search, char **newpath);
177 void add_include_path(char *path);
178 void push_if(if_state_t s);
179 void next_if_state(int);
180 if_state_t pop_if(void);
181 if_state_t if_state(void);
182 int get_if_depth(void);
183
184 /*
185  * From ppl.l
186  */
187 extern FILE *ppin;
188 extern FILE *ppout;
189 extern char *pptext;
190 extern int pp_flex_debug;
191 int pplex(void);
192
193 void do_include(char *fname, int type);
194 void push_ignore_state(void);
195 void pop_ignore_state(void);
196
197 extern int include_state;
198 extern char *include_ppp;
199 extern char *include_filename;
200 extern int include_ifdepth;
201 extern int seen_junk;
202 extern includelogicentry_t *includelogiclist;
203
204 /*
205  * From ppy.y
206  */
207 int ppparse(void);
208 extern int ppdebug;
209
210 #endif
211