14 const string& MultiFileReader::getFilename()
const {
16 if (last_reader)
return last_reader->getFilename();
18 static string nf =
"unknown-source";
21 return reader->getFilename();
23 bool MultiFileReader::getLine_intern(
string&
line) {
26 gotLine = reader->getLine(line);
29 gotLine = getLine_intern(line);
30 if (gotLine) setLineNumber(reader->getLineNumber());
36 FILE *MultiFileReader::open(
int i) {
37 FILE *in = fopen(files[i],
"rt");
42 void MultiFileReader::nextReader() {
52 if (at<files.size()) {
60 MultiFileReader::MultiFileReader(
const CharPtrArray& files_) :
67 for (
size_t i = 0; i<files.size() && !error; ++i) {
72 if (!error) nextReader();
75 MultiFileReader::~MultiFileReader() {
88 void TEST_MultiFileReader() {
90 files.
put(
"general/broken_LF.input");
91 files.
put(
"general/dos.input");
92 files.
put(
"general/mac.input");
93 files.
put(
"general/empty.input");
94 files.
put(
"general/text.input");
97 MultiFileReader reader(files);
102 string emptyLineError;
103 string db_found_msgs;
105 int emptyLineCount = 0;
107 while (reader.getLine(line)) {
111 emptyLineError = reader.lineError(
"seen empty line");
113 else if (strstr(line.c_str(),
"database")) {
114 db_found_msgs += reader.lineError(
"DB") +
"\n";
123 "general/broken_LF.input:2: DB\n"
124 "general/dos.input:2: DB\n"
125 "general/mac.input:2: DB\n"
126 "general/text.input:2: DB\n");
129 files.
put(
"general/nosuch.input");
131 MultiFileReader reader(files);
132 TEST_EXPECT_EQUAL(reader.get_error(),
"While reading 'general/nosuch.input': No such file or directory");
void put(const char *elem)
return string(buffer, length)
GB_ERROR GB_IO_error(const char *action, const char *filename)
#define TEST_PUBLISH(testfunction)
static void error(const char *msg)
#define TEST_EXPECT_NO_ERROR(call)
#define TEST_EXPECT_EQUAL(expr, want)