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>
16 The problem, as far as I can tell, is that MacOS X has its getopt
17 prototype in <unistd.h>, while I think other operating systems have it
18 in other places. <unistd.h> is included by kpathsea.h, so you end up
19 renaming both conflicting prototypes to YAKLUDGE.
21 I found a somewhat more elegant patch for this: Just #include
22 <unistd.h> before defining YAKLUDGE.
30 #define popen REALLYUGLYKLUDGE
31 #define pclose ANOTHERREALLYUGLYKLUDGE
32 #define getopt YAKLUDGE
34 #if HAVE_KPATHSEA_KPATHSEA_H
36 #include <kpathsea/kpathsea.h>
37 #include <kpathsea/tex-file.h>
41 #include "file-path.hh"
43 #include "source-file.hh"
47 kpathsea_find_afm (char const * name)
49 #if (KPATHSEA && HAVE_KPSE_FIND_FILE)
50 char * name_ptr = kpse_find_file (name, kpse_afm_format, false);
55 don't mutter about afms, since we try to find them first, and lots of
58 // warning (_f ("kpathsea couldn't find AFM file `%s'", name));
68 kpathsea_find_tfm (char const *name)
70 String file_name = global_path.find (String (name) + ".tfm");
71 #if (KPATHSEA && HAVE_KPSE_FIND_FILE)
72 if (file_name.is_empty ())
74 /* If invoked for a TeX font, we could do TRUE (must exist).
76 p = kpse_find_file (name, kpse_mf_format, false);
78 p = kpse_find_file (name, kpse_mf_format, true);
80 but we assume that if there is a .PFA, there is also a .TFM,
81 and it's no use generating TFMs on the fly, because PFAs cannot
82 be generated on the fly. */
83 char *p = kpse_find_file (name, kpse_tfm_format, false);
85 warning (_f ("kpathsea can not find TFM file: `%s'", name));
94 /* FIXME: this should be part of kpathsea */
96 static kpse_file_format_type
97 kpathsea_find_format (String name)
99 for (int i = 0; i < kpse_last_format; i++)
101 if (!kpse_format_info[i].type)
102 kpse_init_format ((kpse_file_format_type) i);
104 char const **suffixes[] = { kpse_format_info[i].suffix,
105 kpse_format_info[i].alt_suffix };
106 for (int j = 0; j < 2; j++)
107 for (char const **p = suffixes[j]; p && *p; p++)
110 if (name.right_string (suffix.length ()) == suffix)
111 return (kpse_file_format_type) i;
114 return kpse_last_format;
119 kpathsea_gulp_file_to_string (String name)
121 String file_name = global_path.find (name);
123 #if (KPATHSEA && HAVE_KPSE_FIND_FILE)
124 if (file_name.is_empty ())
126 char *p = kpse_find_file (name.to_str0 (), kpathsea_find_format (name),
131 warning (_f ("kpathsea can not find file: `%s'", name));
135 if (file_name.is_empty ())
136 error (_f ("can't find file: `%s'", name));
138 if (verbose_global_b)
139 progress_indication ("[" + file_name);
142 char *str = gulp_file (file_name, &filesize);
146 if (verbose_global_b)
147 progress_indication ("]");
152 LY_DEFINE (ly_kpathsea_find_file, "ly:kpathsea-find-file",
154 "Return the absolute file name of @var{name},"
155 "or @code{#f} if not found.")
157 SCM_ASSERT_TYPE (scm_is_string (name), name, SCM_ARG1, __FUNCTION__, "string");
159 String nm = ly_scm2string (name);
160 String file_name = global_path.find (nm);
161 if (file_name.is_empty ())
163 if (char *p = kpse_find_file (nm.to_str0 (), kpathsea_find_format (nm),
165 return scm_makfrom0str (p);
168 return scm_makfrom0str (file_name.to_str0 ());
171 LY_DEFINE (ly_kpathsea_expand_variable, "ly:kpathsea-expand-variable",
173 "Return the expanded version @var{var}.")
175 SCM_ASSERT_TYPE (scm_is_string (var), var, SCM_ARG1, __FUNCTION__, "string");
177 String nm = ly_scm2string (var);
178 char *result = kpse_var_expand (nm.to_str0 ());
179 SCM ret = scm_makfrom0str (result);
186 initialize_kpathsea (char *av0)
188 #if KPATHSEA && HAVE_KPATHSEA_KPATHSEA_H
193 kpse_set_program_name (av0, NULL);
194 kpse_maketex_option ("tfm", TRUE);