26#include <guile-mappings.h>
32#include "gnucash-core-app.hpp"
34#include <glib/gi18n.h>
40#include <gnc-locale-utils.h>
44#include "gnucash-locale-platform.h"
46#include <boost/algorithm/string.hpp>
47#include <boost/locale.hpp>
51#include <gnc-report.h>
53namespace bl = boost::locale;
56static QofLogModule log_module = GNC_MOD_GUI;
60#include <gnc-locale-utils.hpp>
64constexpr int is_development_version = TRUE;
66constexpr int is_development_version = FALSE;
70static gchar *userdata_migration_msg = NULL;
73gnc_print_unstable_message(
void)
75 if (!is_development_version)
return;
77 std::cerr <<
_(
"This is a development version. It may or may not work.") <<
"\n"
78 <<
_(
"Report bugs and other problems to gnucash-devel@gnucash.org") <<
"\n"
80 << bl::format (std::string{
_(
"You can also lookup and file bug reports at {1}")}) % PACKAGE_BUGREPORT <<
"\n"
82 << bl::format (std::string{
_(
"To find the last stable version, please refer to {1}")}) % PACKAGE_URL <<
"\n";
86Gnucash::gnc_load_scm_config (MessageCb update_message_cb)
88 static auto is_system_config_loaded =
false;
89 if (!is_system_config_loaded)
92 auto msg =
_(
"Loading system wide Guile extensions…");
93 update_message_cb (msg);
94 auto system_config_dir = gnc_path_get_pkgsysconfdir ();
95 auto system_config = g_build_filename (system_config_dir,
"config",
nullptr);
96 is_system_config_loaded = gfec_try_load (system_config);
97 g_free (system_config_dir);
98 g_free (system_config);
101 static auto is_user_config_loaded =
false;
102 if (!is_user_config_loaded)
104 auto msg =
_(
"Loading user specific Guile extensions…");
105 update_message_cb (msg);
106 auto config_filename = g_build_filename (gnc_userconfig_dir (),
"config-user.scm",
nullptr);
107 is_user_config_loaded = gfec_try_load (config_filename);
108 g_free (config_filename);
113gnc_log_init (
const std::vector <std::string> log_flags,
114 const boost::optional <std::string> &log_to_filename)
116 if (log_to_filename && !log_to_filename->empty())
118 auto utf8_filename = log_to_filename->c_str();
124 auto tracefilename = g_build_filename (g_get_tmp_dir(),
"gnucash.trace",
127 g_free (tracefilename);
130 if (gnc_prefs_is_debugging_enabled())
137 auto log_config_filename = g_build_filename (gnc_userconfig_dir (),
138 "log.conf", (
char *)NULL);
139 if (g_file_test (log_config_filename, G_FILE_TEST_EXISTS))
141 g_free (log_config_filename);
143 for (
auto log_flag : log_flags)
145 if (log_flag.empty () ||
146 log_flag[0] ==
'=' ||
147 log_flag[log_flag.length () - 1] ==
'=')
149 g_warning (
"string [%s] not parseable", log_flag.c_str());
153 std::vector<std::string> split_flag;
154 boost::split (split_flag, log_flag, [](
char c){
return c ==
'=';});
156 auto level = qof_log_level_from_string (split_flag[1].c_str());
161Gnucash::CoreApp::CoreApp (
const char* app_name) : m_app_name {app_name}
163 #ifdef ENABLE_BINRELOC
165 GError *binreloc_error = NULL;
166 if (!gnc_gbr_init(&binreloc_error))
168 std::cerr <<
"main: Error on gnc_gbr_init: " << binreloc_error->message <<
"\n";
169 g_error_free(binreloc_error);
179 #if defined MAC_INTEGRATION || defined __MINGW32__
180 sys_locale = set_platform_locale();
182 #if ! defined MAC_INTEGRATION && ! defined __MINGW32__
183 sys_locale = g_strdup (setlocale (LC_ALL,
""));
186 std::cerr <<
"The locale defined in the environment isn't supported. "
187 <<
"Falling back to the 'C' (US English) locale\n";
188 g_setenv (
"LC_ALL",
"C", TRUE);
189 setlocale (LC_ALL,
"C");
193 auto localedir = gnc_path_get_localedir ();
194 bindtextdomain(PROJECT_NAME, localedir);
195 bindtextdomain(
"iso_4217", localedir);
196 bind_textdomain_codeset(
"iso_4217",
"UTF-8");
197 textdomain(PROJECT_NAME);
198 bind_textdomain_codeset(PROJECT_NAME,
"UTF-8");
200 gnc_init_boost_locale (localedir);
201 std::cerr.imbue (gnc_get_boost_locale());
202 std::cout.imbue (gnc_get_boost_locale());
206 m_tagline =
_(
"- GnuCash, accounting for personal and small business finance");
207 m_opt_desc_display = std::make_unique<bpo::options_description>
208 ((bl::format (std::string{
_(
"{1} [options] [datafile]")}) % m_app_name).str() + std::string(
" ") + m_tagline);
209 add_common_program_options();
218Gnucash::CoreApp::parse_command_line (
int argc,
char **argv)
222 bpo::store (bpo::command_line_parser (argc, argv).
223 options (m_opt_desc_all).positional(m_pos_opt_desc).run(), m_opt_map);
224 bpo::notify (m_opt_map);
226 catch (std::exception &e)
228 std::cerr << e.what() <<
"\n\n";
229 std::cerr << *m_opt_desc_display.get() << std::endl;
236 std::cout <<
_(
"GnuCash Paths") <<
'\n';
237 for (
const auto& ep : gnc_list_all_paths ())
239 std::cout << ep.env_name <<
": " << ep.env_path;
241 std::cout <<
' ' <<
_(
"(user modifiable)");
249 bl::format rel_fmt (std::string{
_(
"GnuCash {1}")});
250 bl::format dev_fmt (std::string{
_(
"GnuCash {1} development version")});
252 if (is_development_version)
257 std::cout <<
_(
"Build ID") <<
": " << gnc_build_id () <<
"\n";
263 std::cout << *m_opt_desc_display.get() << std::endl;
267 gnc_prefs_set_debugging (m_debug);
268 gnc_prefs_set_extra (m_extra);
273Gnucash::CoreApp::add_common_program_options (
void)
275 bpo::options_description common_options(
_(
"Common Options"));
276 common_options.add_options()
277 (
"help,h", bpo::bool_switch (&m_show_help),
278 _(
"Show this help message"))
279 (
"version,v", bpo::bool_switch (&m_show_version),
280 _(
"Show GnuCash version"))
281 (
"debug", bpo::bool_switch (&m_debug),
282 _(
"Enable debugging mode: provide deep detail in the logs.\nThis is equivalent to: --log \"=info\" --log \"qof=info\" --log \"gnc=info\""))
283 (
"extra", bpo::bool_switch(&m_extra),
284 _(
"Enable extra/development/debugging features."))
285 (
"log", bpo::value (&m_log_flags),
286 _(
"Log level overrides, of the form \"modulename={debug,info,warn,crit,error}\"\nExamples: \"--log qof=debug\" or \"--log gnc.backend.file.sx=info\"\nThis can be invoked multiple times."))
287 (
"paths", bpo::bool_switch(&m_show_paths),
289 (
"logto", bpo::value (&m_log_to_filename),
290 _(
"File to log into; defaults to \"/tmp/gnucash.trace\"; can be \"stderr\" or \"stdout\"."));
292 bpo::options_description hidden_options(
_(
"Hidden Options"));
293 hidden_options.add_options()
294 (
"input-file", bpo::value (&m_file_to_load),
297 m_pos_opt_desc.add(
"input-file", -1);
299 m_opt_desc_all.add (common_options);
300 m_opt_desc_all.add (hidden_options);
302 m_opt_desc_display->add (common_options);
306Gnucash::CoreApp::start (
void)
308 gnc_print_unstable_message();
313 userdata_migration_msg = gnc_filepath_init();
314 if (userdata_migration_msg)
315 g_print(
"\n\n%s\n", userdata_migration_msg);
317 gnc_log_init (m_log_flags, m_log_to_filename);
321 PINFO (
"System locale returned %s", sys_locale ? sys_locale :
"(null)");
322 PINFO (
"Effective locale set to %s.", setlocale (LC_ALL, NULL));
All type declarations for the whole Gnucash engine.
code to set up the environment for proper gnucash functioning.
File path resolution utility functions.
Generic api to store and retrieve preferences.
functions to query various version related strings that were set at build time.
void gnc_engine_init(int argc, char **argv)
PROTOTYPES.
void gnc_environment_setup(void)
Parse <prefix>/etc/gnucash/environment and set environment variables based on the contents of that fi...
const char * gnc_version(void)
Parse <prefix>/etc/gnucash/environment and set environment variables based on the contents of that fi...
#define PINFO(format, args...)
Print an informational note.
void qof_log_set_level(QofLogModule log_module, QofLogLevel level)
Set the logging level of the given log_module.
void qof_log_init_filename(const gchar *log_filename)
Specify a filename for log output.
void qof_log_parse_log_config(const char *filename)
Parse a log-configuration file.
void qof_log_init_filename_special(const char *log_to_filename)
If log_to_filename is "stderr" or "stdout" (exactly, case-insensitive), then those special files are ...