2 path.cc - manipulation of paths and filenames.
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 File_path::find (String nm
) const
81 fdebug
<< _("looking for ") << nm
<< ": ";
82 if (!nm
.length_i() || (nm
== "-") )
84 for (int i
=0; i
< size(); i
++)
86 String path
= elem(i
);
88 String
right(path
.right_str (1));
89 if (path
.length_i () && right
!= sep
)
94 fdebug
<< path
<< "? ";
95 FILE *f
= fopen (path
.ch_C(), "r"); // ugh!
98 fdebug
<< _("found\n");
108 File_path::add (String s
)