(parse_symbol_list): Bugfix.
[lilypond/patrick.git] / lily / object-key-undumper.cc
blobb9baee4564e1345317b9ed52fa46fe29fe028481
1 /*
2 object-key-undumper.cc -- implement Object_key_undumper
4 source file of the GNU LilyPond music typesetter
6 (c) 2004--2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
9 #include "object-key-undumper.hh"
11 #include "ly-smobs.icc"
13 IMPLEMENT_SMOBS (Object_key_undumper);
14 IMPLEMENT_DEFAULT_EQUAL_P (Object_key_undumper);
16 SCM
17 Object_key_undumper::mark_smob (SCM smob)
19 Object_key_undumper *undumper = (Object_key_undumper *) SCM_CELL_WORD_1 (smob);
20 for (Int_to_key_map::const_iterator i (undumper->keys_.begin ());
21 i != undumper->keys_.end (); i++)
23 scm_gc_mark ((*i).second->self_scm ());
26 return SCM_BOOL_F;
29 int
30 Object_key_undumper::print_smob (SCM s, SCM port, scm_print_state*)
32 (void) s;
33 scm_puts ("#<Object_key_undumper>", port);
34 return 1;
37 Object_key_undumper::Object_key_undumper ()
39 smobify_self ();
42 void
43 Object_key_undumper::parse_contents (SCM contents)
45 for (SCM s = contents; scm_is_pair (s); s = scm_cdr (s))
47 SCM entry = scm_car (s);
48 if (scm_car (entry) != ly_symbol2scm ("define-key"))
49 continue;
51 int number = scm_to_int (scm_cadr (entry));
52 SCM skey = scm_caddr (entry);
54 SCM new_key = SCM_EOL;
55 SCM *tail = &new_key;
56 for (SCM t = skey; scm_is_pair (t); t = scm_cdr (t))
58 SCM item = scm_car (t);
59 if (scm_is_pair (item)
60 && scm_car (item) == ly_symbol2scm ("key"))
62 int index = scm_to_int (scm_cadr (item));
63 Object_key const *key = get_key (index);
64 *tail = scm_cons (key->self_scm (), SCM_EOL);
66 else
67 *tail = scm_cons (item, SCM_EOL);
68 tail = SCM_CDRLOC (*tail);
71 Object_key *k = Object_key::undump (new_key);
72 keys_[number] = k;
73 k->unprotect ();
77 Object_key const *
78 Object_key_undumper::get_key (int idx)
80 Int_to_key_map::const_iterator i (keys_.find (idx));
81 assert (i != keys_.end ());
83 return (*i).second;
86 Object_key_undumper::~Object_key_undumper ()