2008-01-11 14:42:14 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2003-2008 Dynare Team
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
2006-11-05 00:31:17 +01:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2008-01-30 12:38:09 +01:00
|
|
|
#include <iostream>
|
|
|
|
#include <sstream>
|
|
|
|
#include <fstream>
|
2006-11-17 18:48:11 +01:00
|
|
|
|
2008-01-30 12:38:09 +01:00
|
|
|
#include <cctype> // for tolower()
|
|
|
|
#include <algorithm> // for transform()
|
|
|
|
|
|
|
|
#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).
|
2006-11-05 00:31:17 +01:00
|
|
|
*/
|
2008-03-28 18:21:45 +01:00
|
|
|
void main2(stringstream &in, string &basename, bool debug, bool clear_all);
|
2008-01-30 12:38:09 +01:00
|
|
|
|
2006-11-17 18:48:11 +01:00
|
|
|
int
|
|
|
|
main(int argc, char** argv)
|
2006-11-05 00:31:17 +01:00
|
|
|
{
|
2006-11-17 18:48:11 +01:00
|
|
|
if (argc < 2)
|
2006-11-05 00:31:17 +01:00
|
|
|
{
|
2008-01-30 12:38:09 +01:00
|
|
|
cerr << "Missing model file!" << endl;
|
|
|
|
cerr << "Dynare usage: dynare mod_file [debug] [noclearall] [savemacro]" << endl;
|
2006-11-17 18:48:11 +01:00
|
|
|
exit(-1);
|
|
|
|
}
|
2006-11-05 00:31:17 +01:00
|
|
|
|
2006-12-12 12:54:30 +01:00
|
|
|
bool clear_all = true;
|
2008-01-30 12:38:09 +01:00
|
|
|
bool save_macro = false;
|
2008-03-28 18:21:45 +01:00
|
|
|
bool debug = false;
|
2006-11-05 00:31:17 +01:00
|
|
|
|
2006-11-17 18:48:11 +01:00
|
|
|
// Parse options
|
|
|
|
for (int arg = 2; arg < argc; arg++)
|
|
|
|
{
|
|
|
|
if (string(argv[arg]) == string("debug"))
|
2008-03-28 18:21:45 +01:00
|
|
|
debug = true;
|
2008-01-30 12:38:09 +01:00
|
|
|
else if (string(argv[arg]) == string("noclearall"))
|
|
|
|
clear_all = false;
|
|
|
|
else if (string(argv[arg]) == string("savemacro"))
|
|
|
|
save_macro = true;
|
2006-11-05 00:31:17 +01:00
|
|
|
}
|
|
|
|
|
2008-04-02 17:01:52 +02:00
|
|
|
cout << "Starting Dynare ..." << endl
|
|
|
|
<< "Starting preprocessing of the model file ..." << endl;
|
2006-11-17 18:48:11 +01:00
|
|
|
|
2008-01-30 12:38:09 +01:00
|
|
|
// Construct basename (check file extension is correct then remove it)
|
2006-12-12 12:54:30 +01:00
|
|
|
string basename = argv[1];
|
2008-01-30 12:38:09 +01:00
|
|
|
string ext = basename.substr(basename.size() - 4);
|
|
|
|
transform(ext.begin(), ext.end(), ext.begin(), (int(*)(int)) tolower); // Convert ext to lowercase
|
|
|
|
if (ext != string(".mod") && ext != string(".dyn"))
|
|
|
|
{
|
|
|
|
cerr << "mod_file extension must be .mod or .dyn!" << endl;
|
|
|
|
exit(-1);
|
|
|
|
}
|
2006-12-12 12:54:30 +01:00
|
|
|
basename.erase(basename.size() - 4, 4);
|
2006-11-17 18:48:11 +01:00
|
|
|
|
2008-01-30 12:38:09 +01:00
|
|
|
// Do macro processing
|
2008-03-28 18:38:10 +01:00
|
|
|
MacroDriver m;
|
2008-03-28 18:21:45 +01:00
|
|
|
|
2008-01-30 12:38:09 +01:00
|
|
|
stringstream macro_output;
|
2008-03-28 18:38:10 +01:00
|
|
|
m.parse(argv[1], macro_output, debug);
|
2008-01-30 12:38:09 +01:00
|
|
|
if (save_macro)
|
|
|
|
{
|
|
|
|
ofstream macro_output_file((basename + "-macroexp.mod").c_str());
|
|
|
|
macro_output_file << macro_output.str();
|
|
|
|
macro_output_file.close();
|
|
|
|
}
|
2006-11-28 12:56:02 +01:00
|
|
|
|
2008-01-30 12:38:09 +01:00
|
|
|
// Do the rest
|
2008-03-28 18:21:45 +01:00
|
|
|
main2(macro_output, basename, debug, clear_all);
|
2006-11-17 18:48:11 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|