From ee8d3aa3f337cef3faae8d45c6e23ab05f380db8 Mon Sep 17 00:00:00 2001 From: Tomas Bzatek Date: Sun, 3 Aug 2008 23:29:01 +0200 Subject: Always generate valid XHTML entities No need to double-escape entities in source XML files, just use single & etc. --- generators.c | 186 ++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 115 insertions(+), 71 deletions(-) (limited to 'generators.c') diff --git a/generators.c b/generators.c index a478389..18fa25f 100644 --- a/generators.c +++ b/generators.c @@ -36,11 +36,11 @@ */ void generate_image (TGallerySetup *setup, - TAlbum *items, - TIndexItem *item, + TAlbum *items, + TIndexItem *item, const char *dst, - unsigned long *img_w, unsigned long *img_h, - const char **img_src) + unsigned long *img_w, unsigned long *img_h, + const char **img_src) { unsigned long new_w, new_h; char *thumb_dst; @@ -188,7 +188,7 @@ write_html_album (TGallerySetup *setup, gboolean in_img_list_portrait; gboolean in_go_up_string; char *b; - char *s1, *s2, *s3; + char *s1, *s2, *s3, *s4; TAlbum *parent; TIndexItem *item; int level; @@ -285,33 +285,53 @@ write_html_album (TGallerySetup *setup, /* Simple placeholders */ - if (strstr (b, "") && items->ID) - str_replace (&b, "", items->ID); - if (strstr (b, "") && items->title) - str_replace (&b, "", items->title); - if (strstr (b, "") && items->desc) - str_replace (&b, "", items->desc); - if (strstr (b, "") && setup->footer) - str_replace (&b, "", setup->footer); + if (strstr (b, "") && items->ID) { + s1 = g_strdup (items->ID); + fix_entities (&s1); + str_replace (&b, "", s1, NULL); + g_free (s1); + } + if (strstr (b, "") && items->title) { + s1 = g_strdup (items->title); + fix_entities (&s1); + str_replace (&b, "", s1, NULL); + g_free (s1); + } + if (strstr (b, "") && items->desc) { + s1 = g_strdup (items->desc); + fix_entities (&s1); + str_replace (&b, "", s1, NULL); + g_free (s1); + } + if (strstr (b, "") && setup->footer) { + s1 = g_strdup (setup->footer); + fix_entities (&s1); + str_replace (&b, "", s1, NULL); + g_free (s1); + } if (strstr (b, "")) { s1 = g_strdup_printf ("%d", items->items->len); - str_replace (&b, "", s1); + str_replace (&b, "", s1, NULL); g_free (s1); } if (strstr (b, "")) { s1 = g_strdup (items->ID); + fix_entities (&s1); parent = items->parent_index; level = 1; while (parent) { - s3 = make_string ("../", level); - s2 = g_strconcat ("", parent->ID, " > ", s1, NULL); + s3 = make_string ("../", level); + s4 = g_strdup (parent->ID); + fix_entities (&s4); + s2 = g_strconcat ("", s4, " > ", s1, NULL); free (s3); g_free (s1); + g_free (s4); s1 = s2; parent = parent->parent_index; level++; } - str_replace (&b, "", s1); + str_replace (&b, "", s1, NULL); g_free (s1); } @@ -353,36 +373,44 @@ write_html_album (TGallerySetup *setup, else s1 = strdup (buf_img_list_portrait); - while (strstr (s1, "")) { + if (strstr (s1, "")) { s2 = g_strconcat (item->path, "/index.html", NULL); - str_replace (&s1, "", s2); + str_replace (&s1, "", s2, NULL); g_free (s2); } - while (strstr (s1, "")) { + if (strstr (s1, "")) { s2 = g_strconcat (img_src, ".html", NULL); - str_replace (&s1, "", s2); + str_replace (&s1, "", s2, NULL); g_free (s2); } - while (strstr (s1, "") && item->title) - str_replace (&s1, "", item->title); - while (strstr (s1, "") && item->title_description) - str_replace (&s1, "", item->title_description); - while (strstr(s1, "")) { + if (strstr (s1, "") && item->title) { + s2 = g_strdup (item->title); + fix_entities (&s2); + str_replace (&s1, "", s2, NULL); + g_free (s2); + } + if (strstr (s1, "") && item->title_description) { + s2 = g_strdup (item->title_description); + fix_entities (&s2); + str_replace (&s1, "", s2, NULL); + g_free (s2); + } + if (strstr(s1, "")) { s3 = g_strconcat (items->base_dir, "/", item->path, "/index.xml", NULL); - s2 = g_strdup_printf ("%d", get_album_objects_count(s3)); - str_replace (&s1, "", s2); + s2 = g_strdup_printf ("%d", get_album_objects_count(s3)); + str_replace (&s1, "", s2, NULL); g_free (s2); g_free (s3); } - while (strstr (s1, "")) { + if (strstr (s1, "")) { s3 = g_path_get_basename (img_src); s2 = g_strconcat (THUMBNAIL_DIR, "/", s3, NULL); - str_replace (&s1, "", s2); + str_replace (&s1, "", s2, NULL); g_free (s2); g_free (s3); } - while (strstr (s1, "")) - str_replace (&s1, "", img_src); + if (strstr (s1, "")) + str_replace (&s1, "", img_src, NULL); #ifdef __DEBUG_ALL__ @@ -454,7 +482,7 @@ write_html_image (TGallerySetup *setup, TIndexItem *next_item; TAlbum *parent; int i; - char *s1, *s2, *s3; + char *s1, *s2, *s3, *s4; char *imgname; char *b; gboolean res; @@ -541,145 +569,161 @@ write_html_image (TGallerySetup *setup, /* Simple placeholders */ if (strstr (b, "")) - str_replace (&b, "", imgname); - if (strstr (b, "") && item->title) - str_replace (&b, "", item->title); - if (strstr (b, "") && item->title_description) - str_replace (&b, "", item->title_description); + str_replace (&b, "", imgname, NULL); + if (strstr (b, "") && item->title) { + s1 = g_strdup (item->title); + fix_entities (&s1); + str_replace (&b, "", s1, NULL); + g_free (s1); + } + if (strstr (b, "") && item->title_description) { + s1 = g_strdup (item->title_description); + fix_entities (&s1); + str_replace (&b, "", s1, NULL); + g_free (s1); + } if (strstr (b, "")) { s1 = g_strdup_printf ("%d", parent_items->items->len); - str_replace (&b, "", s1); + str_replace (&b, "", s1, NULL); g_free (s1); } if (strstr (b, "")) { s1 = g_strdup_printf ("%d", item_index); - str_replace(&b, "", s1); + str_replace(&b, "", s1, NULL); g_free (s1); } if (strstr (b, "")) { - s1 = g_strconcat (item->title, " (", imgname, ")", NULL); +// s1 = g_strconcat (item->title, " (", imgname, ")", NULL); + s1 = g_strdup (imgname); parent = parent_items; level = 0; while (parent) { s3 = make_string ("../", level); - s2 = g_strconcat ("", parent->ID, " > ", s1, NULL); + s4 = g_strdup (parent->ID); + fix_entities (&s4); + s2 = g_strconcat ("", s4, " > ", s1, NULL); free (s3); g_free (s1); + g_free (s4); s1 = s2; parent = parent->parent_index; level++; } - str_replace (&b, "", s1); + str_replace (&b, "", s1, NULL); g_free (s1); } if (strstr (b, "")) { s1 = g_strconcat (IMG_BIG_DIR, "/", imgname, NULL); - str_replace (&b, "", s1); + str_replace (&b, "", s1, NULL); g_free (s1); } if (strstr(b, "")) { s1 = g_strconcat (IMG_ORIG_DIR, "/", imgname, NULL); - str_replace (&b, "", s1); + str_replace (&b, "", s1, NULL); g_free (s1); } if (strstr(b, "")) { s1 = g_strdup_printf ("%lu", img_big_w); - str_replace (&b, "", s1); + str_replace (&b, "", s1, NULL); g_free (s1); } if (strstr(b, "")) { s1 = g_strdup_printf ("%lu", img_big_h); - str_replace (&b, "", s1); + str_replace (&b, "", s1, NULL); g_free (s1); } if (strstr(b, "")) { s1 = g_strdup_printf ("%lu", img_orig_w); - str_replace (&b, "", s1); + str_replace (&b, "", s1, NULL); g_free (s1); } if (strstr(b, "")) { s1 = g_strdup_printf ("%lu", img_orig_h); - str_replace (&b, "", s1); + str_replace (&b, "", s1, NULL); g_free (s1); } if (strstr (b, "")) { if (exif->iso) - str_replace (&b, "", exif->iso); + str_replace (&b, "", exif->iso, NULL); else - str_replace (&b, "", "??"); + str_replace (&b, "", "??", NULL); } if (strstr (b, "")) { if (exif->exposure) - str_replace (&b, "", exif->exposure); + str_replace (&b, "", exif->exposure, NULL); else - str_replace (&b, "", "??"); + str_replace (&b, "", "??", NULL); } if (strstr (b, "")) { if (exif->aperture) - str_replace (&b, "", exif->aperture); + str_replace (&b, "", exif->aperture, NULL); else - str_replace (&b, "", "??"); + str_replace (&b, "", "??", NULL); } if (strstr (b, "")) { if (exif->focal_length) - str_replace (&b, "", exif->focal_length); + str_replace (&b, "", exif->focal_length, NULL); else - str_replace (&b, "", "??"); + str_replace (&b, "", "??", NULL); } if (strstr (b, "")) { if (exif->flash) - str_replace (&b, "", exif->flash); + str_replace (&b, "", exif->flash, NULL); else - str_replace (&b, "", "??"); + str_replace (&b, "", "??", NULL); } if (strstr (b, "")) { if (exif->datetime) - str_replace (&b, "", exif->datetime); + str_replace (&b, "", exif->datetime, NULL); else - str_replace (&b, "", "??"); + str_replace (&b, "", "??", NULL); } if (strstr (b, "")) { if (exif->camera_model) - str_replace (&b, "", exif->camera_model); + str_replace (&b, "", exif->camera_model, NULL); else - str_replace (&b, "", "??"); + str_replace (&b, "", "??", NULL); } if (strstr (b, "")) { if (exif->focal_length_35mm) { s1 = g_strconcat ("(", exif->focal_length_35mm, ")", NULL); - str_replace (&b, "", s1); + str_replace (&b, "", s1, NULL); g_free (s1); } else - str_replace (&b, "", ""); + str_replace (&b, "", "", NULL); } if (strstr (b, "")) { if (next_item) { s2 = (next_item->path == NULL && next_item->preview) ? g_path_get_basename (next_item->preview) : g_strdup (next_item->path); s1 = g_strconcat (s2, ".html", NULL); - str_replace (&b, "", s1); + str_replace (&b, "", s1, NULL); g_free (s1); g_free (s2); } else - str_replace (&b, "", "index.html"); + str_replace (&b, "", "index.html", NULL); } if (strstr(b, "")) { if (previous_item) { s2 = (previous_item->path == NULL && previous_item->preview) ? g_path_get_basename (previous_item->preview) : g_strdup (previous_item->path); s1 = g_strconcat (s2, ".html", NULL); - str_replace (&b, "", s1); + str_replace (&b, "", s1, NULL); g_free (s1); g_free (s2); } else - str_replace (&b, "", "index.html"); + str_replace (&b, "", "index.html", NULL); } - if (strstr (b, "")) - str_replace (&b, "", setup->footer); + if (strstr (b, "")) { + s1 = g_strdup (setup->footer); + fix_entities (&s1); + str_replace (&b, "", s1, NULL); + g_free (s1); + } if (! fputs (b, fout)) { fprintf (stderr, "write_html_image: error writing to file \"%s\": %s\n", dst, strerror (errno)); -- cgit v1.2.3