summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2011-07-04 15:02:20 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2011-08-22 15:56:49 +1000
commitfa8f4652819b692faaf2789cf32d7fa99fbb34aa (patch)
tree9ed6fcc47a128e27053c4f67b75ca0a96ee709e4
parent5b5477c05f691205064ca4d8034f8dd47ab975b7 (diff)
xfree86: factor out adding/removing a device from the input device array
No functional changes, just readability improvements. This also gets rid of the count variable. Count was just used for resizing the null-terminated list. Since we're not in a time-critical path here at all we can afford to loop the list multiple times instead of keeping an extra variable around. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Daniel Stone <daniel@fooishbar.org>
-rw-r--r--hw/xfree86/common/xf86Config.c93
1 files changed, 47 insertions, 46 deletions
diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c
index c7d567d55..83eac8b73 100644
--- a/hw/xfree86/common/xf86Config.c
+++ b/hw/xfree86/common/xf86Config.c
@@ -1068,6 +1068,46 @@ Bool xf86DRI2Enabled(void)
return xf86Info.dri2;
}
+/**
+ * Search for the pInfo in the null-terminated list given and remove (and
+ * free) it if present. All other devices are moved forward.
+ */
+static void
+freeDevice(InputInfoPtr *list, InputInfoPtr pInfo)
+{
+ InputInfoPtr *devs;
+
+ for (devs = list; devs && *devs; devs++) {
+ if (*devs == pInfo) {
+ free(*devs);
+ for (; devs && *devs; devs++)
+ devs[0] = devs[1];
+ break;
+ }
+ }
+}
+
+/**
+ * Append pInfo to the null-terminated list, allocating space as necessary.
+ * pInfo is copied into the last element.
+ */
+static InputInfoPtr*
+addDevice(InputInfoPtr *list, InputInfoPtr pInfo)
+{
+ InputInfoPtr *devs;
+ int count = 1;
+
+ for (devs = list; devs && *devs; devs++)
+ count++;
+
+ list = xnfrealloc(list, (count + 1) * sizeof(InputInfoPtr));
+ list[count] = NULL;
+
+ list[count - 1] = xnfalloc(sizeof(InputInfoRec));
+ *list[count - 1] = *pInfo;
+ return list;
+}
+
/*
* Locate the core input devices. These can be specified/located in
* the following ways, in order of priority:
@@ -1094,7 +1134,6 @@ checkCoreInputDevices(serverLayoutPtr servlayoutp, Bool implicitLayout)
InputInfoRec Pointer = {}, Keyboard = {};
XF86ConfInputPtr confInput;
XF86ConfInputRec defPtr, defKbd;
- int count = 0;
MessageType from = X_DEFAULT;
int found = 0;
const char *mousedrivers[] = { "mouse", "synaptics", "evdev", "vmmouse",
@@ -1119,7 +1158,6 @@ checkCoreInputDevices(serverLayoutPtr servlayoutp, Bool implicitLayout)
coreKeyboard = indp;
}
}
- count++;
}
confInput = NULL;
@@ -1139,17 +1177,9 @@ checkCoreInputDevices(serverLayoutPtr servlayoutp, Bool implicitLayout)
* removed.
*/
if (corePointer) {
- for (devs = servlayoutp->inputs; devs && *devs; devs++) {
- if (*devs == corePointer) {
- free(*devs);
- for (; devs && *devs; devs++)
- devs[0] = devs[1];
- break;
- }
- }
- count--;
+ freeDevice(servlayoutp->inputs, corePointer);
+ corePointer = NULL;
}
- corePointer = NULL;
foundPointer = TRUE;
}
@@ -1210,14 +1240,7 @@ checkCoreInputDevices(serverLayoutPtr servlayoutp, Bool implicitLayout)
Pointer.options = xf86addNewOption(Pointer.options,
xnfstrdup("CorePointer"), "on");
Pointer.fd = -1;
- count++;
- devs = xnfrealloc(servlayoutp->inputs,
- (count + 1) * sizeof(InputInfoPtr));
- devs[count - 1] = xnfalloc(sizeof(InputInfoRec));
- devs[count] = NULL;
-
- *devs[count - 1] = Pointer;
- servlayoutp->inputs = devs;
+ servlayoutp->inputs = addDevice(servlayoutp->inputs, &Pointer);
}
}
@@ -1256,14 +1279,7 @@ checkCoreInputDevices(serverLayoutPtr servlayoutp, Bool implicitLayout)
Pointer.options = xf86addNewOption(NULL,
xnfstrdup("AlwaysCore"), "on");
Pointer.fd = -1;
- count++;
- devs = xnfrealloc(servlayoutp->inputs,
- (count + 1) * sizeof(InputInfoPtr));
- devs[count - 1] = xnfalloc(sizeof(InputInfoRec));
- devs[count] = NULL;
-
- *devs[count - 1] = Pointer;
- servlayoutp->inputs = devs;
+ servlayoutp->inputs = addDevice(servlayoutp->inputs, &Pointer);
}
}
@@ -1284,17 +1300,9 @@ checkCoreInputDevices(serverLayoutPtr servlayoutp, Bool implicitLayout)
* removed.
*/
if (coreKeyboard) {
- for (devs = servlayoutp->inputs; devs && *devs; devs++) {
- if (*devs == coreKeyboard) {
- free(*devs);
- for (; devs && *devs; devs++)
- devs[0] = devs[1];
- break;
- }
- }
- count--;
+ freeDevice(servlayoutp->inputs, coreKeyboard);
+ coreKeyboard = NULL;
}
- coreKeyboard = NULL;
foundKeyboard = TRUE;
}
@@ -1353,14 +1361,7 @@ checkCoreInputDevices(serverLayoutPtr servlayoutp, Bool implicitLayout)
Keyboard.options = xf86addNewOption(Keyboard.options,
xnfstrdup("CoreKeyboard"), "on");
Keyboard.fd = -1;
- count++;
- devs = xnfrealloc(servlayoutp->inputs,
- (count + 1) * sizeof(InputInfoPtr));
- devs[count - 1] = xnfalloc(sizeof(InputInfoRec));
- devs[count] = NULL;
-
- *devs[count - 1] = Keyboard;
- servlayoutp->inputs = devs;
+ servlayoutp->inputs = addDevice(servlayoutp->inputs, &Keyboard);
}
}