26 |
#include <sys/stat.h> /* stat */ |
#include <sys/stat.h> /* stat */ |
27 |
#include <sys/time.h> /* gettimeofday */ |
#include <sys/time.h> /* gettimeofday */ |
28 |
#include <sys/times.h> /* times */ |
#include <sys/times.h> /* times */ |
29 |
|
#include <ctype.h> /* toupper */ |
30 |
#include <errno.h> |
#include <errno.h> |
31 |
#include "rdesktop.h" |
#include "rdesktop.h" |
32 |
|
|
41 |
#include "crypto/md5.h" |
#include "crypto/md5.h" |
42 |
#endif |
#endif |
43 |
|
|
44 |
char title[32] = ""; |
char g_title[64] = ""; |
45 |
char username[16]; |
char g_username[64]; |
46 |
char hostname[16]; |
char hostname[16]; |
47 |
char keymapname[16]; |
char keymapname[16]; |
48 |
int keylayout = 0x409; /* Defaults to US keyboard layout */ |
int keylayout = 0x409; /* Defaults to US keyboard layout */ |
49 |
int width = 800; /* If width or height are reset to zero, the geometry will |
|
50 |
be fetched from _NET_WORKAREA */ |
int g_width = 800; /* width is special: If 0, the |
51 |
int height = 600; |
geometry will be fetched from |
52 |
|
_NET_WORKAREA. If negative, |
53 |
|
absolute value specifies the |
54 |
|
percent of the whole screen. */ |
55 |
|
int g_height = 600; |
56 |
int tcp_port_rdp = TCP_PORT_RDP; |
int tcp_port_rdp = TCP_PORT_RDP; |
57 |
int server_bpp = 8; |
int g_server_bpp = 8; |
58 |
int win_button_size = 0; /* If zero, disable single app mode */ |
int g_win_button_size = 0; /* If zero, disable single app mode */ |
59 |
BOOL bitmap_compression = True; |
BOOL g_bitmap_compression = True; |
60 |
BOOL sendmotion = True; |
BOOL g_sendmotion = True; |
61 |
BOOL orders = True; |
BOOL g_orders = True; |
62 |
BOOL encryption = True; |
BOOL g_encryption = True; |
63 |
BOOL packet_encryption = True; |
BOOL packet_encryption = True; |
64 |
BOOL desktop_save = True; |
BOOL g_desktop_save = True; |
65 |
BOOL fullscreen = False; |
BOOL g_fullscreen = False; |
66 |
BOOL grab_keyboard = True; |
BOOL g_grab_keyboard = True; |
67 |
BOOL hide_decorations = False; |
BOOL g_hide_decorations = False; |
68 |
BOOL use_rdp5 = False; |
BOOL g_use_rdp5 = True; |
69 |
extern BOOL owncolmap; |
BOOL g_console_session = False; |
70 |
|
BOOL g_numlock_sync = False; |
71 |
|
extern BOOL g_owncolmap; |
72 |
|
extern BOOL g_ownbackstore; |
73 |
|
|
74 |
|
#ifdef WITH_RDPSND |
75 |
|
BOOL g_rdpsnd = False; |
76 |
|
#endif |
77 |
|
|
78 |
|
extern RDPDR_DEVICE g_rdpdr_device[]; |
79 |
|
extern uint32 g_num_devices; |
80 |
|
|
81 |
#ifdef RDP2VNC |
#ifdef RDP2VNC |
82 |
extern int rfb_port; |
extern int rfb_port; |
96 |
fprintf(stderr, "Usage: %s [options] server[:port]\n", program); |
fprintf(stderr, "Usage: %s [options] server[:port]\n", program); |
97 |
#ifdef RDP2VNC |
#ifdef RDP2VNC |
98 |
fprintf(stderr, " -V: vnc port\n"); |
fprintf(stderr, " -V: vnc port\n"); |
99 |
fprintf(stderr, " -E: defer time (ms)\n"); |
fprintf(stderr, " -Q: defer time (ms)\n"); |
100 |
#endif |
#endif |
101 |
fprintf(stderr, " -u: user name\n"); |
fprintf(stderr, " -u: user name\n"); |
102 |
fprintf(stderr, " -d: domain\n"); |
fprintf(stderr, " -d: domain\n"); |
103 |
fprintf(stderr, " -s: shell\n"); |
fprintf(stderr, " -s: shell\n"); |
|
fprintf(stderr, " -S: caption button size (single application mode)\n"); |
|
104 |
fprintf(stderr, " -c: working directory\n"); |
fprintf(stderr, " -c: working directory\n"); |
105 |
fprintf(stderr, " -p: password (- to prompt)\n"); |
fprintf(stderr, " -p: password (- to prompt)\n"); |
106 |
fprintf(stderr, " -n: client hostname\n"); |
fprintf(stderr, " -n: client hostname\n"); |
107 |
fprintf(stderr, " -k: keyboard layout on terminal server (us,sv,gr,etc.)\n"); |
fprintf(stderr, " -k: keyboard layout on server (en-us, de, sv, etc.)\n"); |
108 |
fprintf(stderr, " -g: desktop geometry (WxH)\n"); |
fprintf(stderr, " -g: desktop geometry (WxH)\n"); |
109 |
fprintf(stderr, " -f: full-screen mode\n"); |
fprintf(stderr, " -f: full-screen mode\n"); |
110 |
fprintf(stderr, " -b: force bitmap updates\n"); |
fprintf(stderr, " -b: force bitmap updates\n"); |
111 |
|
fprintf(stderr, " -B: use BackingStore of X-server (if available)\n"); |
112 |
fprintf(stderr, " -e: disable encryption (French TS)\n"); |
fprintf(stderr, " -e: disable encryption (French TS)\n"); |
113 |
fprintf(stderr, " -E: disable encryption of everything but the logon packet\n"); |
fprintf(stderr, " -E: disable encryption from client to server\n"); |
114 |
fprintf(stderr, " -m: do not send motion events\n"); |
fprintf(stderr, " -m: do not send motion events\n"); |
115 |
fprintf(stderr, " -C: use private colour map\n"); |
fprintf(stderr, " -C: use private colour map\n"); |
116 |
|
fprintf(stderr, " -D: hide window manager decorations\n"); |
117 |
fprintf(stderr, " -K: keep window manager key bindings\n"); |
fprintf(stderr, " -K: keep window manager key bindings\n"); |
118 |
|
fprintf(stderr, " -S: caption button size (single application mode)\n"); |
119 |
fprintf(stderr, " -T: window title\n"); |
fprintf(stderr, " -T: window title\n"); |
120 |
fprintf(stderr, " -D: hide window manager decorations\n"); |
fprintf(stderr, " -N: enable numlock syncronization\n"); |
121 |
fprintf(stderr, " -a: server bpp\n"); |
fprintf(stderr, " -a: connection colour depth\n"); |
122 |
fprintf(stderr, " -5: Use RDP5 (EXPERIMENTAL!)\n"); |
fprintf(stderr, " -r: enable specified device redirection (this flag can be repeated)\n"); |
123 |
|
fprintf(stderr, |
124 |
|
" '-r comport:COM1=/dev/ttyS0': enable serial redirection of /dev/ttyS0 to COM1\n"); |
125 |
|
fprintf(stderr, " or COM1=/dev/ttyS0,COM2=/dev/ttyS1\n"); |
126 |
|
fprintf(stderr, |
127 |
|
" '-r disk:A=/mnt/floppy': enable redirection of /mnt/floppy to A:\n"); |
128 |
|
fprintf(stderr, " or A=/mnt/floppy,D=/mnt/cdrom'\n"); |
129 |
|
fprintf(stderr, |
130 |
|
" '-r lptport:LPT1=/dev/lp0': enable parallel redirection of /dev/lp0 to LPT1\n"); |
131 |
|
fprintf(stderr, " or LPT1=/dev/lp0,LPT2=/dev/lp1\n"); |
132 |
|
fprintf(stderr, " '-r printer:mydeskjet': enable printer redirection\n"); |
133 |
|
fprintf(stderr, |
134 |
|
" or mydeskjet=\"HP LaserJet IIIP\" to enter server driver as well\n"); |
135 |
|
fprintf(stderr, " '-r sound': enable sound redirection\n"); |
136 |
|
fprintf(stderr, " -0: attach to console\n"); |
137 |
|
fprintf(stderr, " -4: use RDP version 4\n"); |
138 |
|
fprintf(stderr, " -5: use RDP version 5 (default)\n"); |
139 |
} |
} |
140 |
|
|
141 |
static BOOL |
static BOOL |
174 |
return ret; |
return ret; |
175 |
} |
} |
176 |
|
|
177 |
|
static void |
178 |
|
parse_server_and_port(char *server) |
179 |
|
{ |
180 |
|
char *p; |
181 |
|
#ifdef IPv6 |
182 |
|
int addr_colons; |
183 |
|
#endif |
184 |
|
|
185 |
|
#ifdef IPv6 |
186 |
|
p = server; |
187 |
|
addr_colons = 0; |
188 |
|
while (*p) |
189 |
|
if (*p++ == ':') |
190 |
|
addr_colons++; |
191 |
|
if (addr_colons >= 2) |
192 |
|
{ |
193 |
|
/* numeric IPv6 style address format - [1:2:3::4]:port */ |
194 |
|
p = strchr(server, ']'); |
195 |
|
if (*server == '[' && p != NULL) |
196 |
|
{ |
197 |
|
if (*(p + 1) == ':' && *(p + 2) != '\0') |
198 |
|
tcp_port_rdp = strtol(p + 2, NULL, 10); |
199 |
|
/* remove the port number and brackets from the address */ |
200 |
|
*p = '\0'; |
201 |
|
strncpy(server, server + 1, strlen(server)); |
202 |
|
} |
203 |
|
} |
204 |
|
else |
205 |
|
{ |
206 |
|
/* dns name or IPv4 style address format - server.example.com:port or 1.2.3.4:port */ |
207 |
|
p = strchr(server, ':'); |
208 |
|
if (p != NULL) |
209 |
|
{ |
210 |
|
tcp_port_rdp = strtol(p + 1, NULL, 10); |
211 |
|
*p = 0; |
212 |
|
} |
213 |
|
} |
214 |
|
#else /* no IPv6 support */ |
215 |
|
p = strchr(server, ':'); |
216 |
|
if (p != NULL) |
217 |
|
{ |
218 |
|
tcp_port_rdp = strtol(p + 1, NULL, 10); |
219 |
|
*p = 0; |
220 |
|
} |
221 |
|
#endif /* IPv6 */ |
222 |
|
|
223 |
|
} |
224 |
|
|
225 |
/* Client program */ |
/* Client program */ |
226 |
int |
int |
227 |
main(int argc, char *argv[]) |
main(int argc, char *argv[]) |
229 |
char server[64]; |
char server[64]; |
230 |
char fullhostname[64]; |
char fullhostname[64]; |
231 |
char domain[16]; |
char domain[16]; |
232 |
char password[16]; |
char password[64]; |
233 |
char shell[128]; |
char shell[128]; |
234 |
char directory[32]; |
char directory[32]; |
235 |
BOOL prompt_password, rdp_retval = False; |
BOOL prompt_password, rdp_retval = False; |
237 |
uint32 flags; |
uint32 flags; |
238 |
char *p; |
char *p; |
239 |
int c; |
int c; |
240 |
|
|
241 |
int username_option = 0; |
int username_option = 0; |
242 |
|
|
243 |
flags = RDP_LOGON_NORMAL; |
flags = RDP_LOGON_NORMAL; |
245 |
domain[0] = password[0] = shell[0] = directory[0] = 0; |
domain[0] = password[0] = shell[0] = directory[0] = 0; |
246 |
strcpy(keymapname, "en-us"); |
strcpy(keymapname, "en-us"); |
247 |
|
|
248 |
|
g_num_devices = 0; |
249 |
|
|
250 |
#ifdef RDP2VNC |
#ifdef RDP2VNC |
251 |
#define VNCOPT "V:E:" |
#define VNCOPT "V:Q:" |
252 |
#else |
#else |
253 |
#define VNCOPT |
#define VNCOPT |
254 |
#endif |
#endif |
255 |
|
|
256 |
while ((c = getopt(argc, argv, VNCOPT "u:d:s:S:c:p:n:k:g:a:fbeEmCKT:Dh?54")) != -1) |
while ((c = getopt(argc, argv, VNCOPT "u:d:s:c:p:n:k:g:fbBeEmCDKS:T:Na:r:045h?")) != -1) |
257 |
{ |
{ |
258 |
switch (c) |
switch (c) |
259 |
{ |
{ |
264 |
rfb_port += 5900; |
rfb_port += 5900; |
265 |
break; |
break; |
266 |
|
|
267 |
case 'E': |
case 'Q': |
268 |
defer_time = strtol(optarg, NULL, 10); |
defer_time = strtol(optarg, NULL, 10); |
269 |
if (defer_time < 0) |
if (defer_time < 0) |
270 |
defer_time = 0; |
defer_time = 0; |
272 |
#endif |
#endif |
273 |
|
|
274 |
case 'u': |
case 'u': |
275 |
STRNCPY(username, optarg, sizeof(username)); |
STRNCPY(g_username, optarg, sizeof(g_username)); |
276 |
username_option = 1; |
username_option = 1; |
277 |
break; |
break; |
278 |
|
|
284 |
STRNCPY(shell, optarg, sizeof(shell)); |
STRNCPY(shell, optarg, sizeof(shell)); |
285 |
break; |
break; |
286 |
|
|
|
case 'S': |
|
|
if (!strcmp(optarg, "standard")) |
|
|
{ |
|
|
win_button_size = 18; |
|
|
break; |
|
|
} |
|
|
|
|
|
win_button_size = strtol(optarg, &p, 10); |
|
|
|
|
|
if (*p) |
|
|
{ |
|
|
error("invalid button size\n"); |
|
|
return 1; |
|
|
} |
|
|
|
|
|
break; |
|
|
|
|
287 |
case 'c': |
case 'c': |
288 |
STRNCPY(directory, optarg, sizeof(directory)); |
STRNCPY(directory, optarg, sizeof(directory)); |
289 |
break; |
break; |
313 |
break; |
break; |
314 |
|
|
315 |
case 'g': |
case 'g': |
316 |
|
g_fullscreen = False; |
317 |
if (!strcmp(optarg, "workarea")) |
if (!strcmp(optarg, "workarea")) |
318 |
{ |
{ |
319 |
width = height = 0; |
g_width = g_height = 0; |
320 |
break; |
break; |
321 |
} |
} |
322 |
|
|
323 |
width = strtol(optarg, &p, 10); |
g_width = strtol(optarg, &p, 10); |
324 |
|
if (g_width <= 0) |
325 |
|
{ |
326 |
|
error("invalid geometry\n"); |
327 |
|
return 1; |
328 |
|
} |
329 |
|
|
330 |
if (*p == 'x') |
if (*p == 'x') |
331 |
height = strtol(p + 1, NULL, 10); |
g_height = strtol(p + 1, NULL, 10); |
332 |
|
|
333 |
if ((width == 0) || (height == 0)) |
if (g_height <= 0) |
334 |
{ |
{ |
335 |
error("invalid geometry\n"); |
error("invalid geometry\n"); |
336 |
return 1; |
return 1; |
337 |
} |
} |
338 |
|
|
339 |
|
if (*p == '%') |
340 |
|
g_width = -g_width; |
341 |
|
|
342 |
break; |
break; |
343 |
|
|
344 |
case 'f': |
case 'f': |
345 |
fullscreen = True; |
g_fullscreen = True; |
346 |
break; |
break; |
347 |
|
|
348 |
case 'b': |
case 'b': |
349 |
orders = False; |
g_orders = False; |
350 |
|
break; |
351 |
|
|
352 |
|
case 'B': |
353 |
|
g_ownbackstore = False; |
354 |
break; |
break; |
355 |
|
|
356 |
case 'e': |
case 'e': |
357 |
encryption = False; |
g_encryption = False; |
358 |
break; |
break; |
359 |
case 'E': |
case 'E': |
360 |
packet_encryption = False; |
packet_encryption = False; |
361 |
break; |
break; |
362 |
case 'm': |
case 'm': |
363 |
sendmotion = False; |
g_sendmotion = False; |
364 |
break; |
break; |
365 |
|
|
366 |
case 'C': |
case 'C': |
367 |
owncolmap = True; |
g_owncolmap = True; |
368 |
|
break; |
369 |
|
|
370 |
|
case 'D': |
371 |
|
g_hide_decorations = True; |
372 |
break; |
break; |
373 |
|
|
374 |
case 'K': |
case 'K': |
375 |
grab_keyboard = False; |
g_grab_keyboard = False; |
376 |
|
break; |
377 |
|
|
378 |
|
case 'S': |
379 |
|
if (!strcmp(optarg, "standard")) |
380 |
|
{ |
381 |
|
g_win_button_size = 18; |
382 |
|
break; |
383 |
|
} |
384 |
|
|
385 |
|
g_win_button_size = strtol(optarg, &p, 10); |
386 |
|
|
387 |
|
if (*p) |
388 |
|
{ |
389 |
|
error("invalid button size\n"); |
390 |
|
return 1; |
391 |
|
} |
392 |
|
|
393 |
break; |
break; |
394 |
|
|
395 |
case 'T': |
case 'T': |
396 |
STRNCPY(title, optarg, sizeof(title)); |
STRNCPY(g_title, optarg, sizeof(g_title)); |
397 |
break; |
break; |
398 |
|
|
399 |
case 'D': |
case 'N': |
400 |
hide_decorations = True; |
g_numlock_sync = True; |
401 |
break; |
break; |
402 |
|
|
403 |
case 'a': |
case 'a': |
404 |
server_bpp = strtol(optarg, NULL, 10); |
g_server_bpp = strtol(optarg, NULL, 10); |
405 |
if (server_bpp != 8 && server_bpp != 16 && server_bpp != 15 |
if (g_server_bpp != 8 && g_server_bpp != 16 && g_server_bpp != 15 |
406 |
&& server_bpp != 24) |
&& g_server_bpp != 24) |
407 |
{ |
{ |
408 |
error("invalid server bpp\n"); |
error("invalid server bpp\n"); |
409 |
return 1; |
return 1; |
410 |
} |
} |
411 |
break; |
break; |
412 |
|
|
413 |
|
case 'r': |
414 |
|
|
415 |
|
if (strncmp("sound", optarg, 5) == 0) |
416 |
|
{ |
417 |
|
#ifdef WITH_RDPSND |
418 |
|
g_rdpsnd = True; |
419 |
|
#else |
420 |
|
warning("Not compiled with sound support"); |
421 |
|
#endif |
422 |
|
} |
423 |
|
else if (strncmp("disk", optarg, 4) == 0) |
424 |
|
{ |
425 |
|
/* -r disk:h:=/mnt/floppy */ |
426 |
|
disk_enum_devices(&g_num_devices, optarg + 4); |
427 |
|
} |
428 |
|
else if (strncmp("comport", optarg, 7) == 0) |
429 |
|
{ |
430 |
|
serial_enum_devices(&g_num_devices, optarg + 7); |
431 |
|
} |
432 |
|
else if (strncmp("lptport", optarg, 7) == 0) |
433 |
|
{ |
434 |
|
parallel_enum_devices(&g_num_devices, optarg + 7); |
435 |
|
} |
436 |
|
else if (strncmp("printer", optarg, 7) == 0) |
437 |
|
{ |
438 |
|
printer_enum_devices(&g_num_devices, optarg + 7); |
439 |
|
} |
440 |
|
else |
441 |
|
{ |
442 |
|
warning("Unknown -r argument\n\n\tPossible arguments are: comport, disk, lptport, printer, sound\n"); |
443 |
|
} |
444 |
|
break; |
445 |
|
|
446 |
|
case '0': |
447 |
|
g_console_session = True; |
448 |
|
break; |
449 |
|
|
450 |
|
case '4': |
451 |
|
g_use_rdp5 = False; |
452 |
|
break; |
453 |
|
|
454 |
case '5': |
case '5': |
455 |
use_rdp5 = True; |
g_use_rdp5 = True; |
456 |
break; |
break; |
457 |
|
|
458 |
case 'h': |
case 'h': |
459 |
case '?': |
case '?': |
460 |
default: |
default: |
470 |
} |
} |
471 |
|
|
472 |
STRNCPY(server, argv[optind], sizeof(server)); |
STRNCPY(server, argv[optind], sizeof(server)); |
473 |
p = strchr(server, ':'); |
parse_server_and_port(server); |
|
if (p != NULL) |
|
|
{ |
|
|
tcp_port_rdp = strtol(p + 1, NULL, 10); |
|
|
*p = 0; |
|
|
} |
|
474 |
|
|
475 |
if (!username_option) |
if (!username_option) |
476 |
{ |
{ |
481 |
return 1; |
return 1; |
482 |
} |
} |
483 |
|
|
484 |
STRNCPY(username, pw->pw_name, sizeof(username)); |
STRNCPY(g_username, pw->pw_name, sizeof(g_username)); |
485 |
} |
} |
486 |
|
|
487 |
if (hostname[0] == 0) |
if (hostname[0] == 0) |
502 |
if (prompt_password && read_password(password, sizeof(password))) |
if (prompt_password && read_password(password, sizeof(password))) |
503 |
flags |= RDP_LOGON_AUTO; |
flags |= RDP_LOGON_AUTO; |
504 |
|
|
505 |
if (title[0] == 0) |
if (g_title[0] == 0) |
506 |
{ |
{ |
507 |
strcpy(title, "rdesktop - "); |
strcpy(g_title, "rdesktop - "); |
508 |
strncat(title, server, sizeof(title) - sizeof("rdesktop - ")); |
strncat(g_title, server, sizeof(g_title) - sizeof("rdesktop - ")); |
509 |
} |
} |
510 |
|
|
511 |
#ifdef RDP2VNC |
#ifdef RDP2VNC |
516 |
if (!ui_init()) |
if (!ui_init()) |
517 |
return 1; |
return 1; |
518 |
|
|
519 |
ipc_init(); // Must be run after ui_init, we need X to be setup. |
#ifdef WITH_RDPSND |
520 |
|
if (g_rdpsnd) |
521 |
if (use_rdp5) |
rdpsnd_init(); |
522 |
cliprdr_init(); // FIXME: Should perhaps be integrated into the channel management code? |
#endif |
523 |
|
rdpdr_init(); |
524 |
|
|
525 |
if (!rdp_connect(server, flags, domain, password, shell, directory)) |
if (!rdp_connect(server, flags, domain, password, shell, directory)) |
526 |
return 1; |
return 1; |
527 |
|
|
528 |
/* By setting encryption to False here, we have an encrypted login |
/* By setting encryption to False here, we have an encrypted login |
529 |
packet but unencrypted transfer of other packets */ |
packet but unencrypted transfer of other packets */ |
530 |
if (!packet_encryption) |
if (!packet_encryption) |
531 |
encryption = False; |
g_encryption = False; |
532 |
|
|
533 |
|
|
534 |
DEBUG(("Connection successful.\n")); |
DEBUG(("Connection successful.\n")); |
544 |
rdp_disconnect(); |
rdp_disconnect(); |
545 |
ui_deinit(); |
ui_deinit(); |
546 |
|
|
547 |
if (True == rdp_retval) |
if (True == rdp_retval) |
548 |
return 0; |
return 0; |
549 |
else |
else |
550 |
return 2; |
return 2; |
710 |
|
|
711 |
/* produce a hex dump */ |
/* produce a hex dump */ |
712 |
void |
void |
713 |
hexdump(unsigned char *p, int len) |
hexdump(unsigned char *p, unsigned int len) |
714 |
{ |
{ |
715 |
unsigned char *line = p; |
unsigned char *line = p; |
716 |
int i, thisline, offset = 0; |
int i, thisline, offset = 0; |
737 |
} |
} |
738 |
} |
} |
739 |
|
|
740 |
|
/* |
741 |
|
input: src is the string we look in for needle. |
742 |
|
Needle may be escaped by a backslash, in |
743 |
|
that case we ignore that particular needle. |
744 |
|
return value: returns next src pointer, for |
745 |
|
succesive executions, like in a while loop |
746 |
|
if retval is 0, then there are no more args. |
747 |
|
pitfalls: |
748 |
|
src is modified. 0x00 chars are inserted to |
749 |
|
terminate strings. |
750 |
|
return val, points on the next val chr after ins |
751 |
|
0x00 |
752 |
|
|
753 |
|
example usage: |
754 |
|
while( (pos = next_arg( optarg, ',')) ){ |
755 |
|
printf("%s\n",optarg); |
756 |
|
optarg=pos; |
757 |
|
} |
758 |
|
|
759 |
|
*/ |
760 |
|
char * |
761 |
|
next_arg(char *src, char needle) |
762 |
|
{ |
763 |
|
char *nextval; |
764 |
|
char *p; |
765 |
|
char *mvp = 0; |
766 |
|
|
767 |
|
/* EOS */ |
768 |
|
if (*src == (char) 0x00) |
769 |
|
return 0; |
770 |
|
|
771 |
|
p = src; |
772 |
|
/* skip escaped needles */ |
773 |
|
while ((nextval = strchr(p, needle))) |
774 |
|
{ |
775 |
|
mvp = nextval - 1; |
776 |
|
/* found backslashed needle */ |
777 |
|
if (*mvp == '\\' && (mvp > src)) |
778 |
|
{ |
779 |
|
/* move string one to the left */ |
780 |
|
while (*(mvp + 1) != (char) 0x00) |
781 |
|
{ |
782 |
|
*mvp = *(mvp + 1); |
783 |
|
*mvp++; |
784 |
|
} |
785 |
|
*mvp = (char) 0x00; |
786 |
|
p = nextval; |
787 |
|
} |
788 |
|
else |
789 |
|
{ |
790 |
|
p = nextval + 1; |
791 |
|
break; |
792 |
|
} |
793 |
|
|
794 |
|
} |
795 |
|
|
796 |
|
/* more args available */ |
797 |
|
if (nextval) |
798 |
|
{ |
799 |
|
*nextval = (char) 0x00; |
800 |
|
return ++nextval; |
801 |
|
} |
802 |
|
|
803 |
|
/* no more args after this, jump to EOS */ |
804 |
|
nextval = src + strlen(src); |
805 |
|
return nextval; |
806 |
|
} |
807 |
|
|
808 |
|
|
809 |
|
void |
810 |
|
toupper_str(char *p) |
811 |
|
{ |
812 |
|
while (*p) |
813 |
|
{ |
814 |
|
if ((*p >= 'a') && (*p <= 'z')) |
815 |
|
*p = toupper((int) *p); |
816 |
|
p++; |
817 |
|
} |
818 |
|
} |
819 |
|
|
820 |
|
|
821 |
|
/* not all clibs got ltoa */ |
822 |
|
#define LTOA_BUFSIZE (sizeof(long) * 8 + 1) |
823 |
|
|
824 |
|
char * |
825 |
|
l_to_a(long N, int base) |
826 |
|
{ |
827 |
|
static char ret[LTOA_BUFSIZE]; |
828 |
|
|
829 |
|
char *head = ret, buf[LTOA_BUFSIZE], *tail = buf + sizeof(buf); |
830 |
|
|
831 |
|
register int divrem; |
832 |
|
|
833 |
|
if (base < 36 || 2 > base) |
834 |
|
base = 10; |
835 |
|
|
836 |
|
if (N < 0) |
837 |
|
{ |
838 |
|
*head++ = '-'; |
839 |
|
N = -N; |
840 |
|
} |
841 |
|
|
842 |
|
tail = buf + sizeof(buf); |
843 |
|
*--tail = 0; |
844 |
|
|
845 |
|
do |
846 |
|
{ |
847 |
|
divrem = N % base; |
848 |
|
*--tail = (divrem <= 9) ? divrem + '0' : divrem + 'a' - 10; |
849 |
|
N /= base; |
850 |
|
} |
851 |
|
while (N); |
852 |
|
|
853 |
|
strcpy(head, tail); |
854 |
|
return ret; |
855 |
|
} |
856 |
|
|
857 |
|
|
858 |
int |
int |
859 |
load_licence(unsigned char **data) |
load_licence(unsigned char **data) |