2 kpath.c -- implement kpathsea bindings
4 source file of the GNU LilyPond music typesetter
6 (c) 2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
13 #include "guile-compatibility.hh"
15 #if KPATHSEA && HAVE_KPATHSEA_KPATHSEA_H
22 The problem, as far as I can tell, is that MacOS X has its getopt
23 prototype in <unistd.h>, while I think other operating systems have it
24 in other places. <unistd.h> is included by kpathsea.h, so you end up
25 renaming both conflicting prototypes to YAKLUDGE.
27 I found a somewhat more elegant patch for this: Just #include
28 <unistd.h> before defining YAKLUDGE.
34 #define popen REALLYUGLYKLUDGE
35 #define pclose ANOTHERREALLYUGLYKLUDGE
36 #define getopt YAKLUDGE
38 #if HAVE_KPATHSEA_KPATHSEA_H
39 #include <kpathsea/kpathsea.h>
40 #include <kpathsea/tex-file.h>
45 /* FIXME: this should be part of kpathsea */
48 kpathsea_find_format (const char* name)
51 int len = strlen (name);
52 for (i = 0; i < kpse_last_format; i++)
54 if (!kpse_format_info[i].type)
55 kpse_init_format ((kpse_file_format_type) i);
57 char const **suffixes[] = { kpse_format_info[i].suffix,
58 kpse_format_info[i].alt_suffix };
59 for (int j = 0; j < 2; j++)
60 for (char const **p = suffixes[j]; p && *p; p++)
62 int suflen = strlen (*p);
64 if (!strncmp (name + len - suflen, *p, suflen))
65 return (kpse_file_format_type) i;
68 return kpse_last_format;
77 // "Return the absolute file name of @var{name}, "
78 // "or @code{#f} if not found.")
80 ly_kpathsea_find_file(SCM name)
82 SCM_ASSERT_TYPE (scm_is_string (name), name, SCM_ARG1, __FUNCTION__, "string");
84 char const * nm = scm_i_string_chars (name);
85 char *p = kpse_find_file (nm, kpathsea_find_format (nm),
88 return scm_makfrom0str (p);
92 // "Return the expanded version @var{var}.")
93 SCM ly_kpathsea_expand_variable(SCM var)
95 SCM_ASSERT_TYPE (scm_is_string (var), var, SCM_ARG1, __FUNCTION__, "string");
97 char const * nm = scm_i_string_chars (var);
98 char *result = kpse_var_expand (nm);
99 SCM ret = scm_makfrom0str (result);
108 initialize_kpathsea ()
113 kpse_set_program_name ("lilypond", NULL);
114 kpse_maketex_option ("tfm", TRUE);
116 SCM find = scm_c_define_gsubr ("ly:kpathsea-find-file", 1, 0, 0, ly_kpathsea_find_file);
117 scm_c_export ("ly:kpathsea-find-file", NULL);
118 SCM expand = scm_c_define_gsubr ("ly:kpathsea-expand-variable", 1, 0, 0, ly_kpathsea_find_file);
119 scm_c_export ("ly:kpathsea-expand-variable", NULL);