From c89be8cc5794d62769a35719e68fddf0a8448faa Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Fri, 7 Jan 2005 13:36:42 +0000 Subject: [PATCH] *** empty log message *** --- lily/grob-interface-scheme.cc | 2 + lily/include/kpath-private.hh | 18 +++++++ lily/input-scheme.cc | 47 ++++++++++++++++++ lily/input-smob.cc | 35 ------------- lily/kpath-scheme.cc | 94 +++++++++++++++++++++++++++++++++++ lily/kpath.cc | 50 +------------------ lily/score-scheme.cc | 50 ++++++++++++++++++- lily/score.cc | 45 ----------------- 8 files changed, 212 insertions(+), 129 deletions(-) create mode 100644 lily/include/kpath-private.hh create mode 100644 lily/input-scheme.cc create mode 100644 lily/kpath-scheme.cc diff --git a/lily/grob-interface-scheme.cc b/lily/grob-interface-scheme.cc index 466c4bbcbb..9eccbd906e 100644 --- a/lily/grob-interface-scheme.cc +++ b/lily/grob-interface-scheme.cc @@ -8,6 +8,8 @@ */ #include "lily-guile.hh" +#include "protected-scm.hh" +#include "string.hh" Protected_scm all_ifaces; diff --git a/lily/include/kpath-private.hh b/lily/include/kpath-private.hh new file mode 100644 index 0000000000..d8fa199e66 --- /dev/null +++ b/lily/include/kpath-private.hh @@ -0,0 +1,18 @@ +/* + kpath-private.hh -- declare + + source file of the GNU LilyPond music typesetter + + (c) 2005 Han-Wen Nienhuys + +*/ + +#ifndef KPATH_PRIVATE_HH +#define KPATH_PRIVATE_HH + +kpse_file_format_type kpathsea_find_format (String name); + +#endif /* KPATH_PRIVATE_HH */ + + + diff --git a/lily/input-scheme.cc b/lily/input-scheme.cc new file mode 100644 index 0000000000..2478bc9591 --- /dev/null +++ b/lily/input-scheme.cc @@ -0,0 +1,47 @@ +/* + input-scheme.cc -- implement Input bindings. + + source file of the GNU LilyPond music typesetter + + (c) 2005 Han-Wen Nienhuys + +*/ + +#include "string.hh" +#include "input-smob.hh" + +/* We don't use IMPLEMENT_TYPE_P, since the smobification part is + implemented separately from the class. */ +LY_DEFINE (ly_input, "ly:input-location?", 1, 0, 0, + (SCM x), + "Return #t if @var{x} is an input location.") +{ + return unsmob_input (x) ? SCM_BOOL_T : SCM_BOOL_F; +} + +LY_DEFINE (ly_input_message, "ly:input-message", 2, 0, 0, (SCM sip, SCM msg), + "Print @var{msg} as a GNU compliant error message, pointing to the" + "location in @var{sip}.\n") +{ + Input *ip = unsmob_input (sip); + SCM_ASSERT_TYPE (ip, sip, SCM_ARG1, __FUNCTION__, "input location"); + SCM_ASSERT_TYPE (scm_is_string (msg), msg, SCM_ARG2, __FUNCTION__, "string"); + + String m = ly_scm2string (msg); + ip->message (m); + + return SCM_UNSPECIFIED; +} + +/* + TODO: rename this function. ly:input-location? vs ly:input-location + */ +LY_DEFINE (ly_input_location, "ly:input-location", 1, 0, 0, (SCM sip), + "Return input location in @var{sip} as (file-name line column).") +{ + Input *ip = unsmob_input (sip); + SCM_ASSERT_TYPE (ip, sip, SCM_ARG1, __FUNCTION__, "input location"); + return scm_list_3 (scm_makfrom0str (ip->file_string ().to_str0 ()), + scm_int2num (ip->line_number ()), + scm_int2num (ip->column_number ())); +} diff --git a/lily/input-smob.cc b/lily/input-smob.cc index 0dd973956f..8dbf4d87f9 100644 --- a/lily/input-smob.cc +++ b/lily/input-smob.cc @@ -71,41 +71,6 @@ unsmob_input (SCM s) return 0; } -/* We don't use IMPLEMENT_TYPE_P, since the smobification part is - implemented separately from the class. */ -LY_DEFINE (ly_input, "ly:input-location?", 1, 0, 0, - (SCM x), - "Return #t if @var{x} is an input location.") -{ - return unsmob_input (x) ? SCM_BOOL_T : SCM_BOOL_F; -} - -LY_DEFINE (ly_input_message, "ly:input-message", 2, 0, 0, (SCM sip, SCM msg), - "Print @var{msg} as a GNU compliant error message, pointing to the" - "location in @var{sip}.\n") -{ - Input *ip = unsmob_input (sip); - SCM_ASSERT_TYPE (ip, sip, SCM_ARG1, __FUNCTION__, "input location"); - SCM_ASSERT_TYPE (scm_is_string (msg), msg, SCM_ARG2, __FUNCTION__, "string"); - - String m = ly_scm2string (msg); - ip->message (m); - - return SCM_UNSPECIFIED; -} - -/* - TODO: rename this function. ly:input-location? vs ly:input-location - */ -LY_DEFINE (ly_input_location, "ly:input-location", 1, 0, 0, (SCM sip), - "Return input location in @var{sip} as (file-name line column).") -{ - Input *ip = unsmob_input (sip); - SCM_ASSERT_TYPE (ip, sip, SCM_ARG1, __FUNCTION__, "input location"); - return scm_list_3 (scm_makfrom0str (ip->file_string ().to_str0 ()), - scm_int2num (ip->line_number ()), - scm_int2num (ip->column_number ())); -} ADD_SCM_INIT_FUNC (input, start_input_smobs); diff --git a/lily/kpath-scheme.cc b/lily/kpath-scheme.cc new file mode 100644 index 0000000000..8275c8b203 --- /dev/null +++ b/lily/kpath-scheme.cc @@ -0,0 +1,94 @@ +/* + kpath-scheme.cc -- implement kpathsea bindings + + source file of the GNU LilyPond music typesetter + + (c) 2005 Han-Wen Nienhuys + +*/ + +#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.hh" + +#define popen REALLYUGLYKLUDGE +#define pclose ANOTHERREALLYUGLYKLUDGE +#define getopt YAKLUDGE + +#if HAVE_KPATHSEA_KPATHSEA_H +extern "C" { +#include +#include +} +#endif + +#include "file-path.hh" +#include "main.hh" +#include "source-file.hh" +#include "warn.hh" +#include "kpath-private.hh" + +LY_DEFINE (ly_find_file, "ly: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 ()) + return SCM_BOOL_F; + + return scm_makfrom0str (file_name.to_str0 ()); +} + +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 ()); +} + +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; + + return ret; +} diff --git a/lily/kpath.cc b/lily/kpath.cc index 592d70d09a..2757cf3508 100644 --- a/lily/kpath.cc +++ b/lily/kpath.cc @@ -42,6 +42,7 @@ extern "C" { #include "main.hh" #include "source-file.hh" #include "warn.hh" +#include "kpath-private.hh" String kpathsea_find_afm (char const *name) @@ -85,7 +86,7 @@ kpathsea_find_tfm (char const *name) #if KPATHSEA /* FIXME: this should be part of kpathsea */ -static kpse_file_format_type +kpse_file_format_type kpathsea_find_format (String name) { for (int i = 0; i < kpse_last_format; i++) @@ -142,53 +143,6 @@ kpathsea_gulp_file_to_string (String name) } -LY_DEFINE (ly_find_file, "ly: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 ()) - return SCM_BOOL_F; - - return scm_makfrom0str (file_name.to_str0 ()); -} - -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 ()); -} - -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; - - return ret; -} void initialize_kpathsea (char *av0) diff --git a/lily/score-scheme.cc b/lily/score-scheme.cc index 63d82b425c..f5b4369971 100644 --- a/lily/score-scheme.cc +++ b/lily/score-scheme.cc @@ -1,5 +1,5 @@ /* - score-scheme.cc -- implement + score-scheme.cc -- implement Score bindings. source file of the GNU LilyPond music typesetter @@ -10,6 +10,8 @@ #include "score.hh" #include "music.hh" +#include "output-def.hh" +#include "global-context.hh" LY_DEFINE (ly_music_scorify, "ly:music-scorify", 2, 0, 0, @@ -26,3 +28,49 @@ LY_DEFINE (ly_music_scorify, "ly:music-scorify", scm_gc_unprotect_object (score->self_scm ()); return score->self_scm (); } + +LY_DEFINE (ly_score_embedded_format, "ly:score-embedded-format", + 2, 1, 0, (SCM score, SCM layout, SCM key), + "Run @var{score} through @var{layout}, an output definition, " + "scaled to correct outputscale already, " + "return a list of layout-lines. " + "\nTake optional Object_key argument." + ) +{ + Score * sc = unsmob_score (score); + Output_def *od = unsmob_output_def (layout); + + if (sc->error_found_) + { + return SCM_EOL; + } + + SCM_ASSERT_TYPE (sc, score, SCM_ARG1, __FUNCTION__, "Score"); + SCM_ASSERT_TYPE (od, layout, SCM_ARG2, __FUNCTION__, "Output_def"); + + Output_def * score_def = 0; + + /* UGR, FIXME, these are default \layout blocks once again. They + suck. */ + for (int i = 0; !score_def && i < sc->defs_.size (); i++) + if (sc->defs_[i]->c_variable ("is-layout") == SCM_BOOL_T) + score_def = sc->defs_[i]; + + if (!score_def) + return scm_c_make_vector (0, SCM_EOL); + + score_def = score_def->clone (); + SCM prot = score_def->self_scm (); + scm_gc_unprotect_object (prot); + + /* TODO: SCORE_DEF should be scaled according to OD->parent_ or OD + itself. */ + score_def->parent_ = od; + + SCM context = ly_run_translator (sc->get_music (), score_def->self_scm (), + key); + SCM lines = ly_format_output (context, scm_makfrom0str ("")); + + scm_remember_upto_here_1 (prot); + return lines; +} diff --git a/lily/score.cc b/lily/score.cc index d94bd14b5f..cadb817b44 100644 --- a/lily/score.cc +++ b/lily/score.cc @@ -210,51 +210,6 @@ Score::book_rendering (String outname, -LY_DEFINE (ly_score_embedded_format, "ly:score-embedded-format", - 2, 1, 0, (SCM score, SCM layout, SCM key), - "Run @var{score} through @var{layout}, an output definition, " - "scaled to correct outputscale already, " - "return a list of layout-lines. " - "\nTake optional Object_key argument." - ) -{ - Score * sc = unsmob_score (score); - Output_def *od = unsmob_output_def (layout); - - if (sc->error_found_) - { - return SCM_EOL; - } - - SCM_ASSERT_TYPE (sc, score, SCM_ARG1, __FUNCTION__, "Score"); - SCM_ASSERT_TYPE (od, layout, SCM_ARG2, __FUNCTION__, "Output_def"); - - Output_def * score_def = 0; - - /* UGR, FIXME, these are default \layout blocks once again. They - suck. */ - for (int i = 0; !score_def && i < sc->defs_.size (); i++) - if (sc->defs_[i]->c_variable ("is-layout") == SCM_BOOL_T) - score_def = sc->defs_[i]; - - if (!score_def) - return scm_c_make_vector (0, SCM_EOL); - - score_def = score_def->clone (); - SCM prot = score_def->self_scm (); - scm_gc_unprotect_object (prot); - - /* TODO: SCORE_DEF should be scaled according to OD->parent_ or OD - itself. */ - score_def->parent_ = od; - - SCM context = ly_run_translator (sc->get_music (), score_def->self_scm (), - key); - SCM lines = ly_format_output (context, scm_makfrom0str ("")); - - scm_remember_upto_here_1 (prot); - return lines; -} void Score::set_music (SCM music, SCM parser) -- 2.39.5