From 3e213519e67c3f9665a4eb1635f5ef37d7171809 Mon Sep 17 00:00:00 2001 From: Tomas Bzatek Date: Sun, 12 Dec 2010 13:40:22 +0100 Subject: setup: Code cleanup --- src/cgg.c | 3 ++- src/setup.c | 55 +++++++++++++++++++++++++++---------------------------- src/setup.h | 4 ++-- 3 files changed, 31 insertions(+), 31 deletions(-) (limited to 'src') diff --git a/src/cgg.c b/src/cgg.c index 5ec8652..6f37760 100644 --- a/src/cgg.c +++ b/src/cgg.c @@ -154,7 +154,8 @@ main (int argc, char* argv[]) } /* Read gallery settings */ - if (! find_setup_xml (setup)) { + setup = find_setup_xml (); + if (! setup) { fprintf (stderr, "error: could not parse gallery settings file\n"); return -2; } diff --git a/src/setup.c b/src/setup.c index daa1ff0..a639348 100644 --- a/src/setup.c +++ b/src/setup.c @@ -40,56 +40,56 @@ /* * find_setup_xml: try to find setup.xml in standard paths */ -gboolean -find_setup_xml (TGallerySetup *setup) +TGallerySetup * +find_setup_xml () { gchar *pth; gchar *cwd; - gboolean b; + TGallerySetup *setup; - b = FALSE; + setup = NULL; cwd = g_get_current_dir (); pth = g_strconcat (cwd, "/", SETUP_XML, NULL); g_free (cwd); if (g_access (pth, R_OK) == 0) - b = parse_setup_xml (pth, setup); + setup = parse_setup_xml (pth); g_free (pth); - if (b) - return TRUE; - pth = g_strconcat (g_getenv ("HOME"), "/.cgg/", SETUP_XML, NULL); - if (g_access (pth, R_OK) == 0) - b = parse_setup_xml (pth, setup); - g_free (pth); - if (b) - return TRUE; + if (! setup) { + pth = g_strconcat (g_getenv ("HOME"), "/.cgg/", SETUP_XML, NULL); + if (g_access (pth, R_OK) == 0) + setup = parse_setup_xml (pth); + g_free (pth); + } - pth = g_strconcat (DATADIR, "/cgg/", SETUP_XML, NULL); - if (g_access (pth, R_OK) == 0) - b = parse_setup_xml (pth, setup); - g_free (pth); - return b; + if (! setup) { + pth = g_strconcat (DATADIR, "/cgg/", SETUP_XML, NULL); + if (g_access (pth, R_OK) == 0) + setup = parse_setup_xml (pth); + g_free (pth); + } + + return setup; } /* * parse_setup_xml: XML parser for setup.xml file */ -gboolean -parse_setup_xml (const gchar *filename, TGallerySetup *setup) +TGallerySetup * +parse_setup_xml (const gchar *filename) { TXMLFile *xml; gchar *s; + TGallerySetup *setup; xml = xml_parser_load (filename); if (xml == NULL) - return FALSE; + return NULL; /* initialize data struct */ - if (setup == NULL) - return FALSE; - memset (setup, 0, sizeof (TGallerySetup)); + setup = g_malloc0 (sizeof (TGallerySetup)); setup->setup_xml_path = g_strdup (filename); setup->templates_path = xml_file_get_node_value (xml, "/gallery_setup/templates/path/text()"); @@ -166,12 +166,12 @@ parse_setup_xml (const gchar *filename, TGallerySetup *setup) g_free (s); xml_parser_close (xml); - return TRUE; + return setup; } -int +static int test_tmpl_access (const gchar *dir, const gchar *path) { gchar *s; @@ -183,7 +183,7 @@ test_tmpl_access (const gchar *dir, const gchar *path) return b; } -int +static int test_tmpl_files (const gchar *dir, TGallerySetup *setup) { return test_tmpl_access (dir, setup->template_album) | @@ -251,6 +251,5 @@ free_setup_data (TGallerySetup *setup) g_free (setup->feed_title); g_free (setup->feed_base_url); g_free (setup); - setup = NULL; } } diff --git a/src/setup.h b/src/setup.h index 16665c4..188191a 100644 --- a/src/setup.h +++ b/src/setup.h @@ -107,12 +107,12 @@ typedef struct { /* * find_setup_xml: try to find setup.xml in standard paths */ -gboolean find_setup_xml (TGallerySetup *setup); +TGallerySetup * find_setup_xml (); /* * parse_setup_xml: XML parser for setup.xml file */ -gboolean parse_setup_xml (const gchar *filename, TGallerySetup *setup); +TGallerySetup * parse_setup_xml (const gchar *filename); /* * free_setup_data: free allocated setup data -- cgit v1.2.3