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;
26 open_file_stream (String filename
, int mode
)
29 if ((filename
== "-"))
30 os
= new ostream (cout
._strbuf
);
33 Path p
= split_path (filename
);
34 if (!p
.dir
.empty_b ())
35 if (mkdir (p
.dir
.ch_C (), 0777) == -1 && errno
!= EEXIST
)
36 error (_f ("can't create directory: `%s'", p
.dir
));
37 os
= new ofstream (filename
.ch_C (), mode
);
40 error (_f ("can't open file: `%s'", filename
));
45 close_file_stream (ostream
*os
)
50 warning (_ ("Error syncing file (disk full?)"));
51 exit_status_global
= 1;
57 Paper_stream::Paper_stream (String filename
)
59 os_
= open_file_stream (filename
);
62 outputting_comment_b_
=false;
65 Paper_stream::~Paper_stream ()
67 close_file_stream (os_
);
68 assert (nest_level
== 0);
71 // print string. don't forget indent.
73 Paper_stream::operator << (String s
)
75 for (char const *cp
= s
.ch_C (); *cp
; cp
++)
77 if (outputting_comment_b_
)
82 outputting_comment_b_
=false;
91 outputting_comment_b_
= true;
104 delete os_
; // we want to see the remains.
105 assert (nest_level
>=0);
108 /* don't break line if not nested; very ugly for ps */
120 if (line_len_i_
> MAXLINELEN
)
129 //urg, for debugging only!!
135 Paper_stream::break_line ()
138 *os_
<< to_str (' ', nest_level
);
139 outputting_comment_b_
= false;