diff --git a/DynareMain.cc b/DynareMain.cc index eb2891a6e30235df2d17a4e08e2714511a84033c..16183842c4dffd9254209fde69c7ee57b2e292e7 100644 --- a/DynareMain.cc +++ b/DynareMain.cc @@ -50,12 +50,12 @@ void main2(stringstream &in, string &basename, bool debug, bool clear_all, bool ); void main1(string &modfile, string &basename, string &modfiletxt, bool debug, bool save_macro, string &save_macro_file, - bool no_line_macro, map<string, string> &defines, vector<string> &path, stringstream ¯o_output); + bool no_line_macro, bool no_empty_line_macro, map<string, string> &defines, vector<string> &path, stringstream ¯o_output); void usage() { - cerr << "Dynare usage: dynare mod_file [debug] [noclearall] [onlyclearglobals] [savemacro[=macro_file]] [onlymacro] [nolinemacro] [notmpterms] [nolog] [warn_uninit]" + cerr << "Dynare usage: dynare mod_file [debug] [noclearall] [onlyclearglobals] [savemacro[=macro_file]] [onlymacro] [nolinemacro] [noemptylinemacro] [notmpterms] [nolog] [warn_uninit]" << " [console] [nograph] [nointeractive] [parallel[=cluster_name]] [conffile=parallel_config_path_and_filename] [parallel_slave_open_mode] [parallel_test]" << " [-D<variable>[=<value>]] [-I/path] [nostrict] [stochastic] [fast] [minimal_workspace] [compute_xrefs] [output=dynamic|first|second|third] [language=C|C++|julia]" << " [params_derivs_order=0|1|2]" @@ -91,6 +91,7 @@ main(int argc, char **argv) bool no_tmp_terms = false; bool only_macro = false; bool no_line_macro = false; + bool no_empty_line_macro = false; bool no_log = false; bool no_warn = false; int params_derivs_order = 2; @@ -162,6 +163,8 @@ main(int argc, char **argv) } else if (!strcmp(argv[arg], "nolinemacro")) no_line_macro = true; + else if (!strcmp(argv[arg], "noemptylinemacro")) + no_empty_line_macro = true; else if (!strcmp(argv[arg], "notmpterms")) no_tmp_terms = true; else if (!strcmp(argv[arg], "nolog")) @@ -389,7 +392,8 @@ main(int argc, char **argv) // Do macro processing stringstream macro_output; - main1(modfile, basename, modfiletxt, debug, save_macro, save_macro_file, no_line_macro, defines, path, macro_output); + main1(modfile, basename, modfiletxt, debug, save_macro, save_macro_file, no_line_macro, no_empty_line_macro, + defines, path, macro_output); if (only_macro) return EXIT_SUCCESS; diff --git a/DynareMain1.cc b/DynareMain1.cc index 83812284648bd88f413eb459717122a0216642c8..c801fd86d8c9b840675e34e863bb49175b681c3a 100644 --- a/DynareMain1.cc +++ b/DynareMain1.cc @@ -22,9 +22,13 @@ #include "macro/MacroDriver.hh" +bool compareNewline (int i, int j) { + return i == '\n' && j == '\n'; +} + void main1(string &modfile, string &basename, string &modfiletxt, bool debug, bool save_macro, string &save_macro_file, - bool no_line_macro, map<string, string> &defines, vector<string> &path, stringstream ¯o_output) + bool no_line_macro, bool no_empty_line_macro, map<string, string> &defines, vector<string> &path, stringstream ¯o_output) { // Do macro processing MacroDriver m; @@ -40,7 +44,11 @@ main1(string &modfile, string &basename, string &modfiletxt, bool debug, bool sa cerr << "Cannot open " << save_macro_file << " for macro output" << endl; exit(EXIT_FAILURE); } - macro_output_file << macro_output.str(); + + string str (macro_output.str()); + if (no_empty_line_macro) + str.erase(unique(str.begin(), str.end(), compareNewline), str.end()); + macro_output_file << str; macro_output_file.close(); } }