// replay.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "LogParser.h" #include "SAXContentHandlerImpl.h" #include #include "options.h" const char * optv[] = { "r:resultfile ", "d:msgdelay ", "w:wait ", "s:startdelay ", "p:path " }; void convertTCharToChar(const TCHAR * source, char ** dest) { #ifdef UNICODE std::wstring wstr(source); int size_needed = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), NULL, 0, NULL, NULL); std::string strTo( size_needed, 0 ); WideCharToMultiByte (CP_UTF8, 0, &wstr[0], (int)wstr.size(), &strTo[0], size_needed, NULL, NULL); *dest = new char[strTo.size()+1]; memcpy((void*)*dest, strTo.c_str(), strTo.size()+1); #else std::string str(source); *dest = new char[strTo.size()+1]; memcpy(*dest, strTo.c_str(), strTo.size()+1); #endif } void convertCharToTChar(const char * source, TCHAR ** dest) { #ifdef UNICODE std::string str(source); int size_needed = MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), NULL, 0); std::wstring wstrTo( size_needed, 0 ); MultiByteToWideChar (CP_UTF8, 0, &str[0], (int)str.size(), &wstrTo[0], size_needed); *dest = new TCHAR[wstrTo.size()+1]; memcpy((void*)*dest, wstrTo.c_str(), (wstrTo.size()+1)*sizeof(TCHAR)); #else std::string str(source); *dest = new char[strTo.size()+1]; memcpy(*dest, strTo.c_str(), strTo.size()+1); #endif } int _tmain(int argc, _TCHAR* argv[]) { if( argc < 3 ) { std::wcout << L"Usage: " << argv[0] << L" [-r ] [-d ] [-w ] [-p ] [-s ]" << std::endl; return 1; } int optchar = 0; const char * optarg; // set default values TCHAR * resultfile = NULL; int msgdelay = 0; int startdelay = 5000; int wait = 1; TCHAR * workingPath = NULL; int argc_char = argc-2; char ** argv_char = new char*[argc_char]; // convert argv to char*[] convertTCharToChar(argv[0], &argv_char[0]); for( int i=3; isetWorkingPath(workingPath); pXMLReader->putContentHandler(parser); hr = pXMLReader->parseURL(replayfile); if( hr!=S_OK ) { std::wcout << L"failure parsing XML file" << std::endl; return 1; } pXMLReader->Release(); std::wcout << L"================================================" << std::endl; std::wcout << L"replay completed" << std::endl; if( resultfile!=NULL ) { results.write(resultfile); std::wcout << L"results written to " << resultfile << std::endl; } } CoUninitialize(); if( wait!=0 ) { std::wcout << L"press enter to exit ..."; getchar(); } delete resultfile; return 0; }