Exemplo n.º 1
0
/* Numeric types are directly converted. Strings may convert -- see strtoll. Booleans fail. */
struct Error ValueToInteger(const struct Value &v, int64_t &out) {
    struct Error e = {true};
    switch(v.type) {
    case Value::Null:
        e.succeeded = false;
        e.error = "Cannot convert null to int";
        break;
    case Value::Boolean:
        e.succeeded = false;
        e.error = "Cannot convert bool to int";
        break;
    case Value::Integer:
        out = v.value.integer;
        break;
    case Value::Floating:
        out = (int64_t)v.value.floating;
        break;
    case Value::String:
        if(!StrToInt64(v.value.string, &out)) {
            e.succeeded = false;
            e.error = std::string("Cannot convert string ``") + v.value.string + "'' to int";
        }
        break;
    }
    return e;
}
void WXMSearchReplaceDialog::WxButtonCountClick(wxCommandEvent& event)
{
	ResetMessage();

	if (g_active_wxmedit == nullptr)
		return;

	int count = 0;
	wxString text;
	m_FindText->GetText(text, true);

	if(text.Len()>0)
	{
		m_RecentFindText->AddItemToHistory(text);

		wxInt64 from = 0, to = 0;
		wxFileOffset rangeFrom = -1, rangeTo = -1;
		if(WxCheckBoxSearchInSelection->IsChecked())
		{
			if(!StrToInt64(WxEditFrom->GetValue(), from))
			{
				ShowMessage(_("The value of 'From' is incorrect."), SMT_WARNING);
				return;
			}
			if(!StrToInt64(WxEditTo->GetValue(), to))
			{
				ShowMessage(_("The value of 'To' is incorrect."), SMT_WARNING);
				return;
			}

			rangeTo = to;
			rangeFrom = from;
		}

		wxm::WXMSearcher* searcher = g_active_wxmedit->Searcher(WxCheckBoxFindHex->GetValue(), WxCheckBoxRegex->GetValue());
		searcher->SetOption(WxCheckBoxCaseSensitive->GetValue(), WxCheckBoxWholeWord->GetValue());

		count = searcher->FindAll(text, false, nullptr, nullptr, rangeFrom, rangeTo);
	}

	if(count >= 0)
	{
		wxString msg;
		msg.Printf(_("'%s' was found %d times."), text.c_str(), count);
		ShowMessage(msg, SMT_NOTICE);
	}
}
Exemplo n.º 3
0
/*************************************
 * ToIn64
 *************************************/
