-
Notifications
You must be signed in to change notification settings - Fork 760
/
gnc-engine-guile.cpp
1915 lines (1545 loc) · 46.6 KB
/
gnc-engine-guile.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/********************************************************************\
* gnc-engine-guile.cpp -- engine helper functions for guile *
* Copyright (C) 2000 Linas Vepstas <linas@linas.org> *
* 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 *
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
* Boston, MA 02110-1301, USA gnu@gnu.org *
* *
\********************************************************************/
#include <config.h>
#include "swig-runtime.h"
#include <libguile.h>
#include <cstring>
extern "C"
{
#include "Account.h"
#include "engine-helpers.h"
#include "gnc-engine-guile.h"
#include "gnc-date.h"
#include "gnc-engine.h"
#include "gnc-session.h"
#include "guile-mappings.h"
#include "gnc-guile-utils.h"
#include <qof.h>
#include <qofbookslots.h>
#ifndef HAVE_STRPTIME
# include "strptime.h"
#endif
}
/** \todo Code dependent on the private query headers
qofquery-p.h and qofquerycore-p.h may need to be modified.
These files are temporarily exported for QOF 0.6.0 but
cannot be considered "standard" or public parts of QOF. */
#include "qofquery-p.h"
#include "qofquerycore-p.h"
#define FUNC_NAME G_STRFUNC
static QofLogModule log_module = GNC_MOD_ENGINE;
GDate gnc_time64_to_GDate(SCM x)
{
time64 time = scm_to_int64 (x);
return time64_to_gdate(time);
}
SCM
gnc_guid2scm(GncGUID guid)
{
char string[GUID_ENCODING_LENGTH + 1];
if (!guid_to_string_buff(&guid, string))
return SCM_BOOL_F;
return scm_from_utf8_string(string);
}
GncGUID
gnc_scm2guid(SCM guid_scm)
{
GncGUID guid;
gchar * str;
if (!scm_is_string(guid_scm)
|| (GUID_ENCODING_LENGTH != scm_c_string_length (guid_scm)))
{
return *guid_null();
}
str = gnc_scm_to_utf8_string (guid_scm);
string_to_guid(str, &guid);
g_free (str);
return guid;
}
int
gnc_guid_p(SCM guid_scm)
{
GncGUID guid;
gchar * str;
int return_int;
if (!scm_is_string(guid_scm))
return FALSE;
if (GUID_ENCODING_LENGTH != scm_c_string_length (guid_scm))
{
return FALSE;
}
str = gnc_scm_to_utf8_string (guid_scm);
return_int = string_to_guid(str, &guid);
g_free (str);
return return_int;
}
/********************************************************************
* 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-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)
*/
typedef enum
{
gnc_QUERY_v1 = 1,
gnc_QUERY_v2
} query_version_t;
/* QofCompareFunc */
static QofQueryCompare
gnc_query_scm2compare (SCM how_scm)
{
return static_cast<QofQueryCompare>(scm_to_int(how_scm));
}
/* QofStringMatch */
static QofStringMatch
gnc_query_scm2string (SCM how_scm)
{
return static_cast<QofStringMatch>(scm_to_int(how_scm));
}
/* QofDateMatch */
static QofDateMatch
gnc_query_scm2date (SCM how_scm)
{
return static_cast<QofDateMatch>(scm_to_int(how_scm));
}
/* QofNumericMatch */
static QofNumericMatch
gnc_query_scm2numericop (SCM how_scm)
{
return static_cast<QofNumericMatch>(scm_to_int(how_scm));
}
/* QofGuidMatch */
static QofGuidMatch
gnc_query_scm2guid (SCM how_scm)
{
return static_cast<QofGuidMatch>(scm_to_int(how_scm));
}
/* QofCharMatch */
static QofCharMatch
gnc_query_scm2char (SCM how_scm)
{
return static_cast<QofCharMatch>(scm_to_int(how_scm));
}
static QofGuidMatch
gnc_scm2acct_match_how (SCM how_scm)
{
QofGuidMatch res;
gchar *how = gnc_scm_symbol_to_locale_string (how_scm);
if (!g_strcmp0 (how, "acct-match-all"))
res = QOF_GUID_MATCH_ALL;
else if (!g_strcmp0 (how, "acct-match-any"))
res = QOF_GUID_MATCH_ANY;
else if (!g_strcmp0 (how, "acct-match-none"))
res = QOF_GUID_MATCH_NONE;
else
{
PINFO ("invalid account match: %s", how);
res = QOF_GUID_MATCH_NULL;
}
g_free (how);
return res;
}
static QofQueryCompare
gnc_scm2amt_match_how (SCM how_scm)
{
QofQueryCompare res;
gchar *how = gnc_scm_symbol_to_locale_string (how_scm);
if (!g_strcmp0 (how, "amt-match-atleast"))
res = QOF_COMPARE_GTE;
else if (!g_strcmp0 (how, "amt-match-atmost"))
res = QOF_COMPARE_LTE;
else if (!g_strcmp0 (how, "amt-match-exactly"))
res = QOF_COMPARE_EQUAL;
else
{
PINFO ("invalid amount match: %s", how);
res = QOF_COMPARE_EQUAL;
}
g_free (how);
return res;
}
static int
gnc_scm2bitfield (SCM field_scm)
{
int field = 0;
if (!scm_is_list (field_scm))
return 0;
while (!scm_is_null (field_scm))
{
SCM scm;
int bit;
scm = SCM_CAR (field_scm);
field_scm = SCM_CDR (field_scm);
bit = scm_to_int(scm);
field |= bit;
}
return field;
}
static cleared_match_t
gnc_scm2cleared_match_how (SCM how_scm)
{
return static_cast<cleared_match_t>(gnc_scm2bitfield (how_scm));
}
static gboolean
gnc_scm2balance_match_how (SCM how_scm, gboolean *resp)
{
gchar *how;
if (!scm_is_list (how_scm))
return FALSE;
if (scm_is_null (how_scm))
return FALSE;
/* Only allow a single-entry list */
if (!scm_is_null (SCM_CDR (how_scm)))
return FALSE;
how = gnc_scm_symbol_to_locale_string (SCM_CAR(how_scm));
if (!g_strcmp0 (how, "balance-match-balanced"))
*resp = TRUE;
else
*resp = FALSE;
g_free (how);
return TRUE;
}
static SCM
gnc_guid_glist2scm (const GList *account_guids)
{
SCM guids = SCM_EOL;
const GList *node;
for (node = account_guids; node; node = node->next)
{
auto guid = static_cast<GncGUID*>(node->data);
if (guid)
guids = scm_cons (gnc_guid2scm (*guid), guids);
}
return scm_reverse (guids);
}
static GList *
gnc_scm2guid_glist (SCM guids_scm)
{
GList *guids = nullptr;
if (!scm_is_list (guids_scm))
return nullptr;
while (!scm_is_null (guids_scm))
{
SCM guid_scm = SCM_CAR (guids_scm);
GncGUID *guid = nullptr;
if (guid_scm != SCM_BOOL_F)
{
guid = guid_malloc ();
*guid = gnc_scm2guid (guid_scm);
}
guids = g_list_prepend (guids, guid);
guids_scm = SCM_CDR (guids_scm);
}
return g_list_reverse (guids);
}
static inline void
gnc_guid_glist_free (GList *guids)
{
g_list_free_full (guids, (GDestroyNotify)guid_free);
}
static SCM
gnc_query_numeric2scm (gnc_numeric val)
{
return scm_cons (scm_from_int64 (val.num),
scm_from_int64 (val.denom));
}
static gboolean
gnc_query_numeric_p (SCM pair)
{
return (scm_is_pair (pair));
}
static gnc_numeric
gnc_query_scm2numeric (SCM pair)
{
SCM denom;
SCM num;
num = SCM_CAR (pair);
denom = SCM_CDR (pair);
return gnc_numeric_create (scm_to_int64 (num),
scm_to_int64 (denom));
}
static SCM
gnc_query_path2scm (const GSList *path)
{
SCM path_scm = SCM_EOL;
const GSList *node;
for (node = path; node; node = node->next)
{
auto key = static_cast<const char *>(node->data);
if (key)
path_scm = scm_cons (scm_from_utf8_string (key), path_scm);
}
return scm_reverse (path_scm);
}
GSList *
gnc_query_scm2path (SCM path_scm)
{
GSList *path = nullptr;
if (!scm_is_list (path_scm))
return nullptr;
while (!scm_is_null (path_scm))
{
SCM key_scm = SCM_CAR (path_scm);
char *key;
if (!scm_is_string (key_scm))
break;
key = gnc_scm_to_utf8_string(key_scm);
path = g_slist_prepend (path, key);
path_scm = SCM_CDR (path_scm);
}
return g_slist_reverse (path);
}
static void
gnc_query_path_free (GSList *path)
{
GSList *node;
for (node = path; node; node = node->next)
g_free (node->data);
g_slist_free (path);
}
static SCM
gnc_queryterm2scm (const QofQueryTerm *qt)
{
SCM qt_scm = SCM_EOL;
QofQueryPredData *pd = nullptr;
qt_scm = scm_cons (gnc_query_path2scm (qof_query_term_get_param_path (qt)),
qt_scm);
qt_scm = scm_cons (SCM_BOOL (qof_query_term_is_inverted (qt)), qt_scm);
pd = qof_query_term_get_pred_data (qt);
qt_scm = scm_cons (scm_from_locale_symbol (pd->type_name), qt_scm);
qt_scm = scm_cons (scm_from_long (pd->how), qt_scm);
if (!g_strcmp0 (pd->type_name, QOF_TYPE_STRING))
{
auto pdata = (query_string_t) pd;
qt_scm = scm_cons (scm_from_long (pdata->options), qt_scm);
qt_scm = scm_cons (SCM_BOOL (pdata->is_regex), qt_scm);
qt_scm = scm_cons (pdata->matchstring ? scm_from_utf8_string (pdata->matchstring) : SCM_BOOL_F, qt_scm);
}
else if (!g_strcmp0 (pd->type_name, QOF_TYPE_DATE))
{
auto pdata = (query_date_t) pd;
qt_scm = scm_cons (scm_from_long (pdata->options), qt_scm);
qt_scm = scm_cons (scm_from_int64 (pdata->date), qt_scm);
}
else if (!g_strcmp0 (pd->type_name, QOF_TYPE_NUMERIC))
{
auto pdata = (query_numeric_t) pd;
qt_scm = scm_cons (scm_from_long (pdata->options), qt_scm);
qt_scm = scm_cons (gnc_query_numeric2scm (pdata->amount), qt_scm);
}
else if (!g_strcmp0 (pd->type_name, QOF_TYPE_GUID))
{
auto pdata = (query_guid_t) pd;
qt_scm = scm_cons (scm_from_long (pdata->options), qt_scm);
qt_scm = scm_cons (gnc_guid_glist2scm (pdata->guids), qt_scm);
}
else if (!g_strcmp0 (pd->type_name, QOF_TYPE_INT64))
{
auto pdata = (query_int64_t) pd;
qt_scm = scm_cons (scm_from_int64 (pdata->val), qt_scm);
}
else if (!g_strcmp0 (pd->type_name, QOF_TYPE_DOUBLE))
{
auto pdata = (query_double_t) pd;
qt_scm = scm_cons (scm_from_double (pdata->val), qt_scm);
}
else if (!g_strcmp0 (pd->type_name, QOF_TYPE_BOOLEAN))
{
auto pdata = (query_boolean_t) pd;
qt_scm = scm_cons (SCM_BOOL (pdata->val), qt_scm);
}
else if (!g_strcmp0 (pd->type_name, QOF_TYPE_CHAR))
{
auto pdata = (query_char_t) pd;
qt_scm = scm_cons (scm_from_long (pdata->options), qt_scm);
qt_scm = scm_cons (pdata->char_list ? scm_from_utf8_string (pdata->char_list) : SCM_BOOL_F, qt_scm);
}
else
{
PWARN ("query core type %s not supported", pd->type_name);
return SCM_BOOL_F;
}
return scm_reverse (qt_scm);
}
static QofQuery *
gnc_scm2query_term_query_v2 (SCM qt_scm)
{
QofQuery *q = nullptr;
QofQueryPredData *pd = nullptr;
SCM scm;
gchar *type = nullptr;
GSList *path = nullptr;
gboolean inverted = FALSE;
QofQueryCompare compare_how;
if (!scm_is_list (qt_scm) || scm_is_null (qt_scm))
return nullptr;
do
{
/* param path */
scm = SCM_CAR (qt_scm);
qt_scm = SCM_CDR (qt_scm);
if (!scm_is_list (scm))
break;
path = gnc_query_scm2path (scm);
/* inverted */
scm = SCM_CAR (qt_scm);
qt_scm = SCM_CDR (qt_scm);
if (!scm_is_bool (scm))
break;
inverted = scm_is_true (scm);
/* type */
scm = SCM_CAR (qt_scm);
qt_scm = SCM_CDR (qt_scm);
if (!scm_is_symbol (scm))
break;
type = gnc_scm_symbol_to_locale_string (scm);
/* QofCompareFunc */
scm = SCM_CAR (qt_scm);
qt_scm = SCM_CDR (qt_scm);
if (scm_is_null (scm))
break;
compare_how = gnc_query_scm2compare (scm);
/* Now compute the predicate */
if (!g_strcmp0 (type, QOF_TYPE_STRING))
{
QofStringMatch options;
gboolean is_regex;
gchar *matchstring;
scm = SCM_CAR (qt_scm);
qt_scm = SCM_CDR (qt_scm);
if (scm_is_null (scm)) break;
options = gnc_query_scm2string (scm);
scm = SCM_CAR (qt_scm);
qt_scm = SCM_CDR (qt_scm);
if (!scm_is_bool (scm)) break;
is_regex = scm_is_true (scm);
scm = SCM_CAR (qt_scm);
if (!scm_is_string (scm)) break;
matchstring = gnc_scm_to_utf8_string (scm);
pd = qof_query_string_predicate (compare_how, matchstring,
options, is_regex);
g_free (matchstring);
}
else if (!g_strcmp0 (type, QOF_TYPE_DATE))
{
QofDateMatch options;
time64 date;
scm = SCM_CAR (qt_scm);
qt_scm = SCM_CDR (qt_scm);
if (scm_is_null (scm))
break;
options = gnc_query_scm2date (scm);
scm = SCM_CAR (qt_scm);
if (scm_is_null (scm))
break;
date = scm_to_int64 (scm);
pd = qof_query_date_predicate (compare_how, options, date);
}
else if (!g_strcmp0 (type, QOF_TYPE_NUMERIC))
{
QofNumericMatch options;
gnc_numeric val;
scm = SCM_CAR (qt_scm);
qt_scm = SCM_CDR (qt_scm);
if (scm_is_null (scm))
break;
options = gnc_query_scm2numericop (scm);
scm = SCM_CAR (qt_scm);
if (!gnc_query_numeric_p (scm))
break;
val = gnc_query_scm2numeric (scm);
pd = qof_query_numeric_predicate (compare_how, options, val);
}
else if (!g_strcmp0 (type, QOF_TYPE_GUID))
{
QofGuidMatch options;
GList *guids;
scm = SCM_CAR (qt_scm);
qt_scm = SCM_CDR (qt_scm);
if (scm_is_null (scm))
break;
options = gnc_query_scm2guid (scm);
scm = SCM_CAR (qt_scm);
if (!scm_is_list (scm))
break;
guids = gnc_scm2guid_glist (scm);
pd = qof_query_guid_predicate (options, guids);
gnc_guid_glist_free (guids);
}
else if (!g_strcmp0 (type, QOF_TYPE_INT64))
{
gint64 val;
scm = SCM_CAR (qt_scm);
if (scm_is_null (scm))
break;
val = scm_to_int64 (scm);
pd = qof_query_int64_predicate (compare_how, val);
}
else if (!g_strcmp0 (type, QOF_TYPE_DOUBLE))
{
double val;
scm = SCM_CAR (qt_scm);
if (!scm_is_number (scm))
break;
val = scm_to_double (scm);
pd = qof_query_double_predicate (compare_how, val);
}
else if (!g_strcmp0 (type, QOF_TYPE_BOOLEAN))
{
gboolean val;
scm = SCM_CAR (qt_scm);
if (!scm_is_bool (scm))
break;
val = scm_is_true (scm);
pd = qof_query_boolean_predicate (compare_how, val);
}
else if (!g_strcmp0 (type, QOF_TYPE_CHAR))
{
QofCharMatch options;
gchar *char_list;
scm = SCM_CAR (qt_scm);
qt_scm = SCM_CDR (qt_scm);
if (scm_is_null (scm))
break;
options = gnc_query_scm2char (scm);
scm = SCM_CAR (qt_scm);
if (!scm_is_string (scm))
break;
char_list = gnc_scm_to_utf8_string (scm);
pd = qof_query_char_predicate (options, char_list);
g_free (char_list);
}
else
{
PWARN ("query core type %s not supported", type);
break;
}
g_free (type);
}
while (FALSE);
if (pd)
{
q = qof_query_create ();
qof_query_add_term (q, path, pd, QOF_QUERY_OR);
if (inverted)
{
QofQuery *outq = qof_query_invert (q);
qof_query_destroy (q);
q = outq;
}
}
else
{
gnc_query_path_free (path);
}
return q;
}
static QofQuery *
gnc_scm2query_term_query_v1 (SCM query_term_scm)
{
gboolean ok = FALSE;
gchar * pd_type = nullptr;
gchar * pr_type = nullptr;
gboolean sense = FALSE;
QofQuery *q = nullptr;
SCM scm;
if (!scm_is_list (query_term_scm) ||
scm_is_null (query_term_scm))
{
PINFO ("null term");
return nullptr;
}
do
{
/* pd_type */
scm = SCM_CAR (query_term_scm);
query_term_scm = SCM_CDR (query_term_scm);
pd_type = gnc_scm_symbol_to_locale_string (scm);
/* pr_type */
if (scm_is_null (query_term_scm))
{
PINFO ("null pr_type");
break;
}
scm = SCM_CAR (query_term_scm);
query_term_scm = SCM_CDR (query_term_scm);
pr_type = gnc_scm_symbol_to_locale_string (scm);
/* sense */
if (scm_is_null (query_term_scm))
{
PINFO ("null sense");
break;
}
scm = SCM_CAR (query_term_scm);
query_term_scm = SCM_CDR (query_term_scm);
sense = scm_is_true (scm);
q = qof_query_create_for(GNC_ID_SPLIT);
if (!g_strcmp0 (pd_type, "pd-date"))
{
gboolean use_start;
gboolean use_end;
time64 start;
time64 end;
/* use_start */
if (scm_is_null (query_term_scm))
{
PINFO ("null use_start");
break;
}
scm = SCM_CAR (query_term_scm);
query_term_scm = SCM_CDR (query_term_scm);
use_start = scm_is_true (scm);
/* start */
if (scm_is_null (query_term_scm))
break;
scm = SCM_CAR (query_term_scm);
query_term_scm = SCM_CDR (query_term_scm);
start = scm_to_int64 (scm);
/* use_end */
if (scm_is_null (query_term_scm))
break;
scm = SCM_CAR (query_term_scm);
query_term_scm = SCM_CDR (query_term_scm);
use_end = scm_is_true (scm);
/* end */
if (scm_is_null (query_term_scm))
break;
scm = SCM_CAR (query_term_scm);
end = scm_to_int64 (scm);
xaccQueryAddDateMatchTT (q, use_start, start, use_end, end, QOF_QUERY_OR);
ok = TRUE;
}
else if (!g_strcmp0 (pd_type, "pd-amount"))
{
QofQueryCompare how;
QofNumericMatch amt_sgn;
double amount;
gnc_numeric val;
/* how */
if (scm_is_null (query_term_scm))
break;
scm = SCM_CAR (query_term_scm);
query_term_scm = SCM_CDR (query_term_scm);
how = gnc_scm2amt_match_how (scm);
/* amt_sgn */
if (scm_is_null (query_term_scm))
break;
scm = SCM_CAR (query_term_scm);
query_term_scm = SCM_CDR (query_term_scm);
amt_sgn = gnc_query_scm2numericop (scm);
/* amount */
if (scm_is_null (query_term_scm))
break;
scm = SCM_CAR (query_term_scm);
val = gnc_numeric_create (scm_to_int64(scm_numerator(scm)),
scm_to_int64(scm_denominator(scm)));
if (!g_strcmp0 (pr_type, "pr-price"))
{
xaccQueryAddSharePriceMatch (q, val, how, QOF_QUERY_OR);
ok = TRUE;
}
else if (!g_strcmp0 (pr_type, "pr-shares"))
{
xaccQueryAddSharesMatch (q, val, how, QOF_QUERY_OR);
ok = TRUE;
}
else if (!g_strcmp0 (pr_type, "pr-value"))
{
xaccQueryAddValueMatch (q, val, amt_sgn, how, QOF_QUERY_OR);
ok = TRUE;
}
else
{
PINFO ("unknown amount predicate: %s", pr_type);
}
}
else if (!g_strcmp0 (pd_type, "pd-account"))
{
QofGuidMatch how;
GList *account_guids;
/* how */
if (scm_is_null (query_term_scm))
{
PINFO ("pd-account: null how");
break;
}
scm = SCM_CAR (query_term_scm);
query_term_scm = SCM_CDR (query_term_scm);
how = gnc_scm2acct_match_how (scm);
/* account guids */
if (scm_is_null (query_term_scm))
{
PINFO ("pd-account: null guids");
break;
}
scm = SCM_CAR (query_term_scm);
account_guids = gnc_scm2guid_glist (scm);
xaccQueryAddAccountGUIDMatch (q, account_guids, how, QOF_QUERY_OR);
gnc_guid_glist_free (account_guids);
ok = TRUE;
}
else if (!g_strcmp0 (pd_type, "pd-string"))
{
gboolean case_sens;
gboolean use_regexp;
gchar *matchstring;
/* case_sens */
if (scm_is_null (query_term_scm))
break;
scm = SCM_CAR (query_term_scm);
query_term_scm = SCM_CDR (query_term_scm);
case_sens = scm_is_true (scm);
/* use_regexp */
if (scm_is_null (query_term_scm))
break;
scm = SCM_CAR (query_term_scm);
query_term_scm = SCM_CDR (query_term_scm);
use_regexp = scm_is_true (scm);
/* matchstring */
if (scm_is_null (query_term_scm))
break;
scm = SCM_CAR (query_term_scm);
matchstring = gnc_scm_to_utf8_string (scm);
if (!g_strcmp0 (pr_type, "pr-action"))
{
xaccQueryAddActionMatch (q, matchstring, case_sens, use_regexp,
QOF_COMPARE_CONTAINS, QOF_QUERY_OR);
ok = TRUE;
}
else if (!g_strcmp0 (pr_type, "pr-desc"))
{
xaccQueryAddDescriptionMatch (q, matchstring, case_sens,
use_regexp, QOF_COMPARE_CONTAINS, QOF_QUERY_OR);
ok = TRUE;
}
else if (!g_strcmp0 (pr_type, "pr-memo"))
{
xaccQueryAddMemoMatch (q, matchstring, case_sens, use_regexp,
QOF_COMPARE_CONTAINS, QOF_QUERY_OR);
ok = TRUE;
}
else if (!g_strcmp0 (pr_type, "pr-num"))
{
xaccQueryAddNumberMatch (q, matchstring, case_sens, use_regexp,
QOF_COMPARE_CONTAINS, QOF_QUERY_OR);
ok = TRUE;
}
else
{
PINFO ("Unknown string predicate: %s", pr_type);
}
g_free (matchstring);
}
else if (!g_strcmp0 (pd_type, "pd-cleared"))
{
cleared_match_t how;
/* how */
if (scm_is_null (query_term_scm))
break;
scm = SCM_CAR (query_term_scm);
how = gnc_scm2cleared_match_how (scm);
xaccQueryAddClearedMatch (q, how, QOF_QUERY_OR);
ok = TRUE;
}
else if (!g_strcmp0 (pd_type, "pd-balance"))
{
gboolean how;
/* how */
if (scm_is_null (query_term_scm))
break;
scm = SCM_CAR (query_term_scm);
if (gnc_scm2balance_match_how (scm, &how) == FALSE)
break;
xaccQueryAddBalanceMatch (q, static_cast<QofQueryCompare>(how), QOF_QUERY_OR);
ok = TRUE;
}
else if (!g_strcmp0 (pd_type, "pd-guid"))
{
GncGUID guid;
QofIdType id_type;
/* guid */
if (scm_is_null (query_term_scm))
break;