2 kpath.cc -- glue kpathsea to lily. Need some ugly kludges for gcc 2.96
4 source file of the GNU LilyPond music typesetter
6 (c) 2000--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
14 The problem, as far as I can tell, is that MacOS X has its getopt
15 prototype in <unistd.h>, while I think other operating systems have it
16 in other places. <unistd.h> is included by kpathsea.h, so you end up
17 renaming both conflicting prototypes to YAKLUDGE.
19 I found a somewhat more elegant patch for this: Just #include
20 <unistd.h> before defining YAKLUDGE.
26 #define popen REALLYUGLYKLUDGE
27 #define pclose ANOTHERREALLYUGLYKLUDGE
28 #define getopt YAKLUDGE
30 #if HAVE_KPATHSEA_KPATHSEA_H
32 #include <kpathsea/kpathsea.h>
33 #include <kpathsea/tex-file.h>
37 #include "file-path.hh"
41 #include "source-file.hh"
45 kpathsea_find_afm (char const * name)
47 #if (KPATHSEA && HAVE_KPSE_FIND_FILE)
48 char * name_ptr = kpse_find_file (name, kpse_afm_format, false);
53 don't mutter about afms, since we try to find them first, and lots of
56 // warning (_f ("kpathsea couldn't find AFM file `%s'", name));
66 kpathsea_find_tfm (char const *name)
68 String filename = global_path.find (String (name) + ".tfm");
69 #if (KPATHSEA && HAVE_KPSE_FIND_FILE)
70 if (filename.is_empty ())
72 /* If invoked for a TeX font, we could do TRUE (must exist).
74 p = kpse_find_file (name, kpse_mf_format, false);
76 p = kpse_find_file (name, kpse_mf_format, true);
78 but we assume that if there is a .PFA, there is also a .TFM,
79 and it's no use generating TFMs on the fly, because PFAs cannot
80 be generated on the fly. */
81 char *p = kpse_find_file (name, kpse_tfm_format, false);
83 warning (_f ("kpathsea can not find TFM file: `%s'", name));
92 /* FIXME: this should be part of kpathsea */
94 static kpse_file_format_type
95 kpathsea_find_format (String name)
97 for (int i = 0; i < kpse_last_format; i++)
99 if (!kpse_format_info[i].type)
100 kpse_init_format ((kpse_file_format_type) i);
102 char const **suffixes[] = { kpse_format_info[i].suffix,
103 kpse_format_info[i].alt_suffix };
104 for (int j = 0; j < 2; j++)
105 for (char const **p = suffixes[j]; p && *p; p++)
108 if (name.right_string (suffix.length ()) == suffix)
109 return (kpse_file_format_type) i;
112 return kpse_last_format;
117 kpathsea_gulp_file_to_string (String name)
119 String filename = global_path.find (name);
121 #if (KPATHSEA && HAVE_KPSE_FIND_FILE)
122 if (filename.is_empty ())
124 char *p = kpse_find_file (name.to_str0 (), kpathsea_find_format (name),
129 warning (_f ("kpathsea can not find file: `%s'", name));
133 if (filename.is_empty ())
134 error (_f ("can't find file: `%s'", name));
136 if (verbose_global_b)
137 progress_indication ("[" + filename);
140 char *str = gulp_file (filename, &filesize);
144 if (verbose_global_b)
145 progress_indication ("]");
152 LY_DEFINE (ly_kpathsea_expand_path, "ly:kpathsea-expand-path",
154 "Return the expanded path of @var{name}, or"
155 "@code{#f} if not found.")
157 SCM_ASSERT_TYPE (ly_c_string_p (name), name, SCM_ARG1, __FUNCTION__, "string");
159 String nm = ly_scm2string (name);
160 String filename = global_path.find (nm);
161 if (filename.is_empty ())
163 char *p = kpse_find_file (nm.to_str0 (), kpathsea_find_format (nm),
166 return scm_makfrom0str (p);
170 return scm_makfrom0str (filename.to_str0 ());
175 initialize_kpathsea (char *av0)
177 #if KPATHSEA && HAVE_KPATHSEA_KPATHSEA_H
182 kpse_set_program_name (av0, NULL);
183 kpse_maketex_option ("tfm", TRUE);