Beispiel #1
0
void ConfigFile::LoadConfig(string conf) throw (Error)
{
	ifstream confile(conf.c_str());
	if (!confile) throw Error404(conf);

	char szBuffer[0xFFFF];		// That's a big buffer... :)
	while (!confile.eof())
	{
		confile.getline(szBuffer, 0xFFFF);

		if (strlen(szBuffer))
		{
			// Anyone knows a good parsing lib?
			// I hate writing ugly, C-style stringed code...

			char *c = szBuffer;
			while (isspace(*c)) c++;
			if (*c == '#') continue;	// comment or empty line

			if ((c = strstr(szBuffer, "DBPATH=")) != 0)
			{
				c += 7;
				char *begin = c;

				if (*c == '"')
				{
					begin++;
					char *end = strstr(begin, "\"");
					*end = 0;
				}

				else if (*c == '\'')
				{
					begin++;
					char *end = strstr(begin, "\'");
					*end = 0;
				}

				else
				{
					char *end = begin;

					while (!isspace(*end)) end++;
					*end = 0;
				}

				strDBPath = string(begin);
			}
		}
	}

	strDBPath += string("/");

	confile.close();
}
Beispiel #2
0
CS::ConfReader::ConfReader(std::string file) : conffile(file) {
    std::ifstream confile(file);
    if (!confile) {
        CS::error(CONFIG_FILE_NO_EXIST);
    }
    std::string s;
    while (getline(confile, s)) {
        auto confitem = this->analy(s);
        confs.insert(confitem);
    }

    if(confs.find("path") == confs.end())
        CS::error(UNKNOW);//TODO:给该错误取名字
    //检查目录是否存在,以及权限问题
    CS::is_directory(conf["path"].c_str(),true);
}