Pull in enough structs and defines from XKBstr.h to only need XKB.h
[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 "tokens.h"
30 #include "expr.h"
31 #include "vmod.h"
32 #include "action.h"
33 #include "misc.h"
34 #include "indicators.h"
35
36 #define KEYCODES        0
37 #define GEOMETRY        1
38 #define TYPES           2
39 #define COMPAT          3
40 #define SYMBOLS         4
41 #define MAX_SECTIONS    5
42
43 static XkbFile *sections[MAX_SECTIONS];
44
45 /**
46  * Compile the given file and store the output in xkb.
47  * @param file A list of XkbFiles, each denoting one type (e.g.
48  * XkmKeyNamesIdx, etc.)
49  */
50 Bool
51 CompileKeymap(XkbFile *file, struct xkb_desc * xkb, unsigned merge)
52 {
53     unsigned have;
54     Bool ok;
55     unsigned required, legal;
56     unsigned mainType;
57     char *mainName;
58     LEDInfo *unbound = NULL;
59
60     bzero(sections, MAX_SECTIONS * sizeof(XkbFile *));
61     mainType = file->type;
62     mainName = file->name;
63     switch (mainType)
64     {
65     case XkmSemanticsFile:
66         required = XkmSemanticsRequired;
67         legal = XkmSemanticsLegal;
68         break;
69     case XkmLayoutFile:        /* standard type  if setxkbmap -print */
70         required = XkmLayoutRequired;
71         legal = XkmKeymapLegal;
72         break;
73     case XkmKeymapFile:
74         required = XkmKeymapRequired;
75         legal = XkmKeymapLegal;
76         break;
77     default:
78         ERROR("Cannot compile %s alone into an XKM file\n",
79                XkbcConfigText(mainType));
80         return False;
81     }
82     have = 0;
83     ok = 1;
84     file = (XkbFile *) file->defs;
85     /* Check for duplicate entries in the input file */
86     while ((file) && (ok))
87     {
88         file->topName = mainName;
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             case XkmGeometryFile:
127                 sections[GEOMETRY] = file;
128                 break;
129             case XkmVirtualModsIndex:
130             case XkmIndicatorsIndex:
131                 WSGO("Found an isolated %s section\n",
132                       XkbcConfigText(file->type));
133                 break;
134             default:
135                 WSGO("Unknown file type %d\n", file->type);
136                 break;
137             }
138         if (ok)
139             have |= (1 << file->type);
140         file = (XkbFile *) file->common.next;
141     }
142     /* compile the sections we have in the file one-by-one, or fail. */
143     if (ok)
144     {
145         if (ok && (sections[KEYCODES] != NULL))
146             ok = CompileKeycodes(sections[KEYCODES], xkb, MergeOverride);
147         if (ok && (sections[GEOMETRY] != NULL))
148             ok = CompileGeometry(sections[GEOMETRY], xkb, MergeOverride);
149         if (ok && (sections[TYPES] != NULL))
150             ok = CompileKeyTypes(sections[TYPES], xkb, MergeOverride);
151         if (ok && (sections[COMPAT] != NULL))
152             ok = CompileCompatMap(sections[COMPAT], xkb, MergeOverride,
153                                   &unbound);
154         if (ok && (sections[SYMBOLS] != NULL))
155             ok = CompileSymbols(sections[SYMBOLS], xkb, MergeOverride);
156     }
157     if (!ok)
158         return False;
159     xkb->defined = have;
160     if (required & (~have))
161     {
162         register int i, bit;
163         unsigned missing;
164         missing = required & (~have);
165         for (i = 0, bit = 1; missing != 0; i++, bit <<= 1)
166         {
167             if (missing & bit)
168             {
169                 ERROR("Missing %s section in a %s file\n",
170                        XkbcConfigText(i), XkbcConfigText(mainType));
171                 missing &= ~bit;
172             }
173         }
174         ACTION("Description of %s not compiled\n",
175                 XkbcConfigText(mainType));
176         ok = False;
177     }
178     ok = BindIndicators(xkb, True, unbound, NULL);
179     return ok;
180 }