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_);
74 assert (nest_level == 0);
77 // print string. don't forget indent.
79 Paper_stream::operator << (String s)
81 for (char const *cp = s.ch_C (); *cp; cp++)
83 if (outputting_comment_b_)
88 outputting_comment_b_=false;
97 outputting_comment_b_ = true;
110 delete os_; // we want to see the remains.
111 assert (nest_level>=0);
114 /* don't break line if not nested; very ugly for ps */
126 if (line_len_i_ > MAXLINELEN)
135 //urg, for debugging only!!
141 Paper_stream::break_line ()
144 *os_ << to_str (' ', nest_level);
145 outputting_comment_b_ = false;