void CClipboardMonitorDlg::OnDrawClipboard()
{
	CString str = PasteClipboardString();
	::SendMessage(m_nextWindowInChain, WM_DRAWCLIPBOARD, 0, 0);	

	ProcessString(str);
}
Exemplo n.º 2
0
HRESULT CMatlabEngine::Execute(LPCTSTR szCode)
{
	VARIANT vArgsTypeText[1];
	DISPPARAMS dpTypeText;
	BSTR bstrName=NULL;

	if (!m_bInitialized || !m_pMtlbDispApp)
		return m_hr=S_FALSE;

	ProcessString(szCode, bstrName);
	
	vArgsTypeText [0].vt = VT_BSTR;
	vArgsTypeText [0].bstrVal = bstrName;	
	
	dpTypeText.cArgs = 1;
	dpTypeText.cNamedArgs = 0;
	dpTypeText.rgvarg = vArgsTypeText;
		
	m_hr = m_pMtlbDispApp ->Invoke(m_dispid_Execute, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &dpTypeText, &m_vResult, &m_excep, &m_uArgErr);

	if (FAILED(m_hr))
		goto Exit;

// Cleaning memory...		
Exit:
	::SysFreeString(bstrName);

	return m_hr;
}
Exemplo n.º 3
0
void AuthenticatedSymmetricCipher::EncryptAndAuthenticate(byte *ciphertext, byte *mac, size_t macSize, const byte *iv, int ivLength, const byte *header, size_t headerLength, const byte *message, size_t messageLength)
{
	Resynchronize(iv, ivLength);
	SpecifyDataLengths(headerLength, messageLength);
	Update(header, headerLength);
	ProcessString(ciphertext, message, messageLength);
	TruncatedFinal(mac, macSize);
}
Exemplo n.º 4
0
bool AuthenticatedSymmetricCipher::DecryptAndVerify(byte *message, const byte *mac, size_t macLength, const byte *iv, int ivLength, const byte *header, size_t headerLength, const byte *ciphertext, size_t ciphertextLength)
{
	Resynchronize(iv, ivLength);
	SpecifyDataLengths(headerLength, ciphertextLength);
	Update(header, headerLength);
	ProcessString(message, ciphertext, ciphertextLength);
	return TruncatedVerify(mac, macLength);
}
Exemplo n.º 5
0
bool CSimpleProcessor::ProcessString(const Wtroka& s, const SDocumentAttribtes& attrs,
                                     yvector<TPair<Stroka,ymap<Stroka,Wtroka> > >& out_facts,
                                     yvector<TPair<int, int> >& facts_positions,
                                     ETypeOfDocument doctype)
{
    if(!ParserOptionsPtr.Get())
        ythrow yexception() << "Parser-params options are not initialized.";
    return ProcessString(s, attrs, out_facts, facts_positions, ParserOptionsPtr.Get(), doctype);
}
Exemplo n.º 6
0
HRESULT CMatlabEngine::PutString(LPCTSTR szName, LPCTSTR szString)
{
	BSTR bstrName=NULL;
	BSTR bstrString=NULL;
	UINT i;

	if (!m_bInitialized || !m_pMtlbDispApp)
		return S_FALSE;

	ProcessString(szName, bstrName);
	ProcessString(szString, bstrString);


	VARIANT vArgPutString[3];
	for (i = 0; i < 3; ++i)
		::VariantInit(&vArgPutString[i]);


	V_VT(&vArgPutString[0]) = VT_BSTR;
	V_BSTR(&vArgPutString[0]) = bstrString;
	V_VT(&vArgPutString[1]) = VT_BSTR;
	V_BSTR(&vArgPutString[1]) = m_bstrWorkspace;
	V_VT(&vArgPutString[2]) = VT_BSTR;
	V_BSTR(&vArgPutString[2]) = bstrName;


	DISPPARAMS dpPutString;
	dpPutString.cArgs = 3;
	dpPutString.cNamedArgs = 0;
	dpPutString.rgvarg = vArgPutString;

	m_hr = m_pMtlbDispApp ->Invoke(m_dispid_PutCharArray, IID_NULL,
		LOCALE_USER_DEFAULT, DISPATCH_METHOD, &dpPutString, NULL, &m_excep, &m_uArgErr);

	if (FAILED(m_hr))
		goto Exit;

Exit:
	::SysFreeString(bstrName);
	::SysFreeString(bstrString);

	return m_hr;
}
Exemplo n.º 7
0
bool TSimpleTextMiner::DoProcess(Wtroka& text, SDocumentAttribtes& docAttr, ETypeOfDocument& docType)
{
    try {
        return ProcessString(text, docAttr, docType);

    } catch (...) {
        (*ErrorStream) << Substitute("Error on document \"$0\" (processing):\n$1",
            docAttr.m_strUrl, CurrentExceptionMessage()) << Endl;
        return false;
    }
}
Exemplo n.º 8
0
void Log::OutputConsole( LogLevel level,const string &str )
{
	int ConsoleLogLevel = sConfig.GetIntDefault("Log.ConsoleLogLevel",LOGLEVEL_INFO);
	if (ConsoleLogLevel < LOGLEVEL_CRITICAL || ConsoleLogLevel > LOGLEVEL_DEBUG)
	{
		ConsoleLogLevel = LOGLEVEL_INFO;
	}
	if (ConsoleLogLevel >= level)
	{
		string outputMe = ProcessString(level,str,false);
		printMutex.Acquire();
		cout << outputMe << std::endl;
		printMutex.Release();
	}
}
Exemplo n.º 9
0
HRESULT CMatlabEngine::GetString(LPCTSTR szName, LPTSTR& szString)
{
	static TCHAR tzBuffer[512];
	BSTR bstrName=NULL;
	UINT i;
	std::vector<double> vSize;

	if (!m_bInitialized || !m_pMtlbDispApp)
		return S_FALSE;

	ProcessString(szName, bstrName);


	// preparing argumetns
	VARIANT vArgGetString[2];
	for (i = 0; i < 1; ++i)
		::VariantInit(&vArgGetString[i]);

	V_VT(&vArgGetString[0]) = VT_BSTR;
	V_BSTR(&vArgGetString[0]) = m_bstrWorkspace;
	V_VT(&vArgGetString[1]) = VT_BSTR;
	V_BSTR(&vArgGetString[1]) = bstrName;


	DISPPARAMS dpGetString;
	dpGetString.cArgs = 2;
	dpGetString.cNamedArgs = 0;
	dpGetString.rgvarg = vArgGetString;

	m_hr = m_pMtlbDispApp ->Invoke(m_dispid_GetCharArray, IID_NULL,
		LOCALE_USER_DEFAULT, DISPATCH_METHOD, &dpGetString, &m_vResult, &m_excep, &m_uArgErr);

	if (FAILED(m_hr))
		goto Exit;

	// process back to szString...
	{
		_bstr_t s(m_vResult);
		szString=new TCHAR[s.length()+1];
		_tcscpy( szString, (LPCTSTR)s);
	}

Exit:
	::SysFreeString(bstrName);

	return m_hr;

}
int main()
{
    char *in = "ABCDEF";
    char chSrc = 'A';
    char chDes = 'B';
    char *out = (char *)malloc(sizeof(char) * strlen(in));
    
    if(!ProcessString(in, chSrc, chDes, out)) {
        int i = 0;
        while(out[i] != '\0')
            printf("%c",out[i++]);
    } else
        printf("异常");
        
    return 0;
}
Exemplo n.º 11
0
void Log::OutputFile( LogLevel level,const string &str )
{
	int FileLogLevel = sConfig.GetIntDefault("Log.FileLogLevel",LOGLEVEL_WARNING);
	if (FileLogLevel < LOGLEVEL_CRITICAL || FileLogLevel > LOGLEVEL_DEBUG)
	{
		FileLogLevel = LOGLEVEL_WARNING;
	}
	if (FileLogLevel >= level)
	{
		string outputMe = ProcessString(level,str,true);
		if (LogFile.is_open() == true)
		{
			fileMutex.Acquire();
			LogFile << outputMe << std::endl;
			fileMutex.Release();
		}
	}
}
Exemplo n.º 12
0
HRESULT CMatlabEngine::GetMatrix( LPCTSTR szName,  UINT& nRows, UINT& nCols, std::vector<double>& vRealArray, std::vector<double>* pImgArray)
{
	if (!m_bInitialized || !m_pMtlbDispApp)
		return m_hr=S_FALSE;

	static TCHAR tzBuffer[512];
	std::vector<double> vSize;
	BSTR bstrName=NULL;

	ProcessString(szName, bstrName);

	// computing size of matrix
	_stprintf(tzBuffer, _T("%sSize=size(%s);"), szName, szName);
	m_hr = Execute(tzBuffer);
	if (FAILED(m_hr))
		goto Exit;

	_stprintf(tzBuffer, _T("%sSize"), szName);
	m_hr = GetMatrixKnownSize( tzBuffer, 1,2, vSize);
	if (FAILED(m_hr))
		goto Exit;

	nRows = vSize[0];
	nCols = vSize[1];

	// getting matrix...
	if (pImgArray)
		m_hr = GetMatrixKnownSize( szName, nRows,nCols, vRealArray, *pImgArray);
	else
		m_hr = GetMatrixKnownSize( szName, nRows,nCols, vRealArray);

	if (FAILED(m_hr))
		goto Exit;
	

Exit:
	::SysFreeString(bstrName);

	return m_hr;
}
Exemplo n.º 13
0
unsigned long TServer::ClientThread()
{
	SOCKET my_sock = _client_socket;
	
	char buff[20*1024];
	memset(buff, '\0', sizeof(buff));

	int bytes_recv = recv(my_sock,&buff[0],sizeof(buff),0);
	while( bytes_recv != SOCKET_ERROR)
	{
		ProcessString(buff, my_sock);

		memset(buff, '\0', sizeof(buff));
		bytes_recv = recv(my_sock,&buff[0],sizeof(buff),0);
	}
	// если мы здесь, то произошел выход из цикла по причине 
	// возращения функцией recv ошибки – соединение с клиентом разорвано
	users->Del(my_sock);
	nclients--; // уменьшаем счетчик активных клиентов
	users->Print();
	// закрываем сокет
	closesocket(my_sock);
	return 0;
};
Exemplo n.º 14
0
void CMatlabEngine::SetWorkspace(LPCTSTR szWorkspace)
{
	ProcessString( szWorkspace, m_bstrWorkspace);
}
Exemplo n.º 15
0
bool  XConfig::ReadFileData(XElement *curElement, int level, TSTR &lpTemp)
{
    while(*lpTemp)
    {
        if(*lpTemp == '}')
            return level != 0;

        if(*lpTemp == '{') //unnamed object, usually only happens at the start of the file, ignore
        {
            ++lpTemp;
            if(!ReadFileData(curElement, level+1, lpTemp))
                return false;
        }
        else if(*lpTemp != ' '   &&
                *lpTemp != L' ' &&
                *lpTemp != '\t'  &&
                *lpTemp != '\r'  &&
                *lpTemp != '\n'  &&
                *lpTemp != ',')
        {
            String strName;

            if(*lpTemp == '"')
                strName = ProcessString(lpTemp);
            else
            {
                TSTR lpDataStart = lpTemp;

                lpTemp = schr(lpTemp, ':');
                if(!lpTemp)
                    return false;

                *lpTemp = 0;
                strName = lpDataStart;
                *lpTemp = ':';

                strName.KillSpaces();
            }

            //---------------------------

            lpTemp = schr(lpTemp, ':');
            if(!lpTemp)
                return false;

            ++lpTemp;

            while( *lpTemp == ' '   ||
                   *lpTemp == L' ' ||
                   *lpTemp == '\t'  )
            {
                ++lpTemp;
            }

            //---------------------------

            if(*lpTemp == '{') //element
            {
                ++lpTemp;

                XElement *newElement = curElement->CreateElement(strName);
                if(!ReadFileData(newElement, level+1, lpTemp))
                    return false;
            }
            else //item
            {
                String data;

                if(*lpTemp == '"')
                    data = ProcessString(lpTemp);
                else
                {
                    TSTR lpDataStart = lpTemp;

                    lpTemp = schr(lpTemp, '\n');
                    if(!lpTemp)
                        return false;

                    if(lpTemp[-1] == '\r') --lpTemp;

                    if(lpTemp != lpDataStart)
                    {
                        TCHAR oldChar = *lpTemp;
                        *lpTemp = 0;
                        data = lpDataStart;
                        *lpTemp = oldChar;

                        data.KillSpaces();
                    }
                }

                lpTemp = schr(lpTemp, '\n');
                if(!lpTemp && curElement != RootElement)
                    return false;

                curElement->SubItems << new XDataItem(strName, data);
            }
        }

        ++lpTemp;
    }

    return (curElement == RootElement);
}
Exemplo n.º 16
0
BOOL LoadResources(LPCTSTR szFilename)
{
	FILE* pFile = NULL;
	if ( _tfopen_s( &pFile, szFilename, _T("rb") ) == 0 )
	{
		CStringA sID;
		for ( States nState = stFile ; nState != stError ; )
		{
			CStringA sLine;
			CHAR* res = fgets( sLine.GetBuffer( 4096 ), 4096, pFile );
			sLine.ReleaseBuffer();
			if ( ! res )
			{
				if ( nState != stFile )
					_tprintf( _T("Error: Unexpected end of file\n") );

				break;		// End of file
			}
			sLine.Trim( ", \t\r\n" );
			if ( sLine.IsEmpty() ||
				 sLine.GetAt( 0 ) == '/' ||
				 sLine.GetAt( 0 ) == '#' )
				continue;	// Skip empty line, comment and pragma

			switch ( nState )
			{
			case stFile:
				if ( sLine == "STRINGTABLE" )
					nState = stStringTable;
				else if ( sLine == "GUIDELINES DESIGNINFO" )
					nState = stGuidelines;
				else
				{
					int nPos = sLine.Find( " DIALOG" );		// DIALOG or DIALOGEX
					if ( nPos != -1 )
					{
						CStringA sID = sLine.SpanExcluding( " " );
						UINT nID;
						if ( ! g_oIDs.Lookup( sID, nID ) )
						{
							_tprintf( _T("Error: Unknown ID \"%hs\" inside DIALOG\n"), sID );
							return 2;
						}
						if ( g_oDialogs.Lookup( sID, nID ) )
						{
							_tprintf( _T("Error: Duplicate ID \"%hs\" inside DIALOG\n"), sID );
							return 2;
						}
						g_oDialogs.SetAt( sID, nID );
					}

					nPos = sLine.Find( " ICON " );
					if ( nPos != -1 )
					{
						CStringA sID = sLine.SpanExcluding( " " );
						UINT nID;
						if ( ! g_oIDs.Lookup( sID, nID ) )
						{
							_tprintf( _T("Error: Unknown ID \"%hs\" of ICON\n"), sID );
							return 2;
						}
						if ( g_oIcons.Lookup( sID, nID ) )
						{
							_tprintf( _T("Error: Duplicate ID \"%hs\" of ICON\n"), sID );
							return 2;
						}
						g_oIcons.SetAt( sID, nID );
					}

					nPos = sLine.Find( " HTML " );
					if ( nPos == -1 )
						nPos = sLine.Find( " GZIP " );
					if ( nPos != -1 )
					{
						CStringA sID = sLine.SpanExcluding( " " );
						UINT nID;
						if ( ! g_oIDs.Lookup( sID, nID ) )
						{
							_tprintf( _T("Error: Unknown ID \"%hs\" of HTML\n"), sID );
							return 2;
						}
						if ( g_oHtmls.Lookup( sID, nID ) )
						{
							_tprintf( _T("Error: Duplicate ID \"%hs\" of HTML\n"), sID );
							return 2;
						}
						g_oHtmls.SetAt( sID, nID );
					}

					nPos = sLine.Find( " BITMAP " );
					if ( nPos == -1 )
						nPos = sLine.Find( " JPEG " );
					if ( nPos == -1 )
						nPos = sLine.Find( " PNG " );
					if ( nPos != -1 )
					{
						CStringA sID = sLine.SpanExcluding( " " );
						UINT nID;
						if ( ! g_oIDs.Lookup( sID, nID ) )
						{
							_tprintf( _T("Error: Unknown ID \"%hs\" of BITMAP\n"), sID );
							return 2;
						}
						if ( g_oBitmaps.Lookup( sID, nID ) )
						{
							_tprintf( _T("Error: Duplicate ID \"%hs\" of BITMAP\n"), sID );
							return 2;
						}
						g_oBitmaps.SetAt( sID, nID );
					}
				}
				break;

			case stGuidelines:
				if ( sLine == "BEGIN" )
					nState = stGuidelinesContent;
				else
				{
					_tprintf( _T("Error: BEGIN not found after GUIDELINES DESIGNINFO\n") );
					return 2;
				}
				break;

			case stGuidelinesContent:
				if ( sLine == "END" )
					nState = stFile;
				else if ( sLine.Right( 6 ) == "DIALOG" )
				{
					nState = stGuidelinesDialog;
					CStringA sID = sLine.SpanExcluding( "," );
					UINT nID;
					if ( ! g_oIDs.Lookup( sID, nID ) )
					{
						_tprintf( _T("Error: Unknown dialog ID \"%hs\" inside GUIDELINES\n"), sID );
						return 2;
					}
					if ( g_oGuidelines.Lookup( sID, nID ) )
					{
						_tprintf( _T("Error: Duplicate dialog ID \"%hs\" inside GUIDELINES\n"), sID );
						return 2;
					}
					if ( ! g_oDialogs.Lookup( sID, nID ) )
					{
						_tprintf( _T("Error: Orphan dialog ID \"%hs\" inside GUIDELINES\n"), sID );
						return 2;
					}
					g_oGuidelines.SetAt( sID, nID );
				}
				else
				{
					_tprintf( _T("Error: Unknown line \"%hs\" inside GUIDELINES\n"), sLine );
					return 2;
				}
				break;

			case stGuidelinesDialog:
				if ( sLine == "END" )
					nState = stGuidelinesContent;
				break;

			case stStringTable:
				if ( sLine == "BEGIN" )
					nState = stContent;
				else
				{
					_tprintf( _T("Error: BEGIN not found after STRINGTABLE\n") );
					return 2;
				}
				break;

			case stContent:
				if ( sLine == "END" )
					nState = stFile;
				else
				{
					int nPos = sLine.FindOneOf( ", \t" );
					if ( nPos != -1 )
					{
						if ( ProcessString( sLine.Left( nPos ),
							sLine.Mid( nPos + 1 ).TrimLeft( ", \t" ) ) )
							nState = stContent;
						else
							nState = stError;
					}
					else
					{
						sID = sLine;
						nState =  stString;
					}
				}
				break;

			case stString:
				if ( ProcessString( sID, sLine ) )
					nState = stContent;
				else
					nState = stError;
				sID.Empty();
				break;
			}
		}

		fclose( pFile );
	}

	return TRUE;
}
Exemplo n.º 17
0
bool  XConfig::ReadFileData2(XElement *curElement, int level, TSTR &lpTemp, bool isJSON)
{
    while(*lpTemp)
    {
        if(*lpTemp == '}')
            return level != 0;

        if(*lpTemp == '{') //unnamed object, usually only happens at the start of the file, ignore
        {
            ++lpTemp;
            if(!ReadFileData2(curElement, level+1, lpTemp, true))
                return false;
        }
        else if(*lpTemp != ' '   &&
                *lpTemp != L' ' &&
                *lpTemp != '\t'  &&
                *lpTemp != '\r'  &&
                *lpTemp != '\n'  &&
                *lpTemp != ',')
        {
            String strName;

            if(*lpTemp == '"')
                strName = ProcessString(lpTemp);
            else
            {
                TSTR lpDataStart = lpTemp;

                lpTemp = schr(lpTemp, ':');
                if(!lpTemp)
                    return false;

                *lpTemp = 0;
                strName = lpDataStart;
                *lpTemp = ':';

                strName.KillSpaces();
            }

            //---------------------------

            lpTemp = schr(lpTemp, ':');
            if(!lpTemp)
                return false;

            ++lpTemp;

            while( *lpTemp == ' '   ||
                   *lpTemp == L' ' ||
                   *lpTemp == '\t'  )
            {
                ++lpTemp;
            }

            //---------------------------

            if(*lpTemp == '{') //element
            {
                ++lpTemp;

                XElement *newElement = curElement->CreateElement(strName);
                if (!ReadFileData2(newElement, level + 1, lpTemp, isJSON))
                    return false;
            }
            else //item
            {
                String data;

                if(*lpTemp == '"')
                    data = ProcessString(lpTemp);
                else
                {
                    TSTR lpDataStart = lpTemp;

                    if (!GetNextLine(lpTemp, isJSON))
                        return false;

                    if(lpTemp[-1] == '\r') --lpTemp;

                    if(lpTemp != lpDataStart)
                    {
                        TCHAR oldChar = *lpTemp;
                        *lpTemp = 0;
                        data = lpDataStart;
                        *lpTemp = oldChar;

                        data.KillSpaces();
                    }
                }

                if (!GetNextLine(lpTemp, isJSON) && curElement != RootElement)
                    return false;

                if (*lpTemp == '}')
                    lpTemp--;

                curElement->SubItems << new XDataItem(strName, data);
            }
        }

        // A ++lpTemp above can step off the end of the string causing
        // the condition on while to go a bit crazy.
        // Making sure we preserve the end of string.
        if (*lpTemp != 0)
        {
            ++lpTemp;
        }
    }

    return (curElement == RootElement);
}
Exemplo n.º 18
0
HRESULT CMatlabEngine::PutMatrix( LPCTSTR szName, const std::vector<double>& vArray, UINT nRows, UINT nCols)
{
	BSTR bstrName=NULL;

	if (!m_bInitialized || !m_pMtlbDispApp || (nRows*nCols > vArray.size()) )
		return m_hr=S_FALSE;

	ProcessString(szName, bstrName);

	SAFEARRAYBOUND realPartDims[2];
	realPartDims[0].lLbound = 0;     // Lower bound of the first dimension
	realPartDims[0].cElements = nRows;
	realPartDims[1].lLbound = 0;     // Lower bound of the second dimension
	realPartDims[1].cElements = nCols;


	SAFEARRAY *realPart = ::SafeArrayCreate(VT_R8, 2, realPartDims);

	long lIndex[2];
	double val;

	for (int i = 0; i < nRows; i++)
	{
		lIndex[0] = i;

		for (int j = 0; j < nCols; j++)
		{
			lIndex[1] = j;

			val=vArray[i*nCols+j];
			m_hr = ::SafeArrayPutElement(realPart, lIndex, &val);
			if (FAILED(m_hr))
				goto Exit;
		}
	}


	VARIANT vArgPutFullMatrix[4];
	for (int i = 0; i < 4; ++i)
		::VariantInit(&vArgPutFullMatrix[i]);


	V_VT(&vArgPutFullMatrix[0]) = VT_ARRAY | VT_R8;
	V_ARRAY(&vArgPutFullMatrix[0]) = NULL; // do set to NULL when not complex
	V_VT(&vArgPutFullMatrix[1]) = VT_ARRAY | VT_R8;
	V_ARRAY(&vArgPutFullMatrix[1])= realPart;
	V_VT(&vArgPutFullMatrix[2]) = VT_BSTR;
	V_BSTR(&vArgPutFullMatrix[2]) = m_bstrWorkspace;
	V_VT(&vArgPutFullMatrix[3]) = VT_BSTR;
	V_BSTR(&vArgPutFullMatrix[3]) = bstrName;


	DISPPARAMS dpPutFullMatrix;
	dpPutFullMatrix.cArgs = 4;
	dpPutFullMatrix.cNamedArgs = 0;
	dpPutFullMatrix.rgvarg = vArgPutFullMatrix;

	m_hr = m_pMtlbDispApp ->Invoke(m_dispid_PutFullMatrix, IID_NULL,
		LOCALE_USER_DEFAULT, DISPATCH_METHOD, &dpPutFullMatrix, NULL, &m_excep, &m_uArgErr);

	if (FAILED(m_hr))
		goto Exit;

Exit:
	::SysFreeString(bstrName);
	m_hr = ::SafeArrayDestroy(realPart);

	return m_hr;
}
Exemplo n.º 19
0
bool CSimpleProcessor::ProcessString(const Wtroka& s, const SDocumentAttribtes& attrs, ETypeOfDocument doctype)
{
    if(!ParserOptionsPtr.Get())
        ythrow yexception() << "Parser-params options are not initialized.";
    return ProcessString(s, attrs, ParserOptionsPtr, doctype);
}
Exemplo n.º 20
0
int main2(int argc, _TCHAR** argv)
{
  CoInitialize(0);
  {
    //string file = "F:\\svn.screenie\\root\\bin-release\\screenie.exe";
    g_hInstance = GetModuleHandle(0);

    argc --;
    argv ++;

    if(argc < 2)
    {
      return Usage();
    }

    // get the filename
    string file = argv[0];
    if(!PathFileExists(file.c_str()))
    {
      cout << "File not found: " << file << endl;
      return 1;
    }

    // parse the rest of the command line args
    argc --;
    argv ++;

    vector<Arg> args;

    Result res;

    for(int i = 0; i < argc; i ++)
    {
      string arg = argv[i];

      if(StringEquals(arg, "/xml"))
      {
        i ++;
        if(i >= argc)
        {
          cout << "/string command line argument is missing its operand." << endl;
          return 1;
        }
        // this will convert the xml file into a list of arguments.
        VersionXMLFile f;
        if(!(res = f.Read(argv[i])))
        {
          cout << res.str() << endl;
          return 1;
        }
        // merge the lists together.
        for(vector<Arg>::iterator it = f.args.begin(); it != f.args.end(); ++ it)
        {
          args.push_back(*it);
        }
      }
      else if(StringEquals(arg, "/string"))
      {
        i ++;
        if(i >= argc)
        {
          cout << "/string command line argument is missing its operand." << endl;
          return 1;
        }
        Arg temp;
        if(!(res = ParseNameValueString(argv[i], temp.name, temp.value)))
        {
          res.Prepend("/string command line argument invalid; ");
          cout << res.str() << endl;
          return 1;
        }
        temp.source = "/string command line argument";
        temp.type = Arg::STRING;
        args.push_back(temp);
      }
      else if(StringEquals(arg, "/delete"))
      {
        i ++;
        if(i >= argc)
        {
          cout << "/delete command line argument is missing its operand." << endl;
          return 1;
        }
        Arg temp;
        temp.source = "/delete command line argument";
        temp.type = Arg::DELETETYPE;
        temp.name = argv[i];
        args.push_back(temp);
      }
      else if(StringEquals(arg, "/fixed"))
      {
        i ++;
        if(i >= argc)
        {
          cout << "/fixed command line argument is missing its operand." << endl;
          return 1;
        }
        Arg temp;
        if(!(res = ParseNameValueString(argv[i], temp.name, temp.value)))
        {
          res.Prepend("/fixed command line argument invalid; ");
          cout << res.str() << endl;
          return 1;
        }
        temp.source = "/fixed command line argument";
        temp.type = Arg::FIXED;
        args.push_back(temp);
      }
      else
      {
        cout << "Unrecognized command line switch: " << arg << endl;
        return 1;
      }
    }

    // open version info.
    Version::VersionResource versionResource;

    if(!(res = LoadVersionResource(file, versionResource)))
    {
      res.Prepend(Format("Failed to read version info from %; ").qs(file).Str());
      cout << res.str() << endl;
      return 1;
    }

    // process the arguments sequentially.
    for(vector<Arg>::iterator it = args.begin(); it != args.end(); ++ it)
    {
      Arg& a(*it);
      switch(a.type)
      {
      case Arg::FIXED:
        if(!(res = ProcessFixed(a, versionResource)))
        {
          cout << res.str() << endl;
          return 1;
        }
        break;
      case Arg::DELETETYPE:
        ProcessDelete(a, versionResource);
        break;
      case Arg::STRING:
        if(!(res = ProcessString(a, versionResource)))
        {
          cout << res.str() << endl;
          return 1;
        }
        break;
      }
    }

    // write it back out in memory
    BinaryMemory memFinal;
    if(!(res = versionResource.Write(memFinal)))
    {
      res.Prepend(Format("Failed to generate version info; ").Str());
      cout << res.str() << endl;
      return 1;
    }

    // update the resource.
    HANDLE hResource = BeginUpdateResource(file.c_str(), FALSE);
    if(NULL == hResource)
    {
      cout << Format("Error updating resources for %. BeginUpdateResource returned %").qs(file).gle().Str() << endl;
      return 1;
    }

    if(0 == UpdateResource(hResource, RT_VERSION, MAKEINTRESOURCE(VS_VERSION_INFO), versionResource.GetLanguage(), (PVOID)/*const_cast*/memFinal.GetBuffer(), (DWORD)memFinal.GetSize()))
    {
      cout << Format("Error updating resources for %. UpdateResource returned %").qs(file).gle().Str() << endl;
      return 1;
    }

    if(0 == EndUpdateResource(hResource, FALSE))
    {
      cout << Format("Error updating resources for %. EndUpdateResource returned %").qs(file).gle().Str() << endl;
      return 1;
    }

    cout << "Version updated successfully." << endl;
  }
  CoUninitialize();
	return 0;
}
Exemplo n.º 21
0
	IRCMessage::IRCMessage(std::string& msgStr) : Origin("unknown")
	{
		ProcessString(msgStr);
	}
