-int XCBParseDisplay(const char *name, char **host, int *displayp, int *screenp)
+int xcb_sumof(uint8_t *list, int len)
+{
+ int i, s = 0;
+ for(i=0; i<len; i++) {
+ s += *list;
+ list++;
+ }
+ return s;
+}
+
+#ifdef HAVE_LAUNCHD
+/* Return true and parse if name matches <path to socket>[.<screen>]
+ * Upon success:
+ * host = <path to socket>
+ * protocol = "unix"
+ * display = 0
+ * screen = <screen>
+ */
+static int _xcb_parse_display_path_to_socket(const char *name, char **host, char **protocol,
+ int *displayp, int *screenp)
+{
+ struct stat sbuf;
+ char path[PATH_MAX];
+ int _screen = 0;
+
+ strlcpy(path, name, sizeof(path));
+ if (0 != stat(path, &sbuf)) {
+ char *dot = strrchr(path, '.');
+ if (!dot)
+ return 0;
+ *dot = '\0';
+
+ if (0 != stat(path, &sbuf))
+ return 0;
+
+ _screen = atoi(dot + 1);
+ }
+
+ if (host) {
+ *host = strdup(path);
+ if (!*host)
+ return 0;
+ }
+
+ if (protocol) {
+ *protocol = strdup("unix");
+ if (!*protocol) {
+ if (host)
+ free(*host);
+ return 0;
+ }
+ }
+
+ if (displayp)
+ *displayp = 0;
+
+ if (screenp)
+ *screenp = _screen;
+
+ return 1;
+}
+#endif
+
+static int _xcb_parse_display(const char *name, char **host, char **protocol,
+ int *displayp, int *screenp)