-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathCKeyMap.cpp
More file actions
97 lines (87 loc) · 2.22 KB
/
CKeyMap.cpp
File metadata and controls
97 lines (87 loc) · 2.22 KB
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
#include "CKeyMap.h"
#include <iostream>
#include <fstream>
#include <sstream>
#include<boost/algorithm/string.hpp>
using namespace std;
using namespace boost;
CKeyMap::CKeyMap()
{
}
bool CKeyMap::LoadFile(std::string config_file)
{
mKeys.clear();
mRandomVids.clear();
mKeyedVids.clear();
//fprintf(stderr, "Opening config file %s\n", config_file.c_str());
ifstream file(config_file.c_str(), ios::in);
if (!file.is_open())
{
printf("Can't find config file.\n");
return(false);
}
string line;
int i = 1;
while (getline(file, line))
{
boost::algorithm::replace_last(line, "\t", " ");
boost::algorithm::replace_all(line, "\t", "");
boost::algorithm::replace_all(line, "\r", "");
boost::algorithm::replace_all(line, "\n", "");
const char c[2] = ":";
char* tok;
tok = strtok((char*)line.c_str(), c);
if (tok != NULL)
{
CKeyCommand cmd;
cmd.mKey = tok;
if (cmd.mKey == "random")
{
tok = strtok(NULL, c);
if (tok != NULL)
{
mRandomVids.push_back(std::string(tok));
}
}
else
{
tok = strtok(NULL, c);
if (tok != NULL)
{
cmd.mCommand = tok;
tok = strtok(NULL, c);
if (tok != NULL)
{
cmd.mArgument1 = tok;
tok = strtok(NULL, c);
if (tok != NULL)
{
cmd.mArgument2 = tok;
}
mKeys.push_back(cmd);
if (cmd.mCommand == "mp4")
{
mKeyedVids.push_back(cmd.mKey);
}
}
}
}
}
++i;
}
file.close();
return(true);
}
CKeyCommand CKeyMap::GetKey(std::string key)
{
CKeyCommand cmd;
int i;
for (i = 0; i < mKeys.size(); i++)
{
if (key == mKeys[i].mKey)
{
return(mKeys[i]);
}
}
return(cmd);
}