From: fred Date: Wed, 15 Jan 1997 17:38:12 +0000 (+0000) Subject: flower-1.0.20 X-Git-Tag: release/1.5.59~6402 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=88fbb93dcd180af560c16fb75e78191f0b9f345a;p=lilypond.git flower-1.0.20 --- diff --git a/flower/path.cc b/flower/path.cc new file mode 100644 index 0000000000..2fd7eea3cb --- /dev/null +++ b/flower/path.cc @@ -0,0 +1,81 @@ +/* + path.cc - manipulation of paths and filenames. +*/ +#include +#include "path.hh" + +#ifndef PATHSEP +#define PATHSEP '/' +#endif + + +void +split_path(String path, + String &drive, String &dirs, String &filebase, String &extension) +{ + // peel off components, one by one. + int di = path.pos(':'); + if (di) + { + drive = path.left(di); + path = path.right(path.len() - di); + } + else + drive = ""; + + di = path.lastPos(PATHSEP); + if (di) + { + dirs = path.left(di); + path = path.right(path.len()-di); + } + else + dirs = ""; + + di = path.lastPos('.'); + if (di) + { + di --; // don't forget '.' + filebase = path.left(di); + extension =path.right(path.len()-di); + } + else + { + extension = ""; + filebase = path; + } +} +/** + INPUT: path the original full filename + OUTPUT: 4 components of the path. They can be empty +*/ + + +File_path::File_path(String pref) +{ + add("."); + add(pref); +} + + +/// +String +File_path::find(String nm) +{ + for (int i=0; i < size(); i++) { + String path = (*this)[i]; + path+= "/"+nm; + + + FILE *f = fopen(path, "r"); // ugh! + if (f) { + fclose(f); + return path; + } + } + return ""; +} +/** + It will search in the current dir, in the construction-arg, and + in any other added path, in this order. + */ diff --git a/flower/path.hh b/flower/path.hh new file mode 100644 index 0000000000..fceaeed647 --- /dev/null +++ b/flower/path.hh @@ -0,0 +1,32 @@ +#ifndef PATH_HH +#define PATH_HH +#include "string.hh" +#include "varray.hh" + + +/// searching directory for file. +class File_path : private Array +{ +public: + /// locate a file in the search path + String find(String nm); + + /// construct using prefix. Normally argv[0]. + File_path(String); + + /// add to end of path. + Array:: add; +}; +/** + + Abstraction of PATH variable. An interface for searching input files. + Search a number of dirs for a file. + + Should use kpathsea? + +*/ + +/// split path into its components +void split_path(String path, String &drive, String &dirs, String &filebase, String &extension); + +#endif