Mercurial > pidgin
annotate src/util.c @ 210:ec0686b3b03f
[gaim-migrate @ 220]
Mostly small changes trying to get -Wall not to give any messages.
committer: Tailor Script <tailor@pidgin.im>
| author | Eric Warmenhoven <eric@warmenhoven.org> |
|---|---|
| date | Mon, 01 May 2000 19:39:00 +0000 |
| parents | 6e9b375e30e7 |
| children | fa67d29b53d5 |
| 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 | |
| 403 int escape_message(char *msg) | |
| 404 { | |
| 405 char *c, *cpy; | |
| 406 int cnt=0; | |
| 407 /* Assumes you have a buffer able to cary at least BUF_LEN * 2 bytes */ | |
| 408 if (strlen(msg) > BUF_LEN) { | |
| 409 sprintf(debug_buff, "Warning: truncating message to 2048 bytes\n"); | |
| 410 debug_print(debug_buff); | |
| 411 msg[2047]='\0'; | |
| 412 } | |
| 413 | |
| 414 cpy = g_strdup(msg); | |
| 415 c = cpy; | |
| 416 while(*c) { | |
| 417 switch(*c) { | |
| 418 case '$': | |
| 419 case '[': | |
| 420 case ']': | |
| 421 case '(': | |
| 422 case ')': | |
| 423 case '#': | |
| 424 msg[cnt++]='\\'; | |
| 425 /* Fall through */ | |
| 426 default: | |
| 427 msg[cnt++]=*c; | |
| 428 } | |
| 429 c++; | |
| 430 } | |
| 431 msg[cnt]='\0'; | |
| 432 g_free(cpy); | |
| 433 return cnt; | |
| 434 } | |
| 435 | |
| 436 int escape_text(char *msg) | |
| 437 { | |
| 438 char *c, *cpy; | |
| 439 int cnt=0; | |
| 79 | 440 /* Assumes you have a buffer able to cary at least BUF_LEN * 4 bytes */ |
| 1 | 441 if (strlen(msg) > BUF_LEN) { |
| 442 fprintf(stderr, "Warning: truncating message to 2048 bytes\n"); | |
| 443 msg[2047]='\0'; | |
| 444 } | |
| 445 | |
| 446 cpy = g_strdup(msg); | |
| 447 c = cpy; | |
| 448 while(*c) { | |
| 449 switch(*c) { | |
| 450 case '\n': | |
| 451 msg[cnt++] = '<'; | |
| 452 msg[cnt++] = 'B'; | |
| 453 msg[cnt++] = 'R'; | |
| 454 msg[cnt++] = '>'; | |
| 455 break; | |
| 456 case '{': | |
| 457 case '}': | |
| 458 case '\\': | |
| 459 case '"': | |
| 460 msg[cnt++]='\\'; | |
| 461 /* Fall through */ | |
| 462 default: | |
| 463 msg[cnt++]=*c; | |
| 464 } | |
| 465 c++; | |
| 466 } | |
| 467 msg[cnt]='\0'; | |
| 468 g_free(cpy); | |
| 469 return cnt; | |
| 470 } | |
| 471 | |
| 472 char * escape_text2(char *msg) | |
| 473 { | |
| 474 char *c, *cpy; | |
| 475 char *woo; | |
| 476 int cnt=0; | |
| 477 /* Assumes you have a buffer able to cary at least BUF_LEN * 2 bytes */ | |
| 478 if (strlen(msg) > BUF_LEN) { | |
| 479 fprintf(stderr, "Warning: truncating message to 2048 bytes\n"); | |
| 480 msg[2047]='\0'; | |
| 481 } | |
| 482 | |
| 79 | 483 woo = malloc(strlen(msg) * 2); |
| 1 | 484 cpy = g_strdup(msg); |
| 485 c = cpy; | |
| 486 while(*c) { | |
| 487 switch(*c) { | |
| 488 case '\n': | |
| 489 woo[cnt++] = '<'; | |
| 490 woo[cnt++] = 'B'; | |
| 491 woo[cnt++] = 'R'; | |
| 492 woo[cnt++] = '>'; | |
| 493 break; | |
| 494 case '{': | |
| 495 case '}': | |
| 496 case '\\': | |
| 497 case '"': | |
| 498 woo[cnt++]='\\'; | |
| 499 /* Fall through */ | |
| 500 default: | |
| 501 woo[cnt++]=*c; | |
| 502 } | |
| 503 c++; | |
| 504 } | |
| 505 woo[cnt]='\0'; | |
| 26 | 506 |
| 507 g_free (cpy); | |
| 1 | 508 return woo; |
| 509 } | |
| 510 | |
| 511 | |
| 512 char alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" | |
| 513 "0123456789+/"; | |
| 514 | |
| 515 | |
| 516 char *tobase64(char *text) | |
| 517 { | |
| 518 char *out = NULL; | |
| 519 char *c; | |
| 520 unsigned int tmp = 0; | |
| 521 int len = 0, n = 0; | |
| 522 | |
| 523 c = text; | |
| 524 | |
| 525 while(c) { | |
| 526 tmp = tmp << 8; | |
| 527 tmp += *c; | |
| 528 n++; | |
| 529 | |
| 530 if (n == 3) { | |
| 531 out = g_realloc(out, len+4); | |
| 532 out[len] = alphabet[(tmp >> 18) & 0x3f]; | |
| 533 out[len+1] = alphabet[(tmp >> 12) & 0x3f]; | |
| 534 out[len+2] = alphabet[(tmp >> 6) & 0x3f]; | |
| 535 out[len+3] = alphabet[tmp & 0x3f]; | |
| 536 len += 4; | |
| 537 tmp = 0; | |
| 538 n = 0; | |
| 539 } | |
| 540 c++; | |
| 541 } | |
| 542 switch(n) { | |
| 543 | |
| 544 case 2: | |
| 545 out = g_realloc(out, len+5); | |
| 546 out[len] = alphabet[(tmp >> 12) & 0x3f]; | |
| 547 out[len+1] = alphabet[(tmp >> 6) & 0x3f]; | |
| 548 out[len+2] = alphabet[tmp & 0x3f]; | |
| 549 out[len+3] = '='; | |
| 550 out[len+4] = 0; | |
| 551 break; | |
| 552 case 1: | |
| 553 out = g_realloc(out, len+4); | |
| 554 out[len] = alphabet[(tmp >> 6) & 0x3f]; | |
| 555 out[len+1] = alphabet[tmp & 0x3f]; | |
| 556 out[len+2] = '='; | |
| 557 out[len+3] = 0; | |
| 558 break; | |
| 559 case 0: | |
| 560 out = g_realloc(out, len+2); | |
| 561 out[len] = '='; | |
| 562 out[len+1] = 0; | |
| 563 break; | |
| 564 } | |
| 565 return out; | |
| 566 } | |
| 567 | |
| 568 | |
| 569 char *frombase64(char *text) | |
| 570 { | |
| 571 char *out = NULL; | |
| 572 char tmp = 0; | |
| 573 char *c; | |
| 574 gint32 tmp2 = 0; | |
| 575 int len = 0, n = 0; | |
| 576 | |
| 577 c = text; | |
| 578 | |
| 579 while(*c) { | |
| 580 if (*c >= 'A' && *c <= 'Z') { | |
| 581 tmp = *c - 'A'; | |
| 582 } else if (*c >= 'a' && *c <= 'z') { | |
| 583 tmp = 26 + (*c - 'a'); | |
| 584 } else if (*c >= '0' && *c <= 57) { | |
| 585 tmp = 52 + (*c - '0'); | |
| 586 } else if (*c == '+') { | |
| 587 tmp = 62; | |
| 588 } else if (*c == '/') { | |
| 589 tmp = 63; | |
| 590 } else if (*c == '=') { | |
| 591 if (n == 3) { | |
| 592 out = g_realloc(out, len + 2); | |
| 593 out[len] = (char)(tmp2 >> 10) & 0xff; | |
| 594 len++; | |
| 595 out[len] = (char)(tmp2 >> 2) & 0xff; | |
| 596 len++; | |
| 597 } else if (n == 2) { | |
| 598 out = g_realloc(out, len + 1); | |
| 599 out[len] = (char)(tmp2 >> 4) & 0xff; | |
| 600 len++; | |
| 601 } | |
| 602 break; | |
| 603 } | |
| 604 tmp2 = ((tmp2 << 6) | (tmp & 0xff)); | |
| 605 n++; | |
| 606 if (n == 4) { | |
| 607 out = g_realloc(out, len + 3); | |
| 608 out[len] = (char)((tmp2 >> 16) & 0xff); | |
| 609 len++; | |
| 610 out[len] = (char)((tmp2 >> 8) & 0xff); | |
| 611 len++; | |
| 612 out[len] = (char)(tmp2 & 0xff); | |
| 613 len++; | |
| 614 tmp2 = 0; | |
| 615 n = 0; | |
| 616 } | |
| 617 c++; | |
| 618 } | |
| 619 | |
|
194
d7690984c0f1
[gaim-migrate @ 204]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
180
diff
changeset
|
620 out = g_realloc(out, len+1); |
| 1 | 621 out[len] = 0; |
| 622 | |
| 623 return out; | |
| 624 } | |
| 625 | |
| 626 | |
| 627 char *normalize(const char *s) | |
| 628 { | |
| 629 static char buf[BUF_LEN]; | |
| 630 char *t, *u; | |
| 631 int x=0; | |
| 632 | |
| 79 | 633 g_return_val_if_fail ((s != NULL), NULL); |
| 26 | 634 |
| 635 u = t = g_strdup(s); | |
| 1 | 636 |
| 637 strcpy(t, s); | |
| 638 g_strdown(t); | |
| 639 | |
| 26 | 640 while(*t && (x < BUF_LEN - 1)) { |
| 1 | 641 if (*t != ' ') { |
| 642 buf[x] = *t; | |
| 643 x++; | |
| 644 } | |
| 645 t++; | |
| 646 } | |
| 647 buf[x]='\0'; | |
| 648 g_free(u); | |
| 649 return buf; | |
| 650 } | |
| 651 | |
| 652 int query_state() | |
| 653 { | |
| 654 return state; | |
| 655 } | |
| 656 | |
| 657 void set_state(int i) | |
| 658 { | |
| 659 state = i; | |
| 660 } | |
| 661 | |
| 662 char *date() | |
| 663 { | |
| 664 static char date[80]; | |
| 665 time_t tme; | |
| 666 time(&tme); | |
| 667 strftime(date, sizeof(date), "%H:%M:%S", localtime(&tme)); | |
| 668 return date; | |
| 669 } | |
| 670 | |
| 671 | |
| 672 gint clean_pid(void *dummy) | |
| 673 { | |
| 674 int status; | |
| 675 pid_t pid; | |
| 676 | |
| 677 pid = waitpid(-1, &status, WNOHANG); | |
| 678 | |
| 679 if (pid == 0) | |
| 680 return TRUE; | |
| 681 | |
| 682 return FALSE; | |
| 683 } | |
| 684 | |
| 685 void aol_icon(GdkWindow *w) | |
| 686 { | |
| 687 #ifndef _WIN32 | |
| 688 if (icon_pm == NULL) { | |
| 689 icon_pm = gdk_pixmap_create_from_xpm_d(w, &icon_bm, | |
| 690 NULL, (gchar **)aimicon_xpm); | |
| 691 } | |
| 692 gdk_window_set_icon(w, NULL, icon_pm, icon_bm); | |
| 10 | 693 if (mainwindow) gdk_window_set_group(w, mainwindow->window); |
| 1 | 694 #endif |
| 695 } | |
| 696 | |
| 697 struct aim_user *find_user(const char *name) | |
| 698 { | |
| 699 char *who = g_strdup(normalize(name)); | |
| 700 GList *usr = aim_users; | |
| 701 struct aim_user *u; | |
| 702 | |
| 703 while(usr) { | |
| 704 u = (struct aim_user *)usr->data; | |
| 705 if (!strcmp(normalize(u->username), who)) { | |
| 706 g_free(who); | |
| 707 return u; | |
| 708 } | |
| 709 usr = usr->next; | |
| 710 } | |
| 711 g_free(who); | |
| 712 return NULL; | |
| 713 } | |
| 180 | 714 |
| 715 void check_gaim_versions() | |
| 716 { | |
| 717 char *cur_ver; | |
| 718 char *tmp; | |
| 719 | |
| 720 cur_ver = (char *)malloc(BUF_LONG); | |
| 721 tmp = (char *)malloc(BUF_LONG); | |
| 722 | |
| 723 cur_ver = (char *)grab_url("http://www.marko.net/gaim/latest-gaim"); | |
| 724 | |
| 725 if (!strncasecmp(cur_ver, "g00", 3)) | |
| 726 { | |
| 727 free(cur_ver); | |
| 728 free(tmp); | |
| 729 return; | |
| 730 } | |
| 731 | |
| 732 g_snprintf(tmp, BUF_LONG, "%s", strstr(cur_ver, "plain")+9); | |
| 733 g_strchomp(tmp); | |
| 734 | |
| 735 if (strcasecmp(tmp, latest_ver)) | |
| 736 { | |
| 737 g_snprintf(cur_ver, BUF_LONG, "GAIM v%s is now available.\n\nDownload it at http://www.marko.net/gaim\n", tmp); | |
| 738 | |
| 739 do_error_dialog(cur_ver, "GAIM - New Version!"); | |
| 740 strcpy(latest_ver, tmp); | |
| 741 save_prefs(); | |
| 742 } | |
| 743 | |
| 744 free(tmp); | |
| 745 free(cur_ver); | |
| 746 } | |
| 747 | |
| 748 | |
| 206 | 749 /* |
| 750 | |
| 751 This function was taken from EveryBuddy and was written by | |
| 752 Torrey Searle. tsearle@valhalla.marko.net | |
| 753 | |
| 754 http://www.everybuddy.com | |
| 755 | |
| 756 */ | |
| 757 | |
| 209 | 758 void spell_checker(GtkWidget * text) |
| 206 | 759 { |
| 760 int start = 0; | |
| 761 int end = 0; | |
| 762 static GdkColor * color = NULL; | |
| 763 int ignore = 0; | |
| 764 int point = gtk_editable_get_position(GTK_EDITABLE(text)); | |
| 765 | |
| 766 GString * string; | |
| 767 | |
| 768 if( color == NULL ) | |
| 769 { | |
| 770 GdkColormap * gc = gtk_widget_get_colormap( text ); | |
| 771 color = g_new0(GdkColor, 1); | |
| 772 color->red = 255 * 256; | |
| 773 gdk_colormap_alloc_color(gc, color, FALSE, TRUE); | |
| 774 } | |
| 775 | |
| 776 | |
| 777 | |
| 778 end = point-1; | |
| 779 for( start = end-1; start >= 0; start-- ) | |
| 780 { | |
| 781 if((isspace(GTK_TEXT_INDEX(GTK_TEXT(text), start)) || start == 0) | |
| 782 && !ignore) | |
| 783 { | |
| 784 char * word; | |
| 785 FILE * file; | |
| 786 char buff[1024]; | |
| 787 word = gtk_editable_get_chars( GTK_EDITABLE(text), start, end ); | |
| 788 g_snprintf(buff, 1024, "echo \"%s\" | ispell -l", word ); | |
| 789 file = popen(buff, "r"); | |
| 790 | |
| 791 buff[0] = 0; | |
| 792 fgets(buff, 255, file); | |
| 793 | |
| 794 if(strlen(buff) > 0 ) | |
| 795 { | |
| 796 string = g_string_new(word); | |
| 797 gtk_text_set_point(GTK_TEXT(text), end); | |
| 798 gtk_text_backward_delete(GTK_TEXT(text), end-start); | |
| 799 gtk_text_insert( GTK_TEXT(text), NULL, color, NULL, | |
| 800 string->str, string->len ); | |
| 801 g_string_free( string, TRUE ); | |
| 802 } | |
| 803 else | |
| 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, &(text->style->fg[0]), NULL, | |
| 809 string->str, string->len ); | |
| 810 g_string_free( string, TRUE ); | |
| 811 } | |
| 812 pclose( file); | |
| 813 break; | |
| 814 } | |
| 815 else if(!isalpha(GTK_TEXT_INDEX(GTK_TEXT(text), start))) | |
| 816 { | |
| 817 ignore = 1; | |
| 818 } | |
| 819 } | |
| 820 gtk_text_set_point(GTK_TEXT(text), point); | |
| 821 | |
| 822 } | |
| 823 |
