[Gnucash-changes] r12242 - gnucash/branches/cashutil/src/bin - gnucash2 - test C start-up routine

Neil Williams codehelp at cvs.gnucash.org
Tue Jan 3 04:15:22 EST 2006


Author: codehelp
Date: 2006-01-03 04:15:18 -0500 (Tue, 03 Jan 2006)
New Revision: 12242
Trac: http://svn.gnucash.org/trac/changeset/12242

Added:
   gnucash/branches/cashutil/src/bin/gnucash2.c
   gnucash/branches/cashutil/src/bin/qof-main.c
   gnucash/branches/cashutil/src/bin/qof-main.h
Modified:
   gnucash/branches/cashutil/src/bin/
   gnucash/branches/cashutil/src/bin/Makefile.am
   gnucash/branches/cashutil/src/bin/overrides/
   gnucash/branches/cashutil/src/bin/test/
Log:
gnucash2 - test C start-up routine


Property changes on: gnucash/branches/cashutil/src/bin
___________________________________________________________________
Name: svn:ignore
   - .deps
.libs
*.diff
*.diffs
*.patch
*.log
*.xac.*.xac
Makefile
Makefile.in
gnucash
gnucash-env
gnucash-make-guids
gnucash-run-script
strsub
update-gnucash-gconf
   + .deps
.libs
*.diff
*.diffs
*.patch
*.log
*.xac.*.xac
Makefile
Makefile.in
gnucash
gnucash-env
gnucash-make-guids
gnucash-run-script
strsub
update-gnucash-gconf
semantic.cache
gnucash2



Modified: gnucash/branches/cashutil/src/bin/Makefile.am
===================================================================
--- gnucash/branches/cashutil/src/bin/Makefile.am	2006-01-03 04:02:42 UTC (rev 12241)
+++ gnucash/branches/cashutil/src/bin/Makefile.am	2006-01-03 09:15:18 UTC (rev 12242)
@@ -1,8 +1,34 @@
 # Order is important here.
 SUBDIRS = . overrides test
 
-AM_CFLAGS = -I${top_builddir} ${GLIB_CFLAGS}
+AM_CFLAGS = \
+ -I${top_builddir} \
+ -I${top_builddir}/src/business/business-core \
+ -I${top_builddir}/src/gnc-module \
+ -I${top_builddir}/src/engine \
+ -I${top_builddir}/src/gnome-utils \
+ -DLOCALE_DIR=\""$(datadir)/locale"\" \
+ ${QOF_CFLAGS} \
+ ${GTK_CFLAGS} \
+ ${GNOME_CFLAGS} \
+ ${GLIB_CFLAGS}
 
+bin_PROGRAMS = gnucash2
+
+gnucash2_SOURCES=\
+  gnucash2.c \
+  qof-main.c
+
+gnucash2_LDADD=\
+  ${top_srcdir}/src/gnome-utils/libgncmod-gnome-utils.la \
+  ${top_srcdir}/src/business/business-core/libcashbusobjects.la \
+  ${QOF_LIBS} \
+  ${GUILE_LIBS} \
+  ${GTK_LIBS} \
+  ${GNOME_LIBS} \
+  ${GLIB_LIBS}
+
+
 # We handle gnucash scripts in a somewhat unexpected way, but we do
 # this so that a user who doesn't necessarily have the right
 # directories in their path can still invoke these commands via their

