]> git.donarmstrong.com Git - lilypond.git/blob - flower/dataf.cc
release: 0.0.4
[lilypond.git] / flower / dataf.cc
1 #include <fstream.h>
2 #include <ctype.h>
3
4 #include "textstr.hh"
5 Text_stream::Text_stream(String fn)
6 {       
7         if (fn == "") 
8             {
9             name = "<STDIN>";       
10             f = stdin;
11             }
12         
13         else 
14             {
15             name = fn;      
16             f = fopen(fn, "r");
17             }
18         
19         if (!f) {
20             cerr <<__FUNCTION__<< ": can't open `" << fn << "'\n";
21             exit(1);
22         }
23
24         line_no = 1;
25     }
26
27 void
28 Text_stream::message(String s)
29 {
30     cerr << "\n"<<get_name() << ": " << line()<<": "<<s<<endl;
31 }
32
33 void 
34 Data_file::gobble_white()
35 {
36     char c;
37     
38     while ((c=data_get()) == ' ' ||c == '\t')
39         if (eof()) 
40             break;
41
42     data_unget(c);
43 }
44
45 String
46 Data_file::get_word() 
47 {// should handle escape seq's
48     String s;
49
50     while (1) 
51         {
52         char    c  = data_get();
53         
54         if (isspace(c) || eof()) 
55             {
56             data_unget(c);
57             break;
58             }
59         
60         
61         if (c == '\"')
62             {
63             rawmode= true;
64
65             while ((c  = data_get()) != '\"')
66                 if (eof())
67                     error("EOF in a string");           
68                 else
69                     s += c;
70             
71
72             rawmode= false;
73             }       
74         else
75             s += c;             
76         }
77     
78     return s;         
79 }
80
81 /// get a char.
82 char
83 Data_file::data_get() {
84     char c =  get(); 
85     if (!rawmode && c == '#') // gobble comment
86         {       
87         while ((c = get()) != '\n' && !eof()) 
88             ;
89             return '\n';
90         }    
91
92     return c;
93 }
94 /**
95    Only class member who uses text_file::get
96    */
97
98 /// read line, gobble '\n'    
99 String Data_file::get_line()     
100 {
101     char c; 
102     String s;
103
104     while ((c  = data_get()) != '\n' && !eof())
105         s += c;
106     return s;   
107 }
108
109 /// gobble stuff before first entry on a line.    
110 void
111 Data_file::gobble_leading_white() 
112 {
113     // eat blank lines.
114     while (!eof()) {
115         char c = data_get();                
116         if (!isspace(c)) {
117             data_unget(c);
118             break;
119         }
120     }
121 }
122
123