Tue, 07 May 2013 05:04:46 -0400
Rewrite debug window filter in JS.
Note, this does cause a couple regressions, but they are probably not
that big a deal. First, the JS regular expression syntax is slightly
different. Second, the JS regex API lacks a way to reliably determine
the location of matched groups, so we can't highlight just the groups
and must highlight the entire expression.
I suspect that none of our users ever had to use any fancy regex in the
debug window, and that most of our developers didn't even know it could
be done. So I doubt these regressions will cause much pain.
|
32513
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
1 | /* pidgin |
|
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
2 | * |
|
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
3 | * Pidgin is the legal property of its developers, whose names are too numerous |
|
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
4 | * to list here. Please refer to the COPYRIGHT file distributed with this |
|
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
5 | * source distribution. |
|
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
6 | * |
|
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
7 | * This program is free software; you can redistribute it and/or modify |
|
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
8 | * it under the terms of the GNU General Public License as published by |
|
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
9 | * the Free Software Foundation; either version 2 of the License, or |
|
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
10 | * (at your option) any later version. |
|
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
11 | * |
|
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
12 | * This program is distributed in the hope that it will be useful, |
|
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
15 | * GNU General Public License for more details. |
|
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
16 | * |
|
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
17 | * You should have received a copy of the GNU General Public License |
|
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
18 | * along with this program; if not, write to the Free Software |
|
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
|
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
20 | * |
|
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
21 | */ |
| 32447 | 22 | |
| 23 | #include <gtk/gtk.h> | |
|
32513
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
24 | #include <debug.h> |
| 32447 | 25 | #include "smileyparser.h" |
| 26 | #include <smiley.h> | |
| 27 | #include <string.h> | |
| 28 | #include "gtkthemes.h" | |
| 29 | ||
|
32513
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
30 | static char * |
|
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
31 | get_fullpath(const char *filename) |
| 32447 | 32 | { |
|
32513
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
33 | if (g_path_is_absolute(filename)) |
|
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
34 | return g_strdup(filename); |
|
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
35 | else |
|
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
36 | return g_build_path(g_get_current_dir(), filename, NULL); |
| 32447 | 37 | } |
| 38 | ||
| 39 | static void | |
|
32513
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
40 | parse_for_shortcut_plaintext(const char *text, const char *shortcut, const char *file, GString *ret) |
| 32447 | 41 | { |
| 42 | const char *tmp = text; | |
| 43 | ||
|
32513
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
44 | for (;*tmp;) { |
|
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
45 | const char *end = strstr(tmp, shortcut); |
| 32447 | 46 | char *path; |
| 47 | char *escaped_path; | |
| 48 | ||
| 49 | if (end == NULL) { | |
|
32513
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
50 | g_string_append(ret, tmp); |
| 32447 | 51 | break; |
| 52 | } | |
|
32513
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
53 | path = get_fullpath(file); |
|
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
54 | escaped_path = g_markup_escape_text(path, -1); |
| 32447 | 55 | |
|
32513
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
56 | g_string_append_len(ret, tmp, end-tmp); |
|
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
57 | g_string_append_printf(ret,"<img alt='%s' src='%s' />", |
| 32447 | 58 | shortcut, escaped_path); |
|
32513
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
59 | g_free(path); |
|
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
60 | g_free(escaped_path); |
|
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
61 | g_assert(strlen(tmp) >= strlen(shortcut)); |
|
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
62 | tmp = end + strlen(shortcut); |
| 32447 | 63 | } |
| 64 | } | |
| 65 | ||
|
32513
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
66 | static char * |
|
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
67 | parse_for_shortcut(const char *markup, const char *shortcut, const char *file) |
| 32447 | 68 | { |
|
32513
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
69 | GString* ret = g_string_new(""); |
|
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
70 | char *local_markup = g_strdup(markup); |
|
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
71 | char *escaped_shortcut = g_markup_escape_text(shortcut, -1); |
| 32447 | 72 | |
| 73 | char *temp = local_markup; | |
|
32513
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
74 | |
| 32447 | 75 | for (;*temp;) { |
|
32513
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
76 | char *end = strchr(temp, '<'); |
| 32447 | 77 | char *end_of_tag; |
| 78 | ||
| 79 | if (!end) { | |
|
32513
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
80 | parse_for_shortcut_plaintext(temp, escaped_shortcut, file, ret); |
| 32447 | 81 | break; |
| 82 | } | |
| 83 | ||
| 84 | *end = 0; | |
|
32513
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
85 | parse_for_shortcut_plaintext(temp, escaped_shortcut, file, ret); |
| 32447 | 86 | *end = '<'; |
| 87 | ||
| 88 | /* if this is well-formed, then there should be no '>' within | |
| 89 | * the tag. TODO: handle a comment tag better :( */ | |
|
32513
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
90 | end_of_tag = strchr(end, '>'); |
| 32447 | 91 | if (!end_of_tag) { |
|
32513
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
92 | g_string_append(ret, end); |
| 32447 | 93 | break; |
| 94 | } | |
| 95 | ||
|
32513
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
96 | g_string_append_len(ret, end, end_of_tag - end + 1); |
| 32447 | 97 | |
| 98 | temp = end_of_tag + 1; | |
| 99 | } | |
|
32513
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
100 | g_free(local_markup); |
|
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
101 | g_free(escaped_shortcut); |
|
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
102 | return g_string_free(ret, FALSE); |
| 32447 | 103 | } |
| 104 | ||
|
32513
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
105 | static char * |
|
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
106 | parse_for_purple_smiley(const char *markup, PurpleSmiley *smiley) |
| 32447 | 107 | { |
|
32513
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
108 | char *file = purple_smiley_get_full_path(smiley); |
|
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
109 | char *ret = parse_for_shortcut(markup, purple_smiley_get_shortcut(smiley), file); |
|
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
110 | g_free(file); |
| 32447 | 111 | return ret; |
| 112 | } | |
| 113 | ||
|
32513
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
114 | static char * |
|
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
115 | parse_for_smiley_list(const char *markup, GHashTable *smileys) |
| 32447 | 116 | { |
| 117 | GHashTableIter iter; | |
| 118 | char *key, *value; | |
|
32513
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
119 | char *ret = g_strdup(markup); |
| 32447 | 120 | |
|
32513
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
121 | g_hash_table_iter_init(&iter, smileys); |
|
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
122 | while (g_hash_table_iter_next(&iter, (gpointer *)&key, (gpointer *)&value)) |
| 32447 | 123 | { |
|
32513
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
124 | char *temp = parse_for_shortcut(ret, key, value); |
|
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
125 | g_free(ret); |
| 32447 | 126 | ret = temp; |
| 127 | } | |
|
32513
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
128 | |
| 32447 | 129 | return ret; |
| 130 | } | |
| 131 | ||
|
32513
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
132 | char * |
|
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
133 | smiley_parse_markup(const char *markup, const char *proto_id) |
| 32447 | 134 | { |
|
32513
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
135 | GList *smileys = purple_smileys_get_all(); |
|
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
136 | char *temp = g_strdup(markup), *temp2; |
| 32447 | 137 | struct smiley_list *list; |
| 138 | const char *proto_name = "default"; | |
| 139 | ||
| 140 | if (proto_id != NULL) { | |
| 141 | PurplePlugin *proto; | |
|
32513
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
142 | proto = purple_find_prpl(proto_id); |
| 32447 | 143 | proto_name = proto->info->name; |
| 144 | } | |
| 145 | ||
| 146 | /* unnecessarily slow, but lets manage for now. */ | |
|
32513
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
147 | for (; smileys; smileys = g_list_next(smileys)) { |
|
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
148 | temp2 = parse_for_purple_smiley(temp, PURPLE_SMILEY(smileys->data)); |
|
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
149 | g_free(temp); |
| 32447 | 150 | temp = temp2; |
| 151 | } | |
| 152 | ||
| 153 | /* now for each theme smiley, observe that this does look nasty */ | |
|
33539
12e93808f35d
Fix some warnings in debug and conv windows
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
32513
diff
changeset
|
154 | if (!current_smiley_theme) { |
|
32513
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
155 | purple_debug_warning("smiley", "theme does not exist\n"); |
| 32447 | 156 | return temp; |
| 157 | } | |
| 158 | ||
| 159 | for (list = current_smiley_theme->list; list; list = list->next) { | |
|
32513
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
160 | if (g_str_equal(list->sml, proto_name)) { |
|
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
161 | temp2 = parse_for_smiley_list(temp, list->files); |
|
9352b4c92d13
Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
32447
diff
changeset
|
162 | g_free(temp); |
| 32447 | 163 | temp = temp2; |
| 164 | } | |
| 165 | } | |
| 166 | ||
| 167 | return temp; | |
| 168 | } | |
| 169 |