Added: gnucash/branches/cashutil/src/bin/gnucash2.c
===================================================================
--- gnucash/branches/cashutil/src/bin/gnucash2.c	2006-01-03 04:02:42 UTC (rev 12241)
+++ gnucash/branches/cashutil/src/bin/gnucash2.c	2006-01-03 09:15:18 UTC (rev 12242)
@@ -0,0 +1,435 @@
+/***************************************************************************
+ *            gnucash2.c
+ *
+ *  Mon Dec 12 11:18:51 2005
+ *  Copyright  2005  Neil Williams
+ *  linux at codehelp.co.uk
+ ****************************************************************************/
+/*
+ *  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.
+ */
+
+#define _GNU_SOURCE
+#include "config.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <regex.h>
+#include <qof.h>
+#include <gmodule.h>
+#include <sys/stat.h>
+#include <gtk/gtkmain.h>
+#include <libgnome/libgnome.h>
+#include <libgnomeui/libgnomeui.h>
+#include "qof-main.h"
+#include "cashobjects.h"
+#include "gnc-module.h"
+#include "gnc-splash.h"
+#include "gncla-dir.h"
+#include "backend-bus.h"
+#include "gnc-file.h"
+#include "gnc-plugin-file-history.h"
+#ifndef HAVE_SETENV
+#include "setenv.h"
+#endif
+
+#define GNC_MOD_CLI "gnucash2-cli"
+#define GNC_QOF_LOG "/tmp/gnucash.trace"
+#define GNC_LIB_NAME "libgnc-backend-file.la"
+#define GNC_LIB_INIT "gnc_provider_init"
+
+/* used to print debug logs. */
+static QofLogModule log_module = GNC_MOD_CLI;
+static gboolean skip_auto = FALSE;
+#define ARGUMENT_BAD_OPTION	17227
+
+#define GNC_MAIN_OP(_) \
+ 	_(qof_op_noop, = 0) \
+	_(qof_op_list,)     \
+	_(qof_op_offline,)  \
+	_(qof_op_category,) \
+	_(qof_op_database,) \
+	_(qof_op_timespec,) \
+	_(qof_op_exclude,)  \
+	_(qof_op_sql,)      \
+	_(qof_op_sql_file,) \
+	_(qof_op_write, )   \
+	_(qof_op_explain,)  \
+	_(qof_op_vers,)     \
+	_(qof_op_compress,) \
+	_(qof_op_guile,)    \
+	_(qof_op_nofile,)   \
+	_(qof_op_debug,)
+
+	DEFINE_ENUM(qof_op_type, GNC_MAIN_OP)
+
+static gboolean
+load_bus_backend (const char *directory)
+{
+	typedef void (* bus_backend_init) (void);
+	GModule *bus_backend;
+	gchar *fullpath;
+	struct stat sbuf;
+	bus_backend_init bus_init;
+	gpointer g;
+
+	g_return_val_if_fail(g_module_supported(), FALSE);
+	fullpath = g_module_build_path(directory, "libgnc-backend-bus.la");
+	g_return_val_if_fail((stat(fullpath, &sbuf) == 0), FALSE);
+	bus_backend = g_module_open(fullpath, G_MODULE_BIND_LAZY);
+	if(!bus_backend) { 
+		PWARN ("%s: %s\n", PACKAGE, g_module_error ()); 
+		return FALSE;
+	}
+	g = &bus_init;
+	if (!g_module_symbol (bus_backend, "backend_business_add", g))
+	{
+		PWARN ("%s: %s\n", PACKAGE, g_module_error ());
+		return FALSE;
+	}
+	g_module_make_resident(bus_backend);
+	bus_init();
+	return TRUE;
+}
+
+static qof_main_context*
+gnc_cli_init(void)
+{
+	qof_main_context *gnc_cli;
+
+	qof_init();
+	/* register objects here */
+	g_return_val_if_fail(cashobjects_register(), NULL);
+	/* makes the business objects mandatory - fix. How? */
+	g_return_val_if_fail(bus_cashobjects_register(), NULL);
+	/* load the backends */
+	g_return_val_if_fail((qof_load_backend_library 
+		(QOF_LIB_DIR, QSF_BACKEND_LIB, QSF_MODULE_INIT)), NULL);
+	g_return_val_if_fail((qof_load_backend_library
+		(GNC_LIBDIR, GNC_LIB_NAME, GNC_LIB_INIT)), NULL);
+	g_return_val_if_fail(load_bus_backend(GNC_LIBDIR), NULL);
+	gnc_cli = g_new0(qof_main_context, 1);
+	return gnc_cli;
+}
+
+static void
+build_environment(void)
+{
+	gchar *gmp, *llp, *glp, *ltdlp;
+
+	gmp = g_strconcat(LIBDIR, "/gnucash:", 
+		DATADIR, "/guile-modules:",
+		DATADIR, "/scm:", 
+		getenv("GNC_MODULE_PATH"), 
+		NULL);
+	glp = g_strconcat(DATADIR, "/guile-modules:",
+		DATADIR, "/scm:",
+		getenv("GUILE_LOAD_PATH"), 
+		NULL);
+	llp = g_strconcat(LIBDIR, "/gnucash:", 
+		LIBDIR, ":",
+		getenv("LD_LIBRARY_PATH"), NULL);
+	ltdlp = g_strconcat(gmp, LIBDIR, ":", LIBDIR, "/gnucash:", 
+		getenv("LTDL_LIBRARY_PATH"), NULL);
+	setenv("GNC_MODULE_PATH", gmp, 1);
+	setenv("LD_LIBRARY_PATH", llp, 1);
+	setenv("GUILE_LOAD_PATH", glp, 1);
+	setenv("LTDL_LIBRARY_PATH", ltdlp, 1);
+	g_message ("set GNC_MODULE_PATH %s LD_LIBRARY_PATH %s"
+		" GUILE_LOAD_PATH %s LTDL_LIBRARY_PATH %s", gmp, llp, glp, ltdlp);
+}
+
+static void
+guile_main(void *closure, int argc, char ** argv)
+{
+	GnomeProgram *gnucash2;
+
+	build_environment();
+	gtk_set_locale ();
+	gtk_init (&argc, &argv);
+	gnucash2 = gnome_program_init(PACKAGE, VERSION,
+		LIBGNOMEUI_MODULE, argc, argv, 
+		GNOME_PROGRAM_STANDARD_PROPERTIES, 
+		GNOME_PARAM_NONE);
+	gnome_program_postinit(gnucash2);
+	gnc_module_system_init();
+	gnc_show_splash_screen();
+	gnc_update_splash_screen(_("Loading modules... "));
+	/** autoloading.
+	Some may need to be loaded in sequence but each should
+	handle this internally - by calling it's own dependencies.
+	Each can only be loaded once anyway.
+	
+	\note the engine module has been removed and replaced with
+	gnc_cli_init - each gnc-mod has been modified to avoid 
+	calling the old engine.
+	*/
+	gnc_module_load_all(GNC_MOD_INTERFACE_VERSION);
+/*	gnc_module_load("gnucash/app-utils", 0);
+	gnc_module_load("gnucash/import-export", 0);
+	gnc_module_load("gnucash/register/ledger-core", 0);
+	gnc_module_load("gnucash/register/register-core", 0);
+	gnc_module_load("gnucash/register/register-gnome", 0);
+	gnc_module_load("gnucash/import-export/binary-import", 0);
+	gnc_module_load("gnucash/import-export/qif-import", 0);
+	gnc_module_load("gnucash/import-export/ofx", 0);
+	gnc_module_load("gnucash/import-export/mt940", 0);
+	gnc_module_load("gnucash/import-export/log-replay", 0);
+	gnc_module_load("gnucash/import-export/hbci", 0);
+	gnc_module_load("gnucash/report/report-system", 0);
+	gnc_module_load("gnucash/report/stylesheets", 0);
+	gnc_module_load("gnucash/report/standard-reports", 0);
+	gnc_module_load("gnucash/report/utility-reports", 0);
+	gnc_module_load("gnucash/report/locale-specific/us", 0);
+	gnc_module_load("gnucash/report/report-gnome", 0);
+	gnc_module_load("gnucash/business-gnome", 0);*/
+	/* handle --no-file */
+	if(!skip_auto)
+	{
+		gchar *last_file;
+
+		last_file = gnc_history_get_last();
+		gnc_file_open_file(last_file);
+	}
+	/** \todo Replace this scheme:
+	    (gnc:update-splash-screen (_ "Checking Finance::Quote..."))
+		gnc:fq-check-sources perl quotes/finance-quote-check
+		(gnc:update-splash-screen (_ "Loading configs..."))
+		(define (gnc:load-account-file)
+		(let ((file (gnc:account-file-to-load)))
+		(if file
+        (begin
+          (gnc:update-splash-screen (_ "Loading data..."))
+          (and (not (gnc:file-open-file file))
+             (begin
+                (gnc:destroy-splash-screen)
+                (gnc:new-user-dialog))
+              (begin
+                (gnc:destroy-splash-screen)
+                (gnc:main-window-set-progressbar-window main-window)
+                (gnc:load-account-file)
+	*/
+	gnc_destroy_splash_screen();
+}
+
+int
+main (int argc, const char *argv[])
+{
+	const char *help_header_text, *input_file;
+	qof_main_context *gnc_cli;
+	gboolean debug_on;
+	poptContext pc;
+	int optc, gz_level;
+	qof_op_type cli_command;
+	QOF_OP_VARS
+
+	struct poptOption options[] = {
+		{"gui", 'g', POPT_ARG_NONE, NULL, qof_op_guile,
+		_("Load the Gtk/guile graphic interface."
+			"Options are ignored."), NULL},
+		{"no-file", 0, POPT_ARG_NONE, NULL, qof_op_nofile,
+		_("Omit automatic load of the last file. "
+			"Requires -g"), NULL},
+		QOF_CLI_OPTIONS
+		POPT_TABLEEND
+	};
+	cli_command = qof_op_noop;
+	debug_on = FALSE;
+	skip_auto = FALSE;
+	QOF_OP_INIT;
+	input_file = NULL;
+
+	help_header_text = _(
+		"\n"
+		"   GnuCash: Open Source Accounting Software \n"
+		"   See http://www.gnucash.org/\n"
+		"   Use --help for more detailed help or\n"
+		"   -g to load the gnucash main window.\n"
+		"   Use exactly one of -x -l -g --explain;\n"
+		"   options are -c -t -w, -d or -e, -s or -f.\n\n");
+
+	#ifdef ENABLE_NLS
+	setlocale (LC_ALL, "");
+	bindtextdomain (GETTEXT_PACKAGE, LOCALE_DIR);
+	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+	textdomain (GETTEXT_PACKAGE);
+	#endif
+	pc = poptGetContext (PACKAGE, argc, argv, options, 0);
+
+	poptSetOtherOptionHelp (pc, help_header_text);
+
+	if (argc < 2)
+	{
+		poptPrintUsage (pc, stderr, 0);
+		return EXIT_FAILURE;
+	}
+	gnc_cli = gnc_cli_init();
+	if(!gnc_cli) 
+	{ 
+		PERR (" Failed to initialise!");
+		return EXIT_FAILURE; 
+	}
+	while ((optc = poptGetNextOpt (pc)) >= 0)
+	{
+		switch (optc)
+		{
+			/* commands - mutually exclusive */
+			case qof_op_offline:
+			case qof_op_list:
+			case qof_op_explain:
+			case qof_op_guile:
+			{
+				if (qof_op_noop != cli_command)
+				{
+					fprintf (stderr, _("%s: ERROR: specify only one of"
+						" -x -l -g or --explain.\n"), PACKAGE);
+					poptPrintUsage(pc, stderr, 0);
+					return EXIT_FAILURE;
+				}
+				cli_command = optc;
+				break;
+			}
+			case qof_op_vers :
+			{
+				fprintf (stdout, _("\n This is %s v%s\n"), PACKAGE, VERSION);
+				fprintf (stdout, _(" Open Source Accounting Software.\n"));
+				fprintf (stdout, "\n Copyright (c) 2005 "
+					"Neil Williams <linux at codehelp.co.uk>\n");
+				/* Translators: Add or subtract dots to keep the translated
+				lines aligned vertically */
+//				fprintf (stdout, _(" Build target.........: %s\n"), HOST_OS);
+				fprintf (stdout, _(" Build date...........: %s %s\n"), 
+					__DATE__, __TIME__);
+				fprintf (stdout, _(" --debug logs to......: %s\n\n"), GNC_QOF_LOG);
+				fprintf (stdout, _(" Please use --help for more detailed options.\n\n"));
+				return EXIT_SUCCESS;
+			}
+			/* optional modifiers - store to act on later. */
+			case qof_op_category:
+			{
+				qof_mod_category (category, gnc_cli);
+				break;
+			}
+			case qof_op_database:
+			{
+				qof_mod_database (database, gnc_cli);
+				break;
+			}
+			case qof_op_timespec:
+			{
+				qof_mod_timespec (date_time, gnc_cli);
+				break;
+			}
+			case qof_op_exclude:
+			{
+				qof_mod_exclude (exclude, gnc_cli);
+				break;
+			}
+			case qof_op_sql:
+			{
+				qof_mod_sql (sql_query, gnc_cli);
+				break;
+			}
+			case qof_op_sql_file:
+			{
+				qof_mod_sql_file (sql_file, gnc_cli);
+				break;
+			}
+			case qof_op_write:
+			{
+				qof_mod_write (write_file, gnc_cli);
+				break;
+			}
+			case qof_op_debug:
+			{
+				qof_log_init_filename(GNC_QOF_LOG);
+				qof_log_set_default(QOF_LOG_DETAIL);
+				qof_log_set_level(QOF_MAIN_CLI, QOF_LOG_DETAIL);
+				qof_log_set_level(QOF_MOD_QSF, QOF_LOG_DETAIL);
+				qof_log_set_level(GNC_MOD_CLI, QOF_LOG_DETAIL);
+				debug_on = TRUE;
+				break;
+			}
+			case qof_op_nofile :
+			{
+				skip_auto = TRUE;
+				break;
+			}
+			case qof_op_compress:
+			{
+				gnc_cli->gz_level = gz_level;
+				break;
+			}
+			default:
+			{
+				fprintf (stderr, _("%s: ERROR: got option %d, arg %s\n"), PACKAGE,
+					 optc, poptGetOptArg (pc));
+				return EXIT_FAILURE;
+			}
+		}
+	}
+	if (optc < -1)
+	{
+		fprintf(stderr, "%s: %s %s\n\n", PACKAGE,
+		poptBadOption(pc, POPT_BADOPTION_NOALIAS),
+		poptStrerror(optc));
+		poptPrintUsage(pc, stderr, 0);
+		return EXIT_FAILURE;
+	}
+	/* If we get this far, we should have sensible options: start the work. */
+	gnc_cli->input_session = qof_session_new();
+	switch (cli_command)
+	{
+		case qof_op_offline:
+		{
+			gnc_cli->filename = g_strdup(filename);
+			qof_cmd_xmlfile (gnc_cli);
+			break;
+		}
+		case qof_op_list:
+		{
+			qof_cmd_list ();
+			break;
+		}
+		case qof_op_explain:
+		{
+			if(!gnc_cli->database) 
+			{ 
+				fprintf (stderr, _("%s: Error: please specify the database to explain.\n\n"), PACKAGE);
+				break;
+			}
+			qof_cmd_explain(gnc_cli);
+			break;
+		}
+		case qof_op_guile :
+		{
+			/* load guile here */
+			scm_boot_guile(argc, (char **)argv, guile_main, NULL);
+			break;
+		}
+		default:
+		{
+			/* should be impossible */
+			break;
+		}
+	}
+	poptFreeContext(pc);
+	g_free(gnc_cli);
+	if(debug_on) { qof_log_shutdown(); }
+	qof_close();
+	return EXIT_SUCCESS;
+}
+
+
+


