Remove geometry support, again
[profile/ivi/libxkbcommon.git] / src / xkbcomp / keymap.c
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 #include "xkbcomp.h"
28 #include "xkbmisc.h"
29 #include "expr.h"
30 #include "vmod.h"
31 #include "action.h"
32 #include "misc.h"
33 #include "indicators.h"
34
35 #define KEYCODES        0
36 #define TYPES           1
37 #define COMPAT          2
38 #define SYMBOLS         3
39 #define MAX_SECTIONS    (SYMBOLS + 1)
40
41 /**
42  * Compile the given file and store the output in xkb.
43  * @param file A list of XkbFiles, each denoting one type (e.g.
44  * XkmKeyNamesIdx, etc.)
45  */
46 Bool
47 CompileKeymap(XkbFile *file, struct xkb_desc * xkb, unsigned merge)
48 {
49     unsigned have;
50     Bool ok;
51     unsigned required, legal;
52     unsigned mainType;
53     char *mainName;
54     LEDInfo *unbound = NULL;
55     XkbFile *sections[MAX_SECTIONS];
56
57     memset(sections, 0, sizeof(sections));
58     mainType = file->type;
59     mainName = file->name;
60     switch (mainType)
61     {
62     case XkmSemanticsFile:
63         required = XkmSemanticsRequired;
64         legal = XkmSemanticsLegal;
65         break;
66     case XkmLayoutFile:        /* standard type  if setxkbmap -print */
67         required = XkmLayoutRequired;
68         legal = XkmKeymapLegal;
69         break;
70     case XkmKeymapFile:
71         required = XkmKeymapRequired;
72         legal = XkmKeymapLegal;
73         break;
74     default:
75         ERROR("Cannot compile %s alone into an XKM file\n",
76                XkbcConfigText(mainType));
77         return False;
78     }
79     have = 0;
80     ok = 1;
81     file = (XkbFile *) file->defs;
82     /* Check for duplicate entries in the input file */
83     while ((file) && (ok))
84     {
85         if (file->topName != mainName) {
86             free(file->topName);
87             file->topName = strdup(mainName);
88         }
89         if ((have & (1 << file->type)) != 0)
90         {
91             ERROR("More than one %s section in a %s file\n",
92                    XkbcConfigText(file->type), XkbcConfigText(mainType));
93             ACTION("All sections after the first ignored\n");
94             ok = False;
95         }
96         else if ((1 << file->type) & (~legal))
97         {
98             ERROR("Cannot define %s in a %s file\n",
99                    XkbcConfigText(file->type), XkbcConfigText(mainType));
100             ok = False;
101         }
102         else
103             switch (file->type)
104             {
105             case XkmSemanticsFile:
106             case XkmLayoutFile:
107             case XkmKeymapFile:
108                 WSGO("Illegal %s configuration in a %s file\n",
109                       XkbcConfigText(file->type), XkbcConfigText(mainType));
110                 ACTION("Ignored\n");
111                 ok = False;
112                 break;
113             case XkmKeyNamesIndex:
114                 sections[KEYCODES] = file;
115                 break;
116             case XkmTypesIndex:
117                 sections[TYPES] = file;
118                 break;
119             case XkmSymbolsIndex:
120                 sections[SYMBOLS] = file;
121                 break;
122             case XkmCompatMapIndex:
123                 sections[COMPAT] = file;
124                 break;
125             case XkmGeometryIndex:
126                 /* XXX free me! */
127                 break;
128             case XkmVirtualModsIndex:
129             case XkmIndicatorsIndex:
130                 WSGO("Found an isolated %s section\n",
131                       XkbcConfigText(file->type));
132                 break;
133             default:
134                 WSGO("Unknown file type %d\n", file->type);
135                 break;
136             }
137         if (ok)
138             have |= (1 << file->type);
139         file = (XkbFile *) file->common.next;
140     }
141     /* compile the sections we have in the file one-by-one, or fail. */
142     if (ok)
143     {
144         if (ok && (sections[KEYCODES] != NULL))
145             ok = CompileKeycodes(sections[KEYCODES], xkb, MergeOverride);
146         if (ok && (sections[TYPES] != NULL))
147             ok = CompileKeyTypes(sections[TYPES], xkb, MergeOverride);
148         if (ok && (sections[COMPAT] != NULL))
149             ok = CompileCompatMap(sections[COMPAT], xkb, MergeOverride,
150                                   &unbound);
151         if (ok && (sections[SYMBOLS] != NULL))
152             ok = CompileSymbols(sections[SYMBOLS], xkb, MergeOverride);
153     }
154     if (!ok)
155         return False;
156     xkb->defined = have;
157     if (required & (~have))
158     {
159         int i, bit;
160         unsigned missing;
161         missing = required & (~have);
162         for (i = 0, bit = 1; missing != 0; i++, bit <<= 1)
163         {
164             if (missing & bit)
165             {
166                 ERROR("Missing %s section in a %s file\n",
167                        XkbcConfigText(i), XkbcConfigText(mainType));
168                 missing &= ~bit;
169             }
170         }
171         ACTION("Description of %s not compiled\n",
172                 XkbcConfigText(mainType));
173         return False;
174     }
175     ok = BindIndicators(xkb, True, unbound, NULL);
176     return ok;
177 }