blob: d050e278c54850b8b3db273eec0548ff8a5c04d0 (
about) (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
#include <fstream.h>
#include <ctype.h>
#include "textstr.hh"
Text_stream::Text_stream(String fn)
{
if (fn == "")
{
name = "<STDIN>";
f = stdin;
}
else
{
name = fn;
f = fopen(fn, "r");
}
if (!f) {
cerr <<__FUNCTION__<< ": can't open `" << fn << "'\n";
exit(1);
}
line_no = 1;
}
void
Text_stream::message(String s)
{
cerr << "\n"<<get_name() << ": " << line()<<": "<<s<<endl;
}
void
Data_file::gobble_white()
{
char c;
while ((c=data_get()) == ' ' ||c == '\t')
if (eof())
break;
data_unget(c);
}
String
Data_file::get_word()
{// should handle escape seq's
String s;
while (1)
{
char c = data_get();
if (isspace(c) || eof())
{
data_unget(c);
break;
}
if (c == '\"')
{
rawmode= true;
while ((c = data_get()) != '\"')
if (eof())
error("EOF in a string");
else
s += c;
rawmode= false;
}
else
s += c;
}
return s;
}
/// get a char.
char
Data_file::data_get() {
char c = get();
if (!rawmode && c == '#') // gobble comment
{
while ((c = get()) != '\n' && !eof())
;
return '\n';
}
return c;
}
/**
Only class member who uses text_file::get
*/
/// read line, gobble '\n'
String Data_file::get_line()
{
char c;
String s;
while ((c = data_get()) != '\n' && !eof())
s += c;
return s;
}
/// gobble stuff before first entry on a line.
void
Data_file::gobble_leading_white()
{
// eat blank lines.
while (!eof()) {
char c = data_get();
if (!isspace(c)) {
data_unget(c);
break;
}
}
}
|