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