2 * Copyright (c) 1990, 2015, Oracle and/or its affiliates. All rights reserved.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
26 * winsysck - determine which window system protocols are available
28 * usage: winsysck [ -va ] [ -display display_name ] protocol [...]
31 * -a check every protocol listed, rather than stopping after
33 * -v print the first available protocol (or every available
34 * protocol, with the -a option) to stdout.
35 * -display display_name
36 * use the display display_name for X11 connections instead of
37 * the one specified by the $DISPLAY environment variable.
39 * The timeout option sets the number of seconds before
40 * the winsysck will time out.
48 * Both the X11 and the NeWS protocols, and both connect to
51 * The SunView protocol.
53 * NOTE: Since news, x11news, and sunview have been unsupported for over
54 * a decade, we no longer actually check for them, but always return false.
57 * 0 if any listed protocols are available
58 * 1 if no listed protocols are available
65 #include <sys/types.h>
74 fprintf(stderr
, "usage: %s %s\n\t%s\n", cmdname
,
75 "[-va] [-display display_name] [-timeout seconds] protocol [...]",
76 "protocol can be one of: x11 news x11news sunview");
81 * Keep track of what protocols we're checking, and in what order.
87 #define PROTO_X11NeWS 3
88 #define PROTO_SunView 4
91 static int proto_list
[N_PROTO
], n_proto
;
97 for (i
=0; i
<N_PROTO
; i
++) {
98 if (proto_list
[i
]==proto
) {
102 proto_list
[n_proto
++]=proto
;
106 * Keep track of the options specified.
108 static int verbose
, showall
, timeout
= 0;
110 static char* display_name
=NULL
;
117 Parse (int argc
, char* argv
[])
119 for (;argc
> 1; argv
++, argc
--) {
120 if (argv
[1][0] == '-') {
121 if (!strcmp(argv
[1], "-display")) {
122 display_name
=argv
[2];
127 if (!strcmp(argv
[1], "-timeout")) {
128 timeout
= atoi(argv
[2]);
133 for (; argv
[1][1]; argv
[1]++) {
134 switch (argv
[1][1]) {
142 fprintf(stderr
, "%s: -%c: unknown option\n",
149 if (!strcmp(argv
[1], "x11")) {
151 } else if (!strcmp(argv
[1], "news")) {
152 AddProto(PROTO_NeWS
);
153 } else if (!strcmp(argv
[1], "x11news")) {
154 AddProto(PROTO_X11NeWS
);
155 } else if (!strcmp(argv
[1], "sunview")) {
156 AddProto(PROTO_SunView
);
158 fprintf(stderr
, "%s: %s: unknown protocol\n",
165 fprintf(stderr
, "%s: no protocols specified\n",
171 /* Last remnants of x11-procs.c */
172 #include <X11/Xlib.h>
175 static Display
*display
=NULL
;
177 static void OnAlarm(int i
)
179 fprintf(stderr
, "winsysck timeout\n");
184 ConnectToX (const char* display_name
)
187 signal(SIGALRM
, OnAlarm
);
190 display
=XOpenDisplay(display_name
);
193 return((display
!= NULL
));
197 DisconnectFromX (void) {
198 XCloseDisplay(display
);
204 * Try connecting via the specified protocols.
210 for(i
=0; (i
< N_PROTO
) && (proto_list
[i
] != PROTO_NONE
); i
++) {
211 switch (proto_list
[i
]) {
213 if (ConnectToX(display_name
)) {
215 if (verbose
) printf("%s\n","x11");
217 if (!showall
) exit(0);
223 /* Don't even bother */
226 fprintf(stderr
, "%s: WSGO: proto_list[%d]==%d\n",
227 cmdname
,i
,proto_list
[i
]);
234 main (int argc
, char* argv
[])