lilypond-0.1.15
[lilypond.git] / flower / path.cc
blob6625864f6e0fa971da65e2061c32273d38e7dc34
1 /*
2 path.cc - manipulation of paths and filenames.
3 */
4 #include <stdio.h>
5 #include "path.hh"
6 #include "flower-debug.hh"
8 #ifndef PATHSEP
9 #define PATHSEP '/'
10 #endif
12 /**
13 @param path the original full filename
14 @return 4 components of the path. They can be empty
16 void
17 split_path (String path,
18 String &drive, String &dirs, String &filebase, String &extension)
20 // peel off components, one by one.
21 int di = path.index_i (':');
22 if (di >= 0)
24 drive = path.left_str (di + 1);
25 path = path.right_str (path.len() - di -1);
27 else
28 drive = "";
30 di = path.index_last_i (PATHSEP);
31 if (di >=0)
33 dirs = path.left_str (di + 1);
34 path = path.right_str (path.len()-di -1);
36 else
37 dirs = "";
39 di = path.index_last_i ('.');
40 if (di >= 0)
42 filebase = path.left_str (di);
43 extension =path.right_str (path.len()-di);
45 else
47 extension = "";
48 filebase = path;
52 /** find a file.
53 It will search in the current dir, in the construction-arg, and
54 in any other added path, in this order.
56 String
57 File_path::find (String nm) const
60 fdebug << "looking for " << nm << ": ";
61 if (!nm.length_i() || (nm == "-") )
62 return nm;
63 for (int i=0; i < size(); i++)
66 String path = elem(i);
67 if (path.length_i() )
68 path += "/";
70 path += nm;
72 fdebug << path << "? ";
73 FILE *f = fopen (path.ch_C(), "r"); // ugh!
74 if (f)
76 fdebug << "found\n";
77 fclose (f);
78 return path;
81 fdebug << "\n";
82 return "";