]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/kpath.cc
* SConstruct: Further development.
[lilypond.git] / lily / kpath.cc
index cb6968aafbf3c5387a901e4c0e78db0ccac1e6b4..2db7be8ee137901798a368380845424c4625130b 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
@@ -38,21 +38,22 @@ extern "C" {
 #include "string.hh"
 #include "main.hh"
 #include "kpath.hh"
+#include "source-file.hh"
 #include "warn.hh"
 
 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)
+  if (!name_ptr)
     {
   /*
     don't mutter about afms, since we try to find them first, and lots of
     TFMs don't have AFMs. 
    */
-      //      warning (_f("kpathsea couldn't find AFM file `%s'", name));
+      //      warning (_f ("kpathsea couldn't find AFM file `%s'", name));
     }
   else
     return name_ptr;
@@ -62,65 +63,118 @@ 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)
+  if (filename.is_empty ())
     {
-      warning (_f("Kpathsea couldn't find TFM file `%s'", name));
+      /* 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;
     }
-  else
-    return name_ptr;
-  
 #endif
-  return "";
+  return filename;
 }
 
+#if KPATHSEA
+/* FIXME: this should be part of kpathsea */
 
-void
-initialize_kpathsea (char *av0)
+static kpse_file_format_type
+kpathsea_find_format (String name)
 {
-#if KPATHSEA && HAVE_KPATHSEA_KPATHSEA_H
-  /*
-    We take two pronged approach to tfms:
+  for (int i = 0; i < kpse_last_format; i++)
+    {
+      if (!kpse_format_info[i].type)
+        kpse_init_format ((kpse_file_format_type) i);
+
+      char const **suffixes[] = { kpse_format_info[i].suffix,
+                                 kpse_format_info[i].alt_suffix };
+      for (int j = 0; j < 2; j++)
+       for (char const **p = suffixes[j]; p && *p; p++)
+         {
+           String suffix = *p;
+           if (name.right_string (suffix.length ()) == suffix)
+             return (kpse_file_format_type) i;
+         }
+    }
+  return kpse_last_format;
+}
+#endif
 
-    * the lilypond tfms (feta*.tfm) are found through our own routines.
+String
+kpathsea_gulp_file_to_string (String name)
+{
+  String filename = global_path.find (name);
 
-    * the TeX tfms are found through vanilla kpathsea.
+#if (KPATHSEA && HAVE_KPSE_FIND_FILE)
+  if (filename.is_empty ())
+    {
+      char *p = kpse_find_file (name.to_str0 (), kpathsea_find_format (name),
+       true);
+      if (p)
+       filename = p;
+      else
+       warning (_f ("kpathsea can not find file: `%s'", name));
+    }
+#endif
 
-    (* other TFMs are not found, i.e. don't use them. )
+  if (filename.is_empty ())
+    error (_f ("can't find file: `%s'", name));
 
-    PRO:
-    - TFM and AFM checksums always match in Lily.
+  if (verbose_global_b)
+    progress_indication ("[" + filename);
 
-    - less hassle, no kpathsea spaghetti
+  int filesize;
+  char *str = gulp_file (filename, &filesize);
+  String string (str);
+  delete[] str;
+  
+  if (verbose_global_b)
+    progress_indication ("]");
 
-    CON:
+  return string;
+}
 
-    - feta PK files are often recreated, locally
-    Solution: cache PK files locally?
 
-    - need env. vars to make sure that TeX finds the TFMs
 
-    - Outdated PK (TFM?) font files are not automatically removed,
-    since VERSION is not part of the standard location.
+LY_DEFINE (ly_kpathsea_expand_path, "ly:kpathsea-expand-path",
+          1, 0, 0, (SCM name),
+          "Read the file @var{name}, and return its expanded path, or "
+          "@code{#f} if not found.")
+{
+  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 ());
+}
 
-    ALTERNATIVE
 
-    we have tried to come up with schemes that leave this kind of work
-    to kpathsea with objective of fixing the CONs, but miserably
-    failed. TeX installations and kpathsea itself form a buggy,
-    inconsistent, and unorderly mess.
-    
-  */
+void
+initialize_kpathsea (char *av0)
+{
+#if KPATHSEA && HAVE_KPATHSEA_KPATHSEA_H
 
   /*
    initialize kpathsea
@@ -129,5 +183,3 @@ initialize_kpathsea (char *av0)
   kpse_maketex_option ("tfm", TRUE);
 #endif
 }
-
-