lilypond-0.0.3
[lilypond.git] / dstream.cc
blob1326b8b667c289b76d40fdc4de34eb4905bd44b5
1 #include <fstream.h>
3 #include "dstream.hh"
4 #include "string.hh"
5 #include "textdb.hh"
8 /*
9 should use Regexp library.
11 static String
12 strip_pretty(String pret)
14 String cl(pret.left(pret.pos('(')-1));
15 int l = cl.lastPos(' ');
16 cl = cl.right(cl.len() -l);
17 return cl;
20 static String
21 strip_member(String pret)
23 String cl(pret.left(pret.lastPos(':')-2));
24 return cl;
27 Dstream&
28 Dstream::identify_as(String name)
30 String mem(strip_pretty(name));
31 String cl(strip_member(mem));
33 if(!silent.elt_query(cl))
34 silent[cl] = false;
35 local_silence = silent[cl];
36 if (classname != cl && !local_silence) {
37 classname=cl;
38 *os << "[" << classname << ":]";
40 return *this;
43 void
44 Dstream::switch_output(String name,bool b)
46 silent[name] = b;
49 ///
50 Dstream &
51 Dstream::operator<<(String s)
53 if (local_silence)
54 return *this;
56 for (const char *cp = s ; *cp; cp++)
57 switch(*cp)
59 case '{':
60 case '[':
61 case '(': indentlvl += INDTAB;
62 *os << *cp;
63 break;
65 case ')':
66 case ']':
67 case '}':
68 indentlvl -= INDTAB;
69 *os << *cp ;
71 if (indentlvl<0) indentlvl = 0;
72 break;
74 case '\n':
75 *os << '\n' << String (' ', indentlvl) << flush;
76 break;
77 default:
78 *os << *cp;
79 break;
81 return *this;
84 /** only output possibility. Delegates all conversion to String class.
87 Dstream::Dstream(ostream &r, const char * cfg_nm )
89 os = &r;
90 indentlvl = 0;
92 const char * fn =cfg_nm ? cfg_nm : ".dstreamrc";
94 ifstream ifs(fn); // can't open
95 if (!ifs)
96 return;
98 cerr << "(" << fn;
99 Text_db cfg(fn);
100 while (! cfg.eof()){
101 Text_record r( cfg++);
102 assert(r.sz() == 2);
103 silent[r[0]] = r[1].to_bool();
105 cerr <<")";