24 #include <glib/gi18n.h>
26 #include "swig-runtime.h"
36 # include "strptime.h"
40 #include "engine-helpers-guile.h"
41 #include "glib-helpers.h"
43 #include "gnc-guile-utils.h"
45 #include "guile-util.h"
46 #include "guile-mappings.h"
54 SCM split_scm_account_guid;
57 SCM split_scm_reconcile_state;
63 SCM trans_scm_description;
65 SCM trans_scm_append_split_scm;
75 SCM trans_scm_split_scms;
76 SCM trans_scm_split_scm;
77 SCM trans_scm_other_split_scm;
101 initialize_scm_functions()
103 static gboolean scm_funcs_inited = FALSE;
105 if (scm_funcs_inited)
108 setters.split_scm_account_guid =
109 scm_c_eval_string(
"gnc:split-scm-set-account-guid");
110 setters.split_scm_memo = scm_c_eval_string(
"gnc:split-scm-set-memo");
111 setters.split_scm_action = scm_c_eval_string(
"gnc:split-scm-set-action");
112 setters.split_scm_reconcile_state =
113 scm_c_eval_string(
"gnc:split-scm-set-reconcile-state");
114 setters.split_scm_amount = scm_c_eval_string(
"gnc:split-scm-set-amount");
115 setters.split_scm_value = scm_c_eval_string(
"gnc:split-scm-set-value");
117 setters.trans_scm_date = scm_c_eval_string(
"gnc:transaction-scm-set-date-posted");
118 setters.trans_scm_num = scm_c_eval_string(
"gnc:transaction-scm-set-num");
119 setters.trans_scm_description =
120 scm_c_eval_string(
"gnc:transaction-scm-set-description");
121 setters.trans_scm_notes = scm_c_eval_string(
"gnc:transaction-scm-set-notes");
122 setters.trans_scm_append_split_scm =
123 scm_c_eval_string(
"gnc:transaction-scm-append-split-scm");
125 getters.split_scm_memo = scm_c_eval_string(
"gnc:split-scm-get-memo");
126 getters.split_scm_action = scm_c_eval_string(
"gnc:split-scm-get-action");
127 getters.split_scm_amount = scm_c_eval_string(
"gnc:split-scm-get-amount");
128 getters.split_scm_value = scm_c_eval_string(
"gnc:split-scm-get-value");
130 getters.trans_scm_split_scms =
131 scm_c_eval_string(
"gnc:transaction-scm-get-split-scms");
132 getters.trans_scm_split_scm =
133 scm_c_eval_string(
"gnc:transaction-scm-get-split-scm");
134 getters.trans_scm_other_split_scm =
135 scm_c_eval_string(
"gnc:transaction-scm-get-other-split-scm");
137 getters.debit_string = scm_c_eval_string(
"gnc:get-debit-string");
138 getters.credit_string = scm_c_eval_string(
"gnc:get-credit-string");
140 predicates.is_split_scm = scm_c_eval_string(
"gnc:split-scm?");
141 predicates.is_trans_scm = scm_c_eval_string(
"gnc:transaction-scm?");
143 scm_funcs_inited = TRUE;
167 ************ NOT TESTED YET **************
170 gnc_scm_lookup(
const char *module,
const char *symbol)
172 SCM scm_module = scm_c_resolve_module(module);
173 SCM value = scm_c_module_lookup(scm_module, symbol);
189 gnc_copy_split(
Split *split, gboolean use_cut_semantics)
191 static swig_type_info *split_type = NULL;
196 return SCM_UNDEFINED;
198 func = scm_c_eval_string(
"gnc:split->split-scm");
199 if (!scm_is_procedure(func))
200 return SCM_UNDEFINED;
203 split_type = SWIG_TypeQuery(
"_p_Split");
205 arg = SWIG_NewPointerObj(split, split_type, 0);
207 return scm_call_2(func, arg, SCM_BOOL(use_cut_semantics));
220 gnc_copy_split_scm_onto_split(SCM split_scm,
Split *split,
223 static swig_type_info *split_type = NULL;
228 if (split_scm == SCM_UNDEFINED)
234 g_return_if_fail (book);
236 func = scm_c_eval_string(
"gnc:split-scm?");
237 if (!scm_is_procedure(func))
240 result = scm_call_1(func, split_scm);
241 if (!scm_is_true(result))
244 func = scm_c_eval_string(
"gnc:split-scm-onto-split");
245 if (!scm_is_procedure(func))
249 split_type = SWIG_TypeQuery(
"_p_Split");
251 arg = SWIG_NewPointerObj(split, split_type, 0);
253 scm_call_3(func, split_scm, arg, gnc_book_to_scm (book));
265 gnc_is_split_scm(SCM scm)
267 initialize_scm_functions();
269 return scm_is_true(scm_call_1(predicates.is_split_scm, scm));
281 gnc_is_trans_scm(SCM scm)
283 initialize_scm_functions();
285 return scm_is_true(scm_call_1(predicates.is_trans_scm, scm));
298 gnc_split_scm_set_account(SCM split_scm,
Account *account)
303 initialize_scm_functions();
305 if (!gnc_is_split_scm(split_scm))
311 if (strlen(guid_string) == 0)
314 arg = scm_from_utf8_string(guid_string);
316 scm_call_2(setters.split_scm_account_guid, split_scm, arg);
329 gnc_split_scm_set_memo(SCM split_scm,
const char *memo)
333 initialize_scm_functions();
335 if (!gnc_is_split_scm(split_scm))
340 arg = scm_from_utf8_string(memo);
342 scm_call_2(setters.split_scm_memo, split_scm, arg);
355 gnc_split_scm_set_action(SCM split_scm,
const char *action)
359 initialize_scm_functions();
361 if (!gnc_is_split_scm(split_scm))
366 arg = scm_from_utf8_string(action);
368 scm_call_2(setters.split_scm_action, split_scm, arg);
381 gnc_split_scm_set_reconcile_state(SCM split_scm,
char reconcile_state)
385 initialize_scm_functions();
387 if (!gnc_is_split_scm(split_scm))
390 arg = SCM_MAKE_CHAR(reconcile_state);
392 scm_call_2(setters.split_scm_reconcile_state, split_scm, arg);
405 gnc_split_scm_set_amount(SCM split_scm,
gnc_numeric amount)
409 initialize_scm_functions();
411 if (!gnc_is_split_scm(split_scm))
414 arg = gnc_numeric_to_scm(amount);
415 scm_call_2(setters.split_scm_amount, split_scm, arg);
428 gnc_split_scm_set_value(SCM split_scm,
gnc_numeric value)
432 initialize_scm_functions();
434 if (!gnc_is_split_scm(split_scm))
437 arg = gnc_numeric_to_scm(value);
438 scm_call_2(setters.split_scm_value, split_scm, arg);
450 gnc_split_scm_get_memo(SCM split_scm)
454 initialize_scm_functions();
456 if (!gnc_is_split_scm(split_scm))
459 result = scm_call_1(getters.split_scm_memo, split_scm);
460 if (!scm_is_string(result))
463 return gnc_scm_to_utf8_string(result);
475 gnc_split_scm_get_action(SCM split_scm)
479 initialize_scm_functions();
481 if (!gnc_is_split_scm(split_scm))
484 result = scm_call_1(getters.split_scm_action, split_scm);
485 if (!scm_is_string(result))
488 return gnc_scm_to_utf8_string(result);
500 gnc_split_scm_get_amount(SCM split_scm)
504 initialize_scm_functions();
506 if (!gnc_is_split_scm(split_scm))
507 return gnc_numeric_zero ();
509 result = scm_call_1(getters.split_scm_amount, split_scm);
510 if (!gnc_numeric_p(result))
511 return gnc_numeric_zero ();
513 return gnc_scm_to_numeric(result);
525 gnc_split_scm_get_value(SCM split_scm)
529 initialize_scm_functions();
531 if (!gnc_is_split_scm(split_scm))
532 return gnc_numeric_zero ();
534 result = scm_call_1(getters.split_scm_value, split_scm);
535 if (!gnc_numeric_p(result))
536 return gnc_numeric_zero ();
538 return gnc_scm_to_numeric(result);
552 gnc_copy_trans(
Transaction *trans, gboolean use_cut_semantics)
554 static swig_type_info *trans_type = NULL;
559 return SCM_UNDEFINED;
561 func = scm_c_eval_string(
"gnc:transaction->transaction-scm");
562 if (!scm_is_procedure(func))
563 return SCM_UNDEFINED;
566 trans_type = SWIG_TypeQuery(
"_p_Transaction");
568 arg = SWIG_NewPointerObj(trans, trans_type, 0);
570 return scm_call_2(func, arg, SCM_BOOL(use_cut_semantics));
584 gnc_copy_trans_scm_onto_trans(SCM trans_scm,
Transaction *trans,
585 gboolean do_commit,
QofBook *book)
587 gnc_copy_trans_scm_onto_trans_swap_accounts(trans_scm, trans, NULL, NULL,
606 gnc_copy_trans_scm_onto_trans_swap_accounts(SCM trans_scm,
613 static swig_type_info *trans_type = NULL;
618 if (trans_scm == SCM_UNDEFINED)
624 g_return_if_fail (book);
626 func = scm_c_eval_string(
"gnc:transaction-scm?");
627 if (!scm_is_procedure(func))
630 result = scm_call_1(func, trans_scm);
631 if (!scm_is_true(result))
634 func = scm_c_eval_string(
"gnc:transaction-scm-onto-transaction");
635 if (!scm_is_procedure(func))
639 trans_type = SWIG_TypeQuery(
"_p_Transaction");
641 arg = SWIG_NewPointerObj(trans, trans_type, 0);
643 if ((guid_1 == NULL) || (guid_2 == NULL))
648 commit = SCM_BOOL(do_commit);
650 args = scm_cons(gnc_book_to_scm (book), args);
651 args = scm_cons(commit, args);
652 args = scm_cons(SCM_EOL, args);
653 args = scm_cons(arg, args);
654 args = scm_cons(trans_scm, args);
656 scm_apply(func, args, SCM_EOL);
666 args = scm_cons(gnc_book_to_scm (book), args);
668 commit = SCM_BOOL(do_commit);
670 args = scm_cons(commit, args);
673 from = scm_from_utf8_string(guidstr);
675 to = scm_from_utf8_string(guidstr);
677 map = scm_cons(scm_cons(from, to), map);
678 map = scm_cons(scm_cons(to, from), map);
680 args = scm_cons(map, args);
681 args = scm_cons(arg, args);
682 args = scm_cons(trans_scm, args);
684 scm_apply(func, args, SCM_EOL);
697 gnc_trans_scm_set_date(SCM trans_scm,
Timespec *ts)
701 initialize_scm_functions();
703 if (!gnc_is_trans_scm(trans_scm))
708 arg = gnc_timespec2timepair(*ts);
710 scm_call_2(setters.trans_scm_date, trans_scm, arg);
723 gnc_trans_scm_set_num(SCM trans_scm,
const char *num)
727 initialize_scm_functions();
729 if (!gnc_is_trans_scm(trans_scm))
734 arg = scm_from_utf8_string(num);
736 scm_call_2(setters.trans_scm_num, trans_scm, arg);
749 gnc_trans_scm_set_description(SCM trans_scm,
const char *description)
753 initialize_scm_functions();
755 if (!gnc_is_trans_scm(trans_scm))
757 if (description == NULL)
760 arg = scm_from_utf8_string(description);
762 scm_call_2(setters.trans_scm_description, trans_scm, arg);
775 gnc_trans_scm_set_notes(SCM trans_scm,
const char *notes)
779 initialize_scm_functions();
781 if (!gnc_is_trans_scm(trans_scm))
786 arg = scm_from_utf8_string(notes);
788 scm_call_2(setters.trans_scm_notes, trans_scm, arg);
801 gnc_trans_scm_append_split_scm(SCM trans_scm, SCM split_scm)
803 initialize_scm_functions();
805 if (!gnc_is_trans_scm(trans_scm))
807 if (!gnc_is_split_scm(split_scm))
810 scm_call_2(setters.trans_scm_append_split_scm, trans_scm, split_scm);
823 gnc_trans_scm_get_split_scm(SCM trans_scm,
int index)
827 initialize_scm_functions();
829 if (!gnc_is_trans_scm(trans_scm))
830 return SCM_UNDEFINED;
832 arg = scm_from_int (index);
834 return scm_call_2(getters.trans_scm_split_scm, trans_scm, arg);
847 gnc_trans_scm_get_other_split_scm(SCM trans_scm, SCM split_scm)
851 initialize_scm_functions();
853 if (!gnc_is_trans_scm(trans_scm))
854 return SCM_UNDEFINED;
855 if (!gnc_is_split_scm(split_scm))
856 return SCM_UNDEFINED;
858 result = scm_call_2(getters.trans_scm_other_split_scm, trans_scm, split_scm);
860 if (!gnc_is_split_scm(result))
861 return SCM_UNDEFINED;
875 gnc_trans_scm_get_num_splits(SCM trans_scm)
879 initialize_scm_functions();
881 if (!gnc_is_trans_scm(trans_scm))
884 result = scm_call_1(getters.trans_scm_split_scms, trans_scm);
886 if (!scm_is_list(result))
889 return scm_to_int(scm_length(result));
906 initialize_scm_functions();
909 return g_strdup(_(
"Debit"));
914 arg = scm_from_long (account_type);
916 result = scm_call_1(getters.debit_string, arg);
917 if (!scm_is_string(result))
920 return scm_to_utf8_string(result);
937 initialize_scm_functions();
940 return g_strdup(_(
"Credit"));
945 arg = scm_from_long (account_type);
947 result = scm_call_1(getters.credit_string, arg);
948 if (!scm_is_string(result))
951 return gnc_scm_to_utf8_string(result);
956 on_child_exit (GPid pid, gint status, gpointer data)
959 g_return_if_fail (proc && proc->pid == pid);
961 g_spawn_close_pid (proc->pid);
971 gnc_spawn_process_async (GList *argl,
const gboolean search_path)
977 gchar **argv, **v_iter;
979 GError *error = NULL;
983 argc = g_list_length (argl);
984 argv = g_malloc ((argc + 1) *
sizeof(gchar*));
986 for (l_iter = argl, v_iter = argv; l_iter; l_iter = l_iter->next, v_iter++)
988 *v_iter = (gchar*) l_iter->data;
993 flags = G_SPAWN_DO_NOT_REAP_CHILD;
995 flags |= G_SPAWN_SEARCH_PATH;
997 retval = g_spawn_async_with_pipes (
998 NULL, argv, NULL, flags, NULL, NULL, &proc->pid,
999 &proc->fd_stdin, &proc->fd_stdout, &proc->fd_stderr, &error);
1003 g_child_watch_add (proc->pid, on_child_exit, proc);
1007 g_warning (
"Could not spawn %s: %s", *argv ? *argv :
"(null)",
1008 error->message ? error->message :
"(null)");
1018 gnc_process_get_fd (
const Process *proc,
const gint std_fd)
1020 const gint *retptr = NULL;
1021 g_return_val_if_fail (proc, -1);
1024 retptr = &proc->fd_stdin;
1025 else if (std_fd == 1)
1026 retptr = &proc->fd_stdout;
1027 else if (std_fd == 2)
1028 retptr = &proc->fd_stderr;
1030 g_return_val_if_reached (-1);
1033 g_warning (
"Pipe to childs file descriptor %d is -1", std_fd);
1038 gnc_detach_process (
Process *proc,
const gboolean kill_it)
1040 g_return_if_fail (proc && proc->pid);
1043 close (proc->fd_stdin);
1046 g_message (
"Close of childs stdin (%d) failed: %s", proc->fd_stdin,
1047 g_strerror (errno));
1050 close (proc->fd_stdout);
1053 g_message (
"Close of childs stdout (%d) failed: %s", proc->fd_stdout,
1057 close (proc->fd_stderr);
1060 g_message (
"Close of childs stderr (%d) failed: %s", proc->fd_stderr,
1065 if (kill_it && !proc->dead)
1068 while (g_main_context_iteration (NULL, FALSE) && !proc->dead)
1076 proc->detached = TRUE;
1083 gnc_parse_time_to_time64 (
const gchar *s,
const gchar *format)
1087 g_return_val_if_fail(s && format, -1);
1089 if (!strptime(s, format, &tm))
Use a 64-bit unsigned int timespec.
gchar * guid_to_string_buff(const GncGUID *guid, gchar *buff)
#define xaccAccountGetGUID(X)
#define GUID_ENCODING_LENGTH
time64 gnc_mktime(struct tm *time)
calculate seconds from the epoch given a time struct
Generic api to store and retrieve preferences.
void gnc_gpid_kill(GPid pid)
gboolean gnc_prefs_get_bool(const gchar *group, const gchar *pref_name)
const gchar * QofLogModule