2 path.cc - manipulation of paths and filenames.
8 #include "file-path.hh"
9 #include "flower-debug.hh"
20 @param path the original full filename
21 @return 4 components of the path. They can be empty
24 split_path (String path,
25 String &drive, String &dirs, String &filebase, String &extension)
27 // peel off components, one by one.
28 int di = path.index_i (':');
31 drive = path.left_str (di + 1);
32 path = path.right_str (path.length_i () - di -1);
37 di = path.index_last_i (DIRSEP);
40 dirs = path.left_str (di + 1);
41 path = path.right_str (path.length_i ()-di -1);
46 di = path.index_last_i ('.');
49 filebase = path.left_str (di);
50 extension =path.right_str (path.length_i ()-di);
60 File_path::parse_path (String p)
64 while ( (l = p.length_i ()) )
66 int i = p.index_i(PATHSEP);
70 p = p.right_str (l- i - 1);
78 It will search in the current dir, in the construction-arg, and
79 in any other added path, in this order.
82 The full path if found, or empty string if not found
85 File_path::find (String nm) const
87 fdebug << "looking for" << nm << ": ";
88 if (!nm.length_i() || (nm == "-") )
90 for (int i=0; i < size(); i++)
92 String path = elem(i);
93 String sep = to_str (DIRSEP);
94 String right(path.right_str (1));
95 if (path.length_i () && right != sep)
96 path += to_str (DIRSEP);
100 fdebug << path << "? ";
101 FILE *f = fopen (path.ch_C(), "r"); // ugh!
114 File_path::add (String s)
120 File_path::str () const
123 for (int i=0; i< size (); i++)