Bug Summary

File:OMOptim/OMOptim/build/../main.cpp
Warning:line 239, column 17
Value stored to 'result' is never read

Annotated Source Code

[?] Use j/k keys for keyboard navigation

1// $Id$
2/**
3 * This file is part of OpenModelica.
4 *
5 * Copyright (c) 1998-CurrentYear, Open Source Modelica Consortium (OSMC),
6 * c/o Linkopings universitet, Department of Computer and Information Science,
7 * SE-58183 Linkoping, Sweden.
8 *
9 * All rights reserved.
10 *
11 * THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR
12 * THIS OSMC PUBLIC LICENSE (OSMC-PL).
13 * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE
14 * OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3, ACCORDING TO RECIPIENTS CHOICE.
15 *
16 * The OpenModelica software and the Open Source Modelica
17 * Consortium (OSMC) Public License (OSMC-PL) are obtained
18 * from OSMC, either from the above address,
19 * from the URLs: http://www.ida.liu.se/projects/OpenModelica or
20 * http://www.openmodelica.org, and in the OpenModelica distribution.
21 * GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html.
22 *
23 * This program is distributed WITHOUT ANY WARRANTY; without
24 * even the implied warranty of MERCHANTABILITY or FITNESS
25 * FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
26 * IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
27 *
28 * See the full OSMC Public License conditions for more details.
29 *
30 * Main contributor 2010, Hubert Thierot, CEP - ARMINES (France)
31 * Main contributor 2010, Hubert Thierot, CEP - ARMINES (France)
32
33 @file main.cpp
34 @brief Comments for file documentation.
35 @author Hubert Thieriot, hubert.thieriot@mines-paristech.fr
36 Company : CEP - ARMINES (France)
37 http://www-cep.ensmp.fr/english/
38 @version
39*/
40
41// QT Headers
42#include <QtGlobal>
43#if (QT_VERSION((5<<16)|(9<<8)|(5)) >= QT_VERSION_CHECK(5, 0, 0)((5<<16)|(0<<8)|(0)))
44#include <QtWidgets>
45#define toAsciitoLatin1 toLatin1
46#else
47#include <QtGui/QApplication>
48#include <QtCore/QSettings>
49#endif
50
51#include "MainWindow.h"
52#include "OMOptimSettings.h"
53#include "MOStyleSheet.h"
54#include "version.h"
55#include "registermetatypes.h"
56#include "config.h"
57#include "scriptparseromoptim.h"
58#include <cstdio> // fileno()
59#include <unistd.h> // isatty()
60#include "GuiTools.h"
61#include "ConsoleWindow.h"
62#include "Utilities.h"
63
64#define HAVE_QAPPLICATION_H
65#define HAVE_QSOCKETNOTIFIER_H
66
67
68#include <omniORB4/CORBA.h>
69CORBA::ORB_var orb;
70
71int main(int argc, char *argv[])
72{
73 // Register Info as a metaType
74 // Needed for Info communication between threads
75 // register meta types for connect signals/slots
76 RegisterMetaTypes::init();
77
78
79 // Application
80 QApplication *app = new QApplication(argc,argv);
81 app->setApplicationName("OMOptim");
82
83 //Read arguments
84 QStringList args;
85 for(int i=0;i<argc;i++)
86 {
87 args.push_back(QString(argv[i]));
88 }
89
90 // separate filepath and options
91 QStringList filePaths;
92 QStringList options;
93 for(int i=1;i<args.size();i++) //arg0 is the executable path
94 {
95 // if start with -, it's an option
96 QRegExp regExpOption("^[\\-]([\\S]*)$");
97
98 if(args.at(i).contains(regExpOption))
99 {
100 options.push_back(regExpOption.cap(1));
101 }
102 else
103 filePaths.push_back(args.at(i));
104 }
105
106
107
108 // Settings
109 OMOptimSettings::initialize();
110
111 // Message handler
112 QString logFilePath = Utilities::getOMLog();
113 QFile logFile(logFilePath);
114 logFile.open(QIODevice::WriteOnly);
115
116 // Setting the Application version
117 QString version = Version::version();
118 app->setApplicationVersion(version);
119
120 // Style
121 MOStyleSheet::initialize(qApp(static_cast<QApplication *>(QCoreApplication::instance
()))
);
122
123
124 QList<QTextStream*> logStreams;
125 //#ifdef _DEBUG
126 QTextStream *logStream = new QTextStream(&logFile);
127 InfoSender::instance()->addLogStream(logStream);
128 logStreams.push_back(logStream);
129 //#endif
130
131
132 bool showGUI = true;
133 bool showConsole = false;
134
135 // if script file to parse
136 bool launchScript = false;
137 QMap<QString,QString> definitions;
138 QStringList scriptCommands;
139
140 if(filePaths.size()==1)
141 {
142 // read commands and options
143 bool scriptResult = ScriptParser::parseFile(QFileInfo(filePaths.at(0)),scriptCommands,definitions);
144
145 // show gui ?
146 QString displayMode = definitions.value("displaymode",QString());
147 if(displayMode=="console")
148 {
149 showGUI = false;
150 showConsole = true;
151 }
152 if(displayMode=="nogui")
153 {
154 showGUI = false;
155 showConsole = false;
156 }
157 if(displayMode=="gui")
158 {
159 showGUI = true;
160 showConsole = false;
161 }
162
163 if(!showGUI && !scriptResult)
164 return -1;
165 else
166 launchScript = true;
167 }
168
169 // Project
170 bool startOMC = true;
171 if(options.contains("noomc"))
172 startOMC = false;
173 if(definitions.value("useomc",QString()).contains(QRegExp("^[false|0]+$")))
174 startOMC = false;
175
176 Project* project = new Project(startOMC);
177 project->setScriptParser(new ScriptParserOMOptim(project));
178 app->connect( app, SIGNAL( lastWindowClosed() )"2""lastWindowClosed()", project->scriptParser(),SLOT(stop())"1""stop()");
179
180 // create GUI
181 MainWindow *w = NULL__null;
182 if(showGUI)
183 {
184 if(!options.contains("nogui"))
185 {
186 w = new MainWindow(project);
187 app->connect( app, SIGNAL( lastWindowClosed() )"2""lastWindowClosed()", w, SLOT( quit() )"1""quit()" );
188 w->show();
189 }
190 }
191
192
193
194
195 // launchScript
196 ConsoleWindow* console = NULL__null;
197 if(launchScript)
198 {
199
200 // bool launchFromCmdLine = false;
201 // if (isatty(fileno(stdin)))
202 // launchFromCmdLine = true;
203
204 // add a script logfile in the temp directory
205 QString scriptLogFilePath = Utilities::getOMScriptLog();
206 QFile scriptLogFile(scriptLogFilePath);
207 scriptLogFile.open(QIODevice::WriteOnly);
208 QTextStream *scriptLogStream = new QTextStream(&scriptLogFile);
209 InfoSender::instance()->addLogStream(scriptLogStream,QList<ListInfo::InfoType>() << ListInfo::SCRIPT);
210 logStreams.push_back(scriptLogStream);
211
212 int result = 0;
213 if(showConsole)
214 {
215 // create a window
216 console = new ConsoleWindow(project,scriptCommands);
217 app->connect( app, SIGNAL( lastWindowClosed() )"2""lastWindowClosed()", app, SLOT( quit() )"1""quit()" );
218 console->show();
219 result = console->launch();
220 //result = console->exec();
221 }
222 else
223 {
224 // set output to terminal
225 QTextStream* stdStream = new QTextStream(stdoutstdout, QIODevice::WriteOnly);
226
227
228 QList<ListInfo::InfoType> logInfoTypes;
229 logInfoTypes << ListInfo::NORMAL2 << ListInfo::WARNING2<<
230 ListInfo::ERROR2<< ListInfo::TASK << ListInfo::SCRIPT;
231 InfoSender::instance()->addLogStream(stdStream,logInfoTypes);
232
233 logStreams.push_back(stdStream);
234
235 bool scriptOk = project->scriptParser()->executeCommands(scriptCommands);
236 if(scriptOk)
237 result = 0;
238 else
239 result = -1;
Value stored to 'result' is never read
240 }
241 scriptLogStream->flush();
242 scriptLogFile.flush();
243 scriptLogFile.close();
244 }
245
246 try
247 {
248 if(!launchScript)
249 app->exec();
250 }
251 catch(std::exception &e)
252 {
253 QString msg(e.what());
254 InfoSender::instance()->debug(msg);
255 //#ifdef _DEBUG
256 //#endif
257 }
258
259
260 logFile.close();
261
262 // delete project
263 delete project;
264
265 // delete logstreams
266 for(int i=0;i<logStreams.size();i++)
267 {
268 logStreams.at(i)->flush();
269 delete logStreams.at(i);
270 }
271
272
273 if(console)
274 return console->_result;
275 else
276 return 0;
277}
278
279
280// load plugins
281// QDir pluginsDir = QDir(QApplication::applicationDirPath()+QDir::separator()+"Plugins");
282// if(pluginsDir.exists())
283// {
284// QStringList pluginsNames = pluginsDir.entryList();
285// pluginsNames.removeAll(".");
286// pluginsNames.removeAll("..");
287// for(int i=0;i<pluginsNames.size();i++)
288// project->loadPlugin(pluginsDir.filePath(pluginsNames.at(i)),false,true);
289// }