Ejemplo n.º 1
0
Parser::ShiftReduceChoice Parser::chooseShiftReduce(int state, Token::Type type, int *x)
{
    if (Token::Unknown_Token == type || state < 0 || state > MaxState)
        return bRet(x, -1, ErrorChoice);
    QString s = Table[state * (MaxType + 1) + type];
    BTextTools::removeTrailingSpaces(&s);
    if (s.isEmpty())
        return bRet(x, -1, ErrorChoice);
    ShiftReduceChoice c = ErrorChoice;
    if (s.startsWith("R"))
        c = ReduceChoice;
    else if (s.startsWith("S"))
        c = StateChangeChoice;
    else
        c = ShiftChoice;
    if (ShiftChoice != c) {
        s = s.mid(1);
        if (s.isEmpty())
            return bRet(x, -1, ErrorChoice);
    }
    bool b = false;
    int xx = s.toInt(&b);
    if (!b)
        return bRet(x, -1, ErrorChoice);
    return bRet(x, xx, c);
}
ApplicationVersion ApplicationVersionRepository::findOneByFields(
        Texsample::ClientType clienType, BeQt::OSType os, BeQt::ProcessorArchitecture arch, bool portable, bool *ok)
{
    ApplicationVersion entity(this);
    if (!isValid() || Texsample::UnknownClient == clienType || BeQt::UnknownOS == os
            || BeQt::UnknownArchitecture == arch) {
        return bRet(ok, false, entity);
    }
    QString ws = "client_type = :client_type AND os_type = :os_type AND portable = :portable "
        "AND processor_architecture_type = :processor_architecture_type";
    QVariantMap values;
    values.insert(":client_type", int(clienType));
    values.insert(":os_type", int(os));
    values.insert(":portable", int(portable));
    values.insert(":processor_architecture_type", int(arch));
    BSqlResult result = Source->select("application_versions", QStringList() << "download_url" << "version",
                                       BSqlWhere(ws, values));
    if (!result.success())
        return bRet(ok, false, entity);
    if (result.values().isEmpty())
        return bRet(ok, true, entity);
    entity.mclienType = clienType;
    entity.mdownloadUrl = QUrl(result.value("download_url").toString());
    entity.mos = os;
    entity.mportable = portable;
    entity.mprocessorArchitecture = arch;
    entity.mversion = BVersion(result.value("version").toString());
    entity.valid = true;
    return bRet(ok, true, entity);
}
Ejemplo n.º 3
0
bool LexicalAnalyzer::matchFuncName(const QString &s, int &matchedLength, bool *builtin)
{
    matchedLength = 0;
    int i = -1;
    bool b = false;
    foreach (const QString &fn, PretexBuiltinFunction::normalFuncNames()) {
        if (s.startsWith(fn)) {
            b = true;
            i = fn.length();
            break;
        }
    }
    if (b) {
        static QList<QChar> chars = QList<QChar>() << '\\' << '#' << '{' << '}' << '[' << ']' << '\"';
        if (i < s.length() && !s.at(i).isSpace() && !chars.contains(s.at(i)))
            return bRet(builtin, false, false);
        matchedLength = i;
        return bRet(builtin, true, true);
    } else {
        if (!s.at(0).isLetter() && s.at(0) != '_')
            return bRet(builtin, false, false);
        int i = 1;
        while (i < s.length() && (s.at(i).isLetterOrNumber() || s.at(i) == '_'))
            ++i;
        matchedLength = i;
        return bRet(builtin, false, true);
    }
}
bool TrigonometricFunction::unaryTh(ExecutionContext *context, QString *err)
{
    switch (context->obligArg().type()) {
    case PretexVariant::Int:
        context->setReturnValue(std::tanh(context->obligArg().toInt()));
        break;
    case PretexVariant::Real:
        context->setReturnValue(std::tanh(context->obligArg().toReal()));
        break;
    case PretexVariant::String:
    default:
        return bRet(err, tr("Invalid argument type", "error"), false);
    }
    return bRet(err, QString(), true);
}
Ejemplo n.º 5
0
UtlBoolean SipTlsServer::startListener()
{
    UtlBoolean bRet(FALSE);
#       ifdef TEST_PRINT
        osPrintf("SIP Server binding to port %d\n", serverPort);
#       endif

    // iterate over the SipServerBroker map and call start
    UtlHashMapIterator iterator(mServerBrokers);
    UtlVoidPtr* pBrokerContainer = NULL;
    SipServerBroker* pBroker = NULL;
    UtlString* pKey = NULL;
    
    while(pKey = (UtlString*)iterator())
    {
        pBrokerContainer = (UtlVoidPtr*) iterator.value();
        if (pBrokerContainer)
        {
            pBroker = (SipServerBroker*)pBrokerContainer->getValue();
            if (pBroker)
            {
                pBroker->start();
                bRet = TRUE;
            }
        }
    }
    return bRet;
}
Ejemplo n.º 6
0
Token *Parser::parse(bool *ok, QString *err, Token *token) const
{
    if (mtokens.isEmpty())
        return bRet(ok, true, err, QString(), token, Token(), new Token(Token::Program_Token));
    TokenStack stack;
    int i = 0;
    while (true) {
        if (mtokens.size() == i) {
            stack.freeAll();
            return bRet(ok, false, err, tr("Unexpected end of token list", "error"), token, Token(), (Token *) 0);
        }
        const Token &t = mtokens.at(i);
        int x = 0;
        ShiftReduceChoice choice = chooseShiftReduce(stack.state(), t.type(), &x);
        switch (choice) {
        case StateChangeChoice: {
            stack.append(new Token(t), x);
            ++i;
            break;
        }
        case ReduceChoice: {
            bool b = false;
            Token *nt = reduce(stack, x, &b, err);
            if (!b) {
                delete nt;
                stack.freeAll();
                return bRet(ok, b, token, t, (Token *) 0);
            }
            if (nt->type() == Token::Program_Token && stack.isEmpty()) {
                if (i < mtokens.size() - 1)
                    return bRet(ok, false, err, tr("Unexpected error", "error"), token, t, (Token *) 0);
                return bRet(ok, true, err, QString(), token, Token(), nt);
            }
            choice = chooseShiftReduce(stack.state(), nt->type(), &x);
            if (ShiftChoice != choice)
                return bRet(ok, false, err, tr("Failed to find shift rule", "error"), token, t, (Token *) 0);
            stack.append(nt, x);
            break;
        }
        case ShiftChoice: {
            stack.freeAll();
            return bRet(ok, false, err, tr("Unexpected shift rule", "error"), token, t, (Token *) 0);
        }
        case ErrorChoice:
        default: {
            stack.freeAll();
            return bRet(ok, false, err, tr("Failed to find shift or reduce rule", "error"), token, t, (Token *) 0);
        }
        }
    }
    return bRet(ok, false, err, tr("Failed to finish parsing", "error"), token, Token(), (Token *) 0);
}
bool TrigonometricFunction::execute(ExecutionContext *context, QString *err)
{
    //Argument count is checked in PretexBuiltinFunction
    switch (mtype) {
    case SinType:
        return unarySin(context, err);
    case CosType:
        return unaryCos(context, err);
    case TanType:
        return unaryTan(context, err);
    case CotType:
        return unaryCot(context, err);
    case SecType:
        return unarySec(context, err);
    case CscType:
        return unaryCsc(context, err);
    case AsinType:
        return unaryAsin(context, err);
    case AcosType:
        return unaryAcos(context, err);
    case AtanType:
        return unaryAtan(context, err);
    case AcotType:
        return unaryAcot(context, err);
    case AsecType:
        return unaryAsec(context, err);
    case AcscType:
        return unaryAcsc(context, err);
    case ShType:
        return unarySh(context, err);
    case ChType:
        return unaryCh(context, err);
    case ThType:
        return unaryTh(context, err);
    case CthType:
        return unaryCth(context, err);
    case SechType:
        return unarySech(context, err);
    case CschType:
        return unaryCsch(context, err);
    case ArshType:
        return unaryArsh(context, err);
    case ArchType:
        return unaryArch(context, err);
    case ArthType:
        return unaryArth(context, err);
    case ArcthType:
        return unaryArcth(context, err);
    case ArschType:
        return unaryArsch(context, err);
    case ArcschType:
        return unaryArcsch(context, err);
    default:
        break;
    }
    return bRet(err, tr("Internal error: failed to find builtin function", "error"), false);
}
Ejemplo n.º 8
0
bool PretexFunction::execute(ExecutionContext *context, Function_TokenData *f, QString *err)
{
    if (!isValid())
        return bRet(err, tr("Attempted to execute invalid function", "error"), false);
    int oblArgCount = obligatoryArgumentCount();
    if (f->obligatoryArgumentCount() != oblArgCount)
        return bRet(err, tr("Argument count mismatch:", "error") + " " + name(), false);
    int optArgCount = optionalArgumentCount();
    if (optArgCount >= 0 && f->optionalArgumentCount() > optArgCount)
        return bRet(err, tr("Argument count mismatch:", "error") + " " + name(), false);
    QList<PretexVariant> oblArgs;
    foreach (int i, bRangeD(0, f->obligatoryArgumentCount() - 1))
    {
        bool b = false;
        PretexVariant a = ExecutionModule::executeSubprogram(context, f->obligatoryArgument(i), "", &b, err);
        if (!b)
            return false;
        oblArgs << a;
    }
    QList<PretexVariant> optArgs;
    foreach (int i, bRangeD(0, f->optionalArgumentCount() - 1))
    {
        bool b = false;
        PretexVariant a = ExecutionModule::executeSubprogram(context, f->optionalArgument(i), "", &b, err);
        if (!b)
            return false;
        optArgs << a;
    }
    ExecutionContext s(oblArgs, optArgs, name(), context);
    bool b = false;
    PretexVariant v = ExecutionModule::executeSubprogram(&s, DATA_CAST(Subprogram, &mbody), f->name(), &b, err);
    if (!b)
        return false;
    context->setReturnValue(v);
    return bRet(err, QString(), true);
}
Ejemplo n.º 9
0
QString RecordingModule::commandFromKeyPress(QKeyEvent *e, bool *ok)
{
    int key = e->key();
    Qt::KeyboardModifiers modifiers = e->modifiers();
    QString text = e->text();
    if (key <= 0)
        return bRet(ok, false, QString());
    if (Qt::Key_Control == key || Qt::Key_Alt == key || Qt::Key_Shift == key)
        return bRet(ok, false, QString());
    if ((modifiers & Qt::ControlModifier) && (modifiers & Qt::ShiftModifier) && (modifiers & Qt::AltModifier)
            && (modifiers & Qt::MetaModifier))
        return bRet(ok, false, QString());
    if (!(modifiers & Qt::ControlModifier) && !(modifiers & Qt::AltModifier) && Qt::Key_Return == key)
        text = "\n";
    if (text.isEmpty() || (!text.at(0).isPrint() && text.at(0) != '\n')
            || (modifiers & Qt::ControlModifier) || (modifiers & Qt::AltModifier)) {
        QString s = "\\press{\"" + QKeySequence(key | modifiers).toString(QKeySequence::PortableText) + "\"}";
        return bRet(ok, true, s);
    }
    text.replace('%', "\\%");
    text.replace('\t', "\\t");
    text.replace('\n', "\\n");
    return bRet(ok, true, "\\insert{\"" + text + "\"}");
}
Ejemplo n.º 10
0
static QList<BParsingOption> createOptions(const QString &options, BTextTools::OptionsParsingError *error)
{
    QList<BParsingOption> list;
    QStringList sl = options.split(QRegExp("\\,\\s*"), QString::SkipEmptyParts);
    if (sl.isEmpty())
        return bRet(error, BTextTools::InvalidParametersError, list);
    foreach (const QString &ss, sl) {
        BParsingOption o;
        if (ss.isEmpty())
            return bRet(error, BTextTools::InvalidParametersError, list);
        QString s = ss;
        if (s.startsWith('[')) {
            if (s.endsWith(']'))
                s = s.mid(1, s.length() - 2);
            else
                return bRet(error, BTextTools::InvalidParametersError, list);
        }
        if (ss != s)
            o.optional = true;
        QStringList idsl = s.split(':');
        if (idsl.size() > 2)
            return bRet(error, BTextTools::InvalidParametersError, list);
        if (idsl.size() == 2) {
            if (idsl.first().isEmpty() || idsl.last().isEmpty())
                return bRet(error, BTextTools::InvalidParametersError, list);
            o.id = idsl.first();
        }
        QStringList vsl = idsl.last().split('=');
        if (vsl.first().isEmpty() || vsl.size() > 2)
            return bRet(error, BTextTools::InvalidParametersError, list);
        if (vsl.size() == 2) {
            o.assignable = true;
            if (!vsl.last().isEmpty())
                o.values = vsl.last().split('|');
            if (o.values.contains(""))
                return bRet(error, BTextTools::InvalidParametersError, list);
        }
        o.keys = vsl.first().split('|');
        if (o.keys.contains(""))
            return bRet(error, BTextTools::InvalidParametersError, list);
        if (o.id.isEmpty())
            o.id = o.keys.first();
        list << o;
    }
Ejemplo n.º 11
0
string GetCurrProcessUser()
{	
	BOOL bRet(TRUE);
	string strName;

	DWORD dwSize = MAX_PATH;
	TCHAR *pszName = new TCHAR[dwSize];
	if (!GetUserName(pszName, &dwSize))
	{
		delete[] pszName;
		pszName = new TCHAR[dwSize];
		bRet = GetUserName(pszName, &dwSize);
	}

	strName = pszName;
	delete[] pszName;		
	return strName;
	//return bRet;
}  
Ejemplo n.º 12
0
BOOL CDUIProgressBarBase::OffsetPos(INT nOffset)
{
	BOOL bRet(TRUE);
	INT nPos = m_nPos + nOffset;
	if(nPos > m_nMax) 
	{
		bRet = FALSE;
		nPos = m_nMax;
	}
	if(nPos < m_nMin)
	{
		bRet = FALSE;
		nPos = m_nMin;
	}

	SetPos(nPos);

	return bRet;
}
Ejemplo n.º 13
0
//author: yy2better
//email: [email protected]
//得到当前进程用户
BOOL CSecurityTool::GetCurrProcessUser(CString& strName)
{	
	BOOL bRet(TRUE);
	strName = _T("");

	DWORD dwSize = MAX_PATH;
	TCHAR *pszName = new TCHAR[dwSize];
	if (!GetUserName(pszName, &dwSize))
	{
		//if (ERROR_MORE_DATA == GetLastError())	错误码不是这个,MSDN说明有误
		delete[] pszName;
		pszName = new TCHAR[dwSize];
		bRet = GetUserName(pszName, &dwSize);
	}
	
	strName = pszName;
	delete[] pszName;
		
	return bRet;
}
Ejemplo n.º 14
0
BOOL CDialogMediaControl::OnInitDialog()
{
	BOOL bRet(CDrawer::OnInitDialog());

	mControlResizer.AddControl(IDC_SLIDER_MEDIA_POS, RSZF_RIGHT_FIXED|RSZF_SIZEY_FIXED);
	mControlResizer.AddControl(IDC_SLIDER_MEDIA_VOLUME, RSZF_RIGHT_FIXED);
	mControlResizer.AddControl(IDC_STATIC_MEDIA_TIME, RSZF_RIGHT_FIXED);
	mControlResizer.AddControl(IDC_BUTTON_MEDIA_FULLSCREEN, RSZF_SIZE_FIXED|RSZF_BOTTOM_FIXED);
	HICON hIcon(::AfxGetApp()->LoadIcon(IDI_ICON_FULLSCREEN));
	((CButton*)GetDlgItem(IDC_BUTTON_MEDIA_FULLSCREEN))->SetIcon(hIcon);
	SetTransparent(150, DWF_TRANSPARENT_INSIDE);
	m_ToolTip.Create(this);
	int ids[] = {IDC_BUTTON_MEDIA_FULLSCREEN, IDC_BUTTON_MEDIA_PLAY_PAUSE};
	LPCTSTR tips[] = {_T("Toggle Fullscreen"), _T("Pause")};
	for (int i = 0; i < sizeof(ids)/sizeof(ids[0]); i++) {
		RECT cr;
		CWnd *pCtrl(GetDlgItem(ids[i]));
		pCtrl->GetClientRect(&cr);
		m_ToolTip.AddTool(pCtrl, tips[i], &cr, ids[i]);
	}
	m_ToolTip.Activate(TRUE);
	return bRet;
}
Ejemplo n.º 15
0
BOOL CMyVolume::SetValue(int nVol)
{
	BOOL bSet = FALSE;
	HMIXER hmier;
	if (mixerOpen(&hmier, 0, 0, 0, 0))
	{
		return FALSE;
	}
	long device = MIXERLINE_COMPONENTTYPE_DST_SPEAKERS;
	MIXERCONTROL volCtrl;
	BOOL bRet(FALSE);
	if ( GetVolumeControl(hmier, device, MIXERCONTROL_CONTROLTYPE_VOLUME, &volCtrl) )
	{
		nVol = nVol* volCtrl.Bounds.lMaximum/MAX_VOL;
		if ( SetVolumeValue(hmier,&volCtrl, nVol ) )
		{
			bRet = TRUE;			
		}

	}
	mixerClose(hmier);
	return bRet;
}
Ejemplo n.º 16
0
BOOL CDUIListBox::OnKeyDown(const DUIEvent& info)
{
	BOOL bRet(FALSE);
	switch(info.wParam)
	{
// 	case VK_SPACE:
// 	case VK_RETURN:
// 		if(m_nSelectIndex >=0 && m_nSelectIndex < GetControlCount())
// 		{
// 			IDUIListItem* pItem = (IDUIListItem*)GetControlByIndex(m_nSelectIndex)->GetInterface(IListItem);
// 			if(pItem != NULL 
// 				&& pItem->IsVisible()
// 				&& pItem->IsEnabled()
// 				&& pItem->GetGroup())
// 			{
// 				ExpandGroup(m_nSelectIndex, !pItem->GetExpand());
// 			}
// 		}
// 		break;

	case VK_LEFT:
	case VK_UP:
		{
			INT nIndex = m_nSelectIndex;
			while(TRUE)
			{
				--nIndex;
				if(nIndex>=0 && nIndex<GetControlCount())
				{
					if((GetControlByIndex(nIndex)->IsVisible()))
					{
						SetCurSel(nIndex);
						if(nIndex < m_nTopIndex
							|| nIndex >= m_nLastIndex)
						{
							SetTopIndex(nIndex);
						}
						break;
					}
				}
				else
				{
					break;
				}
			}
		}

		bRet = TRUE;
		break;

	case VK_RIGHT:
	case VK_DOWN:
		{
			INT nIndex = m_nSelectIndex;
			while(TRUE)
			{
				++nIndex;
				if(nIndex>=0 && nIndex<GetControlCount())
				{
					if(GetControlByIndex(nIndex)->IsVisible())
					{
						SetCurSel(nIndex);
						if(nIndex >= m_nLastIndex
							|| nIndex < m_nTopIndex)
						{
							INT nTopIndex = m_nTopIndex;
							//SetTopIndex(++nTopIndex);
							SetTopIndex(nIndex);
						}
						break;
					}
				}
				else
				{
					break;
				}
			}

		}
		
		bRet = TRUE;
		break;
	}

	return bRet;
}
Ejemplo n.º 17
0
BOOL CDrawQuoteTab::DrawItem( CDC* pDC, CRect& rect, BOOL bPressed)
{
	m_rcTab.SetRectEmpty();
	if (rect.IsRectEmpty())
		return FALSE;
	
	const ColorProperty* colorFrame = m_pColor->GetQuoteGuideTabFrameColorProp(); // 边框颜色
	CPen pen(colorFrame->m_nPenStyle,colorFrame->m_nWidth,colorFrame->m_lColor);
	
	CBrush brush(bPressed?m_pColor->GetQuoteActiveTabBKColor():m_pColor->GetQuoteTabBKColor()); // 选中填充色
	CFont* pFont = m_pFont->GetQuoteGuideTabFont();

	CFont* pOldFont = pDC->SelectObject(pFont);
	COLORREF clrOldTabText = pDC->SetTextColor(bPressed?m_pColor->GetQuoteActiveTabTextColor():m_pColor->GetQuoteTabTextColor());
	CPen* pOldPen = pDC->SelectObject(&pen);
	CBrush* pOldBrush = pDC->SelectObject(&brush);

	// 字体宽度
	CSize size; 
	CSize szText;
	szText = size = pDC->GetTextExtent(m_strName);
	size.cx += 8;

	// 计算当前大小 
	CRect curRC = rect;
	curRC.right = curRC.left + size.cx;
	// 判断是否已经显示到尽头
	BOOL bRet(FALSE);
	if (curRC.right <= rect.right)
	{
		rect.left = curRC.right; // 减去当前已经使用过的区域
		//设定当前标签的范围
		m_rcTab = curRC;

		POINT point[6];
		pDC->MoveTo(m_rcTab.left, m_rcTab.top + 1);
		point[0].x = curRC.left ;
		point[0].y = curRC.top + 1 ;
		point[1].x = curRC.right - 5;
		point[1].y = curRC.top + 1 ;
		point[2].x = curRC.right;
		point[2].y = curRC.top + 6;
		point[3].x = curRC.right;
		point[3].y = curRC.bottom;
		point[4].x = curRC.left;
		point[4].y = curRC.bottom;
		point[5] = point[0];
		pDC->Polygon(point,6);				//选中的tab
		curRC.left += 3;
		pDC->DrawText(m_strName, curRC, DT_SINGLELINE | DT_VCENTER);
		bRet = TRUE;
	}

	//CleanGUI
	pDC->SelectObject(pOldFont);
	pDC->SelectObject(pOldPen);
	pDC->SelectObject(pOldBrush);
	pDC->SetTextColor(clrOldTabText);
	pen.DeleteObject();
	brush.DeleteObject();

	return bRet;
}