]> git.donarmstrong.com Git - lilypond.git/blob - lily/kpath-scheme.cc
8275c8b203dda53e1f0b66c7555d9f505a3b4ba7
[lilypond.git] / lily / kpath-scheme.cc
1 /*
2   kpath-scheme.cc --  implement kpathsea bindings
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
7
8 */
9
10 #include "kpath.hh"
11
12 #include <cstdio>
13 #include <cstring>
14
15 /*
16
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.
21
22 I found a somewhat more elegant patch for this: Just #include
23 <unistd.h> before defining YAKLUDGE.
24
25 */
26
27 #include <unistd.h>     
28
29 #include "config.hh"
30
31 #define popen REALLYUGLYKLUDGE
32 #define pclose ANOTHERREALLYUGLYKLUDGE
33 #define getopt YAKLUDGE
34
35 #if HAVE_KPATHSEA_KPATHSEA_H
36 extern "C" {
37 #include <kpathsea/kpathsea.h>
38 #include <kpathsea/tex-file.h>
39 }
40 #endif
41
42 #include "file-path.hh"
43 #include "main.hh"
44 #include "source-file.hh"
45 #include "warn.hh"
46 #include "kpath-private.hh"
47
48 LY_DEFINE (ly_find_file, "ly:find-file",
49            1, 0, 0, (SCM name),
50            "Return the absolute file name of @var{name},"
51            "or @code{#f} if not found.")
52 {
53   SCM_ASSERT_TYPE (scm_is_string (name), name, SCM_ARG1, __FUNCTION__, "string");
54
55   String nm = ly_scm2string (name);
56   String file_name = global_path.find (nm);
57   if (file_name.is_empty ())
58     return SCM_BOOL_F;
59   
60   return scm_makfrom0str (file_name.to_str0 ());
61 }
62
63 LY_DEFINE (ly_kpathsea_find_file, "ly:kpathsea-find-file",
64            1, 0, 0, (SCM name),
65            "Return the absolute file name of @var{name},"
66            "or @code{#f} if not found.")
67 {
68   SCM_ASSERT_TYPE (scm_is_string (name), name, SCM_ARG1, __FUNCTION__, "string");
69
70   String nm = ly_scm2string (name);
71   String file_name = global_path.find (nm);
72   if (file_name.is_empty ())
73     {
74       if (char *p = kpse_find_file (nm.to_str0 (), kpathsea_find_format (nm),
75                                     true))
76         return scm_makfrom0str (p);
77       return SCM_BOOL_F;
78     }
79   return scm_makfrom0str (file_name.to_str0 ());
80 }
81
82 LY_DEFINE (ly_kpathsea_expand_variable, "ly:kpathsea-expand-variable",
83            1, 0, 0, (SCM var),
84            "Return the expanded version  @var{var}.")
85 {
86   SCM_ASSERT_TYPE (scm_is_string (var), var, SCM_ARG1, __FUNCTION__, "string");
87
88   String nm = ly_scm2string (var);
89   char *result =  kpse_var_expand (nm.to_str0 ());
90   SCM ret =  scm_makfrom0str (result);
91   delete[] result;
92
93   return ret;
94 }