X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fkpath.cc;h=22910f95fcb8a6266a365217e4b272e79ef769e4;hb=2ec5f924eb75dfc6b584a8df25a03bdfde31fc6c;hp=f42c5fd1f6fcbadb101c1d692932af28cd19020c;hpb=7c4b190c428073b0653ddecdbf8c1a9c1e8bc5c4;p=lilypond.git diff --git a/lily/kpath.cc b/lily/kpath.cc index f42c5fd1f6..22910f95fc 100644 --- a/lily/kpath.cc +++ b/lily/kpath.cc @@ -3,16 +3,33 @@ source file of the GNU LilyPond music typesetter - (c) 2000--2001 Han-Wen Nienhuys + (c) 2000--2004 Han-Wen Nienhuys */ -#include -#include +#include "kpath.hh" + +#include +#include + +/* + +The problem, as far as I can tell, is that MacOS X has its getopt +prototype in , while I think other operating systems have it +in other places. is included by kpathsea.h, so you end up +renaming both conflicting prototypes to YAKLUDGE. + +I found a somewhat more elegant patch for this: Just #include + before defining YAKLUDGE. + +*/ + +#include -#include "config.h" +#include "config.hh" #define popen REALLYUGLYKLUDGE #define pclose ANOTHERREALLYUGLYKLUDGE +#define getopt YAKLUDGE #if HAVE_KPATHSEA_KPATHSEA_H extern "C" { @@ -22,129 +39,150 @@ extern "C" { #endif #include "file-path.hh" -#include "string.hh" #include "main.hh" -#include "kpath.hh" -#include "lily-version.hh" - +#include "source-file.hh" +#include "warn.hh" -char * -ly_find_afm (char const * name) +String +kpathsea_find_afm (char const *name) { #if (KPATHSEA && HAVE_KPSE_FIND_FILE) - return kpse_find_file (name, kpse_afm_format, true); + + if (char *afm = kpse_find_file (name, kpse_afm_format, false)) + return afm; +#if 0 /* Do not mutter about afms, since we try to find them first, and + lots of TFMs don't have AFMs. */ + warning (_f ("kpathsea can not find AFM file `%s'", name)); #endif - return 0; +#endif + return ""; } String -ly_find_tfm (char const * name) +kpathsea_find_tfm (char const *name) { - String p = global_path.find (String (name) + ".tfm"); - - if (p.length_i ()) - return p; - + String file_name = global_path.find (String (name) + ".tfm"); #if (KPATHSEA && HAVE_KPSE_FIND_FILE) - return kpse_find_file (name, kpse_tfm_format, true); + if (file_name.is_empty ()) + { + /* If invoked for a TeX font, we could do TRUE (must exist). + We could also do: + p = kpse_find_file (name, kpse_mf_format, false); + if (p) + p = kpse_find_file (name, kpse_mf_format, true); + + but we assume that if there is a .PFA, there is also a .TFM, + and it's no use generating TFMs on the fly, because PFAs cannot + be generated on the fly. */ + if (char *tfm = kpse_find_file (name, kpse_tfm_format, false)) + return tfm; + warning (_f ("kpathsea can not find TFM file: `%s'", name)); + } #endif - return ""; + return file_name; } +#if KPATHSEA +/* FIXME: this should be part of kpathsea */ -void -ly_init_kpath (char *av0) +static kpse_file_format_type +kpathsea_find_format (String name) { -#if KPATHSEA && HAVE_KPATHSEA_KPATHSEA_H - /* - We take two pronged approach to tfms: - - * the lilypond tfms (feta*.tfm) are found through our own routines. + for (int i = 0; i < kpse_last_format; i++) + { + if (!kpse_format_info[i].type) + kpse_init_format ((kpse_file_format_type) i); + + char const **suffixes[] = { kpse_format_info[i].suffix, + kpse_format_info[i].alt_suffix }; + for (int j = 0; j < 2; j++) + for (char const **p = suffixes[j]; p && *p; p++) + { + String suffix = *p; + if (name.right_string (suffix.length ()) == suffix) + return (kpse_file_format_type) i; + } + } + return kpse_last_format; +} +#endif - * the TeX tfms are found through vanilla kpathsea. +String +kpathsea_gulp_file_to_string (String name) +{ + String file_name = global_path.find (name); - (* other TFMs are not found, i.e. don't use them. ) +#if (KPATHSEA && HAVE_KPSE_FIND_FILE) + if (file_name.is_empty ()) + { + char *p = kpse_find_file (name.to_str0 (), kpathsea_find_format (name), + true); + if (p) + file_name = p; + else + warning (_f ("kpathsea can not find file: `%s'", name)); + } +#endif - PRO: - - - TFM and AFM checksums always match in Lily. + if (file_name.is_empty ()) + error (_f ("can't find file: `%s'", name)); - - less hassle, no kpathsea spaghetti + if (verbose_global_b) + progress_indication ("[" + file_name); - CON: + int filesize; + char *str = gulp_file (file_name, &filesize); + String string (str); + delete[] str; + + if (verbose_global_b) + progress_indication ("]"); - - feta PK files are often recreated, locally - Solution: cache PK files locally? + return string; +} - - need env. vars to make sure that TeX finds the TFMs +LY_DEFINE (ly_kpathsea_find_file, "ly:kpathsea-find-file", + 1, 0, 0, (SCM name), + "Return the absolute file name of @var{name}," + "or @code{#f} if not found.") +{ + SCM_ASSERT_TYPE (scm_is_string (name), name, SCM_ARG1, __FUNCTION__, "string"); + + String nm = ly_scm2string (name); + String file_name = global_path.find (nm); + if (file_name.is_empty ()) + { + if (char *p = kpse_find_file (nm.to_str0 (), kpathsea_find_format (nm), + true)) + return scm_makfrom0str (p); + return SCM_BOOL_F; + } + return scm_makfrom0str (file_name.to_str0 ()); +} - - Outdated PK (TFM?) font files are not automatically removed, - since VERSION is not part of the standard location. +LY_DEFINE (ly_kpathsea_expand_variable, "ly:kpathsea-expand-variable", + 1, 0, 0, (SCM var), + "Return the expanded version @var{var}.") +{ + SCM_ASSERT_TYPE (scm_is_string (var), var, SCM_ARG1, __FUNCTION__, "string"); + String nm = ly_scm2string (var); + char *result = kpse_var_expand (nm.to_str0 ()); + SCM ret = scm_makfrom0str (result); + delete[] result; - ALTERNATIVE + return ret; +} - we have tried to come up with schemes that leave this kind of work - to kpathsea with objective of fixing the CONs, but miserably - failed. TeX installations and kpathsea itself form a buggy, - inconsistent, and unorderly mess. - - */ +void +initialize_kpathsea (char *av0) +{ +#if KPATHSEA && HAVE_KPATHSEA_KPATHSEA_H /* initialize kpathsea */ kpse_set_program_name (av0, NULL); kpse_maketex_option ("tfm", TRUE); - -#if 0 - - - /* - - Remove the setting for TFMFONTS if we have kpathsea, because - kpathsea can find TFM fonts anyway. - - If we don't lily will want to make tfms for cmr fonts, even if - there is a :: entry in the TFMFONTS path. - - This will fail if a user has special fonts (outside of feta) that - can not be found by kpath. - - If TFMFONTS is unset, TFMs of feta will be generated on the - fly. The risk is that this will cause checksum mismatch errors, - but MF is reasonably deterministic (so we hope not). - - The advantage is that the PK font will also be generated under - /var/texmf/fonts, reducing clutter and compilation time. - - */ - -#ifndef __CYGWIN__ /* mktextfm/mktexpk does not work on windows */ - unsetenv ("TFMFONTS"); -#endif - -#ifdef DEBIAN - String my_tfm = "$VARTEXFONTS/tfm/public/lilypond"; -#else - String my_tfm = "$VARTEXFONTS/tfm/lilypond/"; - my_tfm += version_str () + "/"; -#endif - -#ifdef DEBIAN - char * mypath = strdup ((my_tfm + ":").ch_C()); - kpse_format_info[kpse_tfm_format].client_path = mypath; -#else - char * mypath = kpse_expand (my_tfm.ch_C ()); - - String prog = "mktextfm --destdir "; - prog += mypath; - - kpse_format_info[kpse_tfm_format].program = strdup (prog.ch_C ()); -#endif -#endif #endif - } - -