]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/kpath.cc
*** empty log message ***
[lilypond.git] / lily / kpath.cc
index bc64468e06573421cf21b574be4df2a37e08f738..4eae83af4991b7bacc38361033fe9c8e77afa58d 100644 (file)
@@ -21,7 +21,7 @@ I found a somewhat more elegant patch for this: Just #include
 
 */
 #include <unistd.h>    
-#include "config.h"
+#include "config.hh"
 
 #define popen REALLYUGLYKLUDGE
 #define pclose ANOTHERREALLYUGLYKLUDGE
@@ -45,7 +45,7 @@ String
 kpathsea_find_afm (char const * name)
 {
 #if (KPATHSEA && HAVE_KPSE_FIND_FILE)
-  char * name_ptr =  kpse_find_file (name, kpse_afm_format, true);
+  char * name_ptr =  kpse_find_file (name, kpse_afm_format, false);
 
   if (!name_ptr)
     {
@@ -63,22 +63,29 @@ kpathsea_find_afm (char const * name)
 }
 
 String
-kpathsea_find_tfm (char const * name)
+kpathsea_find_tfm (char const *name)
 {
-  String p = global_path.find (String (name) + ".tfm");
-
-  if (p.length ())
-    return p;
-  
+  String filename = global_path.find (String (name) + ".tfm");
 #if (KPATHSEA && HAVE_KPSE_FIND_FILE)
-  char * name_ptr =  kpse_find_file (name, kpse_tfm_format, true);
-  if (!name_ptr)
-    warning (_f ("kpathsea can not find TFM file: `%s'", name));
-  else
-    return name_ptr;
+  if (filename.is_empty ())
+    {
+      /* If invoked for a TeX font, we could do TRUE (must exist).
+        We could also do:
+          p = kpse_find_file (name, kpse_mf_format, false);
+          if (p)
+            p = kpse_find_file (name, kpse_mf_format, true);
+
+            but we assume that if there is a .PFA, there is also a .TFM,
+        and it's no use generating TFMs on the fly, because PFAs cannot
+        be generated on the fly. */
+      char *p = kpse_find_file (name, kpse_tfm_format, false);
+      if (!p)
+       warning (_f ("kpathsea can not find TFM file: `%s'", name));
+      else
+       filename = p;
+    }
 #endif
-
-  return "";
+  return filename;
 }
 
 #if KPATHSEA
@@ -140,16 +147,30 @@ kpathsea_gulp_file_to_string (String name)
   return string;
 }
 
-LY_DEFINE (ly_kpathsea_gulp_file, "ly:kpathsea-gulp-file",
+
+
+LY_DEFINE (ly_kpathsea_expand_path, "ly:kpathsea-expand-path",
           1, 0, 0, (SCM name),
-          "Read the file @var{name}, and return its contents in a string.  "
-          "The file is looked up using the search path and kpathsea.")
+          "Return the expanded path of @var{name}, or"
+          "@code{#f} if not found.")
 {
-  SCM_ASSERT_TYPE (ly_string_p (name), name, SCM_ARG1, __FUNCTION__, "string");
-  return scm_makfrom0str
-    (kpathsea_gulp_file_to_string (ly_scm2string (name)).to_str0 ());
+  SCM_ASSERT_TYPE (ly_c_string_p (name), name, SCM_ARG1, __FUNCTION__, "string");
+
+  String nm = ly_scm2string (name);
+  String filename = global_path.find (nm);
+  if (filename.is_empty ())
+    {
+      char *p = kpse_find_file (nm.to_str0 (), kpathsea_find_format (nm),
+       true);
+      if (p)
+       return scm_makfrom0str (p);
+      else
+       return SCM_BOOL_F;
+    }
+  return scm_makfrom0str (filename.to_str0 ());
 }
 
+
 void
 initialize_kpathsea (char *av0)
 {