2 path.cc - manipulation of paths and filenames.
11 #include "file-path.hh"
12 #include "flower-debug.hh"
23 @param path the original full filename
24 @return 4 components of the path. They can be empty
27 split_path (String path,
28 String &drive, String &dirs, String &filebase, String &extension)
30 // peel off components, one by one.
31 int di = path.index_i (':');
34 drive = path.left_str (di + 1);
35 path = path.right_str (path.length_i () - di -1);
40 di = path.index_last_i (DIRSEP);
43 dirs = path.left_str (di + 1);
44 path = path.right_str (path.length_i ()-di -1);
49 di = path.index_last_i ('.');
52 filebase = path.left_str (di);
53 extension =path.right_str (path.length_i ()-di);
63 File_path::parse_path (String p)
67 while ( (l = p.length_i ()) )
69 int i = p.index_i(PATHSEP);
73 p = p.right_str (l- i - 1);
81 It will search in the current dir, in the construction-arg, and
82 in any other added path, in this order.
85 The full path if found, or empty string if not found
88 File_path::find (String nm) const
90 DEBUG_OUT << "looking for" << nm << ": ";
91 if (!nm.length_i() || (nm == "-") )
93 for (int i=0; i < size(); i++)
95 String path = elem(i);
96 String sep = to_str (DIRSEP);
97 String right(path.right_str (1));
98 if (path.length_i () && right != sep)
99 path += to_str (DIRSEP);
103 DEBUG_OUT << path << "? ";
106 Check if directory. TODO: encapsulate for autoconf
109 if (stat (path.ch_C(), &sbuf) == ENOENT)
112 if (!(sbuf.st_mode & __S_IFREG))
115 FILE *f = fopen (path.ch_C(), "r"); // ugh!
118 DEBUG_OUT << "found\n";
128 Add an directory, return false if failed
131 File_path::try_add (String s)
135 FILE * f = fopen (s.ch_C(), "r");
145 File_path::add (String s)
151 File_path::str () const
154 for (int i=0; i< size (); i++)