]> git.donarmstrong.com Git - lilypond.git/blob - flower/data-file.cc
release: 0.1.24
[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@stack.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())
22       break;
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 (isspace (c) || eof())
37         {
38           data_unget (c);
39           break;
40         }
41
42
43       if (c == '\"')
44         {
45           rawmode= true;
46
47           while ((c  = data_get()) != '\"')
48             if (eof())
49               error (_("EOF in a string"));
50             else
51               s += c;
52
53
54           rawmode= false;
55         }
56       else
57         s += c;
58     }
59
60   return s;
61 }
62
63 /**  get a char
64    Only class member who uses text_file::get
65    */
66 char
67 Data_file::data_get() {
68   char c =  get();
69   if (!rawmode && c == '#') // gobble comment
70     {
71       while ((c = get()) != '\n' && !eof ())
72         ;
73       return '\n';
74     }
75
76   return c;
77 }
78
79 /// read line, gobble '\n'
80 String Data_file::get_line()
81 {
82   char c;
83   String s;
84
85   while ((c  = data_get()) != '\n' && !eof ())
86     s += c;
87   return s;
88 }
89
90 /// gobble stuff before first entry on a line.
91 void
92 Data_file::gobble_leading_white()
93 {
94   // eat blank lines.
95   while (!eof())
96     {
97       char c = data_get();
98       if (!isspace (c))
99         {
100           data_unget (c);
101           break;
102         }
103     }
104 }