7 #include "ColorFilterMode.h"
10 #include "MainWindow.h"
11 #include <QApplication>
12 #include <QCoreApplication>
16 #include <QProcessEnvironment>
20 const QString CMD_DEBUG (
"debug");
21 const QString CMD_ERROR_REPORT (
"errorreport");
22 const QString CMD_FILE_CMD_SCRIPT (
"filecmdscript");
23 const QString CMD_GNUPLOT (
"gnuplot");
24 const QString CMD_HELP (
"help");
25 const QString CMD_REGRESSION (
"regression");
26 const QString DASH (
"-");
27 const QString DASH_DEBUG (
"-" + CMD_DEBUG);
28 const QString DASH_ERROR_REPORT (
"-" + CMD_ERROR_REPORT);
29 const QString DASH_FILE_CMD_SCRIPT (
"-" + CMD_FILE_CMD_SCRIPT);
30 const QString DASH_GNUPLOT (
"-" + CMD_GNUPLOT);
31 const QString DASH_HELP (
"-" + CMD_HELP);
32 const QString DASH_REGRESSION (
"-" + CMD_REGRESSION);
33 const QString ENGAUGE_LOG_FILE (
"engauge.log");
36 bool checkFileExists (
const QString &file);
37 QString engaugeLogFilename ();
38 bool engaugeLogFilenameAttempt (
const QString &path,
39 QString &pathAndFile);
40 void parseCmdLine (
int argc,
43 QString &errorReportFile,
44 QString &fileCmdScriptFile,
45 bool &isRegressionTest,
47 QStringList &loadStartupFiles);
50 bool checkFileExists (
const QString &file)
52 QFileInfo check (file);
53 return check.exists() && check.isFile();
56 QString engaugeLogFilename()
58 QProcessEnvironment env;
62 if (!engaugeLogFilenameAttempt (QCoreApplication::applicationDirPath(), pathAndFile)) {
63 if (!engaugeLogFilenameAttempt (env.value (
"HOME"), pathAndFile)) {
64 if (!engaugeLogFilenameAttempt (env.value (
"TEMP"), pathAndFile)) {
65 pathAndFile = ENGAUGE_LOG_FILE;
73 bool engaugeLogFilenameAttempt (
const QString &path,
79 pathAndFile = QString (
"%1%2%3")
81 .arg (QDir::separator())
82 .arg (ENGAUGE_LOG_FILE);
83 QFile file (pathAndFile);
84 if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {
93 int main(
int argc,
char *argv[])
95 qRegisterMetaType<ColorFilterMode> (
"ColorFilterMode");
97 QApplication a(argc, argv);
99 bool isDebug, isGnuplot, isRegressionTest;
100 QString errorReportFile, fileCmdScriptFile;
101 QStringList loadStartupFiles;
111 initializeLogging (
"engauge",
112 engaugeLogFilename(),
114 LOG4CPP_INFO_S ((*mainCat)) <<
"main args=" << QApplication::arguments().join (
" ").toLatin1().data();
126 void parseCmdLine (
int argc,
129 QString &errorReportFile,
130 QString &fileCmdScriptFile,
131 bool &isRegressionTest,
133 QStringList &loadStartupFiles)
135 const int COLUMN_WIDTH = 20;
136 bool showUsage =
false;
139 bool nextIsErrorReportFile =
false;
140 bool nextIsFileCmdScript =
false;
144 errorReportFile =
"";
145 fileCmdScriptFile =
"";
146 isRegressionTest =
false;
149 for (
int i = 1; i < argc; i++) {
151 if (nextIsErrorReportFile) {
152 errorReportFile = argv [i];
153 showUsage |= !checkFileExists (errorReportFile);
154 nextIsErrorReportFile =
false;
155 }
else if (nextIsFileCmdScript) {
156 fileCmdScriptFile = argv [i];
157 showUsage |= !checkFileExists (fileCmdScriptFile);
158 nextIsFileCmdScript =
false;
159 }
else if (strcmp (argv [i], DASH_DEBUG.toLatin1().data()) == 0) {
161 }
else if (strcmp (argv [i], DASH_ERROR_REPORT.toLatin1().data()) == 0) {
162 nextIsErrorReportFile =
true;
163 }
else if (strcmp (argv [i], DASH_FILE_CMD_SCRIPT.toLatin1().data()) == 0) {
164 nextIsFileCmdScript =
true;
165 }
else if (strcmp (argv [i], DASH_GNUPLOT.toLatin1().data()) == 0) {
167 }
else if (strcmp (argv [i], DASH_HELP.toLatin1().data()) == 0) {
169 }
else if (strcmp (argv [i], DASH_REGRESSION.toLatin1().data()) == 0) {
170 isRegressionTest =
true;
171 }
else if (strncmp (argv [i], DASH.toLatin1().data(), 1) == 0) {
176 QString fileName = argv [i];
177 QFileInfo fInfo (fileName);
178 if (fInfo.isRelative()) {
179 fileName = fInfo.absoluteFilePath();
181 loadStartupFiles << fileName;
185 if (showUsage || nextIsErrorReportFile) {
187 cerr <<
"Usage: engauge "
188 <<
"[" << DASH_DEBUG.toLatin1().data() <<
"] "
189 <<
"[" << DASH_ERROR_REPORT.toLatin1().data() <<
" <file>] "
190 <<
"[" << DASH_FILE_CMD_SCRIPT.toLatin1().data() <<
" <file> "
191 <<
"[" << DASH_GNUPLOT.toLatin1().data() <<
"] "
192 <<
"[" << DASH_HELP.toLatin1().data() <<
"] "
193 <<
"[" << DASH_REGRESSION.toLatin1().data() <<
"] "
194 <<
"[<load_file1>] [<load_file2>] ..." << endl
195 <<
" " << DASH_DEBUG.leftJustified(COLUMN_WIDTH,
' ').toLatin1().data()
196 << QObject::tr (
"Enables extra debug information. Used for debugging").toLatin1().data() << endl
197 <<
" " << DASH_ERROR_REPORT.leftJustified(COLUMN_WIDTH,
' ').toLatin1().data()
198 << QObject::tr (
"Specifies an error report file as input. Used for debugging and testing").toLatin1().data() << endl
199 <<
" " << DASH_FILE_CMD_SCRIPT.leftJustified(COLUMN_WIDTH,
' ').toLatin1().data()
200 << QObject::tr (
"Specifies a file command script file as input. Used for debugging and testing").toLatin1().data() << endl
201 <<
" " << DASH_GNUPLOT.leftJustified(COLUMN_WIDTH,
' ').toLatin1().data()
202 << QObject::tr (
"Output diagnostic gnuplot input files. Used for debugging").toLatin1().data() << endl
203 <<
" " << DASH_HELP.leftJustified(COLUMN_WIDTH,
' ').toLatin1().data()
204 << QObject::tr (
"Show this help information").toLatin1().data() << endl
205 <<
" " << DASH_REGRESSION.leftJustified(COLUMN_WIDTH,
' ').toLatin1().data()
206 << QObject::tr (
"Executes the error report file or file command script. Used for regression testing").toLatin1().data() << endl
207 <<
" " << QString (
"<load file> ").leftJustified(COLUMN_WIDTH,
' ').toLatin1().data()
208 << QObject::tr (
"File(s) to be imported or opened at startup").toLatin1().data() << endl;
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...