diff options
| author | Tomas Bzatek <tbzatek@users.sourceforge.net> | 2008-08-10 14:30:23 +0200 |
|---|---|---|
| committer | Tomas Bzatek <tbzatek@users.sourceforge.net> | 2008-08-10 14:30:23 +0200 |
| commit | 3462576fd6bc883c41042fb7ae93ebabb12718d8 (patch) | |
| tree | 3a6e85717d93b375c5b46674894f4b44d2c961b3 /generators.c | |
| parent | ee8d3aa3f337cef3faae8d45c6e23ab05f380db8 (diff) | |
| download | cataract-3462576fd6bc883c41042fb7ae93ebabb12718d8.tar.xz | |
Support for different preview image borders
Strip trailing whitespaces
Diffstat (limited to 'generators.c')
| -rw-r--r-- | generators.c | 378 |
1 files changed, 194 insertions, 184 deletions
diff --git a/generators.c b/generators.c index 18fa25f..210bdb0 100644 --- a/generators.c +++ b/generators.c @@ -1,16 +1,16 @@ /* Cataract - Static web photo gallery generator * Copyright (C) 2008 Tomas Bzatek <tbzatek@users.sourceforge.net> - * + * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -46,27 +46,27 @@ generate_image (TGallerySetup *setup, char *thumb_dst; char *big_dst; char *big_src; - char *orig_dst; + char *orig_dst; char *img_src_full; char *s1, *s2; int bigq; - - *img_src = item->thumbnail; - if (items->type == GALLERY_TYPE_INDEX) + + *img_src = item->thumbnail; + if (items->type == GALLERY_TYPE_INDEX) *img_src = item->thumbnail; - else + else if (items->type == GALLERY_TYPE_ALBUM) *img_src = (item->path == NULL && item->preview) ? item->preview : item->path; - + img_src_full = g_strconcat (items->base_dir, "/", *img_src, NULL); get_image_sizes (img_src_full, img_w, img_h); if ((img_w > 0) && (img_h > 0)) { new_w = *img_w; new_h = *img_h; - - + + /* Generate thumbnail */ s1 = g_path_get_dirname (dst); s2 = g_path_get_basename (*img_src); @@ -75,19 +75,19 @@ generate_image (TGallerySetup *setup, g_free (s2); if (setup->verbose) printf (" Generating thumbnail of '%s' ...", *img_src); - if ((*img_w / *img_h) >= 1) + if ((*img_w / *img_h) >= 1) calculate_sizes (setup->thumbnail_landscape_width, setup->thumbnail_landscape_height, &new_w, &new_h); - else + else calculate_sizes (setup->thumbnail_portrait_width, setup->thumbnail_portrait_height, &new_w, &new_h); if (! resize_image (img_src_full, thumb_dst, new_w, new_h, setup->thumbnail_quality)) fprintf (stderr, "write_html_index: error resizing thumbnail %s\n", img_src_full); - else + else if (setup->verbose) printf (" done.\n"); g_free (thumb_dst); - + /* Generate/copy preview and original image */ - if (items->type == GALLERY_TYPE_ALBUM) + if (items->type == GALLERY_TYPE_ALBUM) { s1 = g_path_get_dirname (dst); s2 = g_path_get_basename (*img_src); @@ -96,11 +96,11 @@ generate_image (TGallerySetup *setup, g_free (s2); if (item->preview == NULL) { - /* No preview image supplied, generate it from original */ + /* No preview image supplied, generate it from original */ bigq = setup->preview_quality; - if ((items->quality > 0) && (items->quality <= 100)) + if ((items->quality > 0) && (items->quality <= 100)) bigq = items->quality; - if ((item->quality > 0) && (item->quality <= 100)) + if ((item->quality > 0) && (item->quality <= 100)) bigq = item->quality; new_w = *img_w; new_h = *img_h; @@ -108,7 +108,7 @@ generate_image (TGallerySetup *setup, if (setup->verbose) printf (" Generating preview of '%s' ...", *img_src); if ((item->width > 0) && (item->height > 0)) { calculate_sizes (item->width, item->height, &new_w, &new_h); - } else { + } else { if ((*img_w / *img_h) >= 1) { if ((items->landscape_width > 0) && (items->landscape_height > 0)) @@ -124,10 +124,10 @@ generate_image (TGallerySetup *setup, calculate_sizes (setup->preview_portrait_width, setup->preview_portrait_height, &new_w, &new_h); } } - + if (! resize_image (img_src_full, big_dst, new_w, new_h, bigq)) fprintf (stderr, "write_html_index: error resizing big image %s\n", img_src_full); - else + else if (setup->verbose) printf (" done.\n"); } else @@ -137,13 +137,13 @@ generate_image (TGallerySetup *setup, if (setup->verbose) printf (" Copying preview image '%s' ...", *img_src); if (! copy_file (big_src, big_dst)) fprintf (stderr, "write_html_index: error copying preview image %s\n", big_src); - else + else if (setup->verbose) printf (" done.\n"); g_free (big_src); } g_free (big_dst); - if (! item->nofullsize) + if (! item->nofullsize) { s1 = g_path_get_dirname(dst); orig_dst = g_strconcat (s1, "/", IMG_ORIG_DIR, "/", *img_src, NULL); @@ -155,22 +155,22 @@ generate_image (TGallerySetup *setup, if (setup->verbose) printf(" done.\n"); g_free (orig_dst); } - } + } } - g_free (img_src_full); + g_free (img_src_full); } /* * write_html_album: process album and index template files - * + * * template_src = template file of the album/index * dst = save generated file as * items = array of items in the album/index * - */ -gboolean + */ +gboolean write_html_album (TGallerySetup *setup, const char *template_src, const char *dst, @@ -180,12 +180,12 @@ write_html_album (TGallerySetup *setup, FILE *fin; FILE *fout; char *buffer; - char *buf_img_list_landscape; + char *buf_img_list_landscape; char *buf_img_list_portrait; char *buf_go_up_string; - gboolean in_img_list; - gboolean in_img_list_landscape; - gboolean in_img_list_portrait; + gboolean in_img_list; + gboolean in_img_list_landscape; + gboolean in_img_list_portrait; gboolean in_go_up_string; char *b; char *s1, *s2, *s3, *s4; @@ -196,32 +196,32 @@ write_html_album (TGallerySetup *setup, int i; unsigned long img_w, img_h; const char *img_src; - - + + fin = fopen (template_src, "r"); if (fin == NULL) { fprintf (stderr, "write_html_index: error reading file \"%s\": %s\n", template_src, strerror (errno)); - return FALSE; + return FALSE; } fout = fopen (dst, "w"); if (fout == NULL) { fprintf (stderr, "write_html_index: error writing to file \"%s\": %s\n", dst, strerror (errno)); fclose (fin); - return FALSE; + return FALSE; } - + buffer = malloc (BUFFER_SIZE); - buf_img_list_landscape = malloc (BUFFER_SIZE); + buf_img_list_landscape = malloc (BUFFER_SIZE); buf_img_list_portrait = malloc (BUFFER_SIZE); buf_go_up_string = malloc (BUFFER_SIZE); - in_img_list = FALSE; - in_img_list_landscape = FALSE; - in_img_list_portrait = FALSE; + in_img_list = FALSE; + in_img_list_landscape = FALSE; + in_img_list_portrait = FALSE; in_go_up_string = FALSE; res = TRUE; - + /* Read through the template and replace placeholders with real data */ - while (! feof (fin)) + while (! feof (fin)) { memset (buffer, 0, BUFFER_SIZE); if (! fgets (buffer, BUFFER_SIZE, fin)) @@ -229,28 +229,28 @@ write_html_album (TGallerySetup *setup, if (buffer == NULL) continue; b = strdup (buffer); - - + + /* Block placeholders */ if (in_img_list && (strstr (buffer, "<!-- $(BEGIN_IMG_LIST_LANDSCAPE) -->"))) { in_img_list_landscape = TRUE; free (b); - continue; + continue; } if (in_img_list && (strstr (buffer, "<!-- $(END_IMG_LIST_LANDSCAPE) -->"))) { in_img_list_landscape = FALSE; free (b); - continue; + continue; } if (in_img_list && (strstr (buffer, "<!-- $(BEGIN_IMG_LIST_PORTRAIT) -->"))) { in_img_list_portrait = TRUE; free (b); - continue; + continue; } if (in_img_list && (strstr (buffer, "<!-- $(END_IMG_LIST_PORTRAIT) -->"))) { in_img_list_portrait = FALSE; free (b); - continue; + continue; } if (in_img_list && in_img_list_landscape) { buf_img_list_landscape = strncat (buf_img_list_landscape, b, BUFFER_SIZE - strlen (buf_img_list_landscape) - 2); @@ -272,7 +272,7 @@ write_html_album (TGallerySetup *setup, if (in_go_up_string && (strstr (buffer, "<!-- $(END_GO_UP) -->"))) { in_go_up_string = FALSE; free (b); - /* print the "Go Up" string if not toplevel */ + /* print the "Go Up" string if not toplevel */ if (items->parent_index) b = strdup (buf_go_up_string); else continue; @@ -283,8 +283,8 @@ write_html_album (TGallerySetup *setup, continue; } - - /* Simple placeholders */ + + /* Simple placeholders */ if (strstr (b, "<!-- $(ID) -->") && items->ID) { s1 = g_strdup (items->ID); fix_entities (&s1); @@ -310,10 +310,10 @@ write_html_album (TGallerySetup *setup, g_free (s1); } if (strstr (b, "<!-- $(TOTAL_ITEMS) -->")) { - s1 = g_strdup_printf ("%d", items->items->len); + s1 = g_strdup_printf ("%d", items->items->len); str_replace (&b, "<!-- $(TOTAL_ITEMS) -->", s1, NULL); g_free (s1); - } + } if (strstr (b, "<!-- $(NAV_BAR) -->")) { s1 = g_strdup (items->ID); fix_entities (&s1); @@ -329,11 +329,11 @@ write_html_album (TGallerySetup *setup, g_free (s4); s1 = s2; parent = parent->parent_index; - level++; + level++; } str_replace (&b, "<!-- $(NAV_BAR) -->", s1, NULL); g_free (s1); - } + } /* Image list, nested placeholders */ if (strstr (buffer, "<!-- $(BEGIN_IMG_LIST) -->")) { @@ -350,15 +350,15 @@ write_html_album (TGallerySetup *setup, in_img_list = FALSE; in_img_list_landscape = FALSE; in_img_list_portrait = FALSE; - + /* Now we have all block placeholders read, generate the items: */ - for (i = 0; i < items->items->len; i++) + for (i = 0; i < items->items->len; i++) { item = g_ptr_array_index (items->items, i); if (item == NULL) { - fprintf (stderr, "write_html_index: error getting item %d\n", i); + fprintf (stderr, "write_html_index: error getting item %d\n", i); free (b); - continue; + continue; } /* Generate the images (preview, original, thumbnail) */ @@ -368,11 +368,11 @@ write_html_album (TGallerySetup *setup, generate_image (setup, items, item, dst, &img_w, &img_h, &img_src); /* Process HTML box code */ - if ((img_w / img_h) >= 1) + if ((img_w / img_h) >= 1) s1 = strdup (buf_img_list_landscape); - else + else s1 = strdup (buf_img_list_portrait); - + if (strstr (s1, "<!-- $(ALBUM_SUBPATH) -->")) { s2 = g_strconcat (item->path, "/index.html", NULL); str_replace (&s1, "<!-- $(ALBUM_SUBPATH) -->", s2, NULL); @@ -401,10 +401,10 @@ write_html_album (TGallerySetup *setup, str_replace (&s1, "<!-- $(ALBUM_NUM_ITEMS) -->", s2, NULL); g_free (s2); g_free (s3); - } + } if (strstr (s1, "<!-- $(IMG_THUMBNAIL) -->")) { s3 = g_path_get_basename (img_src); - s2 = g_strconcat (THUMBNAIL_DIR, "/", s3, NULL); + s2 = g_strconcat (THUMBNAIL_DIR, "/", s3, NULL); str_replace (&s1, "<!-- $(IMG_THUMBNAIL) -->", s2, NULL); g_free (s2); g_free (s3); @@ -412,10 +412,10 @@ write_html_album (TGallerySetup *setup, if (strstr (s1, "<!-- $(IMG_FILENAME) -->")) str_replace (&s1, "<!-- $(IMG_FILENAME) -->", img_src, NULL); - + #ifdef __DEBUG_ALL__ printf("***** %s ******\n", s1); - #endif + #endif if (! fputs (s1, fout)) { fprintf (stderr, "write_html_index: error writing to file \"%s\": %s\n", dst, strerror (errno)); res = FALSE; @@ -437,34 +437,34 @@ write_html_album (TGallerySetup *setup, } free (b); } - + fclose (fout); fclose (fin); free (buffer); - free (buf_img_list_landscape); + free (buf_img_list_landscape); free (buf_img_list_portrait); free (buf_go_up_string); - return res; + return res; } /* * write_html_image: process single image template file - * + * * template_src = template file of the album/index * original_img = source image file (original full-size) to get EXIF data from * dst = save generated file as * item = data for the current item * parent_items = array of items in the album, to determine our position and make links to previous/next image - * - */ -gboolean -write_html_image (TGallerySetup *setup, - const char *template_src, - const char *original_img, - const char *dst, - TIndexItem *item, + * + */ +gboolean +write_html_image (TGallerySetup *setup, + const char *template_src, + const char *original_img, + const char *dst, + TIndexItem *item, TAlbum *parent_items) { #define BUFFER_SIZE 65536 @@ -487,41 +487,41 @@ write_html_image (TGallerySetup *setup, char *b; gboolean res; int level; - - + + fin = fopen (template_src, "r"); if (fin == NULL) { fprintf (stderr, "write_html_image: error reading file \"%s\": %s\n", template_src, strerror (errno)); - return FALSE; + return FALSE; } fout = fopen (dst, "w"); if (fout == NULL) { fprintf (stderr, "write_html_image: error writing to file \"%s\": %s\n", dst, strerror (errno)); fclose (fin); - return FALSE; + return FALSE; } - + buffer = malloc (BUFFER_SIZE); s1 = g_path_get_dirname (dst); imgname = (item->path == NULL && item->preview) ? g_path_get_basename (item->preview) : g_strdup (item->path); big_dst = g_strconcat (s1, "/", IMG_BIG_DIR, "/", imgname, NULL); orig_dst = g_strconcat (s1, "/", IMG_ORIG_DIR, "/", imgname, NULL); g_free (s1); - buf_img_fullsize_link = malloc (BUFFER_SIZE); + buf_img_fullsize_link = malloc (BUFFER_SIZE); memset (buf_img_fullsize_link, 0, BUFFER_SIZE); in_img_fullsize_link = FALSE; res = TRUE; - + /* Get EXIF data from the original image */ if (get_exif (original_img, &exif)) fprintf (stderr, "write_html_image: error getting exif data from file \"%s\"\n", orig_dst); /* Retrieve image sizes of preview and original image */ get_image_sizes (big_dst, &img_big_w, &img_big_h); - if (! item->nofullsize) + if (! item->nofullsize) get_image_sizes (orig_dst, &img_orig_w, &img_orig_h); - + /* Get our index in the album */ item_index = 0; for (i = 0; i < parent_items->items->len; i++) @@ -529,45 +529,45 @@ write_html_image (TGallerySetup *setup, item_index = i + 1; break; } - + /* Get previous and next items */ previous_item = NULL; next_item = NULL; - if (item_index > 1) - previous_item = g_ptr_array_index (parent_items->items, item_index - 2); - if (item_index < parent_items->items->len) + if (item_index > 1) + previous_item = g_ptr_array_index (parent_items->items, item_index - 2); + if (item_index < parent_items->items->len) next_item = g_ptr_array_index (parent_items->items, item_index); - + /* Read through the template and replace placeholders with real data */ while (! feof (fin)) { - memset (buffer, 0, BUFFER_SIZE); - if (! fgets (buffer, BUFFER_SIZE, fin)) + memset (buffer, 0, BUFFER_SIZE); + if (! fgets (buffer, BUFFER_SIZE, fin)) break; b = strdup (buffer); - + /* Block placeholders */ if (strstr (buffer, "<!-- $(BEGIN_IMG_FULLSIZE_LINK) -->")) { in_img_fullsize_link = TRUE; free (b); - continue; + continue; } if (strstr (buffer, "<!-- $(END_IMG_FULLSIZE_LINK) -->")) { in_img_fullsize_link = FALSE; free (b); if (! item->nofullsize) b = strdup (buf_img_fullsize_link); - else continue; + else continue; } if (in_img_fullsize_link) { buf_img_fullsize_link = strncat (buf_img_fullsize_link, b, BUFFER_SIZE - strlen (buf_img_fullsize_link) - 2); free (b); - continue; + continue; } - - /* Simple placeholders */ + + /* Simple placeholders */ if (strstr (b, "<!-- $(FILE_NAME) -->")) str_replace (&b, "<!-- $(FILE_NAME) -->", imgname, NULL); if (strstr (b, "<!-- $(TITLE) -->") && item->title) { @@ -583,15 +583,15 @@ write_html_image (TGallerySetup *setup, g_free (s1); } if (strstr (b, "<!-- $(TOTAL_ITEMS) -->")) { - s1 = g_strdup_printf ("%d", parent_items->items->len); + s1 = g_strdup_printf ("%d", parent_items->items->len); str_replace (&b, "<!-- $(TOTAL_ITEMS) -->", s1, NULL); g_free (s1); - } + } if (strstr (b, "<!-- $(FILE_NO) -->")) { - s1 = g_strdup_printf ("%d", item_index); + s1 = g_strdup_printf ("%d", item_index); str_replace(&b, "<!-- $(FILE_NO) -->", s1, NULL); g_free (s1); - } + } if (strstr (b, "<!-- $(NAV_BAR) -->")) { // s1 = g_strconcat (item->title, " (", imgname, ")", NULL); s1 = g_strdup (imgname); @@ -607,82 +607,92 @@ write_html_image (TGallerySetup *setup, g_free (s4); s1 = s2; parent = parent->parent_index; - level++; + level++; } 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, NULL); g_free (s1); } - if (strstr(b, "<!-- $(IMG_SRC_FULL) -->")) { + if (strstr (b, "<!-- $(IMG_SRC_FULL) -->")) { s1 = g_strconcat (IMG_ORIG_DIR, "/", imgname, NULL); 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); + if (strstr (b, "<!-- $(IMG_SIZE_BIG_W) -->")) { + s1 = g_strdup_printf ("%lu", img_big_w); 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); + if (strstr (b, "<!-- $(IMG_SIZE_BIG_H) -->")) { + s1 = g_strdup_printf ("%lu", img_big_h); 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); + if (strstr (b, "<!-- $(IMG_SIZE_ORIG_W) -->")) { + s1 = g_strdup_printf ("%lu", img_orig_w); 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); + if (strstr (b, "<!-- $(IMG_SIZE_ORIG_H) -->")) { + s1 = g_strdup_printf ("%lu", img_orig_h); str_replace (&b, "<!-- $(IMG_SIZE_ORIG_H) -->", s1, NULL); g_free (s1); } + if (strstr (b, "<!-- $(IMG_BORDER_STYLE) -->")) { + s1 = item->border_style; + if (s1 == NULL) + s1 = parent_items->border_style; + if (s1 == NULL) + s1 = setup->border_style; + if (s1 == NULL) + s1 = "border_single"; + str_replace (&b, "<!-- $(IMG_BORDER_STYLE) -->", s1, NULL); + } if (strstr (b, "<!-- $(EXIF_ISO) -->")) { - if (exif->iso) + if (exif->iso) str_replace (&b, "<!-- $(EXIF_ISO) -->", exif->iso, NULL); - else + else str_replace (&b, "<!-- $(EXIF_ISO) -->", "??", NULL); - } + } if (strstr (b, "<!-- $(EXIF_TIME) -->")) { - if (exif->exposure) + if (exif->exposure) str_replace (&b, "<!-- $(EXIF_TIME) -->", exif->exposure, NULL); - else + else str_replace (&b, "<!-- $(EXIF_TIME) -->", "??", NULL); } if (strstr (b, "<!-- $(EXIF_APERTURE) -->")) { - if (exif->aperture) + if (exif->aperture) str_replace (&b, "<!-- $(EXIF_APERTURE) -->", exif->aperture, NULL); - else + else str_replace (&b, "<!-- $(EXIF_APERTURE) -->", "??", NULL); } if (strstr (b, "<!-- $(EXIF_FOCAL_LENGTH) -->")) { - if (exif->focal_length) + if (exif->focal_length) str_replace (&b, "<!-- $(EXIF_FOCAL_LENGTH) -->", exif->focal_length, NULL); - else + else str_replace (&b, "<!-- $(EXIF_FOCAL_LENGTH) -->", "??", NULL); } if (strstr (b, "<!-- $(EXIF_FLASH) -->")) { - if (exif->flash) + if (exif->flash) str_replace (&b, "<!-- $(EXIF_FLASH) -->", exif->flash, NULL); - else + else str_replace (&b, "<!-- $(EXIF_FLASH) -->", "??", NULL); } if (strstr (b, "<!-- $(EXIF_DATE) -->")) { - if (exif->datetime) + if (exif->datetime) str_replace (&b, "<!-- $(EXIF_DATE) -->", exif->datetime, NULL); - else + else str_replace (&b, "<!-- $(EXIF_DATE) -->", "??", NULL); } if (strstr (b, "<!-- $(EXIF_CAMERA_MODEL) -->")) { - if (exif->camera_model) + if (exif->camera_model) str_replace (&b, "<!-- $(EXIF_CAMERA_MODEL) -->", exif->camera_model, NULL); - else + else str_replace (&b, "<!-- $(EXIF_CAMERA_MODEL) -->", "??", NULL); } if (strstr (b, "<!-- $(EXIF_FOCAL_35) -->")) { @@ -691,7 +701,7 @@ write_html_image (TGallerySetup *setup, str_replace (&b, "<!-- $(EXIF_FOCAL_35) -->", s1, NULL); g_free (s1); } - else + else str_replace (&b, "<!-- $(EXIF_FOCAL_35) -->", "", NULL); } @@ -703,9 +713,9 @@ write_html_image (TGallerySetup *setup, g_free (s1); g_free (s2); } - else + else 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); @@ -714,9 +724,9 @@ write_html_image (TGallerySetup *setup, g_free (s1); g_free (s2); } - else + else str_replace (&b, "<!-- $(LINK_PREV) -->", "index.html", NULL); - } + } if (strstr (b, "<!-- $(FOOTER) -->")) { s1 = g_strdup (setup->footer); @@ -733,8 +743,8 @@ write_html_image (TGallerySetup *setup, } free (b); } - - fclose (fout); + + fclose (fout); fclose (fin); free (buffer); free (big_dst); @@ -748,16 +758,16 @@ write_html_image (TGallerySetup *setup, /* * build_tree: generate complete gallery tree based on source xml files - * + * * src_tree = source directory of the items * dst_dir = destination of the generated items - * parent_index = parent album to determine our descent in the tree - * - */ -gboolean -build_tree (TGallerySetup *setup, - const char *src_tree, - const char *dst_dir, + * parent_index = parent album to determine our descent in the tree + * + */ +gboolean +build_tree (TGallerySetup *setup, + const char *src_tree, + const char *dst_dir, TAlbum *parent_index) { char *idx_file; @@ -771,13 +781,13 @@ build_tree (TGallerySetup *setup, char *imgname; gboolean res; int i; - - printf ("*** Entering directory '%s'\n", src_tree); + + printf ("*** Entering directory '%s'\n", src_tree); #ifdef __DEBUG_ALL__ printf ("setup->real_templates_dir = %s\n", setup->real_templates_dir); #endif - /* Check access permissions */ + /* Check access permissions */ if (access (src_tree, R_OK | X_OK)) { fprintf (stderr, "error accessing source directory: %s\n", strerror (errno)); return FALSE; @@ -787,7 +797,7 @@ build_tree (TGallerySetup *setup, fprintf (stderr, "error creating destination directory: %s\n", strerror (errno)); return FALSE; } - } + } /* Check the index file */ idx_file = g_strconcat (src_tree, "/index.xml", NULL); @@ -796,7 +806,7 @@ build_tree (TGallerySetup *setup, g_free (idx_file); return FALSE; } - + /* Read the index file and fill items array */ items = malloc (sizeof (TAlbum)); if (! parse_album_xml (idx_file, items)) { @@ -808,7 +818,7 @@ build_tree (TGallerySetup *setup, g_free (idx_file); items->parent_index = parent_index; - + /* Copy support files */ if (setup->verbose) printf ("Writing '%s' ...", setup->styles); s1 = g_strconcat (setup->real_templates_dir, "/", setup->styles, NULL); @@ -817,33 +827,33 @@ build_tree (TGallerySetup *setup, g_free (s1); g_free (s2); if (setup->verbose) printf (" done.\n"); - + if (setup->verbose) printf ("Writing '%s' ...", setup->scripts); s1 = g_strconcat (setup->real_templates_dir, "/", setup->scripts, NULL); - s2 = g_strconcat (dst_dir, "/", setup->scripts, NULL); + s2 = g_strconcat (dst_dir, "/", setup->scripts, NULL); copy_file (s1, s2); g_free (s1); g_free (s2); - if (setup->verbose) printf (" done.\n"); + if (setup->verbose) printf (" done.\n"); + - /* Prepare target thumbnail directory */ - thumb_dir = g_strconcat (dst_dir, "/", THUMBNAIL_DIR, NULL); + thumb_dir = g_strconcat (dst_dir, "/", THUMBNAIL_DIR, NULL); if (access (thumb_dir, R_OK | W_OK | X_OK)) if (mkdir (thumb_dir, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) { fprintf (stderr, "error making target thumbnail directory: %s\n", strerror (errno)); g_free (thumb_dir); free_album_data (items); - return FALSE; + return FALSE; } g_free (thumb_dir); - + /* Prepare target preview and orig directories */ - if (items->type == GALLERY_TYPE_ALBUM) + if (items->type == GALLERY_TYPE_ALBUM) { - res = TRUE; - img_big_dir = g_strconcat (dst_dir, "/", IMG_BIG_DIR, NULL); - img_orig_dir = g_strconcat (dst_dir, "/", IMG_ORIG_DIR, NULL); + res = TRUE; + img_big_dir = g_strconcat (dst_dir, "/", IMG_BIG_DIR, NULL); + img_orig_dir = g_strconcat (dst_dir, "/", IMG_ORIG_DIR, NULL); if (access (img_big_dir, R_OK | W_OK | X_OK)) if (mkdir (img_big_dir, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) { fprintf (stderr, "error making target preview directory: %s\n", strerror (errno)); @@ -862,18 +872,18 @@ build_tree (TGallerySetup *setup, } } - + /* Start generating items */ - if (items->type == GALLERY_TYPE_INDEX) + if (items->type == GALLERY_TYPE_INDEX) template = g_strconcat ("/", setup->template_index, NULL); - else - if (items->type == GALLERY_TYPE_ALBUM) + else + if (items->type == GALLERY_TYPE_ALBUM) template = g_strconcat ("/", setup->template_album, NULL); if (setup->verbose) printf ("Writing 'index.html' ...\n"); s1 = g_strconcat (setup->real_templates_dir, template, NULL); s2 = g_strconcat (dst_dir, "/index.html", NULL); - res = write_html_album (setup, s1, s2, items); + res = write_html_album (setup, s1, s2, items); g_free (s1); g_free (s2); g_free (template); @@ -884,16 +894,16 @@ build_tree (TGallerySetup *setup, } if (setup->verbose) printf (" done.\n"); - + /* Recurse to sub-albums (in case of album index) */ - if (items->type == GALLERY_TYPE_INDEX) + if (items->type == GALLERY_TYPE_INDEX) { if (items->items->len > 0) { for (i = 0; i < items->items->len; i++) { item = g_ptr_array_index (items->items, i); if (item == NULL) { - fprintf (stderr, "build_tree: error getting item %d\n", i); - continue; + fprintf (stderr, "build_tree: error getting item %d\n", i); + continue; } s1 = g_strconcat (src_tree, "/", item->path, "/", NULL); s2 = g_strconcat (dst_dir, "/", item->path, "/", NULL); @@ -901,20 +911,20 @@ build_tree (TGallerySetup *setup, g_free (s1); g_free (s2); } - } + } } - + /* Generate separate image pages (in case of album) */ - if (items->type == GALLERY_TYPE_ALBUM) + if (items->type == GALLERY_TYPE_ALBUM) { if (items->items->len > 0) { - for (i = 0; i < items->items->len; i++) { + for (i = 0; i < items->items->len; i++) { item = g_ptr_array_index (items->items, i); if (item == NULL) { - fprintf (stderr, "build_tree: error getting item %d\n", i); - continue; + fprintf (stderr, "build_tree: error getting item %d\n", i); + continue; } - imgname = (item->path == NULL && item->preview) ? g_path_get_basename (item->preview) : g_strdup (item->path); + imgname = (item->path == NULL && item->preview) ? g_path_get_basename (item->preview) : g_strdup (item->path); if (setup->verbose) printf ("Writing '%s.html' ...", imgname); s1 = g_strconcat (setup->real_templates_dir, "/", setup->template_photo, NULL); s2 = g_strconcat (items->base_dir, "/", (item->path == NULL && item->preview) ? item->preview : item->path, NULL); @@ -924,14 +934,14 @@ build_tree (TGallerySetup *setup, g_free (s2); g_free (s3); g_free (imgname); - if (! res ) continue; - if (setup->verbose) printf (" done.\n"); - } + if (! res ) continue; + if (setup->verbose) printf (" done.\n"); + } } } printf ("*** Leaving directory '%s'\n", src_tree); free_album_data (items); - return TRUE; + return TRUE; } |
