Convert args passed to run reports to const std::string&.

This commit is contained in:
John Ralls 2020-05-29 17:11:38 -07:00
parent 1e9b5a5707
commit 3884e24eb9
3 changed files with 28 additions and 20 deletions

View File

@ -97,16 +97,20 @@ Gnucash::GnucashCli::configure_program_options (void)
quotes_options.add_options()
("add-price-quotes", bpo::bool_switch(),
N_("Add price quotes to given GnuCash datafile.\n"))
("namespace", bpo::value<std::string>(),
N_("Regular expression determining which namespace commodities will be retrieved"));
m_opt_desc->add (quotes_options);
bpo::options_description report_options(_("Run Report Options"));
report_options.add_options()
("run-report", bpo::value<std::string>(),
N_("Runs a report\n"))
("export-type", bpo::value<std::string>(),
N_("Specify export type\n"))
("output-file", bpo::value<std::string>(),
N_("Output file for report\n"))
("namespace", bpo::value<std::string>(),
N_("Regular expression determining which namespace commodities will be retrieved"));
N_("Output file for report\n"));
m_opt_desc->add (report_options);
m_opt_desc->add (quotes_options);
}
int

View File

@ -45,10 +45,10 @@ extern "C" {
namespace bl = boost::locale;
struct run_report_args {
const char *file_to_load;
const char *run_report;
const char *export_type;
const char *output_file;
const std::string& file_to_load;
const std::string& run_report;
const std::string& export_type;
const std::string& output_file;
};
/* This static indicates the debugging module that this .o belongs to. */
@ -138,6 +138,7 @@ scm_run_report (void *data,
scm_c_eval_string("(debug-set! stack 200000)");
scm_c_use_module ("gnucash utilities");
scm_c_use_module ("gnucash app-utils");
scm_c_use_module ("gnucash report");
scm_c_use_module ("gnucash reports");
// gnc_report_init ();
@ -145,12 +146,13 @@ scm_run_report (void *data,
// load_user_config();
gnc_prefs_init ();
qof_event_suspend ();
datafile = args->file_to_load;
datafile = args->file_to_load.c_str();
cmdline = scm_c_eval_string ("gnc:cmdline-run-report");
report = scm_from_utf8_string (args->run_report);
type = args->export_type ? scm_from_utf8_string (args->export_type) : SCM_BOOL_F;
file = args->output_file ? scm_from_utf8_string (args->output_file) : SCM_BOOL_F;
report = scm_from_utf8_string (args->run_report.c_str());
type = !args->export_type.empty() ? scm_from_utf8_string (args->export_type.c_str()) : SCM_BOOL_F;
file = !args->output_file.empty() ? scm_from_utf8_string (args->output_file.c_str()) : SCM_BOOL_F;
/* dry-run? is #t: try report, check validity of options */
if (scm_is_false (scm_call_4 (cmdline, report, type, file, SCM_BOOL_T)))
@ -203,13 +205,13 @@ Gnucash::add_quotes (std::string &uri)
}
int
Gnucash::run_report (const std::string file_to_load, std::string &run_report,
std::string &export_type, std::string &output_file)
Gnucash::run_report (const std::string& file_to_load,
const std::string& run_report,
const std::string& export_type,
const std::string& output_file)
{
auto args = run_report_args { file_to_load.c_str(),
run_report.c_str(),
export_type.c_str(),
output_file.c_str() };
auto args = run_report_args { file_to_load, run_report,
export_type, output_file };
if (not run_report.empty())
scm_boot_guile (0, nullptr, scm_run_report, &args);

View File

@ -30,8 +30,10 @@
namespace Gnucash {
int add_quotes (std::string &uri);
int run_report (const std::string file_to_load, std::string &run_report,
std::string &export_type, std::string &output_file);
int run_report (const std::string& file_to_load,
const std::string& run_report,
const std::string& export_type,
const std::string& output_file);
}
#endif