diff --git a/gnucash/gnome-utils/CMakeLists.txt b/gnucash/gnome-utils/CMakeLists.txt index ca95d104e6..a2bc8adb47 100644 --- a/gnucash/gnome-utils/CMakeLists.txt +++ b/gnucash/gnome-utils/CMakeLists.txt @@ -206,6 +206,7 @@ add_library (gnc-gnome-utils target_link_libraries(gnc-gnome-utils gnc-app-utils gnc-engine + gnc-expressions gnc-backend-xml-utils gnucash-guile PkgConfig::GTK3 diff --git a/gnucash/gnome/CMakeLists.txt b/gnucash/gnome/CMakeLists.txt index 2aafc05305..825f558278 100644 --- a/gnucash/gnome/CMakeLists.txt +++ b/gnucash/gnome/CMakeLists.txt @@ -134,6 +134,7 @@ target_link_libraries(gnc-gnome gnc-register-core gnc-gnome-utils gnc-engine + gnc-expressions gnc-html gnc-locale-tax gnucash-guile diff --git a/gnucash/report/CMakeLists.txt b/gnucash/report/CMakeLists.txt index afb1a40cc1..5bf93fd358 100644 --- a/gnucash/report/CMakeLists.txt +++ b/gnucash/report/CMakeLists.txt @@ -28,6 +28,7 @@ target_compile_definitions(gnc-report PRIVATE -DG_LOG_DOMAIN=\"gnc.report.core\" target_link_libraries(gnc-report gnc-app-utils gnucash-guile + gnc-expressions-guile PkgConfig::GTK3 ${GUILE_LDFLAGS}) diff --git a/gnucash/report/report-core.scm b/gnucash/report/report-core.scm index 036ffe0d81..26573c0ca9 100644 --- a/gnucash/report/report-core.scm +++ b/gnucash/report/report-core.scm @@ -22,7 +22,8 @@ (define-module (gnucash report report-core)) (eval-when (compile load eval expand) - (load-extension "libgnc-report" "scm_init_sw_report_module")) + (load-extension "libgnc-report" "scm_init_sw_report_module") + (load-extension "libgnc-expressions-guile" "scm_init_sw_expressions_module")) (use-modules (gnucash engine)) (use-modules (gnucash utilities)) diff --git a/gnucash/report/reports/standard/account-summary.scm b/gnucash/report/reports/standard/account-summary.scm index 3b966e8645..14a9347acb 100644 --- a/gnucash/report/reports/standard/account-summary.scm +++ b/gnucash/report/reports/standard/account-summary.scm @@ -61,7 +61,7 @@ (use-modules (gnucash core-utils)) (use-modules (gnucash app-utils)) (use-modules (gnucash report)) - +(use-modules (sw_expressions)) ;; account summary report prints a table of account information, ;; optionally with clickable links to open the corresponding register ;; window. diff --git a/libgnucash/app-utils/CMakeLists.txt b/libgnucash/app-utils/CMakeLists.txt index a9cf47e7cd..338fd83622 100644 --- a/libgnucash/app-utils/CMakeLists.txt +++ b/libgnucash/app-utils/CMakeLists.txt @@ -7,10 +7,6 @@ include (GncFindLibm) # Build the library set (app_utils_noinst_HEADERS - calculation/finvar.h - calculation/finproto.h - calculation/fin_spl_protos.h - calculation/fin_static_proto.h gnc-option-date.hpp gnc-option-impl.hpp gnc-option-ui.hpp @@ -28,7 +24,6 @@ set (app_utils_HEADERS gnc-addr-quickfill.h gnc-entry-quickfill.h gnc-euro.h - gnc-exp-parser.h gnc-gsettings.h gnc-help-utils.h gnc-helpers.h @@ -37,7 +32,6 @@ set (app_utils_HEADERS gnc-optiondb.hpp gnc-prefs-utils.h gnc-state.h - gnc-sx-instance-model.h gnc-ui-util.h gnc-ui-balances.h ) @@ -60,8 +54,6 @@ gnc_add_swig_python_command (swig-app-utils-python ) set (app_utils_SOURCES - calculation/expression_parser.c - calculation/fin.c QuickFill.c file-utils.c gfec.c @@ -70,7 +62,6 @@ set (app_utils_SOURCES gnc-addr-quickfill.c gnc-entry-quickfill.c gnc-euro.c - gnc-exp-parser.c gnc-gsettings.cpp gnc-helpers.c gnc-option-date.cpp @@ -78,7 +69,6 @@ set (app_utils_SOURCES gnc-option-impl.cpp gnc-optiondb.cpp gnc-prefs-utils.c - gnc-sx-instance-model.c gnc-state.c gnc-ui-util.c gnc-ui-balances.c @@ -175,16 +165,95 @@ if (WITH_PYTHON) endif() +set(expressions_SOURCES + calculation/expression_parser.c + calculation/fin.c + gnc-exp-parser.c + gnc-sx-instance-model.c + ) +set(expressions_noinstall_HEADERS + calculation/finvar.h + calculation/finproto.h + calculation/fin_spl_protos.h + calculation/fin_static_proto.h + ) +set(expressions_HEADERS + gnc-exp-parser.h + gnc-sx-instance-model.h + ) -install(FILES ${app_utils_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/gnucash) +set(expressions_all_sources ${expressions_SOURCES} ${expressions_noinstall_HEADERS} ${expressions_HEADERS}) + +set_source_files_properties(${expressions_SOURCES} PROPERTIES OBJECT_DEPENDS ${CONFIG_H}) +add_library(gnc-expressions + ${expressions_HEADERS} + ${expressions_SOURCES} + ) + +target_include_directories(gnc-expressions + PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/calculation + ${CMAKE_SOURCE_DIR}/bindings/guile + ${CMAKE_SOURCE_DIR}/libgnucash/app-utils + ${GUILE_INCLUDE_DIRS} + ${GLIB2_INCLUDE_DIRS} + PRIVATE + ${CMAKE_SOURCE_DIR}/common + ${CMAKE_BINARY_DIR}/common) + +target_link_libraries(gnc-expressions + PUBLIC + gnc-engine + gnucash-guile + gnc-app-utils + ${GUILE_LDFLAGS} + ${GLIB2_LDFLAGS}) + +install(TARGETS gnc-expressions + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + ) + +#Generate the swig-expressions-guile.c wrapper file +gnc_add_swig_guile_command(swig-expressions-guile-c #target + SWIG_EXPRESSIONS_GUILE_C swig-expressions-guile.c #outvar, output + ${CMAKE_CURRENT_SOURCE_DIR}/expressions.i #input + "${CMAKE_CURRENT_SOURCE_DIR};${CMAKE_SOURCE_DIR}/libgnucash/app-utils;${CMAKE_SOURCE_DIR}/libgnucash/expressions" #includes + ) + +add_library(gnc-expressions-guile SHARED + ${SWIG_EXPRESSIONS_GUILE_C}) + +target_include_directories(gnc-expressions-guile + PUBLIC + ${CMAKE_SOURCE_DIR}/libgnucash/expressions + ${GUILE_INCLUDE_DIRS} + ${GLIB2_INCLUDE_DIRS}) + +target_link_libraries(gnc-expressions-guile + gnc-expressions + gnc-engine + gnc-app-utils + ${GUILE_LDFLAGS} + ${GLIB2_LDFLAGS}) + +install(TARGETS gnc-expressions-guile + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + ) + +install(FILES ${app_utils_HEADERS} ${expressions_HEADERS} + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/gnucash) # And now handle scheme files set (app_utils_SCHEME_1 c-interface.scm date-utilities.scm - fin.scm ) set (app_utils_SCHEME_1a @@ -220,6 +289,18 @@ gnc_add_scheme_targets(scm-app-utils-2 add_custom_target(scm-app-utils ALL DEPENDS scm-app-utils-2 scm-app-utils-1) +set(expressions_SCHEME + fin.scm) + +set(GUILE_INTERNAL_DEPENDS + scm-app-utils-1) + +gnc_add_scheme_targets(scm-expressions + SOURCES "${expressions_SCHEME}" + OUTPUT_DIR "gnucash/app-utils" + DEPENDS "${GUILE_INTERNAL_DEPENDS}" + MAKE_LINKS) + set_local_dist(app_utils_DIST_local ${app_utils_ALL_SOURCES} ${app_utils_SCHEME_1} @@ -228,7 +309,9 @@ set_local_dist(app_utils_DIST_local ${app_utils_SCHEME_1c} ${app_utils_SCHEME_2} ${app_utils_SCHEME_3} - app-utils.i gnc-optiondb.i CMakeLists.txt gnc-help-utils.c) + ${expressions_all_sources} + ${expressions_SCHEME} + app-utils.i gnc-optiondb.i expressions.i CMakeLists.txt gnc-help-utils.c) set(app_utils_DIST ${app_utils_DIST_local} diff --git a/libgnucash/app-utils/app-utils.i b/libgnucash/app-utils/app-utils.i index 6b77ffa4fd..6e1430bc66 100644 --- a/libgnucash/app-utils/app-utils.i +++ b/libgnucash/app-utils/app-utils.i @@ -28,13 +28,11 @@ extern "C" #endif #include #include -#include #include #include #include #include #include -#include #include "gnc-engine-guile.h" #ifdef __cplusplus @@ -119,23 +117,4 @@ gnc_numeric gnc_convert_from_euro(const gnc_commodity * currency, time64 gnc_accounting_period_fiscal_start(void); time64 gnc_accounting_period_fiscal_end(void); -%typemap(out) GHashTable * { - SCM table = scm_c_make_hash_table (g_hash_table_size($1) + 17); - GHashTableIter iter; - gpointer key, value; - - g_hash_table_iter_init (&iter, $1); - while (g_hash_table_iter_next (&iter, &key, &value)) { - const GncGUID* c_guid = (const GncGUID*) key; - const gnc_numeric* c_numeric = (const gnc_numeric*) value; - SCM scm_guid = gnc_guid2scm(*c_guid); - SCM scm_numeric = gnc_numeric_to_scm(*c_numeric); - - scm_hash_set_x(table, scm_guid, scm_numeric); - } - g_hash_table_destroy($1); - $result = table; -} -GHashTable* gnc_sx_all_instantiate_cashflow_all(GDate range_start, GDate range_end); -%clear GHashTable *; #endif diff --git a/libgnucash/app-utils/expressions.i b/libgnucash/app-utils/expressions.i new file mode 100644 index 0000000000..18aafbf6a5 --- /dev/null +++ b/libgnucash/app-utils/expressions.i @@ -0,0 +1,74 @@ +/********************************************************************\ + * 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 * + * * +\********************************************************************/ + +%module sw_expressions +%{ +#include + +SCM scm_init_sw_expressions_module (void); + +static GDate +gnc_time64_to_GDate(SCM x) +{ + time64 time = scm_to_int64 (x); + return time64_to_gdate(time); +} + + +static 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); +} + +static SCM +gnc_numeric_to_scm(gnc_numeric arg) +{ + return gnc_numeric_check (arg) ? SCM_BOOL_F : + scm_divide (scm_from_int64 (arg.num), scm_from_int64 (arg.denom)); +} +%} +#include +%import "base-typemaps.i" + +%typemap(out) GHashTable * { +SCM table = scm_c_make_hash_table (g_hash_table_size($1) + 17); +GHashTableIter iter; +gpointer key, value; + +g_hash_table_iter_init (&iter, $1); +while (g_hash_table_iter_next (&iter, &key, &value)) { +const GncGUID* c_guid = (const GncGUID*) key; +const gnc_numeric* c_numeric = (const gnc_numeric*) value; +SCM scm_guid = gnc_guid2scm(*c_guid); +SCM scm_numeric = gnc_numeric_to_scm(*c_numeric); + +scm_hash_set_x(table, scm_guid, scm_numeric); +} +g_hash_table_destroy($1); +$result = table; +} +GHashTable* gnc_sx_all_instantiate_cashflow_all(GDate range_start, GDate range_end); +%clear GHashTable *; diff --git a/libgnucash/app-utils/test/CMakeLists.txt b/libgnucash/app-utils/test/CMakeLists.txt index b0028c299c..03ed9c2cd7 100644 --- a/libgnucash/app-utils/test/CMakeLists.txt +++ b/libgnucash/app-utils/test/CMakeLists.txt @@ -10,7 +10,13 @@ set(APP_UTILS_TEST_INCLUDE_DIRS ${GUILE_INCLUDE_DIRS} ) -set(APP_UTILS_TEST_LIBS gnc-app-utils gnc-test-engine test-core ${GIO_LDFLAGS} ${GUILE_LDFLAGS}) +set(APP_UTILS_TEST_LIBS + gnc-app-utils + gnc-expressions + gnc-test-engine + test-core + ${GIO_LDFLAGS} + ${GUILE_LDFLAGS}) macro(add_app_utils_test _TARGET _SOURCE_FILES) gnc_add_test(${_TARGET} "${_SOURCE_FILES}" APP_UTILS_TEST_INCLUDE_DIRS APP_UTILS_TEST_LIBS)