flower-1.0.27
[lilypond.git] / src / tstream.cc
blobd56c58a3c404e23cc07d2f228286a95a50d3b08d
1 #include <fstream.h>
2 #include <time.h>
3 #include "tex.hh"
4 #include "main.hh"
5 #include "tstream.hh"
6 #include "debug.hh"
8 Tex_stream::Tex_stream(String filename)
10 os = new ofstream(filename);
11 if (!*os)
12 error("can't open `" + filename+"\'");
13 nest_level = 0;
14 outputting_comment=false;
15 header();
17 void
18 Tex_stream::header()
20 *os << "% Creator: " << get_version();
21 *os << "% Automatically generated, at ";
22 time_t t(time(0));
23 *os << ctime(&t);
24 //*os << "% from input file ..\n";
26 Tex_stream::~Tex_stream()
28 delete os;
29 assert(nest_level == 0);
32 // print string. don't forget indent.
33 Tex_stream &
34 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 /* FALTHROUGH */
62 case '\n':
63 *os << "%\n";
64 *os << String(' ', nest_level);
65 break;
66 default:
67 *os << *cp;
68 break;
71 return *this;
75 /* *************************************************************** */