lilypond-0.0.3
[lilypond.git] / tstream.cc
blobc47fca6da6da3b2f52be6da849d012cf7c01fb8d
1 #include <fstream.h>
2 #include <time.h>
3 #include "tex.hh"
4 #include "misc.hh"
5 #include "tstream.hh"
6 #include "debug.hh"
8 Tex_stream::Tex_stream(String filename)
11 os = new ofstream(filename);
12 if (!*os)
13 error("can't open " + filename);
14 nest_level = 0;
15 outputting_comment=false;
16 header();
18 void
19 Tex_stream::header()
21 *os << "% Creator: " << get_version() << "\n";
22 *os << "% Automatically generated, at ";
23 time_t t(time(0));
24 *os << ctime(&t)<<"\n";
25 //*os << "% from input file ..\n";
27 Tex_stream::~Tex_stream()
29 assert(nest_level == 0);
30 delete os;
33 // print string. don't forget indent.
34 Tex_stream &
35 Tex_stream::operator<<(String s)
37 for (const char *cp = s; *cp; cp++) {
38 if (outputting_comment) {
39 *os << *cp;
40 if (*cp == '\n') {
41 outputting_comment=false;
44 continue;
46 switch(*cp)
48 case '%':
49 outputting_comment = true;
50 *os << *cp;
51 break;
52 case '{':
53 nest_level++;
54 *os << *cp;
55 break;
56 case '}':
57 nest_level--;
58 *os << *cp;
59 assert (nest_level >= 0);
60 /* FALL THROUGH */
62 case '\n':
63 *os << "%\n";
64 *os << String(' ', nest_level);
65 break;
66 default:
67 *os << *cp;
68 break;
71 return *this;
75 /****************************************************************/