summaryrefslogtreecommitdiff
path: root/src/xkbcomp/xkbcomp.c
diff options
context:
space:
mode:
authorRan Benita <ran234@gmail.com>2012-07-14 00:27:19 +0300
committerRan Benita <ran234@gmail.com>2012-07-14 00:29:31 +0300
commitfe4f990902c7cd8f395b9f3be14dc6e8cad7cae9 (patch)
tree9009e88a373d8888e8061c72cea86abc05f2784b /src/xkbcomp/xkbcomp.c
parent57374c3237d5976231a57fdcd9270ddcae313efb (diff)
downloadlibxkbcommon-fe4f990902c7cd8f395b9f3be14dc6e8cad7cae9.tar.gz
libxkbcommon-fe4f990902c7cd8f395b9f3be14dc6e8cad7cae9.tar.bz2
libxkbcommon-fe4f990902c7cd8f395b9f3be14dc6e8cad7cae9.zip
Move CompileKeymap into xkbcomp.c
It's nicer to see the code where its used. Removes keymap.c. Signed-off-by: Ran Benita <ran234@gmail.com>
Diffstat (limited to 'src/xkbcomp/xkbcomp.c')
-rw-r--r--src/xkbcomp/xkbcomp.c126
1 files changed, 124 insertions, 2 deletions
diff --git a/src/xkbcomp/xkbcomp.c b/src/xkbcomp/xkbcomp.c
index 49f7d4c..48e02bc 100644
--- a/src/xkbcomp/xkbcomp.c
+++ b/src/xkbcomp/xkbcomp.c
@@ -63,15 +63,137 @@ keymap_file_from_components(struct xkb_context *ctx,
&keycodes->common, 0);
}
+/**
+ * Compile the given file and store the output in keymap.
+ * @param file A list of XkbFiles, each denoting one type (e.g.
+ * FILE_TYPE_KEYCODES, etc.)
+ */
static struct xkb_keymap *
compile_keymap(struct xkb_context *ctx, XkbFile *file)
{
- struct xkb_keymap *keymap;
+ unsigned have = 0;
+ bool ok;
+ enum xkb_file_type main_type;
+ const char *main_name;
+ struct xkb_keymap *keymap = XkbcAllocKeyboard(ctx);
+ struct {
+ XkbFile *keycodes;
+ XkbFile *types;
+ XkbFile *compat;
+ XkbFile *symbols;
+ } sections = { NULL };
+
+ if (!keymap)
+ return NULL;
+
+ main_type = file->type;
+ main_name = file->name ? file->name : "(unnamed)";
+
+ /*
+ * Other aggregate file types are converted to FILE_TYPE_KEYMAP
+ * in the parser.
+ */
+ if (main_type != FILE_TYPE_KEYMAP) {
+ ERROR("Cannot compile a %s file alone into a keymap\n",
+ XkbcFileTypeText(main_type));
+ goto err;
+ }
+
+ /* Check for duplicate entries in the input file */
+ for (file = (XkbFile *)file->defs; file;
+ file = (XkbFile *)file->common.next) {
+ if (have & file->type) {
+ ERROR("More than one %s section in a %s file\n",
+ XkbcFileTypeText(file->type), XkbcFileTypeText(main_type));
+ ACTION("All sections after the first ignored\n");
+ continue;
+ }
+ else if (!(file->type & LEGAL_FILE_TYPES)) {
+ ERROR("Cannot define %s in a %s file\n",
+ XkbcFileTypeText(file->type), XkbcFileTypeText(main_type));
+ continue;
+ }
+
+ switch (file->type) {
+ case FILE_TYPE_KEYCODES:
+ sections.keycodes = file;
+ break;
+ case FILE_TYPE_TYPES:
+ sections.types = file;
+ break;
+ case FILE_TYPE_SYMBOLS:
+ sections.symbols = file;
+ break;
+ case FILE_TYPE_COMPAT:
+ sections.compat = file;
+ break;
+ default:
+ continue;
+ }
+
+ if (!file->topName || strcmp(file->topName, main_name) != 0) {
+ free(file->topName);
+ file->topName = strdup(main_name);
+ }
+
+ have |= file->type;
+ }
+
+ if (REQUIRED_FILE_TYPES & (~have)) {
+ enum xkb_file_type bit;
+ enum xkb_file_type missing;
+
+ missing = REQUIRED_FILE_TYPES & (~have);
+
+ for (bit = 1; missing != 0; bit <<= 1) {
+ if (missing & bit) {
+ ERROR("Required section %s missing from keymap\n",
+ XkbcFileTypeText(bit));
+ missing &= ~bit;
+ }
+ }
- keymap = CompileKeymap(ctx, file);
+ goto err;
+ }
+
+ /* compile the sections we have in the file one-by-one, or fail. */
+ if (sections.keycodes == NULL ||
+ !CompileKeycodes(sections.keycodes, keymap, MERGE_OVERRIDE))
+ {
+ ERROR("Failed to compile keycodes\n");
+ goto err;
+ }
+ if (sections.types == NULL ||
+ !CompileKeyTypes(sections.types, keymap, MERGE_OVERRIDE))
+ {
+ ERROR("Failed to compile key types\n");
+ goto err;
+ }
+ if (sections.compat == NULL ||
+ !CompileCompatMap(sections.compat, keymap, MERGE_OVERRIDE))
+ {
+ ERROR("Failed to compile compat map\n");
+ goto err;
+ }
+ if (sections.symbols == NULL ||
+ !CompileSymbols(sections.symbols, keymap, MERGE_OVERRIDE))
+ {
+ ERROR("Failed to compile symbols\n");
+ goto err;
+ }
+
+ ok = UpdateModifiersFromCompat(keymap);
+ if (!ok)
+ goto err;
FreeXKBFile(file);
return keymap;
+
+err:
+ ACTION("Failed to compile keymap\n");
+ xkb_map_unref(keymap);
+ FreeXKBFile(file);
+ return NULL;
}
struct xkb_keymap *