]> git.donarmstrong.com Git - lilypond.git/blob - flower/data-file.cc
release: 1.0.1
[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 /**  get a char
67    Only class member who uses text_file::get
68    */
69 char
70 Data_file::data_get()
71 {
72   char c =  get();
73   if (!rawmode && c == '#') // gobble comment
74     {
75       while (!eof_b () && (c = get()) != '\n')
76         ;
77       return '\n';
78     }
79
80   return c;
81 }
82
83 /// read line, gobble '\n'
84 String
85 Data_file::get_line()
86 {
87   char c;
88   String s;
89
90   while (!eof_b () && (c  = data_get()) != '\n')
91     s += to_str (c);
92   return s;
93 }
94
95 /// gobble stuff before first entry on a line.
96 void
97 Data_file::gobble_leading_white()
98 {
99   // eat blank lines.
100   while (!eof_b ())
101     {
102       char c = data_get();
103       if (!isspace (c))
104         {
105           data_unget (c);
106           break;
107         }
108     }
109 }
110
111 Data_file::Data_file (String s)
112   : Text_stream (s) 
113 {
114   //*mlog << "(" << s << flush; 
115   rawmode=  false;      
116 }
117
118 void
119 Data_file::warning (String s)
120 {
121   message (_ ("warning: ") + s);
122 }
123
124 void
125 Data_file::error (String s)
126 {
127   message (s);
128   exit (1);    
129 }
130
131 String
132 Data_file::gulp ()
133 {
134   String s;
135
136   while (!eof_b ())
137     {
138       s += to_str (data_get ());
139     }
140   return s;
141 }
142   
143
144 Data_file::~Data_file ()
145 {
146 }