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