]> git.donarmstrong.com Git - lilypond.git/blobdiff - lib/source.cc
release: 0.1.11
[lilypond.git] / lib / source.cc
index 8a8c52883591bfa49930fec798e3c9afc8746d81..3f2daf6a2356d8c27423b925a6cc1e917f8357c9 100644 (file)
@@ -1,36 +1,82 @@
-//
-// source.cc
-//
+/*
+  source.cc -- implement Sources
+
+  source file of the LilyPond music typesetter
+
+  (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
 
 #include <assert.h>
 
+#include "binary-source-file.hh"
 #include "string.hh"
 #include "proto.hh"
 #include "plist.hh"
-
 #include "source-file.hh"
 #include "source.hh"
+#include "path.hh"
 
-Source::Source()
+Sources::Sources()
 {
+  path_C_= 0;
+  binary_b_ = false;
 }
 
-Source::~Source()
+void
+Sources::set_binary(bool bo)
 {
+  binary_b_ = bo;
 }
 
 void
-Source::add( Source_file* sourcefile_p )
+Sources::set_path(File_path *f_C)
 {
-    sourcefile_p_iplist_.bottom().add( sourcefile_p );
+  path_C_ = f_C;
 }
 
+/**
+  open a file
+
+  @param file_str the file to be opened, name might be changed if it
+  is found in a search path. UGH!
+
+  @return 0 if no file found
+  */
 Source_file*
-Source::sourcefile_l( char const* ch_c_l )
+Sources::get_file_l(String &file_str) //UGH
 {
-    PCursor<Source_file*> sourcefile_l_pcur( sourcefile_p_iplist_.top() );
-    for ( ; sourcefile_l_pcur.ok(); sourcefile_l_pcur++ )
-       if ( sourcefile_l_pcur->in_b( ch_c_l ) )        
-           return *sourcefile_l_pcur;
-    return 0;
+  if (path_C_)
+    {
+      String file_str_o = path_C_->find(file_str); 
+      if ((file_str_o == "") && (file_str != ""))
+       return 0;
+      file_str = file_str_o;
+    }
+  Source_file * f_p= (!binary_b_) ?
+    new Source_file(file_str) : new Binary_source_file(file_str);
+  add(f_p);
+  return f_p;
 }
+
+void
+Sources::add(Source_file* sourcefile_p)
+{
+  sourcefile_p_list_.bottom().add(sourcefile_p);
+}
+
+/**
+  search the list for file whose map contains pointer #ch_C#
+
+  @return 0 if not found.
+  */
+Source_file*
+Sources::sourcefile_l(char const* ch_C)
+{
+  PCursor<Source_file*> sourcefile_l_pcur(sourcefile_p_list_.top());
+  for (; sourcefile_l_pcur.ok(); sourcefile_l_pcur++)
+    if (sourcefile_l_pcur->in_b(ch_C)) 
+      return *sourcefile_l_pcur;
+  return 0;
+}
+