#ifndef __cmt_system_h__
#define __cmt_system_h__

#include "cmt_std.h"
#include "cmt_string.h"
#include "cmt_vector.h"
#include "cmt_regexp.h"

class CmtSystem
{
public:
  typedef cmt_vector<cmt_string> cmt_string_vector;

  static cmt_string pwd ();
  static bool cd (const cmt_string& dir);

  static void basename (const cmt_string& file_name, cmt_string& result);
  static void basename (const cmt_string& file_name,
                        const cmt_string& suffix,
                        cmt_string& result);

  static void dirname (const cmt_string& file_name, cmt_string& result);

  static void name (const cmt_string& file, cmt_string& result);

  static void get_suffix (const cmt_string& file, cmt_string& result);
  static void get_dot_suffix (const cmt_string& file, cmt_string& result);
  static bool has_prefix (const cmt_string& name);
  static bool absolute_path (const cmt_string& name);
  static bool has_device (const cmt_string& name);

  static cmt_string current_branch ();

    /**
     * Implementation of the "test -d" equivalent
     */
  static bool test_directory (const cmt_string& name);
    /**
     * Implementation of the "test -f" equivalent
     */
  static bool test_file (const cmt_string& name);
    /**
     * Check if the file "name1" is identical to "name2"
     */
  static bool compare_files (const cmt_string& name1,
                             const cmt_string& name2);
    /**
     * Check if the file "name1" is identical to "name2"
     * if they are identical, "name1" will be simply deleted
     * otherwise "name1" will be copied to "name2" and deleted afterwards
     */
  static bool compare_and_update_files (const cmt_string& name1,
                                        const cmt_string& name2);
  static int file_size (const cmt_string& name);
  static char file_separator ();
  static void reduce_file_separators (cmt_string& text);
  static char path_separator ();
  static char command_separator ();
  static const cmt_string& ev_open ();
  static const cmt_string& ev_close ();
  static bool create_symlink (const cmt_string& oldname,
                              const cmt_string& newname);
  static bool remove_file (const cmt_string& name);
  static bool remove_directory (const cmt_string& name);
  static bool mkdir (const cmt_string& name);
  static void scan_dir (const cmt_string& dir_name,
                        cmt_string_vector& list);
  static void scan_dir (const cmt_string& dir_name,
                        const cmt_regexp& expression,
                        cmt_string_vector& list);
  static cmt_string_vector& scan_dir (const cmt_string& dir_name);
  static const cmt_string& get_cmt_root ();
  static void get_cmt_version (cmt_string& version);
  static cmt_string get_cmt_config ();
  static cmt_string get_cmt_site ();
  static void get_uname (cmt_string& uname);
  static void get_hosttype (cmt_string& hosttype);
  static cmt_string get_temporary_name ();
  
  static cmt_string get_home_package ();
  static bool is_home_package (const cmt_string& name,
                               const cmt_string& version);
  
  static cmt_string get_user_context_package ();
  static bool is_user_context_package (const cmt_string& name,
                                       const cmt_string& version);
  
  static bool testenv (const cmt_string& name);
  static cmt_string getenv (const cmt_string& name);
  static void add_cmt_path (const cmt_string& path,
                            const cmt_string& path_source,
                            cmt_string_vector& paths,
                            cmt_string_vector& path_pwds,
                            cmt_string_vector& path_sources);
  static void get_cmt_paths (cmt_string_vector& paths,
                             cmt_string_vector& path_pwds,
                             cmt_string_vector& path_sources,
                             const cmt_string& init_text = "");
  static int execute (const cmt_string& command);
  static int execute (const cmt_string& command, cmt_string& output);
  static bool is_package_directory (const cmt_string& name);
  static bool is_version_directory (const cmt_string& name);
  static bool is_version_directory (const cmt_string& name, int& v, int& r, int& p);
  static void split (const cmt_string& text,
                     const cmt_string& separators,
                     cmt_string_vector& strings);

  static void compress_path (const cmt_string& dir, cmt_string& new_dir);
  static void compress_path (cmt_string& dir);

  static cmt_string now ();
  static cmt_string user ();

  static void get_cvsroot (cmt_string& cvsroot);

};

#endif
