2 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 // + This file is part of enGrid. +
6 // + Copyright 2008-2010 enGits GmbH +
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 comment
= "// ";
60 if (filename
.right(3) == ".sh") script
= true;
61 if (filename
.right(3) == ".py") script
= true;
62 if (filename
.right(5) == ".bash") script
= true;
64 file
.open(QIODevice::ReadOnly
);
68 QString line
= f
.readLine();
69 buffer
+= line
+ "\n";
71 buffer
+= comment
+ "\n";
72 buffer
+= comment
+ "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
73 buffer
+= comment
+ "+ +\n";
74 buffer
+= comment
+ "+ This file is part of enGrid. +\n";
75 buffer
+= comment
+ "+ +\n";
76 buffer
+= comment
+ "+ Copyright " + year_text
+ " enGits GmbH" + year_end_text
;
77 buffer
+= comment
+ "+ +\n";
78 buffer
+= comment
+ "+ enGrid is free software: you can redistribute it and/or modify +\n";
79 buffer
+= comment
+ "+ it under the terms of the GNU General Public License as published by +\n";
80 buffer
+= comment
+ "+ the Free Software Foundation, either version 3 of the License, or +\n";
81 buffer
+= comment
+ "+ (at your option) any later version. +\n";
82 buffer
+= comment
+ "+ +\n";
83 buffer
+= comment
+ "+ enGrid is distributed in the hope that it will be useful, +\n";
84 buffer
+= comment
+ "+ but WITHOUT ANY WARRANTY; without even the implied warranty of +\n";
85 buffer
+= comment
+ "+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +\n";
86 buffer
+= comment
+ "+ GNU General Public License for more details. +\n";
87 buffer
+= comment
+ "+ +\n";
88 buffer
+= comment
+ "+ You should have received a copy of the GNU General Public License +\n";
89 buffer
+= comment
+ "+ along with enGrid. If not, see <http://www.gnu.org/licenses/>. +\n";
90 buffer
+= comment
+ "+ +\n";
91 buffer
+= comment
+ "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n";
92 buffer
+= comment
+ "\n";
94 bool src_code
= false;
96 QString line
= f
.readLine();
98 if (line
.size() >= comment
.length()-1) {
99 if (line
.left(comment
.length()-1) != comment
.left(comment
.length()-1)) {
107 buffer
+= line
+ "\n";
112 QFile
file(filename
);
113 file
.open(QIODevice::WriteOnly
);
114 QTextStream
f(&file
);
120 ///\todo replace with shellscript?
121 void makeDistribution()
123 system ("ldd ./engrid > ldd.out");
124 system ("mkdir enGrid");
125 system ("cp engrid enGrid");
127 QFile
file("ldd.out");
128 file
.open(QIODevice::ReadOnly
);
129 QTextStream
f(&file
);
131 QString line
= f
.readLine();
132 QTextStream
l(&line
, QIODevice::ReadOnly
);
135 if (word
.left(1) != "/") {
139 QString cmd
= "cp " + word
+ " enGrid";
140 system(qPrintable(cmd
));
141 cout
<< qPrintable(cmd
) << endl
;
144 system ("tar czf enGrid_bin.tar.gz enGrid/*");
145 system ("rm -rf enGrid");
146 system ("rm ldd.out");
149 /** Message handler to allow output of Qt objects in the terminal (stderr) or the logfile/output window of engrid (stdout)
150 qDebug() is used for writing custom debug output.
151 qWarning() is used to report warnings and recoverable errors in your application.
152 qCritical() is used for writing critical error mesages and reporting system errors.
153 qFatal() is used for writing fatal error messages shortly before exiting.
155 void engridMessageHandler(QtMsgType type
, const char *msg
)
159 // fprintf(stdout, "%s", msg);
163 // fprintf(stderr, "%s", msg);
167 fprintf(stderr
, "Critical: %s\n", msg
);
170 fprintf(stderr
, "Fatal: %s\n", msg
);
175 double getNumber(QString text
)
183 // This code converts from string to number safely.
184 stringstream
myStream(input
);
185 if (myStream
>> myNumber
)
187 qDebug() << "Invalid number, please try again" << endl
;
192 int main( int argc
, char ** argv
)
199 // x^3 + a x^2 + b x + c = 0
203 N = poly_solve_cubic( a, b, c, &(x[0]), &(x[1]), &(x[2]));
204 qDebug()<<"x^3 + "<<a<<" *x^2 + "<<b<<" *x + "<<c<<" = 0";
205 for(int i=0;i<N;i++) qDebug()<<"x["<<i<<"]="<<x[i];
207 // a x^2 + b x + c = 0
211 N = poly_solve_quadratic( a, b, c, &(x[0]), &(x[1]));
212 qDebug()<<a<<" *x^2 + "<<b<<" *x + "<<c<<" = 0";
213 for(int i=0;i<N;i++) qDebug()<<"x["<<i<<"]="<<x[i];
217 qInstallMsgHandler(engridMessageHandler
);
218 Q_INIT_RESOURCE(engrid
);
220 ///\todo use gnu getopt ? Check windows/mac compatibility.
222 if (QString(argv
[1]) == QString("-h")) {
223 QFileInfo
file_info(argv
[0]);
224 cout
<<"Usage:"<<endl
;
225 cout
<<qPrintable(file_info
.fileName())<<" : start engrid"<<endl
;
226 cout
<<qPrintable(file_info
.fileName())<<" -f FILE : start engrid and open FILE"<<endl
;
227 cout
<<qPrintable(file_info
.fileName())<<" -h : Display usage instructions"<<endl
;
228 cout
<<qPrintable(file_info
.fileName())<<" -appendlic FILE1 FILE2 ...: Append license to files"<<endl
;
229 cout
<<qPrintable(file_info
.fileName())<<" -distbin : Create binary distribution"<<endl
;
232 if (QString(argv
[1]) == QString("-appendlic")) {
233 appendLicense(argc
, argv
);
235 if (QString(argv
[1]) == QString("-distbin")) {
238 if (QString(argv
[1]) == QString("-f") && argc
== 3) {
239 QApplication
a( argc
, argv
);
240 QString filename
= QString(argv
[2]);
241 GuiMainWindow
w(filename
);
243 a
.connect( &a
, SIGNAL( lastWindowClosed() ), &a
, SLOT( quit() ) );
247 QApplication
a( argc
, argv
);
250 a
.connect( &a
, SIGNAL( lastWindowClosed() ), &a
, SLOT( quit() ) );