2 paper-stream.cc -- implement Paper_stream
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #include <sys/types.h>
19 #include "paper-stream.hh"
20 #include "file-path.hh"
23 const int MAXLINELEN = 200;
27 open_file_stream (String filename, std::ios_base::openmode mode)
30 open_file_stream (String filename, int mode)
34 if ((filename == "-"))
38 Path p = split_path (filename);
39 if (!p.dir.empty_b ())
40 if (mkdir (p.dir.ch_C (), 0777) == -1 && errno != EEXIST)
41 error (_f ("can't create directory: `%s'", p.dir));
42 os = new ofstream (filename.ch_C (), mode);
45 error (_f ("can't open file: `%s'", filename));
50 close_file_stream (ostream *os)
55 warning (_ ("Error syncing file (disk full?)"));
56 exit_status_global = 1;
63 Paper_stream::Paper_stream (String filename)
65 os_ = open_file_stream (filename);
68 outputting_comment_b_=false;
71 Paper_stream::~Paper_stream ()
73 close_file_stream (os_);
75 programming_error ("Brace nesting in paper output doesn't match");
78 // print string. don't forget indent.
80 Paper_stream::operator << (String s)
82 for (char const *cp = s.ch_C (); *cp; cp++)
84 if (outputting_comment_b_)
89 outputting_comment_b_=false;
98 outputting_comment_b_ = true;
111 delete os_; // we want to see the remains.
112 assert (nest_level>=0);
115 /* don't break line if not nested; very ugly for ps */
127 if (line_len_i_ > MAXLINELEN)
136 //urg, for debugging only!!
142 Paper_stream::break_line ()
145 *os_ << to_str (' ', nest_level);
146 outputting_comment_b_ = false;