diff options
| -rw-r--r-- | src/block-parser.c | 47 | ||||
| -rw-r--r-- | src/block-parser.h | 41 | ||||
| -rw-r--r-- | src/cgg.c | 16 | ||||
| -rw-r--r-- | src/gallery-utils.c | 57 | ||||
| -rw-r--r-- | src/gallery-utils.h | 16 | ||||
| -rw-r--r-- | src/generators.c | 70 | ||||
| -rw-r--r-- | src/generators.h | 14 | ||||
| -rw-r--r-- | src/items.c | 88 | ||||
| -rw-r--r-- | src/items.h | 42 | ||||
| -rw-r--r-- | src/job-manager.c | 33 | ||||
| -rw-r--r-- | src/job-manager.h | 6 | ||||
| -rw-r--r-- | src/jpeg-utils.cpp | 124 | ||||
| -rw-r--r-- | src/jpeg-utils.h | 60 | ||||
| -rw-r--r-- | src/replace-table.c | 24 | ||||
| -rw-r--r-- | src/replace-table.h | 6 | ||||
| -rw-r--r-- | src/setup.c | 133 | ||||
| -rw-r--r-- | src/setup.h | 48 | ||||
| -rw-r--r-- | src/xml-parser.c | 65 | ||||
| -rw-r--r-- | src/xml-parser.h | 18 |
19 files changed, 409 insertions, 499 deletions
diff --git a/src/block-parser.c b/src/block-parser.c index 57eae8c..9166e0c 100644 --- a/src/block-parser.c +++ b/src/block-parser.c @@ -31,18 +31,18 @@ -#define BUFFER_SIZE 65536 /* lines cannot be longer than this */ +#define BUFFER_SIZE 65536 /* line cannot be longer than this */ struct BlockParser { GHashTable *table; GQueue *active_tree; - char *current_line; + gchar *current_line; }; typedef struct { - char *replace_key; - char *data; + gchar *replace_key; + gchar *data; gboolean used; gboolean finished; } BlockData; @@ -93,7 +93,7 @@ block_parser_free (BlockParser *parser) * */ void -block_parser_register_key (BlockParser *parser, const char *key, const char *replace_key) +block_parser_register_key (BlockParser *parser, const gchar *key, const gchar *replace_key) { BlockData *data; @@ -112,8 +112,8 @@ block_parser_register_key (BlockParser *parser, const char *key, const char *rep * returns newly allocated string, caller is responsible for freeing * */ -char * -block_parser_get_data (BlockParser *parser, const char *key) +gchar * +block_parser_get_data (BlockParser *parser, const gchar *key) { BlockData *data = NULL; @@ -133,7 +133,7 @@ block_parser_get_data (BlockParser *parser, const char *key) * */ gboolean -block_parser_has_unused_data (BlockParser *parser, const char *key) +block_parser_has_unused_data (BlockParser *parser, const gchar *key) { BlockData *data = NULL; @@ -153,10 +153,10 @@ block_parser_has_unused_data (BlockParser *parser, const char *key) /* -------------------------------------------------------------------------------------------------------- */ static void -push_string (BlockParser *parser, const char *piece) +push_string (BlockParser *parser, const gchar *piece) { BlockData *data; - char *s; + gchar *s; data = g_queue_peek_head (parser->active_tree); if (data) { @@ -186,14 +186,14 @@ push_string (BlockParser *parser, const char *piece) * - returns newly allocated string, caller is responsible for freeing * */ -char * +gchar * block_parser_read_and_parse (BlockParser *parser, FILE *stream) { - char *buffer; - char *b; - char *token; - char *start, *end; - char *s; + gchar *buffer; + gchar *b; + gchar *token; + gchar *start, *end; + gchar *s; GList *keys; GList *l; BlockData *data; @@ -201,8 +201,7 @@ block_parser_read_and_parse (BlockParser *parser, FILE *stream) g_return_val_if_fail (parser != NULL, NULL); - buffer = malloc (BUFFER_SIZE); - memset (buffer, 0, BUFFER_SIZE); + buffer = g_malloc0 (BUFFER_SIZE); parser->current_line = g_strdup (""); if (! fgets (buffer, BUFFER_SIZE, stream) || strlen (buffer) == 0) return NULL; @@ -222,9 +221,9 @@ block_parser_read_and_parse (BlockParser *parser, FILE *stream) /* match known tags */ for (l = keys; l != NULL; l = l->next) { /* test BEGIN_ tokens */ - s = g_strdup_printf ("BEGIN_%s", (char *) l->data); + s = g_strdup_printf ("BEGIN_%s", (gchar *) l->data); if (strcmp (s, token) == 0) { - data = g_hash_table_lookup (parser->table, (char *) l->data); + data = g_hash_table_lookup (parser->table, (gchar *) l->data); if (data) { g_queue_push_head (parser->active_tree, data); handled = TRUE; @@ -233,11 +232,11 @@ block_parser_read_and_parse (BlockParser *parser, FILE *stream) g_free (s); /* test END_ tokens */ - s = g_strdup_printf ("END_%s", (char *) l->data); + s = g_strdup_printf ("END_%s", (gchar *) l->data); if (strcmp (s, token) == 0) { - data = g_hash_table_lookup (parser->table, (char *) l->data); + data = g_hash_table_lookup (parser->table, (gchar *) l->data); if (data == NULL || data != g_queue_peek_head (parser->active_tree)) { - log_error ("block_parser_read_and_parse: something is wrong with the parser table: expected '%s'\n", (char *) l->data); + log_error ("block_parser_read_and_parse: something is wrong with the parser table: expected '%s'\n", (gchar *) l->data); } else { @@ -267,6 +266,6 @@ block_parser_read_and_parse (BlockParser *parser, FILE *stream) push_string (parser, b); g_list_free (keys); - free (buffer); + g_free (buffer); return parser->current_line; } diff --git a/src/block-parser.h b/src/block-parser.h index 41db0b1..0e94f73 100644 --- a/src/block-parser.h +++ b/src/block-parser.h @@ -36,20 +36,20 @@ void block_parser_free (BlockParser *parser); * placeholder will be surrounded by "<!-- $(replace_key) -->" * */ -void block_parser_register_key (BlockParser *parser, const char *key, const char *replace_key); +void block_parser_register_key (BlockParser *parser, const gchar *key, const gchar *replace_key); /* * block_parser_get_data: return retrieved data or NULL if none read yet * returns newly allocated string, caller is responsible for freeing * */ -char * block_parser_get_data (BlockParser *parser, const char *key); +gchar * block_parser_get_data (BlockParser *parser, const gchar *key); /* * block_parser_has_unused_data: indicates whether the data have already been read and used (by calling block_parser_get_data) * */ -gboolean block_parser_has_unused_data (BlockParser *parser, const char *key); +gboolean block_parser_has_unused_data (BlockParser *parser, const gchar *key); /* * block_parser_read_and_parse: reads input from the file and returns parsed line @@ -61,37 +61,4 @@ gboolean block_parser_has_unused_data (BlockParser *parser, const char *key); * - returns newly allocated string, caller is responsible for freeing * */ -char * block_parser_read_and_parse (BlockParser *parser, FILE *stream); - - - -#if 0 - -/* - * replace_table_add_key: add tag/value pair to replace - * - * tag, value will be referenced inside - * - */ -void replace_table_add_key (ReplaceTable *table, const gchar *tag, const gchar *value); -void replace_table_add_key_int (ReplaceTable *table, const gchar *tag, gint value); -void replace_table_add_key_printf (ReplaceTable *table, const gchar *tag, const gchar *format, ...) G_GNUC_PRINTF (3, 4); - -/* - * replace_table_process: process buffer and replace all tags filled in the replace table - * - * - reallocates source buffer - * - */ -void replace_table_process (gchar **buffer, ReplaceTable *table); - - -/* - * adjust_tags_normal: adjust string for normal HTML use - * adjust_tags_parameter: adjust string for use as tag parameter value - * - both funtions return newly allocated string - */ -void adjust_tags_normal (char **str); -void adjust_tags_parameter (char **str); - -#endif +gchar * block_parser_read_and_parse (BlockParser *parser, FILE *stream); @@ -44,7 +44,7 @@ * parse_cmd: parse commandline and fill global variable parameters */ gboolean -parse_cmd (int argc, char* argv[], char **source_dir, char **dst_dir, gboolean *verbose, int *jobs, gboolean *update) +parse_cmd (int argc, char* argv[], gchar **source_dir, gchar **dst_dir, gboolean *verbose, int *jobs, gboolean *update) { static gboolean _verbose = FALSE; static gchar *_source_dir = NULL; @@ -64,7 +64,7 @@ parse_cmd (int argc, char* argv[], char **source_dir, char **dst_dir, gboolean * GError *error = NULL; GOptionContext *context; - char *s1; + gchar *s1; g_set_prgname ("cgg"); @@ -104,10 +104,10 @@ parse_cmd (int argc, char* argv[], char **source_dir, char **dst_dir, gboolean * int -main(int argc, char* argv[]) +main (int argc, char* argv[]) { - char *source_dir; - char *dst_dir; + gchar *source_dir; + gchar *dst_dir; gboolean verbose; gboolean update; int jobs; @@ -130,7 +130,7 @@ main(int argc, char* argv[]) source_dir = NULL; dst_dir = NULL; - setup = malloc(sizeof(TGallerySetup)); + setup = g_malloc0 (sizeof (TGallerySetup)); /* Parse commandline */ @@ -188,8 +188,8 @@ main(int argc, char* argv[]) /* Cleanup function for the XML library. */ xmlCleanupParser(); - free (source_dir); - free (dst_dir); + g_free (source_dir); + g_free (dst_dir); free_setup_data (setup); return (0); diff --git a/src/gallery-utils.c b/src/gallery-utils.c index 29c456d..1ac8419 100644 --- a/src/gallery-utils.c +++ b/src/gallery-utils.c @@ -34,12 +34,12 @@ * - reallocates the original string */ void -str_replace (char **dst, const char *search, const char *replace) +str_replace (gchar **dst, const gchar *search, const gchar *replace) { #define REPLACE_MAX_LENGTH 32768 - static char d[REPLACE_MAX_LENGTH]; - char *src; - char *found; + static gchar d[REPLACE_MAX_LENGTH]; + gchar *src; + gchar *found; int i; /* TODO: add range checking */ @@ -79,7 +79,7 @@ str_replace (char **dst, const char *search, const char *replace) #endif /* return fixed string */ - free (*dst); + g_free (*dst); *dst = g_strdup (&d[0]); } @@ -88,7 +88,7 @@ str_replace (char **dst, const char *search, const char *replace) * copy_file: copy file from src to dst */ gboolean -copy_file (const char *src, const char *dst) +copy_file (const gchar *src, const gchar *dst) { #define BUFFER_SIZE 65536 @@ -151,18 +151,18 @@ copy_file (const char *src, const char *dst) * make_string: make string of 'substr' substrings * - returns newly allocated string */ -char * -make_string (const char *substr, int count) +gchar * +make_string (const gchar *substr, int count) { int i; - char *s; + gchar *s; if (count < 0) count = 0; - s = malloc (strlen (substr) * count + 1); + s = g_malloc0 (strlen (substr) * count + 1); for (i = 0; i < count; i++) - memcpy (s + (strlen (substr) * i), substr, strlen (substr)); + memcpy (s + (strlen (substr) * i), substr, strlen (substr)); s[strlen (substr) * count] = 0; return s; } @@ -173,12 +173,12 @@ make_string (const char *substr, int count) * - returns newly allocated string */ void -fix_entities (char **str) +fix_entities (gchar **str) { - static char d[REPLACE_MAX_LENGTH]; - char *src; - char *found; - char *scan; + static gchar d[REPLACE_MAX_LENGTH]; + gchar *src; + gchar *found; + gchar *scan; int i; /* TODO: add range checking */ @@ -228,7 +228,7 @@ fix_entities (char **str) #endif /* return fixed string */ - free (*str); + g_free (*str); *str = g_strdup (&d[0]); } @@ -239,12 +239,12 @@ fix_entities (char **str) * - returns newly allocated string */ void -remove_tags (char **str, const char *tag_begin, const char *tag_end) +remove_tags (gchar **str, const gchar *tag_begin, const gchar *tag_end) { - char *src; - char *found; - char *found2; - char *dest; + gchar *src; + gchar *found; + gchar *found2; + gchar *dest; if (! *str || ! tag_begin || ! tag_end || strlen (*str) == 0 || strlen (tag_begin) == 0 || strlen (tag_end) == 0) return; @@ -255,7 +255,7 @@ remove_tags (char **str, const char *tag_begin, const char *tag_end) found2 = strstr (found, tag_end); if (found2) { found2 += strlen (tag_end); - dest = malloc (strlen (src) - (found2 - found) + 1); + dest = g_malloc0 (strlen (src) - (found2 - found) + 1); memcpy (dest, src, found - src); memcpy (dest + (found - src), found2, strlen (found2) + 1); #ifdef __DEBUG_ALL__ @@ -264,7 +264,7 @@ remove_tags (char **str, const char *tag_begin, const char *tag_end) #endif g_free (src); src = g_strdup (dest); - free (dest); + g_free (dest); } else { @@ -276,11 +276,12 @@ remove_tags (char **str, const char *tag_begin, const char *tag_end) *str = src; } + /* * count_dir_levels: returns number of path elements */ int -count_dir_levels (const char *path) +count_dir_levels (const gchar *path) { int i; int level; @@ -301,8 +302,8 @@ count_dir_levels (const char *path) /* * extract_file_ext: returns pointer to filename extension */ -const char * -extract_file_ext (const char *filename) +const gchar * +extract_file_ext (const gchar *filename) { g_return_val_if_fail (filename != NULL, NULL); g_return_val_if_fail (strlen (filename) > 0, NULL); @@ -332,7 +333,7 @@ log_error (const gchar *format, ...) * needs_update: returns TRUE if the destionation file needs updating, also when missing */ gboolean -needs_update (const char *source, const char *dest) +needs_update (const gchar *source, const gchar *dest) { struct stat src_stat; struct stat dst_stat; diff --git a/src/gallery-utils.h b/src/gallery-utils.h index 85ad35d..b354a38 100644 --- a/src/gallery-utils.h +++ b/src/gallery-utils.h @@ -32,41 +32,41 @@ * - multiple occurences of the string are replaced * - reallocates the original string */ -void str_replace (char **dst, const char *search, const char *replace); +void str_replace (gchar **dst, const gchar *search, const gchar *replace); /* * copy_file: copy file from src to dst */ -gboolean copy_file (const char *src, const char *dst); +gboolean copy_file (const gchar *src, const gchar *dst); /* * make_string: make string of 'substr' substrings * - returns newly allocated string */ -char *make_string (const char *substr, int count); +gchar *make_string (const gchar *substr, int count); /* * fix_entities: replace all invalid & entities with & * - returns newly allocated string */ -void fix_entities (char **str); +void fix_entities (gchar **str); /* * remove_tags: remove all occurences of tags beginning with tag_begin and ending with tag_end * - e.g. remove_tags (&x, "<!--", "-->") will remove all comments * - returns newly allocated string */ -void remove_tags (char **str, const char *tag_begin, const char *tag_end); +void remove_tags (gchar **str, const gchar *tag_begin, const gchar *tag_end); /* * count_dir_levels: returns number of path elements */ -int count_dir_levels (const char *path); +int count_dir_levels (const gchar *path); /* * extract_file_ext: returns pointer to filename extension */ -const char *extract_file_ext (const char *filename); +const gchar *extract_file_ext (const gchar *filename); /* * log_error: prints an error and increments stats @@ -76,7 +76,7 @@ void log_error (const gchar *format, ...) G_GNUC_PRINTF (1, 2); /* * needs_update: returns TRUE if the destionation file needs updating, also when missing */ -gboolean needs_update (const char *source, const char *dest); +gboolean needs_update (const gchar *source, const gchar *dest); #ifdef __cplusplus diff --git a/src/generators.c b/src/generators.c index fdea806..d64f5b2 100644 --- a/src/generators.c +++ b/src/generators.c @@ -36,11 +36,11 @@ -static char * -make_thumbnail_string (TGallerySetup *setup, unsigned int item_index, const char *imgname) +static gchar * +make_thumbnail_string (TGallerySetup *setup, unsigned int item_index, const gchar *imgname) { - char *s; - char *num; + gchar *s; + gchar *num; s = g_strdup (setup->thumbnail_name_format); str_replace (&s, "%s", imgname); @@ -60,18 +60,18 @@ generate_image (TGallerySetup *setup, TAlbum *items, TIndexItem *item, unsigned int item_index, - const char *dst_dir, + const gchar *dst_dir, gboolean update_when_necessary) { unsigned long new_w, new_h; unsigned long thumb_w, thumb_h; - char *thumb_dst; - char *big_dst; - char *big_src; - char *orig_dst; - char *img_src_full; - char *thumb_src_full; - char *s1; + gchar *thumb_dst; + gchar *big_dst; + gchar *big_src; + gchar *orig_dst; + gchar *img_src_full; + gchar *thumb_src_full; + gchar *s1; int bigq; gboolean res; @@ -211,15 +211,15 @@ generate_image (TGallerySetup *setup, */ gboolean write_html_album (TGallerySetup *setup, - const char *template_src, - const char *dst, + const gchar *template_src, + const gchar *dst, TAlbum *items) { FILE *fin; FILE *fout; - char *line; - char *block; - char *s1, *s2, *s3, *s4, *s5; + gchar *line; + gchar *block; + gchar *s1, *s2, *s3, *s4, *s5; TAlbum *parent; TIndexItem *item; TIndexItem *tmp_item; @@ -288,14 +288,14 @@ write_html_album (TGallerySetup *setup, s2 = setup->use_inpage_links ? g_strdup_printf ("#i%d", old_parent_item_index) : g_strdup (""); replace_table_add_key_printf (global_replace_table, "GO_UP_LINK", "%s%s%s", s3, setup->index_file_name, s2); g_free (s2); - free (s3); + g_free (s3); while (parent) { s3 = make_string ("../", level); s4 = g_strdup (parent->ID); s5 = setup->use_inpage_links ? g_strdup_printf ("#i%d", old_parent_item_index) : g_strdup (""); s2 = g_strdup_printf ("<a href=\"%s%s%s\">%s</a> > %s", s3, setup->index_file_name, s5, s4, s1); - free (s3); + g_free (s3); g_free (s1); g_free (s4); g_free (s5); @@ -315,7 +315,7 @@ write_html_album (TGallerySetup *setup, /* Supportfiles path */ s1 = make_string ("../", level - 1); replace_table_add_key (global_replace_table, "TEMPLATES_PATH", setup->support_files_use_common_root ? s1 : ""); - free (s1); + g_free (s1); /* META tags */ s1 = g_strdup_printf ("\t<meta name=\"generator\" content=\"Cataract Gallery Generator v%s\" />\n", VERSION); @@ -350,7 +350,7 @@ write_html_album (TGallerySetup *setup, else s2 = g_strdup_printf ("%s\t<link rel=\"icon\" href=\"%s%s\" />\n", s1, setup->support_files_use_common_root ? s3 : "", setup->favicon_file); g_free (s1); - free (s3); + g_free (s3); s1 = s2; } replace_table_add_key (global_replace_table, "CGG_META_TAGS", s1); @@ -477,16 +477,16 @@ write_html_album (TGallerySetup *setup, */ gboolean write_html_image (TGallerySetup *setup, - const char *template_src, - const char *original_img, - const char *dst, + const gchar *template_src, + const gchar *original_img, + const gchar *dst, TIndexItem *item, TAlbum *parent_items) { FILE *fin; FILE *fout; - char *big_dst; - char *orig_dst; + gchar *big_dst; + gchar *orig_dst; TExifData *exif; unsigned long img_big_w, img_big_h, img_orig_w, img_orig_h; unsigned int item_index, real_item_index, real_total_items; @@ -495,11 +495,11 @@ write_html_image (TGallerySetup *setup, TIndexItem *tmp_item; TAlbum *parent; int i; - char *line; - char *block; - char *s1, *s2, *s3, *s4, *s5; - char *imgname, *preload_imgname; - char *title, *title_desc; + gchar *line; + gchar *block; + gchar *s1, *s2, *s3, *s4, *s5; + gchar *imgname, *preload_imgname; + gchar *title, *title_desc; gboolean res, bb; int level, old_parent_item_index; gboolean override_title_meta; @@ -648,7 +648,7 @@ write_html_image (TGallerySetup *setup, s4 = g_strdup (parent->ID); s5 = setup->use_inpage_links ? g_strdup_printf ("#i%d", parent == parent_items ? item_index : old_parent_item_index) : g_strdup (""); s2 = g_strdup_printf ("<a href=\"%s%s%s\">%s</a> > %s", s3, setup->index_file_name, s5, s4, s1); - free (s3); + g_free (s3); g_free (s1); g_free (s4); g_free (s5); @@ -668,7 +668,7 @@ write_html_image (TGallerySetup *setup, /* Supportfiles path */ s1 = make_string ("../", level - 1); replace_table_add_key (replace_table, "TEMPLATES_PATH", setup->support_files_use_common_root ? s1 : ""); - free (s1); + g_free (s1); /* EXIF values */ replace_table_add_key (replace_table, "EXIF_ISO", exif->iso ? exif->iso : "??"); @@ -794,8 +794,8 @@ write_html_image (TGallerySetup *setup, fclose (fin); g_free (title); g_free (title_desc); - free (big_dst); - free (orig_dst); + g_free (big_dst); + g_free (orig_dst); g_free (imgname); g_free (preload_imgname); free_exif_data (exif); diff --git a/src/generators.h b/src/generators.h index 31636f0..3aa9cc2 100644 --- a/src/generators.h +++ b/src/generators.h @@ -15,6 +15,8 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +#include <glib.h> + #include "setup.h" #include "items.h" @@ -27,7 +29,7 @@ gboolean generate_image (TGallerySetup *setup, TAlbum *items, TIndexItem *item, unsigned int item_index, - const char *dst_dir, + const gchar *dst_dir, gboolean update_when_necessary); /* @@ -39,8 +41,8 @@ gboolean generate_image (TGallerySetup *setup, * */ gboolean write_html_album (TGallerySetup *setup, - const char *template_src, - const char *dst, + const gchar *template_src, + const gchar *dst, TAlbum *items); /* @@ -54,8 +56,8 @@ gboolean write_html_album (TGallerySetup *setup, * */ gboolean write_html_image (TGallerySetup *setup, - const char *template_src, - const char *original_img, - const char *dst, + const gchar *template_src, + const gchar *original_img, + const gchar *dst, TIndexItem *item, TAlbum *parent_items); diff --git a/src/items.c b/src/items.c index 27034f2..842f066 100644 --- a/src/items.c +++ b/src/items.c @@ -34,23 +34,23 @@ * parse_album_xml: XML parser for gallery index.xml files */ gboolean -parse_album_xml (const char *filename, TAlbum *index) +parse_album_xml (const gchar *filename, TAlbum *index) { TXMLFile *xml; - char *gallery_type; + gchar *gallery_type; int count; int i; - char *s, *s2; - char *node_name; + gchar *s, *s2; + gchar *node_name; TIndexItem *item; xml = xml_parser_load (filename); if (xml == NULL) - return FALSE; + return FALSE; /* Initialize data struct */ if (index == NULL) - index = malloc (sizeof (TAlbum)); + index = g_malloc0 (sizeof (TAlbum)); memset (index, 0, sizeof (TAlbum)); index->base_dir = g_path_get_dirname (filename); @@ -61,13 +61,13 @@ parse_album_xml (const char *filename, TAlbum *index) printf("gallery_type = %s\n", gallery_type); #endif if (strcmp (gallery_type, "index") == 0) - index->type = GALLERY_TYPE_INDEX; + index->type = GALLERY_TYPE_INDEX; else if (strcmp (gallery_type, "album") == 0) - index->type = GALLERY_TYPE_ALBUM; + index->type = GALLERY_TYPE_ALBUM; else { log_error ("Invalid gallery type (%s)\n", gallery_type); - free (index); + g_free (index); return FALSE; } @@ -79,7 +79,7 @@ parse_album_xml (const char *filename, TAlbum *index) s = xml_file_get_node_value (xml, "/gallery/general/extra_files/text()"); if (s) { index->extra_files = g_strsplit (s, "\n", -1); - free (s); + g_free (s); } @@ -184,7 +184,7 @@ parse_album_xml (const char *filename, TAlbum *index) else { log_error ("%s: No image src specified, skipping!\n", filename); - free (item); + g_free (item); } } else @@ -209,9 +209,9 @@ parse_album_xml (const char *filename, TAlbum *index) } else { /* Free the item if nobody cares */ - free (item); + g_free (item); } - free (node_name); + g_free (node_name); } xml_parser_close (xml); @@ -236,26 +236,16 @@ void free_album_data (TAlbum *album) { if (album) { - if (album->ID) - free (album->ID); - if (album->title) - free (album->title); - if (album->desc) - free (album->desc); - if (album->footnote) - free (album->footnote); - if (album->base_dir) - free (album->base_dir); - if (album->border_style) - free (album->border_style); - if (album->meta_author) - free (album->meta_author); - if (album->meta_description) - free (album->meta_description); - if (album->meta_keywords) - free (album->meta_keywords); - if (album->extra_files) - g_strfreev (album->extra_files); + g_free (album->ID); + g_free (album->title); + g_free (album->desc); + g_free (album->footnote); + g_free (album->base_dir); + g_free (album->border_style); + g_free (album->meta_author); + g_free (album->meta_description); + g_free (album->meta_keywords); + g_strfreev (album->extra_files); if (album->items) { if (album->items->len > 0) { @@ -265,29 +255,21 @@ free_album_data (TAlbum *album) for (i = 0; i < album->items->len; i++) { item = g_ptr_array_index (album->items, i); if (item != NULL) { - if (item->path) - free (item->path); - if (item->title) - free (item->title); - if (item->title_description) - free (item->title_description); - if (item->thumbnail) - free (item->thumbnail); - if (item->preview) - free (item->preview); - if (item->border_style) - free (item->border_style); - if (item->gen_img_src) - free (item->gen_img_src); - if (item->gen_thumb) - free (item->gen_thumb); - free (item); + g_free (item->path); + g_free (item->title); + g_free (item->title_description); + g_free (item->thumbnail); + g_free (item->preview); + g_free (item->border_style); + g_free (item->gen_img_src); + g_free (item->gen_thumb); + g_free (item); } } } g_ptr_array_free (album->items, TRUE); } - free (album); + g_free (album); album = NULL; } } @@ -297,7 +279,7 @@ free_album_data (TAlbum *album) * get_gallery_objects_count: retrieve number of items in specified album */ int -get_album_objects_count (const char *filename) +get_album_objects_count (const gchar *filename) { TXMLFile *xml; int count; @@ -319,7 +301,7 @@ get_album_objects_count (const char *filename) * get_album_titles: retrieve title, description and first thumbnail from specified album */ void -get_album_titles (const char *filename, char **title, char **description, char **thumbnail) +get_album_titles (const gchar *filename, gchar **title, gchar **description, gchar **thumbnail) { TXMLFile *xml; diff --git a/src/items.h b/src/items.h index b7be433..737d4ca 100644 --- a/src/items.h +++ b/src/items.h @@ -35,12 +35,12 @@ typedef enum { typedef struct { TGalleryType type; - char *ID; - char *title; - char *desc; - char *footnote; + gchar *ID; + gchar *title; + gchar *desc; + gchar *footnote; GPtrArray *items; - char *base_dir; + gchar *base_dir; void *parent_index; /* pointer to the parent TAlbum structure */ int parent_item_index; /* item index in the parent album */ int quality; @@ -48,33 +48,33 @@ typedef struct { unsigned long landscape_height; unsigned long portrait_width; unsigned long portrait_height; - char *border_style; - char *meta_author; - char *meta_description; - char *meta_keywords; + gchar *border_style; + gchar *meta_author; + gchar *meta_description; + gchar *meta_keywords; gboolean nofullsize; gboolean fullsize; - char **extra_files; + gchar **extra_files; } TAlbum; typedef struct { - char *path; - char *title; - char *title_description; - char *thumbnail; - char *preview; + gchar *path; + gchar *title; + gchar *title_description; + gchar *thumbnail; + gchar *preview; int quality; unsigned long width; unsigned long height; gboolean force_nofullsize; gboolean force_fullsize; - char *border_style; + gchar *border_style; TIndexItemType type; gboolean hidden; /* generated item info */ - char *gen_img_src; - char *gen_thumb; + gchar *gen_img_src; + gchar *gen_thumb; gboolean gen_portrait; gboolean gen_done; } TIndexItem; @@ -84,7 +84,7 @@ typedef struct { /* * parse_album_xml: XML parser for gallery index.xml files */ -gboolean parse_album_xml (const char *filename, TAlbum *index); +gboolean parse_album_xml (const gchar *filename, TAlbum *index); /* * free_album_data: free allocated album data @@ -94,11 +94,11 @@ void free_album_data (TAlbum *index); /* * get_album_objects_count: retrieve number of items in specified album */ -int get_album_objects_count (const char *filename); +int get_album_objects_count (const gchar *filename); /* * get_album_titles: retrieve title, description and first thumbnail from specified album */ -void get_album_titles (const char *filename, char **title, char **description, char **thumbnail); +void get_album_titles (const gchar *filename, gchar **title, gchar **description, gchar **thumbnail); #endif /* __ITEMS_H__ */ diff --git a/src/job-manager.c b/src/job-manager.c index 1f37595..002ca06 100644 --- a/src/job-manager.c +++ b/src/job-manager.c @@ -40,7 +40,7 @@ typedef struct { TGallerySetup *setup; TAlbum *items; - const char *dst_dir; + const gchar *dst_dir; gboolean force_update; } TJob; @@ -48,10 +48,10 @@ typedef struct { static void -mirror_files (TGallerySetup *setup, char **files, const char *src_tree, const char *dst_dir, const char *label) +mirror_files (TGallerySetup *setup, gchar **files, const gchar *src_tree, const gchar *dst_dir, const gchar *label) { - char **extra; - char *s1, *s2, *s3; + gchar **extra; + gchar *s1, *s2, *s3; int processed = 0; if (files && g_strv_length (files) > 0) { @@ -103,9 +103,9 @@ static gpointer thread_func (gpointer data) { TIndexItem *item; - char *imgname; + gchar *imgname; int i; - char *s1, *s2, *s3; + gchar *s1, *s2, *s3; int total, index, real_index; TJob *job = data; gboolean updated; @@ -180,21 +180,21 @@ thread_func (gpointer data) */ gboolean build_tree (TGallerySetup *setup, - const char *src_tree, - const char *dst_dir, + const gchar *src_tree, + const gchar *dst_dir, TAlbum *parent_index, int parent_item_index, int jobs) { - char *idx_file; + gchar *idx_file; TAlbum *items; TIndexItem *item; - char *s1, *s2, *s3; - char *thumb_dir; - char *img_big_dir; - char *img_orig_dir; - char *template; - char *dst_album_file; + gchar *s1, *s2, *s3; + gchar *thumb_dir; + gchar *img_big_dir; + gchar *img_orig_dir; + gchar *template; + gchar *dst_album_file; gboolean res; int i; TJob *job; @@ -230,8 +230,7 @@ build_tree (TGallerySetup *setup, } /* Read the index file and fill items array */ - items = malloc (sizeof (TAlbum)); - memset (items, 0, sizeof (TAlbum)); + items = g_malloc0 (sizeof (TAlbum)); if (! parse_album_xml (idx_file, items)) { log_error ("error reading index file '%s'\n", idx_file); g_free (idx_file); diff --git a/src/job-manager.h b/src/job-manager.h index 13f08e0..df7e19f 100644 --- a/src/job-manager.h +++ b/src/job-manager.h @@ -15,6 +15,8 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +#include <glib.h> + #include "setup.h" #include "items.h" @@ -28,8 +30,8 @@ * */ gboolean build_tree (TGallerySetup *setup, - const char *src_tree, - const char *dst_dir, + const gchar *src_tree, + const gchar *dst_dir, TAlbum *parent_index, int parent_item_index, int jobs); diff --git a/src/jpeg-utils.cpp b/src/jpeg-utils.cpp index 275e859..af7e4bf 100644 --- a/src/jpeg-utils.cpp +++ b/src/jpeg-utils.cpp @@ -35,12 +35,11 @@ * get_exif: retrieve EXIF informations from a JPEG image */ int -get_exif (const char *filename, TExifData **exif_data) +get_exif (const gchar *filename, TExifData **exif_data) { TExifData *data; - data = (TExifData*) malloc (sizeof (TExifData)); - memset (data, 0, sizeof (TExifData)); + data = (TExifData*) g_malloc0 (sizeof (TExifData)); *exif_data = data; try @@ -60,9 +59,7 @@ get_exif (const char *filename, TExifData **exif_data) /* EXIF::Camera model */ try { - const char *val = exifData["Exif.Image.Model"].toString().c_str(); - if (val && strlen(val) > 0) - data->camera_model = strdup (val); + data->camera_model = g_strdup (exifData["Exif.Image.Model"].toString().c_str()); } catch (...) { } /* EXIF::DateTime */ @@ -71,12 +68,12 @@ get_exif (const char *filename, TExifData **exif_data) try { val = exifData["Exif.Photo.DateTimeOriginal"].toString().c_str(); } catch (...) { } - if ((! val) || (strlen(val) == 0)) + if ((! val) || (strlen (val) == 0)) try { val = exifData["Exif.Image.DateTime"].toString().c_str(); } catch (...) { } - if (val && strlen(val) > 0) { + if (val && strlen (val) > 0) { static struct tm tt; static char conv[1024]; @@ -84,8 +81,8 @@ get_exif (const char *filename, TExifData **exif_data) { tt.tm_year -= 1900; tt.tm_mon--; - if (strftime (&conv[0], sizeof(conv), "%c", &tt)) - data->datetime = strdup (&conv[0]); + if (strftime (&conv[0], sizeof (conv), "%c", &tt)) + data->datetime = g_strdup (&conv[0]); } } } catch (...) { } @@ -105,9 +102,9 @@ get_exif (const char *filename, TExifData **exif_data) try { long int val = exifData["Exif.Photo.Flash"].toLong(); if ((val > 0) && ((val & 1) == 1)) - data->flash = strdup ((char *) "Flash fired"); + data->flash = g_strdup ("Flash fired"); else - data->flash = strdup ((char *) "--"); + data->flash = g_strdup ("--"); } catch (...) { } /* EXIF::Focal length */ @@ -126,27 +123,27 @@ get_exif (const char *filename, TExifData **exif_data) /* EXIF::Software */ try { - data->exif_software = strdup (exifData["Exif.Image.Software"].toString().c_str()); + data->exif_software = g_strdup (exifData["Exif.Image.Software"].toString().c_str()); } catch (...) { } /* EXIF::Image description */ try { - data->exif_imgdesc = strdup (exifData["Exif.Image.ImageDescription"].toString().c_str()); + data->exif_imgdesc = g_strdup (exifData["Exif.Image.ImageDescription"].toString().c_str()); } catch (...) { } /* EXIF::Artist */ try { - data->exif_artist = strdup (exifData["Exif.Image.Artist"].toString().c_str()); + data->exif_artist = g_strdup (exifData["Exif.Image.Artist"].toString().c_str()); } catch (...) { } /* EXIF::Copyright */ try { - data->exif_copyright = strdup (exifData["Exif.Image.Copyright"].toString().c_str()); + data->exif_copyright = g_strdup (exifData["Exif.Image.Copyright"].toString().c_str()); } catch (...) { } /* EXIF::User comment */ try { - data->exif_usercomment = strdup (exifData["Exif.Photo.UserComment"].toString().c_str()); + data->exif_usercomment = g_strdup (exifData["Exif.Photo.UserComment"].toString().c_str()); } catch (...) { } } @@ -154,33 +151,33 @@ get_exif (const char *filename, TExifData **exif_data) if (! iptcData.empty()) { /* IPTC::Object name */ try { - data->iptc_objectname = strdup (iptcData["Iptc.Application2.ObjectName"].toString().c_str()); + data->iptc_objectname = g_strdup (iptcData["Iptc.Application2.ObjectName"].toString().c_str()); } catch (...) { } /* IPTC::Copyright */ try { - data->iptc_copyright = strdup (iptcData["Iptc.Application2.Copyright"].toString().c_str()); + data->iptc_copyright = g_strdup (iptcData["Iptc.Application2.Copyright"].toString().c_str()); } catch (...) { } /* IPTC::Credit */ try { - data->iptc_credit = strdup (iptcData["Iptc.Application2.Credit"].toString().c_str()); + data->iptc_credit = g_strdup (iptcData["Iptc.Application2.Credit"].toString().c_str()); } catch (...) { } /* IPTC::Caption */ try { - data->iptc_caption = strdup (iptcData["Iptc.Application2.Caption"].toString().c_str()); + data->iptc_caption = g_strdup (iptcData["Iptc.Application2.Caption"].toString().c_str()); } catch (...) { } /* IPTC::Author */ try { - data->iptc_author = strdup (iptcData["Iptc.Application2.Byline"].toString().c_str()); + data->iptc_author = g_strdup (iptcData["Iptc.Application2.Byline"].toString().c_str()); } catch (...) { } } /* JPEG::Comment */ try { - data->jpeg_comment = strdup (image->comment().c_str()); + data->jpeg_comment = g_strdup (image->comment().c_str()); } catch (...) { } } catch (Exiv2::AnyError& e) @@ -221,49 +218,30 @@ void free_exif_data (TExifData *data) { if (data) { - if (data->aperture) - free (data->aperture); - if (data->camera_model) - free (data->camera_model); - if (data->datetime) - free (data->datetime); - if (data->exposure) - free (data->exposure); - if (data->flash) - free (data->flash); - if (data->focal_length) - free (data->focal_length); - if (data->focal_length_35mm) - free (data->focal_length_35mm); - if (data->iso) - free (data->iso); - - if (data->exif_software) - free (data->exif_software); - if (data->exif_imgdesc) - free (data->exif_imgdesc); - if (data->exif_artist) - free (data->exif_artist); - if (data->exif_copyright) - free (data->exif_copyright); - if (data->exif_usercomment) - free (data->exif_usercomment); - - if (data->iptc_objectname) - free (data->iptc_objectname); - if (data->iptc_copyright) - free (data->iptc_copyright); - if (data->iptc_credit) - free (data->iptc_credit); - if (data->iptc_caption) - free (data->iptc_caption); - if (data->iptc_author) - free (data->iptc_author); - - if (data->jpeg_comment) - free (data->jpeg_comment); - - free (data); + g_free (data->aperture); + g_free (data->camera_model); + g_free (data->datetime); + g_free (data->exposure); + g_free (data->flash); + g_free (data->focal_length); + g_free (data->focal_length_35mm); + g_free (data->iso); + + g_free (data->exif_software); + g_free (data->exif_imgdesc); + g_free (data->exif_artist); + g_free (data->exif_copyright); + g_free (data->exif_usercomment); + + g_free (data->iptc_objectname); + g_free (data->iptc_copyright); + g_free (data->iptc_credit); + g_free (data->iptc_caption); + g_free (data->iptc_author); + + g_free (data->jpeg_comment); + + g_free (data); data = NULL; } } @@ -273,19 +251,19 @@ free_exif_data (TExifData *data) * resize_image: resize image pointed by src and save result to dst */ gboolean -resize_image (const char *src, const char *dst, +resize_image (const gchar *src, const gchar *dst, int size_x, int size_y, int quality, gboolean thumbnail) { #define ThrowWandException(wand) \ { \ - char *description; \ + gchar *description; \ ExceptionType severity; \ \ description = MagickGetException (wand, &severity); \ log_error ("Error converting image: %s %s %ld %s\n", GetMagickModule(), description); \ - description = (char*) MagickRelinquishMemory (description); \ + description = (gchar*) MagickRelinquishMemory (description); \ return FALSE; \ } @@ -317,17 +295,17 @@ resize_image (const char *src, const char *dst, * get_image_sizes: retrieve image dimensions */ void -get_image_sizes (const char *img, +get_image_sizes (const gchar *img, unsigned long *width, unsigned long *height) { #define xThrowWandException(wand) \ { \ - char *description; \ + gchar *description; \ ExceptionType severity; \ \ description = MagickGetException (wand, &severity); \ log_error ("Error reading image info: %s %s %ld %s\n", GetMagickModule(), description); \ - description = (char*) MagickRelinquishMemory(description); \ + description = (gchar*) MagickRelinquishMemory(description); \ return; \ } @@ -380,7 +358,7 @@ calculate_sizes (const unsigned long max_width, const unsigned long max_height, * - add copyright to Exif::Image::Copyright and Iptc::Application2::Copyright */ void -modify_exif (const char *filename, gboolean strip_thumbnail, const char *add_copyright) +modify_exif (const gchar *filename, gboolean strip_thumbnail, const gchar *add_copyright) { bool was_modified = false; diff --git a/src/jpeg-utils.h b/src/jpeg-utils.h index 9b8919f..65e97c5 100644 --- a/src/jpeg-utils.h +++ b/src/jpeg-utils.h @@ -25,35 +25,35 @@ /* TODO: we want to have numerical values here at some point in the future */ typedef struct { - char *datetime; - char *camera_model; - char *iso; - char *focal_length; - char *focal_length_35mm; - char *aperture; - char *exposure; - char *flash; - - char *exif_software; - char *exif_imgdesc; - char *exif_artist; - char *exif_copyright; - char *exif_usercomment; - - char *iptc_objectname; - char *iptc_copyright; - char *iptc_credit; - char *iptc_caption; - char *iptc_author; - - char *jpeg_comment; + gchar *datetime; + gchar *camera_model; + gchar *iso; + gchar *focal_length; + gchar *focal_length_35mm; + gchar *aperture; + gchar *exposure; + gchar *flash; + + gchar *exif_software; + gchar *exif_imgdesc; + gchar *exif_artist; + gchar *exif_copyright; + gchar *exif_usercomment; + + gchar *iptc_objectname; + gchar *iptc_copyright; + gchar *iptc_credit; + gchar *iptc_caption; + gchar *iptc_author; + + gchar *jpeg_comment; } TExifData; /* * get_exif: retrieve EXIF info from a JPEG image */ -int get_exif (const char *filename, TExifData **exif_data); +int get_exif (const gchar *filename, TExifData **exif_data); /* * free_exif_struct: free allocated structure @@ -65,28 +65,28 @@ void free_exif_data (TExifData *data); * resize_image: resize image pointed by src and save result to dst * - setting thumbnail flag will remove all profiles and optimize for size */ -gboolean resize_image (const char *src, const char *dst, - int size_x, int size_y, - int quality, - gboolean thumbnail); +gboolean resize_image (const gchar *src, const gchar *dst, + int size_x, int size_y, + int quality, + gboolean thumbnail); /* * get_image_sizes: retrieve image dimensions */ -void get_image_sizes (const char *img, +void get_image_sizes (const gchar *img, unsigned long *width, unsigned long *height); /* * calculate_sizes: calculate maximal image sizes within specified limits keeping aspect ratio */ void calculate_sizes (const unsigned long max_width, const unsigned long max_height, - unsigned long *width, unsigned long *height); + unsigned long *width, unsigned long *height); /* * modify_exif: - strip thumbnail stored in EXIF table * - add copyright to Exif::Image::Copyright and Iptc::Application2::Copyright */ -void modify_exif (const char *filename, gboolean strip_thumbnail, const char *add_copyright); +void modify_exif (const gchar *filename, gboolean strip_thumbnail, const gchar *add_copyright); #ifdef __cplusplus diff --git a/src/replace-table.c b/src/replace-table.c index 1f674a3..95d5e30 100644 --- a/src/replace-table.c +++ b/src/replace-table.c @@ -96,10 +96,10 @@ replace_table_add_key_printf (ReplaceTable *table, const gchar *tag, const gchar void replace_table_process (gchar **buffer, ReplaceTable *table) { - char *token; - char *start, *end; - char *b; - char *replace_value; + gchar *token; + gchar *start, *end; + gchar *b; + gchar *replace_value; GString *dst; gboolean tag_parameter; gboolean handled; @@ -150,15 +150,15 @@ replace_table_process (gchar **buffer, ReplaceTable *table) * - both funtions return newly allocated string */ void -adjust_tags_normal (char **str) +adjust_tags_normal (gchar **str) { fix_entities (str); } void -adjust_tags_parameter (char **str) +adjust_tags_parameter (gchar **str) { - /* TODO: replace line endings with single space? */ + /* TODO: replace line endings with a single space? */ remove_tags (str, "<!--", "-->"); /* comments */ remove_tags (str, "<", ">"); /* tags */ fix_entities (str); /* entities */ @@ -178,12 +178,12 @@ adjust_tags_parameter (char **str) * or as a parameter value of some tag ( $(TOKEN) ) * */ -char * -get_next_token (const char *s, char **start, char **end, gboolean *tag_parameter) +gchar * +get_next_token (const gchar *s, gchar **start, gchar **end, gboolean *tag_parameter) { - char *dollar; - char *end_brace; - char *b; + gchar *dollar; + gchar *end_brace; + gchar *b; *start = NULL; *end = NULL; diff --git a/src/replace-table.h b/src/replace-table.h index 8146f25..b59c9fb 100644 --- a/src/replace-table.h +++ b/src/replace-table.h @@ -53,8 +53,8 @@ void replace_table_process (gchar **buffer, ReplaceTable *table); * adjust_tags_parameter: adjust string for use as tag parameter value * - both funtions return newly allocated string */ -void adjust_tags_normal (char **str); -void adjust_tags_parameter (char **str); +void adjust_tags_normal (gchar **str); +void adjust_tags_parameter (gchar **str); @@ -66,4 +66,4 @@ void adjust_tags_parameter (char **str); * or as a parameter value of some tag ( $(TOKEN) ) * */ -char * get_next_token (const char *s, char **start, char **end, gboolean *tag_parameter); +gchar * get_next_token (const gchar *s, gchar **start, gchar **end, gboolean *tag_parameter); diff --git a/src/setup.c b/src/setup.c index 0b92022..1081fa4 100644 --- a/src/setup.c +++ b/src/setup.c @@ -42,25 +42,24 @@ gboolean find_setup_xml (TGallerySetup *setup) { - #define BUFFER_SIZE 65536 - - char *pth; - char *cwd; + gchar *pth; + gchar *cwd; gboolean b; - cwd = malloc (BUFFER_SIZE); - cwd = getcwd (cwd, BUFFER_SIZE); + cwd = g_get_current_dir (); pth = g_strconcat (cwd, "/", SETUP_XML, NULL); - free (cwd); + g_free (cwd); b = parse_setup_xml (pth, setup); g_free (pth); - if (b) return TRUE; + if (b) + return TRUE; - pth = g_strconcat (getenv ("HOME"), "/.cgg/", SETUP_XML, NULL); + pth = g_strconcat (g_getenv ("HOME"), "/.cgg/", SETUP_XML, NULL); b = parse_setup_xml (pth, setup); g_free (pth); - if (b) return TRUE; + if (b) + return TRUE; pth = g_strconcat (DATADIR, "/cgg/", SETUP_XML, NULL); b = parse_setup_xml (pth, setup); @@ -73,20 +72,20 @@ find_setup_xml (TGallerySetup *setup) * parse_setup_xml: XML parser for setup.xml file */ gboolean -parse_setup_xml (const char *filename, TGallerySetup *setup) +parse_setup_xml (const gchar *filename, TGallerySetup *setup) { TXMLFile *xml; - char *s; + gchar *s; xml = xml_parser_load (filename); if (xml == NULL) - return FALSE; + return FALSE; /* initialize data struct */ if (setup == NULL) - return FALSE; + return FALSE; memset (setup, 0, sizeof (TGallerySetup)); - setup->setup_xml_path = strdup (filename); + setup->setup_xml_path = g_strdup (filename); setup->templates_path = xml_file_get_node_value (xml, "/gallery_setup/templates/path/text()"); setup->template_index = xml_file_get_node_value (xml, "/gallery_setup/templates/index/text()"); @@ -95,27 +94,27 @@ parse_setup_xml (const char *filename, TGallerySetup *setup) s = xml_file_get_node_value (xml, "/gallery_setup/templates/template_files/text()"); if (s) { setup->template_files = g_strsplit (s, "\n", -1); - free (s); + g_free (s); } s = xml_file_get_node_attribute (xml, "/gallery_setup/templates/support_files_use_common_root", "value"); setup->support_files_use_common_root = s ? strcasecmp (s, "yes") == 0 : FALSE; /* default to FALSE */ - if (s) g_free (s); + g_free (s); setup->index_file_name = xml_file_get_node_value (xml, "/gallery_setup/templates/index_file/text()"); if (setup->index_file_name == NULL || strlen (setup->index_file_name) == 0) - setup->index_file_name = strdup (DEFAULT_INDEX_FILENAME); + setup->index_file_name = g_strdup (DEFAULT_INDEX_FILENAME); setup->thumbnail_dir = xml_file_get_node_value (xml, "/gallery_setup/images/thumbnail_dir/text()"); if (setup->thumbnail_dir == NULL || strlen (setup->thumbnail_dir) == 0) - setup->thumbnail_dir = strdup (DEFAULT_THUMBNAIL_DIR); + setup->thumbnail_dir = g_strdup (DEFAULT_THUMBNAIL_DIR); setup->img_big_dir = xml_file_get_node_value (xml, "/gallery_setup/images/preview_dir/text()"); if (setup->img_big_dir == NULL || strlen (setup->img_big_dir) == 0) - setup->img_big_dir = strdup (DEFAULT_IMG_BIG_DIR); + setup->img_big_dir = g_strdup (DEFAULT_IMG_BIG_DIR); setup->img_orig_dir = xml_file_get_node_value (xml, "/gallery_setup/images/original_dir/text()"); if (setup->img_orig_dir == NULL || strlen (setup->img_orig_dir) == 0) - setup->img_orig_dir = strdup (DEFAULT_IMG_ORIG_DIR); + setup->img_orig_dir = g_strdup (DEFAULT_IMG_ORIG_DIR); setup->thumbnail_name_format = xml_file_get_node_value (xml, "/gallery_setup/images/thumbnail_name_format/text()"); if (setup->thumbnail_name_format == NULL || strlen (setup->thumbnail_name_format) == 0 || strstr (setup->thumbnail_name_format, "%s") == NULL) - setup->thumbnail_name_format = strdup (DEFAULT_THUMBNAIL_NAME_FORMAT); + setup->thumbnail_name_format = g_strdup (DEFAULT_THUMBNAIL_NAME_FORMAT); setup->thumbnail_landscape_width = xml_file_get_node_attribute_long (xml, "/gallery_setup/images/thumbnail", "landscape_w", 0); @@ -136,28 +135,28 @@ parse_setup_xml (const char *filename, TGallerySetup *setup) s = xml_file_get_node_attribute (xml, "/gallery_setup/images/preload", "value"); setup->preload = s ? strcasecmp (s, "yes") == 0 : TRUE; /* default to TRUE */ - if (s) g_free (s); + g_free (s); s = xml_file_get_node_attribute (xml, "/gallery_setup/images/use_iptc_exif", "value"); setup->use_iptc_exif = s ? strcasecmp (s, "yes") == 0 : FALSE; /* default to FALSE */ - if (s) g_free (s); + g_free (s); s = xml_file_get_node_attribute (xml, "/gallery_setup/images/erase_embed_thumbnail", "value"); setup->erase_exif_thumbnail = s ? strcasecmp (s, "yes") == 0 : FALSE; /* default to FALSE */ - if (s) g_free (s); + g_free (s); s = xml_file_get_node_attribute (xml, "/gallery_setup/meta/use_title_as_meta", "value"); setup->use_title_as_meta = s ? strcasecmp (s, "yes") == 0 : TRUE; /* default to TRUE */ - if (s) g_free (s); + g_free (s); setup->site_title = xml_file_get_node_attribute (xml, "/gallery_setup/meta/site", "title"); setup->add_copyright = xml_file_get_node_value (xml, "/gallery_setup/meta/add_copyright/text()"); s = xml_file_get_node_attribute (xml, "/gallery_setup/navigation/use_inpage_links", "value"); setup->use_inpage_links = s ? strcasecmp (s, "yes") == 0 : TRUE; /* default to TRUE */ - if (s) g_free (s); + g_free (s); s = xml_file_get_node_attribute (xml, "/gallery_setup/navigation/show_go_up", "value"); setup->show_go_up = s ? strcasecmp (s, "yes") == 0 : TRUE; /* default to TRUE */ - if (s) g_free (s); + g_free (s); s = xml_file_get_node_attribute (xml, "/gallery_setup/navigation/show_exif_table", "value"); setup->show_exif_table = s ? strcasecmp (s, "yes") == 0 : TRUE; /* default to TRUE */ - if (s) g_free (s); + g_free (s); setup->nofullsize = xml_file_get_node_present (xml, "/gallery_setup/images/nofullsize"); @@ -197,9 +196,9 @@ parse_setup_xml (const char *filename, TGallerySetup *setup) int -test_tmpl_access (const char *dir, const char *path) +test_tmpl_access (const gchar *dir, const gchar *path) { - char *s; + gchar *s; int b; s = g_strconcat (dir, "/", path, NULL); @@ -209,9 +208,10 @@ test_tmpl_access (const char *dir, const char *path) } int -test_tmpl_files (const char *dir, TGallerySetup *setup) +test_tmpl_files (const gchar *dir, TGallerySetup *setup) { - return test_tmpl_access (dir, setup->template_album) | test_tmpl_access (dir, setup->template_photo) | + return test_tmpl_access (dir, setup->template_album) | + test_tmpl_access (dir, setup->template_photo) | test_tmpl_access (dir, setup->template_index); } @@ -219,11 +219,11 @@ test_tmpl_files (const char *dir, TGallerySetup *setup) * find_templates_directory: absolute/relative path checks, trying to find templates directory * - returned string should be freed */ -char * +gchar * find_templates_directory (TGallerySetup *setup) { - char *base_dir; - char *pth; + gchar *base_dir; + gchar *pth; if (IS_DIR_SEP (*setup->templates_path)) { @@ -232,7 +232,7 @@ find_templates_directory (TGallerySetup *setup) #endif if (! test_tmpl_files (setup->templates_path, setup)) - return strdup (setup->templates_path); + return g_strdup (setup->templates_path); } else { @@ -260,45 +260,26 @@ void free_setup_data (TGallerySetup *setup) { if (setup) { - if (setup->real_templates_dir) - free (setup->real_templates_dir); - if (setup->setup_xml_path) - free (setup->setup_xml_path); - if (setup->templates_path) - free (setup->templates_path); - if (setup->template_index) - free (setup->template_index); - if (setup->template_album) - free (setup->template_album); - if (setup->template_photo) - free (setup->template_photo); - if (setup->template_files) - g_strfreev (setup->template_files); - if (setup->index_file_name) - free (setup->index_file_name); - if (setup->footer) - free (setup->footer); - if (setup->meta_author) - free (setup->meta_author); - if (setup->border_style) - free (setup->border_style); - if (setup->site_title) - free (setup->site_title); - if (setup->add_copyright) - free (setup->add_copyright); - if (setup->favicon_file) - free (setup->favicon_file); - if (setup->favicon_type) - free (setup->favicon_type); - if (setup->thumbnail_dir) - free (setup->thumbnail_dir); - if (setup->img_big_dir) - free (setup->img_big_dir); - if (setup->img_orig_dir) - free (setup->img_orig_dir); - if (setup->thumbnail_name_format) - free (setup->thumbnail_name_format); - free (setup); + g_free (setup->real_templates_dir); + g_free (setup->setup_xml_path); + g_free (setup->templates_path); + g_free (setup->template_index); + g_free (setup->template_album); + g_free (setup->template_photo); + g_strfreev (setup->template_files); + g_free (setup->index_file_name); + g_free (setup->footer); + g_free (setup->meta_author); + g_free (setup->border_style); + g_free (setup->site_title); + g_free (setup->add_copyright); + g_free (setup->favicon_file); + g_free (setup->favicon_type); + g_free (setup->thumbnail_dir); + g_free (setup->img_big_dir); + g_free (setup->img_orig_dir); + g_free (setup->thumbnail_name_format); + g_free (setup); setup = NULL; } } diff --git a/src/setup.h b/src/setup.h index 6bc25cb..fc04616 100644 --- a/src/setup.h +++ b/src/setup.h @@ -37,26 +37,26 @@ typedef struct { gboolean verbose; gboolean update_mode; - char *real_templates_dir; + gchar *real_templates_dir; - char *setup_xml_path; + gchar *setup_xml_path; - char *templates_path; - char *template_index; - char *template_album; - char *template_photo; - char **template_files; + gchar *templates_path; + gchar *template_index; + gchar *template_album; + gchar *template_photo; + gchar **template_files; gboolean support_files_use_common_root; - char *index_file_name; - char *thumbnail_dir; - char *img_big_dir; - char *img_orig_dir; - char *thumbnail_name_format; - - char *footer; - char *meta_author; - char *meta_description; - char *meta_keywords; + gchar *index_file_name; + gchar *thumbnail_dir; + gchar *img_big_dir; + gchar *img_orig_dir; + gchar *thumbnail_name_format; + + gchar *footer; + gchar *meta_author; + gchar *meta_description; + gchar *meta_keywords; gboolean use_title_as_meta; int thumbnail_quality; @@ -71,21 +71,21 @@ typedef struct { unsigned long preview_portrait_width; unsigned long preview_portrait_height; - char *border_style; + gchar *border_style; gboolean nofullsize; gboolean preload; gboolean use_iptc_exif; gboolean erase_exif_thumbnail; - char *site_title; - char *add_copyright; + gchar *site_title; + gchar *add_copyright; gboolean use_inpage_links; gboolean show_go_up; gboolean show_exif_table; - char *favicon_file; - char *favicon_type; + gchar *favicon_file; + gchar *favicon_type; } TGallerySetup; @@ -98,7 +98,7 @@ gboolean find_setup_xml (TGallerySetup *setup); /* * parse_setup_xml: XML parser for setup.xml file */ -gboolean parse_setup_xml (const char *filename, TGallerySetup *setup); +gboolean parse_setup_xml (const gchar *filename, TGallerySetup *setup); /* * free_setup_data: free allocated setup data @@ -109,7 +109,7 @@ void free_setup_data (TGallerySetup *setup); * find_templates_directory: absolute/relative path checks, trying to find templates directory * - returned string should be freed */ -char *find_templates_directory (TGallerySetup *setup); +gchar *find_templates_directory (TGallerySetup *setup); #endif /* __SETUP_H__ */ diff --git a/src/xml-parser.c b/src/xml-parser.c index 34c0ebd..8c4301b 100644 --- a/src/xml-parser.c +++ b/src/xml-parser.c @@ -37,18 +37,17 @@ * xml_parser_load: initialize and load the XML document */ TXMLFile * -xml_parser_load (const char *filename) +xml_parser_load (const gchar *filename) { TXMLFile *file; - file = malloc (sizeof (TXMLFile)); - memset (file, 0, sizeof (TXMLFile)); + file = g_malloc0 (sizeof (TXMLFile)); /* Load XML document */ file->doc = xmlParseFile (filename); if (file->doc == NULL) { log_error ("Error: unable to parse file \"%s\"\n", filename); - free (file); + g_free (file); return NULL; } @@ -57,7 +56,7 @@ xml_parser_load (const char *filename) if (file->xpathCtx == NULL) { log_error ("Error: unable to create new XPath context\n"); xmlFreeDoc (file->doc); - free (file); + g_free (file); return FALSE; } @@ -74,24 +73,24 @@ xml_parser_close (TXMLFile *file) if (file) { xmlXPathFreeContext (file->xpathCtx); - xmlFreeDoc (file->doc); - free (file); - file = NULL; + xmlFreeDoc (file->doc); + g_free (file); + file = NULL; } } /* * xml_file_get_node_name: retrieve name of the XPath node */ -char * -xml_file_get_node_name (TXMLFile *file, const char *x_path) +gchar * +xml_file_get_node_name (TXMLFile *file, const gchar *x_path) { xmlXPathObjectPtr xpathObj; xmlNodePtr cur; - char *attrv; + gchar *attrv; if ((! file) || (! x_path)) - return NULL; + return NULL; /* Evaluate xpath expression */ xpathObj = xmlXPathEvalExpression ((const xmlChar *) x_path, file->xpathCtx); @@ -104,7 +103,7 @@ xml_file_get_node_name (TXMLFile *file, const char *x_path) if ((xpathObj->nodesetval) && (xpathObj->nodesetval->nodeNr > 0)) { cur = xpathObj->nodesetval->nodeTab[0]; if (cur->name) - attrv = strdup ((const char *) cur->name); + attrv = g_strdup ((const gchar *) cur->name); } xmlXPathFreeObject (xpathObj); @@ -117,16 +116,16 @@ xml_file_get_node_name (TXMLFile *file, const char *x_path) * - multiple matched nodes will be concatenated into one string * - otherwise please use [0], [1] etc. quantificators */ -char * -xml_file_get_node_value (TXMLFile *file, const char *x_path) +gchar * +xml_file_get_node_value (TXMLFile *file, const gchar *x_path) { xmlXPathObjectPtr xpathObj; xmlNodePtr cur; - char *val, *valx; + gchar *val, *valx; int i; if ((! file) || (! x_path)) - return NULL; + return NULL; /* Evaluate xpath expression */ xpathObj = xmlXPathEvalExpression ((const xmlChar *) x_path, file->xpathCtx); @@ -152,11 +151,11 @@ xml_file_get_node_value (TXMLFile *file, const char *x_path) { if (val == NULL) { - val = g_strdup ((char *) cur->content); + val = g_strdup ((gchar *) cur->content); } else { - valx = g_strconcat (val, (char *) cur->content, NULL); + valx = g_strconcat (val, (gchar *) cur->content, NULL); g_free (val); val = valx; } @@ -172,16 +171,16 @@ xml_file_get_node_value (TXMLFile *file, const char *x_path) /* * xml_file_get_node_attribute: retrieve attribute value from XPath node */ -char * -xml_file_get_node_attribute (TXMLFile *file, const char *x_path, const char *attr) +gchar * +xml_file_get_node_attribute (TXMLFile *file, const gchar *x_path, const gchar *attr) { xmlXPathObjectPtr xpathObj; xmlNodePtr cur; xmlChar *attrvx; - char *attrv; + gchar *attrv; if ((! file) || (! x_path)) - return NULL; + return NULL; /* Evaluate xpath expression */ xpathObj = xmlXPathEvalExpression ((const xmlChar *) x_path, file->xpathCtx); @@ -195,7 +194,7 @@ xml_file_get_node_attribute (TXMLFile *file, const char *x_path, const char *att cur = xpathObj->nodesetval->nodeTab[0]; attrvx = xmlGetProp (cur, (const xmlChar *) attr); if (attrvx) { - attrv = strdup ((char*) attrvx); + attrv = g_strdup ((gchar*) attrvx); xmlFree (attrvx); } @@ -209,18 +208,18 @@ xml_file_get_node_attribute (TXMLFile *file, const char *x_path, const char *att return attrv; } -long -xml_file_get_node_attribute_long (TXMLFile *file, const char *x_path, const char *attr, const int _default) +long int +xml_file_get_node_attribute_long (TXMLFile *file, const gchar *x_path, const gchar *attr, const int _default) { - char *s; + gchar *s; long int i; s = xml_file_get_node_attribute (file, x_path, attr); if (s == NULL) - return _default; + return _default; i = atol (s); - free (s); + g_free (s); return i; } @@ -228,9 +227,9 @@ xml_file_get_node_attribute_long (TXMLFile *file, const char *x_path, const char * xml_file_get_node_present: existency test of the XPath node */ gboolean -xml_file_get_node_present (TXMLFile *file, const char *x_path) +xml_file_get_node_present (TXMLFile *file, const gchar *x_path) { - return xml_file_node_get_children_count (file, x_path) > 0; + return (xml_file_node_get_children_count (file, x_path) > 0); } @@ -238,13 +237,13 @@ xml_file_get_node_present (TXMLFile *file, const char *x_path) * xml_file_node_get_children_count: retrieve number of children items of the specified XPath node */ int -xml_file_node_get_children_count (TXMLFile *file, const char *x_path) +xml_file_node_get_children_count (TXMLFile *file, const gchar *x_path) { xmlXPathObjectPtr xpathObj; int count; if ((! file) || (! x_path)) - return 0; + return 0; /* Evaluate xpath expression */ xpathObj = xmlXPathEvalExpression ((const xmlChar *) x_path, file->xpathCtx); diff --git a/src/xml-parser.h b/src/xml-parser.h index 02be628..53abf08 100644 --- a/src/xml-parser.h +++ b/src/xml-parser.h @@ -22,8 +22,8 @@ typedef struct { - xmlDocPtr doc; - xmlXPathContextPtr xpathCtx; + xmlDocPtr doc; + xmlXPathContextPtr xpathCtx; } TXMLFile; @@ -31,7 +31,7 @@ typedef struct { /* * xml_parser_load: initialize and load the XML document */ -TXMLFile * xml_parser_load (const char *filename); +TXMLFile * xml_parser_load (const gchar *filename); /* * xml_parser_close: close the XML document parser @@ -41,27 +41,27 @@ void xml_parser_close (TXMLFile *file); /* * xml_file_get_node_name: retrieve name of the XPath node */ -char * xml_file_get_node_name (TXMLFile *file, const char *x_path); +gchar * xml_file_get_node_name (TXMLFile *file, const gchar *x_path); /* * xml_file_get_node_value: retrieve string value from XPath node * - multiple matched nodes will be concatenated into one string * - otherwise please use [0], [1] etc. quantificators */ -char * xml_file_get_node_value (TXMLFile *file, const char *x_path); +gchar * xml_file_get_node_value (TXMLFile *file, const gchar *x_path); /* * xml_file_get_node_attribute: retrieve attribute value from XPath node */ -char * xml_file_get_node_attribute (TXMLFile *file, const char *x_path, const char *attr); -long xml_file_get_node_attribute_long (TXMLFile *file, const char *x_path, const char *attr, const int _default); +gchar * xml_file_get_node_attribute (TXMLFile *file, const gchar *x_path, const gchar *attr); +long int xml_file_get_node_attribute_long (TXMLFile *file, const gchar *x_path, const gchar *attr, const int _default); /* * xml_file_get_node_present: existency test of the XPath node */ -gboolean xml_file_get_node_present (TXMLFile *file, const char *x_path); +gboolean xml_file_get_node_present (TXMLFile *file, const gchar *x_path); /* * xml_file_node_get_children_count: retrieve number of children items of the specified XPath node */ -int xml_file_node_get_children_count (TXMLFile *file, const char *x_path); +int xml_file_node_get_children_count (TXMLFile *file, const gchar *x_path); |
