]> git.donarmstrong.com Git - lilypond.git/commitdiff
flower-1.0.20
authorfred <fred>
Wed, 15 Jan 1997 17:38:12 +0000 (17:38 +0000)
committerfred <fred>
Wed, 15 Jan 1997 17:38:12 +0000 (17:38 +0000)
flower/path.cc [new file with mode: 0644]
flower/path.hh [new file with mode: 0644]

diff --git a/flower/path.cc b/flower/path.cc
new file mode 100644 (file)
index 0000000..2fd7eea
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+   path.cc - manipulation of paths and filenames.
+*/
+#include <stdio.h>
+#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 (file)
index 0000000..fceaeed
--- /dev/null
@@ -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<String>
+{
+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<String>:: 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