lilypond-0.0.32
[lilypond.git] / flower / path.cc
blob3dc38366f26405fa583c5def9d921f6dca61e27d
1 /*
2 path.cc - manipulation of paths and filenames.
3 */
4 #include <stdio.h>
5 #include "path.hh"
7 #ifndef PATHSEP
8 #define PATHSEP '/'
9 #endif
11 /**
12 @param path the original full filename
13 @return 4 components of the path. They can be empty
15 void
16 split_path(String path,
17 String &drive, String &dirs, String &filebase, String &extension)
19 // peel off components, one by one.
20 int di = path.pos(':');
21 if (di)
23 drive = path.left(di);
24 path = path.right(path.len() - di);
26 else
27 drive = "";
29 di = path.lastPos(PATHSEP);
30 if (di)
32 dirs = path.left(di);
33 path = path.right(path.len()-di);
35 else
36 dirs = "";
38 di = path.lastPos('.');
39 if (di)
41 di --; // don't forget '.'
42 filebase = path.left(di);
43 extension =path.right(path.len()-di);
45 else
47 extension = "";
48 filebase = path;
52 File_path::File_path(String pref)
54 add(".");
55 add(pref);
59 /** find a file.
60 It will search in the current dir, in the construction-arg, and
61 in any other added path, in this order.
63 String
64 File_path::find(String nm)
66 for (int i=0; i < size(); i++) {
67 String path = (*this)[i];
68 path+= "/"+nm;
71 FILE *f = fopen(path, "r"); // ugh!
72 if (f) {
73 fclose(f);
74 return path;
77 return "";