2 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 // + This file is part of enGrid. +
6 // + Copyright 2008,2009 Oliver Gloth +
8 // + enGrid is free software: you can redistribute it and/or modify +
9 // + it under the terms of the GNU General Public License as published by +
10 // + the Free Software Foundation, either version 3 of the License, or +
11 // + (at your option) any later version. +
13 // + enGrid is distributed in the hope that it will be useful, +
14 // + but WITHOUT ANY WARRANTY; without even the implied warranty of +
15 // + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +
16 // + GNU General Public License for more details. +
18 // + You should have received a copy of the GNU General Public License +
19 // + along with enGrid. If not, see <http://www.gnu.org/licenses/>. +
21 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
25 #include <QApplication>
27 #include <QTextStream>
30 #include "guimainwindow.h"
31 #include "filetemplate.h"
33 #include "geometrytools.h"
34 using namespace GeometryTools
;
36 ///@@@ TODO: replace with shellscript?
37 void appendLicense(int argc
, char ** argv
)
39 int first_year
= 2008;
40 QString first_year_text
;
41 first_year_text
.setNum(first_year
);
42 int year
= QDate::currentDate().year();
44 year_text
.setNum(year
);
45 if (year
-first_year
== 1) {
46 year_text
= first_year_text
+ "," + year_text
;
48 if (year
-first_year
> 1) {
49 year_text
= first_year_text
+ "-" + year_text
;
51 QString year_end_text
= " +\n";
52 if (year
== first_year
) {
53 year_end_text
= " " + year_end_text
;
55 for (int i
= 2; i
< argc
; ++i
) {
56 QString
filename(argv
[i
]);
57 QString buffer
= "//\n";
58 buffer
+= "// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
60 buffer
+= "// + This file is part of enGrid. +\n";
62 buffer
+= "// + Copyright " + year_text
+ " Oliver Gloth" + year_end_text
;
64 buffer
+= "// + enGrid is free software: you can redistribute it and/or modify +\n";
65 buffer
+= "// + it under the terms of the GNU General Public License as published by +\n";
66 buffer
+= "// + the Free Software Foundation, either version 3 of the License, or +\n";
67 buffer
+= "// + (at your option) any later version. +\n";
69 buffer
+= "// + enGrid is distributed in the hope that it will be useful, +\n";
70 buffer
+= "// + but WITHOUT ANY WARRANTY; without even the implied warranty of +\n";
71 buffer
+= "// + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +\n";
72 buffer
+= "// + GNU General Public License for more details. +\n";
74 buffer
+= "// + You should have received a copy of the GNU General Public License +\n";
75 buffer
+= "// + along with enGrid. If not, see <http://www.gnu.org/licenses/>. +\n";
77 buffer
+= "// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
80 bool src_code
= false;
82 file
.open(QIODevice::ReadOnly
);
85 QString line
= f
.readLine();
87 if (line
.size() >= 2) {
88 if (line
.left(2) != "//") {
96 buffer
+= line
+ "\n";
101 QFile
file(filename
);
102 file
.open(QIODevice::WriteOnly
);
103 QTextStream
f(&file
);
109 ///@@@ TODO: replace with shellscript?
110 void makeDistribution()
112 system ("ldd ./engrid > ldd.out");
113 system ("mkdir enGrid");
114 system ("cp engrid enGrid");
115 system ("cp start_engrid enGrid");
117 QFile
file("ldd.out");
118 file
.open(QIODevice::ReadOnly
);
119 QTextStream
f(&file
);
121 QString line
= f
.readLine();
122 QTextStream
l(&line
, QIODevice::ReadOnly
);
125 if (word
.left(1) != "/") {
129 QString cmd
= "cp " + word
+ " enGrid";
130 system(qPrintable(cmd
));
131 cout
<< qPrintable(cmd
) << endl
;
134 system ("tar czf enGrid_bin.tar.gz enGrid/*");
135 system ("rm -rf enGrid");
136 system ("rm ldd.out");
139 /** Message handler to allow output of Qt objects in the terminal (stderr) or the logfile/output window of engrid (stdout)
140 qDebug() is used for writing custom debug output.
141 qWarning() is used to report warnings and recoverable errors in your application.
142 qCritical() is used for writing critical error mesages and reporting system errors.
143 qFatal() is used for writing fatal error messages shortly before exiting.
145 void engridMessageHandler(QtMsgType type
, const char *msg
)
149 // fprintf(stdout, "%s", msg);
153 // fprintf(stderr, "%s", msg);
157 fprintf(stderr
, "Critical: %s\n", msg
);
160 fprintf(stderr
, "Fatal: %s\n", msg
);
165 int main( int argc
, char ** argv
)
167 qInstallMsgHandler(engridMessageHandler
);
168 Q_INIT_RESOURCE(engrid
);
170 ///@@@ TODO: use gnu getopt ? Check windows/mac compatibility.
172 if (QString(argv
[1]) == QString("-h")) {
173 QFileInfo
file_info(argv
[0]);
174 cout
<<"Usage:"<<endl
;
175 cout
<<qPrintable(file_info
.fileName())<<" : start engrid"<<endl
;
176 cout
<<qPrintable(file_info
.fileName())<<" -f FILE : start engrid and open FILE"<<endl
;
177 cout
<<qPrintable(file_info
.fileName())<<" -h : Display usage instructions"<<endl
;
178 cout
<<qPrintable(file_info
.fileName())<<" -appendlic FILE1 FILE2 ...: Append license to files"<<endl
;
179 cout
<<qPrintable(file_info
.fileName())<<" -distbin : Create binary distribution"<<endl
;
182 if (QString(argv
[1]) == QString("-appendlic")) {
183 appendLicense(argc
, argv
);
185 if (QString(argv
[1]) == QString("-distbin")) {
188 if (QString(argv
[1]) == QString("-f") && argc
== 3) {
189 QApplication
a( argc
, argv
);
192 a
.connect( &a
, SIGNAL( lastWindowClosed() ), &a
, SLOT( quit() ) );
193 GuiMainWindow::pointer()->open(QString(argv
[2]));//this could aventually be done with another GuiMainWindow constructor
197 QApplication
a( argc
, argv
);
200 a
.connect( &a
, SIGNAL( lastWindowClosed() ), &a
, SLOT( quit() ) );