2004-04-11 Han-Wen Nienhuys <hanwen@xs4all.nl>
+ * lily/music-output-def.cc (LY_DEFINE): ly:output-description
+ new function.
+
+ * lily/main.cc: remove global_score_count.
+
+ * lily/book.cc (process): don't take header from global_input_file.
+
+ * buildscripts/lilypond-profile.sh (Error): set GS_FONTPATH
+
+ * lily/parser.yy (My_lily_lexer): remove current_parser global var.
+
+ * lily/music-output-def.cc (LY_DEFINE): new function
+ ly_output_description. This function does the bulk for setting,
+ parsing and breaking down of an input file.
+
+ * lily/ly-module.cc (ly_make_anonymous_module): don't protect
+ anonymous modules globally. Let's hope they get GCd
+
* scripts/lilypond.py (run_dvips): add sauter-mftrace.map
2004-04-11 Jan Nieuwenhuizen <janneke@gnu.org>
## export GS_LIB
# For direct ps output fonts. Add all available TeX Type1 fonts
- ## GS_FONTPATH=`kpsewhich -expand-path=\\$T1FONTS`:${GS_FONTPATH:=""}
- ## export GS_FONTPATH
+ tmppfadir=`kpsewhich ecrm10.pfa`
+ GS_FONTPATH=$datadir/pfa:`dirname $tmppfadir`:${GS_FONTPATH:=""}
+ export GS_FONTPATH
fi # remove for zsh
#include "config.h"
#include "main.hh"
#include "all-font-metrics.hh"
-
#include "warn.hh"
#include "afm.hh"
#include "tfm.hh"
if (paper)
paper_book->papers_.push (paper);
paper_book->scores_.push (systems);
- paper_book->global_headers_.push (global_input_file->header_);
+
+ // fixme.
+ //paper_book->global_headers_.push (global_input_file->header_);
//paper_book->headers_.push (scores_[i]->header_);
paper_book->headers_.push (header);
}
#ifndef FILE_RESULTS_HH
#define FILE_RESULTS_HH
-#include "lily-proto.hh"
-#include "source.hh"
-#include "parray.hh"
-#include "protected-scm.hh"
+#include "lily-guile.hh"
-class Input_file_results
-{
-public:
- Sources sources_;
- Array<String> inclusion_names_;
- Array<String> target_strings_;
- Protected_scm header_;
- int book_count_;
- int score_count_;
-
- void do_deps (String);
-
- Input_file_results (String init, String in, String out);
- ~Input_file_results ();
-
-private:
- /* Make sure we never get an implicit constructor.*/
- Input_file_results ();
-};
-
-extern Input_file_results* global_input_file;
-
-void do_one_file (char const* file);
+SCM ly_parse_file (SCM);
#endif /* FILE_RESULTS_HH */
#include "array.hh"
void read_lily_scm_file (String);
-void ly_init_guile ();
+void ly_c_init_guile ();
bool is_direction (SCM s);
bool is_number_pair (SCM);
void set_default_output (String s);
String find_file (String);
void call_constructors ();
-extern Array<String> get_inclusion_names ();
-extern void set_inclusion_names (Array<String>);
+
+Array<String> get_inclusion_names ();
+void set_inclusion_names (Array<String>);
+
+
extern String init_name_global;
/* FIXME: in warn.cc */
extern Array<String> failed_files;
extern int exit_status_global;
extern File_path global_path;
-extern int score_count_global;
#endif /* MAIN_HH */
public:
Scheme_hash_table * translator_tab_;
Input input_origin_;
-
+ Array<String> targets_;
SCM scope_;
virtual void derived_mark ();
SCM get_scmvar (String id) const;
SCM lookup_variable (SCM sym) const;
void set_variable (SCM, SCM sym);
+ // fixme: dependencies
+ // virtual void add_target_file (String);
DECLARE_SMOBS (Music_output_def,);
};
void kill_lexer ();
void set_lexer ();
-/// lexer for LilyPond
class My_lily_lexer : public Includable_lexer
{
Protected_scm scopes_;
String main_input_name_;
void *lexval;
bool main_input_b_;
+
+ Sources * sources_;
/*
- Scheme hash tables with (oct name acc) values, and symbol keys
+ Scheme hash tables with (oct name acc) values, and symbol keys
*/
Protected_scm chordmodifier_tab_;
Protected_scm pitchname_tab_stack_;
+
Keyword_table * keytable_;
int errorlevel_;
- My_lily_lexer ();
+ My_lily_lexer (Sources*);
~My_lily_lexer ();
int yylex ();
#ifndef MY_LILY_PARSER_HH
#define MY_LILY_PARSER_HH
+#include "protected-scm.hh"
#include "lily-proto.hh"
#include "string.hh"
#include "parray.hh"
#include "lily-proto.hh"
-#include "lily-proto.hh"
#include "duration.hh"
#include "pitch.hh"
#include "string.hh"
class My_lily_parser
{
public:
- My_lily_parser (Input_file_results * sources);
+ My_lily_parser (Sources * sources);
~My_lily_parser ();
void do_init_file ();
Duration default_duration_;
String output_basename_;
- Scheme_hash_table *default_header_;
+ Protected_scm header_;
+ int score_count_;
+ int book_count_;
+ Sources *sources_;
+
int fatal_error_;
- Input_file_results * input_file_;
int error_level_;
My_lily_lexer * lexer_;
/*
- scores.cc -- implement some globals
+ input-file-results.cc -- implement some globals
source file of the GNU LilyPond music typesetter
val = scm_c_eval_string ("line-location");
scm_module_define (global_lily_module, ly_symbol2scm ("point-and-click"), val);
-
- store_locations_global_b =is_procedure (val);
+ store_locations_global_b = is_procedure (val);
return SCM_UNSPECIFIED;
}
fprintf (f, "%s\n", out.to_str0 ());
}
-
-void
-Input_file_results::do_deps (String output)
-{
- if (dependency_global_b)
- {
- Path p = split_path (output);
- p.ext = "dep";
- write_dependency_file (p.to_string (),
- target_strings_,
- inclusion_names_);
- }
-}
-
-Input_file_results::~Input_file_results ()
-{
- inclusion_names_.clear ();
- if (header_)
- header_ = SCM_EOL;
-
- global_input_file = 0;
-
- ly_clear_anonymous_modules ();
-}
-
-Input_file_results* global_input_file;
-
-Input_file_results::Input_file_results (String init,
- String in_file, String out_file)
-{
- header_ = ly_make_anonymous_module ();
- global_input_file = this;
- book_count_ = 0;
- score_count_ = 0;
- sources_.set_path (&global_path);
-
- progress_indication (_f ("Now processing `%s'", in_file.to_str0 ()));
- progress_indication ("\n");
-
- My_lily_parser parser (this);
- parser.parse_file (init, in_file, out_file);
-
- if (parser.error_level_)
- {
- exit_status_global = 1;
- failed_files.push (in_file);
- }
-
- do_deps (out_file);
-}
-
/* Distill full input file name from command argument. PATH describes
file name with added default extension, ".ly" if none. "-" is
STDIN. */
return p;
}
-/* ugr. */
-void
-do_one_file (char const *file)
+LY_DEFINE(ly_parse_file, "ly:parse-file",
+ 1,0,0,
+ (SCM name),
+ "Parse a single @code{.ly} file."
+ )
{
+ SCM_ASSERT_TYPE (is_string (name), name, SCM_ARG1, __FUNCTION__, "string");
+ char const *file = SCM_STRING_CHARS(name);
+
String infile (file);
Path inpath = distill_inname (infile);
{
warning (_f ("can't find file: `%s'", init));
warning (_f ("(search path: `%s')", global_path.to_string ().to_str0 ()));
- return;
+ return SCM_UNSPECIFIED;
}
if ((in_file != "-") && global_path.find (in_file).is_empty ())
{
warning (_f ("can't find file: `%s'", in_file));
- return;
+ return SCM_UNSPECIFIED;
}
+
+ Sources sources;
+ sources.set_path (&global_path);
+
+ progress_indication (_f ("Now processing `%s'", in_file.to_str0 ()));
+ progress_indication ("\n");
- Input_file_results inp_file (init, in_file, out_file);
+ My_lily_parser parser (&sources);
+ parser.parse_file (init, in_file, out_file);
+
+ if (parser.error_level_)
+ {
+ exit_status_global = 1;
+ failed_files.push (in_file);
+ }
+
+#if 0
+ // fixme dependencies
+ if (dependency_global_b)
+ {
+ Path p = split_path (output);
+ p.ext = "dep";
+ write_dependency_file (p.to_string (),
+ target_strings_,
+ inclusion_names_);
+ }
+#endif
+
+ return SCM_UNSPECIFIED;
}
String s (YYText ()+1);
s = s.left_string (s.index_last ('"'));
- new_input (s, &global_input_file->sources_);
+ new_input (s, sources_);
yy_pop_state ();
}
<incl>\\{BLACK}*;?{WHITE} { /* got the include identifier */
SCM sid = lookup_identifier (s);
if (is_string (sid)) {
- new_input (ly_scm2string (sid), &global_input_file->sources_);
+ new_input (ly_scm2string (sid), sources_);
yy_pop_state ();
} else {
String msg (_f ("wrong or undefined identifier: `%s'", s ));
scm_primitive_load_path (scm_makfrom0str ("lily.scm"));
}
-
SCM global_lily_module;
void
-ly_init_guile ()
+ly_c_init_guile ()
{
global_lily_module = scm_c_define_module ("lily", ly_init_ly_module, 0);
scm_c_use_module ("lily");
scm_c_use_module ("lily");
}
-Protected_scm anon_modules;
-
SCM
ly_make_anonymous_module ()
{
String s = "*anonymous-ly-" + to_string (module_count++) + "*";
SCM mod = scm_c_define_module (s.to_str0(), ly_init_anonymous_module, 0);
- anon_modules = scm_cons (mod, anon_modules);
return mod;
}
-void
-ly_clear_anonymous_modules ()
-{
- SCM s = anon_modules;
- anon_modules = SCM_EOL;
-
- for (; is_pair (s) ; s = ly_cdr (s))
- {
- SCM tab= scm_c_make_hash_table (2);
- /* UGH. */
- SCM_STRUCT_DATA (ly_car (s))[scm_module_index_obarray]
- = (long unsigned int) tab;
- }
-}
-
#define FUNC_NAME __FUNCTION__
static SCM
/* Verbose progress indication? */
bool verbose_global_b = false;
-/* Scheme code to execute before parsing, after .scm init */
+/* Scheme code to execute before parsing, after .scm init
+ This is where -e arguments are appended to.
+*/
String init_scheme_code_string = "(begin #t ";
+
/*
* Miscellaneous global stuff.
*/
int exit_status_global;
File_path global_path;
-/* Number of current score output block. If there's more than one
- score block, this counter will be added to the output filename. */
-int score_count_global;
-
/*
* File globals.
prepend_load_path (String (prefix_directory[i]) + "/scm");
}
+
if (verbose_global_b)
dir_info (stderr);
- ly_init_guile ();
+ ly_c_init_guile ();
call_constructors ();
progress_indication ("\n");
scm_gc ();
scm_call_0 (ly_scheme_function ("dump-gc-protects"));
#endif
- do_one_file (arg);
+ ly_parse_file (scm_makfrom0str (arg));
first = false;
}
delete option_parser;
*/
#include "scm-hash.hh"
-
-#include "warn.hh"
-#include "music-output-def.hh"
-#include "global-context.hh"
#include "context-def.hh"
-#include "main.hh"
#include "file-path.hh"
+#include "global-context.hh"
#include "lily-guile.hh"
#include "ly-module.hh"
+#include "main.hh"
+#include "music-output-def.hh"
+#include "paper-def.hh"
+#include "warn.hh"
#include "ly-smobs.icc"
return s;
}
+LY_DEFINE(ly_output_description, "ly:output-description",
+ 1,0,0,
+ (SCM output_def),
+ "Return the description of translators in @var{output-def}.")
+{
+ Music_output_def *id = unsmob_music_output_def (output_def);
+ SCM al = id->translator_tab_->to_alist ();
+ SCM l = SCM_EOL;
+ for (SCM s = al ; is_pair (s); s = ly_cdr (s))
+ {
+ Context_def * td = unsmob_context_def (ly_cdar (s));
+ l = scm_cons (scm_cons (ly_caar (s), td->to_alist ()), l);
+ }
+ return l;
+}
+
+
};
-My_lily_lexer::My_lily_lexer ()
+My_lily_lexer::My_lily_lexer (Sources *srcs)
{
keytable_ = new Keyword_table (the_key_tab);
encoding_ = SCM_EOL;
chordmodifier_tab_ = scm_make_vector (scm_int2num (1), SCM_EOL);
pitchname_tab_stack_ = SCM_EOL;
-
+ sources_ = srcs;
scopes_ = SCM_EOL;
add_scope (ly_make_anonymous_module ());
My_lily_lexer::start_main_input ()
{
// yy_flex_debug = 1;
-
- new_input (main_input_name_, &global_input_file->sources_);
+ new_input (main_input_name_, sources_);
/* Do not allow \include in --safe-mode */
allow_includes_b_ = allow_includes_b_ && ! safe_global_b;
#include "main.hh"
#include "parser.hh"
#include "input-file-results.hh"
+#include "ly-module.hh"
#include "scm-hash.hh"
-My_lily_parser::My_lily_parser (Input_file_results * source)
+My_lily_parser::My_lily_parser (Sources * sources)
{
- input_file_ = source;
+ book_count_ = 0;
+ score_count_ = 0;
lexer_ = 0;
+ sources_ = sources;
default_duration_ = Duration (2,0);
error_level_ = 0;
last_beam_start_ = SCM_EOL;
- default_header_ =0;
+ header_ = ly_make_anonymous_module ();
}
My_lily_parser::~My_lily_parser ()
{
delete lexer_;
- if (default_header_)
- scm_gc_unprotect_object (default_header_->self_scm ());
}
/* Process one .ly file, or book. */
void
My_lily_parser::parse_file (String init, String in_file, String out_file)
{
- lexer_ = new My_lily_lexer;
+ lexer_ = new My_lily_lexer (sources_);
output_basename_ = out_file;
lexer_->main_input_name_ = in_file;
progress_indication ("\n");
set_yydebug (0);
- lexer_->new_input (init, &input_file_->sources_);
+ lexer_->new_input (init, sources_);
/* Read .ly IN_FILE, lex, parse, write \score blocks from IN_FILE to
OUT_FILE (unless IN_FILE redefines output file name). */
error_level_ = 1;
}
- input_file_->inclusion_names_ = lexer_->filename_strings_;
+ // fixme: dependencies
+ //input_file_->inclusion_names_ = lexer_->filename_strings_;
error_level_ = error_level_ | lexer_->errorlevel_; // ugh naming.
}
/*
Parsing looks ahead , so we really want the previous location of the
lexer, not lexer_->here_input ().
- */
+ */
/*
Actually, that gets very icky when there are white space, because
the line-numbers are all wrong. Let's try the character before
the current token. That gets the right result for
note/duration stuff, but doesn't mess up for errors in the 1st token of the line.
- */
+ */
Input hi (lexer_->here_input ());
char const * bla = hi.defined_str0_;
return Input (hi.source_file_, bla);
}
-
-#include "paper-def.hh"
-#include "context-def.hh"
-
-My_lily_parser * current_parser;
-
-MAKE_SCHEME_CALLBACK (My_lily_parser,paper_description, 0);
-
-SCM
-My_lily_parser::paper_description ()
-{
- My_lily_parser * me = current_parser;
-
- Music_output_def *id = unsmob_music_output_def (me->lexer_->lookup_identifier ("$defaultpaper"));
- Paper_def *p = dynamic_cast<Paper_def*> (id->clone ());
-
- SCM al = p->translator_tab_->to_alist ();
- SCM l = SCM_EOL;
- for (SCM s = al ; is_pair (s); s = ly_cdr (s))
- {
- Context_def * td = unsmob_context_def (ly_cdar (s));
- l = scm_cons (scm_cons (ly_caar (s), td->to_alist ()), l);
- }
- return l;
-}
-
-
SCM scopes = SCM_EOL;
if (headers_[i])
scopes = scm_cons (headers_[i], scopes);
- if (global_headers_[i] && global_headers_[i] != headers_[i])
+ if (global_headers_.size ()
+ && global_headers_[i] && global_headers_[i] != headers_[i])
scopes = scm_cons (global_headers_[i], scopes);
return scopes;
}
{
progress_indication (_f ("paper output to `%s'...",
outname == "-" ? String ("<stdout>") : outname));
- global_input_file->target_strings_.push (outname);
+
+ // fixme: dependencies
+ // add_target_file (outname);
+
Paper_outputter * po = new Paper_outputter (outname);
Path p = split_path (outname);
p.ext = "";
toplevel_expression:
lilypond_header {
- THIS->input_file_->header_ = $1;
+ THIS->header_ = $1;
}
| add_quote {
}
| book_block {
Book *book = $1;
- SCM header = THIS->input_file_->header_.to_SCM ();
+ SCM header = THIS->header_;
Path outname = split_path (THIS->output_basename_);
- int *c = &THIS->input_file_->book_count_;
+ int *c = &THIS->book_count_;
if (*c)
outname.base += "-" + to_string (*c);
(*c)++;
| score_block {
Score *sc = $1;
SCM head = is_module (sc->header_) ? sc->header_
- : THIS->input_file_->header_.to_SCM ();
+ : THIS->header_.to_SCM ();
Path p = split_path (THIS->output_basename_);
- int *c = &THIS->input_file_->score_count_;
+ int *c = &THIS->score_count_;
if (*c)
p.base += "-" + to_string (*c);
#endif
}
-extern My_lily_parser *current_parser;
-
void
My_lily_parser::do_yyparse ()
{
- current_parser = this;;
yyparse ((void*)this);
}
Midi_stream midi_stream (out);
progress_indication (_f ("MIDI output to `%s'...", out));
- global_input_file->target_strings_.push (out);
+ // fixme: dependencies
+ //add_target_file (out);
output (midi_stream);
progress_indication ("\n");
Paper_score *ps = dynamic_cast<Paper_score*> (output);
paper_book->papers_.push (ps->paper_);
paper_book->scores_.push (systems);
- paper_book->global_headers_.push (global_input_file->header_);
+
+ // fixme.
+ //paper_book->global_headers_.push (global_input_file->header_);
+
paper_book->headers_.push (header);
paper_book->classic_output (ly_scm2string (outname));
scm_gc_unprotect_object (paper_book->self_scm ());
(if in-which-contexts
(let*
- ((paper-alist (My_lily_parser::paper_description))
+ ((paper-alist (ly:output-description $defaultpaper))
(context-description-alist (map cdr paper-alist))
(contexts
(apply append
(define (all-contexts-doc)
(let* (
(paper-alist
- (sort (My_lily_parser::paper_description)
+ (sort (ly:output-description $defaultpaper)
(lambda (x y) (symbol<? (car x) (car y)))))
(names (sort (map symbol->string (map car paper-alist)) string<?))
(contexts (map cdr paper-alist))
,(delay (ly:font-load "ecti12"))
)))
(#(roman italic bold) .
- (10.0 . #(,(delay (ly:font-load "ecbxti8"))
- ,(delay (ly:font-load "ecbxti10"))
- ,(delay (ly:font-load "ecbxti14"))
+ (10.0 . #(,(delay (ly:font-load "ecbi8"))
+ ,(delay (ly:font-load "ecbi10"))
+ ,(delay (ly:font-load "ecbi14"))
)))
(#(roman caps medium) .