1 /********************************************************************\
2  * This program is free software; you can redistribute it and/or    *
3  * modify it under the terms of the GNU General Public License as   *
4  * published by the Free Software Foundation; either version 2 of   *
5  * the License, or (at your option) any later version.              *
6  *                                                                  *
7  * This program is distributed in the hope that it will be useful,  *
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
10  * GNU General Public License for more details.                     *
11  *                                                                  *
12  * You should have received a copy of the GNU General Public License*
13  * along with this program; if not, contact:                        *
14  *                                                                  *
15  * Free Software Foundation           Voice:  +1-617-542-5942       *
16  * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
17  * Boston, MA  02110-1301,  USA       gnu@gnu.org                   *
18  *                                                                  *
19 \********************************************************************/
20 
21 #if defined(SWIGGUILE)
22 %{
23 /* Disable -Waddress.  GCC 4.2 warns (and fails to compile with -Werror) when
24  * passing the address of a guid on the stack to QOF_BOOK_LOOKUP_ENTITY via
25  * gncInvoiceLookup and friends.  When the macro gets inlined, the compiler
26  * emits a warning that the guid null pointer test is always true.
27  */
28 #if (__GNUC__ >= 4 && __GNUC_MINOR__ >= 2)
29 #    pragma GCC diagnostic warning "-Waddress"
30 #endif
31 %}
32 #endif
33 
34 %rename(gncOwnerReturnGUID) gncOwnerRetGUID;
35 
36 %inline %{
gncTaxTableReturnGUID(GncTaxTable * x)37 static GncGUID gncTaxTableReturnGUID(GncTaxTable *x)
38 { return (x ? *(qof_instance_get_guid(QOF_INSTANCE(x))) : *(guid_null())); }
39 
gncInvoiceReturnGUID(GncInvoice * x)40 static GncGUID gncInvoiceReturnGUID(GncInvoice *x)
41 { return (x ? *(qof_instance_get_guid(QOF_INSTANCE(x))) : *(guid_null())); }
42 
gncJobReturnGUID(GncJob * x)43 static GncGUID gncJobReturnGUID(GncJob *x)
44 { return (x ? *(qof_instance_get_guid(QOF_INSTANCE(x))) : *(guid_null())); }
45 
gncVendorReturnGUID(GncVendor * x)46 static GncGUID gncVendorReturnGUID(GncVendor *x)
47 { return (x ? *(qof_instance_get_guid(QOF_INSTANCE(x))) : *(guid_null())); }
48 
gncCustomerReturnGUID(GncCustomer * x)49 static GncGUID gncCustomerReturnGUID(GncCustomer *x)
50 { return (x ? *(qof_instance_get_guid(QOF_INSTANCE(x))) : *(guid_null())); }
51 
gncEmployeeReturnGUID(GncEmployee * x)52 static GncGUID gncEmployeeReturnGUID(GncEmployee *x)
53 { return (x ? *(qof_instance_get_guid(QOF_INSTANCE(x))) : *(guid_null())); }
54 
gncLotReturnGUID(GNCLot * x)55 static GncGUID gncLotReturnGUID(GNCLot *x)
56 { return (x ? *(qof_instance_get_guid(QOF_INSTANCE(x))) : *(guid_null())); }
57 
gncTaxTableLookupFlip(GncGUID g,QofBook * b)58 static GncTaxTable * gncTaxTableLookupFlip(GncGUID g, QofBook *b)
59 { return gncTaxTableLookup(b, &g); }
60 
gncInvoiceLookupFlip(GncGUID g,QofBook * b)61 static GncInvoice * gncInvoiceLookupFlip(GncGUID g, QofBook *b)
62 { return gncInvoiceLookup(b, &g); }
63 
gncJobLookupFlip(GncGUID g,QofBook * b)64 static GncJob * gncJobLookupFlip(GncGUID g, QofBook *b)
65 { return gncJobLookup(b, &g); }
66 
gncVendorLookupFlip(GncGUID g,QofBook * b)67 static GncVendor * gncVendorLookupFlip(GncGUID g, QofBook *b)
68 { return gncVendorLookup(b, &g); }
69 
gncCustomerLookupFlip(GncGUID g,QofBook * b)70 static GncCustomer * gncCustomerLookupFlip(GncGUID g, QofBook *b)
71 { return gncCustomerLookup(b, &g); }
72 
gncEmployeeLookupFlip(GncGUID g,QofBook * b)73 static GncEmployee * gncEmployeeLookupFlip(GncGUID g, QofBook *b)
74 { return gncEmployeeLookup(b, &g); }
75 
76 %}
77 
78 GLIST_HELPER_INOUT(GncInvoiceList, SWIGTYPE_p__gncInvoice);
79 GLIST_HELPER_INOUT(EntryList, SWIGTYPE_p__gncEntry);
80 GLIST_HELPER_INOUT(GncTaxTableGetTables, SWIGTYPE_p__gncTaxTable);
81 GLIST_HELPER_INOUT(GncTaxTableEntryList, SWIGTYPE_p__gncTaxTableEntry);
82 GLIST_HELPER_INOUT(OwnerList, SWIGTYPE_p__gncOwner);
83 
84 #if defined(SWIGGUILE)
85 %typemap(in) GncAccountValue * "$1 = gnc_scm_to_account_value_ptr($input);"
86 %typemap(out) GncAccountValue * "$result = gnc_account_value_ptr_to_scm($1);"
87 %typemap(in) AccountValueList * {
88   SCM list = $input;
89   GList *c_list = NULL;
90 
91   while (!scm_is_null(list)) {
92         GncAccountValue *p;
93 
94         SCM p_scm = SCM_CAR(list);
95         if (scm_is_false(p_scm) || scm_is_null(p_scm))
96            p = NULL;
97         else
98            p = gnc_scm_to_account_value_ptr(p_scm);
99 
100         c_list = g_list_prepend(c_list, p);
101         list = SCM_CDR(list);
102   }
103 
104   $1 = g_list_reverse(c_list);
105 }
106 %typemap(out) AccountValueList * {
107   SCM list = SCM_EOL;
108   GList *node;
109 
110   for (node = $1; node; node = node->next)
111     list = scm_cons(gnc_account_value_ptr_to_scm(node->data), list);
112 
113   $result = scm_reverse(list);
114 }
115 #endif
116 
117 
118 /* Parse the header files to generate wrappers */
119 %include <gncAddress.h>
120 %include <gncBillTerm.h>
121 %include <gncBusiness.h>
122 %include <gncCustomer.h>
123 %include <gncEmployee.h>
124 %include <gncEntry.h>
125 %include <gncInvoice.h>
126 %include <gncJob.h>
127 %include <gncOrder.h>
128 %include <gncOwner.h>
129 %include <gncTaxTable.h>
130 %include <gncVendor.h>
131 #if defined(SWIGGUILE)
132 %include <gnc-engine-guile.h>
133 #endif
134 /* Import query bindings for the below invoice query functions (but
135  * don't generate bindings for them). */
136 %import <qofquery.h>
137 
138 #define URL_TYPE_CUSTOMER GNC_ID_CUSTOMER
139 #define URL_TYPE_VENDOR GNC_ID_VENDOR
140 #define URL_TYPE_EMPLOYEE GNC_ID_EMPLOYEE
141 #define URL_TYPE_JOB GNC_ID_JOB
142 #define URL_TYPE_INVOICE GNC_ID_INVOICE
143 // not exactly clean
144 #define URL_TYPE_OWNERREPORT "owner-report"
145 
146 %inline %{
qof_query_create_for_invoices(void)147 static QofQuery * qof_query_create_for_invoices(void) {
148   return qof_query_create_for(GNC_ID_INVOICE);
149 }
150 
qof_query_run_for_invoices(QofQuery * q)151 static GncInvoiceList * qof_query_run_for_invoices(QofQuery *q) {
152     return qof_query_run(q);
153 }
154 %}
155 
156 #if defined(SWIGGUILE)
157 %init {
158   {
159     char tmp[100];
160 
161 #define SET_ENUM(e) snprintf(tmp, 100, "(set! %s (%s))", (e), (e));  \
162     scm_c_eval_string(tmp);
163 
164     SET_ENUM("GNC-OWNER-CUSTOMER");
165     SET_ENUM("GNC-OWNER-VENDOR");
166     SET_ENUM("GNC-OWNER-EMPLOYEE");
167     SET_ENUM("GNC-OWNER-JOB");
168     SET_ENUM("GNC-AMT-TYPE-VALUE");
169     SET_ENUM("GNC-AMT-TYPE-PERCENT");
170 
171     SET_ENUM("URL-TYPE-CUSTOMER");
172     SET_ENUM("URL-TYPE-VENDOR");
173     SET_ENUM("URL-TYPE-EMPLOYEE");
174     SET_ENUM("URL-TYPE-JOB");
175     SET_ENUM("URL-TYPE-INVOICE");
176     SET_ENUM("URL-TYPE-OWNERREPORT");
177 
178     SET_ENUM("INVOICE-FROM-TXN");
179     SET_ENUM("INVOICE-FROM-LOT");
180     SET_ENUM("INVOICE-OWNER");
181     SET_ENUM("INVOICE-BILLTO");
182     SET_ENUM("OWNER-PARENTG");
183     SET_ENUM("OWNER-FROM-LOT");
184 
185     SET_ENUM("GNC-INVOICE-UNDEFINED");
186     SET_ENUM("GNC-INVOICE-CUST-INVOICE");
187     SET_ENUM("GNC-INVOICE-VEND-INVOICE");
188     SET_ENUM("GNC-INVOICE-EMPL-INVOICE");
189     SET_ENUM("GNC-INVOICE-CUST-CREDIT-NOTE");
190     SET_ENUM("GNC-INVOICE-VEND-CREDIT-NOTE");
191     SET_ENUM("GNC-INVOICE-EMPL-CREDIT-NOTE");
192 
193 #undef SET_ENUM
194   }
195 
196 }
197 #endif
198