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--2005 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>, whinole 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"
45 #include "kpath-private.hh"
48 kpathsea_find_afm (char const *name)
50 #if (KPATHSEA && HAVE_KPSE_FIND_FILE)
52 if (char *afm = kpse_find_file (name, kpse_afm_format, false))
54 #if 0 /* Do not mutter about afms, since we try to find them first, and
55 lots of TFMs don't have AFMs. */
56 warning (_f ("kpathsea can't find %s file: `%s'", "AFM", name));
63 kpathsea_find_tfm (char const *name)
65 String file_name = global_path.find (String (name) + ".tfm");
66 #if (KPATHSEA && HAVE_KPSE_FIND_FILE)
67 if (file_name.is_empty ())
69 /* If invoked for a TeX font, we could do TRUE (must exist).
71 p = kpse_find_file (name, kpse_mf_format, false);
73 p = kpse_find_file (name, kpse_mf_format, true);
75 but we assume that if there is a .PFA, there is also a .TFM,
76 and it's no use generating TFMs on the fly, because PFAs cannot
77 be generated on the fly. */
78 if (char *tfm = kpse_find_file (name, kpse_tfm_format, false))
80 warning (_f ("kpathsea can't find %s file: `%s'", "TFM", name));
87 /* FIXME: this should be part of kpathsea */
90 kpathsea_find_format (String name)
92 for (int i = 0; i < kpse_last_format; i++)
94 if (!kpse_format_info[i].type)
95 kpse_init_format ((kpse_file_format_type) i);
97 char const **suffixes[] = { kpse_format_info[i].suffix,
98 kpse_format_info[i].alt_suffix };
99 for (int j = 0; j < 2; j++)
100 for (char const **p = suffixes[j]; p && *p; p++)
103 if (name.right_string (suffix.length ()) == suffix)
104 return (kpse_file_format_type) i;
107 return kpse_last_format;
112 kpathsea_gulp_file_to_string (String name)
114 String file_name = global_path.find (name);
116 #if (KPATHSEA && HAVE_KPSE_FIND_FILE)
117 if (file_name.is_empty ())
119 char *p = kpse_find_file (name.to_str0 (), kpathsea_find_format (name),
124 warning (_f ("kpathsea can't find file: `%s'", name));
128 if (file_name.is_empty ())
129 error (_f ("can't find file: `%s'", name));
131 if (be_verbose_global)
132 progress_indication ("[" + file_name);
135 char *str = gulp_file (file_name, &filesize);
139 if (be_verbose_global)
140 progress_indication ("]");
148 initialize_kpathsea (char *av0)
150 #if KPATHSEA && HAVE_KPATHSEA_KPATHSEA_H
155 kpse_set_program_name (av0, NULL);
156 kpse_maketex_option ("tfm", TRUE);