Interp: More lazy keysym resolution
[platform/upstream/libxkbcommon.git] / src / xkbcomp / compat.c
index 991d28a..6058c5a 100644 (file)
@@ -6,19 +6,19 @@
  fee is hereby granted, provided that the above copyright
  notice appear in all copies and that both that copyright
  notice and this permission notice appear in supporting
- documentation, and that the name of Silicon Graphics not be 
- used in advertising or publicity pertaining to distribution 
+ documentation, and that the name of Silicon Graphics not be
+ used in advertising or publicity pertaining to distribution
  of the software without specific prior written permission.
- Silicon Graphics makes no representation about the suitability 
+ Silicon Graphics makes no representation about the suitability
  of this software for any purpose. It is provided "as is"
  without any express or implied warranty.
- SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS 
- SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 
+
+ SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+ SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
- GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 
- DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 
- DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 
+ GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
+ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
  THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
@@ -26,6 +26,8 @@
 
 #include <X11/Xos.h>
 #include "xkbcomp.h"
+#include "xkballoc.h"
+#include "xkbmisc.h"
 #include "tokens.h"
 #include "expr.h"
 #include "vmod.h"
 #include "indicators.h"
 #include "action.h"
 #include "compat.h"
+#include "parseutils.h"
 
 typedef struct _SymInterpInfo
 {
     CommonInfo defs;
-    XkbSymInterpretRec interp;
+    XkbcSymInterpretRec interp;
 } SymInterpInfo;
 
 #define        _SI_VirtualMod          (1<<0)
@@ -116,9 +119,9 @@ InitCompatInfo(CompatInfo * info, XkbcDescPtr xkb)
     info->dflt.interp.flags = 0;
     info->dflt.interp.virtual_mod = XkbNoModifier;
     info->dflt.interp.act.type = XkbSA_NoAction;
-    for (i = 0; i < XkbAnyActionDataSize; i++)
+    for (i = 0; i < XkbcAnyActionDataSize; i++)
     {
-        info->dflt.interp.act.data[i] = 0;
+        info->dflt.interp.act.pad[i] = 0;
     }
     ClearIndicatorMapInfo(&info->ledDflt);
     info->ledDflt.defs.fileID = info->fileID;
@@ -144,9 +147,9 @@ ClearCompatInfo(CompatInfo * info, XkbcDescPtr xkb)
     info->dflt.interp.flags = 0;
     info->dflt.interp.virtual_mod = XkbNoModifier;
     info->dflt.interp.act.type = XkbSA_NoAction;
-    for (i = 0; i < XkbAnyActionDataSize; i++)
+    for (i = 0; i < XkbcAnyActionDataSize; i++)
     {
-        info->dflt.interp.act.data[i] = 0;
+        info->dflt.interp.act.pad[i] = 0;
     }
     ClearIndicatorMapInfo(&info->ledDflt);
     info->nInterps = 0;
@@ -606,19 +609,22 @@ HandleInterpVar(VarDef * stmt, XkbcDescPtr xkb, CompatInfo * info)
 {
     ExprResult elem, field;
     ExprDef *ndx;
+    int ret;
 
     if (ExprResolveLhs(stmt->name, &elem, &field, &ndx) == 0)
-        return 0;               /* internal error, already reported */
-    if (elem.str && (uStrCaseCmp(elem.str, "interpret") == 0))
-        return SetInterpField(&info->dflt, xkb, field.str, ndx, stmt->value,
+        ret = 0;               /* internal error, already reported */
+    else if (elem.str && (uStrCaseCmp(elem.str, "interpret") == 0))
+        ret = SetInterpField(&info->dflt, xkb, field.str, ndx, stmt->value,
                               info);
-    if (elem.str && (uStrCaseCmp(elem.str, "indicator") == 0))
-    {
-        return SetIndicatorMapField(&info->ledDflt, xkb, field.str, ndx,
-                                    stmt->value);
-    }
-    return SetActionField(xkb, elem.str, field.str, ndx, stmt->value,
-                          &info->act);
+    else if (elem.str && (uStrCaseCmp(elem.str, "indicator") == 0))
+        ret = SetIndicatorMapField(&info->ledDflt, xkb, field.str, ndx,
+                                  stmt->value);
+    else
+        ret = SetActionField(xkb, elem.str, field.str, ndx, stmt->value,
+                            &info->act);
+    free(elem.str);
+    free(field.str);
+    return ret;
 }
 
 static int
@@ -662,7 +668,12 @@ HandleInterpDef(InterpDef * def, XkbcDescPtr xkb, unsigned merge,
 
     si = info->dflt;
     si.defs.merge = merge;
-    si.interp.sym = def->sym;
+    if (!LookupKeysym(def->sym, &si.interp.sym))
+    {
+        WARN("Could not resolve keysym %s\n", def->sym);
+        info->errorCount++;
+        return False;
+    }
     si.interp.match = pred & XkbSI_OpMask;
     si.interp.mods = mods;
     if (!HandleInterpBody(def->def, xkb, &si, info))
@@ -718,7 +729,7 @@ HandleCompatMapFile(XkbFile * file,
 
     if (merge == MergeDefault)
         merge = MergeAugment;
-    info->name = uStringDup(file->name);
+    info->name = _XkbDupString(file->name);
     stmt = file->defs;
     while (stmt)
     {
@@ -782,7 +793,7 @@ HandleCompatMapFile(XkbFile * file,
 
 static void
 CopyInterps(CompatInfo * info,
-            XkbCompatMapPtr compat, Bool needSymbol, unsigned pred)
+            XkbcCompatMapPtr compat, Bool needSymbol, unsigned pred)
 {
     SymInterpInfo *si;
 
@@ -823,7 +834,6 @@ CompileCompatMap(XkbFile *file, XkbcDescPtr xkb, unsigned merge,
             Success)
         {
             WSGO("Couldn't allocate compatibility map\n");
-            ACTION("Exiting\n");
             return False;
         }
         if (info.name != NULL)
@@ -838,7 +848,7 @@ CompileCompatMap(XkbFile *file, XkbcDescPtr xkb, unsigned merge,
                         scanFile, info.name);
             }
         }
-        size = info.nInterps * sizeof(XkbSymInterpretRec);
+        size = info.nInterps * sizeof(XkbcSymInterpretRec);
         if (size > 0)
         {
             CopyInterps(&info, xkb->compat, True, XkbSI_Exactly);