#include "FGAuxiliary.h"
#include "FGOutput.h"
#include "FGConfigFile.h"
+#include "FGScript.h"
#ifdef FGFS
#include <simgear/compiler.h>
#include STL_IOSTREAM
-# ifdef SG_HAVE_STD_INCLUDES
-# include <ctime>
-# else
-# include <time.h>
-# endif
#else
# if defined(sgi) && !defined(__GNUC__)
# include <iostream.h>
-# include <time.h>
# else
# include <iostream>
-# include <ctime>
# endif
#endif
int main(int argc, char** argv)
{
FGFDMExec* FDMExec;
- float cmd = 0.0;
bool result = false;
- bool scripted = false;
-
- if (argc == 2) {
- FGConfigFile testFile(argv[1]);
-
- if (!testFile.IsOpen()) {
- cout << "Script file not opened" << endl;
- exit(-1);
- }
+ bool Scripted = false;
+ FGScript* Script;
- testFile.GetNextConfigLine();
- if (testFile.GetValue("runscript").length() <= 0) {
- cout << "File: " << argv[1] << " is not a script file" << endl;
- exit(-1);
- }
- scripted = true;
- } else if (argc != 3) {
- cout << endl
+ if (argc != 3 && argc != 2) {
+ cerr << endl
<< " You must enter the name of a registered aircraft and reset point:"
<< endl << endl << " FDM <aircraft name> <reset file>" << endl;
- cout << endl << " Alternatively, you may specify only the name of a script file:"
+ cerr << endl << " Alternatively, you may specify only the name of a script file:"
<< endl << endl << " FDM <script file>" << endl << endl;
exit(0);
}
FDMExec = new FGFDMExec();
- if (scripted) { // form jsbsim <scriptfile>
- result = FDMExec->LoadScript(argv[1]);
+ if (argc == 2) { // SCRIPTED CASE
+
+ Script = new FGScript(FDMExec);
+ result = Script->LoadScript(argv[1]);
+
if (!result) {
cerr << "Script file " << argv[1] << " was not successfully loaded" << endl;
exit(-1);
}
+
+ Scripted = true;
+
} else { // form jsbsim <acname> <resetfile>
+
if ( ! FDMExec->LoadModel("aircraft", "engine", string(argv[1]))) {
- cerr << "JSBSim could not be started" << endl;
+ cerr << " JSBSim could not be started" << endl << endl;
exit(-1);
}
}
}
- struct FGJSBBase::Message* msg;
- while (FDMExec->Run()) {
+//
+// RUN loop. MESSAGES are read inside the Run() loop and output as necessary.
+//
+
+ FGJSBBase::Message* msg;
+ result = FDMExec->Run();
+ while (result) {
while (FDMExec->ReadMessage()) {
msg = FDMExec->ProcessMessage();
switch (msg->type) {
break;
}
}
+
+ if (Scripted) {
+ if (!Script->RunScript()) break;
+ }
+
+ result = FDMExec->Run();
}
delete FDMExec;