author | Alan Coopersmith <Alan.Coopersmith@Sun.COM> |
Thu, 18 Feb 2010 16:03:08 -0800 | |
changeset 907 | 3c35d611cdaa |
parent 476 | faaf67e90c1a |
child 919 | 425233ae7236 |
permissions | -rw-r--r-- |
472
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
1 |
/* |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
2 |
* Copyright 2008 Sun Microsystems, Inc. All rights reserved. |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
3 |
* Use subject to license terms. |
476
faaf67e90c1a
6727043 Move winsysck to open source tree (fix copyright formatting)
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
472
diff
changeset
|
4 |
* |
472
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
5 |
* Permission is hereby granted, free of charge, to any person obtaining a |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
6 |
* copy of this software and associated documentation files (the |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
7 |
* "Software"), to deal in the Software without restriction, including |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
8 |
* without limitation the rights to use, copy, modify, merge, publish, |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
9 |
* distribute, and/or sell copies of the Software, and to permit persons |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
10 |
* to whom the Software is furnished to do so, provided that the above |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
11 |
* copyright notice(s) and this permission notice appear in all copies of |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
12 |
* the Software and that both the above copyright notice(s) and this |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
13 |
* permission notice appear in supporting documentation. |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
14 |
* |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
15 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
16 |
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
17 |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
18 |
* OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
19 |
* HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
20 |
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
21 |
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
22 |
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
23 |
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
24 |
* |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
25 |
* Except as contained in this notice, the name of a copyright holder |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
26 |
* shall not be used in advertising or otherwise to promote the sale, use |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
27 |
* or other dealings in this Software without prior written authorization |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
28 |
* of the copyright holder. |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
29 |
*/ |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
30 |
|
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
31 |
|
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
32 |
/* |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
33 |
* winsysck - determine which window system protocols are available |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
34 |
* |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
35 |
* usage: winsysck [ -va ] [ -display display_name ] protocol [...] |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
36 |
* |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
37 |
* options: |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
38 |
* -a check every protocol listed, rather than stopping after |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
39 |
* the first one. |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
40 |
* -v print the first available protocol (or every available |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
41 |
* protocol, with the -a option) to stdout. |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
42 |
* -display display_name |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
43 |
* use the display display_name for X11 connections instead of |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
44 |
* the one specified by the $DISPLAY environment variable. |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
45 |
* -timeout seconds |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
46 |
* The timeout option sets the number of seconds before |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
47 |
* the winsysck will time out. |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
48 |
* |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
49 |
* protocols: |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
50 |
* x11 |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
51 |
* The X11 protocol. |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
52 |
* news |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
53 |
* The NeWS protocol. |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
54 |
* x11news |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
55 |
* Both the X11 and the NeWS protocols, and both connect to |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
56 |
* the same server. |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
57 |
* sunview |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
58 |
* The SunView protocol. |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
59 |
* |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
60 |
* NOTE: Since news, x11news, and sunview have been unsupported for over |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
61 |
* a decade, we no longer actually check for them, but always return false. |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
62 |
* |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
63 |
* exit status: |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
64 |
* 0 if any listed protocols are available |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
65 |
* 1 if no listed protocols are available |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
66 |
* 2 usage error |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
67 |
*/ |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
68 |
|
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
69 |
#include <stdio.h> |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
70 |
#include <stdlib.h> |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
71 |
#include <string.h> |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
72 |
#include <sys/types.h> |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
73 |
#include <sys/time.h> |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
74 |
#include <signal.h> |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
75 |
#include <unistd.h> |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
76 |
|
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
77 |
static char* cmdname; |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
78 |
|
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
79 |
static void |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
80 |
usage () { |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
81 |
fprintf(stderr, "usage: %s %s\n\t%s\n", cmdname, |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
82 |
"[-va] [-display display_name] [-timeout seconds] protocol [...]", |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
83 |
"protocol can be one of: x11 news x11news sunview"); |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
84 |
exit(2); |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
85 |
} |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
86 |
|
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
87 |
/* |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
88 |
* Keep track of what protocols we're checking, and in what order. |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
89 |
*/ |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
90 |
|
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
91 |
#define PROTO_NONE 0 |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
92 |
#define PROTO_X11 1 |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
93 |
#define PROTO_NeWS 2 |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
94 |
#define PROTO_X11NeWS 3 |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
95 |
#define PROTO_SunView 4 |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
96 |
#define N_PROTO 4 |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
97 |
|
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
98 |
static int proto_list[N_PROTO], n_proto; |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
99 |
|
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
100 |
static void |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
101 |
AddProto(int proto) |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
102 |
{ |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
103 |
int i; |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
104 |
for (i=0; i<N_PROTO; i++) { |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
105 |
if (proto_list[i]==proto) { |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
106 |
return; |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
107 |
} |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
108 |
} |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
109 |
proto_list[n_proto++]=proto; |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
110 |
} |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
111 |
|
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
112 |
/* |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
113 |
* Keep track of the options specified. |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
114 |
*/ |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
115 |
static int verbose, showall, timeout = 0; |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
116 |
|
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
117 |
static char* display_name=NULL; |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
118 |
|
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
119 |
/* |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
120 |
* Parse the options. |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
121 |
*/ |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
122 |
|
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
123 |
static void |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
124 |
Parse (int argc, char* argv[]) |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
125 |
{ |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
126 |
for (;argc > 1; argv++, argc--) { |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
127 |
if (argv[1][0] == '-') { |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
128 |
if (!strcmp(argv[1], "-display")) { |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
129 |
display_name=argv[2]; |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
130 |
argv++; |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
131 |
argc--; |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
132 |
continue; |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
133 |
} |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
134 |
if (!strcmp(argv[1], "-timeout")) { |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
135 |
timeout = atoi(argv[2]); |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
136 |
argv++; |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
137 |
argc--; |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
138 |
continue; |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
139 |
} |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
140 |
for (; argv[1][1]; argv[1]++) { |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
141 |
switch (argv[1][1]) { |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
142 |
case 'a': |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
143 |
showall++; |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
144 |
break; |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
145 |
case 'v': |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
146 |
verbose++; |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
147 |
break; |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
148 |
default: |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
149 |
fprintf(stderr, "%s: -%c: unknown option\n", |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
150 |
cmdname,argv[1][1]); |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
151 |
usage(); |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
152 |
} |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
153 |
} |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
154 |
} |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
155 |
else { |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
156 |
if (!strcmp(argv[1], "x11")) { |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
157 |
AddProto(PROTO_X11); |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
158 |
} else if (!strcmp(argv[1], "news")) { |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
159 |
AddProto(PROTO_NeWS); |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
160 |
} else if (!strcmp(argv[1], "x11news")) { |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
161 |
AddProto(PROTO_X11NeWS); |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
162 |
} else if (!strcmp(argv[1], "sunview")) { |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
163 |
AddProto(PROTO_SunView); |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
164 |
} else { |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
165 |
fprintf(stderr, "%s: %s: unknown protocol\n", |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
166 |
cmdname,argv[1]); |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
167 |
usage(); |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
168 |
} |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
169 |
} |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
170 |
} |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
171 |
if (!n_proto) { |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
172 |
fprintf(stderr, "%s: no protocols specified\n", |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
173 |
cmdname); |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
174 |
usage(); |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
175 |
} |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
176 |
} |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
177 |
|
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
178 |
/* Last remnants of x11-procs.c */ |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
179 |
#include <X11/Xlib.h> |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
180 |
#include <X11/Xos.h> |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
181 |
|
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
182 |
static Display *display=NULL; |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
183 |
|
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
184 |
static void OnAlarm(int i) |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
185 |
{ |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
186 |
fprintf(stderr, "winsysck timeout\n"); |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
187 |
exit(1); |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
188 |
} |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
189 |
|
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
190 |
static int |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
191 |
ConnectToX (const char* display_name) |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
192 |
{ |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
193 |
if(timeout > 0){ |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
194 |
signal(SIGALRM, OnAlarm); |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
195 |
alarm(timeout); |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
196 |
} |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
197 |
display=XOpenDisplay(display_name); |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
198 |
if(timeout > 0) |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
199 |
alarm(0); |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
200 |
return((display != NULL)); |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
201 |
} |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
202 |
|
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
203 |
static int |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
204 |
DisconnectFromX (void) { |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
205 |
XCloseDisplay(display); |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
206 |
return(1); |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
207 |
} |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
208 |
|
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
209 |
|
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
210 |
/* |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
211 |
* Try connecting via the specified protocols. |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
212 |
*/ |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
213 |
static void |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
214 |
Probe(void) |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
215 |
{ |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
216 |
int i, found=0; |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
217 |
for(i=0; (i < N_PROTO) && (proto_list[i] != PROTO_NONE); i++) { |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
218 |
switch (proto_list[i]) { |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
219 |
case PROTO_X11: |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
220 |
if (ConnectToX(display_name)) { |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
221 |
found++; |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
222 |
if (verbose) printf("%s\n","x11"); |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
223 |
DisconnectFromX(); |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
224 |
if (!showall) exit(0); |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
225 |
} |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
226 |
break; |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
227 |
case PROTO_NeWS: |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
228 |
case PROTO_X11NeWS: |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
229 |
case PROTO_SunView: |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
230 |
/* Don't even bother */ |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
231 |
break; |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
232 |
default: |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
233 |
fprintf(stderr, "%s: WSGO: proto_list[%d]==%d\n", |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
234 |
cmdname,i,proto_list[i]); |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
235 |
} |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
236 |
} |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
237 |
exit(!found); |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
238 |
} |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
239 |
|
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
240 |
int |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
241 |
main (int argc, char* argv[]) |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
242 |
{ |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
243 |
cmdname=argv[0]; |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
244 |
Parse(argc,argv); |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
245 |
Probe(); |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
246 |
exit(0); |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
247 |
} |
c6afe0d6b651
6727043 Move winsysck to open source tree
Jay Cotton <Jay.Cotton@Sun.COM>
parents:
diff
changeset
|
248 |