SHVInt64Val SHVStringUTF8C::ToInt64(SHVChar** endChar) const
{
SHVChar* charBuf = Buffer;
	if (IsNull())
		return 0;
	if (endChar == NULL)
		endChar = &charBuf;
	return StrToInt64(Buffer,endChar,10);
}
Exemplo n.º 4
0
__int64 __fastcall TSrvResponse::ReadInt(TSrvResponseValID ID, __int64 DefVal)
{
	UnicodeString val = this->Read(ID);
	if (val.IsEmpty()) return DefVal;

	try {
		return StrToInt64(val);
	}
	catch (EConvertError& e) {
		throw ESrvResponseError(UnicodeString(L"Invalid ") + ID.FullName + " value. "
			+ e.Message);
	}
}
Exemplo n.º 5
0
bool ShouldConsensusHashBlock(int block) {
    if (msc_debug_consensus_hash_every_block) {
        return true;
    }

    if (!mapArgs.count("-omnishowblockconsensushash")) {
        return false;
    }

    const std::vector<std::string>& vecBlocks = mapMultiArgs["-omnishowblockconsensushash"];
    for (std::vector<std::string>::const_iterator it = vecBlocks.begin(); it != vecBlocks.end(); ++it) {
        int64_t paramBlock = StrToInt64(*it, false);
        if (paramBlock < 1) continue; // ignore non numeric values
        if (paramBlock == block) {
            return true;
        }
    }

    return false;
}
Exemplo n.º 6
0
//---------------------------------------------------------------------------
void __fastcall TAutoSizeForm::FormClose(TObject *Sender,
      TCloseAction &Action)
{
  try
  {
    String S = MaskEdit->Text;
    String New;

    for ( int ii = 1 ; ii <= S.Length() ; ii++ )
      if ( isdigit(S[ii]) )
        New += S[ii];

    m_size64 = StrToInt64(New);
  }
  catch(...)
  {
    m_size64 = -1; // Error
  }

  MainForm->bAutoSizePrompt = CheckBox->Checked;
}
Exemplo n.º 7
0
UnicodeString TConfiguration::GetProductVersionStr() const
{
  UnicodeString Result;
#ifndef __linux__
  TGuard Guard(FCriticalSection);
  try
  {
    TVSFixedFileInfo * Info = GetFixedApplicationInfo();
    /*return FMTLOAD(VERSION,
      HIWORD(Info->dwFileVersionMS),
      LOWORD(Info->dwFileVersionMS),
      HIWORD(Info->dwFileVersionLS),
      LOWORD(Info->dwFileVersionLS));*/
    UnicodeString BuildStr;
    if (!GetIsUnofficial())
    {
      BuildStr = LoadStr(VERSION_BUILD);
    }
    else
    {
      #ifdef _DEBUG
      BuildStr = LoadStr(VERSION_DEBUG_BUILD);
      #else
      BuildStr = LoadStr(VERSION_DEV_BUILD);
      #endif
    }

    int Build = LOWORD(Info->dwFileVersionLS);
    if (Build > 0)
    {
      BuildStr += L" " + ::IntToStr(Build);
    }

#if 0
    #ifndef BUILD_OFFICIAL
    UnicodeString BuildDate = __DATE__;
    UnicodeString MonthStr = CutToChar(BuildDate, L' ', true);
    int Month = ParseShortEngMonthName(MonthStr);
    int Day = StrToInt64(CutToChar(BuildDate, L' ', true));
    int Year = StrToInt64(Trim(BuildDate));
    UnicodeString DateStr = FORMAT("%d-%2.2d-%2.2d", Year, Month, Day);
    AddToList(BuildStr, DateStr, L" ");
    #endif
#endif

    UnicodeString FullVersion = GetProductVersion();

    UnicodeString AReleaseType = GetReleaseType();
    if (DebugAlwaysTrue(!AReleaseType.IsEmpty()) &&
        !SameText(AReleaseType, L"stable") &&
        !SameText(AReleaseType, L"development"))
    {
      FullVersion += L" " + AReleaseType;
    }

    Result = FMTLOAD(VERSION2, GetProductVersion().c_str(), Build);

#if 0
    #ifndef BUILD_OFFICIAL
    Result += L" " + LoadStr(VERSION_DONT_DISTRIBUTE);
    #endif
#endif
  }
  catch (Exception & E)
  {
    throw ExtException(&E, "Can't get application version");
  }
#endif
  return Result;
}
Exemplo n.º 8
0
int TDataModule1::GetOrderReports(AnsiString acc,AnsiString OrdId,AnsiString PosStr,
	TTradeInfo **TrdInfo,int &Num)
{
	int ret = 0;
	if( cn->Connected == false ) return -1;
	TADODataSet *rs = new TADODataSet(NULL);
	try
	{
		rs->Connection = cn;
		rs->CommandType = cmdStoredProc;
		if( OrdId.Length() >0 )
			rs->CommandText = L"GetExecReportByOrdid";
		else
			rs->CommandText = L"dp_GetExecReport";
		rs->Parameters->Refresh();
		rs->Parameters->FindParam(L"@acc")->Value = acc;
		rs->Parameters->FindParam(L"@date")->Value = 0;
		if( OrdId.Length() > 0 )
		{
			rs->Parameters->FindParam(L"@ordid")->Value = StrToInt64(OrdId);
		}
		else
		{
			rs->Parameters->FindParam(L"@startindex")->Value = StrToInt64Def(PosStr,0);
			rs->Parameters->FindParam(L"@maxcount")->Value = Num;
		}

		rs->Open();
		Num = rs->Parameters->FindParam(L"@return_value")->Value;
		*TrdInfo = new TTradeInfo[Num];
		int i =0;
		while( !rs->Eof )
		{
			TTradeInfo &ti = (*TrdInfo)[i];
      ZeroMemory(&ti,sizeof(TTradeInfo));
			lstrcpyn(ti.ContractID ,IntToStr((__int64)rs->FieldByName(L"OrderID")->Value).c_str(),SEQ_LEN);
			lstrcpyn(ti.SecuID,rs->FieldByName(L"Instid")->AsString.c_str(),CODE_LEN);
			lstrcpyn(ti.TrdID,IntToStr((__int64)rs->FieldByName(L"ID")->Value).c_str(),SEQ_LEN);

			ti.Market = mtNo;
			//ti.Market = rs->FieldByName(L"Market")->AsString[1];
			ti.Time = rs->FieldByName(L"ExecTime")->AsInteger;
			ti.Date = rs->FieldByName(L"ExecDate")->AsInteger;
			ti.Type = rs->FieldByName(L"ExecType")->AsString[1];

			ti.Vol  =rs->FieldByName(L"ExecQty")->AsFloat;
			ti.Price=rs->FieldByName(L"ExecPrice")->AsFloat;
			lstrcpyn(ti.Account,rs->FieldByName(L"Account")->AsString.c_str(),ACC_LEN);
			lstrcpyn(ti.SeqNum, ti.TrdID,SEQ_LEN);
			i++;
			rs->Next();
    }
	}
	catch( Exception &e )
	{
		ODS('E',"PTSRF","GetOrderReports Error,%s,%s,%s,%d,message is %s",acc.c_str(),
			OrdId.c_str(),PosStr.c_str(),Num,e.Message.c_str());
		ret = -1;
	}
	if( rs->Active == true )
		rs->Close();
	delete rs;
	return ret;
}
void WXMSearchReplaceDialog::WxButtonReplaceAllClick(wxCommandEvent& event)
{
	ResetMessage();

	if( g_active_wxmedit == nullptr)
		return;

	wxString text;
	m_FindText->GetText(text, true);

	if(WxCheckBoxFindHex->GetValue())
		text.Trim();

	if(text.Len()>0)
	{
		wxString reptext;
		m_ReplaceText->GetText(reptext, true);

		m_RecentFindText->AddItemToHistory(text);

		if(reptext.Len()>0)
		{
			m_RecentReplaceText->AddItemToHistory(reptext);
		}

		wxInt64 from = 0, to = 0;
		wxFileOffset rangeFrom = -1, rangeTo = -1;
		if(WxCheckBoxSearchInSelection->IsChecked())
		{
			if(!StrToInt64(WxEditFrom->GetValue(), from))
			{
				ShowMessage(_("The value of 'From' is incorrect."), SMT_WARNING);
				return;
			}
			if(!StrToInt64(WxEditTo->GetValue(), to))
			{
				ShowMessage(_("The value of 'To' is incorrect."), SMT_WARNING);
				return;
			}

			rangeTo = to;
			rangeFrom = from;
		}

		int count=0;
		wxm::WXMSearcher* searcher = g_active_wxmedit->Searcher(WxCheckBoxFindHex->GetValue(), WxCheckBoxRegex->GetValue());
		searcher->SetOption(WxCheckBoxCaseSensitive->GetValue(), WxCheckBoxWholeWord->GetValue());

		count = searcher->ReplaceAll(text, reptext, nullptr, nullptr, rangeFrom, rangeTo);

		if(count>=0)
		{
			wxString msg;
			if(count==0)
				ShowMessage(_("Cannot find any matched string."), SMT_WARNING);
			else
				ShowMessage(wxString::Format(_("%d string(s) were replaced."), count), SMT_NOTICE);
		}

		m_FindText->SetFocus();
	}
}
void WXMSearchReplaceDialog::WxButtonReplaceClick(wxCommandEvent& event)
{
	ResetMessage();

	if (g_active_wxmedit == nullptr)
		return;

	wxString text;
	m_FindText->GetText(text, true);

	if(WxCheckBoxFindHex->GetValue())
		text.Trim();

	if(text.Len() <= 0)
		return;

	wxString reptext;
	m_ReplaceText->GetText(reptext, true);

	m_RecentFindText->AddItemToHistory(text);

	if(reptext.Len()>0)
	{
		m_RecentReplaceText->AddItemToHistory(reptext);
	}

	wxString msg_selection_end(_("End of selection reached, replace from beginning."));
	wxString msg_file_end(_("End of file reached, replace from beginning."));

	wxInt64 from = 0, to = 0;
	wxFileOffset rangeFrom = -1, rangeTo = -1;
	wxFileOffset caretpos = g_active_wxmedit->GetCaretPosition();
	if(WxCheckBoxSearchInSelection->IsChecked())
	{
		if(!StrToInt64(WxEditFrom->GetValue(), from))
		{
			ShowMessage(_("The value of 'From' is incorrect."), SMT_WARNING);
			return;
		}
		if(!StrToInt64(WxEditTo->GetValue(), to))
		{
			ShowMessage(_("The value of 'To' is incorrect."), SMT_WARNING);
			return;
		}

		rangeTo = to;
		if (caretpos <= from || caretpos > to)
		{
			rangeFrom = from;
		}
		else if (caretpos==to && WxCheckBoxWrapAround->IsChecked())
		{
			ShowMessage(msg_selection_end);
			rangeFrom = from;
		}
	}

	MadReplaceResult ret=RR_EXPR_ERROR;

	wxm::WXMSearcher* searcher = g_active_wxmedit->Searcher(WxCheckBoxFindHex->GetValue(), WxCheckBoxRegex->GetValue());
	searcher->SetOption(WxCheckBoxCaseSensitive->GetValue(), WxCheckBoxWholeWord->GetValue());
	for (;;)
	{
		ret = searcher->ReplaceOnce(text, reptext, rangeFrom, rangeTo);

		if ((ret==RR_REP_NNEXT || ret==RR_NREP_NNEXT) &&
			WxCheckBoxWrapAround->IsChecked() && rangeTo != caretpos)
		{
			bool in_selection = WxCheckBoxSearchInSelection->IsChecked();

			ShowMessage(in_selection? msg_selection_end: msg_file_end);

			rangeTo = caretpos;
			rangeFrom = in_selection? from : 0;
			continue;
		}

		break;
	}

	switch(ret)
	{
	case RR_REP_NNEXT:
		{
			ShowMessage(_("Cannot find the matched string. Replace is finished."), SMT_NOTICE);
			m_FindText->SetFocus();
		}
		break;
	case RR_NREP_NNEXT:
		{
			ShowMessage(_("Cannot find the matched string."), SMT_WARNING);
			m_FindText->SetFocus();
		}
		break;
	case RR_REP_NEXT:
	case RR_NREP_NEXT:
		if(WxCheckBoxMoveFocus->GetValue())
		{
			((wxFrame*)wxTheApp->GetTopWindow())->Raise();
			g_active_wxmedit->SetFocus();
		}
		break;
	default:
		break;
	}
}
void WXMSearchReplaceDialog::WxButtonFindPrevClick(wxCommandEvent& event)
{
	ResetMessage();

	if (g_active_wxmedit == nullptr)
		return;

	wxString text;
	m_FindText->GetText(text, true);

	if(WxCheckBoxFindHex->GetValue())
		text.Trim();

	if(text.Len()>0)
	{
		m_RecentFindText->AddItemToHistory(text);

		MadSearchResult sr;
		wxFileOffset selbeg = g_active_wxmedit->GetSelectionBeginPos();
		wxFileOffset caretpos = g_active_wxmedit->GetCaretPosition();

		wxString msg_selection_begin(_("Beginning of selection reached, search from end."));
		wxString msg_file_begin(_("Beginning of file reached, search from end."));

		wxInt64 from = 0, to = 0;
		wxFileOffset rangeFrom = -1, rangeTo = -1;
		if(WxCheckBoxSearchInSelection->IsChecked())
		{
			if(!StrToInt64(WxEditFrom->GetValue(), from))
			{
				ShowMessage(_("The value of 'From' is incorrect."), SMT_WARNING);
				return;
			}
			if(!StrToInt64(WxEditTo->GetValue(), to))
			{
				ShowMessage(_("The value of 'To' is incorrect."), SMT_WARNING);
				return;
			}

			rangeFrom = from;
			if (caretpos < from || caretpos >= to)
			{
				rangeTo = to;
			}
			else if (caretpos==from && WxCheckBoxWrapAround->IsChecked())
			{
				ShowMessage(msg_selection_begin);
				rangeTo = to;
			}
		}

		wxm::WXMSearcher* searcher = g_active_wxmedit->Searcher(WxCheckBoxFindHex->GetValue(), WxCheckBoxRegex->GetValue());
		searcher->SetOption(WxCheckBoxCaseSensitive->GetValue(), WxCheckBoxWholeWord->GetValue());
		for (;;)
		{
			sr = searcher->FindPrevious(text, rangeTo, rangeFrom);

			if(sr!=SR_NO)
			{
				if(sr == SR_YES && g_active_wxmedit->GetCaretPosition() == selbeg)
				{
					selbeg = -1;
					continue;
				}
				break;
			}

			if (WxCheckBoxWrapAround->IsChecked() && rangeFrom != caretpos)
			{
				bool in_selection = WxCheckBoxSearchInSelection->IsChecked();

				ShowMessage(in_selection? msg_selection_begin: msg_file_begin);

				rangeTo = in_selection? to: g_active_wxmedit->GetFileSize();
				rangeFrom = caretpos;
				continue;
			}

			wxString msg(_("Cannot find the matched string."));
			ShowMessage(msg, SMT_WARNING);
			break;
		}
	}

	if(WxCheckBoxMoveFocus->GetValue())
	{
		((wxFrame*)wxTheApp->GetTopWindow())->Raise();
		g_active_wxmedit->SetFocus();
	}
}
Exemplo n.º 12
0
/*
 * WxButtonReplaceAllClick
 */
