2 paper-stream.cc -- implement Paper_stream
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
11 #include <sys/types.h>
15 #include "paper-stream.hh"
16 #include "file-path.hh"
19 const int MAXLINELEN = 200;
22 open_file_stream (String filename)
25 if (!filename.empty_b () && (filename != "-"))
27 Path p = split_path (filename);
28 if (!p.dir.empty_b ())
29 if (mkdir (p.dir.ch_C (), 0777) == -1 && errno != EEXIST)
30 error (_f ("can't create directory: `%s'", p.dir));
31 os = new ofstream (filename.ch_C ());
34 os = new ostream (cout._strbuf);
36 error (_f ("can't open file: `%s'", filename));
41 close_file_stream (ostream *os)
46 warning (_ ("Error syncing file (disk full?)"));
52 Paper_stream::Paper_stream (String filename)
54 os_ = open_file_stream (filename);
57 outputting_comment_b_=false;
60 Paper_stream::~Paper_stream ()
62 close_file_stream (os_);
63 assert (nest_level == 0);
66 // print string. don't forget indent.
68 Paper_stream::operator << (String s)
70 for (char const *cp = s.ch_C (); *cp; cp++)
72 if (outputting_comment_b_)
77 outputting_comment_b_=false;
86 outputting_comment_b_ = true;
99 delete os_; // we want to see the remains.
100 assert (nest_level>=0);
103 /* don't break line if not nested; very ugly for ps */
115 if (line_len_i_ > MAXLINELEN)
124 //urg, for debugging only!!
130 Paper_stream::break_line ()
133 *os_ << to_str (' ', nest_level);
134 outputting_comment_b_ = false;