Exemplo n.º 22
0
HRESULT CMatlabEngine::GetMatrixKnownSize( LPCTSTR szName,  UINT nRows, UINT nCols, std::vector<double>& vRealArray, std::vector<double>& vImgArray)
{
	if (!m_bInitialized || !m_pMtlbDispApp)
		return m_hr=S_FALSE;

	BSTR bstrName=NULL;
	UINT i,j;
	SAFEARRAY *realPart=NULL;
	SAFEARRAY *imgPart=NULL;
	double*		pRealDummy = NULL ;						// for access to the data
	double*		pImgDummy = NULL ;						// for access to the data
	VARIANT vArgGetFullMatrix[4];


	// Preparing name
	ProcessString(szName, bstrName);

	SAFEARRAYBOUND realPartDims[2];
	realPartDims[0].lLbound = 1;     // Lower bound of the first dimension
	realPartDims[0].cElements = nRows;
	realPartDims[1].lLbound = 1;     // Lower bound of the second dimension
	realPartDims[1].cElements = nCols;
	realPart=::SafeArrayCreate(VT_R8, 2, realPartDims);

	SAFEARRAYBOUND imgPartDims[2];
	imgPartDims[0].lLbound = 1;     // Lower bound of the first dimension
	imgPartDims[0].cElements = nRows;
	imgPartDims[1].lLbound = 1;     // Lower bound of the second dimension
	imgPartDims[1].cElements = nCols;
	imgPart=::SafeArrayCreate(VT_R8, 2, imgPartDims);


	//loading data...
	for (i = 0; i < 4; ++i)
		::VariantInit(&vArgGetFullMatrix[i]);

	V_VT(&vArgGetFullMatrix[0]) = VT_ARRAY | VT_R8 | VT_BYREF;
	vArgGetFullMatrix[0].pparray = &imgPart; // do set to NULL when not complex
	V_VT(&vArgGetFullMatrix[1]) = VT_ARRAY | VT_R8 | VT_BYREF;
	vArgGetFullMatrix[1].pparray = &realPart;
	V_VT(&vArgGetFullMatrix[2]) = VT_BSTR;
	V_BSTR(&vArgGetFullMatrix[2]) = m_bstrWorkspace;
	V_VT(&vArgGetFullMatrix[3]) = VT_BSTR;
	V_BSTR(&vArgGetFullMatrix[3]) = bstrName;

	DISPPARAMS dpGetFullMatrix;
	dpGetFullMatrix.cArgs = 4;
	dpGetFullMatrix.cNamedArgs = 0;
	dpGetFullMatrix.rgvarg = vArgGetFullMatrix;

	m_hr = m_pMtlbDispApp ->Invoke(m_dispid_GetFullMatrix, IID_NULL,
		LOCALE_USER_DEFAULT, DISPATCH_METHOD, &dpGetFullMatrix, NULL, &m_excep, &m_uArgErr);

	if (FAILED(m_hr))
		goto Exit;


	if (::SafeArrayGetDim(realPart) != 2)
	{
		m_hr = S_FALSE;
		goto Exit;
	}

	vRealArray.resize(nRows*nCols);
	vImgArray.resize(nRows*nCols);

	SafeArrayAccessData(realPart, (void HUGEP **)(&pRealDummy)) ;	// dummy now points to the data
	SafeArrayAccessData(imgPart, (void HUGEP **)(&pImgDummy)) ;	// dummy now points to the data
	
	// copy each element across into the matrix to return
	for (i = 0; i < nRows ; ++i)
	{
		for (j = 0; j < nCols ; ++j)
		{
			vRealArray[i*nCols+j]=pRealDummy[i*nCols+j] ;
			vImgArray[i*nCols+j]=pImgDummy[i*nCols+j] ;
		}
	}
	pRealDummy = NULL ;									// no longer valid
	pImgDummy = NULL ;									// no longer valid

Exit:
	::SysFreeString(bstrName);
	::SafeArrayUnaccessData(realPart) ;					// release the safe array data pointer
	::SafeArrayUnaccessData(imgPart) ;					// release the safe array data pointer
	::SafeArrayDestroy(realPart);
	::SafeArrayDestroy(imgPart);

	return m_hr;
}