]> git.donarmstrong.com Git - lilypond.git/blob - flower/dataf.cc
release: 0.0.32
[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    Only class member who uses text_file::get
83    */
84 char
85 Data_file::data_get() {
86     char c =  get(); 
87     if (!rawmode && c == '#') // gobble comment
88         {       
89         while ((c = get()) != '\n' && !eof()) 
90             ;
91             return '\n';
92         }    
93
94     return c;
95 }
96
97 /// read line, gobble '\n'    
98 String Data_file::get_line()     
99 {
100     char c; 
101     String s;
102
103     while ((c  = data_get()) != '\n' && !eof())
104         s += c;
105     return s;   
106 }
107
108 /// gobble stuff before first entry on a line.    
109 void
110 Data_file::gobble_leading_white() 
111 {
112     // eat blank lines.
113     while (!eof()) {
114         char c = data_get();                
115         if (!isspace(c)) {
116             data_unget(c);
117             break;
118         }
119     }
120 }
121
122