Property changes on: gnucash/branches/cashutil/src/bin/overrides
___________________________________________________________________
Name: svn:ignore
   - Makefile
Makefile.in
gnucash-build-env
gnucash-env
guile
   + Makefile
Makefile.in
gnucash-build-env
gnucash-env
guile
semantic.cache


Added: gnucash/branches/cashutil/src/bin/qof-main.c
===================================================================
--- gnucash/branches/cashutil/src/bin/qof-main.c	2006-01-03 04:02:42 UTC (rev 12241)
+++ gnucash/branches/cashutil/src/bin/qof-main.c	2006-01-03 09:15:18 UTC (rev 12242)
@@ -0,0 +1,740 @@
+/***************************************************************************
+ *            qof-main.c
+ *
+ *  This is an auto-generated file. Patches are available from
+ *  http://qof-gen.sourceforge.net/
+ *
+ *  Thu Jan 13 10:55:44 2005
+ *  Copyright  2005  Neil Williams
+ *  linux at codehelp.co.uk
+ ****************************************************************************/
+/*
+ *  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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#define _GNU_SOURCE
+#include "config.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/stat.h>
+#include <regex.h>
+#include <unistd.h>
+#include <errno.h>
+#include "qof-main.h"
+
+static QofLogModule log_module = QOF_MAIN_CLI;
+
+struct param_ref_list
+{
+	GSList *slist;
+	QofType param_type;
+	int i;
+};
+
+static void
+find_param_cb(QofParam *param, gpointer user_data)
+{
+	struct param_ref_list *b;
+	char *buf;
+
+	b = (struct param_ref_list*)user_data;
+	if((param->param_getfcn == NULL)||(param->param_setfcn == NULL)) { return; }
+	if(0 == safe_strcmp(b->param_type, param->param_type))
+	{
+		b->i++;
+		buf = g_strdup(param->param_name);
+		if(buf != NULL) {
+			b->slist = g_slist_append(b->slist, buf);
+		}
+		return;
+	}
+}
+
+GSList*
+qof_main_get_param_list(QofIdTypeConst object_type, QofType param_type)
+{
+	GSList *param_list;
+	char *i;
+	struct param_ref_list p;
+
+	g_return_val_if_fail(object_type != NULL, NULL);
+	param_list = NULL;
+	p.slist = NULL;
+	p.i = 0;
+	p.param_type = g_strdup(param_type);
+	qof_class_param_foreach(object_type, find_param_cb, &p);
+	param_list = g_slist_copy(p.slist);
+	i = g_strdup(object_type);
+	return param_list;
+}
+
+void
+qof_main_free (qof_main_context *context)
+{
+	g_free(context->filename);
+	g_free(context->write_file);
+	g_free(context->sql_file);
+	g_free(context->database);
+//	g_free(context->shortname);
+	g_free(context->category);
+}
+
+static void
+qof_main_run_sql (qof_main_context *context)
+{
+	QofSqlQuery *q;
+	gchar *sql;
+
+	q = qof_sql_query_new();
+	sql = g_strdup(context->sql_str);
+	qof_sql_query_parse(q, sql);
+	context->query = qof_sql_query_get_query(q);
+}
+
+static void
+qof_main_run_query(qof_main_context *context)
+{
+	QofBook *book;
+	GList *results;
+
+	book = qof_session_get_book(context->input_session);
+	qof_query_set_book(context->query, book);
+	results = qof_query_run (context->query);
+	if(results != NULL) {
+		qof_entity_copy_list(context->export_session, results);
+	}
+}
+
+/** takes one database name and runs -c and -t queries against it. */
+static void 
+build_database_list(QofIdTypeConst obj_type, qof_main_context *context)
+{
+	GSList *date_param_list, *category_param_list;
+	QofQueryPredData *date_pred_data;
+	QofQueryPredData *category_pred;
+	QofIdTypeConst find;
+	Timespec min_ts;
+	Timespec max_ts;
+
+    if(!obj_type || !context) { return; }
+    context->query = qof_query_create_for(obj_type);
+    find = qof_query_get_search_for(context->query);
+	if(context->category != NULL) {
+		category_param_list = qof_query_build_param_list(CATEGORY_NAME, NULL);
+		category_pred = qof_query_string_predicate(QOF_COMPARE_EQUAL, 
+			context->category, QOF_STRING_MATCH_CASEINSENSITIVE, FALSE);
+        qof_query_add_term(context->query, category_param_list,
+            category_pred, QOF_QUERY_AND);
+	}
+	if(context->min_ts.tv_sec > 0) {
+		min_ts = context->min_ts;
+		max_ts = context->max_ts;
+		date_param_list = g_slist_copy(qof_main_get_param_list(find, QOF_TYPE_DATE));
+		if(!date_param_list) 
+		{
+            if(context->query) { qof_query_clear(context->query); }
+            PINFO (" no date_param_list");
+			return;
+	}
+	date_pred_data = qof_query_date_predicate(QOF_COMPARE_GTE,
+		   QOF_DATE_MATCH_NORMAL, min_ts);
+	qof_query_add_term(context->query, date_param_list,
+		   date_pred_data, QOF_QUERY_AND);
+	date_param_list = qof_main_get_param_list(
+		   qof_query_get_search_for(context->query), QOF_TYPE_DATE);
+	date_pred_data = qof_query_date_predicate(QOF_COMPARE_LTE,
+		   QOF_DATE_MATCH_NORMAL, max_ts);
+	qof_query_add_term(context->query, date_param_list,
+		   date_pred_data, QOF_QUERY_AND);
+	}
+	qof_main_run_query(context);
+	if(context->query) { qof_query_clear(context->query); }
+}
+
+static void
+select_cb(QofObject *obj, gpointer data)
+{
+	qof_main_context *context;
+	
+	context = (qof_main_context*)data;
+	g_return_if_fail(context);
+	if(0 != safe_strcmp(context->exclude, obj->e_type))
+	{
+		build_database_list(obj->e_type, context);
+	}
+}
+
+void
+qof_main_moderate_query(qof_main_context *context)
+{
+	GSList *date_param_list, *category_param_list;
+	gboolean all;
+
+	all = TRUE;
+    context->query = qof_query_create();
+	date_param_list = NULL;
+	category_param_list = NULL;
+	while (context->sql_list)
+	{
+		context->sql_str = g_strdup(context->sql_list->data);
+		qof_main_run_sql(context);
+		qof_main_run_query(context);
+		if(context->query) { qof_query_clear(context->query); }
+		g_free(context->sql_str);
+		all = FALSE;
+		context->sql_list = g_list_next(context->sql_list);
+	}
+	if(0 < g_list_length(context->sql_list)) { 
+		context->sql_str = NULL;
+		g_list_free(context->sql_list);
+		all = FALSE;
+	}
+	if(context->sql_str != NULL) {
+		qof_main_run_sql(context);
+		qof_main_run_query( context);
+		if(context->query) { qof_query_clear(context->query); }
+		all = FALSE;
+	}
+	if((context->exclude != NULL)&&(qof_class_is_registered(context->exclude)))
+	{
+		qof_object_foreach_type(select_cb, context);
+		all = FALSE;
+	}
+	if((context->database != NULL)&&(qof_class_is_registered(context->database)))
+	{
+		build_database_list(context->database, context);
+		all = FALSE;
+	}
+	if(all == TRUE)
+	{
+		qof_object_foreach_type(select_cb, context);
+	}
+}
+
+static void option_cb (QofBackendOption *option, gpointer data)
+{
+	gint gz_level;
+
+	gz_level = GPOINTER_TO_INT(data);
+	if(0 == safe_strcmp(QSF_COMPRESS, option->option_name)) {
+		option->value = (gpointer)&gz_level;
+	}
+}
+
+gboolean
+qof_check_sql(const char *sql)
+{
+	regex_t *r;
+	int reg_exp_check;
+	static char *pattern = QOF_SQL_SUPPORTED;
+//	QofSqlQuery *q;
+	gboolean result;
+
+	result = FALSE;
+	r = g_new(regex_t, 1);
+	reg_exp_check = regcomp(r, pattern,
+		REG_ICASE | REG_NOSUB | REG_EXTENDED);
+	g_return_val_if_fail(reg_exp_check == 0, FALSE);
+	if(0 == regexec(r, sql, 0, NULL, 0)) { result = TRUE; }
+	regfree(r);
+	g_free(r);
+	return result;
+}
+
+void
+qof_mod_compression (gint gz_level, qof_main_context *context)
+{
+	KvpFrame *be_config;
+	QofBook *book;
+	QofBackend *be;
+
+	if((gz_level > 0) && (gz_level <= 9))
+	{
+		ENTER (" ");
+		book = qof_session_get_book(context->export_session);
+		be = qof_book_get_backend(book);
+		be_config = qof_backend_get_config(be);
+		qof_backend_option_foreach(be_config, option_cb, &gz_level);
+		qof_backend_load_config(be, be_config);
+		LEAVE (" ");
+	}
+}
+
+void
+qof_cmd_xmlfile (qof_main_context *context)
+{
+	QofSession *input_session, *export_session;
+	gchar current_work[PATH_MAX];
+	gchar *temp;
+	QofBackend *be;
+	QofBook *book;
+	KvpFrame *backend_config;
+
+	backend_config = NULL;
+	input_session = context->input_session;
+	if(0 == safe_strcmp(context->exclude, context->database)
+		&&(context->exclude != NULL))
+	{
+		fprintf(stderr, _("%s: Error: Cannot exclude database \"%s\" with option -e\n"
+		"    because option -d is set to the include the same database: \"%s\"\n"
+		"Use the \'-l\' command to see the full list of supported databases.\n"),
+			PACKAGE, context->exclude, context->database);
+		qof_session_end(input_session);
+		return;
+	}
+	qof_session_begin(input_session, context->filename, FALSE, TRUE);
+	qof_session_load(input_session, NULL);
+	if(ERR_BACKEND_LOCKED == qof_session_get_error(input_session))
+	{
+		/** \todo ask the user if it is OK to ignore the lock. */
+		qof_session_begin(input_session, context->filename, TRUE, FALSE);
+		qof_session_load(input_session, NULL);
+	}
+	book = qof_session_get_book(input_session);
+	be = qof_book_get_backend(book);
+	backend_config = qof_backend_get_config(be);
+	PINFO (" trying to get backend config");
+	if(backend_config) 
+	{
+/*		qof_backend_option_foreach(backend_config, 
+			print_config_cb, context);*/
+	}
+	else { PINFO (" failed"); }
+	export_session = qof_session_new();
+	context->export_session = export_session;
+	if(context->write_file != NULL) {
+		if(*context->write_file != '/')
+		{
+			getcwd(current_work, PATH_MAX);
+			temp = g_strconcat(current_work, "/", context->write_file, NULL);
+			context->write_file = temp;
+		}
+		qof_session_begin(export_session, context->write_file, FALSE, TRUE);
+	}
+	else { qof_session_begin(export_session, QOF_STDOUT, TRUE, FALSE); }
+	qof_session_set_current_session(input_session);
+	qof_main_moderate_query(context);
+	qof_session_save(export_session, NULL);
+	qof_main_show_error(export_session);
+	qof_main_show_error(input_session);
+	qof_session_end(input_session);
+	qof_session_end(export_session);
+}
+
+static void
+qof_list_cb(QofObject *obj, gpointer data)
+{
+	if(qof_class_is_registered(obj->e_type)) {
+		fprintf(stdout, "%-20s\t%s\n", obj->e_type, obj->type_label);
+	}
+}
+
+void
+qof_main_select(qof_main_context *context)
+{
+	g_return_if_fail(context);
+	qof_object_foreach_type(select_cb, context);
+}
+
+void
+qof_cmd_list (void)
+{
+	fprintf(stdout, _("\n%s currently supports these database names:\n"
+	"You can use the names with %s -d\n"
+	"and in SQL queries (as the table name) with %s -s|f\n"
+	"Descriptions are shown only for readability.\n\n"
+	"Name                    Description\n\n"
+	)
+	, PACKAGE, PACKAGE, PACKAGE);
+	qof_object_foreach_type(qof_list_cb, NULL);
+	fprintf(stdout, _("\nUse '-d <database> --explain' to see the list of fields within\n"
+	"any supported database.\n"));
+	fprintf(stdout, _("\nThank you for using %s\n\n"), PACKAGE);
+}
+
+static void
+explain_cb (QofParam* param, gpointer user_data)
+{
+	if(param->param_getfcn && param->param_setfcn)
+	{
+		fprintf(stdout, _("Type: %s\tName: %s\n"), 
+			param->param_type, param->param_name);
+	}
+}
+
+void
+qof_cmd_explain (qof_main_context *context)
+{
+
+	if(context->error) { return; }
+	fprintf(stdout, _("\nParameters of the %s database:\n\n"), context->database);
+	qof_class_param_foreach(context->database, explain_cb, NULL);
+	fprintf(stdout, _("\nThank you for using %s\n\n"), PACKAGE);
+}
+
+void
+qof_mod_category (const char *category, qof_main_context *data)
+{
+	data->category = g_strdup(category);
+}
+
+void
+qof_mod_database (const char *database, qof_main_context *data)
+{
+	if(qof_class_is_registered(database)) {
+		data->database = g_strdup(database);
+	}
+}
+
+void
+qof_mod_timespec (const char *date_time, qof_main_context *data)
+{
+	gchar *temp;
+	int year, month, day;
+	gboolean takemonth, takeyear, scanned;
+	char *first_field, *second_field, *third_field;
+	static char *delims = ".,-+/\\() ";
+
+	takemonth = takeyear = scanned = FALSE;
+	day = month = year = 0;
+	second_field = "";
+	third_field = "";
+	temp = g_strdup(date_time);
+	qof_date_format_set(QOF_DATE_FORMAT_UTC);
+	scanned = qof_scan_date(temp, &day, &month, &year);
+	if(scanned == FALSE)
+	{
+		first_field = strtok (temp, delims);
+		if (first_field)
+		{
+			second_field = strtok (NULL, delims);
+			if (second_field)
+			{
+				third_field = strtok (NULL, delims);
+			}
+		}
+		if (third_field && second_field)
+		{
+			year = atoi(first_field);
+			month = atoi(second_field);
+			day = atoi(third_field);
+		} else if (second_field)
+		{
+			year = atoi(first_field);
+			month = atoi(second_field);
+			takemonth = TRUE;
+		} else if (first_field)
+		{
+			year = atoi(first_field);
+			takeyear = TRUE;
+		}
+	}
+	if(takemonth) { day = 1; }
+	if(takeyear)  { day = 1; month = 1; }
+	data->min_ts = gnc_dmy2timespec(day, month, year);
+	if(takemonth) { day = gnc_date_my_last_mday(month, year); }
+	if(takeyear)  {
+		month = 12;
+		day = gnc_date_my_last_mday(month, year);
+	}
+	data->max_ts = gnc_dmy2timespec_end(day, month, year);
+}
+
+void
+qof_mod_exclude (const char *exclude, qof_main_context *data)
+{
+	if(qof_class_is_registered(exclude)) {
+		data->exclude = g_strdup(exclude);
+	}
+}
+
+void
+qof_mod_sql (const char *sql_query, qof_main_context *data)
+{
+	if(!qof_check_sql(sql_query)) { return; }
+	data->sql_str = g_strdup(sql_query);
+}
+
+void
+qof_mod_sql_file (const char *sql_file, qof_main_context *data)
+{
+	FILE *filehandle;
+#ifndef HAVE_GETLINE
+	char lineptr[1024];
+#else
+	char *lineptr;
+#endif
+	char *buf;
+	size_t n;
+	QofQuery *q;
+	struct stat sbuf;
+
+	data->sql_file = g_strdup(sql_file);
+	n = 0;
+	q = NULL;
+	data->sql_list = NULL;
+	if (stat(sql_file, &sbuf) <0) {
+		fprintf(stderr,"%s: ERROR. Unable to open %s (%s)\n\n",
+			PACKAGE, sql_file, strerror(errno));
+		return;
+		}
+	filehandle = fopen(sql_file, "r");
+#ifndef HAVE_GETLINE
+	while (NULL != (fgets(lineptr, sizeof(lineptr), filehandle)))
+#else
+	lineptr = NULL;
+	while (0 < getline(&lineptr, &n, filehandle))
+#endif
+	{
+		if(!qof_check_sql(lineptr)) { continue; }
+		if(0 == safe_strcmp(lineptr, "\n")) { continue; }
+		buf = g_strdup(lineptr);
+		data->sql_list = g_list_append(data->sql_list, buf);
+	}
+
+	fclose(filehandle);
+}
+
+void
+qof_mod_write (const char *write_file, qof_main_context *data)
+{
+	FILE *f;
+
+	data->write_file = g_strdup(write_file);
+	f = fopen(data->write_file, "a+");
+	if(f) {fclose(f); }
+}
+
+void
+qof_main_show_error(QofSession *session)
+{
+	QofBackendError io_error;
+	char *newfile;
+	gboolean uh_oh;
+	const char *fmt;
+
+	uh_oh = TRUE;
+	newfile = g_strdup(qof_session_get_file_path(session));
+	io_error = qof_session_get_error(session);
+	switch (io_error)
+	{
+	case ERR_BACKEND_NO_ERR : {
+		uh_oh = FALSE;
+		return;
+	}
+	case ERR_BACKEND_NO_HANDLER: {
+		fmt = _("%s: No suitable backend was found for %s.\n");
+		fprintf(stderr, fmt, PACKAGE, newfile);
+		break;
+	}
+	case ERR_BACKEND_NO_BACKEND: {
+		fmt = _("%s: The URL '%s' is not supported by this "
+		"version of %s.\n");
+		fprintf(stderr, fmt, PACKAGE, newfile, PACKAGE);
+		break;
+	}
+	case ERR_BACKEND_BAD_URL: {
+		fmt = _("%s: Cannot parse the URL '%s'\n");
+		fprintf(stderr, fmt, PACKAGE, newfile);
+		break;
+	}
+	case ERR_BACKEND_CANT_CONNECT: {
+		fmt = _("%s: Cannot connect to '%s'. "
+		"The host, username or password were incorrect.\n");
+		fprintf(stderr, fmt, PACKAGE, newfile);
+		break;
+	}
+	case ERR_BACKEND_CONN_LOST: {
+		fmt = _("%s: Cannot connect to '%s'. "
+		"Connection was lost, unable to send data.\n");
+		fprintf(stderr, fmt, PACKAGE, newfile);
+		break;
+	}
+	case ERR_BACKEND_TOO_NEW: {
+		fmt = _("%s: This file/URL appears to be from a newer "
+		"version of %s.\n");
+		fprintf (stderr, fmt, PACKAGE, PACKAGE);
+		break;
+	}
+	case ERR_BACKEND_NO_SUCH_DB: {
+		fmt = _("%s: The database '%s' does not seem to exist.\n");
+		fprintf (stderr, fmt, PACKAGE, newfile);
+		break;
+	}
+	case ERR_BACKEND_LOCKED: {
+		fmt = _("%s: Could not obtain the lock for '%s'.\n");
+		fprintf (stderr, fmt, PACKAGE, newfile);
+		break;
+	}
+	case ERR_BACKEND_READONLY: {
+		fmt = _("%s could not write to '%s'. "
+		"That database may be on a read-only file system, "
+		"or you may not have write permission for the directory.\n");
+		fprintf (stderr, fmt, PACKAGE, newfile);
+		break;
+	}
+	case ERR_BACKEND_DATA_CORRUPT: {
+		fmt = _("%s: The file/URL '%s' does not contain %s "
+		"data or the data is corrupt.\n");
+		fprintf (stderr, fmt, PACKAGE, newfile, PACKAGE);
+		break;
+	}
+	case ERR_BACKEND_SERVER_ERR: {
+		fmt = _("%s: The server at URL '%s' "
+		"experienced an error or encountered bad or corrupt data.\n");
+		fprintf (stderr, fmt, PACKAGE, newfile);
+		break;
+	}
+	case ERR_BACKEND_PERM: {
+		fmt = _("%s: You do not have permission to access '%s'.\n");
+		fprintf (stderr, fmt, PACKAGE, newfile);
+		break;
+	}
+	case ERR_BACKEND_MISC: {
+		fmt = _("%s: An error occurred while processing '%s'.\n");
+		fprintf (stderr, fmt, PACKAGE, newfile);
+		break;
+	}
+	/* QSF additions */
+	case ERR_QSF_INVALID_OBJ: {
+		fmt = _("%s: Invalid QSF Object file! The QSF object file '%s' "
+		" failed to validate  against the QSF object schema. "
+		"The XML structure of the file is either not well-formed "
+		"or the file contains illegal data.\n");
+		fprintf (stderr, fmt, PACKAGE, newfile);
+		break;
+	}
+	case ERR_QSF_INVALID_MAP: {
+		fmt = _("%s: Invalid QSF Map file! The QSF map file "
+		"failed to validate against the QSF map schema. "
+		"The XML structure of the file is either not well-formed "
+		"or the file contains illegal data.\n");
+		fprintf (stderr, fmt, PACKAGE);
+		break;
+	}
+	case ERR_QSF_BAD_QOF_VERSION: {
+		fmt = _("%s: The QSF Map file '%s' was written for a different "
+		"version of QOF. It may need to be modified to work with "
+		"your current QOF installation.\n");
+		fprintf (stderr, fmt, PACKAGE, newfile);
+		break;
+	}
+	case ERR_QSF_BAD_MAP: {
+		fmt = _("%s: The selected QSF map '%s' contains unusable or missing data. "
+		"This is usually because not all the required parameters for "
+		"the defined objects have calculations described in the map.\n");
+		fprintf (stderr, fmt, PACKAGE, newfile);
+		break;
+	}
+	case ERR_QSF_BAD_OBJ_GUID: {
+		fmt = _("%s: The selected QSF object file '%s' contains one or "
+		"more invalid GUIDs. The file cannot be processed - "
+		"please check the source of the file and try again.\n");
+		fprintf (stderr, fmt, PACKAGE, newfile);
+		break;
+	}
+	case ERR_QSF_NO_MAP: {
+		fmt = _("%s: The selected QSF Object file '%s' requires a map"
+		"but it was not provided.\n");
+		fprintf (stderr, fmt, PACKAGE, newfile);
+		break;
+	}
+	case ERR_QSF_WRONG_MAP: {
+		fmt = _("%s: Wrong QSF map selected. The selected map, validates "
+		"but was written for different QOF objects. "
+		"The list of objects defined in this map does not include "
+		"all the objects described in the current QSF object file.\n");
+		fprintf (stderr, fmt, PACKAGE);
+		break;
+	}
+	case ERR_QSF_MAP_NOT_OBJ: {
+		fmt = _("%s: The selected file '%s' is a QSF map and cannot"
+		"be opened as a QSF object.\n");
+		fprintf (stderr, fmt, PACKAGE, newfile);
+		break;
+	}
+	case ERR_QSF_OVERFLOW : {
+		fmt = _("%s: When converting XML strings into numbers, an overflow "
+		"has been detected. The QSF object file '%s' contains invalid "
+		"data in a field that is meant to hold a number.\n");
+		fprintf (stderr, fmt, PACKAGE, newfile);
+		break;
+	}
+	case ERR_QSF_OPEN_NOT_MERGE : {
+		fmt = _("%s: The QSF object file '%s' should be merged, "
+		"not opened directly.\n");
+		fprintf (stderr, fmt, PACKAGE, newfile);
+		break;
+	}
+	case ERR_FILEIO_FILE_BAD_READ: {
+		fmt = _("%s: There was an error reading the file '%s'.\n");
+		fprintf (stderr, fmt, PACKAGE, newfile);
+		break;
+	}
+	case ERR_FILEIO_PARSE_ERROR: {
+		fmt = _("%s: There was an error parsing the file '%s'.\n");
+		fprintf (stderr, fmt, PACKAGE, newfile);
+		break;
+	}
+	case ERR_FILEIO_FILE_EMPTY: {
+		fmt = _("%s: The file '%s' is empty.\n");
+		fprintf (stderr, fmt, PACKAGE, newfile);
+		break;
+	}
+	case ERR_FILEIO_FILE_NOT_FOUND: {
+		fmt = _("%s: The file '%s' could not be found.\n");
+		fprintf (stderr, fmt, PACKAGE, newfile);
+		break;
+	}
+	case ERR_FILEIO_FILE_TOO_OLD: {
+		fmt = _("%s: This file is from an older version.\n");
+		fprintf (stderr, fmt, PACKAGE);
+		break;
+	}
+	case ERR_FILEIO_UNKNOWN_FILE_TYPE: {
+		fmt = _("%s: Unknown file type, '%s'.\n");
+		fprintf (stderr, fmt, PACKAGE, newfile);
+		break;
+	}
+	case ERR_FILEIO_BACKUP_ERROR: {
+		fmt = _("%s: Could not make a backup of '%s'.\n");
+		fprintf (stderr, fmt, PACKAGE, newfile);
+		break;
+	}
+	case ERR_FILEIO_WRITE_ERROR: {
+		fmt = _("%s: Could not write to '%s'. Check that you have "
+		"permission to write to this file and that there is sufficient "
+		"space to create it.\n");
+		fprintf (stderr, fmt, PACKAGE, newfile);
+	  break;
+	}
+	case ERR_SQL_DB_TOO_OLD: {
+		fmt = _("%s: This database is from an older version.\n");
+		fprintf (stderr, fmt, PACKAGE);
+		break;
+	}
+	case ERR_SQL_DB_BUSY: {
+		fmt = _("%s: The SQL database is in use by other users.\n");
+		fprintf (stderr, fmt, PACKAGE);
+		break;
+	}
+	default:
+		fmt = _("%s: An unknown I/O error occurred.\n");
+		fprintf (stderr, fmt, PACKAGE);
+	break;
+	}
+}
+
+/*==================== END OF FILE ======================*/

