trunk preprocessor:
* added "onlymacro" option * added the possibility to specify macro output file with "savemacro=..." git-svn-id: https://www.dynare.org/svn/dynare/dynare_v4@2316 ac1d8469-bf42-47a9-8791-bf33cf982152issue#70
parent
6c6d5b4d35
commit
f93c956a3a
|
@ -23,6 +23,7 @@ using namespace std;
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
#include <cctype> // for tolower()
|
#include <cctype> // for tolower()
|
||||||
#include <algorithm> // for transform()
|
#include <algorithm> // for transform()
|
||||||
|
|
||||||
|
@ -37,7 +38,7 @@ void main2(stringstream &in, string &basename, bool debug, bool clear_all, bool
|
||||||
void
|
void
|
||||||
usage()
|
usage()
|
||||||
{
|
{
|
||||||
cerr << "Dynare usage: dynare mod_file [debug] [noclearall] [savemacro] [notmpterms]" << endl;
|
cerr << "Dynare usage: dynare mod_file [debug] [noclearall] [savemacro[=macro_file]] [onlymacro] [notmpterms]" << endl;
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,19 +53,34 @@ main(int argc, char** argv)
|
||||||
|
|
||||||
bool clear_all = true;
|
bool clear_all = true;
|
||||||
bool save_macro = false;
|
bool save_macro = false;
|
||||||
|
string save_macro_file;
|
||||||
bool debug = false;
|
bool debug = false;
|
||||||
bool no_tmp_terms = false;
|
bool no_tmp_terms = false;
|
||||||
|
bool only_macro = false;
|
||||||
|
|
||||||
// Parse options
|
// Parse options
|
||||||
for (int arg = 2; arg < argc; arg++)
|
for (int arg = 2; arg < argc; arg++)
|
||||||
{
|
{
|
||||||
if (string(argv[arg]) == string("debug"))
|
if (!strcmp(argv[arg], "debug"))
|
||||||
debug = true;
|
debug = true;
|
||||||
else if (string(argv[arg]) == string("noclearall"))
|
else if (!strcmp(argv[arg], "noclearall"))
|
||||||
clear_all = false;
|
clear_all = false;
|
||||||
else if (string(argv[arg]) == string("savemacro"))
|
else if (!strcmp(argv[arg], "onlymacro"))
|
||||||
save_macro = true;
|
only_macro = true;
|
||||||
else if (string(argv[arg]) == string("notmpterms"))
|
else if (strlen(argv[arg]) >= 9 && !strncmp(argv[arg], "savemacro", 9))
|
||||||
|
{
|
||||||
|
save_macro = true;
|
||||||
|
if (strlen(argv[arg]) > 9)
|
||||||
|
{
|
||||||
|
if (strlen(argv[arg]) == 10 || argv[arg][9] != '=')
|
||||||
|
{
|
||||||
|
cerr << "Incorrect syntax for savemacro option" << endl;
|
||||||
|
usage();
|
||||||
|
}
|
||||||
|
save_macro_file = string(argv[arg] + 10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (!strcmp(argv[arg], "notmpterms"))
|
||||||
no_tmp_terms = true;
|
no_tmp_terms = true;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -94,11 +110,21 @@ main(int argc, char** argv)
|
||||||
m.parse(argv[1], macro_output, debug);
|
m.parse(argv[1], macro_output, debug);
|
||||||
if (save_macro)
|
if (save_macro)
|
||||||
{
|
{
|
||||||
ofstream macro_output_file((basename + "-macroexp.mod").c_str());
|
if (save_macro_file.empty())
|
||||||
|
save_macro_file = basename + "-macroexp.mod";
|
||||||
|
ofstream macro_output_file(save_macro_file.c_str());
|
||||||
|
if (macro_output_file.fail())
|
||||||
|
{
|
||||||
|
cerr << "Cannot open " << save_macro_file << " for macro output" << endl;
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
macro_output_file << macro_output.str();
|
macro_output_file << macro_output.str();
|
||||||
macro_output_file.close();
|
macro_output_file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (only_macro)
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
|
||||||
// Do the rest
|
// Do the rest
|
||||||
main2(macro_output, basename, debug, clear_all, no_tmp_terms);
|
main2(macro_output, basename, debug, clear_all, no_tmp_terms);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue