[88] | 1 | /* |
---|
| 2 | * $Id: Environment.cpp 137 2010-02-16 12:35:48Z 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" |
---|
[97] | 11 | #include "Common/include/Message.h" |
---|
[88] | 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; |
---|
[137] | 19 | std::string MORPHEO_VERSION; |
---|
| 20 | std::string MORPHEO_HEADER; |
---|
| 21 | std::string MORPHEO_DATE; |
---|
[88] | 22 | |
---|
| 23 | #undef FUNCTION |
---|
| 24 | #define FUNCTION "environment" |
---|
| 25 | void environment (void) |
---|
| 26 | { |
---|
| 27 | if (not environment_initialized) |
---|
| 28 | { |
---|
| 29 | { |
---|
[137] | 30 | char * TOPLEVEL = getenv("MORPHEO_TOPLEVEL"); |
---|
[88] | 31 | |
---|
[137] | 32 | if (TOPLEVEL == NULL) |
---|
[88] | 33 | throw ERRORMORPHEO(FUNCTION,_("Error morpheo environment is not positioned.\n")); |
---|
| 34 | |
---|
[137] | 35 | MORPHEO_TOPLEVEL = TOPLEVEL; |
---|
[88] | 36 | } |
---|
| 37 | |
---|
| 38 | { |
---|
[137] | 39 | char * HOME = getenv("MORPHEO_HOME"); |
---|
[88] | 40 | |
---|
[137] | 41 | if (HOME == NULL) |
---|
[88] | 42 | throw ERRORMORPHEO(FUNCTION,_("Error morpheo environment is not positioned.\n")); |
---|
| 43 | |
---|
[137] | 44 | MORPHEO_HOME = HOME; |
---|
[88] | 45 | } |
---|
| 46 | |
---|
[137] | 47 | { |
---|
| 48 | char * MAJOR_VERSION = getenv("MORPHEO_MAJOR_VERSION"); |
---|
| 49 | char * MINOR_VERSION = getenv("MORPHEO_MINOR_VERSION"); |
---|
| 50 | char * REVISION = getenv("MORPHEO_REVISION"); |
---|
| 51 | char * CODENAME = getenv("MORPHEO_CODENAME"); |
---|
| 52 | char * DATE_DAY = getenv("MORPHEO_DATE_DAY"); |
---|
| 53 | char * DATE_MONTH = getenv("MORPHEO_DATE_MONTH"); |
---|
| 54 | char * DATE_YEAR = getenv("MORPHEO_DATE_YEAR"); |
---|
| 55 | |
---|
| 56 | if ((MAJOR_VERSION == NULL) or |
---|
| 57 | (MINOR_VERSION == NULL) or |
---|
| 58 | (REVISION == NULL) or |
---|
| 59 | (CODENAME == NULL) or |
---|
| 60 | (DATE_DAY == NULL) or |
---|
| 61 | (DATE_MONTH == NULL) or |
---|
| 62 | (DATE_YEAR == NULL)) |
---|
| 63 | throw ERRORMORPHEO(FUNCTION,_("Error morpheo environment is not positioned.\n")); |
---|
| 64 | |
---|
| 65 | MORPHEO_VERSION = toString(MAJOR_VERSION)+"."+toString(MINOR_VERSION)+"."+toString(REVISION); |
---|
| 66 | MORPHEO_HEADER = MORPHEO_VERSION+" - "+toString(CODENAME); |
---|
| 67 | MORPHEO_DATE = toString(DATE_YEAR)+"/"+toString(DATE_MONTH)+"/"+toString(DATE_DAY); |
---|
| 68 | } |
---|
| 69 | |
---|
[88] | 70 | environment_initialized = true; |
---|
| 71 | } |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | static bool directory_initialized; |
---|
| 75 | std::string MORPHEO_STATISTICS; |
---|
| 76 | std::string MORPHEO_VHDL; |
---|
| 77 | std::string MORPHEO_POSITION; |
---|
| 78 | std::string MORPHEO_LOG; |
---|
| 79 | |
---|
| 80 | #undef FUNCTION |
---|
| 81 | #define FUNCTION "exist_directory" |
---|
| 82 | void exist_directory (std::string dir) |
---|
| 83 | { |
---|
| 84 | // struct stat *buf; |
---|
| 85 | // int res = stat(dir.c_str(), buf); |
---|
| 86 | // if ((res != 0) or not S_ISDIR(buf->st_mode)) |
---|
| 87 | // throw ERRORMORPHEO(FUNCTION,toString(_("Error in opening directory \"%s\".\n"),dir.c_str())); |
---|
| 88 | |
---|
| 89 | |
---|
| 90 | char * pwd = getenv("PWD"); |
---|
| 91 | if (chdir(dir.c_str())!=0) |
---|
| 92 | throw ERRORMORPHEO(FUNCTION,toString(_("Error in opening directory \"%s\".\n"),dir.c_str())); |
---|
| 93 | chdir(pwd); |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | #undef FUNCTION |
---|
| 97 | #define FUNCTION "directory_init" |
---|
| 98 | void directory_init (std::string morpheo_statistics, |
---|
| 99 | std::string morpheo_vhdl , |
---|
| 100 | std::string morpheo_position , |
---|
| 101 | std::string morpheo_log ) |
---|
| 102 | { |
---|
| 103 | if (not directory_initialized) |
---|
| 104 | { |
---|
| 105 | exist_directory(morpheo_statistics); |
---|
| 106 | exist_directory(morpheo_vhdl ); |
---|
| 107 | exist_directory(morpheo_position ); |
---|
| 108 | exist_directory(morpheo_log ); |
---|
| 109 | |
---|
| 110 | MORPHEO_STATISTICS = morpheo_statistics; |
---|
| 111 | MORPHEO_VHDL = morpheo_vhdl ; |
---|
| 112 | MORPHEO_POSITION = morpheo_position ; |
---|
| 113 | MORPHEO_LOG = morpheo_log ; |
---|
| 114 | |
---|
| 115 | directory_initialized = true; |
---|
| 116 | } |
---|
| 117 | // else |
---|
| 118 | // { |
---|
| 119 | // msg_printf(WARNING,_("Multi instance of Morpheo : directory, keep actual directory.")); |
---|
| 120 | // } |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | #undef FUNCTION |
---|
| 124 | #define FUNCTION "directory" |
---|
| 125 | void directory (void) |
---|
| 126 | { |
---|
| 127 | // with default value |
---|
| 128 | directory_init(); |
---|
| 129 | }; |
---|
| 130 | |
---|
| 131 | }; //end namespace morpheo |
---|