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

Last change on this file since 88 was 88, checked in by rosiere, 16 years ago

Almost complete design
with Test and test platform

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