2 path.cc - manipulation of paths and filenames.
5 #include "file-path.hh"
6 #include "flower-debug.hh"
17 @param path the original full filename
18 @return 4 components of the path. They can be empty
21 split_path (String path,
22 String &drive, String &dirs, String &filebase, String &extension)
24 // peel off components, one by one.
25 int di = path.index_i (':');
28 drive = path.left_str (di + 1);
29 path = path.right_str (path.length_i () - di -1);
34 di = path.index_last_i (DIRSEP);
37 dirs = path.left_str (di + 1);
38 path = path.right_str (path.length_i ()-di -1);
43 di = path.index_last_i ('.');
46 filebase = path.left_str (di);
47 extension =path.right_str (path.length_i ()-di);
57 File_path::parse_path (String p)
61 while ( (l = p.length_i ()) )
63 int i = p.index_i(PATHSEP);
67 p = p.right_str (l- i - 1);
75 It will search in the current dir, in the construction-arg, and
76 in any other added path, in this order.
79 The full path if found, or empty string if not found
82 File_path::find (String nm) const
84 fdebug << "looking for" << nm << ": ";
85 if (!nm.length_i() || (nm == "-") )
87 for (int i=0; i < size(); i++)
89 String path = elem(i);
90 String sep = to_str (DIRSEP);
91 String right(path.right_str (1));
92 if (path.length_i () && right != sep)
93 path += to_str (DIRSEP);
97 fdebug << path << "? ";
98 FILE *f = fopen (path.ch_C(), "r"); // ugh!
111 File_path::add (String s)