summaryrefslogtreecommitdiff
path: root/generic/Main.cpp
blob: 774cf082504cfcd5779b50bd8f3ed88166431979 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "Main.h"
#include "generic.h"
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

Main::Main() : setted(false) {}

Main::~Main() {}

extern Main * Application;

void Main::set_args(int a_argc, char ** a_argv, char ** a_enve) {
    if (setted) {
	return;
    }
    argc = a_argc;
    argv = a_argv;
    enve = a_enve;
    setted = true;
}

int main(int argc, char ** argv, char ** enve) {
    int r;
    
    try {
	Application->set_args(argc, argv, enve);
	r = Application->startup();
    }
    catch (Exit e) {
	r = e.GetCode();
    }
    catch (GeneralException e) {
	printm(M_ERROR, "The application caused an exception: %s\n", e.GetMsg());
	delete Application;
	exit(-1);
    }
    catch (...) {
	printm(M_ERROR, "The application caused an unknow exception\n");
	delete Application;
	exit(-1);
    }
    delete Application;
    exit(r);
}