lilypond-1.1.49
[lilypond.git] / flower / data-file.cc
blob996752cfce34d48e6f8d6d22f8a1e7a7aab2d291
1 /*
2 data-file.cc -- implement Data_file
4 source file of the Flower Library
6 (c) '95, '96, '97 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 */
9 #include <fstream.h>
10 #include <ctype.h>
12 #include "international.hh"
13 #include "data-file.hh"
15 void
16 Data_file::gobble_white()
18 char c;
20 while ((c=data_get()) == ' ' ||c == '\t')
21 if (eof_b())
22 return;
24 data_unget (c);
27 String
28 Data_file::get_word()
29 {// should handle escape seq's
30 String s;
32 while (1)
34 char c = data_get();
36 if (eof_b ())
37 break;
39 if (isspace (c))
41 data_unget (c);
42 break;
46 if (c == '\"')
48 rawmode= true;
50 while ((c = data_get()) != '\"')
51 if (eof_b ())
52 error (_ ("EOF in a string"));
53 else
54 s += to_str (c);
57 rawmode= false;
59 else
60 s += to_str (c);
63 return s;
66 /** get a char
67 Only class member who uses text_file::get
69 char
70 Data_file::data_get()
72 char c = get();
73 if (!rawmode && c == '#') // gobble comment
75 while (!eof_b () && (c = get()) != '\n')
77 return '\n';
80 return c;
83 /// read line, gobble '\n'
84 String
85 Data_file::get_line()
87 char c;
88 String s;
90 while (!eof_b () && (c = data_get()) != '\n')
91 s += to_str (c);
92 return s;
95 /// gobble stuff before first entry on a line.
96 void
97 Data_file::gobble_leading_white()
99 // eat blank lines.
100 while (!eof_b ())
102 char c = data_get();
103 if (!isspace (c))
105 data_unget (c);
106 break;
111 Data_file::Data_file (String s)
112 : Text_stream (s)
114 //*mlog << "(" << s << flush;
115 rawmode= false;
118 void
119 Data_file::warning (String s)
121 message (_ ("warning: ") + s);
124 void
125 Data_file::error (String s)
127 message (s);
128 exit (1);
131 String
132 Data_file::gulp ()
134 String s;
136 while (!eof_b ())
138 s += to_str (data_get ());
140 return s;
144 Data_file::~Data_file ()