flower-1.0.3
[lilypond.git] / tstream.cc
blobb7c88f1b0bc7a379d6c1c1be9e3bf84e512da2b3
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)
36 for (const char *cp = s; *cp; cp++) {
37 if (outputting_comment) {
38 *os << *cp;
39 if (*cp == '\n') {
40 outputting_comment=false;
43 continue;
45 switch(*cp)
47 case '%':
48 outputting_comment = true;
49 *os << *cp;
50 break;
51 case '{':
52 nest_level++;
53 *os << *cp;
54 break;
55 case '}':
56 nest_level--;
57 *os << *cp;
58 assert (nest_level >= 0);
59 /* FALL THROUGH */
61 case '\n':
62 *os << "%\n";
63 *os << String(' ', nest_level);
64 break;
65 default:
66 *os << *cp;
67 break;
70 return *this;
74 /****************************************************************/