]> git.donarmstrong.com Git - lilypond.git/blobdiff - flower/include/text-stream.hh
patch::: 1.3.144.jcn6
[lilypond.git] / flower / include / text-stream.hh
index 437f8698c7f8262cd00e29cf46c99e4747b8faff..6d7e5530a807d528b06302f93df61d482f6dcad4 100644 (file)
@@ -5,12 +5,12 @@
 #include <stdio.h>
 #include <ctype.h>
 #include "string.hh"
-#include "varray.hh"
+#include "array.hh"
 
 /**
   line counting input stream. 
   a stream for textfiles. linecounting. Thin interface getchar and
-  ungetchar.  (ungetc is unlimited) 
+  ungetchar. (ungetc is unlimited) 
   
   should protect get and unget against improper use
 */
 
 class Text_stream
 {
-    int line_no;
+  int line_no;
 
-    // could just have used streams. 
-    FILE *f;  
-    Array<char> pushback;
-    String name;
+  // could just have used streams. 
+  FILE *f;  
+  Array<char> pushback;
+  String name;
     
- public:
-    Text_stream(String fn);
-    String get_name() { return name; }
-    bool eof() {
-       return feof(f);
-    }
-    bool eol() {
-       return (peek() == '\n');
-    }
-    char peek() {
-       char c = get();
-       unget(c);
-       return c;
-    }
-    int line(){
-       return line_no;
-    }
-
-    char    get() {
-       char c;
+public:
+  Text_stream (String fn);
+  String get_name () { return name; }
+  bool eof_b ();
+  char get () {
+    char c;
        
-       if (pushback.empty())
-           c = getc(f);        
-       else 
-           c = pushback.pop();
+    if (pushback.empty ())
+      c = getc (f);    
+    else 
+      c = pushback.pop ();
 
-       if (c =='\n')
-           line_no++;
-       return c;       
-    }
-    void unget(char c) {
-       if (c =='\n')
-           line_no--;
-       pushback.push(c);
-    }
-    ~Text_stream (){
-       if (!eof()) 
-           cerr <<__FUNCTION__<< ": closing unended file";
-    
-       fclose(f);
-    }
+    if (c =='\n')
+      line_no++;
+    return c;  
+  }
+  void unget (char c) {
+    if (c =='\n')
+      line_no--;
+    pushback.push (c);
+  }
+  char peek () {
+    if (eof_b ())
+      return (char)-1;
+    char c = get ();
+    unget (c);
+    return c;
+  }
+  bool eol () {
+    return (peek () == '\n');
+  }
+  int line (){
+    return line_no;
+  }
+
+  ~Text_stream ();
+  
 
-    /// GNU format message.
-    void message(String s); 
+  /// GNU format message.
+  void message (String s); 
 };
 
 #endif