1 | /* |
---|
2 | * $Id: Environment.cpp 97 2008-12-19 15:34:00Z rosiere $ |
---|
3 | * |
---|
4 | * [ Description ] |
---|
5 | * |
---|
6 | */ |
---|
7 | |
---|
8 | #include "Common/include/Environment.h" |
---|
9 | #include "Common/include/ErrorMorpheo.h" |
---|
10 | #include "Common/include/Debug.h" |
---|
11 | #include "Common/include/Message.h" |
---|
12 | #include <sys/stat.h> |
---|
13 | |
---|
14 | namespace morpheo { |
---|
15 | |
---|
16 | static bool environment_initialized; |
---|
17 | std::string MORPHEO_HOME; |
---|
18 | std::string MORPHEO_TOPLEVEL; |
---|
19 | |
---|
20 | #undef FUNCTION |
---|
21 | #define FUNCTION "environment" |
---|
22 | void environment (void) |
---|
23 | { |
---|
24 | if (not environment_initialized) |
---|
25 | { |
---|
26 | { |
---|
27 | char * toplevel = getenv("MORPHEO_TOPLEVEL"); |
---|
28 | |
---|
29 | if (toplevel == NULL) |
---|
30 | throw ERRORMORPHEO(FUNCTION,_("Error morpheo environment is not positioned.\n")); |
---|
31 | |
---|
32 | MORPHEO_TOPLEVEL = toplevel; |
---|
33 | } |
---|
34 | |
---|
35 | { |
---|
36 | char * home = getenv("MORPHEO_HOME"); |
---|
37 | |
---|
38 | if (home == NULL) |
---|
39 | throw ERRORMORPHEO(FUNCTION,_("Error morpheo environment is not positioned.\n")); |
---|
40 | |
---|
41 | MORPHEO_HOME = home; |
---|
42 | } |
---|
43 | |
---|
44 | environment_initialized = true; |
---|
45 | } |
---|
46 | } |
---|
47 | |
---|
48 | static bool directory_initialized; |
---|
49 | std::string MORPHEO_STATISTICS; |
---|
50 | std::string MORPHEO_VHDL; |
---|
51 | std::string MORPHEO_POSITION; |
---|
52 | std::string MORPHEO_LOG; |
---|
53 | |
---|
54 | #undef FUNCTION |
---|
55 | #define FUNCTION "exist_directory" |
---|
56 | void exist_directory (std::string dir) |
---|
57 | { |
---|
58 | // struct stat *buf; |
---|
59 | // int res = stat(dir.c_str(), buf); |
---|
60 | // if ((res != 0) or not S_ISDIR(buf->st_mode)) |
---|
61 | // throw ERRORMORPHEO(FUNCTION,toString(_("Error in opening directory \"%s\".\n"),dir.c_str())); |
---|
62 | |
---|
63 | |
---|
64 | char * pwd = getenv("PWD"); |
---|
65 | if (chdir(dir.c_str())!=0) |
---|
66 | throw ERRORMORPHEO(FUNCTION,toString(_("Error in opening directory \"%s\".\n"),dir.c_str())); |
---|
67 | chdir(pwd); |
---|
68 | } |
---|
69 | |
---|
70 | #undef FUNCTION |
---|
71 | #define FUNCTION "directory_init" |
---|
72 | void directory_init (std::string morpheo_statistics, |
---|
73 | std::string morpheo_vhdl , |
---|
74 | std::string morpheo_position , |
---|
75 | std::string morpheo_log ) |
---|
76 | { |
---|
77 | if (not directory_initialized) |
---|
78 | { |
---|
79 | exist_directory(morpheo_statistics); |
---|
80 | exist_directory(morpheo_vhdl ); |
---|
81 | exist_directory(morpheo_position ); |
---|
82 | exist_directory(morpheo_log ); |
---|
83 | |
---|
84 | MORPHEO_STATISTICS = morpheo_statistics; |
---|
85 | MORPHEO_VHDL = morpheo_vhdl ; |
---|
86 | MORPHEO_POSITION = morpheo_position ; |
---|
87 | MORPHEO_LOG = morpheo_log ; |
---|
88 | |
---|
89 | directory_initialized = true; |
---|
90 | } |
---|
91 | // else |
---|
92 | // { |
---|
93 | // msg_printf(WARNING,_("Multi instance of Morpheo : directory, keep actual directory.")); |
---|
94 | // } |
---|
95 | } |
---|
96 | |
---|
97 | #undef FUNCTION |
---|
98 | #define FUNCTION "directory" |
---|
99 | void directory (void) |
---|
100 | { |
---|
101 | // with default value |
---|
102 | directory_init(); |
---|
103 | }; |
---|
104 | |
---|
105 | }; //end namespace morpheo |
---|