summaryrefslogtreecommitdiff
path: root/generators.c
diff options
context:
space:
mode:
authorTomas Bzatek <tbzatek@users.sourceforge.net>2008-08-03 23:29:01 +0200
committerTomas Bzatek <tbzatek@users.sourceforge.net>2008-08-03 23:29:01 +0200
commitee8d3aa3f337cef3faae8d45c6e23ab05f380db8 (patch)
tree3d150c956ccd753c5cc4feeff76d6b8ff7bb8266 /generators.c
parent1e355114311d7bf44b96b11b745857a2b68e8a06 (diff)
downloadcataract-ee8d3aa3f337cef3faae8d45c6e23ab05f380db8.tar.xz
Always generate valid XHTML entities
No need to double-escape entities in source XML files, just use single &amp; etc.
Diffstat (limited to 'generators.c')
-rw-r--r--generators.c186
1 files changed, 115 insertions, 71 deletions
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, "<!-- $(ID) -->") && items->ID)
- str_replace (&b, "<!-- $(ID) -->", items->ID);
- if (strstr (b, "<!-- $(TITLE) -->") && items->title)
- str_replace (&b, "<!-- $(TITLE) -->", items->title);
- if (strstr (b, "<!-- $(DESCRIPTION) -->") && items->desc)
- str_replace (&b, "<!-- $(DESCRIPTION) -->", items->desc);
- if (strstr (b, "<!-- $(FOOTER) -->") && setup->footer)
- str_replace (&b, "<!-- $(FOOTER) -->", setup->footer);
+ if (strstr (b, "<!-- $(ID) -->") && items->ID) {
+ s1 = g_strdup (items->ID);
+ fix_entities (&s1);
+ str_replace (&b, "<!-- $(ID) -->", s1, NULL);
+ g_free (s1);
+ }
+ if (strstr (b, "<!-- $(TITLE) -->") && items->title) {
+ s1 = g_strdup (items->title);
+ fix_entities (&s1);
+ str_replace (&b, "<!-- $(TITLE) -->", s1, NULL);
+ g_free (s1);
+ }
+ if (strstr (b, "<!-- $(DESCRIPTION) -->") && items->desc) {
+ s1 = g_strdup (items->desc);
+ fix_entities (&s1);
+ str_replace (&b, "<!-- $(DESCRIPTION) -->", s1, NULL);
+ g_free (s1);
+ }
+ if (strstr (b, "<!-- $(FOOTER) -->") && setup->footer) {
+ s1 = g_strdup (setup->footer);
+ fix_entities (&s1);
+ str_replace (&b, "<!-- $(FOOTER) -->", s1, NULL);
+ g_free (s1);
+ }
if (strstr (b, "<!-- $(TOTAL_ITEMS) -->")) {
s1 = g_strdup_printf ("%d", items->items->len);
- str_replace (&b, "<!-- $(TOTAL_ITEMS) -->", s1);
+ str_replace (&b, "<!-- $(TOTAL_ITEMS) -->", s1, NULL);
g_free (s1);
}
if (strstr (b, "<!-- $(NAV_BAR) -->")) {
s1 = g_strdup (items->ID);
+ fix_entities (&s1);
parent = items->parent_index;
level = 1;
while (parent) {
- s3 = make_string ("../", level);
- s2 = g_strconcat ("<a href=\"", s3, "index.html\">", parent->ID, "</a> &gt; ", s1, NULL);
+ s3 = make_string ("../", level);
+ s4 = g_strdup (parent->ID);
+ fix_entities (&s4);
+ s2 = g_strconcat ("<a href=\"", s3, "index.html\">", s4, "</a> &gt; ", s1, NULL);
free (s3);
g_free (s1);
+ g_free (s4);
s1 = s2;
parent = parent->parent_index;
level++;
}
- str_replace (&b, "<!-- $(NAV_BAR) -->", s1);
+ str_replace (&b, "<!-- $(NAV_BAR) -->", s1, NULL);
g_free (s1);
}
@@ -353,36 +373,44 @@ write_html_album (TGallerySetup *setup,
else
s1 = strdup (buf_img_list_portrait);
- while (strstr (s1, "<!-- $(ALBUM_SUBPATH) -->")) {
+ if (strstr (s1, "<!-- $(ALBUM_SUBPATH) -->")) {
s2 = g_strconcat (item->path, "/index.html", NULL);
- str_replace (&s1, "<!-- $(ALBUM_SUBPATH) -->", s2);
+ str_replace (&s1, "<!-- $(ALBUM_SUBPATH) -->", s2, NULL);
g_free (s2);
}
- while (strstr (s1, "<!-- $(IMG_SUBPAGE) -->")) {
+ if (strstr (s1, "<!-- $(IMG_SUBPAGE) -->")) {
s2 = g_strconcat (img_src, ".html", NULL);
- str_replace (&s1, "<!-- $(IMG_SUBPAGE) -->", s2);
+ str_replace (&s1, "<!-- $(IMG_SUBPAGE) -->", s2, NULL);
g_free (s2);
}
- while (strstr (s1, "<!-- $(IMG_TITLE) -->") && item->title)
- str_replace (&s1, "<!-- $(IMG_TITLE) -->", item->title);
- while (strstr (s1, "<!-- $(IMG_DESCRIPTION) -->") && item->title_description)
- str_replace (&s1, "<!-- $(IMG_DESCRIPTION) -->", item->title_description);
- while (strstr(s1, "<!-- $(ALBUM_NUM_ITEMS) -->")) {
+ if (strstr (s1, "<!-- $(IMG_TITLE) -->") && item->title) {
+ s2 = g_strdup (item->title);
+ fix_entities (&s2);
+ str_replace (&s1, "<!-- $(IMG_TITLE) -->", s2, NULL);
+ g_free (s2);
+ }
+ if (strstr (s1, "<!-- $(IMG_DESCRIPTION) -->") && item->title_description) {
+ s2 = g_strdup (item->title_description);
+ fix_entities (&s2);
+ str_replace (&s1, "<!-- $(IMG_DESCRIPTION) -->", s2, NULL);
+ g_free (s2);
+ }
+ if (strstr(s1, "<!-- $(ALBUM_NUM_ITEMS) -->")) {
s3 = g_strconcat (items->base_dir, "/", item->path, "/index.xml", NULL);
- s2 = g_strdup_printf ("%d", get_album_objects_count(s3));
- str_replace (&s1, "<!-- $(ALBUM_NUM_ITEMS) -->", s2);
+ s2 = g_strdup_printf ("%d", get_album_objects_count(s3));
+ str_replace (&s1, "<!-- $(ALBUM_NUM_ITEMS) -->", s2, NULL);
g_free (s2);
g_free (s3);
}
- while (strstr (s1, "<!-- $(IMG_THUMBNAIL) -->")) {
+ if (strstr (s1, "<!-- $(IMG_THUMBNAIL) -->")) {
s3 = g_path_get_basename (img_src);
s2 = g_strconcat (THUMBNAIL_DIR, "/", s3, NULL);
- str_replace (&s1, "<!-- $(IMG_THUMBNAIL) -->", s2);
+ str_replace (&s1, "<!-- $(IMG_THUMBNAIL) -->", s2, NULL);
g_free (s2);
g_free (s3);
}
- while (strstr (s1, "<!-- $(IMG_FILENAME) -->"))
- str_replace (&s1, "<!-- $(IMG_FILENAME) -->", img_src);
+ if (strstr (s1, "<!-- $(IMG_FILENAME) -->"))
+ str_replace (&s1, "<!-- $(IMG_FILENAME) -->", 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, "<!-- $(FILE_NAME) -->"))
- str_replace (&b, "<!-- $(FILE_NAME) -->", imgname);
- if (strstr (b, "<!-- $(TITLE) -->") && item->title)
- str_replace (&b, "<!-- $(TITLE) -->", item->title);
- if (strstr (b, "<!-- $(DESCRIPTION) -->") && item->title_description)
- str_replace (&b, "<!-- $(DESCRIPTION) -->", item->title_description);
+ str_replace (&b, "<!-- $(FILE_NAME) -->", imgname, NULL);
+ if (strstr (b, "<!-- $(TITLE) -->") && item->title) {
+ s1 = g_strdup (item->title);
+ fix_entities (&s1);
+ str_replace (&b, "<!-- $(TITLE) -->", s1, NULL);
+ g_free (s1);
+ }
+ if (strstr (b, "<!-- $(DESCRIPTION) -->") && item->title_description) {
+ s1 = g_strdup (item->title_description);
+ fix_entities (&s1);
+ str_replace (&b, "<!-- $(DESCRIPTION) -->", s1, NULL);
+ g_free (s1);
+ }
if (strstr (b, "<!-- $(TOTAL_ITEMS) -->")) {
s1 = g_strdup_printf ("%d", parent_items->items->len);
- str_replace (&b, "<!-- $(TOTAL_ITEMS) -->", s1);
+ str_replace (&b, "<!-- $(TOTAL_ITEMS) -->", s1, NULL);
g_free (s1);
}
if (strstr (b, "<!-- $(FILE_NO) -->")) {
s1 = g_strdup_printf ("%d", item_index);
- str_replace(&b, "<!-- $(FILE_NO) -->", s1);
+ str_replace(&b, "<!-- $(FILE_NO) -->", s1, NULL);
g_free (s1);
}
if (strstr (b, "<!-- $(NAV_BAR) -->")) {
- 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 ("<a href=\"", s3, "index.html\">", parent->ID, "</a> &gt; ", s1, NULL);
+ s4 = g_strdup (parent->ID);
+ fix_entities (&s4);
+ s2 = g_strconcat ("<a href=\"", s3, "index.html\">", s4, "</a> &gt; ", s1, NULL);
free (s3);
g_free (s1);
+ g_free (s4);
s1 = s2;
parent = parent->parent_index;
level++;
}
- str_replace (&b, "<!-- $(NAV_BAR) -->", s1);
+ str_replace (&b, "<!-- $(NAV_BAR) -->", s1, NULL);
g_free (s1);
}
if (strstr (b, "<!-- $(IMG_SRC_BIG) -->")) {
s1 = g_strconcat (IMG_BIG_DIR, "/", imgname, NULL);
- str_replace (&b, "<!-- $(IMG_SRC_BIG) -->", s1);
+ str_replace (&b, "<!-- $(IMG_SRC_BIG) -->", s1, NULL);
g_free (s1);
}
if (strstr(b, "<!-- $(IMG_SRC_FULL) -->")) {
s1 = g_strconcat (IMG_ORIG_DIR, "/", imgname, NULL);
- str_replace (&b, "<!-- $(IMG_SRC_FULL) -->", s1);
+ str_replace (&b, "<!-- $(IMG_SRC_FULL) -->", s1, NULL);
g_free (s1);
}
if (strstr(b, "<!-- $(IMG_SIZE_BIG_W) -->")) {
s1 = g_strdup_printf ("%lu", img_big_w);
- str_replace (&b, "<!-- $(IMG_SIZE_BIG_W) -->", s1);
+ str_replace (&b, "<!-- $(IMG_SIZE_BIG_W) -->", s1, NULL);
g_free (s1);
}
if (strstr(b, "<!-- $(IMG_SIZE_BIG_H) -->")) {
s1 = g_strdup_printf ("%lu", img_big_h);
- str_replace (&b, "<!-- $(IMG_SIZE_BIG_H) -->", s1);
+ str_replace (&b, "<!-- $(IMG_SIZE_BIG_H) -->", s1, NULL);
g_free (s1);
}
if (strstr(b, "<!-- $(IMG_SIZE_ORIG_W) -->")) {
s1 = g_strdup_printf ("%lu", img_orig_w);
- str_replace (&b, "<!-- $(IMG_SIZE_ORIG_W) -->", s1);
+ str_replace (&b, "<!-- $(IMG_SIZE_ORIG_W) -->", s1, NULL);
g_free (s1);
}
if (strstr(b, "<!-- $(IMG_SIZE_ORIG_H) -->")) {
s1 = g_strdup_printf ("%lu", img_orig_h);
- str_replace (&b, "<!-- $(IMG_SIZE_ORIG_H) -->", s1);
+ str_replace (&b, "<!-- $(IMG_SIZE_ORIG_H) -->", s1, NULL);
g_free (s1);
}
if (strstr (b, "<!-- $(EXIF_ISO) -->")) {
if (exif->iso)
- str_replace (&b, "<!-- $(EXIF_ISO) -->", exif->iso);
+ str_replace (&b, "<!-- $(EXIF_ISO) -->", exif->iso, NULL);
else
- str_replace (&b, "<!-- $(EXIF_ISO) -->", "??");
+ str_replace (&b, "<!-- $(EXIF_ISO) -->", "??", NULL);
}
if (strstr (b, "<!-- $(EXIF_TIME) -->")) {
if (exif->exposure)
- str_replace (&b, "<!-- $(EXIF_TIME) -->", exif->exposure);
+ str_replace (&b, "<!-- $(EXIF_TIME) -->", exif->exposure, NULL);
else
- str_replace (&b, "<!-- $(EXIF_TIME) -->", "??");
+ str_replace (&b, "<!-- $(EXIF_TIME) -->", "??", NULL);
}
if (strstr (b, "<!-- $(EXIF_APERTURE) -->")) {
if (exif->aperture)
- str_replace (&b, "<!-- $(EXIF_APERTURE) -->", exif->aperture);
+ str_replace (&b, "<!-- $(EXIF_APERTURE) -->", exif->aperture, NULL);
else
- str_replace (&b, "<!-- $(EXIF_APERTURE) -->", "??");
+ str_replace (&b, "<!-- $(EXIF_APERTURE) -->", "??", NULL);
}
if (strstr (b, "<!-- $(EXIF_FOCAL_LENGTH) -->")) {
if (exif->focal_length)
- str_replace (&b, "<!-- $(EXIF_FOCAL_LENGTH) -->", exif->focal_length);
+ str_replace (&b, "<!-- $(EXIF_FOCAL_LENGTH) -->", exif->focal_length, NULL);
else
- str_replace (&b, "<!-- $(EXIF_FOCAL_LENGTH) -->", "??");
+ str_replace (&b, "<!-- $(EXIF_FOCAL_LENGTH) -->", "??", NULL);
}
if (strstr (b, "<!-- $(EXIF_FLASH) -->")) {
if (exif->flash)
- str_replace (&b, "<!-- $(EXIF_FLASH) -->", exif->flash);
+ str_replace (&b, "<!-- $(EXIF_FLASH) -->", exif->flash, NULL);
else
- str_replace (&b, "<!-- $(EXIF_FLASH) -->", "??");
+ str_replace (&b, "<!-- $(EXIF_FLASH) -->", "??", NULL);
}
if (strstr (b, "<!-- $(EXIF_DATE) -->")) {
if (exif->datetime)
- str_replace (&b, "<!-- $(EXIF_DATE) -->", exif->datetime);
+ str_replace (&b, "<!-- $(EXIF_DATE) -->", exif->datetime, NULL);
else
- str_replace (&b, "<!-- $(EXIF_DATE) -->", "??");
+ str_replace (&b, "<!-- $(EXIF_DATE) -->", "??", NULL);
}
if (strstr (b, "<!-- $(EXIF_CAMERA_MODEL) -->")) {
if (exif->camera_model)
- str_replace (&b, "<!-- $(EXIF_CAMERA_MODEL) -->", exif->camera_model);
+ str_replace (&b, "<!-- $(EXIF_CAMERA_MODEL) -->", exif->camera_model, NULL);
else
- str_replace (&b, "<!-- $(EXIF_CAMERA_MODEL) -->", "??");
+ str_replace (&b, "<!-- $(EXIF_CAMERA_MODEL) -->", "??", NULL);
}
if (strstr (b, "<!-- $(EXIF_FOCAL_35) -->")) {
if (exif->focal_length_35mm) {
s1 = g_strconcat ("(", exif->focal_length_35mm, ")", NULL);
- str_replace (&b, "<!-- $(EXIF_FOCAL_35) -->", s1);
+ str_replace (&b, "<!-- $(EXIF_FOCAL_35) -->", s1, NULL);
g_free (s1);
}
else
- str_replace (&b, "<!-- $(EXIF_FOCAL_35) -->", "");
+ str_replace (&b, "<!-- $(EXIF_FOCAL_35) -->", "", NULL);
}
if (strstr (b, "<!-- $(LINK_NEXT) -->")) {
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, "<!-- $(LINK_NEXT) -->", s1);
+ str_replace (&b, "<!-- $(LINK_NEXT) -->", s1, NULL);
g_free (s1);
g_free (s2);
}
else
- str_replace (&b, "<!-- $(LINK_NEXT) -->", "index.html");
+ str_replace (&b, "<!-- $(LINK_NEXT) -->", "index.html", NULL);
}
if (strstr(b, "<!-- $(LINK_PREV) -->")) {
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, "<!-- $(LINK_PREV) -->", s1);
+ str_replace (&b, "<!-- $(LINK_PREV) -->", s1, NULL);
g_free (s1);
g_free (s2);
}
else
- str_replace (&b, "<!-- $(LINK_PREV) -->", "index.html");
+ str_replace (&b, "<!-- $(LINK_PREV) -->", "index.html", NULL);
}
- if (strstr (b, "<!-- $(FOOTER) -->"))
- str_replace (&b, "<!-- $(FOOTER) -->", setup->footer);
+ if (strstr (b, "<!-- $(FOOTER) -->")) {
+ s1 = g_strdup (setup->footer);
+ fix_entities (&s1);
+ str_replace (&b, "<!-- $(FOOTER) -->", s1, NULL);
+ g_free (s1);
+ }
if (! fputs (b, fout)) {
fprintf (stderr, "write_html_image: error writing to file \"%s\": %s\n", dst, strerror (errno));