Allocate xkb_component_names on stack
[platform/upstream/libxkbcommon.git] / src / xkbcomp / xkbcomp.h
1 /************************************************************
2  * Copyright (c) 1994 by Silicon Graphics Computer Systems, Inc.
3  *
4  * Permission to use, copy, modify, and distribute this
5  * software and its documentation for any purpose and without
6  * fee is hereby granted, provided that the above copyright
7  * notice appear in all copies and that both that copyright
8  * notice and this permission notice appear in supporting
9  * documentation, and that the name of Silicon Graphics not be
10  * used in advertising or publicity pertaining to distribution
11  * of the software without specific prior written permission.
12  * Silicon Graphics makes no representation about the suitability
13  * of this software for any purpose. It is provided "as is"
14  * without any express or implied warranty.
15  *
16  * SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
17  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
18  * AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
19  * GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
20  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
21  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
22  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
23  * THE USE OR PERFORMANCE OF THIS SOFTWARE.
24  *
25  ********************************************************/
26
27 #ifndef XKBCOMP_H
28 #define XKBCOMP_H 1
29
30 #include "xkb-priv.h"
31
32 enum stmt_type {
33     STMT_UNKNOWN = 0,
34     STMT_INCLUDE,
35     STMT_KEYCODE,
36     STMT_ALIAS,
37     STMT_EXPR,
38     STMT_VAR,
39     STMT_TYPE,
40     STMT_INTERP,
41     STMT_VMOD,
42     STMT_SYMBOLS,
43     STMT_MODMAP,
44     STMT_GROUP_COMPAT,
45     STMT_INDICATOR_MAP,
46     STMT_INDICATOR_NAME,
47     _STMT_NUM_VALUES
48 };
49
50 enum expr_value_type {
51     EXPR_TYPE_UNKNOWN = 0,
52     EXPR_TYPE_BOOLEAN,
53     EXPR_TYPE_INT,
54     EXPR_TYPE_STRING,
55     EXPR_TYPE_ACTION,
56     EXPR_TYPE_KEYNAME,
57     EXPR_TYPE_SYMBOLS,
58 };
59
60 enum expr_op_type {
61     EXPR_VALUE = 0,
62     EXPR_IDENT,
63     EXPR_ACTION_DECL,
64     EXPR_FIELD_REF,
65     EXPR_ARRAY_REF,
66     EXPR_KEYSYM_LIST,
67     EXPR_ACTION_LIST,
68     EXPR_ADD,
69     EXPR_SUBTRACT,
70     EXPR_MULTIPLY,
71     EXPR_DIVIDE,
72     EXPR_ASSIGN,
73     EXPR_NOT,
74     EXPR_NEGATE,
75     EXPR_INVERT,
76     EXPR_UNARY_PLUS,
77 };
78
79 enum merge_mode {
80     MERGE_DEFAULT,
81     MERGE_AUGMENT,
82     MERGE_OVERRIDE,
83     MERGE_REPLACE,
84 };
85
86 typedef struct _ParseCommon {
87     enum stmt_type type;
88     struct _ParseCommon *next;
89 } ParseCommon;
90
91 typedef struct _IncludeStmt {
92     ParseCommon common;
93     enum merge_mode merge;
94     char *stmt;
95     char *file;
96     char *map;
97     char *modifier;
98     struct _IncludeStmt *next_incl;
99 } IncludeStmt;
100
101 typedef struct _Expr {
102     ParseCommon common;
103     enum expr_op_type op;
104     enum expr_value_type value_type;
105     union {
106         struct {
107             struct _Expr *left;
108             struct _Expr *right;
109         } binary;
110         struct {
111             xkb_atom_t element;
112             xkb_atom_t field;
113         } field;
114         struct {
115             xkb_atom_t element;
116             xkb_atom_t field;
117             struct _Expr *entry;
118         } array;
119         struct {
120             xkb_atom_t name;
121             struct _Expr *args;
122         } action;
123         struct {
124             darray(char *) syms;
125             darray(int) symsMapIndex;
126             darray(unsigned int) symsNumEntries;
127         } list;
128         struct _Expr *child;
129         xkb_atom_t str;
130         unsigned uval;
131         int ival;
132         char keyName[XkbKeyNameLength];
133     } value;
134 } ExprDef;
135
136 typedef struct _VarDef {
137     ParseCommon common;
138     enum merge_mode merge;
139     ExprDef *name;
140     ExprDef *value;
141 } VarDef;
142
143 typedef struct _VModDef {
144     ParseCommon common;
145     enum merge_mode merge;
146     xkb_atom_t name;
147     ExprDef *value;
148 } VModDef;
149
150 typedef struct _KeycodeDef {
151     ParseCommon common;
152     enum merge_mode merge;
153     char name[XkbKeyNameLength];
154     unsigned long value;
155 } KeycodeDef;
156
157 typedef struct _KeyAliasDef {
158     ParseCommon common;
159     enum merge_mode merge;
160     char alias[XkbKeyNameLength];
161     char real[XkbKeyNameLength];
162 } KeyAliasDef;
163
164 typedef struct _KeyTypeDef {
165     ParseCommon common;
166     enum merge_mode merge;
167     xkb_atom_t name;
168     VarDef *body;
169 } KeyTypeDef;
170
171 typedef struct _SymbolsDef {
172     ParseCommon common;
173     enum merge_mode merge;
174     char keyName[XkbKeyNameLength];
175     ExprDef *symbols;
176 } SymbolsDef;
177
178 typedef struct _ModMapDef {
179     ParseCommon common;
180     enum merge_mode merge;
181     xkb_atom_t modifier;
182     ExprDef *keys;
183 } ModMapDef;
184
185 typedef struct _GroupCompatDef {
186     ParseCommon common;
187     enum merge_mode merge;
188     int group;
189     ExprDef *def;
190 } GroupCompatDef;
191
192 typedef struct _InterpDef {
193     ParseCommon common;
194     enum merge_mode merge;
195     char *sym;
196     ExprDef *match;
197     VarDef *def;
198 } InterpDef;
199
200 typedef struct _IndicatorNameDef {
201     ParseCommon common;
202     enum merge_mode merge;
203     int ndx;
204     ExprDef *name;
205     bool virtual;
206 } IndicatorNameDef;
207
208 typedef struct _IndicatorMapDef {
209     ParseCommon common;
210     enum merge_mode merge;
211     xkb_atom_t name;
212     VarDef *body;
213 } IndicatorMapDef;
214
215 typedef struct _XkbFile {
216     ParseCommon common;
217     enum xkb_file_type file_type;
218     char *topName;
219     char *name;
220     ParseCommon *defs;
221     int id;
222     unsigned flags;
223 } XkbFile;
224
225 extern bool
226 CompileKeycodes(XkbFile *file, struct xkb_keymap *keymap,
227                 enum merge_mode merge);
228
229 extern bool
230 CompileKeyTypes(XkbFile *file, struct xkb_keymap *keymap,
231                 enum merge_mode merge);
232
233 extern bool
234 CompileCompatMap(XkbFile *file, struct xkb_keymap *keymap,
235                  enum merge_mode merge);
236
237 extern bool
238 CompileSymbols(XkbFile *file, struct xkb_keymap *keymap,
239                enum merge_mode merge);
240
241 #endif /* XKBCOMP_H */