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

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

1) compatible gcc 4.4.3
2) Translation file in MORPHEO_PREFIX directory

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