summaryrefslogtreecommitdiff
path: root/src/cgg.c
diff options
context:
space:
mode:
authorTomas Bzatek <tbzatek@users.sourceforge.net>2009-02-26 22:50:39 +0100
committerTomas Bzatek <tbzatek@users.sourceforge.net>2009-02-26 22:50:39 +0100
commit89c58dc04c264c5778ae34d1428e12483f3ac5ac (patch)
treed5aef506841b3b0e2e91016d0c0bbb608535873c /src/cgg.c
parent10a77c7a1c4648693ded958d6ac8641afcdf1d34 (diff)
downloadcataract-89c58dc04c264c5778ae34d1428e12483f3ac5ac.tar.xz
Autotoolize
Diffstat (limited to 'src/cgg.c')
-rw-r--r--src/cgg.c155
1 files changed, 155 insertions, 0 deletions
diff --git a/src/cgg.c b/src/cgg.c
new file mode 100644
index 0000000..042e114
--- /dev/null
+++ b/src/cgg.c
@@ -0,0 +1,155 @@
+/* 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.
+ */
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <unistd.h>
+
+#include <glib.h>
+
+#include <libxml/xmlmemory.h>
+
+#include <config.h>
+
+#include "cgg-config.h"
+#include "setup.h"
+#include "generators.h"
+
+
+
+
+
+
+/*
+ * parse_cmd: parse commandline and fill global variable parameters
+ */
+gboolean
+parse_cmd (int argc, char* argv[], char **source_dir, char **dst_dir, gboolean *verbose)
+{
+ static gboolean _verbose = FALSE;
+ static gchar *_source_dir = NULL;
+ static gchar *_dst_dir = NULL;
+
+ static GOptionEntry entries[] =
+ {
+ { "verbose", 'v', 0, G_OPTION_ARG_NONE, &_verbose, "Be verbose", NULL },
+ { "source", 's', 0, G_OPTION_ARG_STRING, &_source_dir, "Specifies path to source structure", NULL },
+ { "output", 'o', 0, G_OPTION_ARG_STRING, &_dst_dir, "Generate files to the specified directory instead of current", NULL },
+ { NULL }
+ };
+
+ GError *error = NULL;
+ GOptionContext *context;
+ char *s1;
+
+ g_set_prgname ("cgg");
+
+ context = g_option_context_new ("- web gallery generator");
+ s1 = g_strdup_printf ("cgg v%s [%s] Copyright (c) %s Tomas Bzatek", VERSION, APP_BUILD_DATE, APP_COPYRIGHT_DATE);
+ g_option_context_set_summary (context, s1);
+ g_free (s1);
+ g_option_context_add_main_entries (context, entries, NULL);
+
+ if (argc == 1) {
+ s1 = g_option_context_get_help (context, TRUE, NULL);
+ g_print ("%s", s1);
+ g_free (s1);
+ g_option_context_free (context);
+ return FALSE;
+ }
+
+ if (! g_option_context_parse (context, &argc, &argv, &error)) {
+ g_print ("option parsing failed: %s\n", error->message);
+ s1 = g_option_context_get_help (context, TRUE, NULL);
+ g_print ("%s", s1);
+ g_free (s1);
+ g_option_context_free (context);
+ return FALSE;
+ }
+ g_option_context_free (context);
+
+ *source_dir = _source_dir;
+ *dst_dir = _dst_dir;
+ *verbose = _verbose;
+
+ return TRUE;
+}
+
+
+
+int
+main(int argc, char* argv[])
+{
+ char *source_dir;
+ char *dst_dir;
+ gboolean verbose;
+ TGallerySetup *setup;
+
+ /*
+ * this initialize the library and check potential ABI mismatches
+ * between the version it was compiled for and the actual shared
+ * library used.
+ */
+ LIBXML_TEST_VERSION;
+
+ source_dir = NULL;
+ dst_dir = NULL;
+ setup = malloc(sizeof(TGallerySetup));
+
+
+ /* Parse commandline */
+ if (! parse_cmd (argc, argv, &source_dir, &dst_dir, &verbose))
+ return -1;
+
+ if ((! source_dir) || (access (source_dir, R_OK))) {
+ fprintf (stderr, "error: source directory must be specified and pointing to valid structure\n");
+ return -4;
+ }
+ if (! dst_dir) {
+ fprintf (stderr, "error: target directory must be specified\n");
+ return -5;
+ }
+
+ /* Read gallery settings */
+ if (! find_setup_xml (setup)) {
+ fprintf (stderr, "error: could not parse gallery settings file\n");
+ return -2;
+ }
+
+ setup->real_templates_dir = find_templates_directory (setup);
+ if (setup->real_templates_dir == NULL) {
+ fprintf (stderr, "error: could not determine templates directory\n");
+ return -3;
+ }
+
+
+ /* Start building the gallery tree */
+ setup->verbose = verbose;
+ build_tree (setup, source_dir, dst_dir, NULL);
+
+
+ /* Cleanup function for the XML library. */
+ xmlCleanupParser();
+
+ free (source_dir);
+ free (dst_dir);
+ free_setup_data (setup);
+
+ return (0);
+}