]> saetta.ns0.it Git - libzakdbt/commitdiff
Added command line tool zdbt.
authorAndrea Zagli <azagli@libero.it>
Sat, 20 Jan 2018 09:28:34 +0000 (10:28 +0100)
committerAndrea Zagli <azagli@libero.it>
Sat, 20 Jan 2018 09:28:34 +0000 (10:28 +0100)
.gitignore
Makefile.am
configure.ac
zdbt/Makefile.am [new file with mode: 0644]
zdbt/zdbt.c [new file with mode: 0644]

index 7b7a89ddf94cdea73477fca3d2ff7e96386ca2d6..3c98c917fe9281a27f5bcf1342341cc223301775 100644 (file)
@@ -53,4 +53,5 @@ Rules-quot
 compile
 config.h.in
 *.gir
-*.typelib
\ No newline at end of file
+*.typelib
+zdbt/zdbt
\ No newline at end of file
index d3043d9ecb19ee17aea59322cfaa93c9750d8880..701ebcaae7cd6dd8129bf047ec33063a03c6f03d 100644 (file)
@@ -1,6 +1,6 @@
 DISTCHECK_CONFIGURE_FLAGS =  --enable-introspection --enable-gtk-doc
 
-SUBDIRS = src tests docs
+SUBDIRS = src tests zdbt docs
 
 ACLOCAL_AMFLAGS = -I m4
 
index 22a82b547d6e2613c6d27928de43725b2330c1cf..d6047e02a8b307c5069e45fdfc0bc3b663183259 100644 (file)
@@ -54,6 +54,7 @@ AC_CONFIG_FILES([
   Makefile
   src/Makefile
   tests/Makefile
+  zdbt/Makefile
   docs/Makefile
   docs/reference/Makefile
   docs/reference/version.xml
diff --git a/zdbt/Makefile.am b/zdbt/Makefile.am
new file mode 100644 (file)
index 0000000..69d2e35
--- /dev/null
@@ -0,0 +1,13 @@
+AM_CPPFLAGS = $(WARN_CFLAGS) \
+              $(DISABLE_DEPRECATED_CFLAGS) \
+              $(DBT_CFLAGS) \
+              -I$(top_srcdir)/src
+
+LIBS = $(DBT_LIBS) \
+       -export-dynamic
+
+LDADD = $(top_builddir)/src/libzakdbt.la
+
+bin_PROGRAMS = zdbt
+
+zdbt_SOURCES = zdbt.c
diff --git a/zdbt/zdbt.c b/zdbt/zdbt.c
new file mode 100644 (file)
index 0000000..7fc6cf3
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2018 Andrea Zagli <azagli@libero.it>
+ *
+ *  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
+ *  (at your option) 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "libzakdbt.h"
+
+static gchar *cnc_string;
+static gchar *xml_filename;
+
+static GOptionEntry entries[] =
+{
+       { "cnc_string", 'c', 0, G_OPTION_ARG_STRING, &cnc_string, "Connection string to database", NULL },
+       { "xml_filename", 'x', 0, G_OPTION_ARG_FILENAME, &xml_filename, "ZakDbt xml file name", NULL },
+       { NULL }
+};
+
+int
+main (int argc, char **argv)
+{
+       GOptionContext *ctx;
+
+       GError *error;
+
+       ZakDbtDbt *dbt;
+
+       cnc_string = NULL;
+       xml_filename = NULL;
+
+       ctx = g_option_context_new ("");
+       g_option_context_add_main_entries (ctx, entries, "zdbt");
+       if (!g_option_context_parse (ctx, &argc, &argv, &error))
+               {
+                       g_warning ("Error on command line arguments: %s.",
+                                  error != NULL && error->message != NULL ? error->message : "no details");
+               }
+
+       if (cnc_string == NULL)
+               {
+                       g_message ("You must provide the connection string to database.");
+                       return 0;
+               }
+
+       if (xml_filename == NULL)
+               {
+                       g_message ("You must provide the ZakDbt xml file name.");
+                       return 0;
+               }
+
+       dbt = zak_dbt_dbt_new ();
+
+       zak_dbt_dbt_set_db_connection_from_string (dbt, cnc_string);
+       zak_dbt_dbt_set_xml_from_filename (dbt, xml_filename);
+
+       if (zak_dbt_dbt_db_is_updated (dbt))
+               {
+                       g_message ("Database is updated.");
+                       return 0;
+               }
+       else
+               {
+                       g_message ("Database is not updated.");
+               }
+
+       zak_dbt_dbt_transform (dbt);
+
+       return 0;
+}