From 2d29c541862a2e500bb5ec42cd7fa88c385b6ca5 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Sat, 20 Jan 2018 10:28:34 +0100 Subject: [PATCH] Added command line tool zdbt. --- .gitignore | 3 +- Makefile.am | 2 +- configure.ac | 1 + zdbt/Makefile.am | 13 ++++++++ zdbt/zdbt.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 zdbt/Makefile.am create mode 100644 zdbt/zdbt.c diff --git a/.gitignore b/.gitignore index 7b7a89d..3c98c91 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/Makefile.am b/Makefile.am index d3043d9..701ebca 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 diff --git a/configure.ac b/configure.ac index 22a82b5..d6047e0 100644 --- a/configure.ac +++ b/configure.ac @@ -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 index 0000000..69d2e35 --- /dev/null +++ b/zdbt/Makefile.am @@ -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 index 0000000..7fc6cf3 --- /dev/null +++ b/zdbt/zdbt.c @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2018 Andrea Zagli + * + * 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; +} -- 2.49.0