pidgin/gtkthemes.c

branch
release-2.x.y
changeset 34514
46ba9c764edc
parent 31294
73607ab89c6f
child 34515
93d7461ccc1c
equal deleted inserted replaced
34506:f161fc3074d1 34514:46ba9c764edc
223 void pidgin_themes_load_smiley_theme(const char *file, gboolean load) 223 void pidgin_themes_load_smiley_theme(const char *file, gboolean load)
224 { 224 {
225 FILE *f = g_fopen(file, "r"); 225 FILE *f = g_fopen(file, "r");
226 char buf[256]; 226 char buf[256];
227 char *i; 227 char *i;
228 gsize line_nbr = 0;
228 struct smiley_theme *theme=NULL; 229 struct smiley_theme *theme=NULL;
229 struct smiley_list *list = NULL; 230 struct smiley_list *list = NULL;
230 GSList *lst = smiley_themes; 231 GSList *lst = smiley_themes;
231 char *dirname; 232 char *dirname;
232 233
258 259
259 while (!feof(f)) { 260 while (!feof(f)) {
260 if (!fgets(buf, sizeof(buf), f)) { 261 if (!fgets(buf, sizeof(buf), f)) {
261 break; 262 break;
262 } 263 }
264 line_nbr++;
263 265
264 if (buf[0] == '#' || buf[0] == '\0') 266 if (buf[0] == '#' || buf[0] == '\0')
265 continue; 267 continue;
266 else { 268 else {
267 int len = strlen(buf); 269 int len = strlen(buf);
268 while (len && (buf[len - 1] == '\r' || buf[len - 1] == '\n')) 270 while (len && (buf[len - 1] == '\r' || buf[len - 1] == '\n'))
269 buf[--len] = '\0'; 271 buf[--len] = '\0';
270 if (len == 0) 272 if (len == 0)
271 continue; 273 continue;
274 }
275
276 if (! g_utf8_validate(buf, -1, NULL)) {
277 purple_debug_error("gtkthemes", "%s:%d is invalid UTF-8\n", file, line_nbr);
278 continue;
272 } 279 }
273 280
274 i = buf; 281 i = buf;
275 while (isspace(*i)) 282 while (isspace(*i))
276 i++; 283 i++;
307 i = i + 2; 314 i = i + 2;
308 } 315 }
309 while (*i) { 316 while (*i) {
310 char l[64]; 317 char l[64];
311 int li = 0; 318 int li = 0;
319 char *next;
312 while (*i && !isspace(*i) && li < sizeof(l) - 1) { 320 while (*i && !isspace(*i) && li < sizeof(l) - 1) {
313 if (*i == '\\' && *(i+1) != '\0') 321 if (*i == '\\' && *(i+1) != '\0')
314 i++; 322 i++;
315 l[li++] = *(i++); 323 next = g_utf8_next_char(i);
324 if ((next - i) > (sizeof(l) - li -1)) {
325 break;
326 }
327 while (i != next)
328 l[li++] = *(i++);
316 } 329 }
317 l[li] = 0; 330 l[li] = 0;
318 if (!sfile) { 331 if (!sfile) {
319 sfile = g_build_filename(dirname, l, NULL); 332 sfile = g_build_filename(dirname, l, NULL);
320 } else { 333 } else {

mercurial