pidgin/gtkthemes.c

branch
soc.2013.gobjectification.plugins
changeset 36959
4806ff428ecd
parent 36626
18fc361b3704
parent 35086
53eae615eb62
child 37102
63a5361c11a1
equal deleted inserted replaced
36958:2ab9fcc7ca7c 36959:4806ff428ecd
205 } 205 }
206 } 206 }
207 207
208 void pidgin_themes_load_smiley_theme(const char *file, gboolean load) 208 void pidgin_themes_load_smiley_theme(const char *file, gboolean load)
209 { 209 {
210 FILE *f = g_fopen(file, "r"); 210 FILE *f = g_fopen(file, "rb");
211 char buf[256]; 211 char buf[256];
212 char *i; 212 char *i;
213 gsize line_nbr = 0;
213 struct smiley_theme *theme=NULL; 214 struct smiley_theme *theme=NULL;
214 struct smiley_list *list = NULL; 215 struct smiley_list *list = NULL;
215 GSList *lst = smiley_themes; 216 GSList *lst = smiley_themes;
216 char *dirname; 217 char *dirname;
217 218
243 244
244 while (!feof(f)) { 245 while (!feof(f)) {
245 if (!fgets(buf, sizeof(buf), f)) { 246 if (!fgets(buf, sizeof(buf), f)) {
246 break; 247 break;
247 } 248 }
249 line_nbr++;
248 250
249 if (buf[0] == '#' || buf[0] == '\0') 251 if (buf[0] == '#' || buf[0] == '\0')
250 continue; 252 continue;
251 else { 253 else {
252 int len = strlen(buf); 254 int len = strlen(buf);
253 while (len && (buf[len - 1] == '\r' || buf[len - 1] == '\n')) 255 while (len && (buf[len - 1] == '\r' || buf[len - 1] == '\n'))
254 buf[--len] = '\0'; 256 buf[--len] = '\0';
255 if (len == 0) 257 if (len == 0)
256 continue; 258 continue;
259 }
260
261 if (! g_utf8_validate(buf, -1, NULL)) {
262 purple_debug_error("gtkthemes", "%s:%" G_GSIZE_FORMAT " is invalid UTF-8\n", file, line_nbr);
263 continue;
257 } 264 }
258 265
259 i = buf; 266 i = buf;
260 while (isspace(*i)) 267 while (isspace(*i))
261 i++; 268 i++;
294 i = i + 2; 301 i = i + 2;
295 } 302 }
296 while (*i) { 303 while (*i) {
297 char l[64]; 304 char l[64];
298 gsize li = 0; 305 gsize li = 0;
306 char *next;
299 while (*i && !isspace(*i) && li < sizeof(l) - 1) { 307 while (*i && !isspace(*i) && li < sizeof(l) - 1) {
300 if (*i == '\\' && *(i+1) != '\0') 308 if (*i == '\\' && *(i+1) != '\0')
301 i++; 309 i++;
302 l[li++] = *(i++); 310 next = g_utf8_next_char(i);
311 if ((gsize)(next - i) > (sizeof(l) - li -1)) {
312 break;
313 }
314 while (i != next)
315 l[li++] = *(i++);
303 } 316 }
304 l[li] = 0; 317 l[li] = 0;
305 if (!sfile) { 318 if (!sfile) {
306 sfile = g_build_filename(dirname, l, NULL); 319 sfile = g_build_filename(dirname, l, NULL);
307 } else { 320 } else {

mercurial