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)
51 if (char *afm = kpse_find_file (name, kpse_afm_format, false))
53 #if 0 /* Do not mutter about afms, since we try to find them first, and
54 lots of TFMs don't have AFMs. */
55 warning (_f ("kpathsea can not find AFM file `%s'", name));
62 kpathsea_find_tfm (char const *name)
64 String file_name = global_path.find (String (name) + ".tfm");
65 #if (KPATHSEA && HAVE_KPSE_FIND_FILE)
66 if (file_name.is_empty ())
68 /* If invoked for a TeX font, we could do TRUE (must exist).
70 p = kpse_find_file (name, kpse_mf_format, false);
72 p = kpse_find_file (name, kpse_mf_format, true);
74 but we assume that if there is a .PFA, there is also a .TFM,
75 and it's no use generating TFMs on the fly, because PFAs cannot
76 be generated on the fly. */
77 if (char *tfm = kpse_find_file (name, kpse_tfm_format, false))
79 warning (_f ("kpathsea can not find TFM file: `%s'", name));
86 /* FIXME: this should be part of kpathsea */
88 static kpse_file_format_type
89 kpathsea_find_format (String name)
91 for (int i = 0; i < kpse_last_format; i++)
93 if (!kpse_format_info[i].type)
94 kpse_init_format ((kpse_file_format_type) i);
96 char const **suffixes[] = { kpse_format_info[i].suffix,
97 kpse_format_info[i].alt_suffix };
98 for (int j = 0; j < 2; j++)
99 for (char const **p = suffixes[j]; p && *p; p++)
102 if (name.right_string (suffix.length ()) == suffix)
103 return (kpse_file_format_type) i;
106 return kpse_last_format;
111 kpathsea_gulp_file_to_string (String name)
113 String file_name = global_path.find (name);
115 #if (KPATHSEA && HAVE_KPSE_FIND_FILE)
116 if (file_name.is_empty ())
118 char *p = kpse_find_file (name.to_str0 (), kpathsea_find_format (name),
123 warning (_f ("kpathsea can not find file: `%s'", name));
127 if (file_name.is_empty ())
128 error (_f ("can't find file: `%s'", name));
130 if (verbose_global_b)
131 progress_indication ("[" + file_name);
134 char *str = gulp_file (file_name, &filesize);
138 if (verbose_global_b)
139 progress_indication ("]");
144 LY_DEFINE (ly_kpathsea_find_file, "ly:kpathsea-find-file",
146 "Return the absolute file name of @var{name},"
147 "or @code{#f} if not found.")
149 SCM_ASSERT_TYPE (scm_is_string (name), name, SCM_ARG1, __FUNCTION__, "string");
151 String nm = ly_scm2string (name);
152 String file_name = global_path.find (nm);
153 if (file_name.is_empty ())
155 if (char *p = kpse_find_file (nm.to_str0 (), kpathsea_find_format (nm),
157 return scm_makfrom0str (p);
160 return scm_makfrom0str (file_name.to_str0 ());
163 LY_DEFINE (ly_kpathsea_expand_variable, "ly:kpathsea-expand-variable",
165 "Return the expanded version @var{var}.")
167 SCM_ASSERT_TYPE (scm_is_string (var), var, SCM_ARG1, __FUNCTION__, "string");
169 String nm = ly_scm2string (var);
170 char *result = kpse_var_expand (nm.to_str0 ());
171 SCM ret = scm_makfrom0str (result);
178 initialize_kpathsea (char *av0)
180 #if KPATHSEA && HAVE_KPATHSEA_KPATHSEA_H
185 kpse_set_program_name (av0, NULL);
186 kpse_maketex_option ("tfm", TRUE);