preprocessor: add option to remove empty lines from macro-expanded mod file. closes #1551
parent
4a6fd427e0
commit
27317d25c5
|
@ -843,6 +843,10 @@ step. Useful in conjunction with @code{savemacro} when one wants that to
|
|||
reuse the intermediary @file{.mod} file, without having it cluttered by
|
||||
line numbering directives.
|
||||
|
||||
@item noemptylinemacro
|
||||
Passing this option removes all empty from the macro expanded mod file created
|
||||
when the @code{savemacro} option is used.
|
||||
|
||||
@item nolog
|
||||
Instructs Dynare to no create a logfile of this run in
|
||||
@file{@var{FILENAME}.log}. The default is to create the logfile.
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue