]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/kpath.cc
release: 1.5.29
[lilypond.git] / lily / kpath.cc
index 8fa0c142bd8fc257fd6b9765737a06a0c6d95d39..aed208d5abea6f4bf17d246318faa21c02527b63 100644 (file)
@@ -1,13 +1,14 @@
 /*   
-kpath.cc --  glue kpathsea to lily. Need some ugly kludges for gcc 2.96
+  kpath.cc -- glue kpathsea to lily. Need some ugly kludges for gcc 2.96
 
-source file of the GNU LilyPond music typesetter
+  source file of the GNU LilyPond music typesetter
 
-(c) 2000--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
-
- */
+  (c) 2000--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+*/
 
 #include <stdio.h>
+#include <string.h>
+
 #include "config.h"
 
 #define popen REALLYUGLYKLUDGE
@@ -20,30 +21,53 @@ extern "C" {
 }
 #endif
 
-#include <sys/types.h>
-#include <fcntl.h>
-#if HAVE_SYS_STAT_H 
-#include <sys/stat.h>
-#endif
-
+#include "file-path.hh"
+#include "string.hh"
+#include "main.hh"
 #include "kpath.hh"
+#include "lily-version.hh"
+#include "warn.hh"
 
-
-
-char * ly_find_afm (char const * name)
+String
+ly_find_afm (char const * name)
 {
 #if (KPATHSEA && HAVE_KPSE_FIND_FILE)
-  return kpse_find_file (name, kpse_afm_format, true);
+  char * name_ptr =  kpse_find_file (name, kpse_afm_format, true);
+
+  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));
+    }
+  else
+    return name_ptr;
+  
 #endif
-  return 0;
+  return "";
 }
 
-char * ly_find_tfm (char const * name)
+String
+ly_find_tfm (char const * name)
 {
+  String p = global_path.find (String (name) + ".tfm");
+
+  if (p.length_i ())
+    return p;
+  
 #if (KPATHSEA && HAVE_KPSE_FIND_FILE)
-  return kpse_find_file (name, kpse_tfm_format, true);
+  char * name_ptr =  kpse_find_file (name, kpse_tfm_format, true);
+  if(!name_ptr)
+    {
+      warning (_f("Kpathsea couldn't find TFM file `%s'", name));
+    }
+  else
+    return name_ptr;
+  
 #endif
-  return 0;
+  return "";
 }
 
 
@@ -52,34 +76,45 @@ ly_init_kpath (char *av0)
 {
 #if KPATHSEA && HAVE_KPATHSEA_KPATHSEA_H
   /*
-   initialize kpathsea
-   */
-  kpse_set_program_name(av0, NULL);
-  kpse_maketex_option("tfm", TRUE);
+    We take two pronged approach to tfms:
 
-  /*
-    UGH: should not use DIR_DATADIR, but /var,
+    * the lilypond tfms (feta*.tfm) are found through our own routines.
 
-    hmm, but where to get /var?
-    
-   */
+    * the TeX tfms are found through vanilla kpathsea.
 
-  int fd;
-  struct stat stat_buf;
-  if (stat (DIR_DATADIR "/tfm", &stat_buf) == 0
-      && (S_ISDIR (stat_buf.st_mode) || S_ISLNK (stat_buf.st_mode))
-      // ugh, howto test if we can write there?
-      //      && (stat_buf.st_mode & S_IWUSR))
-      && ((fd = open (DIR_DATADIR "/tfm/lily", O_CREAT)) != -1))
-    {
-      close (fd);
-      unlink (DIR_DATADIR "/tfm/lily");
-      kpse_format_info[kpse_tfm_format].program ="mktextfm --destdir " DIR_DATADIR "/tfm";
+    (* other TFMs are not found, i.e. don't use them. )
 
-      kpse_format_info[kpse_tfm_format].client_path =
-       (DIR_DATADIR "/tfm" );
-    }
-  
+    PRO:
+    - TFM and AFM checksums always match in Lily.
+
+    - less hassle, no kpathsea spaghetti
+
+    CON:
+
+    - 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.
+
+
+    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.
+    
+  */
+
+  /*
+   initialize kpathsea
+   */
+  kpse_set_program_name (av0, NULL);
+  kpse_maketex_option ("tfm", TRUE);
 #endif
 }