comparison src/protocols/yahoo/util.c @ 6513:63c449a1022f

[gaim-migrate @ 7030] Tim Ringenbach (marv_sf) writes: " This processes yahoo's weird color codes, and turns them into normal html. It also strips about fade, alt, and snd tags, while its at it. This doesn't make gaim send valid yahoo color codes, however. If you don't like some aspect of this patch, let me know and I'll fix it. Actually, I added a couple files, and cvs diff wouldn't cooperate, so I just tarred up the patch and the new files. Maybe I should have just stuck it all in yahoo.c. Oh well, you can make me redo it if you don't like it." someone test this and provide patches for any bugs. committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Wed, 20 Aug 2003 01:17:26 +0000
parents
children e34907332e46
comparison
equal deleted inserted replaced
6512:22acbf225a53 6513:63c449a1022f
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
30
31 /*
32 * I found these on some website but i don't know that they actually
33 * work (or are supposed to work). I didn't impliment them yet.
34 *
35 * [0;30m ---black
36 * [1;37m ---white
37 * [0;37m ---tan
38 * [0;38m ---light black
39 * [1;39m ---dark blue
40 * [0;32m ---green
41 * [0;33m ---yellow
42 * [0;35m ---pink
43 * [1;35m ---purple
44 * [1;30m ---light blue
45 * [0;31m ---red
46 * [0;34m ---blue
47 * [0;36m ---aqua
48 * (shift+comma)lyellow(shift+period) ---light yellow
49 * (shift+comma)lgreen(shift+period) ---light green
50 [2;30m <--white out
51
52 */
53
54
55 static GHashTable *ht = NULL;
56
57 void yahoo_init_colorht()
58 {
59 ht = g_hash_table_new(g_str_hash, g_str_equal);
60
61 g_hash_table_insert(ht, "30", "<FONT COLOR=\"#000000\">"); /* black */
62 g_hash_table_insert(ht, "31", "<FONT COLOR=\"#0000FF\">"); /* blue */
63 g_hash_table_insert(ht, "32", "<FONT COLOR=\"#008080\">"); /* cyan */ /* 00b2b2 */
64 g_hash_table_insert(ht, "33", "<FONT COLOR=\"#808080\">"); /* gray */ /* 808080 */
65 g_hash_table_insert(ht, "34", "<FONT COLOR=\"#008000\">"); /* green */ /* 00c200 */
66 g_hash_table_insert(ht, "35", "<FONT COLOR=\"#FF0080\">"); /* pink */ /* ffafaf */
67 g_hash_table_insert(ht, "36", "<FONT COLOR=\"#800080\">"); /* purple */ /* b200b2 */
68 g_hash_table_insert(ht, "37", "<FONT COLOR=\"#FF8000\">"); /* orange */ /* ffff00 */
69 g_hash_table_insert(ht, "38", "<FONT COLOR=\"#FF0000\">"); /* red */
70 g_hash_table_insert(ht, "39", "<FONT COLOR=\"#808000\">"); /* olive */ /* 546b50 */
71
72 g_hash_table_insert(ht, "1", "<B>");
73 g_hash_table_insert(ht, "x1", "</B>");
74 g_hash_table_insert(ht, "2", "<I>");
75 g_hash_table_insert(ht, "x2", "</I>");
76 g_hash_table_insert(ht, "4", "<U>");
77 g_hash_table_insert(ht, "x4", "</U>");
78
79 g_hash_table_insert(ht, "<black>", "<FONT COLOR=\"#000000\">");
80 g_hash_table_insert(ht, "<blue>", "<FONT COLOR=\"#0000FF\">");
81 g_hash_table_insert(ht, "<cyan>", "<FONT COLOR=\"#008284\">");
82 g_hash_table_insert(ht, "<gray>", "<FONT COLOR=\"#848284\">");
83 g_hash_table_insert(ht, "<green>", "<FONT COLOR=\"#008200\">");
84 g_hash_table_insert(ht, "<pink>", "<FONT COLOR=\"#FF0084\">");
85 g_hash_table_insert(ht, "<purple>", "<FONT COLOR=\"#840084\">");
86 g_hash_table_insert(ht, "<orange>", "<FONT COLOR=\"#FF8000\">");
87 g_hash_table_insert(ht, "<red>", "<FONT COLOR=\"#FF0000\">");
88 g_hash_table_insert(ht, "<yellow>", "<FONT COLOR=\"#848200\">");
89
90 g_hash_table_insert(ht, "</black>", "</FONT>");
91 g_hash_table_insert(ht, "</blue>", "</FONT>");
92 g_hash_table_insert(ht, "</cyan>", "</FONT>");
93 g_hash_table_insert(ht, "</gray>", "</FONT>");
94 g_hash_table_insert(ht, "</green>", "</FONT>");
95 g_hash_table_insert(ht, "</pink>", "</FONT>");
96 g_hash_table_insert(ht, "</purple>", "</FONT>");
97 g_hash_table_insert(ht, "</orange>", "</FONT>");
98 g_hash_table_insert(ht, "</red>", "</FONT>");
99 g_hash_table_insert(ht, "</yellow>", "</FONT>");
100
101 /* remove these once we have proper support for <FADE> and <ALT> */
102 g_hash_table_insert(ht, "</fade>", "");
103 g_hash_table_insert(ht, "</alt>", "");
104 }
105
106 void yahoo_dest_colorht()
107 {
108 g_hash_table_destroy(ht);
109 }
110
111 char *yahoo_codes_to_html(char *x)
112 {
113 GString *s, *tmp;
114 int i, j, xs, nomoreendtags = 0;
115 char *match, *ret;
116
117
118 s = g_string_sized_new(strlen(x));
119
120 for (i = 0, xs = strlen(x); i < xs; i++) {
121 if ((x[i] == 0x1b) && (x[i+1] == '[')) {
122 j = i + 1;
123
124 while (j++ < xs) {
125 if (x[j] != 'm')
126 continue;
127 else {
128 tmp = g_string_new_len(x + i + 2, j - i - 2);
129 if (tmp->str[0] == '#')
130 g_string_append_printf(s, "<FONT COLOR=\"%s\">", tmp->str);
131 else if (match = (char *) g_hash_table_lookup(ht, tmp->str))
132 g_string_append(s, match);
133 else {
134 gaim_debug(GAIM_DEBUG_ERROR, "yahoo",
135 "Unknown ansi code 'ESC[%sm'.\n", tmp->str);
136 g_string_free(tmp, TRUE);
137 break;
138 }
139
140 i = j;
141 g_string_free(tmp, TRUE);
142 break;
143 }
144 }
145
146
147 } else if (!nomoreendtags && (x[i] == '<')) {
148 j = i + 1;
149
150 while (j++ < xs) {
151 if (x[j] != '>')
152 if (j == xs) {
153 g_string_append_c(s, '<');
154 nomoreendtags = 1;
155 }
156 else
157 continue;
158 else {
159 tmp = g_string_new_len(x + i, j - i + 1);
160 g_string_ascii_down(tmp);
161
162 if (match = (char *) g_hash_table_lookup(ht, tmp->str))
163 g_string_append(s, match);
164 else if (!g_ascii_strncasecmp(tmp->str, "<FADE ", 6) ||
165 !g_ascii_strncasecmp(tmp->str, "<ALT ", 5) ||
166 !g_ascii_strncasecmp(tmp->str, "<SND ", 5)) {
167
168 /* remove this if gtkhtml ever supports any of these */
169 i = j;
170 g_string_free(tmp, TRUE);
171 break;
172
173 } else {
174 g_string_append_c(s, '<');
175 g_string_free(tmp, TRUE);
176 break;
177 }
178
179 i = j;
180 g_string_free(tmp, TRUE);
181 break;
182 }
183
184 }
185
186
187
188 } else {
189 g_string_append_c(s, x[i]);
190 }
191 }
192
193 ret = s->str;
194 g_string_free(s, FALSE);
195 gaim_debug(GAIM_DEBUG_MISC, "yahoo", "Returning string: '%s'.\n", ret);
196 return ret;
197 }