From d2e4390228fda788ff46b23c56fdb531f135fd72 Mon Sep 17 00:00:00 2001 From: hanwen Date: Tue, 29 Nov 2005 16:17:57 +0000 Subject: [PATCH] * configure.in (LINK_GXX_STATICALLY): remove kpathsea checks. * scm/kpathsea.scm (ly:kpathsea-expand-variable): new file. Encapsulate kpathsea using commandline tools. * lily/all-font-metrics.cc (kpathsea_find_file): use (scm kpathsea) module. --- ChangeLog | 12 ++ GNUmakefile.in | 4 +- buildscripts/mutopia-index.py | 3 +- configure.in | 2 - kpath-guile/GNUmakefile | 15 --- kpath-guile/SConscript | 19 ---- kpath-guile/kpath.c | 199 ---------------------------------- lily/all-font-metrics.cc | 13 ++- lily/lily-guile.cc | 11 -- scm/backend-library.scm | 4 +- scm/font.scm | 17 +-- scm/framework-tex.scm | 3 +- scm/kpathsea.scm | 48 ++++++++ 13 files changed, 89 insertions(+), 261 deletions(-) delete mode 100644 kpath-guile/GNUmakefile delete mode 100644 kpath-guile/SConscript delete mode 100644 kpath-guile/kpath.c create mode 100644 scm/kpathsea.scm diff --git a/ChangeLog b/ChangeLog index da784ae899..5c2bf061de 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2005-11-29 Han-Wen Nienhuys + + * configure.in (LINK_GXX_STATICALLY): remove kpathsea checks. + + * kpath-guile/: remove directory + + * scm/kpathsea.scm (ly:kpathsea-expand-variable): new + file. Encapsulate kpathsea using commandline tools. + + * lily/all-font-metrics.cc (kpathsea_find_file): use (scm + kpathsea) module. + 2005-11-29 Mats Bengtsson * Documentation/user/advanced-notation.itely (Setting automatic diff --git a/GNUmakefile.in b/GNUmakefile.in index 7da071d5ce..33c9afb210 100644 --- a/GNUmakefile.in +++ b/GNUmakefile.in @@ -3,7 +3,7 @@ depth = . SUBDIRS = buildscripts python scripts \ - flower kpath-guile lily \ + flower lily \ mf ly \ tex ps scm \ po make \ @@ -64,7 +64,7 @@ footifymail = MAILADDRESS=bug-lilypond@gnu.org local-WWW-post: # need UTF8 setting in case this is hosted on a website. echo -e 'AddDefaultCharset utf-8\nAddCharset utf-8 .html\nAddCharset utf-8 .en\nAddCharset utf-8 .nl\nAddCharset utf-8 .txt\n' > $(top-build-dir)/.htaccess - $(PYTHON) $(buildscript-dir)/mutopia-index.py -o $(outdir)/examples.html ./ + $(PYTHON) $(buildscript-dir)/mutopia-index.py -o $(outdir)/examples.html input/ echo '' > $(outdir)/index.html echo 'Redirecting to the documentation index...' >> $(outdir)/index.html diff --git a/buildscripts/mutopia-index.py b/buildscripts/mutopia-index.py index 977226317d..8b02ea4ba2 100644 --- a/buildscripts/mutopia-index.py +++ b/buildscripts/mutopia-index.py @@ -18,6 +18,7 @@ def find (pat, dir): return lst +junk_prefix = 'out-www/' headertext= r""" @@ -132,7 +133,7 @@ hr { border:0; height:1; color: #000000; background-color: #000000; }\n def list_item (file_name, desc, type, lst = list): if os.path.isfile (file_name): lst.write ('
  • %s' - % (file_name, desc)) + % (re.sub (junk_prefix, '', file_name), desc)) # FIXME: include warning if it uses \include # files. diff --git a/configure.in b/configure.in index fa45693908..ad434c0346 100644 --- a/configure.in +++ b/configure.in @@ -46,8 +46,6 @@ AC_SUBST(LINK_GXX_STATICALLY) # must come before any header checks STEPMAKE_COMPILE -STEPMAKE_KPATHSEA - STEPMAKE_PYTHON(REQUIRED, 2.2) STEPMAKE_GCC(REQUIRED, 2.8) STEPMAKE_CXX(REQUIRED) diff --git a/kpath-guile/GNUmakefile b/kpath-guile/GNUmakefile deleted file mode 100644 index e7e92d6f7e..0000000000 --- a/kpath-guile/GNUmakefile +++ /dev/null @@ -1,15 +0,0 @@ -depth = .. - -NAME = kpath-guile -MODULE_NAME = kpath-guile -MODULE_LDFLAGS= = -lkpathsea -SCRIPTS = -STEPMAKE_TEMPLATES = library c po - -MODULE_CFLAGS = -std=c99 - -include $(depth)/make/stepmake.make - -$(outdir)/kpath.o: $(config_hh) - - diff --git a/kpath-guile/SConscript b/kpath-guile/SConscript deleted file mode 100644 index fad693317c..0000000000 --- a/kpath-guile/SConscript +++ /dev/null @@ -1,19 +0,0 @@ -# -*-python-*- - -Import ('env', 'src_glob') -sources = src_glob ('*.c') -includes = src_glob ('*.h') -outdir = Dir ('.').path - -name = 'kpath-guile' -e = env.Copy () -e.Append (CPPPATH = ['/#ttftool/include', '#/flower/include', outdir,], - CCFLAGS = '-std=c99', - ) -if env['static']: - e.Library (name, sources) -if not env['static'] or env['shared']: - e.SharedLibrary (name, sources) - -po = env.Command ('lilypond.po', sources + includes, env['pocommand']) -env.Alias ('po-update', po) diff --git a/kpath-guile/kpath.c b/kpath-guile/kpath.c deleted file mode 100644 index 64cdb187d9..0000000000 --- a/kpath-guile/kpath.c +++ /dev/null @@ -1,199 +0,0 @@ -/* - kpath.c -- implement kpathsea bindings - - source file of the GNU LilyPond music typesetter - - (c) 2005 Han-Wen Nienhuys -*/ - - -#include - -#include "config.hh" - -#if KPATHSEA - -#include "guile-compatibility.hh" - -#if !HAVE_GETTEXT -inline char * -gettext (char const *s) -{ - return (char *)s; -} -#else -#include -#endif - -#define _(x) gettext (x) - -#include -#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 - KPATHSEA_HAS_GETOPT_PROTOTYPE_PROBLEM. - - I (?) found a somewhat more elegant patch for this: Just #include - before defining KPATHSEA_HAS_GETOPT_PROTOTYPE_PROBLEM. */ - -#include - -#define popen KPATHSEA_HAS_POPEN_PROTOTYPE_PROBLEM -#define pclose KPATHSEA_HAS_PCLOSE_PROTOTYPE_PROBLEM -#define getopt KPATHSEA_HAS_GETOPT_PROTOTYPE_PROBLEM - -#if HAVE_KPATHSEA_KPATHSEA_H -#include -#include -#endif - -static void *kpathsea_handle = 0; -static char *(*dl_kpse_find_file) (char const*, kpse_file_format_type, boolean) = 0; -static void (*dl_kpse_maketex_option) (char const*, boolean) = 0; -static void (*dl_kpse_set_program_name) (char const*, char const*) = 0; -static char const *(*dl_kpse_init_format) (kpse_file_format_type) = 0; -static char *(*dl_kpse_var_expand) (char const*) = 0; -static kpse_format_info_type (*dl_kpse_format_info)[kpse_last_format] = 0; - -kpse_file_format_type -kpathsea_find_format (char const* name) -{ - int i; - int len = strlen (name); - for (i = 0; i < kpse_last_format; i++) - { - if (!(*dl_kpse_format_info)[i].type) - (*dl_kpse_init_format) ((kpse_file_format_type) i); - - char const **suffixes[] = { (*dl_kpse_format_info)[i].suffix, - (*dl_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; -} - -// "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 = (*dl_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 = (*dl_kpse_var_expand) (nm); - SCM ret = scm_makfrom0str (result); - free (result); - - return ret; -} - -#ifndef DYNAMIC_OBJECT_EXTENSION -#define DYNAMIC_OBJECT_EXTENSION ".so" -#endif - - -static char const* LIBKPATHSEA = "libkpathsea" DYNAMIC_OBJECT_EXTENSION; - -int -open_library () -{ -#if HAVE_LIBKPATHSEA_SO - struct - { - void **func_pointer; - char const *name; - } symbols[] = { - {(void*)&dl_kpse_find_file, "kpse_find_file"}, - {(void*)&dl_kpse_set_program_name, "kpse_set_program_name"}, - {(void*)&dl_kpse_format_info, "kpse_format_info"}, - {(void*)&dl_kpse_init_format, "kpse_init_format"}, - {(void*)&dl_kpse_maketex_option, "kpse_maketex_option"}, - {(void*)&dl_kpse_var_expand, "kpse_var_expand"}, - {0,0} - }; - - - dlerror (); - kpathsea_handle = dlopen (LIBKPATHSEA, RTLD_LAZY); - if (!kpathsea_handle) - { - /* - todo i18n. - */ - fprintf (stderr, _ ("can't dlopen: %s: %s"), LIBKPATHSEA, dlerror ()); - fprintf (stderr, _ ("install package: %s or %s"), - "libkpathsea3 (teTeX 2.x)", - "libkpathsea4 (teTeX 3.x)"); - - return 1; - } - - for (int i = 0; symbols[i].func_pointer; i++) - { - dlerror (); - *symbols[i].func_pointer = dlsym (kpathsea_handle, symbols[i].name); - if (!symbols[i].func_pointer) - { - fprintf (stderr, _ ("no such symbol: %s: %s"), - symbols[i].name, - dlerror ()); - return 1; - } - } - return 0; -#else - dl_kpse_find_file = &kpse_find_file; - dl_kpse_set_program_name = &kpse_set_program_name; - dl_kpse_format_info = &kpse_format_info; - dl_kpse_init_format = &kpse_init_format; - dl_kpse_maketex_option = &kpse_maketex_option; - dl_kpse_var_expand = &kpse_var_expand; - return 0; -#endif -} - -void -initialize_kpathsea () -{ - if (open_library ()) - { - fprintf (stderr, _ ("error opening kpathsea library")); - fprintf (stderr, _ ("aborting")); - exit (1); - } - - (*dl_kpse_set_program_name) ("lilypond", "lilypond"); - (*dl_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_expand_variable); - scm_c_export ("ly:kpathsea-expand-variable", NULL); -} - -#endif diff --git a/lily/all-font-metrics.cc b/lily/all-font-metrics.cc index e49f36c13a..440e16ca66 100644 --- a/lily/all-font-metrics.cc +++ b/lily/all-font-metrics.cc @@ -107,10 +107,17 @@ kpathsea_find_file (String name, String ext) if (path.length () > 0) return path; - SCM kpath = ly_lily_module_constant ("ly:kpathsea-find-file"); - if (ly_is_procedure (kpath)) + static SCM proc; + if (!proc) { - SCM kp_result = scm_call_1 (kpath, scm_makfrom0str (name.to_str0 ())); + SCM module = scm_c_resolve_module ("scm kpathsea"); + proc = scm_c_module_lookup (module, "ly:kpathsea-find-file"); + proc = scm_variable_ref (proc); + } + + if (ly_is_procedure (proc)) + { + SCM kp_result = scm_call_1 (proc, scm_makfrom0str (name.to_str0 ())); if (scm_is_string (kp_result)) return ly_scm2string (kp_result); } diff --git a/lily/lily-guile.cc b/lily/lily-guile.cc index 2018100d55..c38aa9eeff 100644 --- a/lily/lily-guile.cc +++ b/lily/lily-guile.cc @@ -189,12 +189,6 @@ void add_scm_init_func (void (*f) ()) scm_init_funcs_->push (f); } -#if KPATHSEA -extern "C" { - void initialize_kpathsea (); -} -#endif - void ly_init_ly_module (void *) { @@ -204,11 +198,6 @@ ly_init_ly_module (void *) if (be_verbose_global) progress_indication ("\n"); -#if KPATHSEA - if (is_TeX_format_global) - initialize_kpathsea (); -#endif - scm_primitive_load_path (scm_makfrom0str ("lily.scm")); } diff --git a/scm/backend-library.scm b/scm/backend-library.scm index 18c9c0d2bc..0030b15e1e 100644 --- a/scm/backend-library.scm +++ b/scm/backend-library.scm @@ -27,9 +27,11 @@ (throw 'ly-file-failed))))) (define-public (sanitize-command-option str) + "Kill dubious shell quoting" + (string-append "\"" - (regexp-substitute/global #f "[^- 0-9,.a-zA-Z'\"\\]" str 'pre 'post) + (regexp-substitute/global #f "[^-_ 0-9,.a-zA-Z'\"\\]" str 'pre 'post) "\"")) (define-public (search-executable names) diff --git a/scm/font.scm b/scm/font.scm index d72a8d23a1..bc8723d4f2 100644 --- a/scm/font.scm +++ b/scm/font.scm @@ -327,15 +327,18 @@ (add-node 'italic 'bold)) (define-public (make-cmr-tree factor) - (let ((n (make-font-tree-node 'font-encoding 'fetaMusic))) + (let* + ((n (make-font-tree-node 'font-encoding 'fetaMusic)) + (module (resolve-module '(scm kpathsea))) + (find (eval 'ly:kpathsea-find-file module)) + ) (add-music-fonts n factor) (add-cmr-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)))) + + (if (find "lmr10.pfb") + (add-cork-lm-fonts n factor)) + (if (find "ecrm10.pfa") + (add-ec-fonts n factor)) n)) diff --git a/scm/framework-tex.scm b/scm/framework-tex.scm index 3f2821b783..52ce2e982c 100644 --- a/scm/framework-tex.scm +++ b/scm/framework-tex.scm @@ -15,6 +15,7 @@ (srfi srfi-1) (srfi srfi-13) (srfi srfi-14) + (scm kpathsea) (lily)) (define (output-formats) @@ -345,7 +346,7 @@ (string->number (regexp-substitute/global #f " *%.*\n?" - (ly:kpathsea-expand-variable "$extra_mem_top") + (ly:kpathsea-expand-variable "extra_mem_top") 'pre "" 'post))) (base (basename name ".tex")) (cmd (format diff --git a/scm/kpathsea.scm b/scm/kpathsea.scm new file mode 100644 index 0000000000..845abefb04 --- /dev/null +++ b/scm/kpathsea.scm @@ -0,0 +1,48 @@ +;; +;; kpathsea.scm -- implement kpath support using command-line +;; +;; +;; source file of the GNU LilyPond music typesetter +;; +;; (c) 2005 Han-Wen Nienhuys +;; + +(define-module (scm kpathsea)) + +(use-modules (ice-9 popen) + (lily) + (ice-9 rdelim)) + + + +(define-public (ly:kpathsea-find-file name) + (let* + ((cmd (format #f "kpsewhich ~a" + (sanitize-command-option name))) + (unused (if (ly:get-option 'verbose) + (ly:message "Running ~a" cmd))) + (pipe (open-input-pipe cmd)) + (answer (read-line pipe))) + + (if (string? answer) + answer + #f))) + +(define-public (ly:kpathsea-expand-variable var) + (let* + ((cmd (format #f "kpsexpand '$'~a" + (sanitize-command-option var))) + (unused (if (ly:get-option 'verbose) + (ly:message "Running ~a" cmd))) + (pipe (open-input-pipe cmd)) + (answer (read-line pipe))) + + (if (string? answer) + answer #f))) + +;; Test: + +;;(display (ly:kpathsea-find-file "cmr10.tfm")) +;; +;;(display (ly:kpathsea-expand-variable "TEXMF")) + -- 2.39.5