-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEasylast.cpp
127 lines (101 loc) · 2.62 KB
/
Easylast.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include "Easylast.h"
Easylast::Easylast(){}
vector<string> Easylast::split(const string & msg,const string str_sep)
{
vector<string> res;
typedef boost::tokenizer<boost::char_separator<char> > my_tok;
boost::char_separator<char> sep( str_sep.c_str() );
my_tok tok( msg, sep );
for ( my_tok::const_iterator i = tok.begin();i != tok.end(); ++i )
res.push_back(*i);
return res;
}
map<string,string> Easylast::parse_info(const string & type)
{
QProcess p;
QString o;
string sep = "----------";
string output;
string cmd = "client_last --"+type+" -p";
p.start( stoqs(cmd));
p.waitForFinished(-1);
o = p.readAllStandardOutput();
output = o.toStdString();
vector<string> line_infos_scan = split(output,"\n");
vector<string> temp;
map<string,string> hash_info_scan;
for(vector<string>::iterator i = line_infos_scan.begin(); i != line_infos_scan.end(); ++i)
{
if( *i != sep && *i != type)
{
temp = split(*i,"===>");
temp[0].erase(temp[0].end()-1,temp[0].end());
temp[1].erase(0,1);
hash_info_scan[temp[0]] = temp[1];
}
}
return hash_info_scan;
}
string Easylast::find_summary(const string name,const int & chap)
{
QProcess p;
string cmd = "client_last --fs -t "+name+" -n "+itos(chap);
p.start(stoqs(cmd));
p.waitForFinished(-1);
QString o = p.readAllStandardOutput();
string output = o.toStdString();
vector<string> lines = split(output,"\n");
vector<string> temp;
string ret;
for(vector<string>::iterator i = lines.begin(); i != lines.end(); ++i)
{
temp = split(*i,"=");
if(temp[0] == "summary")
ret = temp[1];
}
cout << ret;
return ret;
}
vector<string> Easylast::list_dir( const string & path)
{
vector<string> list_dir_scan;
DIR* d = opendir(path.c_str());
struct dirent *ent = NULL;
while ((ent = readdir(d)) != NULL)
{
if (strcmp(ent->d_name, ".") != 0 &&
strcmp(ent->d_name, "..") != 0)
{
// cout << ent->d_name << endl;
list_dir_scan.push_back(ent->d_name);
}
}
return list_dir_scan;
}
bool Easylast::is_dir(string path)
{
DIR* d = opendir(path.c_str());
return !(d == NULL);
}
string Easylast::itos(const int & i)
{
ostringstream oss;
oss << i;
return oss.str();
}
QString Easylast::stoqs(const string & s)
{
return QString(s.c_str());
}
QString Easylast::itoqs(const int & i)
{
return stoqs(itos(i));
}
int Easylast::stoi(const string & i)
{
return atoi(i.c_str());
}
int Easylast::qstoi(const QString & i)
{
return atoi(i.toStdString().c_str());
}