1 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 // + This file is part of enGrid. +
5 // + Copyright 2008-2014 enGits GmbH +
7 // + enGrid is free software: you can redistribute it and/or modify +
8 // + it under the terms of the GNU General Public License as published by +
9 // + the Free Software Foundation, either version 3 of the License, or +
10 // + (at your option) any later version. +
12 // + enGrid is distributed in the hope that it will be useful, +
13 // + but WITHOUT ANY WARRANTY; without even the implied warranty of +
14 // + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +
15 // + GNU General Public License for more details. +
17 // + You should have received a copy of the GNU General Public License +
18 // + along with enGrid. If not, see <http://www.gnu.org/licenses/>. +
20 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23 #include <QApplication>
25 #include <QTextStream>
28 #include "guimainwindow.h"
29 #include "filetemplate.h"
31 #include "geometrytools.h"
32 using namespace GeometryTools
;
34 ///\todo replace with shellscript?
35 void appendLicense(int argc
, char ** argv
)
37 int first_year
= 2008;
38 QString first_year_text
;
39 first_year_text
.setNum(first_year
);
40 int year
= QDate::currentDate().year();
42 year_text
.setNum(year
);
43 if (year
-first_year
== 1) {
44 year_text
= first_year_text
+ "," + year_text
;
46 if (year
-first_year
> 1) {
47 year_text
= first_year_text
+ "-" + year_text
;
49 QString year_end_text
= " +\n";
50 if (year
== first_year
) {
51 year_end_text
= " " + year_end_text
;
53 for (int i
= 2; i
< argc
; ++i
) {
54 QString
filename(argv
[i
]);
55 QString comment
= "// ";
58 if (filename
.right(3) == ".sh") script
= true;
59 if (filename
.right(3) == ".py") script
= true;
60 if (filename
.right(5) == ".bash") script
= true;
62 file
.open(QIODevice::ReadOnly
);
66 QString line
= f
.readLine();
67 buffer
+= line
+ "\n";
69 buffer
+= comment
+ "\n";
70 buffer
+= comment
+ "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
71 buffer
+= comment
+ "+ +\n";
72 buffer
+= comment
+ "+ This file is part of enGrid. +\n";
73 buffer
+= comment
+ "+ +\n";
74 buffer
+= comment
+ "+ Copyright " + year_text
+ " enGits GmbH" + year_end_text
;
75 buffer
+= comment
+ "+ +\n";
76 buffer
+= comment
+ "+ enGrid is free software: you can redistribute it and/or modify +\n";
77 buffer
+= comment
+ "+ it under the terms of the GNU General Public License as published by +\n";
78 buffer
+= comment
+ "+ the Free Software Foundation, either version 3 of the License, or +\n";
79 buffer
+= comment
+ "+ (at your option) any later version. +\n";
80 buffer
+= comment
+ "+ +\n";
81 buffer
+= comment
+ "+ enGrid is distributed in the hope that it will be useful, +\n";
82 buffer
+= comment
+ "+ but WITHOUT ANY WARRANTY; without even the implied warranty of +\n";
83 buffer
+= comment
+ "+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +\n";
84 buffer
+= comment
+ "+ GNU General Public License for more details. +\n";
85 buffer
+= comment
+ "+ +\n";
86 buffer
+= comment
+ "+ You should have received a copy of the GNU General Public License +\n";
87 buffer
+= comment
+ "+ along with enGrid. If not, see <http://www.gnu.org/licenses/>. +\n";
88 buffer
+= comment
+ "+ +\n";
89 buffer
+= comment
+ "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
90 buffer
+= comment
+ "\n";
92 bool src_code
= false;
94 QString line
= f
.readLine();
96 if (line
.size() >= comment
.length()-1) {
97 if (line
.left(comment
.length()-1) != comment
.left(comment
.length()-1)) {
105 buffer
+= line
+ "\n";
110 QFile
file(filename
);
111 file
.open(QIODevice::WriteOnly
);
112 QTextStream
f(&file
);
118 ///\todo replace with shellscript?
119 void makeDistribution()
121 system ("ldd ./engrid > ldd.out");
122 system ("mkdir enGrid");
123 system ("cp engrid enGrid");
125 QFile
file("ldd.out");
126 file
.open(QIODevice::ReadOnly
);
127 QTextStream
f(&file
);
129 QString line
= f
.readLine();
130 QTextStream
l(&line
, QIODevice::ReadOnly
);
133 if (word
.left(1) != "/") {
137 QString cmd
= "cp " + word
+ " enGrid";
138 system(qPrintable(cmd
));
139 cout
<< qPrintable(cmd
) << endl
;
142 system ("tar czf enGrid_bin.tar.gz enGrid/*");
143 system ("rm -rf enGrid");
144 system ("rm ldd.out");
147 /** Message handler to allow output of Qt objects in the terminal (stderr) or the logfile/output window of engrid (stdout)
148 qDebug() is used for writing custom debug output.
149 qWarning() is used to report warnings and recoverable errors in your application.
150 qCritical() is used for writing critical error mesages and reporting system errors.
151 qFatal() is used for writing fatal error messages shortly before exiting.
153 void engridMessageHandler(QtMsgType type
, const char *msg
)
157 // fprintf(stdout, "%s", msg);
161 // fprintf(stderr, "%s", msg);
165 fprintf(stderr
, "Critical: %s\n", msg
);
168 fprintf(stderr
, "Fatal: %s\n", msg
);
173 double getNumber(QString text
)
181 // This code converts from string to number safely.
182 stringstream
myStream(input
);
183 if (myStream
>> myNumber
)
185 qDebug() << "Invalid number, please try again" << endl
;
190 int main( int argc
, char ** argv
)
194 //omp_set_num_threads(1);
196 qInstallMsgHandler(engridMessageHandler
);
197 Q_INIT_RESOURCE(engrid
);
200 ///\todo use gnu getopt ? Check windows/mac compatibility.
202 if (QString(argv
[1]) == QString("-h")) {
203 QFileInfo
file_info(argv
[0]);
204 cout
<<"Usage:"<<endl
;
205 cout
<<qPrintable(file_info
.fileName())<<" : start engrid"<<endl
;
206 cout
<<qPrintable(file_info
.fileName())<<" -f FILE : start engrid and open FILE"<<endl
;
207 cout
<<qPrintable(file_info
.fileName())<<" -h : Display usage instructions"<<endl
;
208 cout
<<qPrintable(file_info
.fileName())<<" -appendlic FILE1 FILE2 ...: Append license to files"<<endl
;
209 cout
<<qPrintable(file_info
.fileName())<<" -distbin : Create binary distribution"<<endl
;
212 if (QString(argv
[1]) == QString("-appendlic")) {
213 appendLicense(argc
, argv
);
215 if (QString(argv
[1]) == QString("-distbin")) {
218 if (QString(argv
[1]) == QString("-f") && argc
== 3) {
219 QApplication
a( argc
, argv
);
220 QString filename
= QString(argv
[2]);
221 GuiMainWindow
w(filename
);
223 a
.connect( &a
, SIGNAL( lastWindowClosed() ), &a
, SLOT( quit() ) );
224 app_result
= a
.exec();
227 QApplication
a( argc
, argv
);
230 a
.connect( &a
, SIGNAL( lastWindowClosed() ), &a
, SLOT( quit() ) );
231 app_result
= a
.exec();