Repository navigation
Expand file tree
/
Copy pathtoolkit.cpp
More file actions
146 lines (128 loc) · 2.77 KB
/
Copy pathtoolkit.cpp
File metadata and controls
146 lines (128 loc) · 2.77 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
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#include "stdafx.h"
#include "toolkit.h"
#include <string.h>
#include <time.h>
#if defined _WIN32 || WIN32 || _WINDOWS
#include <direct.h>
#define MKDIR(X) _mkdir((X));
#else
#include <sys/stat.h>
#define MKDIR(X) mkdir((X),S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
#endif // defined
void makedirs(const char* dir)
{
if (nullptr == dir)
return;
int len = strlen(dir);
char * p = new char[len+1];
strcpy(p,dir);
for (int i=0;i<len;++i)
{
char ch = p[i];
if ('\\' == ch ||'/' == ch)
{
p[i] = '\0';
MKDIR(p);
p[i] = ch;
}
}
delete[] p;
}
char* GetSetFromString(const char* szString, const char* seps, vector<char*>& vct, set<char*>& st, int modify, set<string>& st2)
{
vct.clear();
st.clear();
if(nullptr == szString
||nullptr == seps)
return nullptr;
if(strlen(szString)==0
||strlen(seps)==0)
return nullptr;
size_t len = strlen(szString)+1;
char* buf = new char[len];
strncpy(buf,szString,len);
char* token = strtok(buf, seps);
while(token)
{
if (strlen(token)>0)
{
if (modify > 0)
st2.insert(token);
else if (modify<0)
st2.erase(token);
vct.push_back(token);
st.insert(token);
}
token = strtok( nullptr, seps);
}
return buf;
}
void GetExchangeTime(char* TradingDay, char* ActionDay, char* UpdateTime, int* _TradingDay, int* _ActionDay, int* _UpdateTime)
{
// TradingDay处理
*_TradingDay = atoi(TradingDay);
// UpdateTime处理
int HH = atoi(&UpdateTime[0]);
int mm = atoi(&UpdateTime[3]);
int ss = atoi(&UpdateTime[6]);
*_UpdateTime = HH * 10000 + mm * 100 + ss;
if (*_UpdateTime == 0)
{
time_t now = time(0);
struct tm *ptmNow = localtime(&now);
int datetime = ptmNow->tm_hour * 10000 + ptmNow->tm_min * 100 + ptmNow->tm_sec;
if (datetime > 1500 && datetime < 234500)
*_UpdateTime = datetime;
}
// ActionDay处理
if ((ActionDay != nullptr) && (strlen(ActionDay) == 8))
{
*_ActionDay = atoi(ActionDay);
}
else
{
time_t now = time(0);
struct tm *ptmNow = localtime(&now);
if (HH >= 23)
{
if (ptmNow->tm_hour<1)
{
now -= 86400;
ptmNow = localtime(&now);
}
}
else if (HH<1)
{
if (ptmNow->tm_hour >= 23)
{
now += 86400;
ptmNow = localtime(&now);
}
}
*_ActionDay = (1900 + ptmNow->tm_year) * 10000 + (1 + ptmNow->tm_mon) * 100 + ptmNow->tm_mday;
}
}
void GetOnFrontDisconnectedMsg(int ErrorId, char* ErrorMsg)
{
switch (ErrorId)
{
case 0x1001:
strcpy(ErrorMsg,"0x1001 4097 网络读失败");
break;
case 0x1002:
strcpy(ErrorMsg,"0x1002 4098 网络写失败");
break;
case 0x2001:
strcpy(ErrorMsg,"0x2001 8193 接收心跳超时");
break;
case 0x2002:
strcpy(ErrorMsg,"0x2002 8194 发送心跳失败");
break;
case 0x2003:
strcpy(ErrorMsg,"0x2003 8195 收到错误报文");
break;
default:
sprintf(ErrorMsg, "%x %d 未知错误", ErrorId, ErrorId);
break;
}
}