55
55
return ((y + (y >> 3)) & 030707070707) % 077;
58
int xcb_parse_display(const char *name, char **host, int *displayp, int *screenp)
58
static int _xcb_parse_display(const char *name, char **host, char **protocol,
59
int *displayp, int *screenp)
60
61
int len, display, screen;
61
char *colon, *dot, *end;
62
char *slash, *colon, *dot, *end;
62
63
if(!name || !*name)
63
64
name = getenv("DISPLAY");
67
slash = strrchr(name, '/');
71
*protocol = malloc(len + 1);
74
memcpy(*protocol, name, len);
75
(*protocol)[len] = '\0';
66
82
colon = strrchr(name, ':');
99
static int _xcb_open_tcp(char *host, const unsigned short port);
100
static int _xcb_open_unix(const char *file);
115
int xcb_parse_display(const char *name, char **host, int *displayp,
118
return _xcb_parse_display(name, host, NULL, displayp, screenp);
121
static int _xcb_open_tcp(char *host, char *protocol, const unsigned short port);
122
static int _xcb_open_unix(char *protocol, const char *file);
102
static int _xcb_open_decnet(const char *host, const unsigned short port);
124
static int _xcb_open_decnet(const char *host, char *protocol, const unsigned short port);
105
static int _xcb_open(char *host, const int display)
127
static int _xcb_open(char *host, char *protocol, const int display)
130
static const char base[] = "/tmp/.X11-unix/X";
131
char file[sizeof(base) + 20];
112
/* DECnet displays have two colons, so xcb_parse_display will have left
113
one at the end. However, an IPv6 address can end with *two* colons,
114
so only treat this as a DECnet display if host ends with exactly one
136
/* DECnet displays have two colons, so _xcb_parse_display will have
137
left one at the end. However, an IPv6 address can end with *two*
138
colons, so only treat this as a DECnet display if host ends with
139
exactly one colon. */
116
140
char *colon = strchr(host, ':');
117
141
if(colon && *(colon+1) == '\0')
120
fd = _xcb_open_decnet(host, display);
144
return _xcb_open_decnet(host, protocol, display);
125
/* display specifies TCP */
126
unsigned short port = X_TCP_PORT + display;
127
fd = _xcb_open_tcp(host, port);
132
/* display specifies Unix socket */
133
static const char base[] = "/tmp/.X11-unix/X";
134
char file[sizeof(base) + 20];
135
snprintf(file, sizeof(file), "%s%d", base, display);
136
fd = _xcb_open_unix(file);
149
|| strcmp("unix",host)) { /* follow the old unix: rule */
151
/* display specifies TCP */
152
unsigned short port = X_TCP_PORT + display;
153
return _xcb_open_tcp(host, protocol, port);
157
/* display specifies Unix socket */
158
snprintf(file, sizeof(file), "%s%d", base, display);
159
return _xcb_open_unix(protocol, file);
143
static int _xcb_open_decnet(const char *host, const unsigned short port)
166
static int _xcb_open_decnet(const char *host, const char *protocol, const unsigned short port)
146
169
struct sockaddr_dn addr;
229
264
int fd, display = 0;
231
267
xcb_connection_t *c;
232
268
xcb_auth_info_t auth;
234
if(!xcb_parse_display(displayname, &host, &display, screenp))
270
if(!_xcb_parse_display(displayname, &host, &protocol, &display, screenp))
235
271
return (xcb_connection_t *) &error_connection;
236
fd = _xcb_open(host, display);
272
fd = _xcb_open(host, protocol, display);
239
275
return (xcb_connection_t *) &error_connection;
254
290
int fd, display = 0;
257
if(!xcb_parse_display(displayname, &host, &display, screenp))
294
if(!_xcb_parse_display(displayname, &host, &protocol, &display, screenp))
258
295
return (xcb_connection_t *) &error_connection;
259
fd = _xcb_open(host, display);
296
fd = _xcb_open(host, protocol, display);
262
299
return (xcb_connection_t *) &error_connection;