]> git.donarmstrong.com Git - lilypond.git/blobdiff - flower/data-file.cc
release: 1.5.9
[lilypond.git] / flower / data-file.cc
index 0dad79c91ff91cd57184b2b227e8589b281bfad5..9f4c16b115fb6dea2693a352955b9a8751f9ba8b 100644 (file)
-#include <fstream.h>
+/*   
+  data-file.cc --  implement Data_file 
+  
+  source file of the Flower Library
+  
+  (c) '95, '96, '97 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+
+  DEPRECATED
+  
+  */
 #include <ctype.h>
+#include <stdlib.h>
 
+#include "international.hh"
 #include "data-file.hh"
 
-void 
-Data_file::gobble_white()
+void
+Data_file::gobble_white ()
 {
-    char c;
-    
-    while ((c=data_get()) == ' ' ||c == '\t')
-       if (eof()) 
-           break;
+  char c;
+
+  while ((c=data_get ()) == ' ' ||c == '\t')
+    if (eof_b ())
+      return;
 
-    data_unget(c);
+  data_unget (c);
 }
 
 String
-Data_file::get_word() 
+Data_file::get_word ()
 {// should handle escape seq's
-    String s;
+  String s;
 
-    while (1) 
+  while (1)
+    {
+      char     c  = data_get ();
+      
+      if (eof_b ())
+       break;
+
+      if (isspace (c))
        {
-       char    c  = data_get();
-       
-       if (isspace(c) || eof()) 
-           {
-           data_unget(c);
-           break;
-           }
-       
-       
-       if (c == '\"')
-           {
-           rawmode= true;
-
-           while ((c  = data_get()) != '\"')
-               if (eof())
-                   error("EOF in a string");           
-               else
-                   s += c;
-           
-
-           rawmode= false;
-           }       
-       else
-           s += c;             
+         data_unget (c);
+         break;
+       }
+
+
+      if (c == '\"')
+       {
+         rawmode= true;
+
+         while ((c  = data_get ()) != '\"')
+           if (eof_b ())
+             error (_ ("EOF in a string"));
+           else
+             s += to_str (c);
+
+
+         rawmode= false;
        }
-    
-    return s;        
+      else
+       s += to_str (c);
+    }
+
+  return s;
 }
 
-/**  get a char 
-   Only class member who uses text_file::get
-   */
 char
-Data_file::data_get() {
-    char c =  get(); 
-    if (!rawmode && c == '#') // gobble comment
-       {       
-       while ((c = get()) != '\n' && !eof()) 
-           ;
-           return '\n';
-       }    
-
-    return c;
+Data_file::data_get ()
+{
+  char c =  get ();
+  if (!rawmode && c == '#') // gobble comment
+    {
+      while (!eof_b () && (c = get ()) != '\n')
+       ;
+      return '\n';
+    }
+
+  return c;
 }
 
-/// read line, gobble '\n'    
-String Data_file::get_line()     
+String
+Data_file::get_line ()
 {
-    char c; 
-    String s;
+  char c;
+  String s;
 
-    while ((c  = data_get()) != '\n' && !eof())
-       s += c;
-    return s;  
+  while (!eof_b () && (c  = data_get ()) != '\n')
+    s += to_str (c);
+  return s;
 }
 
-/// gobble stuff before first entry on a line.    
 void
-Data_file::gobble_leading_white() 
+Data_file::gobble_leading_white ()
 {
-    // eat blank lines.
-    while (!eof()) {
-       char c = data_get();                
-       if (!isspace(c)) {
-           data_unget(c);
-           break;
+  // eat blank lines.
+  while (!eof_b ())
+    {
+      char c = data_get ();
+      if (!isspace (c))
+       {
+         data_unget (c);
+         break;
        }
     }
 }
 
+Data_file::Data_file (String s)
+  : Text_stream (s) 
+{
+  //*mlog << " (" << s << flush;       
+  rawmode=  false;     
+}
+
+void
+Data_file::warning (String s)
+{
+  message (_ ("warning: ") + s);
+}
+
+void
+Data_file::error (String s)
+{
+  message (s);
+  exit (1);    
+}
 
+String
+Data_file::gulp ()
+{
+  String s;
+
+  while (!eof_b ())
+    {
+      s += to_str (data_get ());
+    }
+  return s;
+}
+  
+
+Data_file::~Data_file ()
+{
+}