From a9a00e58b6c2b0a1e384a42ea6e3325addb6815e Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Sun, 6 Mar 2005 17:02:03 +0000 Subject: [PATCH] * lily/GNUmakefile (MODULE_LIBS): link with kpath-guile * lily/all-font-metrics.cc (kpathsea_find_file): wrapper around new ly:kpathsea-find-file * kpath-guile/kpath.c: new file. Put kpath bindings in lib. * kpath-guile/GNUmakefile: new file * scm/font.scm (add-music-fonts): load dynamics/numbers through fontconfig as well. * mf/GNUmakefile: generate .commonff to not confuse fontconfig. * lily/main.cc: only look at one prefix directory, LILYPONDPREFIX overrides all. * config.hh.in: use lilypond-Major.Minor as data directory. --- ChangeLog | 5 ++ GNUmakefile.in | 2 +- config.hh.in | 7 +-- kpath-guile/GNUmakefile | 21 +++++++ kpath-guile/kpath.c | 122 +++++++++++++++++++++++++++++++++++++++ lily/GNUmakefile | 2 +- lily/all-font-metrics.cc | 23 +++++++- lily/include/main.hh | 1 + lily/kpath-scheme.cc | 0 lily/kpath.cc | 0 lily/lily-guile.cc | 11 +++- lily/main.cc | 55 ++++++++++-------- lily/pitch.cc | 2 +- scm/font.scm | 10 ++-- 14 files changed, 221 insertions(+), 40 deletions(-) create mode 100644 kpath-guile/GNUmakefile create mode 100644 kpath-guile/kpath.c delete mode 100644 lily/kpath-scheme.cc delete mode 100644 lily/kpath.cc diff --git a/ChangeLog b/ChangeLog index f1437d9839..08ae07518c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2005-03-06 Han-Wen Nienhuys + * lily/GNUmakefile (MODULE_LIBS): link with kpath-guile + + * lily/all-font-metrics.cc (kpathsea_find_file): wrapper around + new ly:kpathsea-find-file + * kpath-guile/kpath.c: new file. Put kpath bindings in lib. * kpath-guile/GNUmakefile: new file diff --git a/GNUmakefile.in b/GNUmakefile.in index 45b946f3d6..c603ed52eb 100644 --- a/GNUmakefile.in +++ b/GNUmakefile.in @@ -10,7 +10,7 @@ depth = . # SUBDIRS = buildscripts python scripts \ elisp \ - flower ttftool lily \ + flower kpath-guile ttftool lily \ mf ly tex ps scm \ po make \ cygwin debian stepmake \ diff --git a/config.hh.in b/config.hh.in index dff59ec5b2..759ad72f0b 100644 --- a/config.hh.in +++ b/config.hh.in @@ -7,11 +7,8 @@ /* LilyPond init and input base directory */ -/* -urg. -*/ -/* #define PACKAGE_DATADIR DATADIR "/" PACKAGE "@TOPLEVEL_MAJOR_VERSION@.@TOPLEVEL_MINOR_VERSION@" @MAJOR_VERSION@ -#define LILYPOND_DATADIR PACKAGE_DATADIR */ +#define PACKAGE_DATADIR DATADIR "/" PACKAGE / "@TOPLEVEL_VERSION@" +#define LILYPOND_DATADIR PACKAGE_DATADIR /* default lilypond locale dir */ #define LOCALEDIR "@LOCALEDIR@" diff --git a/kpath-guile/GNUmakefile b/kpath-guile/GNUmakefile new file mode 100644 index 0000000000..7d6296be50 --- /dev/null +++ b/kpath-guile/GNUmakefile @@ -0,0 +1,21 @@ +# title top level makefile for FlowerLib +# file flower/Makefile + +# should reinstate versioning if shared libs are enabled. + +depth = .. + +NAME = kpath-guile +MODULE_NAME = kpath-guile + +SCRIPTS = +STEPMAKE_TEMPLATES=library c po + + + +include $(depth)/make/stepmake.make + +CFLAGS += -std=c99 +$(outdir)/kpath.o: $(config_hh) + + diff --git a/kpath-guile/kpath.c b/kpath-guile/kpath.c new file mode 100644 index 0000000000..01f3fde558 --- /dev/null +++ b/kpath-guile/kpath.c @@ -0,0 +1,122 @@ +/* + kpath.c -- implement kpathsea bindings + + source file of the GNU LilyPond music typesetter + + (c) 2005 Han-Wen Nienhuys +*/ + + +#include + +#include "config.hh" +#include "guile-compatibility.hh" + +#if KPATHSEA && HAVE_KPATHSEA_KPATHSEA_H + +#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 + +#define popen REALLYUGLYKLUDGE +#define pclose ANOTHERREALLYUGLYKLUDGE +#define getopt YAKLUDGE + +#if HAVE_KPATHSEA_KPATHSEA_H +#include +#include +#endif + + +#if KPATHSEA +/* FIXME: this should be part of kpathsea */ + +kpse_file_format_type +kpathsea_find_format (const char* name) +{ + int i; + int len = strlen (name); + for (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++) + { + int suflen = strlen (*p); + + if (!strncmp (name + len - suflen, *p, suflen)) + return (kpse_file_format_type) i; + } + } + return kpse_last_format; +} +#endif + + + + + + +// "Return the absolute file name of @var{name}, " +// "or @code{#f} if not found.") +SCM +ly_kpathsea_find_file(SCM name) +{ + SCM_ASSERT_TYPE (scm_is_string (name), name, SCM_ARG1, __FUNCTION__, "string"); + + char const * nm = scm_i_string_chars (name); + char *p = kpse_find_file (nm, kpathsea_find_format (nm), + true); + if (p) + return scm_makfrom0str (p); + return SCM_BOOL_F; +} + +// "Return the expanded version @var{var}.") +SCM ly_kpathsea_expand_variable(SCM var) +{ + SCM_ASSERT_TYPE (scm_is_string (var), var, SCM_ARG1, __FUNCTION__, "string"); + + char const * nm = scm_i_string_chars (var); + char *result = kpse_var_expand (nm); + SCM ret = scm_makfrom0str (result); + free (result); + + return ret; +} + + + +void +initialize_kpathsea () +{ + /* + initialize kpathsea + */ + kpse_set_program_name ("lilypond", NULL); + kpse_maketex_option ("tfm", TRUE); + + SCM find = scm_c_define_gsubr ("ly:kpathsea-find-file", 1, 0, 0, ly_kpathsea_find_file); + scm_c_export ("ly:kpathsea-find-file", NULL); + SCM expand = scm_c_define_gsubr ("ly:kpathsea-expand-variable", 1, 0, 0, ly_kpathsea_find_file); + scm_c_export ("ly:kpathsea-expand-variable", NULL); +} + +#endif diff --git a/lily/GNUmakefile b/lily/GNUmakefile index e5c1fccb02..8070b6ad40 100644 --- a/lily/GNUmakefile +++ b/lily/GNUmakefile @@ -4,7 +4,7 @@ depth = .. NAME = lilypond SUBDIRS = include -MODULE_LIBS=$(depth)/flower $(depth)/ttftool +MODULE_LIBS=$(depth)/flower $(depth)/ttftool $(depth)/kpath-guile MODULE_INCLUDES= $(depth)/flower/include $(depth)/ttftool/include MODULE_CXXFLAGS= diff --git a/lily/all-font-metrics.cc b/lily/all-font-metrics.cc index 29949539e6..2e0009a6f9 100644 --- a/lily/all-font-metrics.cc +++ b/lily/all-font-metrics.cc @@ -97,6 +97,25 @@ All_font_metrics::find_pango_font (PangoFontDescription*description, #endif +String +kpathsea_find_file (String name, String ext) +{ + name += "." + ext; + String path = global_path.find (name); + if (path.length() > 0) + return path; + + SCM kpath = ly_lily_module_constant ("ly:kpathsea-find-file"); + if (ly_c_procedure_p (kpath)) + { + SCM kp_result = scm_call_1 (kpath, scm_makfrom0str (name.to_str0())); + if (scm_is_string (kp_result)) + return ly_scm2string (kp_result); + } + + return ""; +} + /* TODO: our AFM handling is broken: the units in an AFM file are relative to the design size (1000 units = 1 designsize). Hence we @@ -119,7 +138,7 @@ All_font_metrics::find_afm (String name) if (file_name.is_empty ()) { - String p = kpathsea_find_afm (name.to_str0 ()); + String p = kpathsea_find_file (name, "afm"); if (p.length ()) file_name = p; } @@ -225,7 +244,7 @@ All_font_metrics::find_tfm (String name) { /* FIXME: should add "cork-" prefix to lm* fonts. How to do that, cleanly? */ - String p = kpathsea_find_tfm (name.to_str0 ()); + String p = kpathsea_find_file (name, "tfm"); if (p.length ()) file_name = p; } diff --git a/lily/include/main.hh b/lily/include/main.hh index 153c7a1b3c..8d12c49adb 100644 --- a/lily/include/main.hh +++ b/lily/include/main.hh @@ -33,6 +33,7 @@ extern bool be_safe_global; extern bool be_verbose_global; extern bool do_internal_type_checking_global; extern bool is_pango_format_global; +extern bool is_TeX_format_global; extern String prefix_directory; /* diff --git a/lily/kpath-scheme.cc b/lily/kpath-scheme.cc deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/lily/kpath.cc b/lily/kpath.cc deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/lily/lily-guile.cc b/lily/lily-guile.cc index 12035d6501..00b71274b3 100644 --- a/lily/lily-guile.cc +++ b/lily/lily-guile.cc @@ -14,6 +14,7 @@ #include #include // gettext on macos x +#include "config.hh" #include "version.hh" #include "lily-guile.hh" #include "libc-extension.hh" @@ -196,12 +197,18 @@ ly_init_ly_module (void *) { for (int i = scm_init_funcs_->size () ; i--;) (scm_init_funcs_->elem (i)) (); - + if (be_verbose_global) progress_indication ("\n"); #if KPATHSEA - initialize_kpathsea (); + if (is_TeX_format_global) + { + /* + TODO: load this dynamically + */ + initialize_kpathsea (); + } #endif scm_primitive_load_path (scm_makfrom0str ("lily.scm")); diff --git a/lily/main.cc b/lily/main.cc index 3ad0b6645e..52e2c27710 100644 --- a/lily/main.cc +++ b/lily/main.cc @@ -53,6 +53,7 @@ String init_name_global; String output_backend_global = "ps"; String output_format_global = "pdf"; bool is_pango_format_global; +bool is_TeX_format_global; /* Current output name. */ String output_name_global; @@ -90,25 +91,25 @@ static char const *PROGRAM_NAME = "lilypond"; static char const *PROGRAM_URL = "http://lilypond.org"; static char const *NOTICE = -_f ("This program is free software. It is covered by the GNU General Public\n" - "License and you are welcome to change it and/or distribute copies of it\n" - "under certain conditions. Invoke as `%s --warranty' for more\n" - "information.\n", "lilypond").to_str0 (); +"This program is free software. It is covered by the GNU General Public\n" +"License and you are welcome to change it and/or distribute copies of it\n" +"under certain conditions. Invoke as `%s --warranty' for more\n" +"information.\n"; static char const *WARRANTY = -_i (" This program is free software; you can redistribute it and/or\n" - "modify it under the terms of the GNU General Public License version 2\n" - "as published by the Free Software Foundation.\n" - "\n" - " This program is distributed in the hope that it will be useful,\n" - "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" - "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n" - "General Public License for more details.\n" - "\n" - " You should have received a copy (refer to the file COPYING) of the\n" - "GNU General Public License along with this program; if not, write to\n" - "the Free Software Foundation, Inc., 59 Temple Place - Suite 330,\n" - "Boston, MA 02111-1307, USA.\n"); +" This program is free software; you can redistribute it and/or\n" +"modify it under the terms of the GNU General Public License version 2\n" +"as published by the Free Software Foundation.\n" +"\n" +" This program is distributed in the hope that it will be useful,\n" +"but WITHOUT ANY WARRANTY; without even the implied warranty of\n" +"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n" +"General Public License for more details.\n" +"\n" +" You should have received a copy (refer to the file COPYING) of the\n" +"GNU General Public License along with this program; if not, write to\n" +"the Free Software Foundation, Inc., 59 Temple Place - Suite 330,\n" +"Boston, MA 02111-1307, USA.\n"; /* Where the init files live. Typically: @@ -158,7 +159,12 @@ static void dir_info (FILE *out) { fputs ("\n", out); - fprintf (out, "Directory prefix: \"%s\"\n", prefix_directory.to_str0()); + fprintf (out, "LILYPOND_DATADIR=\"%s\"\n", LILYPOND_DATADIR); + if (char const * env = getenv ("LILYPONDPREFIX")) + fprintf (out, "LILYPONDPREFIX=\"%s\"\n", env); + fprintf (out, "LOCALEDIR=\"%s\"\n", LOCALEDIR); + + fprintf (out, "\nEffective prefix: \"%s\"\n", prefix_directory.to_str0()); } static void @@ -181,7 +187,7 @@ static void notice () { identify (stdout); - printf (_f (NOTICE, PROGRAM_NAME).to_str0 ()); + puts (_f (NOTICE, PROGRAM_NAME).to_str0 ()); printf ("\n"); copyright (); } @@ -220,7 +226,7 @@ warranty () static void setup_paths () { - prefix_directory = DATADIR "/lilypond/" MAJOR_VERSION "." MINOR_VERSION; + prefix_directory = LILYPOND_DATADIR; if (char const * env = getenv ("LILYPONDPREFIX")) prefix_directory = env; @@ -351,6 +357,11 @@ main_with_guile (void *, int, char **) if (be_verbose_global) dir_info (stderr); + is_TeX_format_global = (output_backend_global == "tex" + || output_backend_global == "texstr"); + + is_pango_format_global = !is_TeX_format_global; + ly_c_init_guile (); call_constructors (); @@ -359,9 +370,6 @@ main_with_guile (void *, int, char **) init_freetype (); - is_pango_format_global = (output_backend_global != "tex" - && output_backend_global != "texstr"); - all_fonts_global = new All_font_metrics (global_path.to_string ()); init_scheme_code_string += ")"; @@ -527,7 +535,6 @@ main (int argc, char **argv) setup_paths (); parse_argv (argc, argv); identify (stderr); - initialize_kpathsea (argv[0]); scm_boot_guile (argc, argv, main_with_guile, 0); diff --git a/lily/pitch.cc b/lily/pitch.cc index 28a562bdc8..9b6f7fb6d4 100644 --- a/lily/pitch.cc +++ b/lily/pitch.cc @@ -184,7 +184,7 @@ Pitch::to_string () const { int o = (-octave_) - 1; while (o--) - s += ::to_string (', '); + s += ::to_string (','); } return s; diff --git a/scm/font.scm b/scm/font.scm index bede4008e2..a5fdf4ea85 100644 --- a/scm/font.scm +++ b/scm/font.scm @@ -332,10 +332,12 @@ (let ((n (make-font-tree-node 'font-encoding 'fetaMusic))) (add-music-fonts n factor) (add-cmr-fonts n factor) - (if (ly:kpathsea-find-file "lmr10.pfb") - (add-cork-lm-fonts n factor)) - (if (ly:kpathsea-find-file "ecrm10.pfa") - (add-ec-fonts n factor)) + (if (defined? 'ly:kpathsea-find-file) + (begin + (if (ly:kpathsea-find-file "lmr10.pfb") + (add-cork-lm-fonts n factor)) + (if (ly:kpathsea-find-file "ecrm10.pfa") + (add-ec-fonts n factor)))) n)) (define-public (make-century-schoolbook-tree factor) -- 2.39.2