Mercurial > pidgin
annotate src/util.c @ 550:6bd2bbc1b6c8
[gaim-migrate @ 560]
Always show top of info
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Fri, 28 Jul 2000 21:18:24 +0000 |
parents | 4bf9c74b9e4d |
children | 7c75d69a1129 |
rev | line source |
---|---|
1 | 1 /* |
2 * gaim | |
3 * | |
4 * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net> | |
5 * | |
6 * This program is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or | |
9 * (at your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
19 * | |
20 */ | |
21 | |
349
b402a23f35df
[gaim-migrate @ 359]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
278
diff
changeset
|
22 #ifdef HAVE_CONFIG_H |
b402a23f35df
[gaim-migrate @ 359]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
278
diff
changeset
|
23 #include "../config.h" |
b402a23f35df
[gaim-migrate @ 359]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
278
diff
changeset
|
24 #endif |
1 | 25 #include <unistd.h> |
26 #include <errno.h> | |
27 #include <stdio.h> | |
28 #include <stdlib.h> | |
29 #include <sys/time.h> | |
30 #include <sys/types.h> | |
31 #include <sys/stat.h> | |
32 #include <string.h> | |
33 #include <sys/wait.h> | |
34 #include <gtk/gtk.h> | |
210
ec0686b3b03f
[gaim-migrate @ 220]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
209
diff
changeset
|
35 #include <ctype.h> |
1 | 36 #include <pixmaps/aimicon.xpm> |
37 #include "gaim.h" | |
38 | |
39 static GdkPixmap *icon_pm = NULL; | |
40 static GdkBitmap *icon_bm = NULL; | |
41 static int state; | |
42 | |
70 | 43 char *full_date() { |
44 char * date; | |
45 time_t tme; | |
46 | |
47 time(&tme); | |
48 date = ctime(&tme); | |
49 date[strlen(date)-1] = '\0'; | |
50 return date; | |
51 } | |
52 | |
1 | 53 gint badchar(char c) |
54 { | |
55 if (c == ' ') | |
56 return 1; | |
57 if (c == ',') | |
58 return 1; | |
59 if (c == ')') | |
60 return 1; | |
61 if (c == '(') | |
62 return 1; | |
63 if (c == 0) | |
64 return 1; | |
65 if (c == '\n') | |
66 return 1; | |
413
7ea55575cc01
[gaim-migrate @ 423]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
373
diff
changeset
|
67 if (c == '<') |
7ea55575cc01
[gaim-migrate @ 423]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
373
diff
changeset
|
68 return 1; |
470
4bf9c74b9e4d
[gaim-migrate @ 480]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
423
diff
changeset
|
69 if (c == '>') |
4bf9c74b9e4d
[gaim-migrate @ 480]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
423
diff
changeset
|
70 return 1; |
1 | 71 return 0; |
72 | |
73 | |
74 } | |
75 | |
76 | |
77 char *sec_to_text(int sec) | |
78 { | |
79 int hrs, min; | |
80 char minutes[64]; | |
81 char hours[64]; | |
82 char sep[16]; | |
83 char *ret = g_malloc(256); | |
84 | |
85 hrs = sec / 3600; | |
86 min = sec % 3600; | |
87 | |
88 min = min / 60; | |
89 sec = min % 60; | |
90 | |
91 if (min) { | |
92 if (min == 1) | |
93 g_snprintf(minutes, sizeof(minutes), "%d minute.", min); | |
94 else | |
95 g_snprintf(minutes, sizeof(minutes), "%d minutes.", min); | |
96 sprintf(sep, ", "); | |
97 } else { | |
98 if (!hrs) | |
99 g_snprintf(minutes, sizeof(minutes), "%d minutes.", min); | |
100 else { | |
101 minutes[0] = '.'; | |
102 minutes[1] = '\0'; | |
103 } | |
104 sep[0] = '\0'; | |
105 } | |
106 | |
107 if (hrs) { | |
108 if (hrs == 1) | |
109 g_snprintf(hours, sizeof(hours), "%d hour%s", hrs, sep); | |
110 else | |
111 g_snprintf(hours, sizeof(hours), "%d hours%s", hrs, sep); | |
112 } else | |
113 hours[0] = '\0'; | |
114 | |
115 | |
116 g_snprintf(ret, 256, "%s%s", hours, minutes); | |
117 | |
118 return ret; | |
119 } | |
120 | |
121 gint linkify_text(char *text) | |
122 { | |
123 char *c, *t; | |
124 char cpy[BUF_LONG]; | |
125 char url_buf[512]; | |
126 int cnt=0; | |
127 /* Assumes you have a buffer able to cary at least BUF_LEN * 2 bytes */ | |
128 | |
129 strncpy(cpy, text, strlen(text)); | |
130 cpy[strlen(text)] = 0; | |
131 c = cpy; | |
132 while(*c) { | |
133 if (!strncasecmp(c, "<A", 2)) { | |
134 while(1) { | |
135 if (!strncasecmp(c, "/A>", 3)) { | |
136 break; | |
137 } | |
138 text[cnt++] = *c; | |
139 c++; | |
140 if (!(*c)) | |
141 break; | |
142 } | |
143 } else if (!strncasecmp(c, "http://", 7)) { | |
144 t = c; | |
145 while(1) { | |
146 if (badchar(*t)) { | |
147 if (*(t-1) == '.') | |
148 t--; | |
149 strncpy(url_buf, c, t-c); | |
150 url_buf[t-c] = 0; | |
151 cnt += g_snprintf(&text[cnt++], 1024, "<A HREF=\"%s\">%s</A>", url_buf, url_buf); | |
152 cnt--; | |
153 c = t; | |
154 break; | |
155 } | |
156 if (!t) | |
157 break; | |
158 t++; | |
159 | |
160 } | |
161 } else if (!strncasecmp(c, "www.", 4)) { | |
162 if (strncasecmp(c, "www..", 5)) { | |
163 t = c; | |
164 while(1) { | |
165 if (badchar(*t)) { | |
166 if (t-c == 4) { | |
167 break; | |
168 } | |
169 if (*(t-1) == '.') | |
170 t--; | |
171 strncpy(url_buf, c, t-c); | |
172 url_buf[t-c] = 0; | |
173 cnt += g_snprintf(&text[cnt++], 1024, "<A HREF=\"http://%s\">%s</A>", url_buf, url_buf); | |
174 cnt--; | |
175 c = t; | |
176 break; | |
177 } | |
178 if (!t) | |
179 break; | |
180 t++; | |
181 } | |
182 } | |
183 } else if (!strncasecmp(c, "ftp://", 6)) { | |
184 t = c; | |
185 while(1) { | |
186 if (badchar(*t)) { | |
187 if (*(t-1) == '.') | |
188 t--; | |
189 strncpy(url_buf, c, t-c); | |
190 url_buf[t-c] = 0; | |
191 cnt += g_snprintf(&text[cnt++], 1024, "<A HREF=\"%s\">%s</A>", url_buf, url_buf); | |
192 cnt--; | |
193 c = t; | |
194 break; | |
195 } | |
196 if (!t) | |
197 break; | |
198 t++; | |
199 | |
200 } | |
201 } else if (!strncasecmp(c, "ftp.", 4)) { | |
202 t = c; | |
203 while(1) { | |
204 if (badchar(*t)) { | |
205 if (t-c == 4) { | |
206 break; | |
207 } | |
208 if (*(t-1) == '.') | |
209 t--; | |
210 strncpy(url_buf, c, t-c); | |
211 url_buf[t-c] = 0; | |
212 cnt += g_snprintf(&text[cnt++], 1024, "<A HREF=\"ftp://%s\">%s</A>", url_buf, url_buf); | |
213 cnt--; | |
214 c = t; | |
215 break; | |
216 } | |
217 if (!t) | |
218 break; | |
219 t++; | |
220 } | |
221 } else if (!strncasecmp(c, "mailto:", 7)) { | |
222 t = c; | |
223 while(1) { | |
224 if (badchar(*t)) { | |
225 if (*(t-1) == '.') | |
226 t--; | |
227 strncpy(url_buf, c, t-c); | |
228 url_buf[t-c] = 0; | |
229 cnt += g_snprintf(&text[cnt++], 1024, "<A HREF=\"%s\">%s</A>", url_buf, url_buf); | |
230 cnt--; | |
231 c = t; | |
232 break; | |
233 } | |
234 if (!t) | |
235 break; | |
236 t++; | |
237 | |
238 } | |
239 } else if (!strncasecmp(c, "@", 1)) { | |
240 char *tmp; | |
241 int flag; | |
242 int len=0; | |
243 url_buf[0] = 0; | |
244 | |
245 if (*(c-1) == ' ' || *(c+1) == ' ') | |
246 flag = 0; | |
247 else | |
248 flag = 1; | |
249 | |
250 t = c; | |
251 while(flag) { | |
252 if (badchar(*t)) { | |
253 cnt -= (len - 1); | |
254 break; | |
255 } else { | |
256 len++; | |
257 tmp = g_malloc(len + 1); | |
258 tmp[len] = 0; | |
259 tmp[0] = *t; | |
260 strncpy(tmp + 1, url_buf, len - 1); | |
261 strcpy(url_buf, tmp); | |
262 url_buf[len] = 0; | |
263 g_free(tmp); | |
264 t--; | |
265 if (t < cpy) { | |
266 cnt = 0; | |
267 break; | |
268 } | |
269 } | |
270 } | |
271 | |
272 | |
273 t = c + 1; | |
274 | |
275 while(flag) { | |
276 if (badchar(*t)) { | |
277 if (*(t-1) == '.') | |
278 t--; | |
279 cnt += g_snprintf(&text[cnt++], 1024, "<A HREF=\"mailto:%s\">%s</A>", url_buf, url_buf); | |
280 text[cnt]=0; | |
281 | |
282 | |
283 cnt--; | |
284 c = t; | |
285 | |
286 break; | |
287 } else { | |
288 strncat(url_buf, t, 1); | |
289 len++; | |
290 url_buf[len] = 0; | |
291 } | |
292 | |
293 t++; | |
294 | |
295 } | |
296 | |
297 | |
298 } | |
299 | |
300 if (*c == 0) | |
301 break; | |
302 | |
303 text[cnt++] = *c; | |
304 c++; | |
305 | |
306 } | |
307 text[cnt]=0; | |
308 return cnt; | |
309 } | |
310 | |
311 | |
373
1d29321843b0
[gaim-migrate @ 383]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
349
diff
changeset
|
312 FILE *open_log_file (char *name) |
1 | 313 { |
79 | 314 char *buf; |
315 char *buf2; | |
1 | 316 char log_all_file[256]; |
317 struct log_conversation *l; | |
318 struct stat st; | |
319 int flag = 0; | |
320 FILE *fd; | |
321 int res; | |
322 | |
323 if (!(general_options & OPT_GEN_LOG_ALL)) { | |
324 | |
373
1d29321843b0
[gaim-migrate @ 383]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
349
diff
changeset
|
325 l = find_log_info(name); |
1 | 326 if (!l) |
327 return NULL; | |
328 | |
329 if (stat(l->filename, &st) < 0) | |
330 flag = 1; | |
331 | |
332 fd = fopen(l->filename, "a"); | |
333 | |
334 if (flag) { /* is a new file */ | |
335 fprintf(fd, "<HTML><HEAD><TITLE>" ); | |
373
1d29321843b0
[gaim-migrate @ 383]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
349
diff
changeset
|
336 fprintf(fd, "IM Sessions with %s", name ); |
1 | 337 fprintf(fd, "</TITLE></HEAD><BODY BGCOLOR=\"ffffff\">\n" ); |
338 } | |
339 | |
340 return fd; | |
341 } | |
342 | |
79 | 343 buf = g_malloc(BUF_LONG); |
344 buf2 = g_malloc(BUF_LONG); | |
345 | |
1 | 346 /* Dont log yourself */ |
347 g_snprintf(log_all_file, 256, "%s/.gaim", getenv("HOME")); | |
348 | |
349 stat(log_all_file, &st); | |
350 if (!S_ISDIR(st.st_mode)) | |
351 unlink(log_all_file); | |
352 | |
353 fd = fopen(log_all_file, "r"); | |
354 | |
355 if (!fd) { | |
356 res = mkdir(log_all_file, S_IRUSR | S_IWUSR | S_IXUSR); | |
357 if (res < 0) { | |
358 g_snprintf(buf, BUF_LONG, "Unable to make directory %s for logging", log_all_file); | |
359 do_error_dialog(buf, "Error!"); | |
360 g_free(buf); | |
361 g_free(buf2); | |
362 return NULL; | |
363 } | |
364 } else | |
365 fclose(fd); | |
366 | |
367 g_snprintf(log_all_file, 256, "%s/.gaim/%s", getenv("HOME"), current_user->username); | |
368 | |
369 if (stat(log_all_file, &st) < 0) | |
370 flag = 1; | |
371 if (!S_ISDIR(st.st_mode)) | |
372 unlink(log_all_file); | |
373 | |
374 fd = fopen(log_all_file, "r"); | |
375 if (!fd) { | |
376 res = mkdir(log_all_file, S_IRUSR | S_IWUSR | S_IXUSR); | |
377 if (res < 0) { | |
378 g_snprintf(buf, BUF_LONG, "Unable to make directory %s for logging", log_all_file); | |
379 do_error_dialog(buf, "Error!"); | |
380 g_free(buf); | |
381 g_free(buf2); | |
382 return NULL; | |
383 } | |
384 } else | |
385 fclose(fd); | |
386 | |
387 | |
373
1d29321843b0
[gaim-migrate @ 383]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
349
diff
changeset
|
388 g_snprintf(log_all_file, 256, "%s/.gaim/%s/%s.log", getenv("HOME"), current_user->username, normalize(name)); |
1 | 389 |
390 if (stat(log_all_file, &st) < 0) | |
391 flag = 1; | |
392 | |
393 sprintf(debug_buff,"Logging to: \"%s\"\n", log_all_file); | |
394 debug_print(debug_buff); | |
395 | |
396 fd = fopen(log_all_file, "a"); | |
397 | |
398 if (flag) { /* is a new file */ | |
399 fprintf(fd, "<HTML><HEAD><TITLE>" ); | |
373
1d29321843b0
[gaim-migrate @ 383]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
349
diff
changeset
|
400 fprintf(fd, "IM Sessions with %s", name ); |
1 | 401 fprintf(fd, "</TITLE></HEAD><BODY BGCOLOR=\"ffffff\">\n" ); |
402 } | |
25 | 403 |
404 g_free(buf); | |
405 g_free(buf2); | |
1 | 406 return fd; |
407 } | |
408 | |
409 | |
254
fa67d29b53d5
[gaim-migrate @ 264]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
210
diff
changeset
|
410 /* we only need this for TOC, because messages must be escaped */ |
1 | 411 int escape_message(char *msg) |
412 { | |
423
0d4e80bdb96b
[gaim-migrate @ 433]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
413
diff
changeset
|
413 if (!USE_OSCAR) { |
1 | 414 char *c, *cpy; |
415 int cnt=0; | |
416 /* Assumes you have a buffer able to cary at least BUF_LEN * 2 bytes */ | |
417 if (strlen(msg) > BUF_LEN) { | |
418 sprintf(debug_buff, "Warning: truncating message to 2048 bytes\n"); | |
419 debug_print(debug_buff); | |
420 msg[2047]='\0'; | |
421 } | |
422 | |
423 cpy = g_strdup(msg); | |
424 c = cpy; | |
425 while(*c) { | |
426 switch(*c) { | |
427 case '$': | |
428 case '[': | |
429 case ']': | |
430 case '(': | |
431 case ')': | |
432 case '#': | |
433 msg[cnt++]='\\'; | |
434 /* Fall through */ | |
435 default: | |
436 msg[cnt++]=*c; | |
437 } | |
438 c++; | |
439 } | |
440 msg[cnt]='\0'; | |
441 g_free(cpy); | |
442 return cnt; | |
423
0d4e80bdb96b
[gaim-migrate @ 433]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
413
diff
changeset
|
443 } else { |
254
fa67d29b53d5
[gaim-migrate @ 264]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
210
diff
changeset
|
444 return strlen(msg); |
423
0d4e80bdb96b
[gaim-migrate @ 433]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
413
diff
changeset
|
445 } |
1 | 446 } |
447 | |
254
fa67d29b53d5
[gaim-migrate @ 264]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
210
diff
changeset
|
448 /* we don't need this for oscar either */ |
1 | 449 int escape_text(char *msg) |
450 { | |
423
0d4e80bdb96b
[gaim-migrate @ 433]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
413
diff
changeset
|
451 if (!USE_OSCAR) { |
1 | 452 char *c, *cpy; |
453 int cnt=0; | |
79 | 454 /* Assumes you have a buffer able to cary at least BUF_LEN * 4 bytes */ |
1 | 455 if (strlen(msg) > BUF_LEN) { |
456 fprintf(stderr, "Warning: truncating message to 2048 bytes\n"); | |
457 msg[2047]='\0'; | |
458 } | |
459 | |
460 cpy = g_strdup(msg); | |
461 c = cpy; | |
462 while(*c) { | |
463 switch(*c) { | |
464 case '\n': | |
465 msg[cnt++] = '<'; | |
466 msg[cnt++] = 'B'; | |
467 msg[cnt++] = 'R'; | |
468 msg[cnt++] = '>'; | |
469 break; | |
470 case '{': | |
471 case '}': | |
472 case '\\': | |
473 case '"': | |
474 msg[cnt++]='\\'; | |
475 /* Fall through */ | |
476 default: | |
477 msg[cnt++]=*c; | |
478 } | |
479 c++; | |
480 } | |
481 msg[cnt]='\0'; | |
482 g_free(cpy); | |
483 return cnt; | |
423
0d4e80bdb96b
[gaim-migrate @ 433]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
413
diff
changeset
|
484 } else { |
254
fa67d29b53d5
[gaim-migrate @ 264]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
210
diff
changeset
|
485 return strlen(msg); |
423
0d4e80bdb96b
[gaim-migrate @ 433]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
413
diff
changeset
|
486 } |
1 | 487 } |
488 | |
489 char * escape_text2(char *msg) | |
490 { | |
491 char *c, *cpy; | |
492 char *woo; | |
493 int cnt=0; | |
494 /* Assumes you have a buffer able to cary at least BUF_LEN * 2 bytes */ | |
495 if (strlen(msg) > BUF_LEN) { | |
496 fprintf(stderr, "Warning: truncating message to 2048 bytes\n"); | |
497 msg[2047]='\0'; | |
498 } | |
499 | |
79 | 500 woo = malloc(strlen(msg) * 2); |
1 | 501 cpy = g_strdup(msg); |
502 c = cpy; | |
503 while(*c) { | |
504 switch(*c) { | |
505 case '\n': | |
506 woo[cnt++] = '<'; | |
507 woo[cnt++] = 'B'; | |
508 woo[cnt++] = 'R'; | |
509 woo[cnt++] = '>'; | |
510 break; | |
511 case '{': | |
512 case '}': | |
513 case '\\': | |
514 case '"': | |
515 woo[cnt++]='\\'; | |
516 /* Fall through */ | |
517 default: | |
518 woo[cnt++]=*c; | |
519 } | |
520 c++; | |
521 } | |
522 woo[cnt]='\0'; | |
26 | 523 |
524 g_free (cpy); | |
1 | 525 return woo; |
526 } | |
527 | |
528 | |
529 char alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" | |
530 "0123456789+/"; | |
531 | |
532 | |
533 char *tobase64(char *text) | |
534 { | |
535 char *out = NULL; | |
536 char *c; | |
537 unsigned int tmp = 0; | |
538 int len = 0, n = 0; | |
539 | |
540 c = text; | |
541 | |
542 while(c) { | |
543 tmp = tmp << 8; | |
544 tmp += *c; | |
545 n++; | |
546 | |
547 if (n == 3) { | |
548 out = g_realloc(out, len+4); | |
549 out[len] = alphabet[(tmp >> 18) & 0x3f]; | |
550 out[len+1] = alphabet[(tmp >> 12) & 0x3f]; | |
551 out[len+2] = alphabet[(tmp >> 6) & 0x3f]; | |
552 out[len+3] = alphabet[tmp & 0x3f]; | |
553 len += 4; | |
554 tmp = 0; | |
555 n = 0; | |
556 } | |
557 c++; | |
558 } | |
559 switch(n) { | |
560 | |
561 case 2: | |
562 out = g_realloc(out, len+5); | |
563 out[len] = alphabet[(tmp >> 12) & 0x3f]; | |
564 out[len+1] = alphabet[(tmp >> 6) & 0x3f]; | |
565 out[len+2] = alphabet[tmp & 0x3f]; | |
566 out[len+3] = '='; | |
567 out[len+4] = 0; | |
568 break; | |
569 case 1: | |
570 out = g_realloc(out, len+4); | |
571 out[len] = alphabet[(tmp >> 6) & 0x3f]; | |
572 out[len+1] = alphabet[tmp & 0x3f]; | |
573 out[len+2] = '='; | |
574 out[len+3] = 0; | |
575 break; | |
576 case 0: | |
577 out = g_realloc(out, len+2); | |
578 out[len] = '='; | |
579 out[len+1] = 0; | |
580 break; | |
581 } | |
582 return out; | |
583 } | |
584 | |
585 | |
586 char *frombase64(char *text) | |
587 { | |
588 char *out = NULL; | |
589 char tmp = 0; | |
590 char *c; | |
591 gint32 tmp2 = 0; | |
592 int len = 0, n = 0; | |
593 | |
594 c = text; | |
595 | |
596 while(*c) { | |
597 if (*c >= 'A' && *c <= 'Z') { | |
598 tmp = *c - 'A'; | |
599 } else if (*c >= 'a' && *c <= 'z') { | |
600 tmp = 26 + (*c - 'a'); | |
601 } else if (*c >= '0' && *c <= 57) { | |
602 tmp = 52 + (*c - '0'); | |
603 } else if (*c == '+') { | |
604 tmp = 62; | |
605 } else if (*c == '/') { | |
606 tmp = 63; | |
607 } else if (*c == '=') { | |
608 if (n == 3) { | |
609 out = g_realloc(out, len + 2); | |
610 out[len] = (char)(tmp2 >> 10) & 0xff; | |
611 len++; | |
612 out[len] = (char)(tmp2 >> 2) & 0xff; | |
613 len++; | |
614 } else if (n == 2) { | |
615 out = g_realloc(out, len + 1); | |
616 out[len] = (char)(tmp2 >> 4) & 0xff; | |
617 len++; | |
618 } | |
619 break; | |
620 } | |
621 tmp2 = ((tmp2 << 6) | (tmp & 0xff)); | |
622 n++; | |
623 if (n == 4) { | |
624 out = g_realloc(out, len + 3); | |
625 out[len] = (char)((tmp2 >> 16) & 0xff); | |
626 len++; | |
627 out[len] = (char)((tmp2 >> 8) & 0xff); | |
628 len++; | |
629 out[len] = (char)(tmp2 & 0xff); | |
630 len++; | |
631 tmp2 = 0; | |
632 n = 0; | |
633 } | |
634 c++; | |
635 } | |
636 | |
194
d7690984c0f1
[gaim-migrate @ 204]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
180
diff
changeset
|
637 out = g_realloc(out, len+1); |
1 | 638 out[len] = 0; |
639 | |
640 return out; | |
641 } | |
642 | |
643 | |
644 char *normalize(const char *s) | |
645 { | |
646 static char buf[BUF_LEN]; | |
647 char *t, *u; | |
648 int x=0; | |
649 | |
79 | 650 g_return_val_if_fail ((s != NULL), NULL); |
26 | 651 |
652 u = t = g_strdup(s); | |
1 | 653 |
654 strcpy(t, s); | |
655 g_strdown(t); | |
656 | |
26 | 657 while(*t && (x < BUF_LEN - 1)) { |
1 | 658 if (*t != ' ') { |
659 buf[x] = *t; | |
660 x++; | |
661 } | |
662 t++; | |
663 } | |
664 buf[x]='\0'; | |
665 g_free(u); | |
666 return buf; | |
667 } | |
668 | |
669 int query_state() | |
670 { | |
671 return state; | |
672 } | |
673 | |
674 void set_state(int i) | |
675 { | |
676 state = i; | |
677 } | |
678 | |
679 char *date() | |
680 { | |
681 static char date[80]; | |
682 time_t tme; | |
683 time(&tme); | |
684 strftime(date, sizeof(date), "%H:%M:%S", localtime(&tme)); | |
685 return date; | |
686 } | |
687 | |
688 | |
689 gint clean_pid(void *dummy) | |
690 { | |
691 int status; | |
692 pid_t pid; | |
693 | |
694 pid = waitpid(-1, &status, WNOHANG); | |
695 | |
696 if (pid == 0) | |
697 return TRUE; | |
698 | |
699 return FALSE; | |
700 } | |
701 | |
702 void aol_icon(GdkWindow *w) | |
703 { | |
704 #ifndef _WIN32 | |
705 if (icon_pm == NULL) { | |
706 icon_pm = gdk_pixmap_create_from_xpm_d(w, &icon_bm, | |
707 NULL, (gchar **)aimicon_xpm); | |
708 } | |
709 gdk_window_set_icon(w, NULL, icon_pm, icon_bm); | |
10 | 710 if (mainwindow) gdk_window_set_group(w, mainwindow->window); |
1 | 711 #endif |
712 } | |
713 | |
714 struct aim_user *find_user(const char *name) | |
715 { | |
716 char *who = g_strdup(normalize(name)); | |
717 GList *usr = aim_users; | |
718 struct aim_user *u; | |
719 | |
720 while(usr) { | |
721 u = (struct aim_user *)usr->data; | |
722 if (!strcmp(normalize(u->username), who)) { | |
723 g_free(who); | |
724 return u; | |
725 } | |
726 usr = usr->next; | |
727 } | |
728 g_free(who); | |
729 return NULL; | |
730 } | |
180 | 731 |
732 void check_gaim_versions() | |
733 { | |
734 char *cur_ver; | |
735 char *tmp; | |
736 | |
737 tmp = (char *)malloc(BUF_LONG); | |
738 | |
739 cur_ver = (char *)grab_url("http://www.marko.net/gaim/latest-gaim"); | |
740 | |
741 if (!strncasecmp(cur_ver, "g00", 3)) | |
742 { | |
278
29e1669b006b
[gaim-migrate @ 288]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
254
diff
changeset
|
743 g_free(cur_ver); |
29e1669b006b
[gaim-migrate @ 288]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
254
diff
changeset
|
744 g_free(tmp); |
180 | 745 return; |
746 } | |
747 | |
748 g_snprintf(tmp, BUF_LONG, "%s", strstr(cur_ver, "plain")+9); | |
749 g_strchomp(tmp); | |
750 | |
278
29e1669b006b
[gaim-migrate @ 288]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
254
diff
changeset
|
751 if (strcmp(tmp, latest_ver)) |
180 | 752 { |
753 g_snprintf(cur_ver, BUF_LONG, "GAIM v%s is now available.\n\nDownload it at http://www.marko.net/gaim\n", tmp); | |
754 | |
755 do_error_dialog(cur_ver, "GAIM - New Version!"); | |
756 strcpy(latest_ver, tmp); | |
757 save_prefs(); | |
758 } | |
759 | |
760 free(tmp); | |
761 free(cur_ver); | |
762 } | |
763 | |
764 | |
206 | 765 /* |
766 | |
767 This function was taken from EveryBuddy and was written by | |
768 Torrey Searle. tsearle@valhalla.marko.net | |
769 | |
770 http://www.everybuddy.com | |
771 | |
772 */ | |
773 | |
209 | 774 void spell_checker(GtkWidget * text) |
206 | 775 { |
776 int start = 0; | |
777 int end = 0; | |
778 static GdkColor * color = NULL; | |
779 int ignore = 0; | |
780 int point = gtk_editable_get_position(GTK_EDITABLE(text)); | |
781 | |
782 GString * string; | |
783 | |
784 if( color == NULL ) | |
785 { | |
786 GdkColormap * gc = gtk_widget_get_colormap( text ); | |
787 color = g_new0(GdkColor, 1); | |
788 color->red = 255 * 256; | |
789 gdk_colormap_alloc_color(gc, color, FALSE, TRUE); | |
790 } | |
791 | |
792 | |
793 | |
794 end = point-1; | |
795 for( start = end-1; start >= 0; start-- ) | |
796 { | |
797 if((isspace(GTK_TEXT_INDEX(GTK_TEXT(text), start)) || start == 0) | |
798 && !ignore) | |
799 { | |
800 char * word; | |
801 FILE * file; | |
802 char buff[1024]; | |
803 word = gtk_editable_get_chars( GTK_EDITABLE(text), start, end ); | |
804 g_snprintf(buff, 1024, "echo \"%s\" | ispell -l", word ); | |
805 file = popen(buff, "r"); | |
806 | |
807 buff[0] = 0; | |
808 fgets(buff, 255, file); | |
809 | |
810 if(strlen(buff) > 0 ) | |
811 { | |
812 string = g_string_new(word); | |
813 gtk_text_set_point(GTK_TEXT(text), end); | |
814 gtk_text_backward_delete(GTK_TEXT(text), end-start); | |
815 gtk_text_insert( GTK_TEXT(text), NULL, color, NULL, | |
816 string->str, string->len ); | |
817 g_string_free( string, TRUE ); | |
818 } | |
819 else | |
820 { | |
821 string = g_string_new(word); | |
822 gtk_text_set_point(GTK_TEXT(text), end); | |
823 gtk_text_backward_delete(GTK_TEXT(text), end-start); | |
824 gtk_text_insert( GTK_TEXT(text), NULL, &(text->style->fg[0]), NULL, | |
825 string->str, string->len ); | |
826 g_string_free( string, TRUE ); | |
827 } | |
828 pclose( file); | |
829 break; | |
830 } | |
831 else if(!isalpha(GTK_TEXT_INDEX(GTK_TEXT(text), start))) | |
832 { | |
833 ignore = 1; | |
834 } | |
835 } | |
836 gtk_text_set_point(GTK_TEXT(text), point); | |
837 | |
838 } | |
839 |