]> git.donarmstrong.com Git - lilypond.git/blob - flower/data-file.cc
release: 1.1.52
[lilypond.git] / flower / data-file.cc
1 /*   
2   data-file.cc --  implement Data_file 
3   
4   source file of the Flower Library
5   
6   (c) '95, '96, '97 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8   */
9 #include <fstream.h>
10 #include <ctype.h>
11
12 #include "international.hh"
13 #include "data-file.hh"
14
15 void
16 Data_file::gobble_white()
17 {
18   char c;
19
20   while ((c=data_get()) == ' ' ||c == '\t')
21     if (eof_b())
22       return;
23
24   data_unget (c);
25 }
26
27 String
28 Data_file::get_word()
29 {// should handle escape seq's
30   String s;
31
32   while (1)
33     {
34       char      c  = data_get();
35       
36       if  (eof_b ())
37         break;
38
39       if (isspace (c))
40         {
41           data_unget (c);
42           break;
43         }
44
45
46       if (c == '\"')
47         {
48           rawmode= true;
49
50           while ((c  = data_get()) != '\"')
51             if (eof_b ())
52               error (_ ("EOF in a string"));
53             else
54               s += to_str (c);
55
56
57           rawmode= false;
58         }
59       else
60         s += to_str (c);
61     }
62
63   return s;
64 }
65
66 char
67 Data_file::data_get()
68 {
69   char c =  get();
70   if (!rawmode && c == '#') // gobble comment
71     {
72       while (!eof_b () && (c = get()) != '\n')
73         ;
74       return '\n';
75     }
76
77   return c;
78 }
79
80 String
81 Data_file::get_line()
82 {
83   char c;
84   String s;
85
86   while (!eof_b () && (c  = data_get()) != '\n')
87     s += to_str (c);
88   return s;
89 }
90
91 void
92 Data_file::gobble_leading_white()
93 {
94   // eat blank lines.
95   while (!eof_b ())
96     {
97       char c = data_get();
98       if (!isspace (c))
99         {
100           data_unget (c);
101           break;
102         }
103     }
104 }
105
106 Data_file::Data_file (String s)
107   : Text_stream (s) 
108 {
109   //*mlog << "(" << s << flush; 
110   rawmode=  false;      
111 }
112
113 void
114 Data_file::warning (String s)
115 {
116   message (_ ("warning: ") + s);
117 }
118
119 void
120 Data_file::error (String s)
121 {
122   message (s);
123   exit (1);    
124 }
125
126 String
127 Data_file::gulp ()
128 {
129   String s;
130
131   while (!eof_b ())
132     {
133       s += to_str (data_get ());
134     }
135   return s;
136 }
137   
138
139 Data_file::~Data_file ()
140 {
141 }