void MadReplaceDialog::WxButtonReplaceAllClick(wxCommandEvent& event)
{
    extern MadEdit *g_ActiveMadEdit;

    if(g_ActiveMadEdit==NULL)
        return;

    wxString text;
    m_FindText->GetText(text, true);

    if(text.Len()>0)
    {
        wxString reptext;
        m_ReplaceText->GetText(reptext, true);

        g_SearchDialog->m_RecentFindText->AddFileToHistory(text);

        if(reptext.Len()>0)
        {
            m_RecentReplaceText->AddFileToHistory(reptext);
        }

        wxInt64 from = 0, to = 0;
        wxFileOffset rangeFrom = -1, rangeTo = -1;
        if(WxCheckBoxSearchInSelection->IsChecked())
        {
            if(!StrToInt64(WxEditFrom->GetValue(), from))
            {
                wxMessageBox(_("The value of 'From' is incorrect."), wxT("MadEdit"), wxOK|wxICON_WARNING);
                return;
            }
            if(!StrToInt64(WxEditTo->GetValue(), to))
            {
                wxMessageBox(_("The value of 'To' is incorrect."), wxT("MadEdit"), wxOK|wxICON_WARNING);
                return;
            }

            rangeTo = to;
            rangeFrom = from;
        }

        int count=0;
        if(WxCheckBoxFindHex->GetValue())
        {
            count=g_ActiveMadEdit->ReplaceHexAll(text, reptext, NULL, NULL, rangeFrom, rangeTo);
        }
        else
        {
            count=g_ActiveMadEdit->ReplaceTextAll(text, reptext,
                WxCheckBoxRegex->GetValue(),
                WxCheckBoxCaseSensitive->GetValue(),
                WxCheckBoxWholeWord->GetValue(),
                NULL, NULL, rangeFrom, rangeTo);
        }

        if(count>=0)
        {
            wxString msg;
            if(count==0)
                msg=wxString(_("Cannot find any matched string."));
            else
                msg=wxString::Format(_("%d string(s) were replaced."), count);

            wxMessageDialog dlg(this, msg, wxT("MadEdit"));
            dlg.ShowModal();
        }

        m_FindText->SetFocus();
    }
}
Exemplo n.º 13
0
/*
 * WxButtonReplaceClick
 */
