lilypond-0.1.37
[lilypond.git] / src / tex-stream.cc
blob5722599b311ea6c90559fc4c9efa6965098b0fce
1 /*
2 tex-stream.cc -- implement Tex_stream
4 source file of the LilyPond music typesetter
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
9 #include <fstream.h>
10 #include <time.h>
12 #include "tex.hh"
13 #include "main.hh"
14 #include "tex-stream.hh"
15 #include "debug.hh"
17 Tex_stream::Tex_stream(String filename)
19 os = new ofstream(filename);
20 if (!*os)
21 error("can't open `" + filename+"\'");
22 nest_level = 0;
23 outputting_comment=false;
24 header();
26 void
27 Tex_stream::header()
29 *os << "% Creator: " << get_version();
30 *os << "% Automatically generated, at ";
31 time_t t(time(0));
32 *os << ctime(&t);
34 Tex_stream::~Tex_stream()
36 delete os;
37 assert(nest_level == 0);
40 // print string. don't forget indent.
41 Tex_stream &
42 Tex_stream::operator<<(String s)
45 for (const char *cp = s; *cp; cp++) {
46 if (outputting_comment) {
47 *os << *cp;
48 if (*cp == '\n') {
49 outputting_comment=false;
52 continue;
54 switch(*cp)
56 case '%':
57 outputting_comment = true;
58 *os << *cp;
59 break;
60 case '{':
61 nest_level++;
62 *os << *cp;
63 break;
64 case '}':
65 nest_level--;
66 *os << *cp;
68 if (nest_level < 0) {
69 delete os; // we want to see the remains.
70 assert(nest_level>=0);
72 /* FALLTHROUGH */
74 case '\n':
75 *os << "%\n";
76 *os << String(' ', nest_level);
77 break;
78 default:
79 *os << *cp;
80 break;
83 return *this;
87 /* *************************************************************** */