OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [tags/] [MW_0_8_9PRE7/] [mw/] [src/] [demos/] [vnc/] [vncviewer/] [args.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 673 markom
/*
2
 *  Copyright (C) 1997, 1998 Olivetti & Oracle Research Laboratory
3
 *
4
 *  This is free software; you can redistribute it and/or modify
5
 *  it under the terms of the GNU General Public License as published by
6
 *  the Free Software Foundation; either version 2 of the License, or
7
 *  (at your option) any later version.
8
 *
9
 *  This software is distributed in the hope that it will be useful,
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 *  GNU General Public License for more details.
13
 *
14
 *  You should have received a copy of the GNU General Public License
15
 *  along with this software; if not, write to the Free Software
16
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
17
 *  USA.
18
 */
19
 
20
/*
21
 * args.c - argument processing.
22
 */
23
 
24
#include <sys/utsname.h>
25
#include <vncviewer.h>
26
 
27
#define FLASHPORT  (5400)    /* Offset to listen for `flash' commands */
28
#define CLIENTPORT (5500)    /* Offset to listen for reverse connections */
29
#define SERVERPORT (5900)    /* Offset to server for regular connections */
30
 
31
char *programName;
32
 
33
char hostname[256];
34
int port;
35
 
36
Bool listenSpecified = False;
37
int listenPort = 0, flashPort = 0;
38
 
39
char *displayname = NULL;
40
 
41
Bool shareDesktop = False;
42
Bool viewOnly = False;
43
 
44
CARD32 explicitEncodings[MAX_ENCODINGS];
45
int nExplicitEncodings = 0;
46
Bool addCopyRect = True;
47
Bool addRRE = True;
48
Bool addCoRRE = True;
49
Bool addHextile = True;
50
 
51
Bool useBGR233 = False;
52
Bool forceOwnCmap = False;
53
Bool forceTruecolour = False;
54
int requestedDepth = 0;
55
 
56
char *geometry = NULL;
57
 
58
int wmDecorationWidth = 4;
59
int wmDecorationHeight = 24;
60
 
61
char *passwdFile = NULL;
62
 
63
int updateRequestPeriodms = 0;
64
 
65
int updateRequestX = 0;
66
int updateRequestY = 0;
67
int updateRequestW = 0;
68
int updateRequestH = 0;
69
 
70
int rawDelay = 0;
71
int copyRectDelay = 0;
72
 
73
Bool debug = False;
74
 
75
 
76
void
77
usage()
78
{
79
    fprintf(stderr,"\n"
80
            "usage: %s [<options>] <host>:<display#>\n"
81
            "       %s [<options>] -listen [<display#>]\n"
82
            "\n"
83
            "<options> are:\n"
84
            "              [-display <display>] [-shared] [-viewonly]\n"
85
            "              [-raw] [-copyrect] [-rre] [-corre] [-hextile]\n"
86
            "              [-nocopyrect] [-norre] [-nocorre] [-nohextile]\n"
87
            "              [-bgr233] [-owncmap] [-truecolour] [-depth <d>]\n"
88
            "              [-geometry <geom>]\n"
89
            "              [-wmdecoration <width>x<height>]\n"
90
            "              [-passwd <passwd-file>]\n"
91
            "              [-period <ms>]\n"
92
            "              [-region <x> <y> <width> <height>]\n"
93
            "              [-rawdelay <ms>] [-copyrectdelay <ms>] [-debug]\n\n"
94
            ,programName,programName);
95
    exit(1);
96
}
97
 
98
 
99
void
100
processArgs(int argc, char **argv)
101
{
102
    int i;
103
    Bool argumentSpecified = False;
104
 
105
    programName = argv[0];
106
 
107
    for (i = 1; i < argc; i++) {
108
 
109
        if (strcmp(argv[i],"-display") == 0) {
110
 
111
            if (++i >= argc) usage();
112
            displayname = argv[i];
113
 
114
        } else if (strcmp(argv[i],"-shared") == 0) {
115
 
116
            shareDesktop = True;
117
 
118
        } else if (strcmp(argv[i],"-viewonly") == 0) {
119
 
120
            viewOnly = True;
121
 
122
        } else if (strcmp(argv[i],"-rre") == 0) {
123
 
124
            explicitEncodings[nExplicitEncodings++] = rfbEncodingRRE;
125
            addRRE = False;
126
 
127
        } else if (strcmp(argv[i],"-corre") == 0) {
128
 
129
            explicitEncodings[nExplicitEncodings++] = rfbEncodingCoRRE;
130
            addCoRRE = False;
131
 
132
        } else if (strcmp(argv[i],"-hextile") == 0) {
133
 
134
            explicitEncodings[nExplicitEncodings++] = rfbEncodingHextile;
135
            addHextile = False;
136
 
137
        } else if (strcmp(argv[i],"-copyrect") == 0) {
138
 
139
            explicitEncodings[nExplicitEncodings++] = rfbEncodingCopyRect;
140
            addCopyRect = False;
141
 
142
        } else if (strcmp(argv[i],"-raw") == 0) {
143
 
144
            explicitEncodings[nExplicitEncodings++] = rfbEncodingRaw;
145
 
146
        } else if (strcmp(argv[i],"-norre") == 0) {
147
 
148
            addRRE = False;
149
 
150
        } else if (strcmp(argv[i],"-nocorre") == 0) {
151
 
152
            addCoRRE = False;
153
 
154
        } else if (strcmp(argv[i],"-nohextile") == 0) {
155
 
156
            addHextile = False;
157
 
158
        } else if (strcmp(argv[i],"-nocopyrect") == 0) {
159
 
160
            addCopyRect = False;
161
 
162
        } else if (strcmp(argv[i],"-bgr233") == 0) {
163
 
164
            useBGR233 = True;
165
 
166
        } else if (strcmp(argv[i],"-owncmap") == 0) {
167
 
168
            forceOwnCmap = True;
169
 
170
        } else if (strcmp(argv[i],"-truecolour") == 0) {
171
 
172
            forceTruecolour = True;
173
 
174
        } else if (strcmp(argv[i],"-depth") == 0) {
175
 
176
            if (++i >= argc) usage();
177
            requestedDepth = atoi(argv[i]);
178
 
179
        } else if (strcmp(argv[i],"-geometry") == 0) {
180
 
181
            if (++i >= argc) usage();
182
            geometry = argv[i];
183
 
184
        } else if (strcmp(argv[i],"-wmdecoration") == 0) {
185
 
186
            if (++i >= argc) usage();
187
            if (sscanf(argv[i], "%dx%d",
188
                       &wmDecorationWidth, &wmDecorationHeight) != 2) usage();
189
 
190
        } else if (strcmp(argv[i],"-passwd") == 0) {
191
 
192
            if (++i >= argc) usage();
193
            passwdFile = argv[i];
194
 
195
        } else if (strcmp(argv[i],"-period") == 0) {
196
 
197
            if (++i >= argc) usage();
198
            updateRequestPeriodms = atoi(argv[i]);
199
 
200
        } else if (strcmp(argv[i],"-region") == 0) {
201
 
202
            if ((i+4) >= argc) usage();
203
            updateRequestX = atoi(argv[i+1]);
204
            updateRequestY = atoi(argv[i+2]);
205
            updateRequestW = atoi(argv[i+3]);
206
            updateRequestH = atoi(argv[i+4]);
207
            if ((updateRequestX < 0) || (updateRequestY < 0) ||
208
                (updateRequestW < 0) || (updateRequestH < 0))
209
                usage();
210
            i += 4;
211
 
212
        } else if (strcmp(argv[i],"-rawdelay") == 0) {
213
 
214
            if (++i >= argc) usage();
215
            rawDelay = atoi(argv[i]);
216
 
217
        } else if (strcmp(argv[i],"-copyrectdelay") == 0) {
218
 
219
            if (++i >= argc) usage();
220
            copyRectDelay = atoi(argv[i]);
221
 
222
        } else if (strcmp(argv[i],"-debug") == 0) {
223
 
224
            debug = True;
225
 
226
        } else if (strcmp(argv[i],"-listen") == 0) {
227
 
228
            if (argumentSpecified) usage();
229
 
230
            listenSpecified = True;
231
            if (++i < argc) {
232
                listenPort = CLIENTPORT+atoi(argv[i]);
233
                flashPort = FLASHPORT+atoi(argv[i]);
234
            }
235
 
236
        } else if (argv[i][0] != '-') {
237
 
238
            if (argumentSpecified || listenSpecified) usage();
239
 
240
            argumentSpecified = True;
241
 
242
            if (sscanf(argv[i], "%[^:]:%d", hostname, &port) != 2) usage();
243
 
244
            if (port < 100)
245
                port += SERVERPORT;
246
 
247
        } else {
248
 
249
            usage();
250
 
251
        }
252
    }
253
 
254
    if (listenSpecified) {
255
        if (listenPort == 0) {
256
            char *display;
257
            char *colonPos;
258
            struct utsname hostinfo;
259
 
260
            display = XDisplayName(displayname);
261
            colonPos = strchr(display, ':');
262
 
263
            uname(&hostinfo);
264
 
265
            if (colonPos && ((colonPos == display) ||
266
                             (strncmp(hostinfo.nodename, display,
267
                                      strlen(hostinfo.nodename)) == 0))) {
268
 
269
                listenPort = CLIENTPORT+atoi(colonPos+1);
270
                flashPort = FLASHPORT+atoi(colonPos+1);
271
 
272
            } else {
273
                fprintf(stderr,"%s: cannot work out which display number to "
274
                        "listen on.\n", programName);
275
                fprintf(stderr,
276
                        "Please specify explicitly with -listen <num>\n");
277
                exit(1);
278
            }
279
        }
280
 
281
    } else if (!argumentSpecified) {
282
 
283
        usage();
284
 
285
    }
286
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.