/********************************************************************** * * cfgread.cpp -- * Copyright (C) 1999 The New Zealand Digital Library Project * * PUT COPYRIGHT NOTICE HERE * * $Id: cfgread.cpp 112 1999-01-12 01:51:06Z rjmcnab $ * *********************************************************************/ /* $Log$ Revision 1.3 1999/01/12 01:50:57 rjmcnab Standard header. Revision 1.2 1999/01/08 02:33:13 rjmcnab Added standard header to source files. */ #include "cfgread.h" // returns 0 on success, -1 on failure int read_cfg_line (ifstream &filein, text_tarray &values) { values.erase(values.begin(), values.end()); if (!filein.good()) return -1; text_t curvalue; char c; int firstchar = 1; filein.get(c); while (!filein.eof()) { if (c == '#' && firstchar) { // found a comment, ignore the rest of the line while (!filein.eof() && c != '\n') { filein.get(c); } } else if (firstchar && (c == '\n' || c == ' ' || c == '\t')) { // found initial white space, ignore it } else if (c == '\n') { // found the end of an entry break; } else if (c == '\t') { // found a record separator values.push_back(curvalue); curvalue.clear(); } else { curvalue.push_back(c); firstchar = 0; } filein.get(c); } values.push_back(curvalue); return 0; }