void MadReplaceDialog::WxButtonReplaceClick(wxCommandEvent& event)
{
    extern MadEdit *g_ActiveMadEdit;

    if(g_ActiveMadEdit==NULL)
        return;

    wxString text;
    m_FindText->GetText(text, true);

    if(text.Len()>0)
    {
        wxString reptext;
        m_ReplaceText->GetText(reptext, true);

        g_SearchDialog->m_RecentFindText->AddFileToHistory(text);

        if(reptext.Len()>0)
        {
            m_RecentReplaceText->AddFileToHistory(reptext);
        }

        wxInt64 from = 0, to = 0;
        wxFileOffset rangeFrom = -1, rangeTo = -1;
        if(WxCheckBoxSearchInSelection->IsChecked())
        {
            if(!StrToInt64(WxEditFrom->GetValue(), from))
            {
                wxMessageBox(_("The value of 'From' is incorrect."), wxT("MadEdit"), wxOK|wxICON_WARNING);
                return;
            }
            if(!StrToInt64(WxEditTo->GetValue(), to))
            {
                wxMessageBox(_("The value of 'To' is incorrect."), wxT("MadEdit"), wxOK|wxICON_WARNING);
                return;
            }

            rangeTo = to;
            wxFileOffset caretpos = g_ActiveMadEdit->GetCaretPosition();
            if(caretpos <= from || caretpos > to)
                rangeFrom = from;
        }

        MadReplaceResult ret=RR_EXPR_ERROR;
        if(WxCheckBoxFindHex->GetValue())
        {
            ret=g_ActiveMadEdit->ReplaceHex(text, reptext, rangeFrom, rangeTo);
        }
        else
        {
            ret=g_ActiveMadEdit->ReplaceText(text, reptext,
                WxCheckBoxRegex->GetValue(),
                WxCheckBoxCaseSensitive->GetValue(),
                WxCheckBoxWholeWord->GetValue(),
                rangeFrom, rangeTo);
        }

        switch(ret)
        {
        case RR_REP_NNEXT:
        case RR_NREP_NNEXT:
            {
                wxMessageDialog dlg(this, _("Cannot find the matched string.\nReplace is finished."), wxT("MadEdit"));
                dlg.ShowModal();
                m_FindText->SetFocus();
            }
            break;
        case RR_REP_NEXT:
        case RR_NREP_NEXT:
            if(WxCheckBoxMoveFocus->GetValue())
            {
                ((wxFrame*)wxTheApp->GetTopWindow())->Raise();
                g_ActiveMadEdit->SetFocus();
            }
            break;
        }
    }
}