Tue, 04 Nov 2003 00:10:29 +0000
[gaim-migrate @ 8022]
(19:08:24) deryni: Paco-Paco can stop wanting to kill Sean for using ctrl-f
in conversations, and all the rest of you can have fun making offline
buddies take priority over online ones (I'm sure you'll figure it out =)
and a change from free() to g_free() in yahoo from zuperdee, since g_free
is theoretically doing more error checking
committer: Luke Schierer <lschiere@pidgin.im>
| 6513 | 1 | /* |
| 2 | * gaim | |
| 3 | * | |
| 4 | * Some code copyright 2003 Tim Ringenbach <omarvo@hotmail.com> | |
| 5 | * (marv on irc.freenode.net) | |
| 6 | * | |
| 7 | * This program is free software; you can redistribute it and/or modify | |
| 8 | * it under the terms of the GNU General Public License as published by | |
| 9 | * the Free Software Foundation; either version 2 of the License, or | |
| 10 | * (at your option) any later version. | |
| 11 | * | |
| 12 | * This program is distributed in the hope that it will be useful, | |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 15 | * GNU General Public License for more details. | |
| 16 | * | |
| 17 | * You should have received a copy of the GNU General Public License | |
| 18 | * along with this program; if not, write to the Free Software | |
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 20 | * | |
| 21 | */ | |
| 22 | ||
| 23 | #ifdef HAVE_CONFIG_H | |
| 24 | #include "config.h" | |
| 25 | #endif | |
| 26 | ||
| 27 | #include "prpl.h" | |
| 28 | #include "debug.h" | |
| 29 | ||
|
6546
6a14dfe43d5c
[gaim-migrate @ 7068]
Mark Doliner <markdoliner@pidgin.im>
parents:
6513
diff
changeset
|
30 | #include <string.h> |
|
6a14dfe43d5c
[gaim-migrate @ 7068]
Mark Doliner <markdoliner@pidgin.im>
parents:
6513
diff
changeset
|
31 | |
| 6513 | 32 | |
| 33 | /* | |
| 34 | * I found these on some website but i don't know that they actually | |
| 35 | * work (or are supposed to work). I didn't impliment them yet. | |
| 36 | * | |
| 37 | * [0;30m ---black | |
| 38 | * [1;37m ---white | |
| 39 | * [0;37m ---tan | |
| 40 | * [0;38m ---light black | |
| 41 | * [1;39m ---dark blue | |
| 42 | * [0;32m ---green | |
| 43 | * [0;33m ---yellow | |
| 44 | * [0;35m ---pink | |
| 45 | * [1;35m ---purple | |
| 46 | * [1;30m ---light blue | |
| 47 | * [0;31m ---red | |
| 48 | * [0;34m ---blue | |
| 49 | * [0;36m ---aqua | |
| 50 | * (shift+comma)lyellow(shift+period) ---light yellow | |
| 51 | * (shift+comma)lgreen(shift+period) ---light green | |
| 52 | [2;30m <--white out | |
| 53 | ||
| 54 | */ | |
| 55 | ||
| 56 | ||
| 57 | static GHashTable *ht = NULL; | |
| 58 | ||
| 59 | void yahoo_init_colorht() | |
| 60 | { | |
| 61 | ht = g_hash_table_new(g_str_hash, g_str_equal); | |
| 6629 | 62 | /* the numbers in comments are what gyach uses, but i think they're incorrect */ |
| 6513 | 63 | g_hash_table_insert(ht, "30", "<FONT COLOR=\"#000000\">"); /* black */ |
| 64 | g_hash_table_insert(ht, "31", "<FONT COLOR=\"#0000FF\">"); /* blue */ | |
| 65 | g_hash_table_insert(ht, "32", "<FONT COLOR=\"#008080\">"); /* cyan */ /* 00b2b2 */ | |
| 66 | g_hash_table_insert(ht, "33", "<FONT COLOR=\"#808080\">"); /* gray */ /* 808080 */ | |
| 67 | g_hash_table_insert(ht, "34", "<FONT COLOR=\"#008000\">"); /* green */ /* 00c200 */ | |
| 68 | g_hash_table_insert(ht, "35", "<FONT COLOR=\"#FF0080\">"); /* pink */ /* ffafaf */ | |
| 69 | g_hash_table_insert(ht, "36", "<FONT COLOR=\"#800080\">"); /* purple */ /* b200b2 */ | |
| 70 | g_hash_table_insert(ht, "37", "<FONT COLOR=\"#FF8000\">"); /* orange */ /* ffff00 */ | |
| 71 | g_hash_table_insert(ht, "38", "<FONT COLOR=\"#FF0000\">"); /* red */ | |
| 72 | g_hash_table_insert(ht, "39", "<FONT COLOR=\"#808000\">"); /* olive */ /* 546b50 */ | |
| 73 | ||
| 74 | g_hash_table_insert(ht, "1", "<B>"); | |
| 75 | g_hash_table_insert(ht, "x1", "</B>"); | |
| 76 | g_hash_table_insert(ht, "2", "<I>"); | |
| 77 | g_hash_table_insert(ht, "x2", "</I>"); | |
| 78 | g_hash_table_insert(ht, "4", "<U>"); | |
| 79 | g_hash_table_insert(ht, "x4", "</U>"); | |
| 80 | ||
| 6629 | 81 | /* these just tell us the text they surround is supposed |
| 82 | * to be a link. gaim figures that out on its own so we | |
| 83 | * just ignore it. | |
| 84 | */ | |
| 85 | g_hash_table_insert(ht, "l", ""); /* link start */ | |
| 86 | g_hash_table_insert(ht, "xl", ""); /* link end */ | |
| 87 | ||
| 88 | ||
| 6513 | 89 | g_hash_table_insert(ht, "<black>", "<FONT COLOR=\"#000000\">"); |
| 90 | g_hash_table_insert(ht, "<blue>", "<FONT COLOR=\"#0000FF\">"); | |
| 91 | g_hash_table_insert(ht, "<cyan>", "<FONT COLOR=\"#008284\">"); | |
| 92 | g_hash_table_insert(ht, "<gray>", "<FONT COLOR=\"#848284\">"); | |
| 93 | g_hash_table_insert(ht, "<green>", "<FONT COLOR=\"#008200\">"); | |
| 94 | g_hash_table_insert(ht, "<pink>", "<FONT COLOR=\"#FF0084\">"); | |
| 95 | g_hash_table_insert(ht, "<purple>", "<FONT COLOR=\"#840084\">"); | |
| 96 | g_hash_table_insert(ht, "<orange>", "<FONT COLOR=\"#FF8000\">"); | |
| 97 | g_hash_table_insert(ht, "<red>", "<FONT COLOR=\"#FF0000\">"); | |
| 98 | g_hash_table_insert(ht, "<yellow>", "<FONT COLOR=\"#848200\">"); | |
| 99 | ||
| 100 | g_hash_table_insert(ht, "</black>", "</FONT>"); | |
| 101 | g_hash_table_insert(ht, "</blue>", "</FONT>"); | |
| 102 | g_hash_table_insert(ht, "</cyan>", "</FONT>"); | |
| 103 | g_hash_table_insert(ht, "</gray>", "</FONT>"); | |
| 104 | g_hash_table_insert(ht, "</green>", "</FONT>"); | |
| 105 | g_hash_table_insert(ht, "</pink>", "</FONT>"); | |
| 106 | g_hash_table_insert(ht, "</purple>", "</FONT>"); | |
| 107 | g_hash_table_insert(ht, "</orange>", "</FONT>"); | |
| 108 | g_hash_table_insert(ht, "</red>", "</FONT>"); | |
| 109 | g_hash_table_insert(ht, "</yellow>", "</FONT>"); | |
| 110 | ||
| 111 | /* remove these once we have proper support for <FADE> and <ALT> */ | |
| 112 | g_hash_table_insert(ht, "</fade>", ""); | |
| 113 | g_hash_table_insert(ht, "</alt>", ""); | |
| 114 | } | |
| 115 | ||
| 116 | void yahoo_dest_colorht() | |
| 117 | { | |
| 118 | g_hash_table_destroy(ht); | |
| 119 | } | |
| 120 | ||
| 6629 | 121 | static int point_to_html(int x) |
| 122 | { | |
| 123 | if (x < 9) | |
| 124 | return 1; | |
| 125 | if (x < 11) | |
| 126 | return 2; | |
| 127 | if (x < 13) | |
| 128 | return 3; | |
| 129 | if (x < 17) | |
| 130 | return 4; | |
| 131 | if (x < 25) | |
| 132 | return 5; | |
| 133 | if (x < 35) | |
| 134 | return 6; | |
| 135 | return 7; | |
| 136 | } | |
| 137 | static void _font_tags_fix_size(GString *tag, GString *dest) | |
| 138 | { | |
| 139 | char *x, *end; | |
| 140 | int size; | |
| 141 | ||
| 142 | if (((x = strstr(tag->str, "size"))) && ((x = strchr(tag->str, '=')))) { | |
| 143 | while (*x && !g_ascii_isdigit(*x)) | |
| 144 | x++; | |
| 145 | if (*x) { | |
| 146 | size = strtol(x, &end, 10); | |
| 147 | size = point_to_html(size); | |
| 148 | g_string_append_len(dest, tag->str, x - tag->str); | |
| 149 | g_string_append_printf(dest, "%d", size); | |
| 150 | g_string_append(dest, end); | |
| 151 | } else { | |
| 152 | g_string_append(dest, tag->str); | |
| 153 | return; | |
| 154 | } | |
| 155 | } else { | |
| 156 | g_string_append(dest, tag->str); | |
| 157 | return; | |
| 158 | } | |
| 159 | } | |
| 160 | ||
| 161 | char *yahoo_codes_to_html(const char *x) | |
| 6513 | 162 | { |
| 163 | GString *s, *tmp; | |
| 6629 | 164 | int i, j, xs, nomoreendtags = 0; /* s/endtags/closinganglebrackets */ |
| 6513 | 165 | char *match, *ret; |
| 166 | ||
| 167 | ||
| 168 | s = g_string_sized_new(strlen(x)); | |
| 169 | ||
| 170 | for (i = 0, xs = strlen(x); i < xs; i++) { | |
| 171 | if ((x[i] == 0x1b) && (x[i+1] == '[')) { | |
| 172 | j = i + 1; | |
| 173 | ||
| 174 | while (j++ < xs) { | |
| 175 | if (x[j] != 'm') | |
| 176 | continue; | |
| 177 | else { | |
| 178 | tmp = g_string_new_len(x + i + 2, j - i - 2); | |
|
6621
2a18ef3e5224
[gaim-migrate @ 7145]
Robert McQueen <robot101@debian.org>
parents:
6546
diff
changeset
|
179 | if (tmp->str[0] == '#') |
| 6513 | 180 | g_string_append_printf(s, "<FONT COLOR=\"%s\">", tmp->str); |
|
6546
6a14dfe43d5c
[gaim-migrate @ 7068]
Mark Doliner <markdoliner@pidgin.im>
parents:
6513
diff
changeset
|
181 | else if ((match = (char *) g_hash_table_lookup(ht, tmp->str))) |
| 6513 | 182 | g_string_append(s, match); |
| 183 | else { | |
| 184 | gaim_debug(GAIM_DEBUG_ERROR, "yahoo", | |
| 185 | "Unknown ansi code 'ESC[%sm'.\n", tmp->str); | |
| 186 | g_string_free(tmp, TRUE); | |
| 187 | break; | |
| 188 | } | |
| 189 | ||
| 190 | i = j; | |
| 191 | g_string_free(tmp, TRUE); | |
| 192 | break; | |
| 193 | } | |
| 194 | } | |
| 195 | ||
| 196 | ||
| 197 | } else if (!nomoreendtags && (x[i] == '<')) { | |
| 6629 | 198 | j = i; |
| 6513 | 199 | |
| 200 | while (j++ < xs) { | |
| 201 | if (x[j] != '>') | |
| 202 | if (j == xs) { | |
| 203 | g_string_append_c(s, '<'); | |
| 204 | nomoreendtags = 1; | |
| 205 | } | |
| 206 | else | |
| 207 | continue; | |
| 208 | else { | |
| 209 | tmp = g_string_new_len(x + i, j - i + 1); | |
| 210 | g_string_ascii_down(tmp); | |
| 211 | ||
|
6546
6a14dfe43d5c
[gaim-migrate @ 7068]
Mark Doliner <markdoliner@pidgin.im>
parents:
6513
diff
changeset
|
212 | if ((match = (char *) g_hash_table_lookup(ht, tmp->str))) |
| 6513 | 213 | g_string_append(s, match); |
| 6629 | 214 | else if (!strncmp(tmp->str, "<fade ", 6) || |
| 215 | !strncmp(tmp->str, "<alt ", 5) || | |
| 216 | !strncmp(tmp->str, "<snd ", 5)) { | |
| 6513 | 217 | |
| 6629 | 218 | /* remove this if gtkimhtml ever supports any of these */ |
| 6513 | 219 | i = j; |
| 220 | g_string_free(tmp, TRUE); | |
| 221 | break; | |
| 222 | ||
| 6629 | 223 | } else if (!strncmp(tmp->str, "<font ", 6)) { |
| 224 | _font_tags_fix_size(tmp, s); | |
| 6513 | 225 | } else { |
| 226 | g_string_append_c(s, '<'); | |
| 227 | g_string_free(tmp, TRUE); | |
| 228 | break; | |
| 229 | } | |
| 230 | ||
| 231 | i = j; | |
| 232 | g_string_free(tmp, TRUE); | |
| 233 | break; | |
| 234 | } | |
| 235 | ||
| 236 | } | |
| 237 | ||
| 238 | ||
| 239 | ||
| 240 | } else { | |
| 241 | g_string_append_c(s, x[i]); | |
| 242 | } | |
| 243 | } | |
| 244 | ||
| 245 | ret = s->str; | |
| 246 | g_string_free(s, FALSE); | |
| 6629 | 247 | gaim_debug(GAIM_DEBUG_MISC, "yahoo", "yahoo_codes_to_html: Returning string: '%s'.\n", ret); |
| 6513 | 248 | return ret; |
| 249 | } | |
| 6629 | 250 | |
| 251 | /* borrowed from gtkimhtml */ | |
| 252 | #define MAX_FONT_SIZE 7 | |
| 253 | #define POINT_SIZE(x) (_point_sizes [MIN ((x), MAX_FONT_SIZE) - 1]) | |
| 254 | static gint _point_sizes [] = { 8, 10, 12, 14, 20, 30, 40 }; | |
| 255 | ||
| 256 | enum fatype { size, color, face, junk }; | |
| 257 | typedef struct { | |
| 258 | enum fatype type; | |
| 259 | union { | |
| 260 | int size; | |
| 261 | char *color; | |
| 262 | char *face; | |
| 263 | char *junk; | |
| 264 | } u; | |
| 265 | } fontattr; | |
| 266 | ||
| 267 | static void fontattr_free(fontattr *f) | |
| 268 | { | |
| 269 | if (f->type == color) | |
| 270 | g_free(f->u.color); | |
| 271 | else if (f->type == face) | |
| 272 | g_free(f->u.face); | |
| 273 | g_free(f); | |
| 274 | } | |
| 275 | ||
| 276 | static void yahoo_htc_queue_cleanup(GQueue *q) | |
| 277 | { | |
| 278 | char *tmp; | |
| 279 | ||
| 280 | while ((tmp = g_queue_pop_tail(q))) | |
| 281 | g_free(tmp); | |
| 282 | g_queue_free(q); | |
| 283 | } | |
| 284 | ||
| 285 | static void _parse_font_tag(const char *src, GString *dest, int *i, int *j, | |
| 286 | int len, GQueue *colors, GQueue *tags, GQueue *ftattr) | |
| 287 | { | |
| 288 | ||
| 289 | int m, n, vstart; | |
| 290 | gboolean quote = 0, done = 0; | |
| 291 | ||
| 292 | m = *j; | |
| 293 | ||
| 294 | while (1) { | |
| 295 | m++; | |
| 296 | ||
| 297 | if (m >= len) { | |
| 298 | g_string_append(dest, &src[*i]); | |
| 299 | *i = len; | |
| 300 | break; | |
| 301 | } | |
| 302 | ||
| 303 | if (src[m] == '=') { | |
| 304 | n = vstart = m; | |
| 305 | while (1) { | |
| 306 | n++; | |
| 307 | ||
| 308 | if (n >= len) { | |
| 309 | m = n; | |
| 310 | break; | |
| 311 | } | |
| 312 | ||
|
6631
a2608d595a32
[gaim-migrate @ 7155]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
6629
diff
changeset
|
313 | if (src[n] == '"') { |
| 6629 | 314 | if (!quote) { |
| 315 | quote = 1; | |
| 316 | vstart = n; | |
| 317 | continue; | |
| 318 | } else { | |
| 319 | done = 1; | |
| 320 | } | |
|
6631
a2608d595a32
[gaim-migrate @ 7155]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
6629
diff
changeset
|
321 | } |
| 6629 | 322 | |
| 323 | if (!quote && ((src[n] == ' ') || (src[n] == '>'))) | |
| 324 | done = 1; | |
| 325 | ||
| 326 | if (done) { | |
| 327 | if (!g_ascii_strncasecmp(&src[*j+1], "FACE", m - *j - 1)) { | |
| 328 | fontattr *f; | |
| 329 | ||
| 330 | f = g_new(fontattr, 1); | |
| 331 | f->type = face; | |
| 332 | f->u.face = g_strndup(&src[vstart+1], n-vstart-1); | |
| 333 | if (!ftattr) | |
| 334 | ftattr = g_queue_new(); | |
| 335 | g_queue_push_tail(ftattr, f); | |
| 336 | m = n; | |
| 337 | break; | |
| 338 | } else if (!g_ascii_strncasecmp(&src[*j+1], "SIZE", m - *j - 1)) { | |
| 339 | fontattr *f; | |
| 340 | ||
| 341 | f = g_new(fontattr, 1); | |
| 342 | f->type = size; | |
| 343 | f->u.size = POINT_SIZE(strtol(&src[vstart+1], NULL, 10)); | |
| 344 | if (!ftattr) | |
| 345 | ftattr = g_queue_new(); | |
| 346 | g_queue_push_tail(ftattr, f); | |
| 347 | m = n; | |
| 348 | break; | |
| 349 | } else if (!g_ascii_strncasecmp(&src[*j+1], "COLOR", m - *j - 1)) { | |
| 350 | fontattr *f; | |
| 351 | ||
| 352 | f = g_new(fontattr, 1); | |
| 353 | f->type = color; | |
| 354 | f->u.color = g_strndup(&src[vstart+1], n-vstart-1); | |
| 355 | if (!ftattr) | |
| 356 | ftattr = g_queue_new(); | |
| 357 | g_queue_push_head(ftattr, f); | |
| 358 | m = n; | |
| 359 | break; | |
| 360 | } else { | |
| 361 | fontattr *f; | |
| 362 | ||
| 363 | f = g_new(fontattr, 1); | |
| 364 | f->type = junk; | |
| 365 | f->u.junk = g_strndup(&src[*j+1], n-*j); | |
| 366 | if (!ftattr) | |
| 367 | ftattr = g_queue_new(); | |
| 368 | g_queue_push_tail(ftattr, f); | |
| 369 | m = n; | |
| 370 | break; | |
| 371 | } | |
| 372 | ||
| 373 | } | |
| 374 | } | |
| 375 | } | |
| 376 | ||
| 377 | if (src[m] == ' ') | |
| 378 | *j = m; | |
| 379 | ||
| 380 | ||
| 381 | ||
| 382 | if (src[m] == '>') { | |
| 383 | gboolean needendtag = 0; | |
| 384 | fontattr *f; | |
| 385 | GString *tmp = g_string_new(NULL); | |
| 386 | char *colorstr; | |
| 387 | ||
| 388 | if (!g_queue_is_empty(ftattr)) { | |
| 389 | while ((f = g_queue_pop_tail(ftattr))) { | |
| 390 | switch (f->type) { | |
| 391 | case size: | |
| 392 | if (!needendtag) { | |
| 393 | needendtag = 1; | |
| 394 | g_string_append(dest, "<font "); | |
| 395 | } | |
| 396 | ||
| 397 | g_string_append_printf(dest, "size=\"%d\" ", f->u.size); | |
| 398 | fontattr_free(f); | |
| 399 | break; | |
| 400 | case face: | |
| 401 | if (!needendtag) { | |
| 402 | needendtag = 1; | |
| 403 | g_string_append(dest, "<font "); | |
| 404 | } | |
| 405 | ||
| 406 | g_string_append_printf(dest, "face=\"%s\" ", f->u.face); | |
| 407 | fontattr_free(f); | |
| 408 | break; | |
| 409 | case junk: | |
| 410 | if (!needendtag) { | |
| 411 | needendtag = 1; | |
| 412 | g_string_append(dest, "<font "); | |
| 413 | } | |
| 414 | ||
| 415 | g_string_append(dest, f->u.junk); | |
| 416 | fontattr_free(f); | |
| 417 | break; | |
| 418 | ||
| 419 | case color: | |
| 420 | if (needendtag) { | |
| 421 | g_string_append(tmp, "</font>"); | |
| 422 | dest->str[dest->len-1] = '>'; | |
| 423 | needendtag = 0; | |
| 424 | } | |
| 425 | ||
| 426 | colorstr = g_queue_peek_tail(colors); | |
| 427 | g_string_append(tmp, colorstr ? colorstr : "\033[#000000m"); | |
| 428 | g_string_append_printf(dest, "\033[%sm", f->u.color); | |
| 429 | g_queue_push_tail(colors, g_strdup_printf("\033[%sm", f->u.color)); | |
| 430 | fontattr_free(f); | |
| 431 | break; | |
| 432 | } | |
| 433 | } | |
| 434 | ||
| 435 | g_queue_free(ftattr); | |
| 436 | ftattr = NULL; | |
| 437 | ||
| 438 | if (needendtag) { | |
| 439 | dest->str[dest->len-1] = '>'; | |
| 440 | g_queue_push_tail(tags, g_strdup("</font>")); | |
| 441 | g_string_free(tmp, TRUE); | |
| 442 | } else { | |
| 443 | g_queue_push_tail(tags, tmp->str); | |
| 444 | g_string_free(tmp, FALSE); | |
| 445 | } | |
| 446 | } | |
| 447 | ||
| 448 | *i = *j = m; | |
| 449 | break; | |
| 450 | } | |
| 451 | } | |
| 452 | ||
| 453 | } | |
| 454 | ||
| 455 | char *yahoo_html_to_codes(const char *src) | |
| 456 | { | |
|
6631
a2608d595a32
[gaim-migrate @ 7155]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
6629
diff
changeset
|
457 | int i, j, len; |
| 6629 | 458 | GString *dest; |
| 459 | char *ret, *esc; | |
| 460 | GQueue *colors, *tags; | |
| 461 | GQueue *ftattr = NULL; | |
| 462 | ||
| 463 | ||
| 464 | colors = g_queue_new(); | |
| 465 | tags = g_queue_new(); | |
| 466 | ||
| 467 | dest = g_string_sized_new(strlen(src)); | |
| 468 | ||
| 469 | for (i = 0, len = strlen(src); i < len; i++) { | |
| 470 | ||
| 471 | if (src[i] == '<') { | |
| 472 | j = i; | |
| 473 | ||
| 474 | while (1) { | |
| 475 | j++; | |
| 476 | ||
| 477 | if (j >= len) { /* no '>' */ | |
| 478 | g_string_append_len(dest, &src[i], len - i); | |
| 479 | i = len; | |
| 480 | ||
| 481 | break; | |
| 482 | } | |
| 483 | ||
| 484 | if (src[j] == '<') { | |
| 485 | g_string_append_len(dest, &src[i], j - i); | |
| 486 | i = j - 1; | |
| 487 | if (ftattr) { | |
| 488 | fontattr *f; | |
| 489 | ||
| 490 | while ((f = g_queue_pop_head(ftattr))) | |
| 491 | fontattr_free(f); | |
| 492 | g_queue_free(ftattr); | |
| 493 | ftattr = NULL; | |
| 494 | } | |
| 495 | break; | |
| 496 | } | |
| 497 | ||
| 498 | if (src[j] == ' ') { | |
| 499 | if (!g_ascii_strncasecmp(&src[i+1], "BODY", j - i - 1)) { | |
| 500 | char *t = strchr(&src[j], '>'); | |
| 501 | if (!t) { | |
| 502 | g_string_append(dest, &src[i]); | |
| 503 | i = len; | |
| 504 | break; | |
| 505 | } else { | |
| 506 | i = t - src; | |
| 507 | break; | |
| 508 | } | |
| 509 | } else if (g_ascii_strncasecmp(&src[i+1], "FONT", j - i - 1)) { /* not interested! */ | |
| 510 | while (1) { | |
| 511 | if (++j >= len) { | |
| 512 | g_string_append(dest, &src[i]); | |
| 513 | i = len; | |
| 514 | break; | |
| 515 | } | |
| 516 | if (src[j] == '>') { | |
| 517 | g_string_append_len(dest, &src[i], j - i + 1); | |
| 518 | i = j; | |
| 519 | break; | |
| 520 | } | |
| 521 | } | |
| 522 | } else { /* yay we have a font tag */ | |
| 523 | _parse_font_tag(src, dest, &i, &j, len, colors, tags, ftattr); | |
| 524 | } | |
| 525 | ||
| 526 | break; | |
| 527 | } | |
| 528 | ||
| 529 | if (src[j] == '>') { | |
| 530 | int sublen = j - i - 1; | |
| 531 | ||
| 532 | if (sublen) { | |
| 533 | if (!g_ascii_strncasecmp(&src[i+1], "B", sublen)) { | |
| 534 | g_string_append(dest, "\033[1m"); | |
| 535 | } else if (!g_ascii_strncasecmp(&src[i+1], "/B", sublen)) { | |
| 536 | g_string_append(dest, "\033[x1m"); | |
| 537 | } else if (!g_ascii_strncasecmp(&src[i+1], "I", sublen)) { | |
| 538 | g_string_append(dest, "\033[2m"); | |
| 539 | } else if (!g_ascii_strncasecmp(&src[i+1], "/I", sublen)) { | |
| 540 | g_string_append(dest, "\033[x2m"); | |
| 541 | } else if (!g_ascii_strncasecmp(&src[i+1], "U", sublen)) { | |
| 542 | g_string_append(dest, "\033[4m"); | |
| 543 | } else if (!g_ascii_strncasecmp(&src[i+1], "/U", sublen)) { | |
| 544 | g_string_append(dest, "\033[x4m"); | |
| 545 | } else if (!g_ascii_strncasecmp(&src[i+1], "/BODY", sublen)) { | |
| 546 | /* mmm, </body> tags. *BURP* */ | |
| 547 | } else if (!g_ascii_strncasecmp(&src[i+1], "/FONT", sublen) && g_queue_peek_tail(tags)) { | |
| 548 | char *etag, *cl; | |
| 549 | ||
| 550 | etag = g_queue_pop_tail(tags); | |
| 551 | if (etag) { | |
| 552 | g_string_append(dest, etag); | |
| 553 | if (!strcmp(etag, "</font>")) { | |
| 554 | cl = g_queue_pop_tail(colors); | |
| 555 | if (cl) | |
| 556 | g_free(cl); | |
| 557 | } | |
| 558 | g_free(etag); | |
| 559 | } | |
| 560 | } else { | |
| 561 | g_string_append_len(dest, &src[i], j - i + 1); | |
| 562 | } | |
| 563 | } else { | |
| 564 | g_string_append_len(dest, &src[i], j - i + 1); | |
| 565 | } | |
| 566 | ||
| 567 | i = j; | |
| 568 | break; | |
| 569 | } | |
| 570 | ||
| 571 | } | |
| 572 | ||
| 573 | } else { | |
| 574 | g_string_append_c(dest, src[i]); | |
| 575 | } | |
| 576 | } | |
| 577 | ||
| 578 | ret = dest->str; | |
| 579 | g_string_free(dest, FALSE); | |
| 580 | ||
| 581 | esc = g_strescape(ret, NULL); | |
| 582 | gaim_debug(GAIM_DEBUG_MISC, "yahoo", "yahoo_html_to_codes: Returning string: '%s'.\n", esc); | |
| 583 | g_free(esc); | |
| 584 | ||
| 585 | yahoo_htc_queue_cleanup(colors); | |
| 586 | yahoo_htc_queue_cleanup(tags); | |
| 587 | ||
| 588 | return ret; | |
| 589 | } |