Added: gnucash/branches/cashutil/src/bin/qof-main.h
===================================================================
--- gnucash/branches/cashutil/src/bin/qof-main.h	2006-01-03 04:02:42 UTC (rev 12241)
+++ gnucash/branches/cashutil/src/bin/qof-main.h	2006-01-03 09:15:18 UTC (rev 12242)
@@ -0,0 +1,453 @@
+/***************************************************************************
+ *            qof-main.h
+ *
+ *  This is an auto-generated file. Patches are available from
+ *  http://qof-gen.sourceforge.net/
+ *
+ *  Thu Jan 13 12:15:41 2005
+ *  Copyright  2005  Neil Williams
+ *  linux at codehelp.co.uk
+ ****************************************************************************/
+/*
+ *  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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+/** @addtogroup QOFCLI Query Object Framework Command Line Interface.
+
+QOF provides an outline CLI that is easily patched
+from the qof-generator project to make it easier
+to keep various QOF projects updated.
+
+This CLI is easily extended to support your own functions
+and options and includes macros to help you keep up to date
+with changes in main QOF options. It is recommended that you
+do not edit this file, instead please feed patches back to the
+QOF-devel mailing list at
+http://lists.sourceforge.net/mailman/listinfo/qof-devel
+so that other projects can be updated.
+
+@{
+*/
+/** @file qof-main.h
+  @brief Common functions for the QOF external framework
+  @author Copyright (c) 2005 Neil Williams <linux at codehelp.co.uk>
+*/
+
+#ifndef _QOF_MAIN_H
+#define _QOF_MAIN_H
+#include <qof.h>
+#include <stdlib.h>
+#include <time.h>
+#include <popt.h>
+
+#if defined(HAVE_GETTEXT)             /* HAVE_GETTEXT */
+
+#include <libintl.h>
+#include <locale.h>
+
+#undef _
+#undef Q_
+
+#ifdef DISABLE_GETTEXT_UNDERSCORE
+#define _(String) (String)
+#define Q_(String) gnc_qualifier_prefix_noop(String)
+#else                                 /* ENABLE_GETTEXT_UNDERSCORE */
+#define _(String) gettext(String)
+#define Q_(String) gnc_qualifier_prefix_gettext(String)
+#endif                                /* End ENABLE_GETTEXT_UNDERSCORE */
+
+#else                                 /* Not HAVE_GETTEXT */
+#if !defined(__USE_GNU_GETTEXT)
+
+#undef _
+#undef Q_
+#define _(String)       (String)
+#define Q_(String) gnc_qualifier_prefix_noop(String)
+#define gettext(String) (String)
+#define ngettext(msgid, msgid_plural, n) (((n)==1) ? \
+                                            (msgid) : (msgid_plural))
+
+#endif                                /* End not__USE_GNU_GETTEXT */
+#endif                                /* End Not HAVE_GETTEXT */
+
+#undef  N_
+#define N_(String) (String)
+
+/** \brief List of all parameters for this object of one QOF type. 
+
+Return a GSList of all parameters of this object that are a
+particular QOF type, QOF_TYPE_STRING, QOF_TYPE_BOOLEAN etc.
+
+The returned GSList should be freed by the caller.
+
+\note The return list is a singly linked list - GSList -
+\b not the doubly-linked list - GList - returned by 
+::qof_class_get_referenceList.
+
+\param object_type  object->e_type for the relevant object.
+\param param_type  The type of parameter to match, QOF_TYPE_STRING etc.
+
+\return GSList of all matching parameters or NULL if none exist.
+*/
+GSList*
+qof_main_get_param_list(QofIdTypeConst object_type, QofType param_type);
+
+/** Maximum length of the UTC timestamp used by QSF
+
+QOF_UTC_DATE_FORMAT   "%Y-%m-%dT%H:%M:%SZ"
+*/
+#define QOF_DATE_STRING_LENGTH  MAX_DATE_LENGTH
+
+/** Debug module for qof-main */
+#define QOF_MAIN_CLI  "QOF-mod-command-line"
+
+/** \brief Category name.
+
+The name of the parameter that holds the category of the entity.
+
+Many CLI data sources categorise data by user-editable category
+strings. If your program does not, simply implement a modified
+QOF_CLI_OPTIONS in your code without the category option:
+\verbatim
+{"category", 'c', POPT_ARG_STRING, &category, qof_op_category,
+_("Shorthand to only query objects that are set to the specified category."),
+"string"},
+\endverbatim
+*/
+#define CATEGORY_NAME "category"
+
+/** backend configuration index string for QSF
+
+The identifier for the configuration option within
+QSF supported by the CLI. Matches the
+QofBackendOption->option_name in the KvpFrame
+holding the options.
+*/
+#define QSF_COMPRESS "compression_level"
+
+/** The SQL commands supported by QOF
+
+A regular expression used to exclude unsupported commands
+from SQL files. Anything that does \b not match the expression
+will be silently ignored. This allows genuine
+SQL dump files to be parsed without errors.
+
+ A QOF object is similar to a definition of a SQL table.\n
+ A QOF entity is similar to an instance of a SQL record.\n
+ A QOF parameter is similar to data in a SQL field.
+
+Certain SQL commands have no QOF equivalent and should
+always be ignored silently:
+ - ALTER (the object parameters cannot be changed at runtime)
+ - CREATE (new tables - new objects - cannot be created at runtime)
+ - DROP  (an object cannot be "de-registered" without re-compiling)
+ - FLUSH (QOF has no permissions system)
+ - GRANT
+ - KILL
+ - LOCK
+ - OPTIMIZE
+ - REVOKE
+ - USE (QOF only has one database, itself.)
+*/
+#define QOF_SQL_SUPPORTED  "^SELECT|INSERT"
+
+/** \brief Output error messages from QOF
+
+QOF will set errors in the QofSession. The
+application determines how to output those
+messages and for the CLI, this will be to
+stderr. Not all these messages are implemented
+in any one QOF CLI.
+
+\param session Any current session.
+*/
+void qof_main_show_error(QofSession *session);
+
+/** \brief The qof-main context struct.
+
+Intended as a core type for QOF-based CLI programs, wrap
+your own context struct around qof_main_context
+*/
+typedef struct qof_main_s {
+	gchar *filename;		    /**< Input filename containing QSF XML data, if any.*/
+	gchar *write_file; 		    /**< Export filename, if any.*/
+	gchar *input_file;		    /**< File containing data to upload, if any. */
+	gchar *sql_file;		    /**< SQL file, if any. */
+	gchar *sql_str;			    /**< The current SQL, overwritten each iteration
+								if using a file.*/
+	gchar *database;		    /**< The database to include with -d. */
+	gchar *exclude;			    /**< The database to exclude with -e. */
+	gchar *category;		    /**< The category to include with -c.*/
+	Timespec min_ts;		    /**< Holds the converted -t field - minimum.
+								Matches objects above min. */
+	Timespec max_ts;		    /**< Holds the converted -t field - maximum.
+								Matches objects below max. */
+	QofSession *input_session;  /**< The input session - hotsync or offline storage. */
+	QofSession *export_session; /**< The query results session, for STDOUT or -w,
+								both as QSF XML. */
+	gboolean error;             /**< general error, abort. */
+    QofQuery *query;            /**< The current QofQuery, converted from QofSqlQuery */
+	GList *sql_list;            /**< List of sql commands from a file. */
+	gint gz_level;              /**< Use compression (>0 <=9) or not (0)*/
+}qof_main_context;
+
+/** Free qof_main_context values when work is done. */
+void qof_main_free (qof_main_context *context);
+
+/** \brief Check that the SQL command is supported.*/
+gboolean qof_check_sql(const char *sql);
+
+/** \enum qof_op_type
+
+main operator enum
+*/
+/** \enum qof_op_type::qof_op_noop
+
+undefined check value
+*/
+/**\enum qof_op_type::qof_op_input
+
+execute input command
+*/
+/** \enum qof_op_type::qof_op_list
+
+List supported databases command.
+*/
+/** \enum qof_op_type::qof_op_category
+
+Shorthand category option.
+*/
+
+/** query the QSF XML data */
+void qof_cmd_xmlfile (qof_main_context *context);
+
+/** \brief Lists all databases supported by the current QOF framework.
+
+Prints the name and description for each object type
+registered with this instance of QOF. No options are used.
+*/
+void qof_cmd_list (void);
+
+/** \brief Shorthand to only query objects that are set to the specified category.
+
+Modifies the QOF query to only query objects that are set to
+\a category.
+*/
+void qof_mod_category (const char *category, qof_main_context *data);
+
+/** \brief Shorthand to only query objects within one specific supported database.
+
+Used to only query objects within the specified
+database.
+*/
+void qof_mod_database (const char *database, qof_main_context *data);
+
+/** \brief Shorthand to only query objects that contain the specified date.
+
+Used to modify the QOF query to only query objects that contain
+at least one parameter containing a QOF_TYPE_DATE that
+matches the range specified. Dates need to be specified as YY-MM-DD.
+
+You can specify a UTC timestring, just as normally output by QSF,
+but the time will not be matched when using the shorthand option,
+only the year, month and day.
+
+For more precise time matches or to set a defined period that doesn't follow
+whole calendar months, (e.g. the UK financial year) use a SQL statement:
+
+"SELECT * from pilot_datebook where start_time > '2004-04-06T00:00Z'\n
+and end_time < '2005-04-05T23:59:59Z';"
+
+Partial matches are allowed, so YY-MM matches
+any object where a date is within the specified month and year,
+YY matches any object where a date is within the specified year.
+
+The query range starts at midnight on the first day of the range
+and ends at 1 second to midnight on the last day of the range.
+*/
+void qof_mod_timespec (const char *date_time, qof_main_context *data);
+
+/** \brief Shorthand to exclude a supported database from the query.
+
+Excludes the (single) specified database from the query.
+*/
+void qof_mod_exclude (const char *exclude, qof_main_context *data);
+
+/** \brief Specify a SQL query on the command line.
+
+For SELECT, the returned list is a list of all of the instances of 'SomeObj' that
+match the query. The 'SORT' term is optional. The 'WHERE' term is optional; but
+if you don't include 'WHERE', you will get a list of all of the object instances.
+The Boolean operations 'AND' and 'OR' together with parenthesis can be used to construct
+arbitrarily nested predicates.
+
+For INSERT, the returned list is a list containing the newly created instance of 'SomeObj'.
+
+Date queries handle full date and time strings, using the format exported by the QSF
+backend. To query dates and times, convert user input into UTC time using the
+QOF_UTC_DATE_FORMAT string. e.g. set the UTC date format and call qof_print_time_buff
+with a time_t obtained via timespecToTime_t.
+
+If the param is a KVP frame, then we use a special markup to indicate frame values.
+The markup should look like /some/kvp/path:value. Thus, for example,\n
+SELECT * FROM SomeObj WHERE (param_a < '/some/kvp:10.0')\n
+will search for the object where param_a is a KVP frame, and this KVP frame contains
+a path '/some/kvp' and the value stored at that path is floating-point and that float
+value is less than 10.0.
+
+*/
+void qof_mod_sql (const char *sql_query, qof_main_context *data);
+
+/** \brief Specify one or more SQL queries contained in a file.
+
+The rules for single SQL commands also apply with regard to the lack of explicit
+support for joins and the pending support for selecting only certain parameters
+from a certain object.
+
+See ::qof_mod_sql for information on the queries supported.
+
+\note Where possible, this function uses the safer GNU extension: getline().
+On Mac OSX and other platforms that do not provide getline, the call uses
+the less reliable fgets(). If the input file contains a NULL, fgets will
+get confused and the read may terminate early on such platforms.\n
+http://www.gnu.org/software/libc/manual/html_node/Line-Input.html
+
+*/
+void qof_mod_sql_file (const char *sql_file, qof_main_context *data);
+
+/** \brief Write the results of any query to the file
+
+\a filename of the file to be written out using the QSF XML
+QofBackend.
+
+*/
+void qof_mod_write (const char *write_file, qof_main_context *data);
+
+/** Pass the requested compression to QSF
+
+ at param gz_level Integer between 0 and 9, 9 highest compression, 0 for none.
+*/
+void
+qof_mod_compression (gint gz_level, qof_main_context *context);
+
+/** \brief Assemble the components of the query.
+
+If any SQL statements are found, run
+separately from any -c, -d or -t options.
+
+All queries are additive: Successive queries add
+more entities to the result set but no entity is
+set more than once.
+*/
+void
+qof_main_moderate_query(qof_main_context *context);
+
+/** Print a list of available parameters for a database.
+
+Used with qof_mod_database to print a list of
+QofParam for the QofObject set in context->database.
+*/
+void
+qof_cmd_explain (qof_main_context *context);
+
+void qof_main_select(qof_main_context *context);
+
+/** \brief Common QOF CLI options
+ *
+ * These are definitions for popt support in the CLI. Every program's
+ * popt table should start with QOF_CLI_OPTIONS or a replacement to insert
+ * the standard options into it. Also enables autohelp. End your
+ * popt option list with POPT_TABLEEND. If you want to remove any
+ * of these options, simply copy QOF_CLI_OPTIONS into a macro of
+ * your own and remove the options you do not need.
+*/
+#define QOF_CLI_OPTIONS POPT_AUTOHELP \
+	{"list", 'l', POPT_ARG_NONE, NULL, qof_op_list, \
+	 _("List all databases supported by the current QOF framework and exit."), \
+	 NULL}, \
+	{"explain", 0, POPT_ARG_NONE, NULL, qof_op_explain, \
+	 _("List the fields within the specified database and exit, requires -d."), \
+	 NULL}, \
+    {"xml-file", 'x', POPT_ARG_STRING, &filename, qof_op_offline, \
+     _("Query the QSF XML data in <filename>"), \
+     "filename"}, \
+	{"date", 't', POPT_ARG_STRING, &date_time, qof_op_timespec, \
+	 _("Shorthand to only query objects that contain the specified date."), \
+	 "string"}, \
+	{"database", 'd', POPT_ARG_STRING, &database, qof_op_database, \
+	 _("Shorthand to only query objects within a specific supported database. "), \
+	 "string"}, \
+	{"exclude", 'e', POPT_ARG_STRING, &exclude, qof_op_exclude, \
+	 _("Shorthand to exclude a supported database from the query."), \
+	 "string"}, \
+	{"sql", 's', POPT_ARG_STRING, &sql_query, qof_op_sql, \
+	 _("Specify a SQL query on the command line."), "string"}, \
+	{"sql-file", 'f', POPT_ARG_STRING, &sql_file, qof_op_sql_file, \
+	 _("Specify one or more SQL queries contained in a file."), \
+	 "filename"}, \
+	{"write", 'w', POPT_ARG_STRING, &write_file, qof_op_write, \
+	 _("Write the results of any query to the file"), "filename"}, \
+	{"compress", 0, POPT_ARG_INT, &gz_level, qof_op_compress, \
+	 _("Compress output files, 0 for none, 9 for maximum"), "integer"}, \
+	{"debug", 0, POPT_ARG_NONE, NULL, qof_op_debug, \
+	 _("Print debugging information to a temporary file."), NULL}, \
+	{"version", 0, POPT_ARG_NONE, NULL, qof_op_vers, \
+	 _("Display version information"), NULL}, \
+    {"category", 'c', POPT_ARG_STRING, &category, qof_op_category, \
+     _("Shorthand to only query objects that are set to the specified category."), \
+     "string"},
+
+
+/** use only if you have no extended options, otherwise use as a template. */
+#define QOF_MAIN_OP \
+ 	_(qof_op_noop, = 0) \
+	_(qof_op_list,)     \
+    _(qof_op_xmlfile,)  \
+	_(qof_op_category,) \
+	_(qof_op_database,) \
+	_(qof_op_timespec,) \
+	_(qof_op_exclude,)  \
+	_(qof_op_sql,)      \
+	_(qof_op_sql_file,) \
+	_(qof_op_write, )   \
+	_(qof_op_explain,)  \
+	_(qof_op_vers,)     \
+	_(qof_op_compress,) \
+	_(qof_op_debug,)
+
+/** Define the variables for the standard QOF CLI options.
+
+If you remove any QOF CLI options, ensure you also remove
+the option variable and it's initialiser.
+*/
+#define QOF_OP_VARS \
+       const char *exclude,  *date_time,  *category,  *database; \
+       const char *sql_file, *write_file, *sql_query, *filename;
+
+/** initialise the standard QOF CLI option variables.
+
+A simple convenience macro.
+*/
+#define QOF_OP_INIT    \
+       exclude = NULL;    \
+       category = NULL;   \
+       database = NULL;   \
+       sql_file = NULL;   \
+       write_file = NULL; \
+       sql_query = NULL;  \
+       filename = NULL;
+/** @} */
+/** @} */
+
+#endif				/* _QOF_MAIN_H */


Property changes on: gnucash/branches/cashutil/src/bin/test
___________________________________________________________________
Name: svn:ignore
   - Makefile
Makefile.in
overrides
overrides.stamp
   + Makefile
Makefile.in
overrides
overrides.stamp
semantic.cache




More information about the gnucash-changes mailing list