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
|
30 #include <string.h>
|
|
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);
|
|
62
|
|
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
|
|
81 g_hash_table_insert(ht, "<black>", "<FONT COLOR=\"#000000\">");
|
|
82 g_hash_table_insert(ht, "<blue>", "<FONT COLOR=\"#0000FF\">");
|
|
83 g_hash_table_insert(ht, "<cyan>", "<FONT COLOR=\"#008284\">");
|
|
84 g_hash_table_insert(ht, "<gray>", "<FONT COLOR=\"#848284\">");
|
|
85 g_hash_table_insert(ht, "<green>", "<FONT COLOR=\"#008200\">");
|
|
86 g_hash_table_insert(ht, "<pink>", "<FONT COLOR=\"#FF0084\">");
|
|
87 g_hash_table_insert(ht, "<purple>", "<FONT COLOR=\"#840084\">");
|
|
88 g_hash_table_insert(ht, "<orange>", "<FONT COLOR=\"#FF8000\">");
|
|
89 g_hash_table_insert(ht, "<red>", "<FONT COLOR=\"#FF0000\">");
|
|
90 g_hash_table_insert(ht, "<yellow>", "<FONT COLOR=\"#848200\">");
|
|
91
|
|
92 g_hash_table_insert(ht, "</black>", "</FONT>");
|
|
93 g_hash_table_insert(ht, "</blue>", "</FONT>");
|
|
94 g_hash_table_insert(ht, "</cyan>", "</FONT>");
|
|
95 g_hash_table_insert(ht, "</gray>", "</FONT>");
|
|
96 g_hash_table_insert(ht, "</green>", "</FONT>");
|
|
97 g_hash_table_insert(ht, "</pink>", "</FONT>");
|
|
98 g_hash_table_insert(ht, "</purple>", "</FONT>");
|
|
99 g_hash_table_insert(ht, "</orange>", "</FONT>");
|
|
100 g_hash_table_insert(ht, "</red>", "</FONT>");
|
|
101 g_hash_table_insert(ht, "</yellow>", "</FONT>");
|
|
102
|
|
103 /* remove these once we have proper support for <FADE> and <ALT> */
|
|
104 g_hash_table_insert(ht, "</fade>", "");
|
|
105 g_hash_table_insert(ht, "</alt>", "");
|
|
106 }
|
|
107
|
|
108 void yahoo_dest_colorht()
|
|
109 {
|
|
110 g_hash_table_destroy(ht);
|
|
111 }
|
|
112
|
|
113 char *yahoo_codes_to_html(char *x)
|
|
114 {
|
|
115 GString *s, *tmp;
|
|
116 int i, j, xs, nomoreendtags = 0;
|
|
117 char *match, *ret;
|
|
118
|
|
119
|
|
120 s = g_string_sized_new(strlen(x));
|
|
121
|
|
122 for (i = 0, xs = strlen(x); i < xs; i++) {
|
|
123 if ((x[i] == 0x1b) && (x[i+1] == '[')) {
|
|
124 j = i + 1;
|
|
125
|
|
126 while (j++ < xs) {
|
|
127 if (x[j] != 'm')
|
|
128 continue;
|
|
129 else {
|
|
130 tmp = g_string_new_len(x + i + 2, j - i - 2);
|
6546
|
131 if ((tmp->str[0] == '#'))
|
6513
|
132 g_string_append_printf(s, "<FONT COLOR=\"%s\">", tmp->str);
|
6546
|
133 else if ((match = (char *) g_hash_table_lookup(ht, tmp->str)))
|
6513
|
134 g_string_append(s, match);
|
|
135 else {
|
|
136 gaim_debug(GAIM_DEBUG_ERROR, "yahoo",
|
|
137 "Unknown ansi code 'ESC[%sm'.\n", tmp->str);
|
|
138 g_string_free(tmp, TRUE);
|
|
139 break;
|
|
140 }
|
|
141
|
|
142 i = j;
|
|
143 g_string_free(tmp, TRUE);
|
|
144 break;
|
|
145 }
|
|
146 }
|
|
147
|
|
148
|
|
149 } else if (!nomoreendtags && (x[i] == '<')) {
|
|
150 j = i + 1;
|
|
151
|
|
152 while (j++ < xs) {
|
|
153 if (x[j] != '>')
|
|
154 if (j == xs) {
|
|
155 g_string_append_c(s, '<');
|
|
156 nomoreendtags = 1;
|
|
157 }
|
|
158 else
|
|
159 continue;
|
|
160 else {
|
|
161 tmp = g_string_new_len(x + i, j - i + 1);
|
|
162 g_string_ascii_down(tmp);
|
|
163
|
6546
|
164 if ((match = (char *) g_hash_table_lookup(ht, tmp->str)))
|
6513
|
165 g_string_append(s, match);
|
|
166 else if (!g_ascii_strncasecmp(tmp->str, "<FADE ", 6) ||
|
|
167 !g_ascii_strncasecmp(tmp->str, "<ALT ", 5) ||
|
|
168 !g_ascii_strncasecmp(tmp->str, "<SND ", 5)) {
|
|
169
|
|
170 /* remove this if gtkhtml ever supports any of these */
|
|
171 i = j;
|
|
172 g_string_free(tmp, TRUE);
|
|
173 break;
|
|
174
|
|
175 } else {
|
|
176 g_string_append_c(s, '<');
|
|
177 g_string_free(tmp, TRUE);
|
|
178 break;
|
|
179 }
|
|
180
|
|
181 i = j;
|
|
182 g_string_free(tmp, TRUE);
|
|
183 break;
|
|
184 }
|
|
185
|
|
186 }
|
|
187
|
|
188
|
|
189
|
|
190 } else {
|
|
191 g_string_append_c(s, x[i]);
|
|
192 }
|
|
193 }
|
|
194
|
|
195 ret = s->str;
|
|
196 g_string_free(s, FALSE);
|
|
197 gaim_debug(GAIM_DEBUG_MISC, "yahoo", "Returning string: '%s'.\n", ret);
|
|
198 return ret;
|
|
199 }
|