2 path.cc - manipulation of paths and filenames.
6 #include "file-path.hh"
7 #include "flower-debug.hh"
18 @param path the original full filename
19 @return 4 components of the path. They can be empty
22 split_path (String path,
23 String &drive, String &dirs, String &filebase, String &extension)
25 // peel off components, one by one.
26 int di = path.index_i (':');
29 drive = path.left_str (di + 1);
30 path = path.right_str (path.length_i () - di -1);
35 di = path.index_last_i (DIRSEP);
38 dirs = path.left_str (di + 1);
39 path = path.right_str (path.length_i ()-di -1);
44 di = path.index_last_i ('.');
47 filebase = path.left_str (di);
48 extension =path.right_str (path.length_i ()-di);
58 File_path::parse_path (String p)
62 while ( (l = p.length_i ()) )
64 int i = p.index_i(PATHSEP);
68 p = p.right_str (l- i - 1);
76 It will search in the current dir, in the construction-arg, and
77 in any other added path, in this order.
80 The full path if found, or empty string if not found
83 File_path::find (String nm) const
85 fdebug << "looking for" << nm << ": ";
86 if (!nm.length_i() || (nm == "-") )
88 for (int i=0; i < size(); i++)
90 String path = elem(i);
91 String sep = to_str (DIRSEP);
92 String right(path.right_str (1));
93 if (path.length_i () && right != sep)
94 path += to_str (DIRSEP);
98 fdebug << path << "? ";
99 FILE *f = fopen (path.ch_C(), "r"); // ugh!
112 File_path::add (String s)