| 1 |
/* |
| 2 |
* For HPND: |
| 3 |
* Copyright (c) 1994 by Silicon Graphics Computer Systems, Inc. |
| 4 |
* |
| 5 |
* For MIT: |
| 6 |
* Copyright © 2012 Ran Benita <[email protected]> |
| 7 |
* |
| 8 |
* SPDX-License-Identifier: HPND AND MIT |
| 9 |
*/ |
| 10 |
#pragma once |
| 11 |
|
| 12 |
#include "config.h" |
| 13 |
|
| 14 |
#include "xkbcommon/xkbcommon.h" |
| 15 |
|
| 16 |
#include "atom.h" |
| 17 |
#include "darray.h" |
| 18 |
|
| 19 |
enum xkb_file_type { |
| 20 |
/* Component files, by order of compilation. */ |
| 21 |
FILE_TYPE_KEYCODES = 0, |
| 22 |
FILE_TYPE_TYPES = 1, |
| 23 |
FILE_TYPE_COMPAT = 2, |
| 24 |
FILE_TYPE_SYMBOLS = 3, |
| 25 |
|
| 26 |
/* File types which must be found in a keymap file. */ |
| 27 |
FIRST_KEYMAP_FILE_TYPE = FILE_TYPE_KEYCODES, |
| 28 |
LAST_KEYMAP_FILE_TYPE = FILE_TYPE_SYMBOLS, |
| 29 |
|
| 30 |
/* Geometry is not compiled any more. */ |
| 31 |
FILE_TYPE_GEOMETRY = 4, |
| 32 |
|
| 33 |
/* A top level file which includes the above files. */ |
| 34 |
FILE_TYPE_KEYMAP, |
| 35 |
|
| 36 |
|
| 37 |
/* This one doesn't mix with the others, but useful here as well. */ |
| 38 |
FILE_TYPE_RULES, |
| 39 |
|
| 40 |
_FILE_TYPE_NUM_ENTRIES, |
| 41 |
FILE_TYPE_INVALID = _FILE_TYPE_NUM_ENTRIES |
| 42 |
}; |
| 43 |
|
| 44 |
enum stmt_type { |
| 45 |
STMT_UNKNOWN = 0, |
| 46 |
STMT_INCLUDE, |
| 47 |
STMT_KEYCODE, |
| 48 |
STMT_ALIAS, |
| 49 |
STMT_EXPR_STRING_LITERAL, |
| 50 |
STMT_EXPR_INTEGER_LITERAL, |
| 51 |
STMT_EXPR_FLOAT_LITERAL, |
| 52 |
STMT_EXPR_BOOLEAN_LITERAL, |
| 53 |
STMT_EXPR_KEYNAME_LITERAL, |
| 54 |
STMT_EXPR_KEYSYM_LITERAL, |
| 55 |
STMT_EXPR_IDENT, |
| 56 |
STMT_EXPR_ACTION_DECL, |
| 57 |
STMT_EXPR_FIELD_REF, |
| 58 |
STMT_EXPR_ARRAY_REF, |
| 59 |
/* Needed because of the ambiguity between keysym and action empty lists */ |
| 60 |
STMT_EXPR_EMPTY_LIST, |
| 61 |
STMT_EXPR_KEYSYM_LIST, |
| 62 |
STMT_EXPR_ACTION_LIST, |
| 63 |
STMT_EXPR_ADD, |
| 64 |
STMT_EXPR_SUBTRACT, |
| 65 |
STMT_EXPR_MULTIPLY, |
| 66 |
STMT_EXPR_DIVIDE, |
| 67 |
STMT_EXPR_ASSIGN, |
| 68 |
STMT_EXPR_NOT, |
| 69 |
STMT_EXPR_NEGATE, |
| 70 |
STMT_EXPR_INVERT, |
| 71 |
STMT_EXPR_UNARY_PLUS, |
| 72 |
STMT_VAR, |
| 73 |
STMT_TYPE, |
| 74 |
STMT_INTERP, |
| 75 |
STMT_VMOD, |
| 76 |
STMT_SYMBOLS, |
| 77 |
STMT_MODMAP, |
| 78 |
STMT_GROUP_COMPAT, |
| 79 |
STMT_LED_MAP, |
| 80 |
STMT_LED_NAME, |
| 81 |
|
| 82 |
_STMT_NUM_VALUES |
| 83 |
}; |
| 84 |
|
| 85 |
enum merge_mode { |
| 86 |
MERGE_DEFAULT, |
| 87 |
MERGE_AUGMENT, |
| 88 |
MERGE_OVERRIDE, |
| 89 |
MERGE_REPLACE, |
| 90 |
_MERGE_MODE_NUM_ENTRIES, |
| 91 |
}; |
| 92 |
|
| 93 |
const char * |
| 94 |
xkb_file_type_to_string(enum xkb_file_type type); |
| 95 |
|
| 96 |
const char * |
| 97 |
stmt_type_to_string(enum stmt_type type); |
| 98 |
|
| 99 |
char |
| 100 |
stmt_type_to_operator_char(enum stmt_type type); |
| 101 |
|
| 102 |
typedef struct _ParseCommon { |
| 103 |
struct _ParseCommon *next; |
| 104 |
enum stmt_type type; |
| 105 |
} ParseCommon; |
| 106 |
|
| 107 |
typedef struct _IncludeStmt { |
| 108 |
ParseCommon common; |
| 109 |
enum merge_mode merge; |
| 110 |
char *stmt; |
| 111 |
char *file; |
| 112 |
char *map; |
| 113 |
char *modifier; |
| 114 |
struct _IncludeStmt *next_incl; |
| 115 |
} IncludeStmt; |
| 116 |
|
| 117 |
typedef union ExprDef ExprDef; |
| 118 |
|
| 119 |
typedef struct { |
| 120 |
ParseCommon common; |
| 121 |
xkb_atom_t ident; |
| 122 |
} ExprIdent; |
| 123 |
|
| 124 |
typedef struct { |
| 125 |
ParseCommon common; |
| 126 |
xkb_atom_t str; |
| 127 |
} ExprString; |
| 128 |
|
| 129 |
typedef struct { |
| 130 |
ParseCommon common; |
| 131 |
bool set; |
| 132 |
} ExprBoolean; |
| 133 |
|
| 134 |
typedef struct { |
| 135 |
ParseCommon common; |
| 136 |
int64_t ival; |
| 137 |
} ExprInteger; |
| 138 |
|
| 139 |
typedef struct { |
| 140 |
ParseCommon common; |
| 141 |
/* We don't support floats, but we still represnt them in the AST, in |
| 142 |
* order to provide proper error messages. */ |
| 143 |
} ExprFloat; |
| 144 |
|
| 145 |
typedef struct { |
| 146 |
ParseCommon common; |
| 147 |
xkb_atom_t key_name; |
| 148 |
} ExprKeyName; |
| 149 |
|
| 150 |
typedef struct { |
| 151 |
ParseCommon common; |
| 152 |
/* Keysyms are resolved early, so this might contain `NoSymbol` in case of |
| 153 |
* failure, to enable error recovery. */ |
| 154 |
xkb_keysym_t keysym; |
| 155 |
} ExprKeySym; |
| 156 |
|
| 157 |
typedef struct { |
| 158 |
ParseCommon common; |
| 159 |
ExprDef *left; |
| 160 |
ExprDef *right; |
| 161 |
} ExprBinary; |
| 162 |
|
| 163 |
typedef struct { |
| 164 |
ParseCommon common; |
| 165 |
ExprDef *child; |
| 166 |
} ExprUnary; |
| 167 |
|
| 168 |
typedef struct { |
| 169 |
ParseCommon common; |
| 170 |
xkb_atom_t element; |
| 171 |
xkb_atom_t field; |
| 172 |
} ExprFieldRef; |
| 173 |
|
| 174 |
typedef struct { |
| 175 |
ParseCommon common; |
| 176 |
xkb_atom_t element; |
| 177 |
xkb_atom_t field; |
| 178 |
ExprDef *entry; |
| 179 |
} ExprArrayRef; |
| 180 |
|
| 181 |
typedef struct { |
| 182 |
ParseCommon common; |
| 183 |
xkb_atom_t name; |
| 184 |
ExprDef *args; |
| 185 |
} ExprAction; |
| 186 |
|
| 187 |
typedef struct { |
| 188 |
ParseCommon common; |
| 189 |
/* List of actions for a single level. */ |
| 190 |
ExprDef *actions; |
| 191 |
} ExprActionList; |
| 192 |
|
| 193 |
typedef struct { |
| 194 |
ParseCommon common; |
| 195 |
/* List of keysym for a single level. */ |
| 196 |
darray(xkb_keysym_t) syms; |
| 197 |
} ExprKeysymList; |
| 198 |
|
| 199 |
union ExprDef { |
| 200 |
ParseCommon common; |
| 201 |
ExprIdent ident; |
| 202 |
ExprString string; |
| 203 |
ExprBoolean boolean; |
| 204 |
ExprInteger integer; |
| 205 |
ExprKeyName key_name; |
| 206 |
ExprKeySym keysym; |
| 207 |
ExprBinary binary; |
| 208 |
ExprUnary unary; |
| 209 |
ExprFieldRef field_ref; |
| 210 |
ExprArrayRef array_ref; |
| 211 |
ExprAction action; |
| 212 |
ExprActionList actions; |
| 213 |
ExprKeysymList keysym_list; |
| 214 |
}; |
| 215 |
|
| 216 |
typedef struct { |
| 217 |
ParseCommon common; |
| 218 |
enum merge_mode merge; |
| 219 |
ExprDef *name; |
| 220 |
ExprDef *value; |
| 221 |
} VarDef; |
| 222 |
|
| 223 |
typedef struct { |
| 224 |
ParseCommon common; |
| 225 |
enum merge_mode merge; |
| 226 |
xkb_atom_t name; |
| 227 |
ExprDef *value; |
| 228 |
} VModDef; |
| 229 |
|
| 230 |
typedef struct { |
| 231 |
ParseCommon common; |
| 232 |
enum merge_mode merge; |
| 233 |
xkb_atom_t name; |
| 234 |
int64_t value; |
| 235 |
} KeycodeDef; |
| 236 |
|
| 237 |
typedef struct { |
| 238 |
ParseCommon common; |
| 239 |
enum merge_mode merge; |
| 240 |
xkb_atom_t alias; |
| 241 |
xkb_atom_t real; |
| 242 |
} KeyAliasDef; |
| 243 |
|
| 244 |
typedef struct { |
| 245 |
ParseCommon common; |
| 246 |
enum merge_mode merge; |
| 247 |
xkb_atom_t name; |
| 248 |
VarDef *body; |
| 249 |
} KeyTypeDef; |
| 250 |
|
| 251 |
typedef struct { |
| 252 |
ParseCommon common; |
| 253 |
enum merge_mode merge; |
| 254 |
xkb_atom_t keyName; |
| 255 |
VarDef *symbols; |
| 256 |
} SymbolsDef; |
| 257 |
|
| 258 |
typedef struct { |
| 259 |
ParseCommon common; |
| 260 |
enum merge_mode merge; |
| 261 |
// NOTE: Can also be “None”, rather than a modifier name. |
| 262 |
xkb_atom_t modifier; |
| 263 |
ExprDef *keys; |
| 264 |
} ModMapDef; |
| 265 |
|
| 266 |
typedef struct { |
| 267 |
ParseCommon common; |
| 268 |
enum merge_mode merge; |
| 269 |
int64_t group; |
| 270 |
ExprDef *def; |
| 271 |
} GroupCompatDef; |
| 272 |
|
| 273 |
typedef struct { |
| 274 |
ParseCommon common; |
| 275 |
enum merge_mode merge; |
| 276 |
xkb_keysym_t sym; |
| 277 |
ExprDef *match; |
| 278 |
VarDef *def; |
| 279 |
} InterpDef; |
| 280 |
|
| 281 |
typedef struct { |
| 282 |
ParseCommon common; |
| 283 |
enum merge_mode merge; |
| 284 |
int64_t ndx; |
| 285 |
ExprDef *name; |
| 286 |
bool virtual; |
| 287 |
} LedNameDef; |
| 288 |
|
| 289 |
typedef struct { |
| 290 |
ParseCommon common; |
| 291 |
enum merge_mode merge; |
| 292 |
xkb_atom_t name; |
| 293 |
VarDef *body; |
| 294 |
} LedMapDef; |
| 295 |
|
| 296 |
enum xkb_map_flags { |
| 297 |
MAP_IS_DEFAULT = (1 << 0), |
| 298 |
MAP_IS_PARTIAL = (1 << 1), |
| 299 |
MAP_IS_HIDDEN = (1 << 2), |
| 300 |
MAP_HAS_ALPHANUMERIC = (1 << 3), |
| 301 |
MAP_HAS_MODIFIER = (1 << 4), |
| 302 |
MAP_HAS_KEYPAD = (1 << 5), |
| 303 |
MAP_HAS_FN = (1 << 6), |
| 304 |
MAP_IS_ALTGR = (1 << 7), |
| 305 |
}; |
| 306 |
|
| 307 |
typedef struct { |
| 308 |
ParseCommon common; |
| 309 |
enum xkb_file_type file_type; |
| 310 |
char *name; |
| 311 |
ParseCommon *defs; |
| 312 |
enum xkb_map_flags flags; |
| 313 |
} XkbFile; |