1 /************************************************************
2 * Copyright (c) 1996 by Silicon Graphics Computer Systems, Inc.
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.
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.
25 ********************************************************/
28 * Copyright © 2012 Ran Benita <ran234@gmail.com>
30 * Permission is hereby granted, free of charge, to any person obtaining a
31 * copy of this software and associated documentation files (the "Software"),
32 * to deal in the Software without restriction, including without limitation
33 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
34 * and/or sell copies of the Software, and to permit persons to whom the
35 * Software is furnished to do so, subject to the following conditions:
37 * The above copyright notice and this permission notice (including the next
38 * paragraph) shall be included in all copies or substantial portions of the
41 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
42 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
43 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
44 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
45 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
46 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
47 * DEALINGS IN THE SOFTWARE.
50 #include "xkbcomp-priv.h"
53 #include "scanner-utils.h"
57 /* Values returned with some tokens, like yylval. */
76 return is_graph(ch) && ch != '\\';
79 static enum rules_token
80 lex(struct scanner *s, union lvalue *val)
82 skip_more_whitespace_and_comments:
84 while (chr(s, ' ') || chr(s, '\t'));
88 while (!eof(s) && !eol(s)) next(s);
93 while (eol(s)) next(s);
94 return TOK_END_OF_LINE;
97 /* Escaped line continuation. */
100 scanner_err(s, "illegal new line escape; must appear at end of line");
104 goto skip_more_whitespace_and_comments;
107 /* See if we're done. */
108 if (eof(s)) return TOK_END_OF_FILE;
111 s->token_line = s->line;
112 s->token_column = s->column;
114 /* Operators and punctuation. */
115 if (chr(s, '!')) return TOK_BANG;
116 if (chr(s, '=')) return TOK_EQUALS;
117 if (chr(s, '*')) return TOK_STAR;
121 val->string.start = s->s + s->pos;
123 while (is_ident(peek(s))) {
127 if (val->string.len == 0) {
128 scanner_err(s, "unexpected character after \'$\'; expected name");
131 return TOK_GROUP_NAME;
135 if (is_ident(peek(s))) {
136 val->string.start = s->s + s->pos;
138 while (is_ident(peek(s))) {
142 return TOK_IDENTIFIER;
145 scanner_err(s, "unrecognized token");
149 /***====================================================================***/
159 #define SVAL_LIT(literal) { literal, sizeof(literal) - 1 }
161 static const struct sval rules_mlvo_svals[_MLVO_NUM_ENTRIES] = {
162 [MLVO_MODEL] = SVAL_LIT("model"),
163 [MLVO_LAYOUT] = SVAL_LIT("layout"),
164 [MLVO_VARIANT] = SVAL_LIT("variant"),
165 [MLVO_OPTION] = SVAL_LIT("option"),
177 static const struct sval rules_kccgst_svals[_KCCGST_NUM_ENTRIES] = {
178 [KCCGST_KEYCODES] = SVAL_LIT("keycodes"),
179 [KCCGST_TYPES] = SVAL_LIT("types"),
180 [KCCGST_COMPAT] = SVAL_LIT("compat"),
181 [KCCGST_SYMBOLS] = SVAL_LIT("symbols"),
182 [KCCGST_GEOMETRY] = SVAL_LIT("geometry"),
186 * A broken-down version of xkb_rule_names (without the rules,
192 darray_sval variants;
198 darray_sval elements;
202 int mlvo_at_pos[_MLVO_NUM_ENTRIES];
203 unsigned int num_mlvo;
204 unsigned int defined_mlvo_mask;
205 xkb_layout_index_t layout_idx, variant_idx;
206 int kccgst_at_pos[_KCCGST_NUM_ENTRIES];
207 unsigned int num_kccgst;
208 unsigned int defined_kccgst_mask;
212 enum mlvo_match_type {
213 MLVO_MATCH_NORMAL = 0,
219 struct sval mlvo_value_at_pos[_MLVO_NUM_ENTRIES];
220 enum mlvo_match_type match_type_at_pos[_MLVO_NUM_ENTRIES];
221 unsigned int num_mlvo_values;
222 struct sval kccgst_value_at_pos[_KCCGST_NUM_ENTRIES];
223 unsigned int num_kccgst_values;
228 * This is the main object used to match a given RMLVO against a rules
229 * file and aggragate the results in a KcCGST. It goes through a simple
230 * matching state machine, with tokens as transitions (see
234 struct xkb_context *ctx;
236 struct rule_names rmlvo;
238 struct scanner scanner;
239 darray(struct group) groups;
240 /* Current mapping. */
241 struct mapping mapping;
245 darray_char kccgst[_KCCGST_NUM_ENTRIES];
249 strip_spaces(struct sval v)
251 while (v.len > 0 && is_space(v.start[0])) { v.len--; v.start++; }
252 while (v.len > 0 && is_space(v.start[v.len - 1])) v.len--;
257 split_comma_separated_string(const char *s)
259 darray_sval arr = darray_new();
262 * Make sure the array returned by this function always includes at
263 * least one value, e.g. "" -> { "" } and "," -> { "", "" }.
267 struct sval val = { NULL, 0 };
268 darray_append(arr, val);
273 struct sval val = { s, 0 };
274 while (*s != '\0' && *s != ',') { s++; val.len++; }
275 darray_append(arr, strip_spaces(val));
276 if (*s == '\0') break;
283 static struct matcher *
284 matcher_new(struct xkb_context *ctx,
285 const struct xkb_rule_names *rmlvo)
287 struct matcher *m = calloc(1, sizeof(*m));
292 m->rmlvo.model.start = rmlvo->model;
293 m->rmlvo.model.len = strlen_safe(rmlvo->model);
294 m->rmlvo.layouts = split_comma_separated_string(rmlvo->layout);
295 m->rmlvo.variants = split_comma_separated_string(rmlvo->variant);
296 m->rmlvo.options = split_comma_separated_string(rmlvo->options);
302 matcher_free(struct matcher *m)
307 darray_free(m->rmlvo.layouts);
308 darray_free(m->rmlvo.variants);
309 darray_free(m->rmlvo.options);
310 darray_foreach(group, m->groups)
311 darray_free(group->elements);
312 darray_free(m->groups);
316 #define matcher_err(matcher, fmt, ...) \
317 scanner_err(&(matcher)->scanner, fmt, ## __VA_ARGS__)
320 matcher_group_start_new(struct matcher *m, struct sval name)
322 struct group group = { .name = name, .elements = darray_new() };
323 darray_append(m->groups, group);
327 matcher_group_add_element(struct matcher *m, struct sval element)
329 darray_append(darray_item(m->groups, darray_size(m->groups) - 1).elements,
334 matcher_mapping_start_new(struct matcher *m)
336 for (unsigned i = 0; i < _MLVO_NUM_ENTRIES; i++)
337 m->mapping.mlvo_at_pos[i] = -1;
338 for (unsigned i = 0; i < _KCCGST_NUM_ENTRIES; i++)
339 m->mapping.kccgst_at_pos[i] = -1;
340 m->mapping.layout_idx = m->mapping.variant_idx = XKB_LAYOUT_INVALID;
341 m->mapping.num_mlvo = m->mapping.num_kccgst = 0;
342 m->mapping.defined_mlvo_mask = 0;
343 m->mapping.defined_kccgst_mask = 0;
344 m->mapping.skip = false;
348 extract_layout_index(const char *s, size_t max_len, xkb_layout_index_t *out)
350 /* This function is pretty stupid, but works for now. */
351 *out = XKB_LAYOUT_INVALID;
354 if (s[0] != '[' || !is_digit(s[1]) || s[2] != ']')
356 if (s[1] - '0' < 1 || s[1] - '0' > XKB_MAX_GROUPS)
358 /* To zero-based index. */
359 *out = s[1] - '0' - 1;
364 matcher_mapping_set_mlvo(struct matcher *m, struct sval ident)
366 enum rules_mlvo mlvo;
367 struct sval mlvo_sval;
369 for (mlvo = 0; mlvo < _MLVO_NUM_ENTRIES; mlvo++) {
370 mlvo_sval = rules_mlvo_svals[mlvo];
372 if (svaleq_prefix(mlvo_sval, ident))
377 if (mlvo >= _MLVO_NUM_ENTRIES) {
378 matcher_err(m, "invalid mapping: %.*s is not a valid value here; ignoring rule set",
379 ident.len, ident.start);
380 m->mapping.skip = true;
384 if (m->mapping.defined_mlvo_mask & (1u << mlvo)) {
385 matcher_err(m, "invalid mapping: %.*s appears twice on the same line; ignoring rule set",
386 mlvo_sval.len, mlvo_sval.start);
387 m->mapping.skip = true;
391 /* If there are leftovers still, it must be an index. */
392 if (mlvo_sval.len < ident.len) {
393 xkb_layout_index_t idx;
394 int consumed = extract_layout_index(ident.start + mlvo_sval.len,
395 ident.len - mlvo_sval.len, &idx);
396 if ((int) (ident.len - mlvo_sval.len) != consumed) {
397 matcher_err(m, "invalid mapping: \"%.*s\" may only be followed by a valid group index; ignoring rule set",
398 mlvo_sval.len, mlvo_sval.start);
399 m->mapping.skip = true;
403 if (mlvo == MLVO_LAYOUT) {
404 m->mapping.layout_idx = idx;
406 else if (mlvo == MLVO_VARIANT) {
407 m->mapping.variant_idx = idx;
410 matcher_err(m, "invalid mapping: \"%.*s\" cannot be followed by a group index; ignoring rule set",
411 mlvo_sval.len, mlvo_sval.start);
412 m->mapping.skip = true;
417 m->mapping.mlvo_at_pos[m->mapping.num_mlvo] = mlvo;
418 m->mapping.defined_mlvo_mask |= 1u << mlvo;
419 m->mapping.num_mlvo++;
423 matcher_mapping_set_kccgst(struct matcher *m, struct sval ident)
425 enum rules_kccgst kccgst;
426 struct sval kccgst_sval;
428 for (kccgst = 0; kccgst < _KCCGST_NUM_ENTRIES; kccgst++) {
429 kccgst_sval = rules_kccgst_svals[kccgst];
431 if (svaleq(rules_kccgst_svals[kccgst], ident))
436 if (kccgst >= _KCCGST_NUM_ENTRIES) {
437 matcher_err(m, "invalid mapping: %.*s is not a valid value here; ignoring rule set",
438 ident.len, ident.start);
439 m->mapping.skip = true;
443 if (m->mapping.defined_kccgst_mask & (1u << kccgst)) {
444 matcher_err(m, "invalid mapping: %.*s appears twice on the same line; ignoring rule set",
445 kccgst_sval.len, kccgst_sval.start);
446 m->mapping.skip = true;
450 m->mapping.kccgst_at_pos[m->mapping.num_kccgst] = kccgst;
451 m->mapping.defined_kccgst_mask |= 1u << kccgst;
452 m->mapping.num_kccgst++;
456 matcher_mapping_verify(struct matcher *m)
458 if (m->mapping.num_mlvo == 0) {
459 matcher_err(m, "invalid mapping: must have at least one value on the left hand side; ignoring rule set");
463 if (m->mapping.num_kccgst == 0) {
464 matcher_err(m, "invalid mapping: must have at least one value on the right hand side; ignoring rule set");
469 * This following is very stupid, but this is how it works.
470 * See the "Notes" section in the overview above.
473 if (m->mapping.defined_mlvo_mask & (1u << MLVO_LAYOUT)) {
474 if (m->mapping.layout_idx == XKB_LAYOUT_INVALID) {
475 if (darray_size(m->rmlvo.layouts) > 1)
479 if (darray_size(m->rmlvo.layouts) == 1 ||
480 m->mapping.layout_idx >= darray_size(m->rmlvo.layouts))
485 if (m->mapping.defined_mlvo_mask & (1u << MLVO_VARIANT)) {
486 if (m->mapping.variant_idx == XKB_LAYOUT_INVALID) {
487 if (darray_size(m->rmlvo.variants) > 1)
491 if (darray_size(m->rmlvo.variants) == 1 ||
492 m->mapping.variant_idx >= darray_size(m->rmlvo.variants))
500 m->mapping.skip = true;
504 matcher_rule_start_new(struct matcher *m)
506 memset(&m->rule, 0, sizeof(m->rule));
507 m->rule.skip = m->mapping.skip;
511 matcher_rule_set_mlvo_common(struct matcher *m, struct sval ident,
512 enum mlvo_match_type match_type)
514 if (m->rule.num_mlvo_values + 1 > m->mapping.num_mlvo) {
515 matcher_err(m, "invalid rule: has more values than the mapping line; ignoring rule");
519 m->rule.match_type_at_pos[m->rule.num_mlvo_values] = match_type;
520 m->rule.mlvo_value_at_pos[m->rule.num_mlvo_values] = ident;
521 m->rule.num_mlvo_values++;
525 matcher_rule_set_mlvo_wildcard(struct matcher *m)
527 struct sval dummy = { NULL, 0 };
528 matcher_rule_set_mlvo_common(m, dummy, MLVO_MATCH_WILDCARD);
532 matcher_rule_set_mlvo_group(struct matcher *m, struct sval ident)
534 matcher_rule_set_mlvo_common(m, ident, MLVO_MATCH_GROUP);
538 matcher_rule_set_mlvo(struct matcher *m, struct sval ident)
540 matcher_rule_set_mlvo_common(m, ident, MLVO_MATCH_NORMAL);
544 matcher_rule_set_kccgst(struct matcher *m, struct sval ident)
546 if (m->rule.num_kccgst_values + 1 > m->mapping.num_kccgst) {
547 matcher_err(m, "invalid rule: has more values than the mapping line; ignoring rule");
551 m->rule.kccgst_value_at_pos[m->rule.num_kccgst_values] = ident;
552 m->rule.num_kccgst_values++;
556 match_group(struct matcher *m, struct sval group_name, struct sval to)
559 struct sval *element;
562 darray_foreach(group, m->groups) {
563 if (svaleq(group->name, group_name)) {
571 * rules/evdev intentionally uses some undeclared group names
572 * in rules (e.g. commented group definitions which may be
573 * uncommented if needed). So we continue silently.
578 darray_foreach(element, group->elements)
579 if (svaleq(to, *element))
586 match_value(struct matcher *m, struct sval val, struct sval to,
587 enum mlvo_match_type match_type)
589 if (match_type == MLVO_MATCH_WILDCARD)
591 if (match_type == MLVO_MATCH_GROUP)
592 return match_group(m, val, to);
593 return svaleq(val, to);
597 * This function performs %-expansion on @value (see overview above),
598 * and appends the result to @to.
601 append_expanded_kccgst_value(struct matcher *m, darray_char *to,
604 const char *s = value.start;
605 darray_char expanded = darray_new();
607 bool expanded_plus, to_plus;
610 * Some ugly hand-lexing here, but going through the scanner is more
611 * trouble than it's worth, and the format is ugly on its own merit.
613 for (unsigned i = 0; i < value.len; ) {
615 xkb_layout_index_t idx;
617 struct sval expanded_value;
619 /* Check if that's a start of an expansion. */
621 /* Just a normal character. */
622 darray_appends_nullterminate(expanded, &s[i++], 1);
625 if (++i >= value.len) goto error;
629 /* Check for prefix. */
630 if (s[i] == '(' || s[i] == '+' || s[i] == '|' ||
631 s[i] == '_' || s[i] == '-') {
633 if (s[i] == '(') sfx = ')';
634 if (++i >= value.len) goto error;
637 /* Mandatory model/layout/variant specifier. */
639 case 'm': mlv = MLVO_MODEL; break;
640 case 'l': mlv = MLVO_LAYOUT; break;
641 case 'v': mlv = MLVO_VARIANT; break;
645 /* Check for index. */
646 idx = XKB_LAYOUT_INVALID;
647 if (i < value.len && s[i] == '[') {
650 if (mlv != MLVO_LAYOUT && mlv != MLVO_VARIANT) {
651 matcher_err(m, "invalid index in %%-expansion; may only index layout or variant");
655 consumed = extract_layout_index(s + i, value.len - i, &idx);
656 if (consumed == -1) goto error;
660 /* Check for suffix, if there supposed to be one. */
662 if (i >= value.len) goto error;
663 if (s[i++] != sfx) goto error;
666 /* Get the expanded value. */
667 expanded_value.len = 0;
669 if (mlv == MLVO_LAYOUT) {
670 if (idx != XKB_LAYOUT_INVALID &&
671 idx < darray_size(m->rmlvo.layouts) &&
672 darray_size(m->rmlvo.layouts) > 1)
673 expanded_value = darray_item(m->rmlvo.layouts, idx);
674 else if (idx == XKB_LAYOUT_INVALID &&
675 darray_size(m->rmlvo.layouts) == 1)
676 expanded_value = darray_item(m->rmlvo.layouts, 0);
678 else if (mlv == MLVO_VARIANT) {
679 if (idx != XKB_LAYOUT_INVALID &&
680 idx < darray_size(m->rmlvo.variants) &&
681 darray_size(m->rmlvo.variants) > 1)
682 expanded_value = darray_item(m->rmlvo.variants, idx);
683 else if (idx == XKB_LAYOUT_INVALID &&
684 darray_size(m->rmlvo.variants) == 1)
685 expanded_value = darray_item(m->rmlvo.variants, 0);
687 else if (mlv == MLVO_MODEL) {
688 expanded_value = m->rmlvo.model;
691 /* If we didn't get one, skip silently. */
692 if (expanded_value.len <= 0)
696 darray_appends_nullterminate(expanded, &pfx, 1);
697 darray_appends_nullterminate(expanded,
698 expanded_value.start, expanded_value.len);
700 darray_appends_nullterminate(expanded, &sfx, 1);
704 * Appending bar to foo -> foo (not an error if this happens)
705 * Appending +bar to foo -> foo+bar
706 * Appending bar to +foo -> bar+foo
707 * Appending +bar to +foo -> +foo+bar
710 ch = (darray_empty(expanded) ? '\0' : darray_item(expanded, 0));
711 expanded_plus = (ch == '+' || ch == '|');
712 ch = (darray_empty(*to) ? '\0' : darray_item(*to, 0));
713 to_plus = (ch == '+' || ch == '|');
715 if (expanded_plus || darray_empty(*to))
716 darray_appends_nullterminate(*to, expanded.item, expanded.size);
718 darray_prepends_nullterminate(*to, expanded.item, expanded.size);
720 darray_free(expanded);
724 darray_free(expanded);
725 matcher_err(m, "invalid %%-expansion in value; not used");
730 matcher_rule_verify(struct matcher *m)
732 if (m->rule.num_mlvo_values != m->mapping.num_mlvo ||
733 m->rule.num_kccgst_values != m->mapping.num_kccgst) {
734 matcher_err(m, "invalid rule: must have same number of values as mapping line; ignoring rule");
740 matcher_rule_apply_if_matches(struct matcher *m)
742 for (unsigned i = 0; i < m->mapping.num_mlvo; i++) {
743 enum rules_mlvo mlvo = m->mapping.mlvo_at_pos[i];
744 struct sval value = m->rule.mlvo_value_at_pos[i];
745 enum mlvo_match_type match_type = m->rule.match_type_at_pos[i];
746 bool matched = false;
748 if (mlvo == MLVO_MODEL) {
749 matched = match_value(m, value, m->rmlvo.model, match_type);
751 else if (mlvo == MLVO_LAYOUT) {
752 xkb_layout_index_t idx = m->mapping.layout_idx;
753 idx = (idx == XKB_LAYOUT_INVALID ? 0 : idx);
754 matched = match_value(m, value,
755 darray_item(m->rmlvo.layouts, idx),
758 else if (mlvo == MLVO_VARIANT) {
759 xkb_layout_index_t idx = m->mapping.layout_idx;
760 idx = (idx == XKB_LAYOUT_INVALID ? 0 : idx);
761 matched = match_value(m, value,
762 darray_item(m->rmlvo.variants, idx),
765 else if (mlvo == MLVO_OPTION) {
767 darray_foreach(option, m->rmlvo.options) {
768 matched = match_value(m, value, *option, match_type);
778 for (unsigned i = 0; i < m->mapping.num_kccgst; i++) {
779 enum rules_kccgst kccgst = m->mapping.kccgst_at_pos[i];
780 struct sval value = m->rule.kccgst_value_at_pos[i];
781 append_expanded_kccgst_value(m, &m->kccgst[kccgst], value);
785 * If a rule matches in a rule set, the rest of the set should be
786 * skipped. However, rule sets matching against options may contain
787 * several legitimate rules, so they are processed entirely.
789 if (!(m->mapping.defined_mlvo_mask & (1 << MLVO_OPTION)))
790 m->mapping.skip = true;
793 static enum rules_token
794 gettok(struct matcher *m)
796 return lex(&m->scanner, &m->val);
800 matcher_match(struct matcher *m, const char *string, size_t len,
801 const char *file_name, struct xkb_component_names *out)
803 enum rules_token tok;
808 scanner_init(&m->scanner, m->ctx, string, len, file_name);
811 switch (tok = gettok(m)) {
814 case TOK_END_OF_LINE:
816 case TOK_END_OF_FILE:
823 switch (tok = gettok(m)) {
825 matcher_group_start_new(m, m->val.string);
828 matcher_mapping_start_new(m);
829 matcher_mapping_set_mlvo(m, m->val.string);
836 switch (tok = gettok(m)) {
844 switch (tok = gettok(m)) {
846 matcher_group_add_element(m, m->val.string);
848 case TOK_END_OF_LINE:
855 switch (tok = gettok(m)) {
857 if (!m->mapping.skip)
858 matcher_mapping_set_mlvo(m, m->val.string);
867 switch (tok = gettok(m)) {
869 if (!m->mapping.skip)
870 matcher_mapping_set_kccgst(m, m->val.string);
872 case TOK_END_OF_LINE:
873 if (!m->mapping.skip)
874 matcher_mapping_verify(m);
875 goto rule_mlvo_first;
881 switch (tok = gettok(m)) {
884 case TOK_END_OF_LINE:
885 goto rule_mlvo_first;
886 case TOK_END_OF_FILE:
889 matcher_rule_start_new(m);
890 goto rule_mlvo_no_tok;
899 matcher_rule_set_mlvo(m, m->val.string);
903 matcher_rule_set_mlvo_wildcard(m);
907 matcher_rule_set_mlvo_group(m, m->val.string);
916 switch (tok = gettok(m)) {
919 matcher_rule_set_kccgst(m, m->val.string);
921 case TOK_END_OF_LINE:
923 matcher_rule_verify(m);
925 matcher_rule_apply_if_matches(m);
926 goto rule_mlvo_first;
940 if (darray_empty(m->kccgst[KCCGST_KEYCODES]) ||
941 darray_empty(m->kccgst[KCCGST_TYPES]) ||
942 darray_empty(m->kccgst[KCCGST_COMPAT]) ||
943 /* darray_empty(m->kccgst[KCCGST_GEOMETRY]) || */
944 darray_empty(m->kccgst[KCCGST_SYMBOLS]))
947 out->keycodes = darray_mem(m->kccgst[KCCGST_KEYCODES], 0);
948 out->types = darray_mem(m->kccgst[KCCGST_TYPES], 0);
949 out->compat = darray_mem(m->kccgst[KCCGST_COMPAT], 0);
950 /* out->geometry = darray_mem(m->kccgst[KCCGST_GEOMETRY], 0); */
951 darray_free(m->kccgst[KCCGST_GEOMETRY]);
952 out->symbols = darray_mem(m->kccgst[KCCGST_SYMBOLS], 0);
957 matcher_err(m, "unexpected token");
963 xkb_components_from_rules(struct xkb_context *ctx,
964 const struct xkb_rule_names *rmlvo,
965 struct xkb_component_names *out)
972 struct matcher *matcher;
974 file = FindFileInXkbPath(ctx, rmlvo->rules, FILE_TYPE_RULES, &path);
978 ret = map_file(file, &string, &size);
980 log_err(ctx, "Couldn't read rules file \"%s\": %s\n",
981 path, strerror(errno));
985 matcher = matcher_new(ctx, rmlvo);
986 ret = matcher_match(matcher, string, size, path, out);
988 log_err(ctx, "No components returned from XKB rules \"%s\"\n", path);
989 matcher_free(matcher);
991 unmap_file(string, size);