source: CMT/v1r25p20130606/source/cmt_system.h

Last change on this file was 610, checked in by rybkin, 12 years ago

See C.L. 485

  • Property svn:eol-style set to native
File size: 7.1 KB
Line 
1//-----------------------------------------------------------
2// Copyright Christian Arnault LAL-Orsay CNRS
3// arnault@lal.in2p3.fr
4// See the complete license in cmt_license.txt "http://www.cecill.info".
5//-----------------------------------------------------------
6
7#ifndef __cmt_system_h__
8#define __cmt_system_h__
9
10#include "cmt_std.h"
11#include "cmt_string.h"
12#include "cmt_vector.h"
13#include "cmt_regexp.h"
14
15class Project;
16
17class IProjectFactory
18{
19public:
20  virtual void reset () = 0;
21  virtual Project* create_project (const cmt_string& name,
22                                   const cmt_string& path,
23                                   const cmt_string& path_source,
24                                   Project* parent) = 0;
25};
26
27class CmtSystem
28{
29public:
30  typedef cmt_vector<cmt_string> cmt_string_vector;
31
32  static cmt_string pwd ();
33  static bool cd (const cmt_string& dir);
34
35  static void basename (const cmt_string& file_name, cmt_string& result);
36  static void basename (const cmt_string& file_name,
37                        const cmt_string& suffix,
38                        cmt_string& result);
39
40  // Resolve symbolic links in a path.
41  static bool realpath (const cmt_string& path, cmt_string& result);
42  // Currently the above does not resolve symbolic links in a path.
43  static bool realpath_ (const cmt_string& path, cmt_string& result);
44
45  static void dirname (const cmt_string& file_name, cmt_string& result);
46
47  static void name (const cmt_string& file, cmt_string& result);
48
49  static void get_suffix (const cmt_string& file, cmt_string& result);
50  static void get_dot_suffix (const cmt_string& file, cmt_string& result);
51  static bool has_prefix (const cmt_string& name);
52  static bool absolute_path (const cmt_string& name);
53  static bool has_device (const cmt_string& name);
54
55  static cmt_string current_branch ();
56
57    /**
58     * Implementation of the "test -d" equivalent
59     */
60  static bool test_directory (const cmt_string& name);
61    /**
62     * Implementation of the "test -f" equivalent
63     */               
64  static bool test_file (const cmt_string& name);
65    /**
66     * Implementation of the "touch" function equivalent
67     */               
68  static bool touch_file (const cmt_string& name);   
69    /**
70     * Check if the file "name1" is identical to "name2"
71     */
72  static bool compare_files (const cmt_string& name1,
73                             const cmt_string& name2);
74    /**
75     * Check if the file "name1" is identical to "name2"
76     * if they are identical, "name1" will be simply deleted
77     * otherwise "name1" will be copied to "name2" and deleted afterwards
78     */
79  static bool compare_and_update_files (const cmt_string& name1,
80                                        const cmt_string& name2);
81  static int file_size (const cmt_string& name);
82  inline static char file_separator ()
83    {
84#ifdef WIN32
85      return ('\\');
86#else
87      return ('/');
88#endif
89    }
90  static void reduce_file_separators (cmt_string& text);
91  inline static char path_separator ()
92    {
93#ifdef WIN32
94      return (';');
95#else
96      return (':');
97#endif
98    }
99  inline static char command_separator ()
100    {
101#ifdef WIN32
102      return ('&');
103#else
104      return (';');
105#endif
106    }
107  //static const char* cwd_variable ();
108  static const cmt_string& ev_open ();
109  static const cmt_string& ev_close ();
110  static bool create_symlink (const cmt_string& oldname,
111                              const cmt_string& newname);
112  static bool remove_file (const cmt_string& name);
113  static bool remove_directory (const cmt_string& name);
114  static bool mkdir (const cmt_string& name);
115  static void scan_dir (const cmt_string& dir_name,
116                        cmt_string_vector& list);
117  static void scan_dir (const cmt_string& dir_name,
118                        const cmt_regexp& expression,
119                        cmt_string_vector& list);
120  static cmt_string_vector& scan_dir (const cmt_string& dir_name);
121  static const cmt_string& get_cmt_root ();
122  static void get_cmt_version (cmt_string& version);
123  static cmt_string get_cmt_config ();
124  static cmt_string get_cmt_site ();
125  static void get_uname (cmt_string& uname);
126  static void get_hosttype (cmt_string& hosttype);
127  static cmt_string get_temporary_name ();
128 
129  static cmt_string get_home_package ();
130  static bool is_home_package (const cmt_string& name,
131                               const cmt_string& version);
132 
133  static cmt_string get_user_context_package ();
134  static bool is_user_context_package (const cmt_string& name,
135                                       const cmt_string& version);
136 
137  static cmt_string get_project_package ();
138  static bool is_project_package (const cmt_string& name,
139                                  const cmt_string& version);
140 
141  static bool testenv (const cmt_string& name);
142  static cmt_string getenv (const cmt_string& name);
143  static bool putenv (const cmt_string& name, const cmt_string& value);
144  static void get_cmt_paths (IProjectFactory& factory,
145                             const cmt_string& init_text,
146                             const cmt_string& cmt_user_context,
147                             const cmt_string& cmt_home);
148  static int execute (const cmt_string& command);
149  static int execute (const cmt_string& command, cmt_string& output);
150  static bool is_package_directory (const cmt_string& name);
151  static bool is_version_directory (const cmt_string& name);
152  static bool is_version_directory (const cmt_string& name, int& v, int& r, int& p);
153  static void split (const cmt_string& text,
154                     const cmt_string& separators,
155                     cmt_string_vector& strings,
156                     const bool& unquote = true);
157  static cmt_string quote (const cmt_string& text,
158                           const cmt_string& separators);
159  static int mangle (const cmt_string& text, cmt_string& out);
160  static cmt_string mangle (const cmt_string& text);
161
162  static void compress_path (const cmt_string& dir, cmt_string& new_dir);
163  static void compress_path (cmt_string& dir);
164
165  static cmt_string now ();
166  static cmt_string user ();
167
168  static void get_cvsroot (cmt_string& cvsroot);
169
170  static bool get_home_directory (cmt_string& dir);
171
172  static cmt_string get_makefile_suffix ();
173
174  static void close_ostream (FILE *stream, const cmt_string& name = "" );
175  static void close_stdout (void);
176
177};
178
179class FilePath
180{
181public:
182
183  FilePath ();
184
185  FilePath (const FilePath& other);
186  FilePath (const cmt_string& other);
187  FilePath (const char* other);
188
189  FilePath& operator = (const FilePath& other);
190  FilePath& operator = (const cmt_string& other);
191  FilePath& operator = (const char* other);
192
193  bool operator == (const FilePath& other) const;
194  bool operator == (const cmt_string& other) const;
195  bool operator == (const char* other) const;
196
197  bool operator != (const FilePath& other) const;
198  bool operator != (const cmt_string& other) const;
199  bool operator != (const char* other) const;
200
201  const cmt_string& name () const;
202  operator const cmt_string& () const;
203
204  bool in (const FilePath& other) const;
205  bool in (const cmt_string& other) const;
206  bool in (const char* other) const;
207
208  bool cd () const;
209
210private:
211
212  void set (const FilePath& other);
213  void set (const cmt_string& other);
214  void set (const char* other);
215
216  cmt_string p_name; // physical name
217  cmt_string l_name; // first logical name
218
219  CmtSystem::cmt_string_vector alternates; // other logical names
220};
221
222
223#endif
Note: See TracBrowser for help on using the repository browser.