fixed: in htmlfilter: <area> should be treated as single tag

changed: ConfParser is abble to recognize lists


git-svn-id: svn://ttmath.org/publicrep/winix/trunk@623 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2010-07-21 17:24:16 +00:00
parent 93da32cfb3
commit e4683b9a05
7 changed files with 521 additions and 116 deletions

View File

@@ -72,7 +72,8 @@ bool Config::ReadConfig(bool errors_to_stdout_)
log << log2 << "Config: reading a config file" << logend;
ConfParser::Status status = conf_parser.Parse( data.config_file.c_str() );
conf_parser.SplitSingle(true);
ConfParser::Status status = conf_parser.Parse( data.config_file );
if( status == ConfParser::ok )
@@ -141,10 +142,6 @@ void Config::AssignValues()
data.session_file = Text("session_file");
data.compression = Bool("compression", true);
std::string p = Text("plugin");
data.plugin_file.push_back(p);
data.html_filter = Bool("html_filter", true);
data.locale_str = Text("locale", "en");
@@ -153,6 +150,8 @@ void Config::AssignValues()
data.title_separator = Text("title_separator", " / ");
ListText(data.plugin_file, "plugin");
}
@@ -173,9 +172,9 @@ std::string Config::Text(const char * name, const char * def)
std::string Config::Text(const std::string & name, const std::string & def)
{
ConfParser::Table::iterator i = conf_parser.table.find(name);
ConfParser::TableSingle::iterator i = conf_parser.table_single.find(name);
if( i == conf_parser.table.end() )
if( i == conf_parser.table_single.end() )
return def;
return i->second;
@@ -197,9 +196,9 @@ int Config::Int(const char * name, int def)
int Config::Int(const std::string & name, int def)
{
ConfParser::Table::iterator i = conf_parser.table.find(name);
ConfParser::TableSingle::iterator i = conf_parser.table_single.find(name);
if( i == conf_parser.table.end() || i->second.empty() )
if( i == conf_parser.table_single.end() || i->second.empty() )
return def;
long res = (i->second[0] == '0')? strtol(i->second.c_str() + 1, 0, 8) : strtol(i->second.c_str(), 0, 10);
@@ -222,9 +221,9 @@ bool Config::Bool(const char * name, bool def)
bool Config::Bool(const std::string & name, bool def)
{
ConfParser::Table::iterator i = conf_parser.table.find(name);
ConfParser::TableSingle::iterator i = conf_parser.table_single.find(name);
if( i == conf_parser.table.end() || i->second.empty() )
if( i == conf_parser.table_single.end() || i->second.empty() )
return def;
bool res = false;
@@ -239,6 +238,34 @@ return res;
}
// in lists we don't use default values
void Config::ListText(std::vector<std::string> & list, const char * name)
{
ListText(list, std::string(name));
}
void Config::ListText(std::vector<std::string> & list, const std::string & name)
{
list.clear();
ConfParser::TableSingle::iterator i = conf_parser.table_single.find(name);
if( i != conf_parser.table_single.end() )
{
list.push_back(i->second);
return;
}
ConfParser::Table::iterator z = conf_parser.table.find(name);
if( z != conf_parser.table.end() )
{
list = z->second;
return;
}
}
void Config::NoLastSlash(std::string & s)

View File

@@ -44,6 +44,9 @@ private:
bool Bool(const char * name, bool def);
bool Bool(const std::string & name, bool def);
void ListText(std::vector<std::string> & list, const char * name);
void ListText(std::vector<std::string> & list, const std::string & name);
std::string default_str;
int default_int;
bool default_bool;

View File

@@ -1024,7 +1024,8 @@ void HTMLFilter::CheckExceptions()
IsLastTag("br") ||
IsLastTag("hr") ||
IsLastTag("img") ||
IsLastTag("link") )
IsLastTag("link") ||
IsLastTag("area") )
{
LastItem().type = Item::simple;
PopStack();

View File

@@ -22,9 +22,9 @@ Locale::Locale()
void Locale::AddLocale(Lang lang)
{
ConfParser::Table::iterator i = loc_parser.table.begin();
ConfParser::TableSingle::iterator i = loc_parser.table_single.begin();
for( ; i != loc_parser.table.end() ; ++i)
for( ; i != loc_parser.table_single.end() ; ++i)
loc_tab[lang][i->first] = i->second;
}
@@ -41,40 +41,37 @@ void Locale::ReadFile(const char * dir, const char * dir_def, Lang lang, const c
loc_tab[lang].clear();
bool read = false;
if( dir_def )
{
file_name = dir_def;
file_name += '/';
file_name += file;
if( loc_parser.Parse(file_name.c_str()) == ConfParser::ok )
{
read = true;
AddLocale(lang);
log << log3 << "Locale: read locale from: " << file_name << logend;
}
}
if( dir )
{
file_name = dir;
file_name += '/';
file_name += file;
if( loc_parser.Parse(file_name.c_str()) == ConfParser::ok )
{
read = true;
AddLocale(lang);
log << log3 << "Locale: read locale from: " << file_name << logend;
}
}
if( dir_def && ReadFile(dir_def, lang, file) )
read = true;
if( dir && ReadFile(dir, lang, file) )
read = true;
if( !read )
log << log1 << "Locale: cant open file for locale: " << file << logend;
log << log1 << "Locale: can't open locale's file: " << file << logend;
}
bool Locale::ReadFile(const char * dir, Lang lang, const char * file)
{
bool read = false;
file_name = dir;
file_name += '/';
file_name += file;
loc_parser.SplitSingle(true);
if( loc_parser.Parse(file_name) == ConfParser::ok )
{
read = true;
AddLocale(lang);
log << log3 << "Locale: read locale from: " << file_name << logend;
}
return read;
}
void Locale::Read(const char * dir, const char * dir_def)
{
@@ -126,7 +123,7 @@ bool Locale::IsKey(const std::string & key, Lang lang) const
}
// looking in the lang language
ConfParser::Table::const_iterator i = loc_tab[lang].find(key);
ConfParser::TableSingle::const_iterator i = loc_tab[lang].find(key);
if( i != loc_tab[lang].end() )
return true;
@@ -168,7 +165,7 @@ const std::string & Locale::Get(const std::string & key, Lang lang) const
}
// looking in the lang language
ConfParser::Table::const_iterator i = loc_tab[lang].find(key);
ConfParser::TableSingle::const_iterator i = loc_tab[lang].find(key);
if( i != loc_tab[lang].end() )
return i->second;

View File

@@ -56,9 +56,10 @@ private:
void AddLocale(Lang lang);
void ReadFile(const char * dir, const char * dir_def, Lang lang, const char * file);
bool ReadFile(const char * dir, Lang lang, const char * file);
std::vector<ConfParser::Table> loc_tab;
std::vector<ConfParser::TableSingle> loc_tab;
ConfParser loc_parser;
std::string file_name;
std::string empty;