]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/paper-stream.cc
release: 1.5.7
[lilypond.git] / lily / paper-stream.cc
index b15e2628928f1673fbeb91134448897dfac6ba1a..d2bbeb3f9ca676d2fc2bf2ab3f40af21c09d162e 100644 (file)
@@ -3,14 +3,18 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c)  1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c)  1997--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 */
 
 #include <errno.h>
-#include <sys/stat.h>
 #include <sys/types.h>
 #include <fstream.h>
 
+#include "config.h"
+#if HAVE_SYS_STAT_H 
+#include <sys/stat.h>
+#endif
+
 #include "main.hh"
 #include "paper-stream.hh"
 #include "file-path.hh"
 
 const int MAXLINELEN = 200;
 
+#if __GNUC__ > 2
 ostream *
-open_file_stream (String filename)
+open_file_stream (String filename, std::ios_base::openmode mode)
+#else
+ostream *
+open_file_stream (String filename, int mode)
+#endif
 {
   ostream *os;
-  if (!filename.empty_b () && (filename != "-"))
+  if ((filename == "-"))
+    os = &cout;
+  else
     {
       Path p = split_path (filename);
       if (!p.dir.empty_b ())
        if (mkdir (p.dir.ch_C (), 0777) == -1 && errno != EEXIST)
          error (_f ("can't create directory: `%s'", p.dir));
-      os = new ofstream (filename.ch_C ());
+      os = new ofstream (filename.ch_C (), mode);
     }
-  else
-    os = new ostream (cout._strbuf);
   if (!*os)
     error (_f ("can't open file: `%s'", filename));
   return os;
@@ -44,9 +53,11 @@ close_file_stream (ostream *os)
   if (!*os)
     {
       warning (_ ("Error syncing file (disk full?)"));
-      exit_status_i_ = 1;
+      exit_status_global = 1;
     }
-  delete os;
+  if (os != &cout)
+    delete os;
+  os = 0;
 }  
 
 Paper_stream::Paper_stream (String filename)
@@ -60,7 +71,8 @@ Paper_stream::Paper_stream (String filename)
 Paper_stream::~Paper_stream ()
 {
   close_file_stream (os_);
-  assert (nest_level == 0);
+  if (nest_level != 0)
+    programming_error ("Brace nesting in paper output doesn't match");
 }
 
 // print string. don't forget indent.