2008-12-11 03:46:16 +01:00
|
|
|
/*
|
|
|
|
* This file is a part of CMSLU -- Content Management System like Unix
|
|
|
|
* and is not publicly distributed
|
|
|
|
*
|
|
|
|
* Copyright (c) 2008, Tomasz Sowa
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef headerfileconfparser
|
|
|
|
#define headerfileconfparser
|
|
|
|
|
|
|
|
#include <fstream>
|
|
|
|
#include <string>
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
|
|
|
|
class ConfParser
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
enum Status { ok, cant_open_file, syntax_error };
|
|
|
|
|
|
|
|
ConfParser();
|
|
|
|
Status Parse(const char * file_name);
|
|
|
|
|
|
|
|
|
|
|
|
// last status
|
|
|
|
Status status;
|
|
|
|
|
|
|
|
// line in which there is a syntax_error
|
|
|
|
int line;
|
|
|
|
|
|
|
|
typedef std::map<std::string, std::string> Table;
|
|
|
|
Table table;
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
// last read variable, value
|
|
|
|
std::string variable, value;
|
|
|
|
|
|
|
|
// separator between a variable and a value, usually '='
|
|
|
|
int separator;
|
|
|
|
|
|
|
|
// commentary char
|
|
|
|
int commentary;
|
|
|
|
|
|
|
|
// last read char
|
|
|
|
int lastc;
|
|
|
|
|
|
|
|
// current file
|
|
|
|
std::ifstream file;
|
|
|
|
|
|
|
|
|
|
|
|
Status ParseFile();
|
|
|
|
|
|
|
|
bool IsVariableChar(int c);
|
|
|
|
bool IsValueSimpleChar(int c);
|
|
|
|
|
|
|
|
bool ReadVariable();
|
|
|
|
bool ReadValue();
|
|
|
|
bool ReadValueQuoted();
|
|
|
|
bool ReadValueSimple();
|
|
|
|
|
|
|
|
int ReadChar();
|
|
|
|
bool IsWhite(int c);
|
|
|
|
void SkipWhite();
|
|
|
|
void SkipLine();
|
2010-01-28 16:39:01 +01:00
|
|
|
void Trim(std::string & s);
|
2008-12-11 03:46:16 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|