Make BindIndicators static
authorDaniel Stone <daniel@fooishbar.org>
Tue, 3 Jul 2012 20:22:09 +0000 (21:22 +0100)
committerDaniel Stone <daniel@fooishbar.org>
Thu, 12 Jul 2012 08:42:27 +0000 (09:42 +0100)
Since BindIndicators was only ever called immediately after
CopyIndicatorMapDefs, move it up in the file and turn it into a static
function, which avoids the need to ever pass the unbound LEDs around.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
src/xkbcomp/compat.c
src/xkbcomp/indicators.c
src/xkbcomp/indicators.h

index 5da98d7..d3e94c0 100644 (file)
@@ -784,7 +784,6 @@ CompileCompatMap(XkbFile *file, struct xkb_keymap *keymap, enum merge_mode merge
     int i;
     CompatInfo info;
     GroupCompatInfo *gcm;
-    LEDInfo *unbound = NULL;
 
     InitCompatInfo(&info, keymap);
     info.dflt.defs.merge = merge;
@@ -820,13 +819,11 @@ CompileCompatMap(XkbFile *file, struct xkb_keymap *keymap, enum merge_mode merge
     }
 
     if (info.leds != NULL) {
-        if (!CopyIndicatorMapDefs(keymap, info.leds, &unbound))
+        if (!CopyIndicatorMapDefs(keymap, info.leds))
             info.errorCount++;
         info.leds = NULL;
     }
 
-    BindIndicators(keymap, unbound);
-
     ClearCompatInfo(&info, keymap);
     return true;
 
index f1daca9..41b3649 100644 (file)
@@ -360,79 +360,7 @@ HandleIndicatorMapDef(IndicatorMapDef *def, struct xkb_keymap *keymap,
     return NULL;
 }
 
-bool
-CopyIndicatorMapDefs(struct xkb_keymap *keymap, LEDInfo *leds,
-                     LEDInfo **unboundRtrn)
-{
-    LEDInfo *led, *next;
-    LEDInfo *unbound, *last;
-
-    if (XkbcAllocNames(keymap, XkbIndicatorNamesMask, 0) != Success)
-    {
-        WSGO("Couldn't allocate names\n");
-        ACTION("Indicator names may be incorrect\n");
-    }
-    if (XkbcAllocIndicatorMaps(keymap) != Success)
-    {
-        WSGO("Can't allocate indicator maps\n");
-        ACTION("Indicator map definitions may be lost\n");
-        return false;
-    }
-    last = unbound = (unboundRtrn ? *unboundRtrn : NULL);
-    while ((last != NULL) && (last->defs.next != NULL))
-    {
-        last = (LEDInfo *) last->defs.next;
-    }
-    for (led = leds; led != NULL; led = next)
-    {
-        next = (LEDInfo *) led->defs.next;
-        if ((led->groups != 0) && (led->which_groups == 0))
-            led->which_groups = XkbIM_UseEffective;
-        if ((led->which_mods == 0) && ((led->real_mods) || (led->vmods)))
-            led->which_mods = XkbIM_UseEffective;
-        if ((led->indicator == _LED_NotBound) || (!keymap->indicators))
-        {
-            if (unboundRtrn != NULL)
-            {
-                led->defs.next = NULL;
-                if (last != NULL)
-                    last->defs.next = (CommonInfo *) led;
-                else
-                    unbound = led;
-                last = led;
-            }
-            else
-                free(led);
-        }
-        else
-        {
-            struct xkb_indicator_map * im;
-            im = &keymap->indicators->maps[led->indicator - 1];
-            im->flags = led->flags;
-            im->which_groups = led->which_groups;
-            im->groups = led->groups;
-            im->which_mods = led->which_mods;
-            im->mods.mask = led->real_mods;
-            im->mods.real_mods = led->real_mods;
-            im->mods.vmods = led->vmods;
-            im->ctrls = led->ctrls;
-            if (keymap->names != NULL)
-            {
-                free(keymap->names->indicators[led->indicator - 1]);
-                keymap->names->indicators[led->indicator-1] =
-                    xkb_atom_strdup(keymap->ctx, led->name);
-            }
-            free(led);
-        }
-    }
-    if (unboundRtrn != NULL)
-    {
-        *unboundRtrn = unbound;
-    }
-    return true;
-}
-
-void
+static void
 BindIndicators(struct xkb_keymap *keymap, LEDInfo *unbound)
 {
     int i;
@@ -532,3 +460,64 @@ BindIndicators(struct xkb_keymap *keymap, LEDInfo *unbound)
         free(led);
     }
 }
+
+bool
+CopyIndicatorMapDefs(struct xkb_keymap *keymap, LEDInfo *leds)
+{
+    LEDInfo *led, *next;
+    LEDInfo *unbound = NULL, *last = NULL;
+
+    if (XkbcAllocNames(keymap, XkbIndicatorNamesMask, 0) != Success)
+    {
+        WSGO("Couldn't allocate names\n");
+        ACTION("Indicator names may be incorrect\n");
+    }
+    if (XkbcAllocIndicatorMaps(keymap) != Success)
+    {
+        WSGO("Can't allocate indicator maps\n");
+        ACTION("Indicator map definitions may be lost\n");
+        return false;
+    }
+    for (led = leds; led != NULL; led = next)
+    {
+        next = (LEDInfo *) led->defs.next;
+        if ((led->groups != 0) && (led->which_groups == 0))
+            led->which_groups = XkbIM_UseEffective;
+        if ((led->which_mods == 0) && ((led->real_mods) || (led->vmods)))
+            led->which_mods = XkbIM_UseEffective;
+        if ((led->indicator == _LED_NotBound) || (!keymap->indicators))
+        {
+            led->defs.next = NULL;
+            if (last != NULL)
+                last->defs.next = (CommonInfo *) led;
+            else
+                unbound = led;
+            last = led;
+        }
+        else
+        {
+            struct xkb_indicator_map * im;
+            im = &keymap->indicators->maps[led->indicator - 1];
+            im->flags = led->flags;
+            im->which_groups = led->which_groups;
+            im->groups = led->groups;
+            im->which_mods = led->which_mods;
+            im->mods.mask = led->real_mods;
+            im->mods.real_mods = led->real_mods;
+            im->mods.vmods = led->vmods;
+            im->ctrls = led->ctrls;
+            if (keymap->names != NULL)
+            {
+                free(keymap->names->indicators[led->indicator - 1]);
+                keymap->names->indicators[led->indicator-1] =
+                    xkb_atom_strdup(keymap->ctx, led->name);
+            }
+            free(led);
+        }
+    }
+
+    if (unbound)
+        BindIndicators(keymap, unbound);
+
+    return true;
+}
index 713d46c..e485db5 100644 (file)
@@ -69,10 +69,5 @@ HandleIndicatorMapDef(IndicatorMapDef *stmt, struct xkb_keymap *keymap,
                       LEDInfo *dflt, LEDInfo *oldLEDs, enum merge_mode mergeMode);
 
 extern bool
-CopyIndicatorMapDefs(struct xkb_keymap *keymap, LEDInfo *leds,
-                     LEDInfo **unboundRtrn);
-
-extern void
-BindIndicators(struct xkb_keymap *keymap, LEDInfo *unbound);
-
+CopyIndicatorMapDefs(struct xkb_keymap *keymap, LEDInfo *leds);
 #endif /* INDICATORS_H */