]> git.donarmstrong.com Git - lilypond.git/blob - lily/kpath.cc
* scm/framework-ps.scm (dump-page): use output-units for landscape.
[lilypond.git] / lily / kpath.cc
1 /*   
2   kpath.cc -- glue kpathsea to lily. Need some ugly kludges for gcc 2.96
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2000--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "kpath.hh"
10
11 #include <cstdio>
12 #include <cstring>
13
14 /*
15
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.
20
21 I found a somewhat more elegant patch for this: Just #include
22 <unistd.h> before defining YAKLUDGE.
23
24 */
25
26 #include <unistd.h>     
27
28 #include "config.hh"
29
30 #define popen REALLYUGLYKLUDGE
31 #define pclose ANOTHERREALLYUGLYKLUDGE
32 #define getopt YAKLUDGE
33
34 #if HAVE_KPATHSEA_KPATHSEA_H
35 extern "C" {
36 #include <kpathsea/kpathsea.h>
37 #include <kpathsea/tex-file.h>
38 }
39 #endif
40
41 #include "file-path.hh"
42 #include "main.hh"
43 #include "source-file.hh"
44 #include "warn.hh"
45 #include "kpath-private.hh"
46
47 String
48 kpathsea_find_afm (char const *name)
49 {
50 #if (KPATHSEA && HAVE_KPSE_FIND_FILE)
51
52   if (char *afm = kpse_find_file (name, kpse_afm_format, false))
53     return afm;
54
55 #endif
56   return "";
57 }
58
59 String
60 kpathsea_find_tfm (char const *name)
61 {
62   String file_name = global_path.find (String (name) + ".tfm");
63 #if (KPATHSEA && HAVE_KPSE_FIND_FILE)
64   if (file_name.is_empty ())
65     {
66       /* If invoked for a TeX font, we could do TRUE (must exist).
67          We could also do:
68            p = kpse_find_file (name, kpse_mf_format, false);
69            if (p)
70              p = kpse_find_file (name, kpse_mf_format, true);
71
72              but we assume that if there is a .PFA, there is also a .TFM,
73          and it's no use generating TFMs on the fly, because PFAs cannot
74          be generated on the fly. */
75       if (char *tfm = kpse_find_file (name, kpse_tfm_format, false))
76         return tfm;
77       warning (_f ("kpathsea can't find %s file: `%s'", "TFM", name));
78     }
79 #endif
80   return file_name;
81 }
82
83 #if KPATHSEA
84 /* FIXME: this should be part of kpathsea */
85
86 kpse_file_format_type
87 kpathsea_find_format (String name)
88 {
89   for (int i = 0; i < kpse_last_format; i++)
90     {
91       if (!kpse_format_info[i].type)
92         kpse_init_format ((kpse_file_format_type) i);
93
94       char const **suffixes[] = { kpse_format_info[i].suffix,
95                                   kpse_format_info[i].alt_suffix };
96       for (int j = 0; j < 2; j++)
97         for (char const **p = suffixes[j]; p && *p; p++)
98           {
99             String suffix = *p;
100             if (name.right_string (suffix.length ()) == suffix)
101               return (kpse_file_format_type) i;
102           }
103     }
104   return kpse_last_format;
105 }
106 #endif
107
108
109
110 void
111 initialize_kpathsea (char *av0)
112 {
113 #if KPATHSEA && HAVE_KPATHSEA_KPATHSEA_H
114
115   /*
116    initialize kpathsea
117    */
118   kpse_set_program_name (av0, NULL);
119   kpse_maketex_option ("tfm", TRUE);
120 #endif
121 }