* scm/beam.scm (check-slope-callbacks): check sign of slope.
[lilypond.git] / lily / kpath.cc
blob63b288bea2d4daff8d737f4278c7c1bc013b804d
1 /*
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>
7 */
9 #include <stdio.h>
10 #include <string.h>
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.
23 #include <unistd.h>
24 #include "config.h"
26 #define popen REALLYUGLYKLUDGE
27 #define pclose ANOTHERREALLYUGLYKLUDGE
28 #define getopt YAKLUDGE
30 #if HAVE_KPATHSEA_KPATHSEA_H
31 extern "C" {
32 #include <kpathsea/kpathsea.h>
33 #include <kpathsea/tex-file.h>
35 #endif
37 #include "file-path.hh"
38 #include "string.hh"
39 #include "main.hh"
40 #include "kpath.hh"
41 #include "source-file.hh"
42 #include "warn.hh"
44 String
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);
50 if (!name_ptr)
53 don't mutter about afms, since we try to find them first, and lots of
54 TFMs don't have AFMs.
56 // warning (_f ("kpathsea couldn't find AFM file `%s'", name));
58 else
59 return name_ptr;
61 #endif
62 return "";
65 String
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).
73 We could also do:
74 p = kpse_find_file (name, kpse_mf_format, false);
75 if (p)
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);
82 if (!p)
83 warning (_f ("kpathsea can not find TFM file: `%s'", name));
84 else
85 filename = p;
87 #endif
88 return filename;
91 #if KPATHSEA
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++)
107 String suffix = *p;
108 if (name.right_string (suffix.length ()) == suffix)
109 return (kpse_file_format_type) i;
112 return kpse_last_format;
114 #endif
116 String
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),
125 true);
126 if (p)
127 filename = p;
128 else
129 warning (_f ("kpathsea can not find file: `%s'", name));
131 #endif
133 if (filename.is_empty ())
134 error (_f ("can't find file: `%s'", name));
136 if (verbose_global_b)
137 progress_indication ("[" + filename);
139 int filesize;
140 char *str = gulp_file (filename, &filesize);
141 String string (str);
142 delete[] str;
144 if (verbose_global_b)
145 progress_indication ("]");
147 return string;
150 LY_DEFINE (ly_kpathsea_gulp_file, "ly:kpathsea-gulp-file",
151 1, 0, 0, (SCM name),
152 "Read the file @var{name}, and return its contents in a string. "
153 "The file is looked up using the search path and kpathsea.")
155 SCM_ASSERT_TYPE (ly_c_string_p (name), name, SCM_ARG1, __FUNCTION__, "string");
156 return scm_makfrom0str
157 (kpathsea_gulp_file_to_string (ly_scm2string (name)).to_str0 ());
160 void
161 initialize_kpathsea (char *av0)
163 #if KPATHSEA && HAVE_KPATHSEA_KPATHSEA_H
166 initialize kpathsea
168 kpse_set_program_name (av0, NULL);
169 kpse_maketex_option ("tfm", TRUE);
170 #endif