]> git.donarmstrong.com Git - lilypond.git/blob - flower/path.cc
2fd7eea3cb5b1321f66e92310d0c32bf11b8342c
[lilypond.git] / flower / path.cc
1 /*
2    path.cc - manipulation of paths and filenames.
3 */
4 #include <stdio.h>
5 #include "path.hh"
6
7 #ifndef PATHSEP
8 #define PATHSEP '/'
9 #endif
10
11
12 void
13 split_path(String path, 
14            String &drive, String &dirs, String &filebase, String &extension)
15 {
16     // peel off components, one by one.
17     int di = path.pos(':');
18     if (di) 
19         {
20         drive = path.left(di);
21         path = path.right(path.len() - di);
22         } 
23     else
24         drive = "";
25     
26     di = path.lastPos(PATHSEP);
27     if (di) 
28         {
29         dirs = path.left(di);
30         path = path.right(path.len()-di);
31         }
32     else
33         dirs = "";
34     
35     di = path.lastPos('.');
36     if (di) 
37         {
38         di --; // don't forget '.'
39         filebase = path.left(di);
40         extension =path.right(path.len()-di);   
41         } 
42     else 
43         {
44         extension = "";   
45         filebase = path;
46         }
47 }
48 /**
49    INPUT: path the original full filename
50    OUTPUT: 4 components of the path. They can be empty
51 */
52
53
54 File_path::File_path(String pref)
55 {
56     add(".");
57     add(pref);
58 }
59
60
61 ///
62 String
63 File_path::find(String nm)
64 {
65      for (int i=0; i < size(); i++) {
66          String path  = (*this)[i];
67          path+= "/"+nm;
68
69
70          FILE *f = fopen(path, "r"); // ugh!
71          if (f) {
72              fclose(f);
73              return path;
74          }
75      }
76      return "";
77 }
78 /**
79   It will search in the current dir, in the construction-arg, and
80   in any other added path, in this order.
81   */