I've attached a patch to move utils.c utils.h to src/engine as discussed in Bug 625193.
Mike E -- GPG Key: 1024D/050895C2 Keyserver: http://pgp.mit.edu/ Search String: 0x050895C2
diff --git src/engine/Makefile.am src/engine/Makefile.am index dc99dee..be838d5 100644 --- src/engine/Makefile.am +++ src/engine/Makefile.am @@ -55,6 +55,7 @@ libgncmod_engine_la_SOURCES = \ gncOrder.c \ gncOwner.c \ gncTaxTable.c \ + gncIDSearch.c \ gncVendor.c EXTRA_libgncmod_engine_la_SOURCES = iso-4217-currencies.c diff --git src/engine/gncIDSearch.c src/engine/gncIDSearch.c new file mode 100644 index 0000000..3237fee --- /dev/null +++ src/engine/gncIDSearch.c @@ -0,0 +1,179 @@ +/** utils.c +* +* 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. +* +* Developed (aka copied?) from code written by Sebastian Held <sebastian.h...@gmx.de> +* as part of his GnuCash invoice importer module +* Mike Evans <mi...@saxicola.co.uk> +* +**********************************************************************/ + +#include "gncIDSearch.h" + + +/*********************************************************************** + * Search the book for a Customer with the same ID. If it exists return a + * Customer object, if nit then return NULL. + @param QofBook The book + @param gchar ID of the Customer + @return GncCustomer * Pointer to the customer or NULL of there is no customer + * + **********************************************************************/ +GncCustomer * +search_customer_on_id (QofBook * book, const gchar *id) +{ + QueryNew *q; + GNCIdType type = GNC_CUSTOMER_MODULE_NAME; + GList *result; // do not free this! + QueryPredData_t string_pred_data; + GncCustomer *customer = NULL; + gint len; + + g_return_val_if_fail (id, NULL); + g_return_val_if_fail (book, NULL); + + // Build the query + q = gncQueryCreateFor (type); + gncQuerySetBook (q, book); + + // Search only the customer id field + string_pred_data = gncQueryStringPredicate (COMPARE_EQUAL, id, STRING_MATCH_NORMAL, FALSE); + gncQueryAddTerm (q, gncQueryBuildParamList(CUSTOMER_ID), string_pred_data, QUERY_AND); + + // Run the query + result = gncQueryRun (q); + + // now compare _exactly_ + len = g_list_length (result); + if (result && (len>0)) { + result = g_list_first (result); + while (result) { + GncCustomer *c = result->data; + if (strcmp(id,gncCustomerGetID(c)) == 0) { + // correct id found + customer = c; + break; + } + result = g_list_next (result); + } + } + + gncQueryDestroy (q); + return customer; +} + +/*********************************************************************** + * Search the book for an Invoice with the same ID. If it exists return an + * Invoice object, if not then return NULL. + @param QofBook The book + @param gchar ID of the invoice + @return GncCustomer * Pointer to the Invoice or NULL of there is no customer + * + **********************************************************************/ +GncInvoice * +search_invoice_on_id(QofBook *book, const gchar *id) +{ + QueryNew *q; + GNCIdType type = GNC_INVOICE_MODULE_NAME; + GList *result; // do not free this! + QueryPredData_t string_pred_data; + GncInvoice *invoice = NULL; + gint len; + + g_return_val_if_fail (id, NULL); + g_return_val_if_fail (book, NULL); + + // Build the query + q = gncQueryCreateFor (type); + gncQuerySetBook (q, book); + + // Search only the invoice id field + string_pred_data = gncQueryStringPredicate (COMPARE_EQUAL, id, STRING_MATCH_NORMAL, FALSE); + gncQueryAddTerm (q, gncQueryBuildParamList(INVOICE_ID), string_pred_data, QUERY_AND); + + // Run the query + result = gncQueryRun (q); + + // now compare _exactly_ + len = g_list_length (result); + if (result && (len>0)) { + result = g_list_first (result); + while (result) { + GncInvoice *c = result->data; + if (strcmp(id,gncInvoiceGetID(c)) == 0) { + // correct id found + invoice = c; + break; + } + result = g_list_next (result); + } + } + + gncQueryDestroy (q); + return invoice; +} + + +/*********************************************************************** + * Search the book for a Bill with the same ID. If it exists return an + * Invoice object, if not then return NULL. + @param QofBook The book + @param gchar ID of the invoice + @return GncCustomer * Pointer to the Invoice or NULL of there is no customer + * + **********************************************************************/ +GncInvoice * +search_bill_on_id(QofBook *book, const gchar *id) +{ + QueryNew *q; + GNCIdType type = GNC_INVOICE_MODULE_NAME; + GList *result; // do not free this! + QueryPredData_t string_pred_data; + GncInvoice *bill = NULL; + gint len; + + g_return_val_if_fail (id, NULL); + g_return_val_if_fail (book, NULL); + + // Build the query + q = gncQueryCreateFor (type); + gncQuerySetBook (q, book); + + // Search only the invoice id field + string_pred_data = gncQueryStringPredicate (COMPARE_EQUAL, id, STRING_MATCH_NORMAL, FALSE); + gncQueryAddTerm (q, gncQueryBuildParamList(INVOICE_ID), string_pred_data, QUERY_AND); + + // Run the query + result = gncQueryRun (q); + + // now compare _exactly_ + len = g_list_length (result); + if (result && (len>0)) { + result = g_list_first (result); + while (result) { + GncInvoice *c = result->data; + if (strcmp(id,gncInvoiceGetID(c)) == 0) { + // correct id found + bill = c; + break; + } + result = g_list_next (result); + } + } + + gncQueryDestroy (q); + return bill; +} diff --git src/engine/gncIDSearch.h src/engine/gncIDSearch.h new file mode 100644 index 0000000..d1b377b --- /dev/null +++ src/engine/gncIDSearch.h @@ -0,0 +1,47 @@ +/** utils.h +* +* 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. +* +* Developed from code written by Sebastian Held <sebastian.h...@gmx.de> +* as part of his invoice importer module +* Mike Evans <mi...@saxicola.co.uk> +* +**********************************************************************/ +#include "config.h" +#include <glib/gi18n.h> +#include <regex.h> +#include <glib.h> +#include <glib/gstdio.h> +#include "qof.h" +//#include "gncAddressP.h" +#include "gncCustomerP.h" +//#include "gncCustomer.h" +#include "gncInvoice.h" +#include "gncBusiness.h" +// query +#include "QueryCore.h" +#include "QueryNew.h" +#include "GNCId.h" + +#ifndef GNC_PLUGIN_invoice_import_invoice_import_H +#define GNC_PLUGIN_invoice_import_invoice_import_H + + +GncCustomer * search_customer_on_id (QofBook *book, const gchar *id); +GncInvoice * search_invoice_on_id (QofBook *book, const gchar *id); +GncInvoice * search_bill_on_id (QofBook *book, const gchar *id); + +#endif diff --git src/optional/python-bindings/Makefile.am src/optional/python-bindings/Makefile.am index 6f5874e..d0fcbe4 100644 --- src/optional/python-bindings/Makefile.am +++ src/optional/python-bindings/Makefile.am @@ -12,7 +12,7 @@ pkgpython_PYTHON = \ pkgpyexec_LTLIBRARIES = _gnucash_core_c.la _gnucash_core_c_la_SOURCES = \ - gnucash_core.c utils.c + gnucash_core.c _gnucash_core_c_la_CPPFLAGS = \ $(PYTHON_CPPFLAGS) \ diff --git src/optional/python-bindings/gnucash_core.i src/optional/python-bindings/gnucash_core.i index 82d1a5e..57cca55 100644 --- src/optional/python-bindings/gnucash_core.i +++ src/optional/python-bindings/gnucash_core.i @@ -57,7 +57,7 @@ #include "gncJob.h" #include "gncEntry.h" #include "gncTaxTable.h" -#include "utils.h" +#include "gncIDSearch.h" %} @@ -177,7 +177,7 @@ %include <gncJob.h> %include <gncEntry.h> %include <gncTaxTable.h> -%include "utils.h" +%include <gncIDSearch.h> %init %{ diff --git src/optional/python-bindings/utils.c src/optional/python-bindings/utils.c deleted file mode 100644 index f3710dd..0000000 --- src/optional/python-bindings/utils.c +++ /dev/null @@ -1,179 +0,0 @@ -/** utils.c -* -* 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. -* -* Developed (aka copied?) from code written by Sebastian Held <sebastian.h...@gmx.de> -* as part of his GnuCash invoice importer module -* Mike Evans <mi...@saxicola.co.uk> -* -**********************************************************************/ - -#include "utils.h" - - -/*********************************************************************** - * Search the book for a Customer with the same ID. If it exists return a - * Customer object, if nit then return NULL. - @param QofBook The book - @param gchar ID of the Customer - @return GncCustomer * Pointer to the customer or NULL of there is no customer - * - **********************************************************************/ -GncCustomer * -search_customer_on_id (QofBook * book, const gchar *id) -{ - QueryNew *q; - GNCIdType type = GNC_CUSTOMER_MODULE_NAME; - GList *result; // do not free this! - QueryPredData_t string_pred_data; - GncCustomer *customer = NULL; - gint len; - - g_return_val_if_fail (id, NULL); - g_return_val_if_fail (book, NULL); - - // Build the query - q = gncQueryCreateFor (type); - gncQuerySetBook (q, book); - - // Search only the customer id field - string_pred_data = gncQueryStringPredicate (COMPARE_EQUAL, id, STRING_MATCH_NORMAL, FALSE); - gncQueryAddTerm (q, gncQueryBuildParamList(CUSTOMER_ID), string_pred_data, QUERY_AND); - - // Run the query - result = gncQueryRun (q); - - // now compare _exactly_ - len = g_list_length (result); - if (result && (len>0)) { - result = g_list_first (result); - while (result) { - GncCustomer *c = result->data; - if (strcmp(id,gncCustomerGetID(c)) == 0) { - // correct id found - customer = c; - break; - } - result = g_list_next (result); - } - } - - gncQueryDestroy (q); - return customer; -} - -/*********************************************************************** - * Search the book for an Invoice with the same ID. If it exists return an - * Invoice object, if not then return NULL. - @param QofBook The book - @param gchar ID of the invoice - @return GncCustomer * Pointer to the Invoice or NULL of there is no customer - * - **********************************************************************/ -GncInvoice * -search_invoice_on_id(QofBook *book, const gchar *id) -{ - QueryNew *q; - GNCIdType type = GNC_INVOICE_MODULE_NAME; - GList *result; // do not free this! - QueryPredData_t string_pred_data; - GncInvoice *invoice = NULL; - gint len; - - g_return_val_if_fail (id, NULL); - g_return_val_if_fail (book, NULL); - - // Build the query - q = gncQueryCreateFor (type); - gncQuerySetBook (q, book); - - // Search only the invoice id field - string_pred_data = gncQueryStringPredicate (COMPARE_EQUAL, id, STRING_MATCH_NORMAL, FALSE); - gncQueryAddTerm (q, gncQueryBuildParamList(INVOICE_ID), string_pred_data, QUERY_AND); - - // Run the query - result = gncQueryRun (q); - - // now compare _exactly_ - len = g_list_length (result); - if (result && (len>0)) { - result = g_list_first (result); - while (result) { - GncInvoice *c = result->data; - if (strcmp(id,gncInvoiceGetID(c)) == 0) { - // correct id found - invoice = c; - break; - } - result = g_list_next (result); - } - } - - gncQueryDestroy (q); - return invoice; -} - - -/*********************************************************************** - * Search the book for a Bill with the same ID. If it exists return an - * Invoice object, if not then return NULL. - @param QofBook The book - @param gchar ID of the invoice - @return GncCustomer * Pointer to the Invoice or NULL of there is no customer - * - **********************************************************************/ -GncInvoice * -search_bill_on_id(QofBook *book, const gchar *id) -{ - QueryNew *q; - GNCIdType type = GNC_INVOICE_MODULE_NAME; - GList *result; // do not free this! - QueryPredData_t string_pred_data; - GncInvoice *bill = NULL; - gint len; - - g_return_val_if_fail (id, NULL); - g_return_val_if_fail (book, NULL); - - // Build the query - q = gncQueryCreateFor (type); - gncQuerySetBook (q, book); - - // Search only the invoice id field - string_pred_data = gncQueryStringPredicate (COMPARE_EQUAL, id, STRING_MATCH_NORMAL, FALSE); - gncQueryAddTerm (q, gncQueryBuildParamList(INVOICE_ID), string_pred_data, QUERY_AND); - - // Run the query - result = gncQueryRun (q); - - // now compare _exactly_ - len = g_list_length (result); - if (result && (len>0)) { - result = g_list_first (result); - while (result) { - GncInvoice *c = result->data; - if (strcmp(id,gncInvoiceGetID(c)) == 0) { - // correct id found - bill = c; - break; - } - result = g_list_next (result); - } - } - - gncQueryDestroy (q); - return bill; -} diff --git src/optional/python-bindings/utils.h src/optional/python-bindings/utils.h deleted file mode 100644 index 36eb31d..0000000 --- src/optional/python-bindings/utils.h +++ /dev/null @@ -1,57 +0,0 @@ -/** utils.h -* -* 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. -* -* Developed from code written by Sebastian Held <sebastian.h...@gmx.de> -* as part of his invoice importer module -* Mike Evans <mi...@saxicola.co.uk> -* -**********************************************************************/ - - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <glib/gi18n.h> -#include <regex.h> -#include <glib.h> -#include <glib/gstdio.h> - -#include "gnc-ui.h" -#include "gnc-ui-util.h" -#include "gnome-utils/gnc-gui-query.h" -#include "gncAddress.h" -#include "gncCustomerP.h" -#include "gncCustomer.h" -#include "gncInvoice.h" -#include "gnc-exp-parser.h" - -// query -#include "QueryCore.h" -#include "QueryNew.h" -#include "GNCId.h" - - - -#ifndef GNC_PLUGIN_invoice_import_invoice_import_H -#define GNC_PLUGIN_invoice_import_invoice_import_H - -GncCustomer * search_customer_on_id (QofBook *book, const gchar *id); -GncInvoice * search_invoice_on_id (QofBook *book, const gchar *id); -GncInvoice * search_bill_on_id (QofBook *book, const gchar *id); - -#endif
_______________________________________________ gnucash-devel mailing list gnucash-devel@gnucash.org https://lists.gnucash.org/mailman/listinfo/gnucash-devel