]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/tex-stream.cc
release: 1.0.1
[lilypond.git] / lily / tex-stream.cc
index 5e2e959181c674aa1d29c0427ba55f45bd14df4e..9866c231ad07af68c163e4a13decf0885550b2f2 100644 (file)
@@ -1,9 +1,10 @@
 /*
   tex-stream.cc -- implement Tex_stream
 
-  source file of the LilyPond music typesetter
+  source file of the GNU LilyPond music typesetter
+
+  (c)  1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 
-  (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
 */
 
 #include <fstream.h>
 #include "tex-stream.hh"
 #include "debug.hh"
 
-Tex_stream::Tex_stream(String filename) 
+const int MAXLINELEN = 200;
+
+Tex_stream::Tex_stream (String filename)
 {
-    os = new ofstream(filename);
-    if (!*os)
-       error("can't open `" + filename+"\'");
-    nest_level = 0;
-    outputting_comment=false;
-    header();
+  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;
+  header();
 }
 void
 Tex_stream::header()
 {
-    *os << "% Creator: " << get_version_str();
-    *os << "% Automatically generated, at ";
-    time_t t(time(0));
-    *os << ctime(&t)<<"\n";
+  *os << _ ("% Creator: ");
+  if (no_timestamps_global_b)
+    *os << "GNU LilyPond\n";
+  else
+    *os << get_version_str() << '\n';
+  *os << _ ("% Automatically generated");
+  if (no_timestamps_global_b)
+    *os << ".\n";
+  else
+    {
+      *os << _ (", at ");
+      time_t t (time (0));
+      *os << ctime (&t) << "%\n";
+    }
 }
+
 Tex_stream::~Tex_stream()
 {
-    delete os;
-    assert(nest_level == 0);
+  *os << flush;
+  if (!*os)
+    {
+      warning(_ ("error syncing file (disk full?)"));
+      exit_status_i_ = 1;
+    }
+  delete os;
+  assert (nest_level == 0);
 }
 
 // print string. don't forget indent.
-Tex_stream &
-Tex_stream::operator<<(String s)
+Tex_stream&
+Tex_stream::operator << (Scalar s)
 {
-    
-    for (char const *cp = s; *cp; cp++) {
-       if (outputting_comment) {
+  for (char const *cp = s.ch_C (); *cp; cp++)
+    {
+       if (outputting_comment)
+         {
            *os << *cp;
-           if (*cp == '\n') {
+           if (*cp == '\n')
+             {
                outputting_comment=false;
 
-           }
+             }
            continue;
-       }
-       switch(*cp) 
+         }
+       line_len_i_ ++;
+       switch (*cp)
            {
            case '%':
                outputting_comment = true;
@@ -59,29 +87,41 @@ Tex_stream::operator<<(String s)
                break;
            case '{':
                nest_level++;
-               *os << *cp;             
+               *os << *cp;
                break;
            case '}':
-               nest_level--;           
+               nest_level--;
                *os << *cp;
-               
-               if (nest_level < 0) {
+
+               if (nest_level < 0)
+                 {
                    delete os;  // we want to see the remains.
-                   assert(nest_level>=0);
-               }
+                   assert (nest_level>=0);
+                 }
                /* FALLTHROUGH */
-               
+
            case '\n':
-               *os << "%\n";
-               *os << String(' ', nest_level);
-               break;        
+               break_line();
+               break;
+           case ' ':
+               *os <<  ' ';
+               if (line_len_i_ > MAXLINELEN)
+                  break_line();
+
+               break;
            default:
                *os << *cp;
                break;
-           }
+             }
     }
-    return *this;
+  return *this;
 }
 
+void
+Tex_stream::break_line()
+{
+  *os << "%\n";
+  *os << to_str (' ', nest_level);
+  line_len_i_ = 0;
+}
 
-/* *************************************************************** */