Код написанный в Visual C++ 10 не переносится в QtCreator под MinGW, wtf???
Код:
#include <stdio.h>
#include <string>
#include <vector>
int mprintnf(char** dst, std::string Types, ...)
{
char* beginParamList = ((char*)&Types) + sizeof(Types);
char* currentParam = beginParamList;
int totalSize = 0;
int sizeNextParam = 0;
int strPos = 0;
int strLen = Types.length();
int strLenSubstr = 0;
int strBeginPosSubstr = 0;
std::vector<std::string> parsedTypes;
while(strPos != strLen)
{
if(strPos == strLen - 1) strLenSubstr++;
if(Types[strPos] == '%' || strPos == strLen - 1)
{
if(strLenSubstr > 0)
{
std::string strSubstr = Types.substr(strBeginPosSubstr, strLenSubstr);
parsedTypes.push_back(strSubstr);
strLenSubstr = 0;
strBeginPosSubstr = strPos;
if(strSubstr == "%d")
{
totalSize += sizeof(int);
currentParam += sizeof(int);
}
else if(strSubstr == "%ns")
{
sizeNextParam = *((int*)currentParam);
totalSize += sizeof(int);
currentParam += sizeof(int);
}
else if(strSubstr == "%ch")
{
totalSize += sizeNextParam;
currentParam += sizeof(char*);
}
else if(strSubstr == "%ts")
{
totalSize += sizeof(int);
}
}
}
strPos++;
strLenSubstr++;
}
*dst = new char[totalSize];
currentParam = beginParamList;
int offsetInDst = 0;
typedef std::vector<std::string>::iterator parsedTypesIterator;
for(parsedTypesIterator i = parsedTypes.begin(); i != parsedTypes.end(); ++i)
{
int cpySize = 0;
int offsetNextParam = 0;
char* srcCpy = NULL;
if(*i == "%d")
{
offsetNextParam = sizeof(int);
cpySize = sizeof(int);
srcCpy = currentParam;
}
else if(*i == "%ns")
{
sizeNextParam = *((int*)currentParam);
offsetNextParam += sizeof(int);
cpySize = sizeof(int);
srcCpy = (char*)&sizeNextParam;
}
else if(*i == "%ch")
{
offsetNextParam += sizeof(char*);
cpySize = sizeNextParam;
srcCpy = *((char**)currentParam);
}
else if(*i == "%ts")
{
cpySize = sizeof(int);
srcCpy = (char*)&totalSize;
}
if(cpySize != 0)
{
memcpy((void*)((*dst) + offsetInDst), (void*)srcCpy, cpySize);
offsetInDst += cpySize;
}
//////////////////////////////////////////////////////////////////////////
for(int i = 0; i < totalSize; i++)
{
int out = *((*dst) + i);
printf("%d ", out);
}
printf("\n");
//////////////////////////////////////////////////////////////////////////
currentParam += offsetNextParam;
}
return totalSize;
}
int mscannf(char* scr, std::string Types, ...)
{
char* beginParamList = ((char*)&Types) + sizeof(Types);
char* currentParam = beginParamList;
int sizeNextParam = 0;
int strPos = 0;
int strLen = Types.length();
int strLenSubstr = 0;
int strBeginPosSubstr = 0;
int offsetScr = 0;
int totalSize = 0;
while(strPos != strLen)
{
if(strPos == strLen - 1) strLenSubstr++;
if(Types[strPos] == '%' || strPos == strLen - 1)
{
if(strLenSubstr > 0)
{
std::string strSubstr = Types.substr(strBeginPosSubstr, strLenSubstr);
strLenSubstr = 0;
strBeginPosSubstr = strPos;
if(strSubstr == "%d")
{
memcpy((void*)(*((int**)currentParam)), (void*)(scr + offsetScr), sizeof(int));
offsetScr += sizeof(int);
currentParam += sizeof(int*);
}
else if(strSubstr == "%ns")
{
memcpy((void*)(*((int**)currentParam)), (void*)(scr + offsetScr), sizeof(int));
offsetScr += sizeof(int);
currentParam += sizeof(int*);
}
else if(strSubstr == "%ch")
{
*(*(char***)currentParam) = scr + offsetScr;
offsetScr += sizeNextParam;
currentParam += sizeof(char*);
}
else if(strSubstr == "%ts")
{
memcpy((void*)(*((int**)currentParam)), (void*)(scr + offsetScr), sizeof(int));
totalSize = *((int*)(scr + offsetScr));
offsetScr += sizeof(int);
currentParam += sizeof(int*);
}
}
}
strPos++;
strLenSubstr++;
}
return totalSize;
}
int main(int argc, char* argv[])
{
char* dst = NULL;
mprintnf(&dst, "%ts");
int size = 0;
mscannf(dst, "%ts", &size);
return 0;
}
#include <string>
#include <vector>
int mprintnf(char** dst, std::string Types, ...)
{
char* beginParamList = ((char*)&Types) + sizeof(Types);
char* currentParam = beginParamList;
int totalSize = 0;
int sizeNextParam = 0;
int strPos = 0;
int strLen = Types.length();
int strLenSubstr = 0;
int strBeginPosSubstr = 0;
std::vector<std::string> parsedTypes;
while(strPos != strLen)
{
if(strPos == strLen - 1) strLenSubstr++;
if(Types[strPos] == '%' || strPos == strLen - 1)
{
if(strLenSubstr > 0)
{
std::string strSubstr = Types.substr(strBeginPosSubstr, strLenSubstr);
parsedTypes.push_back(strSubstr);
strLenSubstr = 0;
strBeginPosSubstr = strPos;
if(strSubstr == "%d")
{
totalSize += sizeof(int);
currentParam += sizeof(int);
}
else if(strSubstr == "%ns")
{
sizeNextParam = *((int*)currentParam);
totalSize += sizeof(int);
currentParam += sizeof(int);
}
else if(strSubstr == "%ch")
{
totalSize += sizeNextParam;
currentParam += sizeof(char*);
}
else if(strSubstr == "%ts")
{
totalSize += sizeof(int);
}
}
}
strPos++;
strLenSubstr++;
}
*dst = new char[totalSize];
currentParam = beginParamList;
int offsetInDst = 0;
typedef std::vector<std::string>::iterator parsedTypesIterator;
for(parsedTypesIterator i = parsedTypes.begin(); i != parsedTypes.end(); ++i)
{
int cpySize = 0;
int offsetNextParam = 0;
char* srcCpy = NULL;
if(*i == "%d")
{
offsetNextParam = sizeof(int);
cpySize = sizeof(int);
srcCpy = currentParam;
}
else if(*i == "%ns")
{
sizeNextParam = *((int*)currentParam);
offsetNextParam += sizeof(int);
cpySize = sizeof(int);
srcCpy = (char*)&sizeNextParam;
}
else if(*i == "%ch")
{
offsetNextParam += sizeof(char*);
cpySize = sizeNextParam;
srcCpy = *((char**)currentParam);
}
else if(*i == "%ts")
{
cpySize = sizeof(int);
srcCpy = (char*)&totalSize;
}
if(cpySize != 0)
{
memcpy((void*)((*dst) + offsetInDst), (void*)srcCpy, cpySize);
offsetInDst += cpySize;
}
//////////////////////////////////////////////////////////////////////////
for(int i = 0; i < totalSize; i++)
{
int out = *((*dst) + i);
printf("%d ", out);
}
printf("\n");
//////////////////////////////////////////////////////////////////////////
currentParam += offsetNextParam;
}
return totalSize;
}
int mscannf(char* scr, std::string Types, ...)
{
char* beginParamList = ((char*)&Types) + sizeof(Types);
char* currentParam = beginParamList;
int sizeNextParam = 0;
int strPos = 0;
int strLen = Types.length();
int strLenSubstr = 0;
int strBeginPosSubstr = 0;
int offsetScr = 0;
int totalSize = 0;
while(strPos != strLen)
{
if(strPos == strLen - 1) strLenSubstr++;
if(Types[strPos] == '%' || strPos == strLen - 1)
{
if(strLenSubstr > 0)
{
std::string strSubstr = Types.substr(strBeginPosSubstr, strLenSubstr);
strLenSubstr = 0;
strBeginPosSubstr = strPos;
if(strSubstr == "%d")
{
memcpy((void*)(*((int**)currentParam)), (void*)(scr + offsetScr), sizeof(int));
offsetScr += sizeof(int);
currentParam += sizeof(int*);
}
else if(strSubstr == "%ns")
{
memcpy((void*)(*((int**)currentParam)), (void*)(scr + offsetScr), sizeof(int));
offsetScr += sizeof(int);
currentParam += sizeof(int*);
}
else if(strSubstr == "%ch")
{
*(*(char***)currentParam) = scr + offsetScr;
offsetScr += sizeNextParam;
currentParam += sizeof(char*);
}
else if(strSubstr == "%ts")
{
memcpy((void*)(*((int**)currentParam)), (void*)(scr + offsetScr), sizeof(int));
totalSize = *((int*)(scr + offsetScr));
offsetScr += sizeof(int);
currentParam += sizeof(int*);
}
}
}
strPos++;
strLenSubstr++;
}
return totalSize;
}
int main(int argc, char* argv[])
{
char* dst = NULL;
mprintnf(&dst, "%ts");
int size = 0;
mscannf(dst, "%ts", &size);
return 0;
}