2008-02-03 11:28:36 +01:00
|
|
|
/*
|
2010-10-25 18:20:58 +02:00
|
|
|
* Copyright (C) 2003-2010 Dynare Team
|
2008-02-03 11:28:36 +01:00
|
|
|
*
|
|
|
|
* This file is part of Dynare.
|
|
|
|
*
|
|
|
|
* Dynare is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Dynare is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <sstream>
|
|
|
|
#include <fstream>
|
|
|
|
|
2009-01-21 13:08:11 +01:00
|
|
|
#include <cstdlib>
|
2008-12-15 15:39:36 +01:00
|
|
|
#include <cstring>
|
2009-05-16 00:41:51 +02:00
|
|
|
#ifndef PACKAGE_VERSION
|
2009-12-16 18:13:23 +01:00
|
|
|
# define PACKAGE_VERSION 4.
|
2009-05-16 00:41:51 +02:00
|
|
|
#endif
|
2008-02-03 11:28:36 +01:00
|
|
|
#include "macro/MacroDriver.hh"
|
|
|
|
|
|
|
|
/* Prototype for second part of main function
|
|
|
|
Splitting main() in two parts was necessary because ParsingDriver.h and MacroDriver.h can't be
|
|
|
|
included simultaneously (because of Bison limitations).
|
|
|
|
*/
|
2010-10-28 11:19:11 +02:00
|
|
|
void main2(stringstream &in, string &basename, bool debug, bool clear_all, bool no_tmp_terms, bool warn_uninit, bool console,
|
2010-10-25 18:20:58 +02:00
|
|
|
bool parallel, const string ¶llel_config_file, const string &cluster_name, bool parallel_slave_open_mode,
|
|
|
|
bool parallel_test
|
2009-12-11 15:46:21 +01:00
|
|
|
#if defined(_WIN32) || defined(__CYGWIN32__)
|
2009-12-16 18:13:23 +01:00
|
|
|
, bool cygwin, bool msvc
|
2009-12-11 15:46:21 +01:00
|
|
|
#endif
|
2009-12-16 18:13:23 +01:00
|
|
|
);
|
2008-02-03 11:28:36 +01:00
|
|
|
|
2008-10-29 16:19:56 +01:00
|
|
|
void
|
|
|
|
usage()
|
|
|
|
{
|
2009-12-11 15:46:21 +01:00
|
|
|
cerr << "Dynare usage: dynare mod_file [debug] [noclearall] [savemacro[=macro_file]] [onlymacro] [nolinemacro] [notmpterms] [warn_uninit]"
|
2011-03-29 15:53:10 +02:00
|
|
|
<< " [console] [parallel[=cluster_name]] [conffile=parallel_config_path_and_filename] [parallel_slave_open_mode] [parallel_test] "
|
|
|
|
<< " [-D<variable>[=<value>]]"
|
2009-12-11 15:46:21 +01:00
|
|
|
#if defined(_WIN32) || defined(__CYGWIN32__)
|
|
|
|
<< " [cygwin] [msvc]"
|
|
|
|
#endif
|
|
|
|
<< endl;
|
2008-10-29 16:19:56 +01:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2008-02-03 11:28:36 +01:00
|
|
|
int
|
2009-12-16 18:13:23 +01:00
|
|
|
main(int argc, char **argv)
|
2008-02-03 11:28:36 +01:00
|
|
|
{
|
|
|
|
if (argc < 2)
|
|
|
|
{
|
|
|
|
cerr << "Missing model file!" << endl;
|
2008-10-29 16:19:56 +01:00
|
|
|
usage();
|
2008-02-03 11:28:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool clear_all = true;
|
|
|
|
bool save_macro = false;
|
2008-12-15 15:39:36 +01:00
|
|
|
string save_macro_file;
|
2008-03-28 18:21:45 +01:00
|
|
|
bool debug = false;
|
2008-10-29 16:10:51 +01:00
|
|
|
bool no_tmp_terms = false;
|
2008-12-15 15:39:36 +01:00
|
|
|
bool only_macro = false;
|
2009-01-21 14:45:44 +01:00
|
|
|
bool no_line_macro = false;
|
2009-11-06 19:31:03 +01:00
|
|
|
bool warn_uninit = false;
|
2010-10-28 11:19:11 +02:00
|
|
|
bool console = false;
|
2009-12-11 15:46:21 +01:00
|
|
|
#if defined(_WIN32) || defined(__CYGWIN32__)
|
|
|
|
bool cygwin = false;
|
|
|
|
bool msvc = false;
|
|
|
|
#endif
|
2010-10-25 18:20:58 +02:00
|
|
|
string parallel_config_file;
|
|
|
|
bool parallel = false;
|
|
|
|
string cluster_name;
|
|
|
|
bool parallel_slave_open_mode = false;
|
|
|
|
bool parallel_test = false;
|
2011-03-29 15:53:10 +02:00
|
|
|
map<string, string> defines;
|
2008-02-03 11:28:36 +01:00
|
|
|
|
|
|
|
// Parse options
|
|
|
|
for (int arg = 2; arg < argc; arg++)
|
|
|
|
{
|
2008-12-15 15:39:36 +01:00
|
|
|
if (!strcmp(argv[arg], "debug"))
|
2008-03-28 18:21:45 +01:00
|
|
|
debug = true;
|
2008-12-15 15:39:36 +01:00
|
|
|
else if (!strcmp(argv[arg], "noclearall"))
|
2008-02-03 11:28:36 +01:00
|
|
|
clear_all = false;
|
2008-12-15 15:39:36 +01:00
|
|
|
else if (!strcmp(argv[arg], "onlymacro"))
|
|
|
|
only_macro = true;
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2009-01-21 14:45:44 +01:00
|
|
|
else if (!strcmp(argv[arg], "nolinemacro"))
|
|
|
|
no_line_macro = true;
|
2008-12-15 15:39:36 +01:00
|
|
|
else if (!strcmp(argv[arg], "notmpterms"))
|
2008-10-29 16:10:51 +01:00
|
|
|
no_tmp_terms = true;
|
2009-11-06 19:31:03 +01:00
|
|
|
else if (!strcmp(argv[arg], "warn_uninit"))
|
|
|
|
warn_uninit = true;
|
2010-10-28 11:19:11 +02:00
|
|
|
else if (!strcmp(argv[arg], "console"))
|
|
|
|
console = true;
|
2009-12-11 15:46:21 +01:00
|
|
|
#if defined(_WIN32) || defined(__CYGWIN32__)
|
|
|
|
else if (!strcmp(argv[arg], "cygwin"))
|
|
|
|
cygwin = true;
|
|
|
|
else if (!strcmp(argv[arg], "msvc"))
|
|
|
|
msvc = true;
|
|
|
|
#endif
|
2010-10-25 18:20:58 +02:00
|
|
|
else if (strlen(argv[arg]) >= 8 && !strncmp(argv[arg], "conffile", 8))
|
|
|
|
{
|
|
|
|
if (strlen(argv[arg]) <= 9 || argv[arg][8] != '=')
|
|
|
|
{
|
|
|
|
cerr << "Incorrect syntax for conffile option" << endl;
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
parallel_config_file = string(argv[arg] + 9);
|
|
|
|
}
|
|
|
|
else if (!strcmp(argv[arg], "parallel_slave_open_mode"))
|
|
|
|
parallel_slave_open_mode = true;
|
|
|
|
else if (!strcmp(argv[arg], "parallel_test"))
|
|
|
|
parallel_test = true;
|
|
|
|
else if (strlen(argv[arg]) >= 8 && !strncmp(argv[arg], "parallel", 8))
|
|
|
|
{
|
|
|
|
parallel = true;
|
|
|
|
if (strlen(argv[arg]) > 8)
|
|
|
|
{
|
|
|
|
if (strlen(argv[arg]) == 9 || argv[arg][8] != '=')
|
|
|
|
{
|
|
|
|
cerr << "Incorrect syntax for parallel option" << endl;
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
cluster_name = string(argv[arg] + 9);
|
|
|
|
}
|
|
|
|
}
|
2011-03-29 15:53:10 +02:00
|
|
|
else if (strlen(argv[arg]) >= 2 && !strncmp(argv[arg], "-D", 2))
|
|
|
|
{
|
|
|
|
if (strlen(argv[arg]) == 2)
|
|
|
|
{
|
|
|
|
cerr << "Incorrect syntax for command line define: the defined variable "
|
|
|
|
<< "must not be separated from -D by whitespace." << endl;
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t equal_index = string(argv[arg]).find('=');
|
|
|
|
if (equal_index != string::npos)
|
|
|
|
{
|
|
|
|
string key = string(argv[arg]).erase(equal_index).erase(0,2);
|
|
|
|
defines[key] = string(argv[arg]).erase(0, equal_index+1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
string key = string(argv[arg]).erase(0,2);
|
|
|
|
defines[key] = "1";
|
|
|
|
}
|
|
|
|
}
|
2008-10-29 16:19:56 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
cerr << "Unknown option: " << argv[arg] << endl;
|
|
|
|
usage();
|
|
|
|
}
|
2008-02-03 11:28:36 +01:00
|
|
|
}
|
|
|
|
|
2009-04-23 17:52:00 +02:00
|
|
|
cout << "Starting Dynare (version " << PACKAGE_VERSION << ")." << endl
|
2008-04-02 17:01:52 +02:00
|
|
|
<< "Starting preprocessing of the model file ..." << endl;
|
2008-02-03 11:28:36 +01:00
|
|
|
|
2009-01-21 13:08:11 +01:00
|
|
|
// Construct basename (i.e. remove file extension if there is one)
|
2008-02-03 11:28:36 +01:00
|
|
|
string basename = argv[1];
|
2009-01-21 13:08:11 +01:00
|
|
|
size_t pos = basename.find_last_of('.');
|
|
|
|
if (pos != string::npos)
|
|
|
|
basename.erase(pos);
|
2008-02-03 11:28:36 +01:00
|
|
|
|
|
|
|
// Do macro processing
|
2008-03-28 18:38:10 +01:00
|
|
|
MacroDriver m;
|
2008-03-28 18:21:45 +01:00
|
|
|
|
2008-02-03 11:28:36 +01:00
|
|
|
stringstream macro_output;
|
2011-03-29 15:53:10 +02:00
|
|
|
m.parse(argv[1], macro_output, debug, no_line_macro, defines);
|
2008-02-03 11:28:36 +01:00
|
|
|
if (save_macro)
|
|
|
|
{
|
2008-12-15 15:39:36 +01:00
|
|
|
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);
|
|
|
|
}
|
2008-02-03 11:28:36 +01:00
|
|
|
macro_output_file << macro_output.str();
|
|
|
|
macro_output_file.close();
|
|
|
|
}
|
|
|
|
|
2008-12-15 15:39:36 +01:00
|
|
|
if (only_macro)
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
|
2008-02-03 11:28:36 +01:00
|
|
|
// Do the rest
|
2010-10-28 11:19:11 +02:00
|
|
|
main2(macro_output, basename, debug, clear_all, no_tmp_terms, warn_uninit, console,
|
2010-10-25 18:20:58 +02:00
|
|
|
parallel, parallel_config_file, cluster_name, parallel_slave_open_mode, parallel_test
|
2009-12-11 15:46:21 +01:00
|
|
|
#if defined(_WIN32) || defined(__CYGWIN32__)
|
2009-12-11 15:52:04 +01:00
|
|
|
, cygwin, msvc
|
2009-12-11 15:46:21 +01:00
|
|
|
#endif
|
2009-12-16 18:13:23 +01:00
|
|
|
);
|
2008-02-03 11:28:36 +01:00
|
|
|
|
2008-10-29 16:33:16 +01:00
|
|
|
return EXIT_SUCCESS;
|
2008-02-03 11:28:36 +01:00
|
|
|
}
|