move anonymous namespaces to the top

This commit is contained in:
unK
2008-10-28 12:52:30 +01:00
parent 6b2356318f
commit 8bd081e964
2 changed files with 176 additions and 176 deletions

View File

@@ -28,6 +28,61 @@ const string keys_config_file = config_dir + "keys";
using std::ifstream;
namespace
{
void GetKeys(string line, int *key)
{
int i = line.find("=")+1;
line = line.substr(i, line.length()-i);
i = 0;
if (line[i] == ' ')
while (line[++i] == ' ') { }
line = line.substr(i, line.length()-i);
i = line.find(" ");
string one;
string two;
if (i != string::npos)
{
one = line.substr(0, i);
i++;
two = line.substr(i, line.length()-i);
}
else
one = line;
key[0] = !one.empty() && one[0] == '\'' ? one[1] : (atoi(one.c_str()) == 0 ? null_key : atoi(one.c_str()));
key[1] = !two.empty() && two[0] == '\'' ? two[1] : (atoi(two.c_str()) == 0 ? null_key : atoi(two.c_str()));
}
Color IntoColor(const string &color)
{
Color result = clDefault;
if (color == "black")
result = clBlack;
else if (color == "red")
result = clRed;
else if (color == "green")
result = clGreen;
else if (color == "yellow")
result = clYellow;
else if (color == "blue")
result = clBlue;
else if (color == "magenta")
result = clMagenta;
else if (color == "cyan")
result = clCyan;
else if (color == "white")
result = clWhite;
return result;
}
Border IntoBorder(const string &color)
{
return (Border) IntoColor(color);
}
}
void CreateConfigDir()
{
mkdir(config_dir.c_str(), 0755);
@@ -279,61 +334,6 @@ mpd_TagItems IntoTagItem(char c)
}
}
namespace
{
void GetKeys(string line, int *key)
{
int i = line.find("=")+1;
line = line.substr(i, line.length()-i);
i = 0;
if (line[i] == ' ')
while (line[++i] == ' ') { }
line = line.substr(i, line.length()-i);
i = line.find(" ");
string one;
string two;
if (i != string::npos)
{
one = line.substr(0, i);
i++;
two = line.substr(i, line.length()-i);
}
else
one = line;
key[0] = !one.empty() && one[0] == '\'' ? one[1] : (atoi(one.c_str()) == 0 ? null_key : atoi(one.c_str()));
key[1] = !two.empty() && two[0] == '\'' ? two[1] : (atoi(two.c_str()) == 0 ? null_key : atoi(two.c_str()));
}
Color IntoColor(const string &color)
{
Color result = clDefault;
if (color == "black")
result = clBlack;
else if (color == "red")
result = clRed;
else if (color == "green")
result = clGreen;
else if (color == "yellow")
result = clYellow;
else if (color == "blue")
result = clBlue;
else if (color == "magenta")
result = clMagenta;
else if (color == "cyan")
result = clCyan;
else if (color == "white")
result = clWhite;
return result;
}
Border IntoBorder(const string &color)
{
return (Border) IntoColor(color);
}
}
void ReadKeys(ncmpcpp_keys &keys)
{
ifstream f(keys_config_file.c_str());

View File

@@ -41,6 +41,127 @@ extern Menu<string> *mTagEditor;
extern Window *wFooter;
extern Window *wPrev;
namespace
{
const string patterns_list_file = config_dir + "patterns.list";
vector<string> patterns_list;
void GetPatternList()
{
if (patterns_list.empty())
{
std::ifstream input(patterns_list_file.c_str());
if (input.is_open())
{
string line;
while (getline(input, line))
{
if (!line.empty())
patterns_list.push_back(line);
}
input.close();
}
}
}
void SavePatternList()
{
std::ofstream output(patterns_list_file.c_str());
if (output.is_open())
{
for (vector<string>::const_iterator it = patterns_list.begin(); it != patterns_list.end() && it != patterns_list.begin()+30; it++)
output << *it << std::endl;
output.close();
}
}
SongSetFunction IntoSetFunction(char c)
{
switch (c)
{
case 'a':
return &Song::SetArtist;
case 't':
return &Song::SetTitle;
case 'b':
return &Song::SetAlbum;
case 'y':
return &Song::SetYear;
case 'n':
return &Song::SetTrack;
case 'g':
return &Song::SetGenre;
case 'c':
return &Song::SetComposer;
case 'p':
return &Song::SetPerformer;
case 'd':
return &Song::SetDisc;
case 'C':
return &Song::SetComment;
default:
return NULL;
}
}
string GenerateFilename(const Song &s, string &pattern)
{
string result = Window::OmitBBCodes(DisplaySong(s, &pattern));
EscapeUnallowedChars(result);
return result;
}
string ParseFilename(Song &s, string mask, bool preview)
{
std::stringstream result;
vector<string> separators;
vector< std::pair<char, string> > tags;
string file = s.GetName().substr(0, s.GetName().find_last_of("."));
try
{
for (int i = mask.find("%"); i != string::npos; i = mask.find("%"))
{
tags.push_back(make_pair(mask.at(i+1), ""));
mask = mask.substr(i+2);
i = mask.find("%");
if (!mask.empty())
separators.push_back(mask.substr(0, i));
}
int i = 0;
for (vector<string>::const_iterator it = separators.begin(); it != separators.end(); it++, i++)
{
int j = file.find(*it);
tags.at(i).second = file.substr(0, j);
file = file.substr(j+it->length());
}
if (!file.empty())
tags.at(i).second = file;
}
catch (std::out_of_range)
{
return "Error while parsing filename!";
}
for (vector< std::pair<char, string> >::iterator it = tags.begin(); it != tags.end(); it++)
{
for (string::iterator j = it->second.begin(); j != it->second.end(); j++)
if (*j == '_')
*j = ' ';
if (!preview)
{
SongSetFunction set = IntoSetFunction(it->first);
if (set)
(s.*set)(it->second);
}
else
result << "%" << it->first << ": " << it->second << "\n";
}
return result.str();
}
}
SongSetFunction IntoSetFunction(mpd_TagItems tag)
{
switch (tag)
@@ -294,127 +415,6 @@ bool WriteTags(Song &s)
return false;
}
namespace
{
const string patterns_list_file = config_dir + "patterns.list";
vector<string> patterns_list;
void GetPatternList()
{
if (patterns_list.empty())
{
std::ifstream input(patterns_list_file.c_str());
if (input.is_open())
{
string line;
while (getline(input, line))
{
if (!line.empty())
patterns_list.push_back(line);
}
input.close();
}
}
}
void SavePatternList()
{
std::ofstream output(patterns_list_file.c_str());
if (output.is_open())
{
for (vector<string>::const_iterator it = patterns_list.begin(); it != patterns_list.end() && it != patterns_list.begin()+30; it++)
output << *it << std::endl;
output.close();
}
}
SongSetFunction IntoSetFunction(char c)
{
switch (c)
{
case 'a':
return &Song::SetArtist;
case 't':
return &Song::SetTitle;
case 'b':
return &Song::SetAlbum;
case 'y':
return &Song::SetYear;
case 'n':
return &Song::SetTrack;
case 'g':
return &Song::SetGenre;
case 'c':
return &Song::SetComposer;
case 'p':
return &Song::SetPerformer;
case 'd':
return &Song::SetDisc;
case 'C':
return &Song::SetComment;
default:
return NULL;
}
}
string GenerateFilename(const Song &s, string &pattern)
{
string result = Window::OmitBBCodes(DisplaySong(s, &pattern));
EscapeUnallowedChars(result);
return result;
}
string ParseFilename(Song &s, string mask, bool preview)
{
std::stringstream result;
vector<string> separators;
vector< std::pair<char, string> > tags;
string file = s.GetName().substr(0, s.GetName().find_last_of("."));
try
{
for (int i = mask.find("%"); i != string::npos; i = mask.find("%"))
{
tags.push_back(make_pair(mask.at(i+1), ""));
mask = mask.substr(i+2);
i = mask.find("%");
if (!mask.empty())
separators.push_back(mask.substr(0, i));
}
int i = 0;
for (vector<string>::const_iterator it = separators.begin(); it != separators.end(); it++, i++)
{
int j = file.find(*it);
tags.at(i).second = file.substr(0, j);
file = file.substr(j+it->length());
}
if (!file.empty())
tags.at(i).second = file;
}
catch (std::out_of_range)
{
return "Error while parsing filename!";
}
for (vector< std::pair<char, string> >::iterator it = tags.begin(); it != tags.end(); it++)
{
for (string::iterator j = it->second.begin(); j != it->second.end(); j++)
if (*j == '_')
*j = ' ';
if (!preview)
{
SongSetFunction set = IntoSetFunction(it->first);
if (set)
(s.*set)(it->second);
}
else
result << "%" << it->first << ": " << it->second << "\n";
}
return result.str();
}
}
void __deal_with_filenames(SongList &v)
{
int width = 30;