1 /* BurrTools
2 *
3 * BurrTools is the legal property of its developers, whose
4 * names are listed in the COPYRIGHT file, which is included
5 * within the source distribution.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11
12 * This program 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.
16
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21
22
23 #include "mainwindow.h"
24 #include "assertwindow.h"
25
26 #include <FL/Fl.H>
27
28 #include <time.h>
29
30 #include "../lib/bt_assert.h"
31 #include "../lib/gridtype.h"
32 #include "../lib/puzzle.h"
33
34 #include "../tools/xml.h"
35 #include "../tools/gzstream.h"
36
37 class my_Fl : public Fl {
38
39 public:
40
run(mainWindow_c * ui)41 static int run(mainWindow_c * ui) {
42
43 time_t start = time(0);
44
45 while (Fl::first_window()) {
46 wait(0.5);
47 if (time(0)-start >= 1) {
48 ui->update();
49 start = time(0);
50 }
51 }
52
53 return 0;
54 }
55 };
56
main(int argc,char ** argv)57 int main(int argc, char ** argv) {
58
59 bt_assert_init();
60
61 Fl::set_boxtype(FL_UP_BOX, FL_THIN_UP_BOX);
62 Fl::set_boxtype(FL_DOWN_BOX, FL_THIN_DOWN_BOX);
63 Fl::set_boxtype(FL_UP_FRAME, FL_THIN_UP_FRAME);
64 Fl::set_boxtype(FL_DOWN_FRAME, FL_THIN_DOWN_FRAME);
65
66 Fl::get_system_colors();
67
68 mainWindow_c *ui = new mainWindow_c(new gridType_c());
69
70 int res = 0;
71
72 try {
73
74 ui->show(argc, argv);
75
76 res = my_Fl::run(ui);
77 }
78
79 catch (assert_exception a) {
80
81 assertWindow_c * aw = new assertWindow_c("I'm sorry there is a bug in this program. It needs to be closed.\n"
82 "I try to save the current puzzle in '__rescue.xmpuzzle'\n",
83 &a);
84
85 aw->show();
86
87 while (aw->visible())
88 Fl::wait();
89
90 delete aw;
91
92 ogzstream ostr("__rescue.xmpuzzle");
93
94 if (ostr)
95 {
96 xmlWriter_c xml(ostr);
97 ui->getPuzzle()->save(xml);
98 }
99
100 return -1;
101 }
102
103 catch (...) {
104 printf(" exception\n");
105 }
106
107 delete ui;
108 return res;
109 }
110