From acce150795dbb6f6501873dd5e645bdea77dda3d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien.villemot@ens.fr>
Date: Thu, 28 Oct 2010 11:19:11 +0200
Subject: [PATCH] New "console" option (closes #130)

---
 DynareMain.cc  | 9 ++++++---
 DynareMain2.cc | 4 ++--
 ModFile.cc     | 5 ++++-
 ModFile.hh     | 4 +++-
 4 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/DynareMain.cc b/DynareMain.cc
index 27225bfa..5aec0a9b 100644
--- a/DynareMain.cc
+++ b/DynareMain.cc
@@ -34,7 +34,7 @@ using namespace std;
    Splitting main() in two parts was necessary because ParsingDriver.h and MacroDriver.h can't be
    included simultaneously (because of Bison limitations).
 */
-void main2(stringstream &in, string &basename, bool debug, bool clear_all, bool no_tmp_terms, bool warn_uninit,
+void main2(stringstream &in, string &basename, bool debug, bool clear_all, bool no_tmp_terms, bool warn_uninit, bool console,
            bool parallel, const string &parallel_config_file, const string &cluster_name, bool parallel_slave_open_mode,
            bool parallel_test
 #if defined(_WIN32) || defined(__CYGWIN32__)
@@ -46,7 +46,7 @@ void
 usage()
 {
   cerr << "Dynare usage: dynare mod_file [debug] [noclearall] [savemacro[=macro_file]] [onlymacro] [nolinemacro] [notmpterms] [warn_uninit]"
-       << " [parallel[=cluster_name]] [conffile=parallel_config_path_and_filename] [parallel_slave_open_mode] [parallel_test]"
+       << " [console] [parallel[=cluster_name]] [conffile=parallel_config_path_and_filename] [parallel_slave_open_mode] [parallel_test]"
 #if defined(_WIN32) || defined(__CYGWIN32__)
        << " [cygwin] [msvc]"
 #endif
@@ -71,6 +71,7 @@ main(int argc, char **argv)
   bool only_macro = false;
   bool no_line_macro = false;
   bool warn_uninit = false;
+  bool console = false;
 #if defined(_WIN32) || defined(__CYGWIN32__)
   bool cygwin = false;
   bool msvc = false;
@@ -109,6 +110,8 @@ main(int argc, char **argv)
         no_tmp_terms = true;
       else if (!strcmp(argv[arg], "warn_uninit"))
         warn_uninit = true;
+      else if (!strcmp(argv[arg], "console"))
+        console = true;
 #if defined(_WIN32) || defined(__CYGWIN32__)
       else if (!strcmp(argv[arg], "cygwin"))
         cygwin = true;
@@ -180,7 +183,7 @@ main(int argc, char **argv)
     return EXIT_SUCCESS;
 
   // Do the rest
-  main2(macro_output, basename, debug, clear_all, no_tmp_terms, warn_uninit,
+  main2(macro_output, basename, debug, clear_all, no_tmp_terms, warn_uninit, console,
         parallel, parallel_config_file, cluster_name, parallel_slave_open_mode, parallel_test
 #if defined(_WIN32) || defined(__CYGWIN32__)
         , cygwin, msvc
diff --git a/DynareMain2.cc b/DynareMain2.cc
index 5b944a4a..3813a6e2 100644
--- a/DynareMain2.cc
+++ b/DynareMain2.cc
@@ -26,7 +26,7 @@ using namespace std;
 #include "ConfigFile.hh"
 
 void
-main2(stringstream &in, string &basename, bool debug, bool clear_all, bool no_tmp_terms, bool warn_uninit,
+main2(stringstream &in, string &basename, bool debug, bool clear_all, bool no_tmp_terms, bool warn_uninit, bool console,
       bool parallel, const string &parallel_config_file, const string &cluster_name, bool parallel_slave_open_mode,
       bool parallel_test
 #if defined(_WIN32) || defined(__CYGWIN32__)
@@ -56,7 +56,7 @@ main2(stringstream &in, string &basename, bool debug, bool clear_all, bool no_tm
   mod_file->computingPass(no_tmp_terms);
 
   // Write outputs
-  mod_file->writeOutputFiles(basename, clear_all, config_file
+  mod_file->writeOutputFiles(basename, clear_all, console, config_file
 #if defined(_WIN32) || defined(__CYGWIN32__)
                              , cygwin, msvc
 #endif
diff --git a/ModFile.cc b/ModFile.cc
index bf6b9130..ab1eb655 100644
--- a/ModFile.cc
+++ b/ModFile.cc
@@ -345,7 +345,7 @@ ModFile::computingPass(bool no_tmp_terms)
 }
 
 void
-ModFile::writeOutputFiles(const string &basename, bool clear_all, const ConfigFile &config_file
+ModFile::writeOutputFiles(const string &basename, bool clear_all, bool console, const ConfigFile &config_file
 #if defined(_WIN32) || defined(__CYGWIN32__)
                           , bool cygwin, bool msvc
 #endif
@@ -398,6 +398,9 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, const ConfigFi
               << "end" << endl
               << "diary(logname_)" << endl;
 
+  if (console)
+    mOutputFile << "options_.console_mode = 1;" << endl;
+
   cout << "Processing outputs ...";
 
   symbol_table.writeOutput(mOutputFile);
diff --git a/ModFile.hh b/ModFile.hh
index 71d36316..00999c88 100644
--- a/ModFile.hh
+++ b/ModFile.hh
@@ -105,9 +105,11 @@ public:
   /*!
     \param basename The base name used for writing output files. Should be the name of the mod file without its extension
     \param clear_all Should a "clear all" instruction be written to output ?
+    \param console Are we in console mode ?
+    \param cygwin Should the MEX command of use_dll be adapted for Cygwin?
     \param msvc Should the MEX command of use_dll be adapted for MSVC?
   */
-  void writeOutputFiles(const string &basename, bool clear_all, const ConfigFile &config_file
+  void writeOutputFiles(const string &basename, bool clear_all, bool console, const ConfigFile &config_file
 #if defined(_WIN32) || defined(__CYGWIN32__)
                         , bool cygwin, bool msvc
 #endif
-- 
GitLab