]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/paper-stream.cc
release: 1.3.117
[lilypond.git] / lily / paper-stream.cc
index 401b120842f365814c7283ef9b143a1c30e45878..86f2ee5de8adef3145a3179a3faf91f3b5b73c02 100644 (file)
@@ -3,7 +3,7 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c)  1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c)  1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 */
 
 #include <fstream.h>
 
 const int MAXLINELEN = 200;
 
-Paper_stream::Paper_stream (String filename)
+ostream *
+open_file_stream (String filename)
 {
+  ostream *os;
   if (filename.length_i () && (filename != "-"))
     os = new ofstream (filename.ch_C ());
   else
-    //    os = new ostream (cout.ostreambuf ());
     os = new ostream (cout._strbuf);
   if (!*os)
-    error (_f ("can't open file: `%s\'", filename));
-  nest_level = 0;
-  line_len_i_ = 0;
-  outputting_comment=false;
+    error (_f ("can't open file: `%s'", filename));
+  return os;
 }
 
-Paper_stream::~Paper_stream ()
+void
+close_file_stream (ostream *os)
 {
   *os << flush;
   if (!*os)
     {
-      warning (_ ("error syncing file (disk full?)"));
+      warning (_ ("Error syncing file (disk full?)"));
       exit_status_i_ = 1;
     }
   delete os;
+}  
+
+Paper_stream::Paper_stream (String filename)
+{
+  os_ = open_file_stream (filename);
+  nest_level = 0;
+  line_len_i_ = 0;
+  outputting_comment_b_=false;
+}
+
+Paper_stream::~Paper_stream ()
+{
+  close_file_stream (os_);
   assert (nest_level == 0);
 }
 
 // print string. don't forget indent.
 Paper_stream&
-Paper_stream::operator << (Scalar s)
+Paper_stream::operator << (String s)
 {
   for (char const *cp = s.ch_C (); *cp; cp++)
     {
-      if (outputting_comment)
+      if (outputting_comment_b_)
        {
-         *os << *cp;
+         *os_ << *cp;
          if (*cp == '\n')
            {
-             outputting_comment=false;
-
+             outputting_comment_b_=false;
+             line_len_i_ =0;
            }
          continue;
        }
@@ -60,20 +73,20 @@ Paper_stream::operator << (Scalar s)
       switch (*cp)
        {
        case '%':
-         outputting_comment = true;
-         *os << *cp;
+         outputting_comment_b_ = true;
+         *os_ << *cp;
          break;
        case '{':
          nest_level++;
-         *os << *cp;
+         *os_ << *cp;
          break;
        case '}':
          nest_level--;
-         *os << *cp;
+         *os_ << *cp;
 
          if (nest_level < 0)
            {
-             delete os       // we want to see the remains.
+             delete os_;       // we want to see the remains.
              assert (nest_level>=0);
            }
 
@@ -81,33 +94,34 @@ Paper_stream::operator << (Scalar s)
          if (nest_level == 0)
            break;
 
-         *os << '%';
+         *os_ << '%';
          break_line ();
          break;
        case '\n':
          break_line ();
          break;
        case ' ':
-         *os <<  ' ';
+         *os_ <<  ' ';
          if (line_len_i_ > MAXLINELEN)
            break_line ();
 
          break;
        default:
-         *os << *cp;
+         *os_ << *cp;
          break;
        }
     }
   //urg, for debugging only!!
-  *os << flush;
+  *os_ << flush;
   return *this;
 }
 
 void
 Paper_stream::break_line ()
 {
-  *os << '\n';
-  *os << to_str (' ', nest_level);
+  *os_ << '\n';
+  *os_ << to_str (' ', nest_level);
+  outputting_comment_b_ = false;
   line_len_i_ = 0;
 }