lilypond-0.0.4
[lilypond.git] / symtable.cc
blobb4de607b8d3a54a574510a4817c6b3ea7bff3c21
1 #include "misc.hh"
2 #include "dimen.hh"
3 #include "debug.hh"
4 #include "real.hh"
5 #include "symbol.hh"
6 #include "assoc.hh"
7 #include "symtable.hh"
13 Symbol
14 Symtable::lookup(String s) const
16 if (elt_query(s))
17 return (*this)[s];
18 else {
19 Symbol unknown;
20 WARN<<"Unknown symbol " << s <<'\n';
21 return unknown;
25 Symtable*
26 Symtables::operator()(String s)
28 if (!done_reading){ // read on demand
29 *mlog << '(' << fname ;
30 read();
31 done_reading = true;
32 *mlog << ")\n";
34 return Assoc<String, Symtable*>::operator[](s);
37 void
38 Symtables::read()
40 Text_db symini(fname);
41 while (!symini.eof()) {
42 Text_record r( symini++);
43 assert (r[0] == "table");
45 String tabnam = r[1];
46 Symtable * sp = new Symtable;
47 while (!symini.eof()){
48 r = symini++;
49 if (r[0] == "end")
50 break;
52 assert(r.sz() == 6);
53 int i=0;
54 String id=r[i++];
55 String tex=r[i++];
56 svec<Real> dims;
57 for (int j=0; j < 4; j++)
58 dims.add( parse_dimen(r[i++]));
60 Symbol s(tex, Box(dims));
61 (*sp)[id] = s;
63 (*this)[tabnam] = sp;