2001-08-07 18:29:04 -05:00
|
|
|
/********************************************************************\
|
|
|
|
* engine-helpers.c -- gnucash g-wrap helper functions *
|
2003-06-10 12:59:06 -05:00
|
|
|
* Copyright (C) 2000 Linas Vepstas <linas@linas.org> *
|
2001-08-07 18:29:04 -05:00
|
|
|
* Copyright (C) 2001 Linux Developers Group, Inc. *
|
|
|
|
* *
|
|
|
|
* 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, contact: *
|
|
|
|
* *
|
|
|
|
* Free Software Foundation Voice: +1-617-542-5942 *
|
|
|
|
* 59 Temple Place - Suite 330 Fax: +1-617-542-2652 *
|
|
|
|
* Boston, MA 02111-1307, USA gnu@gnu.org *
|
|
|
|
* *
|
|
|
|
\********************************************************************/
|
|
|
|
|
|
|
|
#include "config.h"
|
2001-11-14 03:07:49 -06:00
|
|
|
|
2002-01-09 15:39:49 -06:00
|
|
|
#include <g-wrap-wct.h>
|
2001-11-14 03:07:49 -06:00
|
|
|
#include <libguile.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2001-11-24 06:10:42 -06:00
|
|
|
#include "Account.h"
|
|
|
|
#include "Group.h"
|
2001-08-07 18:29:04 -05:00
|
|
|
#include "engine-helpers.h"
|
|
|
|
#include "glib-helpers.h"
|
2003-06-10 12:59:06 -05:00
|
|
|
#include "gnc-date.h"
|
2001-11-14 03:07:49 -06:00
|
|
|
#include "gnc-engine-util.h"
|
|
|
|
#include "gnc-engine.h"
|
|
|
|
#include "gnc-numeric.h"
|
2003-09-12 08:17:26 -05:00
|
|
|
#include "gnc-trace.h"
|
2003-02-22 02:15:53 -06:00
|
|
|
#include "guile-mappings.h"
|
2003-06-24 19:52:46 -05:00
|
|
|
#include "qofbook.h"
|
2003-06-25 02:38:15 -05:00
|
|
|
#include "qofquery.h"
|
|
|
|
#include "qofquery-p.h"
|
2003-06-25 00:14:10 -05:00
|
|
|
#include "qofquerycore.h"
|
|
|
|
#include "qofquerycore-p.h"
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2001-12-30 11:02:56 -06:00
|
|
|
static short module = MOD_ENGINE;
|
|
|
|
|
2001-08-07 18:29:04 -05:00
|
|
|
Timespec
|
2001-12-30 11:02:56 -06:00
|
|
|
gnc_transaction_get_date_posted(Transaction *t)
|
|
|
|
{
|
2001-08-07 18:29:04 -05:00
|
|
|
Timespec result;
|
|
|
|
xaccTransGetDatePostedTS(t, &result);
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
Timespec
|
2001-12-30 11:02:56 -06:00
|
|
|
gnc_transaction_get_date_entered(Transaction *t)
|
|
|
|
{
|
2001-08-07 18:29:04 -05:00
|
|
|
Timespec result;
|
|
|
|
xaccTransGetDateEnteredTS(t, &result);
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
Timespec
|
2001-12-30 11:02:56 -06:00
|
|
|
gnc_split_get_date_reconciled(Split *s)
|
|
|
|
{
|
2001-08-07 18:29:04 -05:00
|
|
|
Timespec result;
|
|
|
|
xaccSplitGetDateReconciledTS(s, &result);
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-12-30 11:02:56 -06:00
|
|
|
gnc_transaction_set_date_posted(Transaction *t, const Timespec d)
|
|
|
|
{
|
2001-08-07 18:29:04 -05:00
|
|
|
xaccTransSetDatePostedTS(t, &d);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-12-30 11:02:56 -06:00
|
|
|
gnc_transaction_set_date_entered(Transaction *t, const Timespec d)
|
|
|
|
{
|
2001-08-07 18:29:04 -05:00
|
|
|
xaccTransSetDateEnteredTS(t, &d);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gnc_transaction_set_date(Transaction *t, Timespec ts)
|
|
|
|
{
|
|
|
|
xaccTransSetDatePostedTS(t, &ts);
|
|
|
|
}
|
|
|
|
|
|
|
|
SCM
|
|
|
|
gnc_timespec2timepair(Timespec t)
|
|
|
|
{
|
|
|
|
SCM secs;
|
|
|
|
SCM nsecs;
|
|
|
|
|
|
|
|
secs = gnc_gint64_to_scm(t.tv_sec);
|
2003-02-22 02:15:53 -06:00
|
|
|
nsecs = scm_long2num(t.tv_nsec);
|
|
|
|
return(scm_cons(secs, nsecs));
|
2001-08-07 18:29:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
Timespec
|
|
|
|
gnc_timepair2timespec(SCM x)
|
|
|
|
{
|
|
|
|
Timespec result = {0,0};
|
|
|
|
if (gnc_timepair_p (x))
|
|
|
|
{
|
2003-02-22 02:15:53 -06:00
|
|
|
result.tv_sec = gnc_scm_to_gint64(SCM_CAR(x));
|
|
|
|
result.tv_nsec = scm_num2long(SCM_CDR(x), SCM_ARG1, __FUNCTION__);
|
2001-08-07 18:29:04 -05:00
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
gnc_timepair_p(SCM x)
|
|
|
|
{
|
2003-02-22 02:15:53 -06:00
|
|
|
return(SCM_CONSP(x) &&
|
|
|
|
gnc_gh_gint64_p(SCM_CAR(x)) &&
|
|
|
|
gnc_gh_gint64_p(SCM_CDR(x)));
|
2001-08-07 18:29:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
SCM
|
|
|
|
gnc_guid2scm(GUID guid)
|
|
|
|
{
|
|
|
|
char string[GUID_ENCODING_LENGTH + 1];
|
|
|
|
|
|
|
|
if (!guid_to_string_buff(&guid, string))
|
|
|
|
return SCM_UNDEFINED;
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
return scm_makfrom0str(string);
|
2001-08-07 18:29:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
GUID
|
|
|
|
gnc_scm2guid(SCM guid_scm) {
|
|
|
|
char string[GUID_ENCODING_LENGTH + 1];
|
|
|
|
GUID guid;
|
|
|
|
|
|
|
|
gh_get_substr(guid_scm, string, 0, GUID_ENCODING_LENGTH);
|
|
|
|
string[GUID_ENCODING_LENGTH] = '\0';
|
|
|
|
|
|
|
|
string_to_guid(string, &guid);
|
|
|
|
|
|
|
|
return guid;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
gnc_guid_p(SCM guid_scm) {
|
|
|
|
char string[GUID_ENCODING_LENGTH + 1];
|
|
|
|
GUID guid;
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
if (!SCM_STRINGP(guid_scm))
|
2001-11-05 18:49:46 -06:00
|
|
|
return FALSE;
|
2001-08-07 18:29:04 -05:00
|
|
|
|
|
|
|
gh_get_substr(guid_scm, string, 0, GUID_ENCODING_LENGTH);
|
|
|
|
string[GUID_ENCODING_LENGTH] = '\0';
|
|
|
|
|
|
|
|
return string_to_guid(string, &guid);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/********************************************************************
|
|
|
|
* type converters for query API
|
|
|
|
********************************************************************/
|
|
|
|
|
|
|
|
/* The query scm representation is a list of pairs, where the
|
|
|
|
* car of each pair is one of the following symbols:
|
|
|
|
*
|
|
|
|
* Symbol cdr
|
|
|
|
* 'terms list of OR terms
|
|
|
|
* 'primary-sort scm rep of sort_type_t
|
|
|
|
* 'secondary-sort scm rep of sort_type_t
|
|
|
|
* 'tertiary-sort scm rep of sort_type_t
|
|
|
|
* 'primary-increasing boolean
|
|
|
|
* 'secondary-increasing boolean
|
|
|
|
* 'tertiary-increasing boolean
|
|
|
|
* 'max-splits integer
|
|
|
|
*
|
|
|
|
* Each OR term is a list of AND terms.
|
|
|
|
* Each AND term is a list of one of the following forms:
|
|
|
|
*
|
|
|
|
* ('pd-date pr-type sense-bool use-start-bool start-timepair
|
|
|
|
* use-end-bool use-end-timepair)
|
|
|
|
* ('pd-amount pr-type sense-bool amt-match-how amt-match-sign amount)
|
|
|
|
* ('pd-account pr-type sense-bool acct-match-how list-of-account-guids)
|
|
|
|
* ('pd-string pr-type sense-bool case-sense-bool use-regexp-bool string)
|
|
|
|
* ('pd-cleared pr-type sense-bool cleared-field)
|
|
|
|
* ('pd-balance pr-type sense-bool balance-field)
|
|
|
|
*/
|
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
typedef enum {
|
|
|
|
gnc_QUERY_v1 = 1,
|
|
|
|
gnc_QUERY_v2
|
|
|
|
} query_version_t;
|
|
|
|
|
2001-08-07 18:29:04 -05:00
|
|
|
static SCM
|
|
|
|
gnc_gw_enum_val2scm (const char *typestr, int value)
|
|
|
|
{
|
|
|
|
char *func_name;
|
|
|
|
SCM func;
|
|
|
|
SCM scm;
|
|
|
|
|
|
|
|
func_name = g_strdup_printf ("gw:enum-%s-val->sym", typestr);
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
func = scm_c_eval_string (func_name);
|
|
|
|
if (SCM_PROCEDUREP (func))
|
|
|
|
scm = scm_call_2 (func, scm_int2num (value), SCM_BOOL_F);
|
2001-08-07 18:29:04 -05:00
|
|
|
else
|
|
|
|
scm = SCM_BOOL_F;
|
|
|
|
|
|
|
|
g_free (func_name);
|
|
|
|
|
|
|
|
return scm;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
gnc_gw_enum_scm2val (const char *typestr, SCM enum_scm)
|
|
|
|
{
|
|
|
|
char *func_name;
|
|
|
|
SCM func;
|
|
|
|
SCM scm;
|
|
|
|
|
|
|
|
func_name = g_strdup_printf ("gw:enum-%s-val->int", typestr);
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
func = scm_c_eval_string (func_name);
|
|
|
|
if (SCM_PROCEDUREP (func))
|
|
|
|
scm = scm_call_1 (func, enum_scm);
|
2001-08-07 18:29:04 -05:00
|
|
|
else
|
2003-02-22 02:15:53 -06:00
|
|
|
scm = scm_int2num (0);
|
2001-08-07 18:29:04 -05:00
|
|
|
|
|
|
|
g_free (func_name);
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
return scm_num2int (scm, SCM_ARG1, __FUNCTION__);
|
2001-08-07 18:29:04 -05:00
|
|
|
}
|
|
|
|
|
2003-06-25 23:30:43 -05:00
|
|
|
/* QofCompareFunc */
|
2002-06-05 16:59:35 -05:00
|
|
|
|
2001-08-07 18:29:04 -05:00
|
|
|
static SCM
|
2003-06-25 00:14:10 -05:00
|
|
|
gnc_query_compare2scm (QofQueryCompare how)
|
2001-08-07 18:29:04 -05:00
|
|
|
{
|
2002-06-05 16:59:35 -05:00
|
|
|
return gnc_gw_enum_val2scm ("<gnc:query-compare-how>", how);
|
2001-08-07 18:29:04 -05:00
|
|
|
}
|
|
|
|
|
2003-06-25 00:14:10 -05:00
|
|
|
static QofQueryCompare
|
2002-06-05 16:59:35 -05:00
|
|
|
gnc_query_scm2compare (SCM how_scm)
|
2001-08-07 18:29:04 -05:00
|
|
|
{
|
2002-06-05 16:59:35 -05:00
|
|
|
return gnc_gw_enum_scm2val ("<gnc:query-compare-how>", how_scm);
|
2001-08-07 18:29:04 -05:00
|
|
|
}
|
|
|
|
|
2003-06-25 00:14:10 -05:00
|
|
|
/* QofStringMatch */
|
2001-08-07 18:29:04 -05:00
|
|
|
static SCM
|
2003-06-25 00:14:10 -05:00
|
|
|
gnc_query_string2scm (QofStringMatch how)
|
2001-08-07 18:29:04 -05:00
|
|
|
{
|
2002-06-05 16:59:35 -05:00
|
|
|
return gnc_gw_enum_val2scm ("<gnc:string-match-how>", how);
|
2001-08-07 18:29:04 -05:00
|
|
|
}
|
|
|
|
|
2003-06-25 00:14:10 -05:00
|
|
|
static QofStringMatch
|
2002-06-05 16:59:35 -05:00
|
|
|
gnc_query_scm2string (SCM how_scm)
|
2001-08-07 18:29:04 -05:00
|
|
|
{
|
2002-06-05 16:59:35 -05:00
|
|
|
return gnc_gw_enum_scm2val ("<gnc:string-match-how>", how_scm);
|
2001-08-07 18:29:04 -05:00
|
|
|
}
|
|
|
|
|
2003-06-25 00:14:10 -05:00
|
|
|
/* QofDateMatch */
|
2001-08-07 18:29:04 -05:00
|
|
|
static SCM
|
2003-06-25 00:14:10 -05:00
|
|
|
gnc_query_date2scm (QofDateMatch how)
|
2001-08-07 18:29:04 -05:00
|
|
|
{
|
2002-06-05 16:59:35 -05:00
|
|
|
return gnc_gw_enum_val2scm ("<gnc:date-match-how>", how);
|
2001-08-07 18:29:04 -05:00
|
|
|
}
|
|
|
|
|
2003-06-25 00:14:10 -05:00
|
|
|
static QofDateMatch
|
2002-06-05 16:59:35 -05:00
|
|
|
gnc_query_scm2date (SCM how_scm)
|
2001-08-07 18:29:04 -05:00
|
|
|
{
|
2002-06-05 16:59:35 -05:00
|
|
|
return gnc_gw_enum_scm2val ("<gnc:date-match-how>", how_scm);
|
2001-08-07 18:29:04 -05:00
|
|
|
}
|
|
|
|
|
2003-06-25 00:14:10 -05:00
|
|
|
/* QofNumericMatch */
|
2001-08-07 18:29:04 -05:00
|
|
|
static SCM
|
2003-06-25 00:14:10 -05:00
|
|
|
gnc_query_numericop2scm (QofNumericMatch how)
|
2001-08-07 18:29:04 -05:00
|
|
|
{
|
2002-06-05 16:59:35 -05:00
|
|
|
return gnc_gw_enum_val2scm ("<gnc:numeric-match-how>", how);
|
2001-08-07 18:29:04 -05:00
|
|
|
}
|
|
|
|
|
2003-06-25 00:14:10 -05:00
|
|
|
static QofNumericMatch
|
2002-06-05 16:59:35 -05:00
|
|
|
gnc_query_scm2numericop (SCM how_scm)
|
2001-08-07 18:29:04 -05:00
|
|
|
{
|
2002-06-05 16:59:35 -05:00
|
|
|
return gnc_gw_enum_scm2val ("<gnc:numeric-match-how>", how_scm);
|
2001-08-07 18:29:04 -05:00
|
|
|
}
|
|
|
|
|
2003-06-25 00:14:10 -05:00
|
|
|
/* QofGuidMatch */
|
2001-08-07 18:29:04 -05:00
|
|
|
static SCM
|
2003-06-25 00:14:10 -05:00
|
|
|
gnc_query_guid2scm (QofGuidMatch how)
|
2001-08-07 18:29:04 -05:00
|
|
|
{
|
2002-06-05 16:59:35 -05:00
|
|
|
return gnc_gw_enum_val2scm ("<gnc:guid-match-how>", how);
|
2001-08-07 18:29:04 -05:00
|
|
|
}
|
|
|
|
|
2003-06-25 00:14:10 -05:00
|
|
|
static QofGuidMatch
|
2002-06-05 16:59:35 -05:00
|
|
|
gnc_query_scm2guid (SCM how_scm)
|
2001-08-07 18:29:04 -05:00
|
|
|
{
|
2002-06-05 16:59:35 -05:00
|
|
|
return gnc_gw_enum_scm2val ("<gnc:guid-match-how>", how_scm);
|
2001-08-07 18:29:04 -05:00
|
|
|
}
|
|
|
|
|
2003-06-25 00:14:10 -05:00
|
|
|
/* QofCharMatch */
|
2001-11-05 18:49:46 -06:00
|
|
|
static SCM
|
2003-06-25 00:14:10 -05:00
|
|
|
gnc_query_char2scm (QofCharMatch how)
|
2001-11-05 18:49:46 -06:00
|
|
|
{
|
2002-06-05 16:59:35 -05:00
|
|
|
return gnc_gw_enum_val2scm ("<gnc:char-match-how>", how);
|
2001-11-05 18:49:46 -06:00
|
|
|
}
|
|
|
|
|
2003-06-25 00:14:10 -05:00
|
|
|
static QofCharMatch
|
2002-06-05 16:59:35 -05:00
|
|
|
gnc_query_scm2char (SCM how_scm)
|
2001-11-05 18:49:46 -06:00
|
|
|
{
|
2002-06-05 16:59:35 -05:00
|
|
|
return gnc_gw_enum_scm2val ("<gnc:char-match-how>", how_scm);
|
2001-11-05 18:49:46 -06:00
|
|
|
}
|
|
|
|
|
2003-06-25 00:14:10 -05:00
|
|
|
static QofGuidMatch
|
2002-06-05 16:59:35 -05:00
|
|
|
gnc_scm2acct_match_how (SCM how_scm)
|
2001-08-07 18:29:04 -05:00
|
|
|
{
|
2003-06-25 00:14:10 -05:00
|
|
|
QofGuidMatch res;
|
2002-06-05 16:59:35 -05:00
|
|
|
char *how = gh_symbol2newstr (how_scm, NULL);
|
|
|
|
|
|
|
|
if (!safe_strcmp (how, "acct-match-all"))
|
2003-06-25 00:14:10 -05:00
|
|
|
res = QOF_GUID_MATCH_ALL;
|
2002-06-05 16:59:35 -05:00
|
|
|
else if (!safe_strcmp (how, "acct-match-any"))
|
2003-06-25 00:14:10 -05:00
|
|
|
res = QOF_GUID_MATCH_ANY;
|
2002-06-05 16:59:35 -05:00
|
|
|
else if (!safe_strcmp (how, "acct-match-none"))
|
2003-06-25 00:14:10 -05:00
|
|
|
res = QOF_GUID_MATCH_NONE;
|
2002-06-05 16:59:35 -05:00
|
|
|
else {
|
|
|
|
PINFO ("invalid account match: %s", how);
|
2003-06-25 00:14:10 -05:00
|
|
|
res = QOF_GUID_MATCH_NULL;
|
2002-06-05 16:59:35 -05:00
|
|
|
}
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
if (how) free (how);
|
|
|
|
return res;
|
2001-08-07 18:29:04 -05:00
|
|
|
}
|
|
|
|
|
2003-06-25 00:14:10 -05:00
|
|
|
static QofQueryCompare
|
2002-06-05 16:59:35 -05:00
|
|
|
gnc_scm2amt_match_how (SCM how_scm)
|
2001-08-07 18:29:04 -05:00
|
|
|
{
|
2003-06-25 00:14:10 -05:00
|
|
|
QofQueryCompare res;
|
2002-06-05 16:59:35 -05:00
|
|
|
char *how = gh_symbol2newstr (how_scm, NULL);
|
|
|
|
|
|
|
|
if (!safe_strcmp (how, "amt-match-atleast"))
|
2003-06-25 00:41:38 -05:00
|
|
|
res = QOF_COMPARE_GTE;
|
2002-06-05 16:59:35 -05:00
|
|
|
else if (!safe_strcmp (how, "amt-match-atmost"))
|
2003-06-25 00:41:38 -05:00
|
|
|
res = QOF_COMPARE_LTE;
|
2002-06-05 16:59:35 -05:00
|
|
|
else if (!safe_strcmp (how, "amt-match-exactly"))
|
2003-06-25 00:14:10 -05:00
|
|
|
res = QOF_COMPARE_EQUAL;
|
2002-06-05 16:59:35 -05:00
|
|
|
else {
|
|
|
|
PINFO ("invalid amount match: %s", how);
|
2003-06-25 00:14:10 -05:00
|
|
|
res = QOF_COMPARE_EQUAL;
|
2002-06-05 16:59:35 -05:00
|
|
|
}
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
if (how) free (how);
|
|
|
|
return res;
|
|
|
|
}
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2003-06-25 00:14:10 -05:00
|
|
|
static QofQueryCompare
|
2002-06-05 16:59:35 -05:00
|
|
|
gnc_scm2kvp_match_how (SCM how_scm)
|
|
|
|
{
|
2003-06-25 00:14:10 -05:00
|
|
|
QofQueryCompare res;
|
2002-06-05 16:59:35 -05:00
|
|
|
char *how = gh_symbol2newstr (how_scm, NULL);
|
|
|
|
|
|
|
|
if (!safe_strcmp (how, "kvp-match-lt"))
|
2003-06-25 00:14:10 -05:00
|
|
|
res = QOF_COMPARE_LT;
|
2002-06-05 16:59:35 -05:00
|
|
|
else if (!safe_strcmp (how, "kvp-match-lte"))
|
2003-06-25 00:41:38 -05:00
|
|
|
res = QOF_COMPARE_LTE;
|
2002-06-05 16:59:35 -05:00
|
|
|
else if (!safe_strcmp (how, "kvp-match-eq"))
|
2003-06-25 00:14:10 -05:00
|
|
|
res = QOF_COMPARE_EQUAL;
|
2002-06-05 16:59:35 -05:00
|
|
|
else if (!safe_strcmp (how, "kvp-match-gte"))
|
2003-06-25 00:41:38 -05:00
|
|
|
res = QOF_COMPARE_GTE;
|
2002-06-05 16:59:35 -05:00
|
|
|
else if (!safe_strcmp (how, "kvp-match-gt"))
|
2003-06-25 00:14:10 -05:00
|
|
|
res = QOF_COMPARE_GT;
|
2002-06-05 16:59:35 -05:00
|
|
|
else {
|
|
|
|
PINFO ("invalid kvp match: %s", how);
|
2003-06-25 00:14:10 -05:00
|
|
|
res = QOF_COMPARE_EQUAL;
|
2001-08-07 18:29:04 -05:00
|
|
|
}
|
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
if (how) free (how);
|
|
|
|
return res;
|
2001-08-07 18:29:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
gnc_scm2bitfield (const char *typestr, SCM field_scm)
|
|
|
|
{
|
|
|
|
int field = 0;
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
if (!SCM_LISTP (field_scm))
|
2001-08-07 18:29:04 -05:00
|
|
|
return 0;
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
while (!SCM_NULLP (field_scm))
|
2001-08-07 18:29:04 -05:00
|
|
|
{
|
|
|
|
SCM scm;
|
|
|
|
int bit;
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
scm = SCM_CAR (field_scm);
|
|
|
|
field_scm = SCM_CDR (field_scm);
|
2001-08-07 18:29:04 -05:00
|
|
|
|
|
|
|
bit = gnc_gw_enum_scm2val (typestr, scm);
|
|
|
|
field |= bit;
|
|
|
|
}
|
|
|
|
|
|
|
|
return field;
|
|
|
|
}
|
|
|
|
|
|
|
|
static cleared_match_t
|
|
|
|
gnc_scm2cleared_match_how (SCM how_scm)
|
|
|
|
{
|
|
|
|
return gnc_scm2bitfield ("<gnc:cleared-match-how>", how_scm);
|
|
|
|
}
|
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
static gboolean
|
|
|
|
gnc_scm2balance_match_how (SCM how_scm, gboolean *resp)
|
2001-08-07 18:29:04 -05:00
|
|
|
{
|
2002-06-05 16:59:35 -05:00
|
|
|
char *how;
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
if (!SCM_LISTP (how_scm))
|
2002-06-05 16:59:35 -05:00
|
|
|
return FALSE;
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
if (SCM_NULLP (how_scm))
|
2002-06-05 16:59:35 -05:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* Only allow a single-entry list */
|
2003-02-22 02:15:53 -06:00
|
|
|
if (!SCM_NULLP (SCM_CDR (how_scm)))
|
2002-06-05 16:59:35 -05:00
|
|
|
return FALSE;
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
how = gh_symbol2newstr (SCM_CAR (how_scm), NULL);
|
2002-06-05 16:59:35 -05:00
|
|
|
|
|
|
|
if (!safe_strcmp (how, "balance-match-balanced"))
|
|
|
|
*resp = TRUE;
|
|
|
|
else
|
|
|
|
*resp = FALSE;
|
|
|
|
|
|
|
|
if (how) free (how);
|
|
|
|
|
|
|
|
return TRUE;
|
2001-11-05 18:49:46 -06:00
|
|
|
}
|
|
|
|
|
2003-06-26 02:30:48 -05:00
|
|
|
static QofIdType
|
2001-11-05 18:49:46 -06:00
|
|
|
gnc_scm2kvp_match_where (SCM where_scm)
|
|
|
|
{
|
2003-06-26 02:30:48 -05:00
|
|
|
QofIdType res;
|
2002-06-05 16:59:35 -05:00
|
|
|
char *where;
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
if (!SCM_LISTP (where_scm))
|
2002-06-05 16:59:35 -05:00
|
|
|
return NULL;
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
where = gh_symbol2newstr (SCM_CAR (where_scm), NULL);
|
2002-06-05 16:59:35 -05:00
|
|
|
|
|
|
|
if (!safe_strcmp (where, "kvp-match-split"))
|
|
|
|
res = GNC_ID_SPLIT;
|
|
|
|
else if (!safe_strcmp (where, "kvp-match-trans"))
|
|
|
|
res = GNC_ID_TRANS;
|
|
|
|
else if (!safe_strcmp (where, "kvp-match-account"))
|
|
|
|
res = GNC_ID_ACCOUNT;
|
|
|
|
else {
|
|
|
|
PINFO ("Unknown kvp-match-where: %s", where);
|
|
|
|
res = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (where) free (where);
|
|
|
|
return res;
|
2001-11-05 18:49:46 -06:00
|
|
|
}
|
|
|
|
|
2001-08-07 18:29:04 -05:00
|
|
|
static SCM
|
2002-06-05 16:59:35 -05:00
|
|
|
gnc_guid_glist2scm (GList *account_guids)
|
2001-08-07 18:29:04 -05:00
|
|
|
{
|
|
|
|
SCM guids = SCM_EOL;
|
|
|
|
GList *node;
|
|
|
|
|
|
|
|
for (node = account_guids; node; node = node->next)
|
|
|
|
{
|
|
|
|
GUID *guid = node->data;
|
|
|
|
|
|
|
|
if (guid)
|
2003-02-22 02:15:53 -06:00
|
|
|
guids = scm_cons (gnc_guid2scm (*guid), guids);
|
2001-08-07 18:29:04 -05:00
|
|
|
}
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
return scm_reverse (guids);
|
2001-08-07 18:29:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static GList *
|
2002-06-05 16:59:35 -05:00
|
|
|
gnc_scm2guid_glist (SCM guids_scm)
|
2001-08-07 18:29:04 -05:00
|
|
|
{
|
|
|
|
GList *guids = NULL;
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
if (!SCM_LISTP (guids_scm))
|
2001-08-07 18:29:04 -05:00
|
|
|
return NULL;
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
while (!SCM_NULLP (guids_scm))
|
2001-08-07 18:29:04 -05:00
|
|
|
{
|
2003-02-22 02:15:53 -06:00
|
|
|
SCM guid_scm = SCM_CAR (guids_scm);
|
2001-08-07 18:29:04 -05:00
|
|
|
GUID *guid;
|
|
|
|
|
2003-06-26 02:30:48 -05:00
|
|
|
guid = guid_malloc ();
|
2001-08-07 18:29:04 -05:00
|
|
|
*guid = gnc_scm2guid (guid_scm);
|
|
|
|
|
|
|
|
guids = g_list_prepend (guids, guid);
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
guids_scm = SCM_CDR (guids_scm);
|
2001-08-07 18:29:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return g_list_reverse (guids);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-06-05 16:59:35 -05:00
|
|
|
gnc_guid_glist_free (GList *guids)
|
2001-08-07 18:29:04 -05:00
|
|
|
{
|
|
|
|
GList *node;
|
|
|
|
|
|
|
|
for (node = guids; node; node = node->next)
|
2003-06-26 02:30:48 -05:00
|
|
|
guid_free (node->data);
|
2001-08-07 18:29:04 -05:00
|
|
|
|
|
|
|
g_list_free (guids);
|
|
|
|
}
|
|
|
|
|
2001-11-05 18:49:46 -06:00
|
|
|
static SCM
|
2002-06-05 16:59:35 -05:00
|
|
|
gnc_query_numeric2scm (gnc_numeric val)
|
|
|
|
{
|
2003-02-22 02:15:53 -06:00
|
|
|
return scm_cons (gnc_gint64_to_scm (val.num),
|
2002-06-05 16:59:35 -05:00
|
|
|
gnc_gint64_to_scm (val.denom));
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gnc_query_numeric_p (SCM pair)
|
|
|
|
{
|
2003-02-22 02:15:53 -06:00
|
|
|
return (SCM_CONSP (pair));
|
2002-06-05 16:59:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static gnc_numeric
|
|
|
|
gnc_query_scm2numeric (SCM pair)
|
|
|
|
{
|
|
|
|
SCM denom;
|
|
|
|
SCM num;
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
num = SCM_CAR (pair);
|
|
|
|
denom = SCM_CDR (pair);
|
2002-06-05 16:59:35 -05:00
|
|
|
|
|
|
|
return gnc_numeric_create (gnc_scm_to_gint64 (num),
|
|
|
|
gnc_scm_to_gint64 (denom));
|
|
|
|
}
|
|
|
|
|
|
|
|
static SCM
|
|
|
|
gnc_query_path2scm (GSList *path)
|
2001-11-05 18:49:46 -06:00
|
|
|
{
|
|
|
|
SCM path_scm = SCM_EOL;
|
|
|
|
GSList *node;
|
|
|
|
|
|
|
|
for (node = path; node; node = node->next)
|
|
|
|
{
|
|
|
|
const char *key = node->data;
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
if (key)
|
|
|
|
path_scm = scm_cons (scm_makfrom0str (key), path_scm);
|
2001-11-05 18:49:46 -06:00
|
|
|
}
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
return scm_reverse (path_scm);
|
2001-11-05 18:49:46 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static GSList *
|
2002-06-05 16:59:35 -05:00
|
|
|
gnc_query_scm2path (SCM path_scm)
|
2001-11-05 18:49:46 -06:00
|
|
|
{
|
|
|
|
GSList *path = NULL;
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
if (!SCM_LISTP (path_scm))
|
2001-11-05 18:49:46 -06:00
|
|
|
return NULL;
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
while (!SCM_NULLP (path_scm))
|
2001-11-05 18:49:46 -06:00
|
|
|
{
|
2003-02-22 02:15:53 -06:00
|
|
|
SCM key_scm = SCM_CAR (path_scm);
|
2001-11-05 18:49:46 -06:00
|
|
|
char *key, *tmp;
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
if (!SCM_STRINGP (key_scm))
|
2001-11-05 18:49:46 -06:00
|
|
|
break;
|
|
|
|
|
|
|
|
tmp = gh_scm2newstr (key_scm, NULL);
|
|
|
|
key = g_strdup (tmp);
|
|
|
|
if (tmp) free (tmp);
|
|
|
|
|
|
|
|
path = g_slist_prepend (path, key);
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
path_scm = SCM_CDR (path_scm);
|
2001-11-05 18:49:46 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return g_slist_reverse (path);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-06-05 16:59:35 -05:00
|
|
|
gnc_query_path_free (GSList *path)
|
2001-11-05 18:49:46 -06:00
|
|
|
{
|
|
|
|
GSList *node;
|
|
|
|
|
|
|
|
for (node = path; node; node = node->next)
|
|
|
|
g_free (node->data);
|
|
|
|
|
|
|
|
g_slist_free (path);
|
|
|
|
}
|
|
|
|
|
|
|
|
static SCM
|
2003-06-27 18:33:00 -05:00
|
|
|
gnc_KvpValueTypeype2scm (KvpValueType how)
|
2001-11-05 18:49:46 -06:00
|
|
|
{
|
|
|
|
return gnc_gw_enum_val2scm ("<gnc:kvp-value-t>", how);
|
|
|
|
}
|
|
|
|
|
2003-06-27 18:33:00 -05:00
|
|
|
static KvpValueType
|
|
|
|
gnc_scm2KvpValueTypeype (SCM value_type_scm)
|
2001-11-05 18:49:46 -06:00
|
|
|
{
|
|
|
|
return gnc_gw_enum_scm2val ("<gnc:kvp-value-t>", value_type_scm);
|
|
|
|
}
|
|
|
|
|
2003-06-27 18:33:00 -05:00
|
|
|
static SCM gnc_kvp_frame2scm (KvpFrame *frame);
|
2001-11-05 18:49:46 -06:00
|
|
|
|
|
|
|
static SCM
|
2003-06-27 18:33:00 -05:00
|
|
|
gnc_kvp_value2scm (KvpValue *value)
|
2001-11-05 18:49:46 -06:00
|
|
|
{
|
|
|
|
SCM value_scm = SCM_EOL;
|
2003-06-27 18:33:00 -05:00
|
|
|
KvpValueType value_t;
|
2001-11-05 18:49:46 -06:00
|
|
|
SCM scm;
|
|
|
|
|
|
|
|
if (!value) return SCM_BOOL_F;
|
|
|
|
|
|
|
|
value_t = kvp_value_get_type (value);
|
|
|
|
|
2003-06-27 18:33:00 -05:00
|
|
|
value_scm = scm_cons (gnc_KvpValueTypeype2scm (value_t), value_scm);
|
2001-11-05 18:49:46 -06:00
|
|
|
|
|
|
|
switch (value_t)
|
|
|
|
{
|
|
|
|
case KVP_TYPE_GINT64:
|
|
|
|
scm = gnc_gint64_to_scm (kvp_value_get_gint64 (value));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case KVP_TYPE_DOUBLE:
|
2003-02-22 02:15:53 -06:00
|
|
|
scm = scm_make_real (kvp_value_get_double (value));
|
2001-11-05 18:49:46 -06:00
|
|
|
break;
|
|
|
|
|
|
|
|
case KVP_TYPE_STRING:
|
2003-02-22 02:15:53 -06:00
|
|
|
scm = scm_makfrom0str (kvp_value_get_string (value));
|
2001-11-05 18:49:46 -06:00
|
|
|
break;
|
|
|
|
|
|
|
|
case KVP_TYPE_GUID:
|
|
|
|
scm = gnc_guid2scm (*kvp_value_get_guid (value));
|
|
|
|
break;
|
|
|
|
|
2001-11-21 03:49:02 -06:00
|
|
|
case KVP_TYPE_TIMESPEC:
|
|
|
|
scm = gnc_timespec2timepair (kvp_value_get_timespec (value));
|
|
|
|
break;
|
|
|
|
|
2001-11-05 18:49:46 -06:00
|
|
|
case KVP_TYPE_BINARY:
|
|
|
|
scm = SCM_BOOL_F;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case KVP_TYPE_NUMERIC: {
|
|
|
|
gnc_numeric n = kvp_value_get_numeric (value);
|
2002-06-05 16:59:35 -05:00
|
|
|
scm = gnc_query_numeric2scm (n);
|
2001-11-05 18:49:46 -06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case KVP_TYPE_GLIST: {
|
|
|
|
GList *node;
|
|
|
|
|
|
|
|
scm = SCM_EOL;
|
|
|
|
for (node = kvp_value_get_glist (value); node; node = node->next)
|
2003-02-22 02:15:53 -06:00
|
|
|
scm = scm_cons (gnc_kvp_value2scm (node->data), scm);
|
|
|
|
scm = scm_reverse (scm);
|
2001-11-05 18:49:46 -06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case KVP_TYPE_FRAME:
|
|
|
|
scm = gnc_kvp_frame2scm (kvp_value_get_frame (value));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
scm = SCM_BOOL_F;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
value_scm = scm_cons (scm, value_scm);
|
2001-11-05 18:49:46 -06:00
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
return scm_reverse (value_scm);
|
2001-11-05 18:49:46 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
SCM scm;
|
|
|
|
} KVPSCMData;
|
|
|
|
|
|
|
|
static void
|
2003-06-27 18:33:00 -05:00
|
|
|
kvp_frame_slot2scm (const char *key, KvpValue *value, gpointer data)
|
2001-11-05 18:49:46 -06:00
|
|
|
{
|
|
|
|
KVPSCMData *ksd = data;
|
|
|
|
SCM value_scm;
|
|
|
|
SCM key_scm;
|
|
|
|
SCM pair;
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
key_scm = scm_makfrom0str (key);
|
2001-11-05 18:49:46 -06:00
|
|
|
value_scm = gnc_kvp_value2scm (value);
|
2003-02-22 02:15:53 -06:00
|
|
|
pair = scm_cons (key_scm, value_scm);
|
2001-11-05 18:49:46 -06:00
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
ksd->scm = scm_cons (pair, ksd->scm);
|
2001-11-05 18:49:46 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static SCM
|
2003-06-27 18:33:00 -05:00
|
|
|
gnc_kvp_frame2scm (KvpFrame *frame)
|
2001-11-05 18:49:46 -06:00
|
|
|
{
|
|
|
|
KVPSCMData ksd;
|
|
|
|
|
|
|
|
if (!frame) return SCM_BOOL_F;
|
|
|
|
|
|
|
|
ksd.scm = SCM_EOL;
|
|
|
|
|
|
|
|
kvp_frame_for_each_slot (frame, kvp_frame_slot2scm, &ksd);
|
|
|
|
|
|
|
|
return ksd.scm;
|
|
|
|
}
|
|
|
|
|
2003-06-27 18:33:00 -05:00
|
|
|
static KvpFrame * gnc_scm2KvpFrame (SCM frame_scm);
|
2001-11-05 18:49:46 -06:00
|
|
|
|
2003-06-27 18:33:00 -05:00
|
|
|
static KvpValue *
|
|
|
|
gnc_scm2KvpValue (SCM value_scm)
|
2001-11-05 18:49:46 -06:00
|
|
|
{
|
2003-06-27 18:33:00 -05:00
|
|
|
KvpValueType value_t;
|
|
|
|
KvpValue *value;
|
2001-11-05 18:49:46 -06:00
|
|
|
SCM type_scm;
|
|
|
|
SCM val_scm;
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
if (!SCM_LISTP (value_scm) || SCM_NULLP (value_scm))
|
2001-11-05 18:49:46 -06:00
|
|
|
return NULL;
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
type_scm = SCM_CAR (value_scm);
|
2003-06-27 18:33:00 -05:00
|
|
|
value_t = gnc_scm2KvpValueTypeype (type_scm);
|
2001-11-05 18:49:46 -06:00
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
value_scm = SCM_CDR (value_scm);
|
|
|
|
if (!SCM_LISTP (value_scm) || SCM_NULLP (value_scm))
|
2001-11-05 18:49:46 -06:00
|
|
|
return NULL;
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
val_scm = SCM_CAR (value_scm);
|
2001-11-05 18:49:46 -06:00
|
|
|
|
|
|
|
switch (value_t)
|
|
|
|
{
|
|
|
|
case KVP_TYPE_GINT64:
|
|
|
|
value = kvp_value_new_gint64 (gnc_scm_to_gint64 (val_scm));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case KVP_TYPE_DOUBLE:
|
2003-02-22 02:15:53 -06:00
|
|
|
value = kvp_value_new_double (scm_num2dbl (val_scm, __FUNCTION__));
|
2001-11-05 18:49:46 -06:00
|
|
|
break;
|
|
|
|
|
|
|
|
case KVP_TYPE_STRING: {
|
|
|
|
char *str = gh_scm2newstr (val_scm, NULL);
|
|
|
|
value = kvp_value_new_string (str);
|
|
|
|
if (str) free (str);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case KVP_TYPE_GUID: {
|
|
|
|
GUID guid = gnc_scm2guid (val_scm);
|
|
|
|
value = kvp_value_new_guid (&guid);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2001-11-21 03:49:02 -06:00
|
|
|
case KVP_TYPE_TIMESPEC: {
|
|
|
|
Timespec ts = gnc_timepair2timespec (val_scm);
|
|
|
|
value = kvp_value_new_timespec(ts);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2001-11-05 18:49:46 -06:00
|
|
|
case KVP_TYPE_BINARY:
|
|
|
|
return NULL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case KVP_TYPE_NUMERIC: {
|
|
|
|
gnc_numeric n;
|
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
if (!gnc_query_numeric_p (val_scm))
|
|
|
|
return NULL;
|
2001-11-05 18:49:46 -06:00
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
n = gnc_query_scm2numeric (val_scm);
|
2001-11-05 18:49:46 -06:00
|
|
|
|
|
|
|
value = kvp_value_new_gnc_numeric (n);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case KVP_TYPE_GLIST: {
|
|
|
|
GList *list = NULL;
|
|
|
|
GList *node;
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
for (; SCM_LISTP (val_scm) && !SCM_NULLP (val_scm);
|
|
|
|
val_scm = SCM_CDR (val_scm))
|
2001-11-05 18:49:46 -06:00
|
|
|
{
|
2003-02-22 02:15:53 -06:00
|
|
|
SCM scm = SCM_CAR (val_scm);
|
2001-11-05 18:49:46 -06:00
|
|
|
|
2003-06-27 18:33:00 -05:00
|
|
|
list = g_list_prepend (list, gnc_scm2KvpValue (scm));
|
2001-11-05 18:49:46 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
list = g_list_reverse (list);
|
|
|
|
|
|
|
|
value = kvp_value_new_glist (list);
|
|
|
|
|
|
|
|
for (node = list; node; node = node->next)
|
|
|
|
kvp_value_delete (node->data);
|
|
|
|
g_list_free (list);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case KVP_TYPE_FRAME: {
|
2003-06-27 18:33:00 -05:00
|
|
|
KvpFrame *frame;
|
2001-11-05 18:49:46 -06:00
|
|
|
|
2003-06-27 18:33:00 -05:00
|
|
|
frame = gnc_scm2KvpFrame (val_scm);
|
2001-11-05 18:49:46 -06:00
|
|
|
value = kvp_value_new_frame (frame);
|
|
|
|
kvp_frame_delete (frame);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
2001-12-30 11:02:56 -06:00
|
|
|
PWARN ("unexpected type: %d", value_t);
|
2001-11-05 18:49:46 -06:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2003-06-27 18:33:00 -05:00
|
|
|
static KvpFrame *
|
|
|
|
gnc_scm2KvpFrame (SCM frame_scm)
|
2001-11-05 18:49:46 -06:00
|
|
|
{
|
2003-06-27 18:33:00 -05:00
|
|
|
KvpFrame * frame;
|
2001-11-05 18:49:46 -06:00
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
if (!SCM_LISTP (frame_scm)) return NULL;
|
2001-11-05 18:49:46 -06:00
|
|
|
|
|
|
|
frame = kvp_frame_new ();
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
for (; SCM_LISTP (frame_scm) && !SCM_NULLP (frame_scm);
|
|
|
|
frame_scm = SCM_CDR (frame_scm))
|
2001-11-05 18:49:46 -06:00
|
|
|
{
|
2003-02-22 02:15:53 -06:00
|
|
|
SCM pair = SCM_CAR (frame_scm);
|
2003-06-27 18:33:00 -05:00
|
|
|
KvpValue *value;
|
2001-11-05 18:49:46 -06:00
|
|
|
SCM key_scm;
|
|
|
|
SCM val_scm;
|
|
|
|
char *key;
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
if (!SCM_CONSP (pair))
|
2001-11-05 18:49:46 -06:00
|
|
|
continue;
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
key_scm = SCM_CAR (pair);
|
|
|
|
val_scm = SCM_CDR (pair);
|
2001-11-05 18:49:46 -06:00
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
if (!SCM_STRINGP (key_scm))
|
2001-11-05 18:49:46 -06:00
|
|
|
continue;
|
|
|
|
|
|
|
|
key = gh_scm2newstr (key_scm, NULL);
|
|
|
|
if (!key)
|
|
|
|
continue;
|
|
|
|
|
2003-06-27 18:33:00 -05:00
|
|
|
value = gnc_scm2KvpValue (val_scm);
|
2001-11-05 18:49:46 -06:00
|
|
|
if (!value)
|
|
|
|
{
|
|
|
|
free (key);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
kvp_frame_set_slot_nc (frame, key, value);
|
|
|
|
|
|
|
|
free (key);
|
|
|
|
}
|
|
|
|
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
2001-08-07 18:29:04 -05:00
|
|
|
static SCM
|
2003-06-28 16:24:07 -05:00
|
|
|
gnc_queryterm2scm (QofQueryTerm *qt)
|
2001-08-07 18:29:04 -05:00
|
|
|
{
|
|
|
|
SCM qt_scm = SCM_EOL;
|
2003-06-25 00:14:10 -05:00
|
|
|
QofQueryPredData *pd = NULL;
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2003-06-25 02:38:15 -05:00
|
|
|
qt_scm = scm_cons (gnc_query_path2scm (qof_query_term_get_param_path (qt)),
|
2002-06-05 16:59:35 -05:00
|
|
|
qt_scm);
|
2003-06-25 02:38:15 -05:00
|
|
|
qt_scm = scm_cons (SCM_BOOL (qof_query_term_is_inverted (qt)), qt_scm);
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2003-06-25 02:38:15 -05:00
|
|
|
pd = qof_query_term_get_pred_data (qt);
|
2003-02-22 02:15:53 -06:00
|
|
|
qt_scm = scm_cons (scm_str2symbol (pd->type_name), qt_scm);
|
|
|
|
qt_scm = scm_cons (gnc_query_compare2scm (pd->how), qt_scm);
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2003-06-25 00:14:10 -05:00
|
|
|
if (!safe_strcmp (pd->type_name, QOF_QUERYCORE_STRING)) {
|
2002-06-05 16:59:35 -05:00
|
|
|
query_string_t pdata = (query_string_t) pd;
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
qt_scm = scm_cons (gnc_query_string2scm (pdata->options), qt_scm);
|
|
|
|
qt_scm = scm_cons (SCM_BOOL (pdata->is_regex), qt_scm);
|
|
|
|
qt_scm = scm_cons (scm_makfrom0str (pdata->matchstring), qt_scm);
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2003-06-25 00:14:10 -05:00
|
|
|
} else if (!safe_strcmp (pd->type_name, QOF_QUERYCORE_DATE)) {
|
2002-06-05 16:59:35 -05:00
|
|
|
query_date_t pdata = (query_date_t) pd;
|
2001-11-05 18:49:46 -06:00
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
qt_scm = scm_cons (gnc_query_date2scm (pdata->options), qt_scm);
|
|
|
|
qt_scm = scm_cons (gnc_timespec2timepair (pdata->date), qt_scm);
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2003-06-25 00:14:10 -05:00
|
|
|
} else if (!safe_strcmp (pd->type_name, QOF_QUERYCORE_NUMERIC)) {
|
2002-06-05 16:59:35 -05:00
|
|
|
query_numeric_t pdata = (query_numeric_t) pd;
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
qt_scm = scm_cons (gnc_query_numericop2scm (pdata->options), qt_scm);
|
|
|
|
qt_scm = scm_cons (gnc_query_numeric2scm (pdata->amount), qt_scm);
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2003-06-25 00:14:10 -05:00
|
|
|
} else if (!safe_strcmp (pd->type_name, QOF_QUERYCORE_GUID)) {
|
2002-06-05 16:59:35 -05:00
|
|
|
query_guid_t pdata = (query_guid_t) pd;
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
qt_scm = scm_cons (gnc_query_guid2scm (pdata->options), qt_scm);
|
|
|
|
qt_scm = scm_cons (gnc_guid_glist2scm (pdata->guids), qt_scm);
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2003-06-25 00:14:10 -05:00
|
|
|
} else if (!safe_strcmp (pd->type_name, QOF_QUERYCORE_INT64)) {
|
2002-06-05 16:59:35 -05:00
|
|
|
query_int64_t pdata = (query_int64_t) pd;
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
qt_scm = scm_cons (gnc_gint64_to_scm (pdata->val), qt_scm);
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2003-06-25 00:14:10 -05:00
|
|
|
} else if (!safe_strcmp (pd->type_name, QOF_QUERYCORE_DOUBLE)) {
|
2002-06-05 16:59:35 -05:00
|
|
|
query_double_t pdata = (query_double_t) pd;
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
qt_scm = scm_cons (scm_make_real (pdata->val), qt_scm);
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2003-06-25 00:14:10 -05:00
|
|
|
} else if (!safe_strcmp (pd->type_name, QOF_QUERYCORE_BOOLEAN)) {
|
2002-06-05 16:59:35 -05:00
|
|
|
query_boolean_t pdata = (query_boolean_t) pd;
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
qt_scm = scm_cons (SCM_BOOL (pdata->val), qt_scm);
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2003-06-25 00:14:10 -05:00
|
|
|
} else if (!safe_strcmp (pd->type_name, QOF_QUERYCORE_CHAR)) {
|
2002-06-05 16:59:35 -05:00
|
|
|
query_char_t pdata = (query_char_t) pd;
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
qt_scm = scm_cons (gnc_query_char2scm (pdata->options), qt_scm);
|
|
|
|
qt_scm = scm_cons (scm_makfrom0str (pdata->char_list), qt_scm);
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2003-06-25 00:14:10 -05:00
|
|
|
} else if (!safe_strcmp (pd->type_name, QOF_QUERYCORE_KVP)) {
|
2002-06-05 16:59:35 -05:00
|
|
|
query_kvp_t pdata = (query_kvp_t) pd;
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
qt_scm = scm_cons (gnc_query_path2scm (pdata->path), qt_scm);
|
|
|
|
qt_scm = scm_cons (gnc_kvp_value2scm (pdata->value), qt_scm);
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
} else {
|
|
|
|
PWARN ("query core type %s not supported", pd->type_name);
|
|
|
|
return SCM_BOOL_F;
|
|
|
|
}
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
return scm_reverse (qt_scm);
|
2002-06-05 16:59:35 -05:00
|
|
|
}
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2003-06-25 23:30:43 -05:00
|
|
|
static QofQuery *
|
2002-06-05 16:59:35 -05:00
|
|
|
gnc_scm2query_term_query_v2 (SCM qt_scm)
|
|
|
|
{
|
2003-06-25 23:30:43 -05:00
|
|
|
QofQuery *q = NULL;
|
2003-06-25 00:14:10 -05:00
|
|
|
QofQueryPredData *pd = NULL;
|
2002-06-05 16:59:35 -05:00
|
|
|
SCM scm;
|
|
|
|
char *type = NULL;
|
|
|
|
GSList *path = NULL;
|
|
|
|
gboolean inverted = FALSE;
|
2003-06-25 00:14:10 -05:00
|
|
|
QofQueryCompare compare_how;
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
if (!SCM_LISTP (qt_scm) || SCM_NULLP (qt_scm))
|
2002-06-05 16:59:35 -05:00
|
|
|
return NULL;
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
do {
|
|
|
|
/* param path */
|
2003-02-22 02:15:53 -06:00
|
|
|
scm = SCM_CAR (qt_scm);
|
|
|
|
qt_scm = SCM_CDR (qt_scm);
|
|
|
|
if (!SCM_LISTP (scm))
|
2002-06-05 16:59:35 -05:00
|
|
|
break;
|
|
|
|
path = gnc_query_scm2path (scm);
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
/* inverted */
|
2003-02-22 02:15:53 -06:00
|
|
|
scm = SCM_CAR (qt_scm);
|
|
|
|
qt_scm = SCM_CDR (qt_scm);
|
|
|
|
if (!SCM_BOOLP (scm))
|
2002-06-05 16:59:35 -05:00
|
|
|
break;
|
2003-02-22 02:15:53 -06:00
|
|
|
inverted = SCM_NFALSEP (scm);
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
/* type */
|
2003-02-22 02:15:53 -06:00
|
|
|
scm = SCM_CAR (qt_scm);
|
|
|
|
qt_scm = SCM_CDR (qt_scm);
|
|
|
|
if (!SCM_SYMBOLP (scm))
|
2002-06-05 16:59:35 -05:00
|
|
|
break;
|
|
|
|
type = gh_symbol2newstr (scm, NULL);
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2003-06-25 23:30:43 -05:00
|
|
|
/* QofCompareFunc */
|
2003-02-22 02:15:53 -06:00
|
|
|
scm = SCM_CAR (qt_scm);
|
|
|
|
qt_scm = SCM_CDR (qt_scm);
|
|
|
|
if (SCM_NULLP (scm))
|
2002-06-05 16:59:35 -05:00
|
|
|
break;
|
|
|
|
compare_how = gnc_query_scm2compare (scm);
|
|
|
|
|
|
|
|
/* Now compute the predicate */
|
|
|
|
|
2003-06-25 00:14:10 -05:00
|
|
|
if (!safe_strcmp (type, QOF_QUERYCORE_STRING)) {
|
|
|
|
QofStringMatch options;
|
2002-06-05 16:59:35 -05:00
|
|
|
gboolean is_regex;
|
|
|
|
char *matchstring;
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
scm = SCM_CAR (qt_scm);
|
|
|
|
qt_scm = SCM_CDR (qt_scm);
|
|
|
|
if (SCM_NULLP (scm))
|
2002-06-05 16:59:35 -05:00
|
|
|
break;
|
|
|
|
options = gnc_query_scm2string (scm);
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
scm = SCM_CAR (qt_scm);
|
|
|
|
qt_scm = SCM_CDR (qt_scm);
|
|
|
|
if (!SCM_BOOLP (scm))
|
2002-06-05 16:59:35 -05:00
|
|
|
break;
|
2003-02-22 02:15:53 -06:00
|
|
|
is_regex = SCM_NFALSEP (scm);
|
2002-06-05 16:59:35 -05:00
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
scm = SCM_CAR (qt_scm);
|
|
|
|
qt_scm = SCM_CDR (qt_scm);
|
|
|
|
if (!SCM_STRINGP (scm))
|
2002-06-05 16:59:35 -05:00
|
|
|
break;
|
|
|
|
matchstring = gh_scm2newstr (scm, NULL);
|
|
|
|
|
2003-06-25 00:14:10 -05:00
|
|
|
pd = qof_query_string_predicate (compare_how, matchstring,
|
2002-06-05 16:59:35 -05:00
|
|
|
options, is_regex);
|
|
|
|
free (matchstring);
|
|
|
|
|
2003-06-25 00:14:10 -05:00
|
|
|
} else if (!safe_strcmp (type, QOF_QUERYCORE_DATE)) {
|
|
|
|
QofDateMatch options;
|
2002-06-05 16:59:35 -05:00
|
|
|
Timespec date;
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
scm = SCM_CAR (qt_scm);
|
|
|
|
qt_scm = SCM_CDR (qt_scm);
|
|
|
|
if (SCM_NULLP (scm))
|
2002-06-05 16:59:35 -05:00
|
|
|
break;
|
|
|
|
options = gnc_query_scm2date (scm);
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
scm = SCM_CAR (qt_scm);
|
|
|
|
qt_scm = SCM_CDR (qt_scm);
|
|
|
|
if (SCM_NULLP (scm))
|
2002-06-05 16:59:35 -05:00
|
|
|
break;
|
|
|
|
date = gnc_timepair2timespec (scm);
|
|
|
|
|
2003-06-25 00:14:10 -05:00
|
|
|
pd = qof_query_date_predicate (compare_how, options, date);
|
2002-06-05 16:59:35 -05:00
|
|
|
|
2003-06-25 00:14:10 -05:00
|
|
|
} else if (!safe_strcmp (type, QOF_QUERYCORE_NUMERIC)) {
|
|
|
|
QofNumericMatch options;
|
2002-06-05 16:59:35 -05:00
|
|
|
gnc_numeric val;
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
scm = SCM_CAR (qt_scm);
|
|
|
|
qt_scm = SCM_CDR (qt_scm);
|
|
|
|
if (SCM_NULLP (scm))
|
2002-06-05 16:59:35 -05:00
|
|
|
break;
|
|
|
|
options = gnc_query_scm2numericop (scm);
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
scm = SCM_CAR (qt_scm);
|
|
|
|
qt_scm = SCM_CDR (qt_scm);
|
2002-06-05 16:59:35 -05:00
|
|
|
if (!gnc_query_numeric_p (scm))
|
|
|
|
break;
|
|
|
|
val = gnc_query_scm2numeric (scm);
|
|
|
|
|
2003-06-25 00:14:10 -05:00
|
|
|
pd = qof_query_numeric_predicate (compare_how, options, val);
|
2002-06-05 16:59:35 -05:00
|
|
|
|
2003-06-25 00:14:10 -05:00
|
|
|
} else if (!safe_strcmp (type, QOF_QUERYCORE_GUID)) {
|
|
|
|
QofGuidMatch options;
|
2002-06-05 16:59:35 -05:00
|
|
|
GList *guids;
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
scm = SCM_CAR (qt_scm);
|
|
|
|
qt_scm = SCM_CDR (qt_scm);
|
|
|
|
if (SCM_NULLP (scm))
|
2002-06-05 16:59:35 -05:00
|
|
|
break;
|
|
|
|
options = gnc_query_scm2guid (scm);
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
scm = SCM_CAR (qt_scm);
|
|
|
|
qt_scm = SCM_CDR (qt_scm);
|
|
|
|
if (!SCM_LISTP (scm))
|
2002-06-05 16:59:35 -05:00
|
|
|
break;
|
|
|
|
guids = gnc_scm2guid_glist (scm);
|
|
|
|
|
2003-06-25 00:14:10 -05:00
|
|
|
pd = qof_query_guid_predicate (options, guids);
|
2002-06-05 16:59:35 -05:00
|
|
|
|
|
|
|
gnc_guid_glist_free (guids);
|
|
|
|
|
2003-06-25 00:14:10 -05:00
|
|
|
} else if (!safe_strcmp (type, QOF_QUERYCORE_INT64)) {
|
2002-06-05 16:59:35 -05:00
|
|
|
gint64 val;
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
scm = SCM_CAR (qt_scm);
|
|
|
|
qt_scm = SCM_CDR (qt_scm);
|
|
|
|
if (SCM_NULLP (scm))
|
2002-06-05 16:59:35 -05:00
|
|
|
break;
|
|
|
|
val = gnc_scm_to_gint64 (scm);
|
|
|
|
|
2003-06-25 00:14:10 -05:00
|
|
|
pd = qof_query_int64_predicate (compare_how, val);
|
2002-06-05 16:59:35 -05:00
|
|
|
|
2003-06-25 00:14:10 -05:00
|
|
|
} else if (!safe_strcmp (type, QOF_QUERYCORE_DOUBLE)) {
|
2002-06-05 16:59:35 -05:00
|
|
|
double val;
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
scm = SCM_CAR (qt_scm);
|
|
|
|
qt_scm = SCM_CDR (qt_scm);
|
|
|
|
if (!SCM_NUMBERP (scm))
|
2002-06-05 16:59:35 -05:00
|
|
|
break;
|
2003-02-22 02:15:53 -06:00
|
|
|
val = scm_num2dbl (scm, __FUNCTION__);
|
2002-06-05 16:59:35 -05:00
|
|
|
|
2003-06-25 00:14:10 -05:00
|
|
|
pd = qof_query_double_predicate (compare_how, val);
|
2002-06-05 16:59:35 -05:00
|
|
|
|
2003-06-25 00:14:10 -05:00
|
|
|
} else if (!safe_strcmp (type, QOF_QUERYCORE_BOOLEAN)) {
|
2002-06-05 16:59:35 -05:00
|
|
|
gboolean val;
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
scm = SCM_CAR (qt_scm);
|
|
|
|
qt_scm = SCM_CDR (qt_scm);
|
|
|
|
if (!SCM_BOOLP (scm))
|
2002-06-05 16:59:35 -05:00
|
|
|
break;
|
2003-02-22 02:15:53 -06:00
|
|
|
val = SCM_NFALSEP (scm);
|
2002-06-05 16:59:35 -05:00
|
|
|
|
2003-06-25 00:14:10 -05:00
|
|
|
pd = qof_query_boolean_predicate (compare_how, val);
|
2002-06-05 16:59:35 -05:00
|
|
|
|
2003-06-25 00:14:10 -05:00
|
|
|
} else if (!safe_strcmp (type, QOF_QUERYCORE_CHAR)) {
|
|
|
|
QofCharMatch options;
|
2002-06-05 16:59:35 -05:00
|
|
|
char *char_list;
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
scm = SCM_CAR (qt_scm);
|
|
|
|
qt_scm = SCM_CDR (qt_scm);
|
|
|
|
if (SCM_NULLP (scm))
|
2002-06-05 16:59:35 -05:00
|
|
|
break;
|
|
|
|
options = gnc_query_scm2char (scm);
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
scm = SCM_CAR (qt_scm);
|
|
|
|
qt_scm = SCM_CDR (qt_scm);
|
|
|
|
if (!SCM_STRINGP (scm))
|
2002-06-05 16:59:35 -05:00
|
|
|
break;
|
|
|
|
char_list = gh_scm2newstr (scm, NULL);
|
|
|
|
|
2003-06-25 00:14:10 -05:00
|
|
|
pd = qof_query_char_predicate (options, char_list);
|
2002-06-05 16:59:35 -05:00
|
|
|
free (char_list);
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2003-06-25 00:14:10 -05:00
|
|
|
} else if (!safe_strcmp (type, QOF_QUERYCORE_KVP)) {
|
2002-06-05 16:59:35 -05:00
|
|
|
GSList *kvp_path;
|
2003-06-27 18:33:00 -05:00
|
|
|
KvpValue *value;
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
scm = SCM_CAR (qt_scm);
|
|
|
|
qt_scm = SCM_CDR (qt_scm);
|
|
|
|
if (!SCM_LISTP (scm))
|
2002-06-05 16:59:35 -05:00
|
|
|
break;
|
|
|
|
kvp_path = gnc_query_scm2path (scm);
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
scm = SCM_CAR (qt_scm);
|
|
|
|
qt_scm = SCM_CDR (qt_scm);
|
|
|
|
if (SCM_NULLP (scm)) {
|
2002-06-05 16:59:35 -05:00
|
|
|
gnc_query_path_free (kvp_path);
|
|
|
|
break;
|
2001-08-07 18:29:04 -05:00
|
|
|
}
|
2003-06-27 18:33:00 -05:00
|
|
|
value = gnc_scm2KvpValue (scm);
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2003-06-25 00:14:10 -05:00
|
|
|
pd = qof_query_kvp_predicate (compare_how, kvp_path, value);
|
2002-06-05 16:59:35 -05:00
|
|
|
gnc_query_path_free (kvp_path);
|
|
|
|
kvp_value_delete (value);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
PWARN ("query core type %s not supported", type);
|
2001-08-07 18:29:04 -05:00
|
|
|
break;
|
2002-06-05 16:59:35 -05:00
|
|
|
}
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
} while (FALSE);
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
if (pd) {
|
2003-06-25 02:38:15 -05:00
|
|
|
q = qof_query_create ();
|
|
|
|
qof_query_add_term (q, path, pd, QOF_QUERY_OR);
|
2002-06-05 16:59:35 -05:00
|
|
|
if (inverted) {
|
2003-06-25 02:38:15 -05:00
|
|
|
Query *outq = qof_query_invert (q);
|
|
|
|
qof_query_destroy (q);
|
2002-06-05 16:59:35 -05:00
|
|
|
q = outq;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
gnc_query_path_free (path);
|
|
|
|
}
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
if (type)
|
|
|
|
free (type);
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
return q;
|
|
|
|
}
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2003-06-25 23:30:43 -05:00
|
|
|
static QofQuery *
|
2002-06-05 16:59:35 -05:00
|
|
|
gnc_scm2query_term_query_v1 (SCM query_term_scm)
|
|
|
|
{
|
|
|
|
gboolean ok = FALSE;
|
|
|
|
char * pd_type = NULL;
|
|
|
|
char * pr_type = NULL;
|
|
|
|
gboolean sense = FALSE;
|
2003-06-25 23:30:43 -05:00
|
|
|
QofQuery *q = NULL;
|
2002-06-05 16:59:35 -05:00
|
|
|
SCM scm;
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
if (!SCM_LISTP (query_term_scm) ||
|
|
|
|
SCM_NULLP (query_term_scm)) {
|
2002-06-05 16:59:35 -05:00
|
|
|
PINFO ("null term");
|
|
|
|
return NULL;
|
|
|
|
}
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
do {
|
|
|
|
/* pd_type */
|
2003-02-22 02:15:53 -06:00
|
|
|
scm = SCM_CAR (query_term_scm);
|
|
|
|
query_term_scm = SCM_CDR (query_term_scm);
|
2002-06-05 16:59:35 -05:00
|
|
|
pd_type = gh_symbol2newstr (scm, NULL);
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
/* pr_type */
|
2003-02-22 02:15:53 -06:00
|
|
|
if (SCM_NULLP (query_term_scm)) {
|
2002-06-05 16:59:35 -05:00
|
|
|
PINFO ("null pr_type");
|
2001-08-07 18:29:04 -05:00
|
|
|
break;
|
2002-06-05 16:59:35 -05:00
|
|
|
}
|
2003-02-22 02:15:53 -06:00
|
|
|
scm = SCM_CAR (query_term_scm);
|
|
|
|
query_term_scm = SCM_CDR (query_term_scm);
|
2002-06-05 16:59:35 -05:00
|
|
|
pr_type = gh_symbol2newstr (scm, NULL);
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
/* sense */
|
2003-02-22 02:15:53 -06:00
|
|
|
if (SCM_NULLP (query_term_scm)) {
|
2002-06-05 16:59:35 -05:00
|
|
|
PINFO ("null sense");
|
|
|
|
break;
|
|
|
|
}
|
2003-02-22 02:15:53 -06:00
|
|
|
scm = SCM_CAR (query_term_scm);
|
|
|
|
query_term_scm = SCM_CDR (query_term_scm);
|
|
|
|
sense = SCM_NFALSEP (scm);
|
2002-06-05 16:59:35 -05:00
|
|
|
|
|
|
|
q = xaccMallocQuery ();
|
|
|
|
|
|
|
|
if (!safe_strcmp (pd_type, "pd-date")) {
|
|
|
|
gboolean use_start;
|
|
|
|
gboolean use_end;
|
|
|
|
Timespec start;
|
|
|
|
Timespec end;
|
|
|
|
|
|
|
|
/* use_start */
|
2003-02-22 02:15:53 -06:00
|
|
|
if (SCM_NULLP (query_term_scm)) {
|
2002-06-05 16:59:35 -05:00
|
|
|
PINFO ("null use_start");
|
|
|
|
break;
|
|
|
|
}
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
scm = SCM_CAR (query_term_scm);
|
|
|
|
query_term_scm = SCM_CDR (query_term_scm);
|
|
|
|
use_start = SCM_NFALSEP (scm);
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
/* start */
|
2003-02-22 02:15:53 -06:00
|
|
|
if (SCM_NULLP (query_term_scm))
|
2002-06-05 16:59:35 -05:00
|
|
|
break;
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
scm = SCM_CAR (query_term_scm);
|
|
|
|
query_term_scm = SCM_CDR (query_term_scm);
|
2002-06-05 16:59:35 -05:00
|
|
|
start = gnc_timepair2timespec (scm);
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
/* use_end */
|
2003-02-22 02:15:53 -06:00
|
|
|
if (SCM_NULLP (query_term_scm))
|
2002-06-05 16:59:35 -05:00
|
|
|
break;
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
scm = SCM_CAR (query_term_scm);
|
|
|
|
query_term_scm = SCM_CDR (query_term_scm);
|
|
|
|
use_end = SCM_NFALSEP (scm);
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
/* end */
|
2003-02-22 02:15:53 -06:00
|
|
|
if (SCM_NULLP (query_term_scm))
|
2002-06-05 16:59:35 -05:00
|
|
|
break;
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
scm = SCM_CAR (query_term_scm);
|
|
|
|
query_term_scm = SCM_CDR (query_term_scm);
|
2002-06-05 16:59:35 -05:00
|
|
|
end = gnc_timepair2timespec (scm);
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2003-06-25 02:38:15 -05:00
|
|
|
xaccQueryAddDateMatchTS (q, use_start, start, use_end, end, QOF_QUERY_OR);
|
2001-08-07 18:29:04 -05:00
|
|
|
|
|
|
|
ok = TRUE;
|
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
} else if (!safe_strcmp (pd_type, "pd-amount")) {
|
2003-06-25 00:14:10 -05:00
|
|
|
QofQueryCompare how;
|
|
|
|
QofNumericMatch amt_sgn;
|
2002-06-05 16:59:35 -05:00
|
|
|
double amount;
|
|
|
|
gnc_numeric val;
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
/* how */
|
2003-02-22 02:15:53 -06:00
|
|
|
if (SCM_NULLP (query_term_scm))
|
2002-06-05 16:59:35 -05:00
|
|
|
break;
|
2003-02-22 02:15:53 -06:00
|
|
|
scm = SCM_CAR (query_term_scm);
|
|
|
|
query_term_scm = SCM_CDR (query_term_scm);
|
2002-06-05 16:59:35 -05:00
|
|
|
how = gnc_scm2amt_match_how (scm);
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
/* amt_sgn */
|
2003-02-22 02:15:53 -06:00
|
|
|
if (SCM_NULLP (query_term_scm))
|
2002-06-05 16:59:35 -05:00
|
|
|
break;
|
2003-02-22 02:15:53 -06:00
|
|
|
scm = SCM_CAR (query_term_scm);
|
|
|
|
query_term_scm = SCM_CDR (query_term_scm);
|
2002-06-05 16:59:35 -05:00
|
|
|
amt_sgn = gnc_query_scm2numericop (scm);
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
/* amount */
|
2003-02-22 02:15:53 -06:00
|
|
|
if (SCM_NULLP (query_term_scm))
|
2002-06-05 16:59:35 -05:00
|
|
|
break;
|
2003-02-22 02:15:53 -06:00
|
|
|
scm = SCM_CAR (query_term_scm);
|
|
|
|
query_term_scm = SCM_CDR (query_term_scm);
|
|
|
|
amount = scm_num2dbl (scm, __FUNCTION__);
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
val = double_to_gnc_numeric (amount, GNC_DENOM_AUTO, GNC_RND_ROUND);
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
if (!safe_strcmp (pr_type, "pr-price")) {
|
2003-06-25 02:38:15 -05:00
|
|
|
xaccQueryAddSharePriceMatch (q, val, how, QOF_QUERY_OR);
|
2002-06-05 16:59:35 -05:00
|
|
|
ok = TRUE;
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
} else if (!safe_strcmp (pr_type, "pr-shares")) {
|
2003-06-25 02:38:15 -05:00
|
|
|
xaccQueryAddSharesMatch (q, val, how, QOF_QUERY_OR);
|
2002-06-05 16:59:35 -05:00
|
|
|
ok = TRUE;
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
} else if (!safe_strcmp (pr_type, "pr-value")) {
|
2003-06-25 02:38:15 -05:00
|
|
|
xaccQueryAddValueMatch (q, val, amt_sgn, how, QOF_QUERY_OR);
|
2002-06-05 16:59:35 -05:00
|
|
|
ok = TRUE;
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
} else {
|
|
|
|
PINFO ("unknown amount predicate: %s", pr_type);
|
|
|
|
}
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
} else if (!safe_strcmp (pd_type, "pd-account")) {
|
2003-06-25 00:14:10 -05:00
|
|
|
QofGuidMatch how;
|
2002-06-05 16:59:35 -05:00
|
|
|
GList *account_guids;
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
/* how */
|
2003-02-22 02:15:53 -06:00
|
|
|
if (SCM_NULLP (query_term_scm)) {
|
2002-06-05 16:59:35 -05:00
|
|
|
PINFO ("pd-account: null how");
|
|
|
|
break;
|
2001-08-07 18:29:04 -05:00
|
|
|
}
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
scm = SCM_CAR (query_term_scm);
|
|
|
|
query_term_scm = SCM_CDR (query_term_scm);
|
2002-06-05 16:59:35 -05:00
|
|
|
how = gnc_scm2acct_match_how (scm);
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
/* account guids */
|
2003-02-22 02:15:53 -06:00
|
|
|
if (SCM_NULLP (query_term_scm)) {
|
2002-06-05 16:59:35 -05:00
|
|
|
PINFO ("pd-account: null guids");
|
|
|
|
break;
|
|
|
|
}
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
scm = SCM_CAR (query_term_scm);
|
|
|
|
query_term_scm = SCM_CDR (query_term_scm);
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
account_guids = gnc_scm2guid_glist (scm);
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2003-06-25 02:38:15 -05:00
|
|
|
xaccQueryAddAccountGUIDMatch (q, account_guids, how, QOF_QUERY_OR);
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
gnc_guid_glist_free (account_guids);
|
2001-08-07 18:29:04 -05:00
|
|
|
|
|
|
|
ok = TRUE;
|
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
} else if (!safe_strcmp (pd_type, "pd-string")) {
|
|
|
|
gboolean case_sens;
|
|
|
|
gboolean use_regexp;
|
|
|
|
char *matchstring;
|
|
|
|
|
|
|
|
/* case_sens */
|
2003-02-22 02:15:53 -06:00
|
|
|
if (SCM_NULLP (query_term_scm))
|
2002-06-05 16:59:35 -05:00
|
|
|
break;
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
scm = SCM_CAR (query_term_scm);
|
|
|
|
query_term_scm = SCM_CDR (query_term_scm);
|
|
|
|
case_sens = SCM_NFALSEP (scm);
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
/* use_regexp */
|
2003-02-22 02:15:53 -06:00
|
|
|
if (SCM_NULLP (query_term_scm))
|
2002-06-05 16:59:35 -05:00
|
|
|
break;
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
scm = SCM_CAR (query_term_scm);
|
|
|
|
query_term_scm = SCM_CDR (query_term_scm);
|
|
|
|
use_regexp = SCM_NFALSEP (scm);
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
/* matchstring */
|
2003-02-22 02:15:53 -06:00
|
|
|
if (SCM_NULLP (query_term_scm))
|
2002-06-05 16:59:35 -05:00
|
|
|
break;
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
scm = SCM_CAR (query_term_scm);
|
|
|
|
query_term_scm = SCM_CDR (query_term_scm);
|
2002-06-05 16:59:35 -05:00
|
|
|
matchstring = gh_scm2newstr (scm, NULL);
|
|
|
|
|
|
|
|
if (!safe_strcmp (pr_type, "pr-action")) {
|
|
|
|
xaccQueryAddActionMatch (q, matchstring, case_sens, use_regexp,
|
2003-06-25 02:38:15 -05:00
|
|
|
QOF_QUERY_OR);
|
2002-06-05 16:59:35 -05:00
|
|
|
ok = TRUE;
|
|
|
|
|
|
|
|
} else if (!safe_strcmp (pr_type, "pr-desc")) {
|
|
|
|
xaccQueryAddDescriptionMatch (q, matchstring, case_sens,
|
2003-06-25 02:38:15 -05:00
|
|
|
use_regexp, QOF_QUERY_OR);
|
2002-06-05 16:59:35 -05:00
|
|
|
ok = TRUE;
|
|
|
|
|
|
|
|
} else if (!safe_strcmp (pr_type, "pr-memo")) {
|
|
|
|
xaccQueryAddMemoMatch (q, matchstring, case_sens, use_regexp,
|
2003-06-25 02:38:15 -05:00
|
|
|
QOF_QUERY_OR);
|
2002-06-05 16:59:35 -05:00
|
|
|
ok = TRUE;
|
|
|
|
|
|
|
|
} else if (!safe_strcmp (pr_type, "pr-num")) {
|
|
|
|
xaccQueryAddNumberMatch (q, matchstring, case_sens, use_regexp,
|
2003-06-25 02:38:15 -05:00
|
|
|
QOF_QUERY_OR);
|
2002-06-05 16:59:35 -05:00
|
|
|
ok = TRUE;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
PINFO ("Unknown string predicate: %s", pr_type);
|
2001-08-07 18:29:04 -05:00
|
|
|
}
|
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
} else if (!safe_strcmp (pd_type, "pd-cleared")) {
|
|
|
|
cleared_match_t how;
|
|
|
|
|
|
|
|
/* how */
|
2003-02-22 02:15:53 -06:00
|
|
|
if (SCM_NULLP (query_term_scm))
|
2002-06-05 16:59:35 -05:00
|
|
|
break;
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
scm = SCM_CAR (query_term_scm);
|
|
|
|
query_term_scm = SCM_CDR (query_term_scm);
|
2002-06-05 16:59:35 -05:00
|
|
|
how = gnc_scm2cleared_match_how (scm);
|
|
|
|
|
2003-06-25 02:38:15 -05:00
|
|
|
xaccQueryAddClearedMatch (q, how, QOF_QUERY_OR);
|
2001-08-07 18:29:04 -05:00
|
|
|
ok = TRUE;
|
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
} else if (!safe_strcmp (pd_type, "pd-balance")) {
|
|
|
|
gboolean how;
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
/* how */
|
2003-02-22 02:15:53 -06:00
|
|
|
if (SCM_NULLP (query_term_scm))
|
2002-06-05 16:59:35 -05:00
|
|
|
break;
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
scm = SCM_CAR (query_term_scm);
|
|
|
|
query_term_scm = SCM_CDR (query_term_scm);
|
2002-06-05 16:59:35 -05:00
|
|
|
if (gnc_scm2balance_match_how (scm, &how) == FALSE)
|
|
|
|
break;
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2003-06-25 02:38:15 -05:00
|
|
|
xaccQueryAddBalanceMatch (q, how, QOF_QUERY_OR);
|
2002-06-05 16:59:35 -05:00
|
|
|
ok = TRUE;
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
} else if (!safe_strcmp (pd_type, "pd-guid")) {
|
|
|
|
GUID guid;
|
2003-06-26 02:30:48 -05:00
|
|
|
QofIdType id_type;
|
2002-06-05 16:59:35 -05:00
|
|
|
char *tmp;
|
2001-11-14 03:07:49 -06:00
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
/* guid */
|
2003-02-22 02:15:53 -06:00
|
|
|
if (SCM_NULLP (query_term_scm))
|
2002-06-05 16:59:35 -05:00
|
|
|
break;
|
2001-11-14 03:07:49 -06:00
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
scm = SCM_CAR (query_term_scm);
|
|
|
|
query_term_scm = SCM_CDR (query_term_scm);
|
2002-06-05 16:59:35 -05:00
|
|
|
guid = gnc_scm2guid (scm);
|
2001-11-14 03:07:49 -06:00
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
/* id type */
|
2003-02-22 02:15:53 -06:00
|
|
|
scm = SCM_CAR (query_term_scm);
|
|
|
|
query_term_scm = SCM_CDR (query_term_scm);
|
2002-06-05 16:59:35 -05:00
|
|
|
tmp = gh_scm2newstr (scm, NULL);
|
|
|
|
id_type = g_strdup (tmp);
|
|
|
|
if (tmp) free (tmp);
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2003-06-25 02:38:15 -05:00
|
|
|
xaccQueryAddGUIDMatch (q, &guid, id_type, QOF_QUERY_OR);
|
2001-08-07 18:29:04 -05:00
|
|
|
ok = TRUE;
|
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
} else if (!safe_strcmp (pd_type, "pd-kvp")) {
|
2001-11-05 18:49:46 -06:00
|
|
|
GSList *path;
|
2003-06-27 18:33:00 -05:00
|
|
|
KvpValue *value;
|
2003-06-25 00:14:10 -05:00
|
|
|
QofQueryCompare how;
|
2003-06-26 02:30:48 -05:00
|
|
|
QofIdType where;
|
2001-11-05 18:49:46 -06:00
|
|
|
|
|
|
|
/* how */
|
2003-02-22 02:15:53 -06:00
|
|
|
if (SCM_NULLP (query_term_scm))
|
2001-11-05 18:49:46 -06:00
|
|
|
break;
|
2003-02-22 02:15:53 -06:00
|
|
|
scm = SCM_CAR (query_term_scm);
|
|
|
|
query_term_scm = SCM_CDR (query_term_scm);
|
2001-11-05 18:49:46 -06:00
|
|
|
how = gnc_scm2kvp_match_how (scm);
|
|
|
|
|
|
|
|
/* where */
|
2003-02-22 02:15:53 -06:00
|
|
|
if (SCM_NULLP (query_term_scm))
|
2001-11-05 18:49:46 -06:00
|
|
|
break;
|
2003-02-22 02:15:53 -06:00
|
|
|
scm = SCM_CAR (query_term_scm);
|
|
|
|
query_term_scm = SCM_CDR (query_term_scm);
|
2001-11-05 18:49:46 -06:00
|
|
|
where = gnc_scm2kvp_match_where (scm);
|
|
|
|
|
|
|
|
/* path */
|
2003-02-22 02:15:53 -06:00
|
|
|
if (SCM_NULLP (query_term_scm))
|
2001-11-05 18:49:46 -06:00
|
|
|
break;
|
2003-02-22 02:15:53 -06:00
|
|
|
scm = SCM_CAR (query_term_scm);
|
|
|
|
query_term_scm = SCM_CDR (query_term_scm);
|
2002-06-05 16:59:35 -05:00
|
|
|
path = gnc_query_scm2path (scm);
|
2001-11-05 18:49:46 -06:00
|
|
|
|
|
|
|
/* value */
|
2003-02-22 02:15:53 -06:00
|
|
|
if (SCM_NULLP (query_term_scm))
|
2001-11-05 18:49:46 -06:00
|
|
|
break;
|
2003-02-22 02:15:53 -06:00
|
|
|
scm = SCM_CAR (query_term_scm);
|
|
|
|
query_term_scm = SCM_CDR (query_term_scm);
|
2003-06-27 18:33:00 -05:00
|
|
|
value = gnc_scm2KvpValue (scm);
|
2001-11-05 18:49:46 -06:00
|
|
|
|
2003-06-25 02:38:15 -05:00
|
|
|
xaccQueryAddKVPMatch (q, path, value, how, where, QOF_QUERY_OR);
|
2001-11-05 18:49:46 -06:00
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
gnc_query_path_free (path);
|
2001-11-05 18:49:46 -06:00
|
|
|
kvp_value_delete (value);
|
2002-06-05 16:59:35 -05:00
|
|
|
ok = TRUE;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
PINFO ("Unknown Predicate: %s", pd_type);
|
2001-11-05 18:49:46 -06:00
|
|
|
}
|
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
} while (FALSE);
|
2001-11-05 18:49:46 -06:00
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
if (pd_type)
|
|
|
|
free (pd_type);
|
|
|
|
|
|
|
|
if (pr_type)
|
|
|
|
free (pr_type);
|
2001-08-07 18:29:04 -05:00
|
|
|
|
|
|
|
if (ok)
|
|
|
|
{
|
|
|
|
Query *out_q;
|
|
|
|
|
|
|
|
if (sense)
|
|
|
|
out_q = q;
|
2002-06-05 16:59:35 -05:00
|
|
|
else {
|
2001-08-07 18:29:04 -05:00
|
|
|
out_q = xaccQueryInvert (q);
|
|
|
|
xaccFreeQuery (q);
|
|
|
|
}
|
|
|
|
|
|
|
|
return out_q;
|
|
|
|
}
|
|
|
|
|
|
|
|
xaccFreeQuery (q);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
static Query *
|
|
|
|
gnc_scm2query_term_query (SCM query_term_scm, query_version_t vers)
|
|
|
|
{
|
|
|
|
switch (vers) {
|
|
|
|
case gnc_QUERY_v1:
|
|
|
|
return gnc_scm2query_term_query_v1 (query_term_scm);
|
|
|
|
case gnc_QUERY_v2:
|
|
|
|
return gnc_scm2query_term_query_v2 (query_term_scm);
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-08-07 18:29:04 -05:00
|
|
|
static SCM
|
|
|
|
gnc_query_terms2scm (GList *terms)
|
|
|
|
{
|
|
|
|
SCM or_terms = SCM_EOL;
|
|
|
|
GList *or_node;
|
|
|
|
|
|
|
|
for (or_node = terms; or_node; or_node = or_node->next)
|
|
|
|
{
|
|
|
|
SCM and_terms = SCM_EOL;
|
|
|
|
GList *and_node;
|
|
|
|
|
|
|
|
for (and_node = or_node->data; and_node; and_node = and_node->next)
|
|
|
|
{
|
2003-06-28 16:24:07 -05:00
|
|
|
QofQueryTerm *qt = and_node->data;
|
2001-08-07 18:29:04 -05:00
|
|
|
SCM qt_scm;
|
|
|
|
|
|
|
|
qt_scm = gnc_queryterm2scm (qt);
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
and_terms = scm_cons (qt_scm, and_terms);
|
2001-08-07 18:29:04 -05:00
|
|
|
}
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
and_terms = scm_reverse (and_terms);
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
or_terms = scm_cons (and_terms, or_terms);
|
2001-08-07 18:29:04 -05:00
|
|
|
}
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
return scm_reverse (or_terms);
|
2001-08-07 18:29:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static Query *
|
2002-06-05 16:59:35 -05:00
|
|
|
gnc_scm2query_and_terms (SCM and_terms, query_version_t vers)
|
2001-08-07 18:29:04 -05:00
|
|
|
{
|
|
|
|
Query *q = NULL;
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
if (!SCM_LISTP (and_terms))
|
2001-08-07 18:29:04 -05:00
|
|
|
return NULL;
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
while (!SCM_NULLP (and_terms))
|
2001-08-07 18:29:04 -05:00
|
|
|
{
|
|
|
|
SCM term;
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
term = SCM_CAR (and_terms);
|
|
|
|
and_terms = SCM_CDR (and_terms);
|
2001-08-07 18:29:04 -05:00
|
|
|
|
|
|
|
if (!q)
|
2002-06-05 16:59:35 -05:00
|
|
|
q = gnc_scm2query_term_query (term, vers);
|
2001-08-07 18:29:04 -05:00
|
|
|
else
|
|
|
|
{
|
|
|
|
Query *q_and;
|
|
|
|
Query *q_new;
|
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
q_and = gnc_scm2query_term_query (term, vers);
|
2001-08-07 18:29:04 -05:00
|
|
|
|
|
|
|
if (q_and)
|
|
|
|
{
|
2003-06-25 02:38:15 -05:00
|
|
|
q_new = xaccQueryMerge (q, q_and, QOF_QUERY_AND);
|
2001-08-07 18:29:04 -05:00
|
|
|
|
|
|
|
if (q_new)
|
|
|
|
{
|
|
|
|
xaccFreeQuery (q);
|
|
|
|
q = q_new;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return q;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Query *
|
2002-06-05 16:59:35 -05:00
|
|
|
gnc_scm2query_or_terms (SCM or_terms, query_version_t vers)
|
2001-08-07 18:29:04 -05:00
|
|
|
{
|
|
|
|
Query *q = NULL;
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
if (!SCM_LISTP (or_terms))
|
2001-08-07 18:29:04 -05:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
q = xaccMallocQuery ();
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
while (!SCM_NULLP (or_terms))
|
2001-08-07 18:29:04 -05:00
|
|
|
{
|
|
|
|
SCM and_terms;
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
and_terms = SCM_CAR (or_terms);
|
|
|
|
or_terms = SCM_CDR (or_terms);
|
2001-08-07 18:29:04 -05:00
|
|
|
|
|
|
|
if (!q)
|
2002-06-05 16:59:35 -05:00
|
|
|
q = gnc_scm2query_and_terms (and_terms, vers);
|
2001-08-07 18:29:04 -05:00
|
|
|
else
|
|
|
|
{
|
|
|
|
Query *q_or;
|
|
|
|
Query *q_new;
|
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
q_or = gnc_scm2query_and_terms (and_terms, vers);
|
2001-08-07 18:29:04 -05:00
|
|
|
|
|
|
|
if (q_or)
|
|
|
|
{
|
2003-06-25 02:38:15 -05:00
|
|
|
q_new = xaccQueryMerge (q, q_or, QOF_QUERY_OR);
|
2001-08-07 18:29:04 -05:00
|
|
|
|
|
|
|
if (q_new)
|
|
|
|
{
|
|
|
|
xaccFreeQuery (q);
|
|
|
|
q = q_new;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return q;
|
|
|
|
}
|
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
static SCM
|
2003-06-28 16:24:07 -05:00
|
|
|
gnc_query_sort2scm (QofQuerySort *qs)
|
2002-06-05 16:59:35 -05:00
|
|
|
{
|
|
|
|
SCM sort_scm = SCM_EOL;
|
|
|
|
GSList *path;
|
|
|
|
|
2003-06-25 02:38:15 -05:00
|
|
|
path = qof_query_sort_get_param_path (qs);
|
2002-06-05 16:59:35 -05:00
|
|
|
if (path == NULL)
|
|
|
|
return SCM_BOOL_F;
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
sort_scm = scm_cons (gnc_query_path2scm (path), sort_scm);
|
2003-06-25 02:38:15 -05:00
|
|
|
sort_scm = scm_cons (scm_int2num (qof_query_sort_get_sort_options (qs)), sort_scm);
|
|
|
|
sort_scm = scm_cons (SCM_BOOL (qof_query_sort_get_increasing (qs)), sort_scm);
|
2002-06-05 16:59:35 -05:00
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
return scm_reverse (sort_scm);
|
2002-06-05 16:59:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gnc_query_scm2sort (SCM sort_scm, GSList **path, gint *options, gboolean *inc)
|
|
|
|
{
|
|
|
|
SCM val;
|
|
|
|
GSList *p;
|
|
|
|
gint o;
|
|
|
|
gboolean i;
|
|
|
|
|
|
|
|
g_return_val_if_fail (path && options && inc, FALSE);
|
|
|
|
g_return_val_if_fail (*path == NULL, FALSE);
|
|
|
|
|
|
|
|
/* This is ok -- it means we have an empty sort. Don't do anything */
|
2003-02-22 02:15:53 -06:00
|
|
|
if (SCM_BOOLP (sort_scm))
|
2002-06-05 16:59:35 -05:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* Ok, this had better be a list */
|
2003-02-22 02:15:53 -06:00
|
|
|
if (!SCM_LISTP (sort_scm))
|
2002-06-05 16:59:35 -05:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* Parse the path, options, and increasing */
|
2003-02-22 02:15:53 -06:00
|
|
|
val = SCM_CAR (sort_scm);
|
|
|
|
sort_scm = SCM_CDR (sort_scm);
|
|
|
|
if (!SCM_LISTP (val))
|
2002-06-05 16:59:35 -05:00
|
|
|
return FALSE;
|
|
|
|
p = gnc_query_scm2path (val);
|
|
|
|
|
|
|
|
/* options */
|
2003-02-22 02:15:53 -06:00
|
|
|
val = SCM_CAR (sort_scm);
|
|
|
|
sort_scm = SCM_CDR (sort_scm);
|
|
|
|
if (!SCM_NUMBERP (val)) {
|
2002-06-05 16:59:35 -05:00
|
|
|
gnc_query_path_free (p);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2003-02-22 02:15:53 -06:00
|
|
|
o = scm_num2int (val, SCM_ARG1, __FUNCTION__);
|
2002-06-05 16:59:35 -05:00
|
|
|
|
|
|
|
/* increasing */
|
2003-02-22 02:15:53 -06:00
|
|
|
val = SCM_CAR (sort_scm);
|
|
|
|
sort_scm = SCM_CDR (sort_scm);
|
|
|
|
if (!SCM_BOOLP (val)) {
|
2002-06-05 16:59:35 -05:00
|
|
|
gnc_query_path_free (p);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2003-02-22 02:15:53 -06:00
|
|
|
i = SCM_NFALSEP (val);
|
2002-06-05 16:59:35 -05:00
|
|
|
|
|
|
|
/* EOL */
|
2003-02-22 02:15:53 -06:00
|
|
|
if (!SCM_NULLP (sort_scm)) {
|
2002-06-05 16:59:35 -05:00
|
|
|
gnc_query_path_free (p);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
*path = p;
|
|
|
|
*options = o;
|
|
|
|
*inc = i;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2001-08-07 18:29:04 -05:00
|
|
|
SCM
|
2003-06-28 16:24:07 -05:00
|
|
|
gnc_query2scm (QofQuery *q)
|
2001-08-07 18:29:04 -05:00
|
|
|
{
|
|
|
|
SCM query_scm = SCM_EOL;
|
|
|
|
SCM pair;
|
2003-06-28 16:24:07 -05:00
|
|
|
QofQuerySort *s1, *s2, *s3;
|
2001-08-07 18:29:04 -05:00
|
|
|
|
|
|
|
if (!q) return SCM_BOOL_F;
|
|
|
|
|
2003-09-09 19:01:54 -05:00
|
|
|
++scm_block_gc;
|
|
|
|
|
2001-08-07 18:29:04 -05:00
|
|
|
/* terms */
|
2003-06-25 02:38:15 -05:00
|
|
|
pair = scm_cons (gnc_query_terms2scm (qof_query_get_terms (q)), SCM_EOL);
|
2003-02-22 02:15:53 -06:00
|
|
|
pair = scm_cons (scm_str2symbol ("terms"), pair);
|
|
|
|
query_scm = scm_cons (pair, query_scm);
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
/* search-for */
|
2003-06-25 02:38:15 -05:00
|
|
|
pair = scm_cons (scm_str2symbol (qof_query_get_search_for (q)), SCM_EOL);
|
2003-02-22 02:15:53 -06:00
|
|
|
pair = scm_cons (scm_str2symbol ("search-for"), pair);
|
|
|
|
query_scm = scm_cons (pair, query_scm);
|
2002-06-05 16:59:35 -05:00
|
|
|
|
|
|
|
/* sorts... */
|
2003-06-25 02:38:15 -05:00
|
|
|
qof_query_get_sorts (q, &s1, &s2, &s3);
|
2002-06-05 16:59:35 -05:00
|
|
|
|
|
|
|
/* primary-sort */
|
2003-02-22 02:15:53 -06:00
|
|
|
pair = scm_cons (gnc_query_sort2scm (s1), SCM_EOL);
|
|
|
|
pair = scm_cons (scm_str2symbol ("primary-sort"), pair);
|
|
|
|
query_scm = scm_cons (pair, query_scm);
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
/* secondary-sort */
|
2003-02-22 02:15:53 -06:00
|
|
|
pair = scm_cons (gnc_query_sort2scm (s2), SCM_EOL);
|
|
|
|
pair = scm_cons (scm_str2symbol ("secondary-sort"), pair);
|
|
|
|
query_scm = scm_cons (pair, query_scm);
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
/* tertiary-sort */
|
2003-02-22 02:15:53 -06:00
|
|
|
pair = scm_cons (gnc_query_sort2scm (s3), SCM_EOL);
|
|
|
|
pair = scm_cons (scm_str2symbol ("tertiary-sort"), pair);
|
|
|
|
query_scm = scm_cons (pair, query_scm);
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
/* max results */
|
2003-06-25 02:38:15 -05:00
|
|
|
pair = scm_cons (scm_int2num (qof_query_get_max_results (q)), SCM_EOL);
|
2003-02-22 02:15:53 -06:00
|
|
|
pair = scm_cons (scm_str2symbol ("max-results"), pair);
|
|
|
|
query_scm = scm_cons (pair, query_scm);
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
/* Reverse this list; tag it as 'query-v2' */
|
2003-02-22 02:15:53 -06:00
|
|
|
pair = scm_reverse (query_scm);
|
2003-09-09 19:01:54 -05:00
|
|
|
--scm_block_gc;
|
2003-02-22 02:15:53 -06:00
|
|
|
return scm_cons (scm_str2symbol ("query-v2"), pair);
|
2002-06-05 16:59:35 -05:00
|
|
|
}
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
static GSList *
|
|
|
|
gnc_query_sort_to_list (char * symbol)
|
|
|
|
{
|
|
|
|
GSList *path = NULL;
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
if (!symbol)
|
|
|
|
return NULL;
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
if (!safe_strcmp (symbol, "by-none")) {
|
|
|
|
path = NULL;
|
|
|
|
} else if (!safe_strcmp (symbol, "by-standard")) {
|
|
|
|
path = g_slist_prepend (path, QUERY_DEFAULT_SORT);
|
|
|
|
|
|
|
|
} else if (!safe_strcmp (symbol, "by-date") ||
|
|
|
|
!safe_strcmp (symbol, "by-date-rounded")) {
|
|
|
|
path = g_slist_prepend (path, TRANS_DATE_POSTED);
|
|
|
|
path = g_slist_prepend (path, SPLIT_TRANS);
|
|
|
|
|
|
|
|
} else if (!safe_strcmp (symbol, "by-date-entered") ||
|
|
|
|
!safe_strcmp (symbol, "by-date-entered-rounded")) {
|
|
|
|
path = g_slist_prepend (path, TRANS_DATE_ENTERED);
|
|
|
|
path = g_slist_prepend (path, SPLIT_TRANS);
|
|
|
|
|
|
|
|
} else if (!safe_strcmp (symbol, "by-date-reconciled") ||
|
|
|
|
!safe_strcmp (symbol, "by-date-reconciled-rounded")) {
|
|
|
|
path = g_slist_prepend (path, SPLIT_DATE_RECONCILED);
|
|
|
|
|
|
|
|
} else if (!safe_strcmp (symbol, "by-num")) {
|
|
|
|
path = g_slist_prepend (path, TRANS_NUM);
|
|
|
|
path = g_slist_prepend (path, SPLIT_TRANS);
|
|
|
|
|
|
|
|
} else if (!safe_strcmp (symbol, "by-amount")) {
|
|
|
|
path = g_slist_prepend (path, SPLIT_VALUE);
|
|
|
|
|
|
|
|
} else if (!safe_strcmp (symbol, "by-memo")) {
|
|
|
|
path = g_slist_prepend (path, SPLIT_MEMO);
|
|
|
|
|
|
|
|
} else if (!safe_strcmp (symbol, "by-desc")) {
|
|
|
|
path = g_slist_prepend (path, TRANS_DESCRIPTION);
|
|
|
|
path = g_slist_prepend (path, SPLIT_TRANS);
|
|
|
|
|
|
|
|
} else if (!safe_strcmp (symbol, "by-reconcile")) {
|
|
|
|
path = g_slist_prepend (path, SPLIT_RECONCILE);
|
|
|
|
|
|
|
|
} else if (!safe_strcmp (symbol, "by-account-full-name")) {
|
|
|
|
path = g_slist_prepend (path, SPLIT_ACCT_FULLNAME);
|
|
|
|
|
|
|
|
} else if (!safe_strcmp (symbol, "by-account-code")) {
|
|
|
|
path = g_slist_prepend (path, ACCOUNT_CODE_);
|
|
|
|
path = g_slist_prepend (path, SPLIT_ACCOUNT);
|
|
|
|
|
|
|
|
} else if (!safe_strcmp (symbol, "by-corr-account-full-name")) {
|
|
|
|
path = g_slist_prepend (path, SPLIT_CORR_ACCT_NAME);
|
|
|
|
|
|
|
|
} else if (!safe_strcmp (symbol, "by-corr-account-code")) {
|
|
|
|
path = g_slist_prepend (path, SPLIT_CORR_ACCT_CODE);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
PERR ("Unknown sort-type, %s", symbol);
|
|
|
|
}
|
|
|
|
|
|
|
|
free (symbol);
|
|
|
|
|
|
|
|
return path;
|
2001-08-07 18:29:04 -05:00
|
|
|
}
|
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
static Query *
|
|
|
|
gnc_scm2query_v1 (SCM query_scm)
|
2001-08-07 18:29:04 -05:00
|
|
|
{
|
|
|
|
Query *q = NULL;
|
|
|
|
gboolean ok = TRUE;
|
2002-06-05 16:59:35 -05:00
|
|
|
char * primary_sort = NULL;
|
|
|
|
char * secondary_sort = NULL;
|
|
|
|
char * tertiary_sort = NULL;
|
2001-08-07 18:29:04 -05:00
|
|
|
gboolean primary_increasing = TRUE;
|
|
|
|
gboolean secondary_increasing = TRUE;
|
|
|
|
gboolean tertiary_increasing = TRUE;
|
|
|
|
int max_splits = -1;
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
while (!SCM_NULLP (query_scm))
|
2001-08-07 18:29:04 -05:00
|
|
|
{
|
|
|
|
char *symbol;
|
|
|
|
SCM sym_scm;
|
|
|
|
SCM value;
|
|
|
|
SCM pair;
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
pair = SCM_CAR (query_scm);
|
|
|
|
query_scm = SCM_CDR (query_scm);
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
if (!SCM_CONSP (pair)) {
|
2002-06-05 16:59:35 -05:00
|
|
|
PERR ("Not a Pair");
|
2001-08-07 18:29:04 -05:00
|
|
|
ok = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
sym_scm = SCM_CAR (pair);
|
|
|
|
value = SCM_CADR (pair);
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
if (!SCM_SYMBOLP (sym_scm)) {
|
2002-06-05 16:59:35 -05:00
|
|
|
PERR ("Not a symbol");
|
2001-08-07 18:29:04 -05:00
|
|
|
ok = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
symbol = gh_symbol2newstr (sym_scm, NULL);
|
2002-06-05 16:59:35 -05:00
|
|
|
if (!symbol) {
|
|
|
|
PERR ("No string found");
|
2001-08-07 18:29:04 -05:00
|
|
|
ok = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
if (safe_strcmp ("terms", symbol) == 0) {
|
2001-08-07 18:29:04 -05:00
|
|
|
if (q)
|
|
|
|
xaccFreeQuery (q);
|
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
q = gnc_scm2query_or_terms (value, gnc_QUERY_v1);
|
|
|
|
if (!q) {
|
|
|
|
PINFO ("invalid terms");
|
2001-08-07 18:29:04 -05:00
|
|
|
ok = FALSE;
|
|
|
|
free (symbol);
|
|
|
|
break;
|
|
|
|
}
|
2002-06-05 16:59:35 -05:00
|
|
|
|
|
|
|
} else if (safe_strcmp ("primary-sort", symbol) == 0) {
|
2003-02-22 02:15:53 -06:00
|
|
|
if (!SCM_SYMBOLP (value)) {
|
2002-06-05 16:59:35 -05:00
|
|
|
PINFO ("Invalid primary sort");
|
2001-08-07 18:29:04 -05:00
|
|
|
ok = FALSE;
|
|
|
|
free (symbol);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
primary_sort = gh_symbol2newstr (value, NULL);
|
|
|
|
|
|
|
|
} else if (safe_strcmp ("secondary-sort", symbol) == 0) {
|
2003-02-22 02:15:53 -06:00
|
|
|
if (!SCM_SYMBOLP (value)) {
|
2002-06-05 16:59:35 -05:00
|
|
|
PINFO ("Invalid secondary sort");
|
2001-08-07 18:29:04 -05:00
|
|
|
ok = FALSE;
|
|
|
|
free (symbol);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
secondary_sort = gh_symbol2newstr (value, NULL);
|
|
|
|
|
|
|
|
} else if (safe_strcmp ("tertiary-sort", symbol) == 0) {
|
2003-02-22 02:15:53 -06:00
|
|
|
if (!SCM_SYMBOLP (value)) {
|
2002-06-05 16:59:35 -05:00
|
|
|
PINFO ("Invalid tertiary sort");
|
2001-08-07 18:29:04 -05:00
|
|
|
ok = FALSE;
|
|
|
|
free (symbol);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
tertiary_sort = gh_symbol2newstr (value, NULL);
|
|
|
|
|
|
|
|
} else if (safe_strcmp ("primary-increasing", symbol) == 0) {
|
2003-02-22 02:15:53 -06:00
|
|
|
primary_increasing = SCM_NFALSEP (value);
|
2002-06-05 16:59:35 -05:00
|
|
|
|
|
|
|
} else if (safe_strcmp ("secondary-increasing", symbol) == 0) {
|
2003-02-22 02:15:53 -06:00
|
|
|
secondary_increasing = SCM_NFALSEP (value);
|
2002-06-05 16:59:35 -05:00
|
|
|
|
|
|
|
} else if (safe_strcmp ("tertiary-increasing", symbol) == 0) {
|
2003-02-22 02:15:53 -06:00
|
|
|
tertiary_increasing = SCM_NFALSEP (value);
|
2002-06-05 16:59:35 -05:00
|
|
|
|
|
|
|
} else if (safe_strcmp ("max-splits", symbol) == 0) {
|
2003-02-22 02:15:53 -06:00
|
|
|
if (!SCM_NUMBERP (value)) {
|
2002-06-05 16:59:35 -05:00
|
|
|
PERR ("invalid max-splits");
|
2001-08-07 18:29:04 -05:00
|
|
|
ok = FALSE;
|
|
|
|
free (symbol);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
max_splits = scm_num2int (value, SCM_ARG1, __FUNCTION__);
|
2002-06-05 16:59:35 -05:00
|
|
|
|
|
|
|
} else {
|
|
|
|
PERR ("Unknown symbol: %s", symbol);
|
2001-08-07 18:29:04 -05:00
|
|
|
ok = FALSE;
|
|
|
|
free (symbol);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
free (symbol);
|
|
|
|
}
|
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
if (ok) {
|
|
|
|
GSList *s1, *s2, *s3;
|
|
|
|
s1 = gnc_query_sort_to_list (primary_sort);
|
|
|
|
s2 = gnc_query_sort_to_list (secondary_sort);
|
|
|
|
s3 = gnc_query_sort_to_list (tertiary_sort);
|
|
|
|
|
2003-06-25 02:38:15 -05:00
|
|
|
qof_query_set_sort_order (q, s1, s2, s3);
|
|
|
|
qof_query_set_sort_increasing (q, primary_increasing, secondary_increasing,
|
2002-06-05 16:59:35 -05:00
|
|
|
tertiary_increasing);
|
2001-08-07 18:29:04 -05:00
|
|
|
xaccQuerySetMaxSplits (q, max_splits);
|
|
|
|
|
|
|
|
return q;
|
|
|
|
}
|
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
if (primary_sort)
|
|
|
|
free (primary_sort);
|
|
|
|
|
|
|
|
if (secondary_sort)
|
|
|
|
free (secondary_sort);
|
|
|
|
|
|
|
|
if (tertiary_sort)
|
|
|
|
free (tertiary_sort);
|
|
|
|
|
|
|
|
xaccFreeQuery (q);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Query *
|
|
|
|
gnc_scm2query_v2 (SCM query_scm)
|
|
|
|
{
|
|
|
|
Query *q = NULL;
|
|
|
|
gboolean ok = TRUE;
|
|
|
|
char * search_for = NULL;
|
|
|
|
GSList *sp1 = NULL, *sp2 = NULL, *sp3 = NULL;
|
|
|
|
gint so1 = 0, so2 = 0, so3 = 0;
|
|
|
|
gboolean si1 = TRUE, si2 = TRUE, si3 = TRUE;
|
|
|
|
int max_results = -1;
|
|
|
|
|
2003-09-09 19:01:54 -05:00
|
|
|
++scm_block_gc;
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
while (!SCM_NULLP (query_scm))
|
2002-06-05 16:59:35 -05:00
|
|
|
{
|
|
|
|
char *symbol;
|
|
|
|
SCM sym_scm;
|
|
|
|
SCM value;
|
|
|
|
SCM pair;
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
pair = SCM_CAR (query_scm);
|
|
|
|
query_scm = SCM_CDR (query_scm);
|
2002-06-05 16:59:35 -05:00
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
if (!SCM_CONSP (pair)) {
|
2002-06-05 16:59:35 -05:00
|
|
|
ok = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
sym_scm = SCM_CAR (pair);
|
|
|
|
value = SCM_CADR (pair);
|
2002-06-05 16:59:35 -05:00
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
if (!SCM_SYMBOLP (sym_scm)) {
|
2002-06-05 16:59:35 -05:00
|
|
|
ok = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
symbol = gh_symbol2newstr (sym_scm, NULL);
|
|
|
|
if (!symbol) {
|
|
|
|
ok = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!safe_strcmp ("terms", symbol)) {
|
|
|
|
if (q)
|
|
|
|
xaccFreeQuery (q);
|
|
|
|
|
|
|
|
q = gnc_scm2query_or_terms (value, gnc_QUERY_v2);
|
|
|
|
if (!q) {
|
|
|
|
ok = FALSE;
|
|
|
|
free (symbol);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (!safe_strcmp ("search-for", symbol)) {
|
2003-02-22 02:15:53 -06:00
|
|
|
if (!SCM_SYMBOLP (value)) {
|
2002-06-05 16:59:35 -05:00
|
|
|
ok = FALSE;
|
|
|
|
free (symbol);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
search_for = gh_symbol2newstr (value, NULL);
|
|
|
|
|
|
|
|
} else if (safe_strcmp ("primary-sort", symbol) == 0) {
|
|
|
|
if (! gnc_query_scm2sort (value, &sp1, &so1, &si1)) {
|
|
|
|
ok = FALSE;
|
|
|
|
free (symbol);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (!safe_strcmp ("secondary-sort", symbol)) {
|
|
|
|
if (! gnc_query_scm2sort (value, &sp2, &so2, &si2)) {
|
|
|
|
ok = FALSE;
|
|
|
|
free (symbol);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (!safe_strcmp ("tertiary-sort", symbol)) {
|
|
|
|
if (! gnc_query_scm2sort (value, &sp3, &so3, &si3)) {
|
|
|
|
ok = FALSE;
|
|
|
|
free (symbol);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (!safe_strcmp ("max-results", symbol)) {
|
2003-02-22 02:15:53 -06:00
|
|
|
if (!SCM_NUMBERP (value)) {
|
2002-06-05 16:59:35 -05:00
|
|
|
ok = FALSE;
|
|
|
|
free (symbol);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
max_results = scm_num2int (value, SCM_ARG1, __FUNCTION__);
|
2002-06-05 16:59:35 -05:00
|
|
|
|
|
|
|
} else {
|
|
|
|
ok = FALSE;
|
|
|
|
free (symbol);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
free (symbol);
|
|
|
|
}
|
|
|
|
|
2003-09-09 19:01:54 -05:00
|
|
|
--scm_block_gc;
|
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
if (ok && search_for) {
|
2003-06-25 02:38:15 -05:00
|
|
|
qof_query_search_for (q, search_for);
|
|
|
|
qof_query_set_sort_order (q, sp1, sp2, sp3);
|
|
|
|
qof_query_set_sort_options (q, so1, so2, so3);
|
|
|
|
qof_query_set_sort_increasing (q, si1, si2, si3);
|
|
|
|
qof_query_set_max_results (q, max_results);
|
2002-06-05 16:59:35 -05:00
|
|
|
|
|
|
|
return q;
|
|
|
|
}
|
|
|
|
|
2001-08-07 18:29:04 -05:00
|
|
|
xaccFreeQuery (q);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2002-06-05 16:59:35 -05:00
|
|
|
Query *
|
|
|
|
gnc_scm2query (SCM query_scm)
|
|
|
|
{
|
|
|
|
SCM q_type;
|
|
|
|
char *type;
|
|
|
|
Query *q = NULL;
|
|
|
|
|
|
|
|
/* Not a list or NULL? No need to go further */
|
2003-02-22 02:15:53 -06:00
|
|
|
if (!SCM_LISTP (query_scm) || SCM_NULLP (query_scm))
|
2002-06-05 16:59:35 -05:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* Grab the 'type' (for v2 and above) */
|
2003-02-22 02:15:53 -06:00
|
|
|
q_type = SCM_CAR (query_scm);
|
2001-08-07 18:29:04 -05:00
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
if (!SCM_SYMBOLP (q_type)) {
|
|
|
|
if (SCM_CONSP (q_type)) {
|
2002-06-05 16:59:35 -05:00
|
|
|
/* Version-1 queries are just a list */
|
|
|
|
return gnc_scm2query_v1 (query_scm);
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Ok, the LHS is the version and the RHS is the actual query list */
|
|
|
|
type = gh_symbol2newstr (q_type, NULL);
|
|
|
|
if (!type)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!safe_strcmp (type, "query-v2"))
|
2003-02-22 02:15:53 -06:00
|
|
|
q = gnc_scm2query_v2 (SCM_CDR (query_scm));
|
2002-06-05 16:59:35 -05:00
|
|
|
|
|
|
|
free (type);
|
|
|
|
return q;
|
|
|
|
}
|
2001-08-07 18:29:04 -05:00
|
|
|
|
|
|
|
static int
|
|
|
|
gnc_scm_traversal_adapter(Transaction *t, void *data)
|
|
|
|
{
|
|
|
|
static SCM trans_type = SCM_BOOL_F;
|
|
|
|
SCM result;
|
|
|
|
SCM scm_trans;
|
|
|
|
SCM thunk = *((SCM *) data);
|
|
|
|
|
|
|
|
if(trans_type == SCM_BOOL_F) {
|
2003-02-22 02:15:53 -06:00
|
|
|
trans_type = scm_c_eval_string("<gnc:Transaction*>");
|
2001-08-07 18:29:04 -05:00
|
|
|
/* don't really need this - types are bound globally anyway. */
|
|
|
|
if(trans_type != SCM_BOOL_F) scm_protect_object(trans_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
scm_trans = gw_wcp_assimilate_ptr(t, trans_type);
|
2003-02-22 02:15:53 -06:00
|
|
|
result = scm_call_1(thunk, scm_trans);
|
2001-08-07 18:29:04 -05:00
|
|
|
|
|
|
|
return (result != SCM_BOOL_F);
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gnc_scmGroupStagedTransactionTraversal(AccountGroup *grp,
|
|
|
|
unsigned int new_marker,
|
|
|
|
SCM thunk)
|
|
|
|
{
|
|
|
|
return xaccGroupStagedTransactionTraversal(grp, new_marker,
|
|
|
|
gnc_scm_traversal_adapter,
|
|
|
|
&thunk);
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gnc_scmAccountStagedTransactionTraversal(Account *a,
|
|
|
|
unsigned int new_marker,
|
|
|
|
SCM thunk)
|
|
|
|
{
|
|
|
|
return xaccAccountStagedTransactionTraversal(a, new_marker,
|
|
|
|
gnc_scm_traversal_adapter,
|
|
|
|
&thunk);
|
|
|
|
}
|
|
|
|
|
|
|
|
SCM
|
|
|
|
gnc_gint64_to_scm(const gint64 x)
|
|
|
|
{
|
|
|
|
#if GUILE_LONG_LONG_OK
|
|
|
|
return scm_long_long2num(x);
|
|
|
|
#else
|
|
|
|
const gchar negative_p = (x < 0);
|
|
|
|
const guint64 magnitude = negative_p ? -x : x;
|
|
|
|
const guint32 lower_half = (guint32) (magnitude & 0xFFFFFFFF);
|
|
|
|
const guint32 upper_half = (guint32) (magnitude >> 32);
|
|
|
|
SCM result;
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
result = scm_sum(scm_ash(scm_ulong2num(upper_half), SCM_MAKINUM(32)),
|
|
|
|
scm_ulong2num(lower_half));
|
2001-08-07 18:29:04 -05:00
|
|
|
|
|
|
|
if(negative_p) {
|
|
|
|
return scm_difference(SCM_INUM0, result);
|
|
|
|
} else {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
gint64
|
|
|
|
gnc_scm_to_gint64(SCM num)
|
|
|
|
{
|
|
|
|
#if GUILE_LONG_LONG_OK
|
2003-01-13 23:11:34 -06:00
|
|
|
#ifdef SCM_MINOR_VERSION
|
|
|
|
/* Guile 1.6 and later have the SCM_XXX_VERSION macro */
|
|
|
|
return scm_num2long_long(num, SCM_ARG1, "gnc_scm_to_gint64");
|
|
|
|
#else
|
2003-01-07 18:20:28 -06:00
|
|
|
return scm_num2long_long(num, (char *) SCM_ARG1, "gnc_scm_to_gint64");
|
2003-01-13 23:11:34 -06:00
|
|
|
#endif
|
2001-08-07 18:29:04 -05:00
|
|
|
#else
|
|
|
|
static SCM bits00to15_mask = SCM_BOOL_F;
|
|
|
|
SCM magnitude = scm_abs(num);
|
|
|
|
SCM bits;
|
|
|
|
unsigned long c_bits;
|
|
|
|
long long c_result = 0;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* This doesn't work -- atm (bit-extract 4000 0 32) proves it */
|
|
|
|
/*
|
|
|
|
SCM lower = scm_bit_extract(magnitude, SCM_MAKINUM(0), SCM_MAKINUM(32));
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (bits00to15_mask == SCM_BOOL_F) {
|
2003-02-22 02:15:53 -06:00
|
|
|
bits00to15_mask = scm_ulong2num(0xFFFF);
|
2001-08-07 18:29:04 -05:00
|
|
|
scm_protect_object (bits00to15_mask);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This isn't very complicated (IMHO). We work from the "top" of
|
|
|
|
* the number downwards. We assume this is no more than a 64-bit
|
|
|
|
* number, otherwise it will fail right away. Anyways, we keep
|
|
|
|
* taking the top 16 bits of the number and move it to c_result.
|
|
|
|
* Then we 'remove' those bits from the original number and continue
|
|
|
|
* with the next 16 bits down, and so on. -- warlord@mit.edu
|
|
|
|
* 2001/02/13
|
|
|
|
*/
|
|
|
|
for (i = 48; i >=0; i-= 16) {
|
|
|
|
bits = scm_ash(magnitude, SCM_MAKINUM(-i));
|
2003-02-22 02:15:53 -06:00
|
|
|
c_bits = scm_num2ulong(scm_logand(bits, bits00to15_mask), SCM_ARG1, __FUNCTION__);
|
2001-08-07 18:29:04 -05:00
|
|
|
c_result += ((long long)c_bits << i);
|
|
|
|
magnitude = scm_difference(magnitude, scm_ash(bits, SCM_MAKINUM(i)));
|
|
|
|
}
|
|
|
|
|
|
|
|
if(scm_negative_p(num) != SCM_BOOL_F) {
|
|
|
|
return(- c_result);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return(c_result);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
gnc_gh_gint64_p(SCM num)
|
|
|
|
{
|
|
|
|
static int initialized = 0;
|
|
|
|
static SCM maxval;
|
|
|
|
static SCM minval;
|
|
|
|
|
2001-11-15 18:41:30 -06:00
|
|
|
if (!initialized)
|
|
|
|
{
|
2001-08-07 18:29:04 -05:00
|
|
|
/* to be super safe, we have to build these manually because
|
|
|
|
though we know that we have gint64's here, we *don't* know how
|
|
|
|
to portably specify a 64bit constant to the compiler (i.e. like
|
|
|
|
0x7FFFFFFFFFFFFFFF). */
|
|
|
|
gint64 tmp;
|
|
|
|
|
|
|
|
tmp = 0x7FFFFFFF;
|
|
|
|
tmp <<= 32;
|
|
|
|
tmp |= 0xFFFFFFFF;
|
|
|
|
maxval = gnc_gint64_to_scm(tmp);
|
|
|
|
|
|
|
|
tmp = 0x80000000;
|
|
|
|
tmp <<= 32;
|
|
|
|
minval = gnc_gint64_to_scm(tmp);
|
|
|
|
|
|
|
|
scm_protect_object(maxval);
|
|
|
|
scm_protect_object(minval);
|
|
|
|
initialized = 1;
|
|
|
|
}
|
2001-11-15 18:41:30 -06:00
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
return (SCM_EXACTP(num) &&
|
2001-11-15 18:41:30 -06:00
|
|
|
(scm_geq_p(num, minval) != SCM_BOOL_F) &&
|
2001-11-05 18:49:46 -06:00
|
|
|
(scm_leq_p(num, maxval) != SCM_BOOL_F));
|
2001-08-07 18:29:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
gnc_numeric
|
|
|
|
gnc_scm_to_numeric(SCM gncnum)
|
|
|
|
{
|
|
|
|
static SCM get_num = SCM_BOOL_F;
|
|
|
|
static SCM get_denom = SCM_BOOL_F;
|
|
|
|
|
|
|
|
if(get_num == SCM_BOOL_F) {
|
2003-02-22 02:15:53 -06:00
|
|
|
get_num = scm_c_eval_string("gnc:gnc-numeric-num");
|
2001-08-07 18:29:04 -05:00
|
|
|
}
|
|
|
|
if(get_denom == SCM_BOOL_F) {
|
2003-02-22 02:15:53 -06:00
|
|
|
get_denom = scm_c_eval_string("gnc:gnc-numeric-denom");
|
2001-08-07 18:29:04 -05:00
|
|
|
}
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
return gnc_numeric_create(gnc_scm_to_gint64(scm_call_1(get_num, gncnum)),
|
|
|
|
gnc_scm_to_gint64(scm_call_1(get_denom, gncnum)));
|
2001-08-07 18:29:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
SCM
|
|
|
|
gnc_numeric_to_scm(gnc_numeric arg)
|
|
|
|
{
|
|
|
|
static SCM maker = SCM_BOOL_F;
|
|
|
|
|
|
|
|
if(maker == SCM_BOOL_F) {
|
2003-02-22 02:15:53 -06:00
|
|
|
maker = scm_c_eval_string("gnc:make-gnc-numeric");
|
2001-08-07 18:29:04 -05:00
|
|
|
}
|
|
|
|
|
2003-02-22 02:15:53 -06:00
|
|
|
return scm_call_2(maker, gnc_gint64_to_scm(gnc_numeric_num(arg)),
|
|
|
|
gnc_gint64_to_scm(gnc_numeric_denom(arg)));
|
2001-08-07 18:29:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
gnc_numeric_p(SCM arg)
|
|
|
|
{
|
|
|
|
static SCM type_p = SCM_BOOL_F;
|
|
|
|
SCM ret = SCM_BOOL_F;
|
|
|
|
|
|
|
|
if(type_p == SCM_BOOL_F) {
|
2003-02-22 02:15:53 -06:00
|
|
|
type_p = scm_c_eval_string("gnc:gnc-numeric?");
|
2001-08-07 18:29:04 -05:00
|
|
|
}
|
2003-02-22 02:15:53 -06:00
|
|
|
ret = scm_call_1(type_p, arg);
|
2001-08-07 18:29:04 -05:00
|
|
|
|
|
|
|
if(ret == SCM_BOOL_F) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
2001-09-11 02:41:26 -05:00
|
|
|
|
2001-08-07 18:29:04 -05:00
|
|
|
/********************************************************************
|
|
|
|
* gnc_scm_to_commodity
|
|
|
|
********************************************************************/
|
|
|
|
gnc_commodity *
|
|
|
|
gnc_scm_to_commodity(SCM scm)
|
|
|
|
{
|
|
|
|
static SCM commodity_type = SCM_UNDEFINED;
|
|
|
|
|
|
|
|
if(commodity_type == SCM_UNDEFINED) {
|
2003-02-22 02:15:53 -06:00
|
|
|
commodity_type = scm_c_eval_string("<gnc:commodity*>");
|
2001-08-07 18:29:04 -05:00
|
|
|
/* don't really need this - types are bound globally anyway. */
|
|
|
|
if(commodity_type != SCM_UNDEFINED) scm_protect_object(commodity_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!gw_wcp_is_of_type_p(commodity_type, scm)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return gw_wcp_get_ptr(scm);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/********************************************************************
|
|
|
|
* gnc_commodity_to_scm
|
|
|
|
********************************************************************/
|
|
|
|
SCM
|
|
|
|
gnc_commodity_to_scm (const gnc_commodity *commodity)
|
|
|
|
{
|
|
|
|
static SCM commodity_type = SCM_UNDEFINED;
|
|
|
|
|
|
|
|
if(commodity == NULL) return SCM_BOOL_F;
|
|
|
|
|
|
|
|
if(commodity_type == SCM_UNDEFINED) {
|
2003-02-22 02:15:53 -06:00
|
|
|
commodity_type = scm_c_eval_string("<gnc:commodity*>");
|
2001-08-07 18:29:04 -05:00
|
|
|
/* don't really need this - types are bound globally anyway. */
|
|
|
|
if(commodity_type != SCM_UNDEFINED) scm_protect_object(commodity_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
return gw_wcp_assimilate_ptr((void *) commodity, commodity_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************************************************************
|
|
|
|
* gnc_book_to_scm
|
|
|
|
********************************************************************/
|
|
|
|
SCM
|
2003-06-24 19:52:46 -05:00
|
|
|
gnc_book_to_scm (QofBook *book)
|
2001-08-07 18:29:04 -05:00
|
|
|
{
|
|
|
|
static SCM book_type = SCM_UNDEFINED;
|
|
|
|
|
|
|
|
if (!book)
|
|
|
|
return SCM_BOOL_F;
|
|
|
|
|
|
|
|
if (book_type == SCM_UNDEFINED)
|
|
|
|
{
|
2003-02-22 02:15:53 -06:00
|
|
|
book_type = scm_c_eval_string ("<gnc:Book*>");
|
2001-08-07 18:29:04 -05:00
|
|
|
|
|
|
|
/* don't really need this - types are bound globally anyway. */
|
|
|
|
if (book_type != SCM_UNDEFINED)
|
|
|
|
scm_protect_object (book_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
return gw_wcp_assimilate_ptr ((void *) book, book_type);
|
|
|
|
}
|
|
|
|
|
2001-10-05 03:35:04 -05:00
|
|
|
/********************************************************************
|
2003-06-26 21:51:10 -05:00
|
|
|
* qof_session_to_scm
|
2001-10-05 03:35:04 -05:00
|
|
|
********************************************************************/
|
|
|
|
SCM
|
2003-06-26 21:51:10 -05:00
|
|
|
qof_session_to_scm (QofSession *session)
|
2001-10-05 03:35:04 -05:00
|
|
|
{
|
|
|
|
static SCM session_type = SCM_UNDEFINED;
|
|
|
|
|
|
|
|
if (!session)
|
|
|
|
return SCM_BOOL_F;
|
|
|
|
|
|
|
|
if (session_type == SCM_UNDEFINED)
|
|
|
|
{
|
2003-02-22 02:15:53 -06:00
|
|
|
session_type = scm_c_eval_string ("<gnc:Session*>");
|
2001-10-05 03:35:04 -05:00
|
|
|
|
|
|
|
/* don't really need this - types are bound globally anyway. */
|
|
|
|
if (session_type != SCM_UNDEFINED)
|
|
|
|
scm_protect_object (session_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
return gw_wcp_assimilate_ptr ((void *) session, session_type);
|
|
|
|
}
|