]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/kpath.cc
* lily/all-font-metrics.cc (find_font): Add "lm" to try-AFM-first
[lilypond.git] / lily / kpath.cc
index 4eae83af4991b7bacc38361033fe9c8e77afa58d..22910f95fcb8a6266a365217e4b272e79ef769e4 100644 (file)
@@ -6,8 +6,10 @@
   (c) 2000--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 */
 
-#include <stdio.h>
-#include <string.h>
+#include "kpath.hh"
+
+#include <cstdio>
+#include <cstring>
 
 /*
 
@@ -20,7 +22,9 @@ I found a somewhat more elegant patch for this: Just #include
 <unistd.h> before defining YAKLUDGE.
 
 */
+
 #include <unistd.h>    
+
 #include "config.hh"
 
 #define popen REALLYUGLYKLUDGE
@@ -35,29 +39,21 @@ extern "C" {
 #endif
 
 #include "file-path.hh"
-#include "string.hh"
 #include "main.hh"
-#include "kpath.hh"
 #include "source-file.hh"
 #include "warn.hh"
 
 String
-kpathsea_find_afm (char const * name)
+kpathsea_find_afm (char const *name)
 {
 #if (KPATHSEA && HAVE_KPSE_FIND_FILE)
-  char * name_ptr =  kpse_find_file (name, kpse_afm_format, false);
 
-  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;
-  
+  if (char *afm = kpse_find_file (name, kpse_afm_format, false))
+    return afm;
+#if 0 /* Do not mutter about afms, since we try to find them first, and
+        lots of TFMs don't have AFMs. */
+  warning (_f ("kpathsea can not find AFM file `%s'", name));
+#endif
 #endif
   return "";
 }
@@ -65,9 +61,9 @@ kpathsea_find_afm (char const * name)
 String
 kpathsea_find_tfm (char const *name)
 {
-  String filename = global_path.find (String (name) + ".tfm");
+  String file_name = global_path.find (String (name) + ".tfm");
 #if (KPATHSEA && HAVE_KPSE_FIND_FILE)
-  if (filename.is_empty ())
+  if (file_name.is_empty ())
     {
       /* If invoked for a TeX font, we could do TRUE (must exist).
         We could also do:
@@ -78,14 +74,12 @@ kpathsea_find_tfm (char const *name)
             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;
+      if (char *tfm = kpse_find_file (name, kpse_tfm_format, false))
+       return tfm;
+      warning (_f ("kpathsea can not find TFM file: `%s'", name));
     }
 #endif
-  return filename;
+  return file_name;
 }
 
 #if KPATHSEA
@@ -116,28 +110,28 @@ kpathsea_find_format (String name)
 String
 kpathsea_gulp_file_to_string (String name)
 {
-  String filename = global_path.find (name);
+  String file_name = global_path.find (name);
 
 #if (KPATHSEA && HAVE_KPSE_FIND_FILE)
-  if (filename.is_empty ())
+  if (file_name.is_empty ())
     {
       char *p = kpse_find_file (name.to_str0 (), kpathsea_find_format (name),
        true);
       if (p)
-       filename = p;
+       file_name = p;
       else
        warning (_f ("kpathsea can not find file: `%s'", name));
     }
 #endif
 
-  if (filename.is_empty ())
+  if (file_name.is_empty ())
     error (_f ("can't find file: `%s'", name));
 
   if (verbose_global_b)
-    progress_indication ("[" + filename);
+    progress_indication ("[" + file_name);
 
   int filesize;
-  char *str = gulp_file (filename, &filesize);
+  char *str = gulp_file (file_name, &filesize);
   String string (str);
   delete[] str;
   
@@ -147,29 +141,38 @@ kpathsea_gulp_file_to_string (String name)
   return string;
 }
 
-
-
-LY_DEFINE (ly_kpathsea_expand_path, "ly:kpathsea-expand-path",
+LY_DEFINE (ly_kpathsea_find_file, "ly:kpathsea-find-file",
           1, 0, 0, (SCM name),
-          "Return the expanded path of @var{name}, or"
-          "@code{#f} if not found.")
+          "Return the absolute file name of @var{name},"
+          "or @code{#f} if not found.")
 {
-  SCM_ASSERT_TYPE (ly_c_string_p (name), name, SCM_ARG1, __FUNCTION__, "string");
+  SCM_ASSERT_TYPE (scm_is_string (name), name, SCM_ARG1, __FUNCTION__, "string");
 
   String nm = ly_scm2string (name);
-  String filename = global_path.find (nm);
-  if (filename.is_empty ())
+  String file_name = global_path.find (nm);
+  if (file_name.is_empty ())
     {
-      char *p = kpse_find_file (nm.to_str0 (), kpathsea_find_format (nm),
-       true);
-      if (p)
+      if (char *p = kpse_find_file (nm.to_str0 (), kpathsea_find_format (nm),
+                                   true))
        return scm_makfrom0str (p);
-      else
-       return SCM_BOOL_F;
+      return SCM_BOOL_F;
     }
-  return scm_makfrom0str (filename.to_str0 ());
+  return scm_makfrom0str (file_name.to_str0 ());
 }
 
+LY_DEFINE (ly_kpathsea_expand_variable, "ly:kpathsea-expand-variable",
+          1, 0, 0, (SCM var),
+          "Return the expanded version  @var{var}.")
+{
+  SCM_ASSERT_TYPE (scm_is_string (var), var, SCM_ARG1, __FUNCTION__, "string");
+
+  String nm = ly_scm2string (var);
+  char *result =  kpse_var_expand (nm.to_str0 ());
+  SCM ret =  scm_makfrom0str (result);
+  delete[] result;
+
+  return ret;
+}
 
 void
 initialize_kpathsea (char *av0)