| 1 |
@@ -1,10 +1,5 @@ |
| 1 |
//! @file
|
| 2 |
//! @author Claes Nasten <pekdon{@}pekdon{.}net
|
| 3 |
//! @date 2005-06-15
|
| 4 |
//! @brief Configuration parser source handler.
|
| 5 |
|
| 6 |
//
|
| 7 |
// Copyright (C) 2005 Claes Nasten <pekdon{@}pekdon{.}net>
|
| 8 |
// Copyright © 2005-2008 Claes Nästén <me@pekdon.net>
|
| 9 |
//
|
| 10 |
// This program is licensed under the GNU GPL.
|
| 11 |
// See the LICENSE file for more information.
|
| ... |
|
| 27 |
@@ -32,73 +27,73 @@ |
| 27 |
SOURCE_VIRTUAL //!< Source base type.
|
| 28 |
};
|
| 29 |
|
| 35 |
CfgParserSource (const std::string &or_source) :
|
| 36 |
_op_file (NULL), _or_name(or_source),
|
| 37 |
_type(SOURCE_VIRTUAL), _i_line (0)
|
| 33 |
CfgParserSource(const std::string &source)
|
| 34 |
: _file(0), _name(source),
|
| 35 |
_type(SOURCE_VIRTUAL), _line(0)
|
| 36 |
{
|
| 37 |
}
|
| 38 |
virtual ~CfgParserSource (void) { }
|
| 39 |
|
| 45 |
//! @brief Gets a character from _op_file, increments line count if \n.
|
| 46 |
inline int getc (void) {
|
| 47 |
int i_c = fgetc (_op_file);
|
| 48 |
if (i_c == '\n') {
|
| 49 |
++_i_line;
|
| 45 |
//! @brief Gets a character from _file, increments line count if \n.
|
| 46 |
inline int getc(void) {
|
| 47 |
int c = fgetc(_file);
|
| 48 |
if (c == '\n') {
|
| 49 |
++_line;
|
| 50 |
}
|
| 56 |
return i_c;
|
| 52 |
return c;
|
| 53 |
}
|
| 54 |
|
| 55 |
//! @brief Returns a character to _op_file, decrements line count if \n.
|
| 61 |
inline void ungetc (int i_c) {
|
| 62 |
::ungetc (i_c, _op_file);
|
| 63 |
if (i_c == '\n') {
|
| 64 |
--_i_line;
|
| 60 |
inline void ungetc(int c) {
|
| 61 |
::ungetc (c, _file);
|
| 62 |
if (c == '\n') {
|
| 63 |
--_line;
|
| 64 |
}
|
| 65 |
}
|
| 66 |
|
| 72 |
const std::string &get_name(void) { return _or_name; }
|
| 68 |
const std::string &get_name(void) { return _name; }
|
| 69 |
CfgParserSource::Type get_type(void) { return _type; }
|
| 75 |
int get_line (void) { return _i_line; }
|
| 71 |
int get_line(void) { return _line; }
|
| 72 |
|
| 78 |
virtual bool open (void) throw (std::string&) { return false; }
|
| 79 |
virtual void close (void) throw (std::string&) { }
|
| 75 |
virtual bool open(void) throw (std::string&) { return false; }
|
| 76 |
virtual void close(void) throw (std::string&) { }
|
| 77 |
|
| 78 |
protected:
|
| 84 |
FILE *_op_file;
|
| 85 |
const std::string &_or_name;
|
| 81 |
FILE *_file;
|
| 82 |
const std::string &_name;
|
| 83 |
CfgParserSource::Type _type;
|
| 89 |
int _i_line;
|
| 85 |
int _line;
|
| 86 |
};
|
| 87 |
|
| 88 |
class CfgParserSourceFile : public CfgParserSource
|
| 89 |
{
|
| 90 |
public:
|
| 96 |
CfgParserSourceFile (const std::string &or_source)
|
| 97 |
: CfgParserSource (or_source)
|
| 93 |
CfgParserSourceFile (const std::string &source)
|
| 94 |
: CfgParserSource(source)
|
| 95 |
{
|
| 96 |
_type = SOURCE_FILE;
|
| 97 |
}
|
| 98 |
virtual ~CfgParserSourceFile (void) { }
|
| 99 |
|
| 105 |
virtual bool open (void) throw (std::string&);
|
| 106 |
virtual void close (void) throw (std::string&);
|
| 102 |
virtual bool open(void) throw (std::string&);
|
| 103 |
virtual void close(void) throw (std::string&);
|
| 104 |
};
|
| 105 |
|
| 106 |
class CfgParserSourceCommand : public CfgParserSource
|
| 107 |
{
|
| 108 |
public:
|
| 114 |
CfgParserSourceCommand (const std::string &or_source)
|
| 115 |
: CfgParserSource (or_source)
|
| 111 |
CfgParserSourceCommand(const std::string &source)
|
| 112 |
: CfgParserSource (source)
|
| 113 |
{
|
| 114 |
_type = SOURCE_COMMAND;
|
| 115 |
}
|
| 121 |
virtual ~CfgParserSourceCommand (void) { }
|
| 117 |
virtual ~CfgParserSourceCommand(void) { }
|
| 118 |
|
| 124 |
virtual bool open (void) throw (std::string&);
|
| 125 |
virtual void close (void) throw (std::string&);
|
| 121 |
virtual bool open(void) throw (std::string&);
|
| 122 |
virtual void close(void) throw (std::string&);
|
| 123 |
|
| 124 |
private:
|
| 130 |
pid_t _o_pid;
|
| 126 |
pid_t _pid;
|
| 127 |
|
| 128 |
struct sigaction _sigaction; //!< sigaction for restore.
|
| 129 |
static unsigned int _sigaction_counter; //!< Counts open.
|
| ... |
|