mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
add kvp g-wrap module.
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@5162 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
@@ -11,3 +11,6 @@ gw-glib.h
|
||||
gw-glib.html
|
||||
*.lo
|
||||
*.la
|
||||
gw-kvp.c
|
||||
gw-kvp.h
|
||||
gw-kvp.html
|
||||
|
||||
@@ -64,6 +64,7 @@ noinst_HEADERS = \
|
||||
gnc-pricedb.h \
|
||||
guid.h \
|
||||
kvp_frame.h \
|
||||
kvp-scm.h \
|
||||
md5.h \
|
||||
FreqSpec.h \
|
||||
SchedXaction.h
|
||||
@@ -74,10 +75,13 @@ libgncmod_engine_la_LDFLAGS = -module
|
||||
libgncmod_engine_la_LIBADD = ${GUILE_LIBS} ${GLIB_LIBS}
|
||||
|
||||
libgw_glib_la_SOURCES=gw-glib.c glib-helpers.c
|
||||
libgw_glib_la_LDFLAGS=-module
|
||||
libgw_glib_la_LDFLAGS=-module -lg-wrap-runtime-guile
|
||||
|
||||
libgw_engine_la_SOURCES=gw-engine.c engine-helpers.c
|
||||
libgw_engine_la_LDFLAGS=-module
|
||||
libgw_engine_la_LDFLAGS=-module -lg-wrap-runtime-guile
|
||||
|
||||
libgw_kvp_la_SOURCES=gw-kvp.c kvp-scm.c
|
||||
libgw_kvp_la_LDFLAGS=-module -lg-wrap-runtime-guile
|
||||
|
||||
gncmoddir=${GNC_SHAREDIR}/guile-modules/gnucash
|
||||
gncmod_DATA=engine.scm
|
||||
@@ -87,8 +91,8 @@ gncscm_DATA=commodity-table.scm engine-init.scm engine-interface.scm \
|
||||
engine-utilities.scm gnc-numeric.scm iso-4217-currencies.scm
|
||||
|
||||
gwmoddir=${GNC_SHAREDIR}/guile-modules/g-wrapped
|
||||
gwmod_LTLIBRARIES=libgw-glib.la libgw-engine.la
|
||||
gwmod_DATA=gw-engine-spec.scm gw-glib-spec.scm
|
||||
gwmod_LTLIBRARIES=libgw-glib.la libgw-engine.la libgw-kvp.la
|
||||
gwmod_DATA=gw-engine-spec.scm gw-glib-spec.scm gw-kvp-spec.scm
|
||||
|
||||
EXTRA_DIST = \
|
||||
.cvsignore \
|
||||
@@ -116,5 +120,12 @@ gw-glib.c gw-glib.h: .scm-links gw-glib-spec.scm
|
||||
(primitive-load \"./gw-glib-spec.scm\") \
|
||||
(gw:generate-module \"gw-glib\")"
|
||||
|
||||
BUILT_SOURCES += gw-engine.c gw-engine.h gw-glib.c gw-glib.h
|
||||
CLEANFILES += gw-engine.c gw-engine.h gw-engine.html gw-glib.c gw-glib.h gw-glib.html gnucash g-wrapped .scm-links
|
||||
gw-kvp.c gw-kvp.h: .scm-links gw-kvp-spec.scm
|
||||
FLAVOR=gnome guile -c \
|
||||
"(set! %load-path (cons \"${G_WRAP_MODULE_DIR}\" %load-path)) \
|
||||
(set! %load-path (cons \"${PWD}\" %load-path)) \
|
||||
(primitive-load \"./gw-kvp-spec.scm\") \
|
||||
(gw:generate-module \"gw-kvp\")"
|
||||
|
||||
BUILT_SOURCES += gw-engine.c gw-engine.h gw-glib.c gw-glib.h gw-kvp.c gw-kvp.h
|
||||
CLEANFILES += gw-engine.c gw-engine.h gw-engine.html gw-glib.c gw-glib.h gw-glib.html gnucash g-wrapped .scm-links gw-kvp.c gw-kvp.h
|
||||
|
||||
@@ -275,10 +275,6 @@
|
||||
(gw:wrap-non-native-type mod '<gnc:AccountGroup*>
|
||||
"AccountGroup*" "const AccountGroup*")
|
||||
(gw:wrap-non-native-type mod '<gnc:Book*> "GNCBook*" "const GNCBook*")
|
||||
(gw:wrap-non-native-type mod '<gnc:kvp-frame*>
|
||||
"kvp_frame*" "const kvp_frame*")
|
||||
(gw:wrap-non-native-type mod '<gnc:kvp-value*>
|
||||
"kvp_value*" "const kvp_value*")
|
||||
|
||||
(gw:wrap-non-native-type mod '<gnc:Split*> "Split*" "const Split*")
|
||||
(gw:wrap-non-native-type mod '<gnc:Transaction*>
|
||||
@@ -1631,30 +1627,6 @@ of having a parent transaction with which one is working...")
|
||||
(<gnc:numeric> amount))
|
||||
"Set the share price and amount for split entry")
|
||||
|
||||
(gw:wrap-function
|
||||
mod
|
||||
'gnc:split-get-slots
|
||||
'<gnc:kvp-frame*>
|
||||
"xaccSplitGetSlots"
|
||||
'((<gnc:Split*> s))
|
||||
"Get the split's slots.")
|
||||
|
||||
(gw:wrap-function
|
||||
mod
|
||||
'gnc:transaction-get-slots
|
||||
'<gnc:kvp-frame*>
|
||||
"xaccTransGetSlots"
|
||||
'((<gnc:Transaction*> s))
|
||||
"Get the transaction's slots.")
|
||||
|
||||
(gw:wrap-function
|
||||
mod
|
||||
'gnc:account-get-slots
|
||||
'<gnc:kvp-frame*>
|
||||
"xaccAccountGetSlots"
|
||||
'((<gnc:Account*> s))
|
||||
"Get the account's slots.")
|
||||
|
||||
(gw:wrap-function
|
||||
mod
|
||||
'gnc:malloc-query
|
||||
|
||||
117
src/engine/gw-kvp-spec.scm
Normal file
117
src/engine/gw-kvp-spec.scm
Normal file
@@ -0,0 +1,117 @@
|
||||
(define-module (g-wrapped gw-kvp-spec)
|
||||
:use-module (g-wrap)
|
||||
:use-module (g-wrapped gw-glib-spec)
|
||||
:use-module (g-wrapped gw-engine-spec))
|
||||
|
||||
(let ((mod (gw:new-module "gw-kvp")))
|
||||
|
||||
(define (standard-c-call-gen result func-call-code)
|
||||
(list (gw:result-get-c-name result) " = " func-call-code ";\n"))
|
||||
|
||||
(define (add-standard-result-handlers! type c->scm-converter)
|
||||
(define (standard-pre-handler result)
|
||||
(let* ((ret-type-name (gw:result-get-proper-c-type-name result))
|
||||
(ret-var-name (gw:result-get-c-name result)))
|
||||
(list "{\n"
|
||||
" " ret-type-name " " ret-var-name ";\n")))
|
||||
|
||||
(gw:type-set-pre-call-result-ccodegen! type standard-pre-handler)
|
||||
|
||||
(gw:type-set-post-call-result-ccodegen!
|
||||
type
|
||||
(lambda (result)
|
||||
(let* ((scm-name (gw:result-get-scm-name result))
|
||||
(c-name (gw:result-get-c-name result)))
|
||||
(list
|
||||
(c->scm-converter scm-name c-name)
|
||||
" }\n")))))
|
||||
|
||||
(gw:module-depends-on mod "gw-runtime")
|
||||
(gw:module-depends-on mod "gw-glib")
|
||||
(gw:module-depends-on mod "gw-engine")
|
||||
(gw:module-set-guile-module! mod '(g-wrapped gw-kvp))
|
||||
|
||||
(gw:module-set-declarations-ccodegen!
|
||||
mod
|
||||
(lambda (client-only?)
|
||||
(list
|
||||
"#include <kvp_frame.h>\n"
|
||||
"#include <kvp-scm.h>\n"
|
||||
"#include <Transaction.h>\n")))
|
||||
;; (gw:module-set-init-ccodegen!
|
||||
;; mod
|
||||
;; (lambda (client-only?)
|
||||
;; (if client-only?
|
||||
;; '()
|
||||
;; (gw:inline-scheme '(use-modules (gnucash kvp))))))
|
||||
|
||||
|
||||
(gw:wrap-non-native-type mod '<gnc:kvp-frame*>
|
||||
"kvp_frame*" "const kvp_frame*")
|
||||
|
||||
(let ((wt (gw:wrap-type mod '<gnc:kvp-value*>
|
||||
"kvp_value*" "const kvp_value*")))
|
||||
|
||||
(gw:type-set-scm-arg-type-test-ccodegen!
|
||||
wt
|
||||
(lambda (param)
|
||||
(list "gnc_kvp_value_ptr_p(" (gw:param-get-scm-name param) ")")))
|
||||
|
||||
(gw:type-set-pre-call-arg-ccodegen!
|
||||
wt
|
||||
(lambda (param)
|
||||
(list (gw:param-get-c-name param) " = "
|
||||
(list "gnc_scm_to_kvp_value_ptr("
|
||||
(gw:param-get-scm-name param) ")")
|
||||
";\n")))
|
||||
|
||||
(gw:type-set-call-ccodegen! wt standard-c-call-gen)
|
||||
|
||||
(add-standard-result-handlers!
|
||||
wt
|
||||
(lambda (scm-name c-name)
|
||||
(let ((old-func (lambda (x) (list "gnc_kvp_value_ptr_to_scm(" x ")"))))
|
||||
(list scm-name " = " (old-func c-name) ";\n")))))
|
||||
|
||||
;; (gw:wrap-function
|
||||
;; mod
|
||||
;; 'gnc:split-get-slots
|
||||
;; '<gnc:kvp-frame*>
|
||||
;; "xaccSplitGetSlots"
|
||||
;; '((<gnc:Split*> s))
|
||||
;; "Get the split's slots.")
|
||||
|
||||
|
||||
(gw:wrap-function
|
||||
mod
|
||||
'gnc:transaction-get-slots
|
||||
'<gnc:kvp-frame*>
|
||||
"xaccTransGetSlots"
|
||||
'((<gnc:Transaction*> s))
|
||||
"Get the transaction's slots.")
|
||||
|
||||
(gw:wrap-function
|
||||
mod
|
||||
'gnc:kvp-frame-set-slot
|
||||
'<gw:void>
|
||||
"kvp_frame_set_slot"
|
||||
'((<gnc:kvp-frame*> k) ((<gw:m-chars-caller-owned> gw:const) c)
|
||||
(<gnc:kvp-value*> v))
|
||||
"Sets the slot c in frame k to the value v")
|
||||
|
||||
(gw:wrap-function
|
||||
mod
|
||||
'gnc:kvp-frame-get-slot
|
||||
'<gnc:kvp-value*>
|
||||
"kvp_frame_get_slot"
|
||||
'((<gnc:kvp-frame*> k) ((<gw:m-chars-caller-owned> gw:const) c))
|
||||
"Gets the slot c from frame k")
|
||||
|
||||
;; (gw:wrap-function
|
||||
;; mod
|
||||
;; 'gnc:account-get-slots
|
||||
;; '<gnc:kvp-frame*>
|
||||
;; "xaccAccountGetSlots"
|
||||
;; '((<gnc:Account*> s))
|
||||
;; "Get the account's slots.")
|
||||
)
|
||||
94
src/engine/kvp-scm.c
Normal file
94
src/engine/kvp-scm.c
Normal file
@@ -0,0 +1,94 @@
|
||||
#include <kvp_frame.h>
|
||||
#include <g-wrap-runtime-guile.h>
|
||||
#include <libguile.h>
|
||||
#include <engine-helpers.h>
|
||||
|
||||
int
|
||||
gnc_kvp_value_ptr_p(SCM arg)
|
||||
{
|
||||
return TRUE;
|
||||
/* static SCM type_p = SCM_BOOL_F; */
|
||||
|
||||
/* if(type_p == SCM_BOOL_F) */
|
||||
/* { */
|
||||
/* type_p = gh_eval_str("gnc:gnc-kvp-value-ptr?"); */
|
||||
/* } */
|
||||
/* if(gh_call1(type_p, arg) == SCM_BOOL_F) */
|
||||
/* { */
|
||||
/* return FALSE; */
|
||||
/* } */
|
||||
/* else */
|
||||
/* { */
|
||||
/* return TRUE; */
|
||||
/* } */
|
||||
}
|
||||
|
||||
kvp_value*
|
||||
gnc_scm_to_kvp_value_ptr(SCM val)
|
||||
{
|
||||
if(gnc_gh_gint64_p(val))
|
||||
{
|
||||
return kvp_value_new_gint64(gnc_scm_to_gint64(val));
|
||||
}
|
||||
else if(gh_number_p(val))
|
||||
{
|
||||
return kvp_value_new_double(gh_scm2double(val));
|
||||
}
|
||||
else if(gnc_numeric_p(val))
|
||||
{
|
||||
return kvp_value_new_gnc_numeric(gnc_scm_to_numeric(val));
|
||||
}
|
||||
else if(gnc_guid_p(val))
|
||||
{
|
||||
GUID tmpguid = gnc_scm2guid(val);
|
||||
return kvp_value_new_guid(&tmpguid);
|
||||
}
|
||||
else if(gh_string_p(val))
|
||||
{
|
||||
char *newstr;
|
||||
kvp_value *ret;
|
||||
newstr = gh_scm2newstr(val, NULL);
|
||||
ret = kvp_value_new_string(newstr);
|
||||
g_free(newstr);
|
||||
return ret;
|
||||
}
|
||||
/* FIXME: add binary handler here when it's figured out */
|
||||
else if(gh_list_p(val))
|
||||
{
|
||||
}
|
||||
/* FIXME: add frame handler here when it's figured out */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SCM
|
||||
gnc_kvp_value_ptr_to_scm(kvp_value* val)
|
||||
{
|
||||
switch(kvp_value_get_type(val))
|
||||
{
|
||||
case KVP_TYPE_GINT64:
|
||||
return gnc_gint64_to_scm(kvp_value_get_gint64(val));
|
||||
break;
|
||||
case KVP_TYPE_DOUBLE:
|
||||
return gh_double2scm(kvp_value_get_double(val));
|
||||
break;
|
||||
case KVP_TYPE_NUMERIC:
|
||||
return gnc_numeric_to_scm(kvp_value_get_numeric(val));
|
||||
break;
|
||||
case KVP_TYPE_STRING:
|
||||
return gh_str02scm(kvp_value_get_string(val));
|
||||
break;
|
||||
case KVP_TYPE_GUID:
|
||||
{
|
||||
GUID *tempguid = kvp_value_get_guid(val);
|
||||
return gnc_guid2scm(*tempguid);
|
||||
}
|
||||
break;
|
||||
case KVP_TYPE_BINARY:
|
||||
break;
|
||||
case KVP_TYPE_GLIST:
|
||||
break;
|
||||
case KVP_TYPE_FRAME:
|
||||
break;
|
||||
}
|
||||
return SCM_BOOL_F;
|
||||
}
|
||||
12
src/engine/kvp-scm.h
Normal file
12
src/engine/kvp-scm.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#ifndef KVP_SCM_H
|
||||
#define KVP_SCM_H
|
||||
|
||||
#include <kvp_frame.h>
|
||||
#include <libguile.h>
|
||||
|
||||
int gnc_kvp_value_ptr_p(SCM arg);
|
||||
kvp_value* gnc_scm_to_kvp_value_ptr(SCM kvpval);
|
||||
SCM gnc_kvp_value_ptr_to_scm(kvp_value* val);
|
||||
|
||||
#endif /* KVP_SCM_H */
|
||||
|
||||
Reference in New Issue
Block a user