2 kpath-scheme.cc -- implement kpathsea bindings
4 source file of the GNU LilyPond music typesetter
6 (c) 2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
17 The problem, as far as I can tell, is that MacOS X has its getopt
18 prototype in <unistd.h>, while I think other operating systems have it
19 in other places. <unistd.h> is included by kpathsea.h, so you end up
20 renaming both conflicting prototypes to YAKLUDGE.
22 I found a somewhat more elegant patch for this: Just #include
23 <unistd.h> before defining YAKLUDGE.
31 #define popen REALLYUGLYKLUDGE
32 #define pclose ANOTHERREALLYUGLYKLUDGE
33 #define getopt YAKLUDGE
35 #if HAVE_KPATHSEA_KPATHSEA_H
37 #include <kpathsea/kpathsea.h>
38 #include <kpathsea/tex-file.h>
42 #include "file-path.hh"
44 #include "source-file.hh"
46 #include "kpath-private.hh"
48 LY_DEFINE (ly_find_file, "ly:find-file",
50 "Return the absolute file name of @var{name}, "
51 "or @code{#f} if not found.")
53 SCM_ASSERT_TYPE (scm_is_string (name), name, SCM_ARG1, __FUNCTION__, "string");
55 String nm = ly_scm2string (name);
56 String file_name = global_path.find (nm);
57 if (file_name.is_empty ())
60 return scm_makfrom0str (file_name.to_str0 ());
63 LY_DEFINE (ly_kpathsea_find_file, "ly:kpathsea-find-file",
65 "Return the absolute file name of @var{name}, "
66 "or @code{#f} if not found.")
68 SCM_ASSERT_TYPE (scm_is_string (name), name, SCM_ARG1, __FUNCTION__, "string");
70 String nm = ly_scm2string (name);
71 String file_name = global_path.find (nm);
72 if (file_name.is_empty ())
74 if (char *p = kpse_find_file (nm.to_str0 (), kpathsea_find_format (nm),
76 return scm_makfrom0str (p);
79 return scm_makfrom0str (file_name.to_str0 ());
82 LY_DEFINE (ly_kpathsea_expand_variable, "ly:kpathsea-expand-variable",
84 "Return the expanded version @var{var}.")
86 SCM_ASSERT_TYPE (scm_is_string (var), var, SCM_ARG1, __FUNCTION__, "string");
88 String nm = ly_scm2string (var);
89 char *result = kpse_var_expand (nm.to_str0 ());
90 SCM ret = scm_makfrom0str (result);