]> git.donarmstrong.com Git - lilypond.git/blob - lily/kpath-scheme.cc
* buildscripts/gen-emmentaler-scripts.py (outdir): capitalize
[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
49 LY_DEFINE (ly_kpathsea_find_file, "ly:kpathsea-find-file",
50            1, 0, 0, (SCM name),
51            "Return the absolute file name of @var{name}, "
52            "or @code{#f} if not found.")
53 {
54   SCM_ASSERT_TYPE (scm_is_string (name), name, SCM_ARG1, __FUNCTION__, "string");
55
56   String nm = ly_scm2string (name);
57   String file_name = global_path.find (nm);
58   if (file_name.is_empty ())
59     {
60       if (char *p = kpse_find_file (nm.to_str0 (), kpathsea_find_format (nm),
61                                     true))
62         return scm_makfrom0str (p);
63       return SCM_BOOL_F;
64     }
65   return scm_makfrom0str (file_name.to_str0 ());
66 }
67
68 LY_DEFINE (ly_kpathsea_expand_variable, "ly:kpathsea-expand-variable",
69            1, 0, 0, (SCM var),
70            "Return the expanded version  @var{var}.")
71 {
72   SCM_ASSERT_TYPE (scm_is_string (var), var, SCM_ARG1, __FUNCTION__, "string");
73
74   String nm = ly_scm2string (var);
75   char *result =  kpse_var_expand (nm.to_str0 ());
76   SCM ret =  scm_makfrom0str (result);
77   delete[] result;
78
79   return ret;
80 }