source: trunk/IPs/systemC/processor/Morpheo/Common/src/Environment.cpp @ 137

Last change on this file since 137 was 137, checked in by rosiere, 14 years ago

Various modif (add test, and vhdl)

  • Property svn:keywords set to Id
File size: 3.6 KB
Line 
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"
11#include "Common/include/Message.h"
12#include <sys/stat.h>
13
14namespace morpheo {
15
16static bool environment_initialized;
17std::string MORPHEO_HOME;
18std::string MORPHEO_TOPLEVEL;
19std::string MORPHEO_VERSION;
20std::string MORPHEO_HEADER;
21std::string MORPHEO_DATE;
22
23#undef  FUNCTION
24#define FUNCTION "environment"
25void environment (void)
26{
27  if (not environment_initialized)
28    {
29      {
30        char * TOPLEVEL = getenv("MORPHEO_TOPLEVEL");
31       
32        if (TOPLEVEL == NULL)
33          throw ERRORMORPHEO(FUNCTION,_("Error morpheo environment is not positioned.\n"));
34
35        MORPHEO_TOPLEVEL = TOPLEVEL;
36      }
37
38      {
39        char * HOME = getenv("MORPHEO_HOME");
40       
41        if (HOME == NULL)
42          throw ERRORMORPHEO(FUNCTION,_("Error morpheo environment is not positioned.\n"));
43
44        MORPHEO_HOME = HOME;
45      }
46
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
70      environment_initialized = true;
71    }
72}
73
74static bool directory_initialized;
75std::string MORPHEO_STATISTICS;
76std::string MORPHEO_VHDL;
77std::string MORPHEO_POSITION;
78std::string MORPHEO_LOG;
79
80#undef  FUNCTION
81#define FUNCTION "exist_directory"
82void 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"
98void 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"
125void directory (void)
126{
127  // with default value
128  directory_init();
129};
130
131}; //end namespace morpheo
Note: See TracBrowser for help on using the repository browser.