1 /* $Id: plainfile.cpp,v 1.5 2007-05-09 21:23:09 adam Exp $
2 Copyright (c) 2005-2007, Index Data.
4 This file is part of Metaproxy.
6 Metaproxy is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2, or (at your option) any later
11 Metaproxy is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with Metaproxy; see the file LICENSE. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
31 #define PLAINFILE_MAX_LINE 256
33 namespace mp = metaproxy_1;
35 namespace metaproxy_1 {
36 class PlainFile::Rep {
37 friend class PlainFile;
45 mp::PlainFile::Rep::Rep() : lineno(1)
50 mp::PlainFile::PlainFile() : m_p(new Rep)
54 void mp::PlainFile::Rep::close()
61 mp::PlainFile::~PlainFile()
66 bool mp::PlainFile::open(const std::string &fname)
70 std::ifstream *new_file = new std::ifstream(fname.c_str());
80 bool mp::PlainFile::getline(std::vector<std::string> &args)
85 return false; // no file at all.
87 char line_cstr[PLAINFILE_MAX_LINE];
92 m_p->close(); // might as well close it now
97 m_p->fh->getline(line_cstr, PLAINFILE_MAX_LINE-1);
98 char first = line_cstr[0];
99 if (first && !strchr("# \t", first))
101 // comment or blank line.. read next.
103 const char *cp = line_cstr;
107 while (*cp && strchr(" \t", *cp))
111 const char *cp0 = cp;
112 while (*cp && !strchr(" \t", *cp))
114 std::string arg(cp0, cp - cp0);
123 * indent-tabs-mode: nil
124 * c-file-style: "stroustrup"
126 * vim: shiftwidth=4 tabstop=8 expandtab