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();
183 set_platform_ctype_to_acp();
185 #if ! defined MAC_INTEGRATION && ! defined __MINGW32__
186 sys_locale = g_strdup (setlocale (LC_ALL,
""));
189 std::cerr <<
"The locale defined in the environment isn't supported. "
190 <<
"Falling back to the 'C' (US English) locale\n";
191 g_setenv (
"LC_ALL",
"C", TRUE);
192 setlocale (LC_ALL,
"C");
196 auto localedir = gnc_path_get_localedir ();
197 bindtextdomain(PROJECT_NAME, localedir);
198 bindtextdomain(
"iso_4217", localedir);
199 bind_textdomain_codeset(
"iso_4217",
"UTF-8");
200 textdomain(PROJECT_NAME);
201 bind_textdomain_codeset(PROJECT_NAME,
"UTF-8");
203 gnc_init_boost_locale (localedir);
204 std::cerr.imbue (gnc_get_boost_locale());
205 std::cout.imbue (gnc_get_boost_locale());
209 m_tagline =
_(
"- GnuCash, accounting for personal and small business finance");
210 m_opt_desc_display = std::make_unique<bpo::options_description>
211 ((bl::format (std::string{
_(
"{1} [options] [datafile]")}) % m_app_name).str() + std::string(
" ") + m_tagline);
212 add_common_program_options();
221Gnucash::CoreApp::parse_command_line (
int argc,
char **argv)
225 bpo::store (bpo::command_line_parser (argc, argv).
226 options (m_opt_desc_all).positional(m_pos_opt_desc).run(), m_opt_map);
227 bpo::notify (m_opt_map);
229 catch (std::exception &e)
231 std::cerr << e.what() <<
"\n\n";
232 std::cerr << *m_opt_desc_display.get() << std::endl;
239 std::cout <<
_(
"GnuCash Paths") <<
'\n';
240 for (
const auto& ep : gnc_list_all_paths ())
242 std::cout << ep.env_name <<
": " << ep.env_path;
244 std::cout <<
' ' <<
_(
"(user modifiable)");
252 bl::format rel_fmt (std::string{
_(
"GnuCash {1}")});
253 bl::format dev_fmt (std::string{
_(
"GnuCash {1} development version")});
255 if (is_development_version)
260 std::cout <<
_(
"Build ID") <<
": " << gnc_build_id () <<
"\n";
266 std::cout << *m_opt_desc_display.get() << std::endl;
270 gnc_prefs_set_debugging (m_debug);
271 gnc_prefs_set_extra (m_extra);
276Gnucash::CoreApp::add_common_program_options (
void)
278 bpo::options_description common_options(
_(
"Common Options"));
279 common_options.add_options()
280 (
"help,h", bpo::bool_switch (&m_show_help),
281 _(
"Show this help message"))
282 (
"version,v", bpo::bool_switch (&m_show_version),
283 _(
"Show GnuCash version"))
284 (
"debug", bpo::bool_switch (&m_debug),
285 _(
"Enable debugging mode: provide deep detail in the logs.\nThis is equivalent to: --log \"=info\" --log \"qof=info\" --log \"gnc=info\""))
286 (
"extra", bpo::bool_switch(&m_extra),
287 _(
"Enable extra/development/debugging features."))
288 (
"log", bpo::value (&m_log_flags),
289 _(
"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."))
290 (
"paths", bpo::bool_switch(&m_show_paths),
292 (
"logto", bpo::value (&m_log_to_filename),
293 _(
"File to log into; defaults to \"/tmp/gnucash.trace\"; can be \"stderr\" or \"stdout\"."));
295 bpo::options_description hidden_options(
_(
"Hidden Options"));
296 hidden_options.add_options()
297 (
"input-file", bpo::value (&m_file_to_load),
300 m_pos_opt_desc.add(
"input-file", -1);
302 m_opt_desc_all.add (common_options);
303 m_opt_desc_all.add (hidden_options);
305 m_opt_desc_display->add (common_options);
309Gnucash::CoreApp::start (
void)
311 gnc_print_unstable_message();
316 userdata_migration_msg = gnc_filepath_init();
317 if (userdata_migration_msg)
318 g_print(
"\n\n%s\n", userdata_migration_msg);
320 gnc_log_init (m_log_flags, m_log_to_filename);
324 PINFO (
"System locale returned %s", sys_locale ? sys_locale :
"(null)");
325 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 ...