Remake
Loading...
Searching...
No Matches
Functions
Path helpers

Functions

static void init_working_dir ()
 
static void init_prefix_dir ()
 
static std::string normalize_abs (std::string const &s, std::string const &p)
 
static std::string normalize (std::string const &s, std::string const &w, std::string const &p)
 
static void normalize_list (string_list &l, std::string const &w, std::string const &p)
 

Detailed Description

Function Documentation

◆ init_prefix_dir()

static void init_prefix_dir ( )
static

Initialize prefix_dir and switch to it.

Definition at line 897 of file remake.cpp.

898{
899 for (;;)
900 {
901 struct stat s;
902 if (stat((prefix_dir + "/Remakefile").c_str(), &s) == 0)
903 {
904 if (!changed_prefix_dir) return;
905 if (chdir(prefix_dir.c_str()))
906 {
907 perror("Failed to change working directory");
909 }
910 if (show_targets)
911 {
912 std::cout << "remake: Entering directory `" << prefix_dir << '\'' << std::endl;
913 }
914 return;
915 }
916 size_t pos = prefix_dir.find_last_of('/');
917 if (pos == std::string::npos)
918 {
919 std::cerr << "Failed to locate Remakefile in the current directory or one of its parents" << std::endl;
921 }
922 prefix_dir.erase(pos);
923 changed_prefix_dir = true;
924 }
925}
static bool changed_prefix_dir
Definition remake.cpp:744
static bool show_targets
Definition remake.cpp:719
static std::string prefix_dir
Definition remake.cpp:739
ref_ptr()
Definition remake.cpp:489

Referenced by main().

◆ init_working_dir()

static void init_working_dir ( )
static

Initialize working_dir.

Definition at line 875 of file remake.cpp.

876{
877 char buf[1024];
878 char *res = getcwd(buf, sizeof(buf));
879 if (!res)
880 {
881 perror("Failed to get working directory");
883 }
885#ifdef WINDOWS
886 for (size_t i = 0, l = working_dir.size(); i != l; ++i)
887 {
888 if (working_dir[i] == '\\') working_dir[i] = '/';
889 }
890#endif
892}
static std::string working_dir
Definition remake.cpp:734

Referenced by main().

◆ normalize()

static std::string normalize ( std::string const & s,
std::string const & w,
std::string const & p )
static

Normalize path s (possibly relative to w) with respect to p.

  • If both p and w are empty, the function just removes ".", "..", "//".
  • If only p is empty, the function returns an absolute path.

Definition at line 953 of file remake.cpp.

954{
955#ifdef WINDOWS
956 char const *delim = "/\\";
957#else
958 char delim = '/';
959#endif
960 size_t pos = s.find_first_of(delim);
961 if (pos == std::string::npos && w == p) return s;
962 bool absolute = pos == 0;
963 if (!absolute && w != p && !w.empty())
964 return normalize(w + '/' + s, w, p);
965 size_t prev = 0, len = s.length();
967 for (;;)
968 {
969 if (pos != prev)
970 {
971 std::string n = s.substr(prev, pos - prev);
972 if (n == "..")
973 {
974 if (!l.empty()) l.pop_back();
975 else if (!absolute && !w.empty())
976 return normalize(w + '/' + s, w, p);
977 }
978 else if (n != ".")
979 l.push_back(n);
980 }
981 ++pos;
982 if (pos >= len) break;
983 prev = pos;
984 pos = s.find_first_of(delim, prev);
985 if (pos == std::string::npos) pos = len;
986 }
987 string_list::const_iterator i = l.begin(), i_end = l.end();
988 if (i == i_end) return absolute ? "/" : ".";
989 std::string n;
990 if (absolute) n.push_back('/');
991 n.append(*i);
992 for (++i; i != i_end; ++i)
993 {
994 n.push_back('/');
995 n.append(*i);
996 }
997 if (absolute && !p.empty()) return normalize_abs(n, p);
998 return n;
999}
static std::string normalize_abs(std::string const &s, std::string const &p)
Definition remake.cpp:931
static std::string normalize(std::string const &s, std::string const &w, std::string const &p)
Definition remake.cpp:953
std::list< std::string > string_list
Definition remake.cpp:469

Referenced by main(), normalize(), and normalize_list().

◆ normalize_abs()

static std::string normalize_abs ( std::string const & s,
std::string const & p )
static

Normalize an absolute path with respect to p. Paths outside the subtree are left unchanged.

Definition at line 931 of file remake.cpp.

932{
933 size_t l = p.length();
934 if (s.compare(0, l, p)) return s;
935 size_t ll = s.length();
936 if (ll == l) return ".";
937 if (s[l] != '/')
938 {
939 size_t pos = s.rfind('/', l);
940 assert(pos != std::string::npos);
941 return s.substr(pos + 1);
942 }
943 if (ll == l + 1) return ".";
944 return s.substr(l + 1);
945}

Referenced by normalize().

◆ normalize_list()

static void normalize_list ( string_list & l,
std::string const & w,
std::string const & p )
static

Normalize the content of a list of targets.

Definition at line 1004 of file remake.cpp.

1005{
1006 for (string_list::iterator i = l.begin(),
1007 i_end = l.end(); i != i_end; ++i)
1008 {
1009 *i = normalize(*i, w, p);
1010 }
1011}

Referenced by load_rule(), and main().