lilypond-0.0.1
[lilypond.git] / tstream.cc
blob78c9a72852021c372456eab527ac6ca79c7c7e81
1 #include <fstream.h>
2 #include "tex.hh"
3 #include "tstream.hh"
4 #include "debug.hh"
6 Tex_stream::Tex_stream(String filename)
9 os = new ofstream(filename);
10 if (!*os)
11 error("can't open " + filename);
12 nest_level = 0;
13 outputting_comment=false;
16 Tex_stream::~Tex_stream()
18 assert(nest_level == 0);
19 delete os;
22 // print string. don't forget indent.
23 Tex_stream &
24 Tex_stream::operator<<(String s)
26 for (const char *cp = s; *cp; cp++) {
27 if (outputting_comment) {
28 *os << *cp;
29 if (*cp == '\n') {
30 outputting_comment=false;
33 continue;
35 switch(*cp)
37 case '%':
38 outputting_comment = true;
39 *os << *cp;
40 break;
41 case '{':
42 nest_level++;
43 *os << *cp;
44 break;
45 case '}':
46 nest_level--;
47 *os << *cp;
48 assert (nest_level >= 0);
49 /* FALL THROUGH */
51 case '\n':
52 *os << "%\n";
53 *os << String(' ', nest_level);
54 break;
55 default:
56 *os << *cp;
57 break;
60 return *this;
64 /****************************************************************/