1 /* This file is part of Metaproxy.
2 Copyright (C) 2005-2011 Index Data
4 Metaproxy is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
9 Metaproxy is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 #include <metaproxy/util.hpp>
28 #define PLAINFILE_MAX_LINE 256
30 namespace mp = metaproxy_1;
32 namespace metaproxy_1 {
33 class PlainFile::Rep {
34 friend class PlainFile;
42 mp::PlainFile::Rep::Rep() : lineno(1)
47 mp::PlainFile::PlainFile() : m_p(new Rep)
51 void mp::PlainFile::Rep::close()
58 mp::PlainFile::~PlainFile()
63 bool mp::PlainFile::open(const std::string &fname)
67 std::ifstream *new_file = new std::ifstream(fname.c_str());
77 bool mp::PlainFile::getline(std::vector<std::string> &args)
82 return false; // no file at all.
84 char line_cstr[PLAINFILE_MAX_LINE];
89 m_p->close(); // might as well close it now
94 m_p->fh->getline(line_cstr, PLAINFILE_MAX_LINE-1);
95 char first = line_cstr[0];
96 if (first && !strchr("# \t", first))
98 // comment or blank line.. read next.
100 const char *cp = line_cstr;
104 while (*cp && strchr(" \t", *cp))
108 const char *cp0 = cp;
109 while (*cp && !strchr(" \t", *cp))
111 std::string arg(cp0, cp - cp0);
120 * c-file-style: "Stroustrup"
121 * indent-tabs-mode: nil
123 * vim: shiftwidth=4 tabstop=8 expandtab