-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.cpp
229 lines (195 loc) · 4.19 KB
/
utils.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#include "utils.h"
#include <iostream>
#include <windows.h>
using namespace std;
#define stop __asm nop
void log( const wstring &msg )
{
char buff1[260];
CharToOem(msg.c_str(), (LPSTR)buff1);
//SetConsoleOutputCP(1251);
printf(buff1);
printf("\n");
OutputDebugString(msg.c_str());
OutputDebugString( L"\n" );
stop
}
void log( const string &msg )
{
cout<<msg<<endl;
OutputDebugStringW((LPCWSTR)msg.c_str());
OutputDebugString( (LPCWSTR)"\n" );
stop
}
wstring extractFileName( const wstring &fullPath, bool extension )
{
int first = 0, last = (int)fullPath.length() - 1;
for( int i = last; i >= 0; --i )
{
if( fullPath[i] == '.' )
{
last = i;
}
else if( fullPath[i] == '\\' || fullPath[i] == '/' )
{
first = i + 1;
break;
}
}
if( extension )
return fullPath.substr( first, fullPath.length() - first );
else
return fullPath.substr( first, last - first );
}
string extractFileName( const string &fullPath, bool extension )
{
int first = 0, last = (int)fullPath.length() - 1;
for( int i = last; i >= 0; --i )
{
if( fullPath[i] == '.' )
{
last = i;
}
else if( fullPath[i] == '\\' || fullPath[i] == '/' )
{
first = i + 1;
break;
}
}
if( extension )
return fullPath.substr( first, fullPath.length() - first );
else
return fullPath.substr( first, last - first );
}
string extractFilePath( const string &fullPath )
{
int first = 0;
int last = (int)fullPath.length() - 1;
for( int i = last; i >= 0; --i )
{
if( fullPath[i] == '\\' || fullPath[i] == '/' )
{
last = i;
break;
}
}
return fullPath.substr( first, last );
}
/* wchar_t to char */
char* wtoc(const wchar_t* w, size_t max)
{
char* c = new char[max];
wcstombs(c,w,max);
return c;
}
/* char to wchar_t */
wchar_t* ctow(const char* c, size_t max)
{
wchar_t* w = new wchar_t[max];
mbstowcs(w,c,max);
return w;
}
void removeGate( string &s )
{
if( s.length() == 0 ) return;
if( s[0] == '#' ) s = s.substr( 1, s.length() - 1 );
}
bool parseString( char *s, unsigned int &pos, string &token )
{
token = "";
token.reserve( 16 );
s += pos;
// End of string?
if( *s == 0x0 ) return false;
// Skip whitespaces
while( *s != 0x0 )
{
if (strchr(" \t\n\r", *s) == 0x0) break;
++s; ++pos;
}
// End of string?
if( *s == 0x0 ) return false;
// Copy token
while (*s != 0x0)
{
if (strchr(" \t\n\r", *s) != 0x0) break;
token += *s++; ++pos;
}
return true;
}
bool parseFloat( char *s, unsigned int &pos, float &value )
{
string token;
if( !parseString( s, pos, token ) ) return false;
value = (float)atof( token.c_str() );
return true;
}
bool parseUInt( char *s, unsigned int &pos, unsigned int &value )
{
string token;
if( !parseString( s, pos, token ) ) return false;
value = (unsigned int)atoi( token.c_str() );
return true;
}
//Matrix4f makeMatrix4f( float *floatArray16, bool y_up )
//{
//
// Matrix4f mat( floatArray16 );
// mat = mat.transposed();
//
// // Flip matrix if necessary
// if( !y_up )
// {
// // Swap y/z rows
// swap( mat.c[0][1], mat.c[0][2] );
// swap( mat.c[1][1], mat.c[1][2] );
// swap( mat.c[2][1], mat.c[2][2] );
// swap( mat.c[3][1], mat.c[3][2] );
//
// // Swap y/z columns
// swap( mat.c[1][0], mat.c[2][0] );
// swap( mat.c[1][1], mat.c[2][1] );
// swap( mat.c[1][2], mat.c[2][2] );
// swap( mat.c[1][3], mat.c[2][3] );
//
// // Invert z-axis to make system right-handed again
// // (The swapping above results in a left-handed system)
// mat.c[0][2] *= -1;
// mat.c[1][2] *= -1;
// mat.c[3][2] *= -1;
// mat.c[2][0] *= -1;
// mat.c[2][1] *= -1;
// mat.c[2][3] *= -1;
// }
//
// return mat;
//}
int StrCompare(char* a, char* b)
{
while (1)
{
if (*a==0) return 5; // 5 åñëè ðàâíû è ïåðâàÿ ñòðîêà çàêîí÷èëàñü
if (*b==0) return 7; // 7 åñëè ðàâíû è âòîðàÿ ñòðîêà çàêîí÷èëàñü
if (*a!=*b)
{
// 0 åñëè ñòðîêè íå ðàâíû
if ( ((*a)>='a')&&((*a)<='z')&&(*a!=((*b)+('a'-'A'))) ||
((*a)>='A')&&((*a)<='Z')&&(*a!=((*b)-('a'-'A'))) ) return 0;
}
a++; b++;
}
}
bool StrFind(char* a, char* b)
{
int i,cnt;
char *tmp;
if (strlen(a)<strlen(b));
else {tmp=a;a=b;b=tmp; };
i=strlen(b)-strlen(a);
for (cnt=0;cnt<=i;cnt++)
{
if (StrCompare(a,b)>0) return true; //ñîäåðæèò
b++;
}
return false; // íå ñîäåðæèò
}