Exemplo n.º 1
0
bool VarUnit::shouldSave(QTreeWidgetItem* p)
{
    TVar* var = getWVar(p);
    if (var->getValueType() == 6 || var->isReference()) {
        return false;
    }
    return true;
}
Exemplo n.º 2
0
bool CompAB(const TVar& a, const TVar& b, TVarFuncCmp fcmp)
{
	bool r = true;
	__int64 bi;
	double bd;

	switch (a.vType)
	{
		case vtUnknown:
		case vtInteger:

			switch (b.vType)
			{
				case vtUnknown:
				case vtInteger: r = fcmp(vtInteger,&a.inum,&b.inum); break;
				case vtDouble:  r = fcmp(vtDouble,&a.inum,&b.dnum);  break;
				case vtString:
				{
					switch (checkTypeString(b.asString()))
					{
						case tsStr:   r = fcmp(vtString,a.asString().data(),b.str.data()); break;
						case tsInt:   bi=b.asInteger(); r = fcmp(vtInteger,&a.inum,&bi);  break;
						case tsFloat: bd=b.asDouble(); r = fcmp(vtDouble,&a.inum,&bd);   break;
					}

					break;
				}
			}

			break;
		case vtDouble:

			switch (b.vType)
			{
				case vtUnknown:
				case vtInteger: r = fcmp(vtInteger,&a.dnum,&b.inum); break;
				case vtDouble:  r = fcmp(vtDouble,&a.dnum,&b.dnum);  break;
				case vtString:
				{
					switch (checkTypeString(b.str))
					{
						case tsStr:   r = fcmp(vtString,a.asString().data(),b.str.data()); break;
						case tsInt:
						case tsFloat: bd=b.asDouble(); r = fcmp(vtDouble,&a.inum,&bd);   break;
					}

					break;
				}
			}

			break;
		case vtString:
		{
			r = fcmp(vtString,a.asString().data(),b.asString().data());
			break;
		}
	}

	return r;
};
Exemplo n.º 3
0
QStringList VarUnit::shortVarName(TVar * var){
    QStringList names;
    if (!var || var->getName() == "_G"){
        names << "";
        return names;
    }
    names << var->getName();
    TVar * p = var->getParent();
    while (p && p->getName() != "_G"){
        names.insert(0, p->getName());
        p = p->getParent();
    }
    return names;
}
Exemplo n.º 4
0
QStringList VarUnit::varName(TVar * var){
    QStringList names;
    names << "_G";
    if (var == base || ! var ){
        return names;
    }
    names << var->getName();
    TVar * p = var->getParent();
    while (p && p != base){
        names.insert(1, p->getName());
        if (p == base)
            break;
        p = p->getParent();
    }
    return names;
}
Exemplo n.º 5
0
void VarUnit::buildVarTree(QTreeWidgetItem* p, TVar* var, bool showHidden)
{
    QList<QTreeWidgetItem*> cList;
    QListIterator<TVar*> it(var->getChildren(true));
    while (it.hasNext()) {
        TVar* child = it.next();
        if (showHidden || !isHidden(child)) {
            QStringList s1;
            s1 << child->getName();
            auto pItem = new QTreeWidgetItem(s1);
            pItem->setText(0, child->getName());
            pItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDropEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsTristate | Qt::ItemIsUserCheckable);
            pItem->setToolTip(0, "Checked variables will be saved and loaded with your profile.");
            pItem->setCheckState(0, Qt::Unchecked);
            if (isSaved(child)) {
                pItem->setCheckState(0, Qt::Checked);
            }
            if (!shouldSave(child)) { // 6 is lua_tfunction, parent must be saveable as well if not global
                pItem->setFlags(pItem->flags() & ~(Qt::ItemIsDropEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsUserCheckable));
                pItem->setForeground(0, QBrush(QColor("grey")));
                pItem->setToolTip(0, "");
            }
            pItem->setData(0, Qt::UserRole, child->getValueType());
            QIcon icon;
            switch (child->getValueType()) {
            case 5:
                icon.addPixmap(QPixmap(QStringLiteral(":/icons/table.png")), QIcon::Normal, QIcon::Off);
                break;
            case 6:
                icon.addPixmap(QPixmap(QStringLiteral(":/icons/function.png")), QIcon::Normal, QIcon::Off);
                break;
            default:
                icon.addPixmap(QPixmap(QStringLiteral(":/icons/variable.png")), QIcon::Normal, QIcon::Off);
                break;
            }
            pItem->setIcon(0, icon);
            wVars.insert(pItem, child);
            cList.append(pItem);
            if (child->getValueType() == 5) {
                buildVarTree((QTreeWidgetItem*)pItem, child, showHidden);
            }
        }
    }
    p->addChildren(cList);
}
Exemplo n.º 6
0
TVar operator%(const TVar& a, const TVar& b)
{
	TVar r;

	switch (a.vType)
	{
		case vtUnknown:
		case vtInteger:
		{
			switch (b.vType)
			{
				case vtUnknown:
				case vtInteger: r = b.inum ? (a.inum % b.inum) : 0; break;
				case vtDouble:  r = fabs(b.dnum) > DBL_EPSILON? fmod((double)a.inum, b.dnum) : 0.0; break;
				case vtString:
				{
					switch (checkTypeString(b.str))
					{
						case tsStr:   r = a;     break;
						case tsInt:
						{
							__int64 bi=b.i();
							r = bi ? a.inum % bi : 0; break;
						}
						case tsFloat:
						{
							double bd=b.d();
							r = fabs(bd) > DBL_EPSILON? fmod((double)a.inum, bd) : 0.0; break;
						}
					}

					break;
				}
			}

			break;
		}
		case vtDouble:
		{
			switch (b.vType)
			{
				case vtUnknown:
				case vtInteger: r = b.inum ? fmod(a.dnum,(double)b.inum) : 0.0; break;
				case vtDouble:  r = fabs(b.dnum) > DBL_EPSILON? fmod(a.dnum,b.dnum) : 0.0; break;
				case vtString:
				{
					switch (checkTypeString(b.str))
					{
						case tsStr:   r = a;     break;
						case tsInt:
						case tsFloat:
						{
							double bd=b.d();
							r = fabs(bd) > DBL_EPSILON? fmod(a.dnum, bd) : 0.0; break;
						}
					}

					break;
				}
			}

			break;
		}
		case vtString:
		{
			TypeString tsA=checkTypeString(a.str),tsB;

			if (b.vType == vtInteger || b.vType == vtUnknown)
				tsB=tsInt;
			else if (b.vType == vtDouble)
				tsB=tsFloat;
			else
				tsA=tsB=tsStr;

			if ((tsA == tsStr && tsB == tsStr) || (tsA != tsStr && tsB == tsStr) || (tsA == tsStr && tsB != tsStr))
				r = a;
			else if (tsA == tsInt && tsB == tsInt)
			{
				__int64 bi=b.i();
				r = bi ? (a.i() % bi) : 0;
			}
			else
			{
				double bd=b.d();
				r = fabs(bd) > DBL_EPSILON? fmod(a.d() , bd) : 0.0;
			}

			break;
		}
	}

	return r;
};
Exemplo n.º 7
0
TVar operator*(const TVar& a, const TVar& b)
{
	TVar r;

	switch (a.vType)
	{
		case vtUnknown:
		case vtInteger:
		{
			switch (b.vType)
			{
				case vtUnknown:
				case vtInteger: r = a.inum * b.inum; break;
				case vtDouble:  r = (double)a.inum * b.dnum; break;
				case vtString:
				{
					switch (checkTypeString(b.str))
					{
						case tsStr:   r = a;     break;
						case tsInt:   r = a.inum * b.i(); break;
						case tsFloat: r = (double)a.inum * b.d(); break;
					}

					break;
				}
			}

			break;
		}
		case vtDouble:
		{
			switch (b.vType)
			{
				case vtUnknown:
				case vtInteger: r = a.dnum * (double)b.inum;          break;
				case vtDouble:  r = a.dnum * b.dnum;                  break;
				case vtString:
				{
					switch (checkTypeString(b.str))
					{
						case tsStr:   r = a;     break;
						case tsInt:
						case tsFloat: r = a.dnum * b.d(); break;
					}

					break;
				}
			}

			break;
		}
		case vtString:
		{
			TypeString tsA=checkTypeString(a.str),tsB;

			if (b.vType == vtInteger || b.vType == vtUnknown)
				tsB=tsInt;
			else if (b.vType == vtDouble)
				tsB=tsFloat;
			else
				tsA=tsB=tsStr;

			if ((tsA == tsStr && tsB == tsStr) || (tsA != tsStr && tsB == tsStr) || (tsA == tsStr && tsB != tsStr))
				r = a;
			else if (tsA == tsInt && tsB == tsInt)
				r = a.i() * b.i();
			else
				r = a.d() * b.d();

			break;
		}
	}

	return r;
}
Exemplo n.º 8
0
int TVar::CompAB(const TVar& a, const TVar& b, TVarFuncCmp fcmp)
{
	int r = 1;
	__int64 bi;
	double bd;

	switch (a.vType)
	{
		case vtUnknown:
		case vtInteger:

			switch (b.vType)
			{
				case vtUnknown:
				case vtInteger: r = fcmp(vtInteger,&a.inum,&b.inum); break;
				case vtDouble:  r = fcmp(vtDouble,&a.inum,&b.dnum);  break;
				case vtString:
				{
					switch (checkTypeString(b.s()))
					{
						case tsStr:             r = fcmp(vtString,a.s(),b.str); break;
						case tsInt:   bi=b.i(); r = fcmp(vtInteger,&a.inum,&bi);  break;
						case tsFloat: bd=b.d(); r = fcmp(vtDouble,&a.inum,&bd);   break;
					}

					break;
				}
			}

			break;
		case vtDouble:

			switch (b.vType)
			{
				case vtUnknown:
				case vtInteger: r = fcmp(vtInteger,&a.dnum,&b.inum); break;
				case vtDouble:  r = fcmp(vtDouble,&a.dnum,&b.dnum);  break;
				case vtString:
				{
					switch (checkTypeString(b.str))
					{
						case tsStr:             r = fcmp(vtString,a.s(),b.str); break;
						case tsInt:
						case tsFloat: bd=b.d(); r = fcmp(vtDouble,&a.inum,&bd);   break;
					}

					break;
				}
			}

			break;
		case vtString:
		{
#if defined(TVAR_USE_STRMUN)
			__int64 bi;
			double bd;
			TypeString tsA=checkTypeString(a.str), tsB;

			if (b.vType == vtInteger || b.vType == vtUnknown)
				tsB=tsInt;
			else if (b.vType == vtDouble)
				tsB=tsFloat;
			else
				tsB=checkTypeString(b.str);

			if ((tsA == tsStr && tsB == tsStr) || (tsA != tsStr && tsB == tsStr) || (tsA == tsStr && tsB != tsStr))
				r = fcmp(vtString,a.s(),b.s());
			else if (tsA == tsInt && tsB == tsInt)
			{
				ai=a.i();
				bi=b.i();
				r = fcmp(vtInteger,&ai,&bi);
			}
			else
			{
				ad=a.d();
				bd=b.d();
				r = fcmp(vtDouble,&ad,&bd);
			}

#else
			r = fcmp(vtString,a.s(),b.s());
#endif
			break;
		}
	}

	return r;
};
Exemplo n.º 9
0
bool XMLexport::writeHost( Host * pT )
{
    writeStartElement( "Host" );

    writeAttribute( "autoClearCommandLineAfterSend", pT->mAutoClearCommandLineAfterSend ? "yes" : "no" );
    writeAttribute( "disableAutoCompletion", pT->mDisableAutoCompletion ? "yes" : "no" );
    writeAttribute( "printCommand", pT->mPrintCommand ? "yes" : "no" );
    writeAttribute( "USE_IRE_DRIVER_BUGFIX", pT->mUSE_IRE_DRIVER_BUGFIX ? "yes" : "no" );
    writeAttribute( "mUSE_FORCE_LF_AFTER_PROMPT", pT->mUSE_FORCE_LF_AFTER_PROMPT ? "yes" : "no" );
    writeAttribute( "mUSE_UNIX_EOL", pT->mUSE_UNIX_EOL ? "yes" : "no" );
    writeAttribute( "mNoAntiAlias", pT->mNoAntiAlias ? "yes" : "no" );
    writeAttribute( "mRawStreamDump", pT->mRawStreamDump ? "yes" : "no" );
    writeAttribute( "mAlertOnNewData", pT->mAlertOnNewData ? "yes" : "no" );
    writeAttribute( "mFORCE_NO_COMPRESSION", pT->mFORCE_NO_COMPRESSION ? "yes" : "no" );
    writeAttribute( "mFORCE_GA_OFF", pT->mFORCE_GA_OFF ? "yes" : "no" );
    writeAttribute( "mFORCE_SAVE_ON_EXIT", pT->mFORCE_SAVE_ON_EXIT ? "yes" : "no" );
    writeAttribute( "mEnableGMCP", pT->mEnableGMCP ? "yes" : "no" );
    writeAttribute( "mMapStrongHighlight", pT->mMapStrongHighlight ? "yes" : "no" );
    writeAttribute( "mLogStatus", pT->mLogStatus ? "yes" : "no" );
    writeAttribute( "mEnableSpellCheck", pT->mEnableSpellCheck ? "yes" : "no" );
    writeAttribute( "mShowInfo", pT->mShowInfo ? "yes" : "no" );
    writeAttribute( "mAcceptServerGUI", pT->mAcceptServerGUI ? "yes" : "no" );
    writeAttribute( "mMapperUseAntiAlias", pT->mMapperUseAntiAlias ? "yes" : "no" );
    writeAttribute( "mFORCE_MXP_NEGOTIATION_OFF", pT->mFORCE_MXP_NEGOTIATION_OFF ? "yes" : "no" );
    writeAttribute( "mRoomSize", QString::number(pT->mRoomSize));
    writeAttribute( "mLineSize", QString::number(pT->mLineSize));
    writeAttribute( "mBubbleMode", pT->mBubbleMode ? "yes" : "no");
    writeAttribute( "mShowRoomIDs", pT->mShowRoomID ? "yes" : "no");
    writeAttribute( "mShowPanel", pT->mShowPanel ? "yes" : "no");
    writeAttribute( "mHaveMapperScript", pT->mHaveMapperScript ? "yes" : "no");
    QString ignore;
    QSetIterator<QChar> it(pT->mDoubleClickIgnore);
    while( it.hasNext() )
    {
        ignore = ignore.append(it.next());
    }
    writeAttribute( "mDoubleClickIgnore", ignore);

    writeTextElement( "name", pT->mHostName );
    //writeTextElement( "login", pT->mLogin );
    //writeTextElement( "pass", pT->mPass );
    writeStartElement( "mInstalledPackages" );
    for( int i=0; i<pT->mInstalledPackages.size(); i++ )
    {
        writeTextElement( "string", pT->mInstalledPackages[i] );
    }
    writeEndElement();
    if (pT->mInstalledModules.size()){
        qDebug()<<"installed module being done";
        writeStartElement( "mInstalledModules" );
        QMapIterator<QString, QStringList> it(pT->mInstalledModules);
        pT->modulesToWrite.clear();
        while( it.hasNext() )
        {
            it.next();
            writeTextElement("key", it.key());
            QStringList entry = it.value();
            qDebug()<<"XMLexport"<<entry[0]<<","<<entry[1];
            writeTextElement("filepath", entry[0]);
            writeTextElement("globalSave", entry[1]);
            if (entry[1].toInt()){
                qDebug()<<"adding module to write list:"<<it.key();
                pT->modulesToWrite[it.key()] = entry;
            }
            writeTextElement("priority", QString::number(pT->mModulePriorities[it.key()]));
        }
        writeEndElement();
    }
    writeTextElement( "url", pT->mUrl );
    writeTextElement( "serverPackageName", pT->mServerGUI_Package_name );
    writeTextElement( "serverPackageVersion", QString::number(pT->mServerGUI_Package_version ) );
    writeTextElement( "port", QString::number(pT->mPort) );
    writeTextElement( "borderTopHeight", QString::number(pT->mBorderTopHeight) );
    writeTextElement( "borderBottomHeight", QString::number(pT->mBorderBottomHeight) );
    writeTextElement( "borderLeftWidth", QString::number(pT->mBorderLeftWidth) );
    writeTextElement( "borderRightWidth", QString::number(pT->mBorderRightWidth) );
    writeTextElement( "wrapAt", QString::number(pT->mWrapAt) );
    writeTextElement( "wrapIndentCount", QString::number(pT->mWrapIndentCount) );
    writeTextElement( "commandSeperator", pT->mCommandSeperator );
    writeTextElement( "mFgColor", pT->mFgColor.name() );
    writeTextElement( "mBgColor", pT->mBgColor.name() );
    writeTextElement( "mCommandFgColor", pT->mCommandFgColor.name() );
    writeTextElement( "mCommandBgColor", pT->mCommandBgColor.name() );
    writeTextElement( "mCommandLineFgColor", pT->mCommandLineFgColor.name() );
    writeTextElement( "mCommandLineBgColor", pT->mCommandLineBgColor.name() );
    writeTextElement( "mBlack", pT->mBlack.name() );
    writeTextElement( "mLightBlack", pT->mLightBlack.name() );
    writeTextElement( "mRed", pT->mRed.name() );
    writeTextElement( "mLightRed", pT->mLightRed.name() );
    writeTextElement( "mBlue", pT->mBlue.name() );
    writeTextElement( "mLightBlue", pT->mLightBlue.name() );
    writeTextElement( "mGreen", pT->mGreen.name() );
    writeTextElement( "mLightGreen", pT->mLightGreen.name() );
    writeTextElement( "mYellow", pT->mYellow.name() );
    writeTextElement( "mLightYellow", pT->mLightYellow.name() );
    writeTextElement( "mCyan", pT->mCyan.name() );
    writeTextElement( "mLightCyan", pT->mLightCyan.name() );
    writeTextElement( "mMagenta", pT->mMagenta.name() );
    writeTextElement( "mLightMagenta", pT->mLightMagenta.name() );
    writeTextElement( "mWhite", pT->mWhite.name() );
    writeTextElement( "mLightWhite", pT->mLightWhite.name() );
    writeTextElement( "mDisplayFont", pT->mDisplayFont.toString() );
    writeTextElement( "mCommandLineFont", pT->mCommandLineFont.toString() );
    writeTextElement( "mCommandSeparator", pT->mCommandSeparator );
    writeTextElement( "commandLineMinimumHeight", QString::number(pT->commandLineMinimumHeight) );

    writeTextElement( "mFgColor2", pT->mFgColor_2.name() );
    writeTextElement( "mBgColor2", pT->mBgColor_2.name() );
    writeTextElement( "mBlack2", pT->mBlack_2.name() );
    writeTextElement( "mLightBlack2", pT->mLightBlack_2.name() );
    writeTextElement( "mRed2", pT->mRed_2.name() );
    writeTextElement( "mLightRed2", pT->mLightRed_2.name() );
    writeTextElement( "mBlue2", pT->mBlue_2.name() );
    writeTextElement( "mLightBlue2", pT->mLightBlue_2.name() );
    writeTextElement( "mGreen2", pT->mGreen_2.name() );
    writeTextElement( "mLightGreen2", pT->mLightGreen_2.name() );
    writeTextElement( "mYellow2", pT->mYellow_2.name() );
    writeTextElement( "mLightYellow2", pT->mLightYellow_2.name() );
    writeTextElement( "mCyan2", pT->mCyan_2.name() );
    writeTextElement( "mLightCyan2", pT->mLightCyan_2.name() );
    writeTextElement( "mMagenta2", pT->mMagenta_2.name() );
    writeTextElement( "mLightMagenta2", pT->mLightMagenta_2.name() );
    writeTextElement( "mWhite2", pT->mWhite_2.name() );
    writeTextElement( "mLightWhite2", pT->mLightWhite_2.name() );
    writeTextElement( "mSpellDic", pT->mSpellDic );
    writeTextElement( "mLineSize", QString::number(pT->mLineSize) );
    writeTextElement( "mRoomSize", QString::number(pT->mRoomSize) );
    writeEndElement(); // end Host tag
    writeEndElement(); // end HostPackage tag

    writeStartElement( "TriggerPackage" );
    bool ret = true;
    typedef list<TTrigger *>::const_iterator ItTriggerUnit;
    for( ItTriggerUnit it1 = pT->mTriggerUnit.mTriggerRootNodeList.begin(); it1 != pT->mTriggerUnit.mTriggerRootNodeList.end(); it1++)
    {
        TTrigger * pChildTrigger = *it1;
        if( ! pChildTrigger || pChildTrigger->mModuleMember) continue;
        if( ! pChildTrigger->isTempTrigger())
        {
            ret = writeTrigger( pChildTrigger );
        }
    }
    writeEndElement(); //end trigger package tag

    writeStartElement("TimerPackage");
    typedef list<TTimer *>::const_iterator ItTimerUnit;
    for( ItTimerUnit it2 = pT->mTimerUnit.mTimerRootNodeList.begin(); it2 != pT->mTimerUnit.mTimerRootNodeList.end(); it2++)
    {
        TTimer * pChildTimer = *it2;
        if (pChildTimer->mModuleMember) continue;
        if( ! pChildTimer->isTempTimer())
        {
            ret = writeTimer( pChildTimer );
        }
    }
    writeEndElement();

    writeStartElement("AliasPackage");
    typedef list<TAlias *>::const_iterator ItAliasUnit;
    for( ItAliasUnit it3 = pT->mAliasUnit.mAliasRootNodeList.begin(); it3 != pT->mAliasUnit.mAliasRootNodeList.end(); it3++)
    {
        TAlias * pChildAlias = *it3;
        if (pChildAlias->mModuleMember) continue;
        if( ! pChildAlias->isTempAlias())
        {
            ret = writeAlias( pChildAlias );
        }
    }
    writeEndElement();

    writeStartElement("ActionPackage");
    typedef list<TAction *>::const_iterator ItActionUnit;
    for( ItActionUnit it4 = pT->mActionUnit.mActionRootNodeList.begin(); it4 != pT->mActionUnit.mActionRootNodeList.end(); it4++)
    {
        TAction * pChildAction = *it4;
        if (pChildAction->mModuleMember) continue;
        ret = writeAction( pChildAction );
    }
    writeEndElement();

    writeStartElement("ScriptPackage");
    typedef list<TScript *>::const_iterator ItScriptUnit;
    for( ItScriptUnit it5 = pT->mScriptUnit.mScriptRootNodeList.begin(); it5 != pT->mScriptUnit.mScriptRootNodeList.end(); it5++)
    {
        TScript * pChildScript = *it5;
        if (pChildScript->mModuleMember) continue;
        ret = writeScript( pChildScript );
    }
    writeEndElement();

    writeStartElement("KeyPackage");
    typedef list<TKey *>::const_iterator ItKeyUnit;
    for( ItKeyUnit it6 = pT->mKeyUnit.mKeyRootNodeList.begin(); it6 != pT->mKeyUnit.mKeyRootNodeList.end(); it6++)
    {
        TKey * pChildKey = *it6;
        if (pChildKey->mModuleMember) continue;
        ret = writeKey( pChildKey );
    }
    writeEndElement();

    writeStartElement("VariablePackage");
    LuaInterface * lI = pT->getLuaInterface();
    VarUnit * vu = lI->getVarUnit();
    //do hidden variables first
    writeStartElement("HiddenVariables");
    QSetIterator<QString> it8( vu->hiddenByUser );
    while( it8.hasNext() )
    {
        writeTextElement( "name", it8.next() );
    }
    writeEndElement();
    TVar * base = vu->getBase();
    QListIterator<TVar *> it7( base->getChildren() );
    while( it7.hasNext() )
    {
        TVar * var = it7.next();
        writeVariable( var, lI, vu );
    }
    writeEndElement();

    return ret;
}
Exemplo n.º 10
0
static void prim()
{
	switch (currTok)
	{
		case tEnd:
			break;
		case tFunc:
			calcFunc();
			getToken();
			break;
		case tVar:
			put(MCODE_OP_PUSHVAR);
			putstr(nameString);
			getToken();
			break;
		case tConst:
			put(MCODE_OP_PUSHCONST);
			putstr(nameString);
			getToken();
			break;
		case tInt:
			put(MCODE_OP_PUSHINT);
			put64(currVar.i());
			getToken();
			break;
		case tFloat:
			put(MCODE_OP_PUSHFLOAT);
			putDouble(currVar.d());
			getToken();
			break;
		case tFARVar:
			put(FARVar); // nFARVar получаем в getToken()
			getToken();
			break;
		case tStr:
			put(MCODE_OP_PUSHSTR);
			putstr(currVar.s());
			getToken();
			break;
		case tMinus:
			getToken();
			prim();
			put(MCODE_OP_NEGATE);
			break;
		case tBitNot:
			getToken();
			prim();
			put(MCODE_OP_BITNOT);
			break;
		case tNot:
			getToken();
			prim();
			put(MCODE_OP_NOT);
			break;
		case tLp:
			getToken();
			expr();

			if (currTok != tRp)
				keyMacroParseError(err_Expected_Token, L")");

			getToken();
			break;
		case tRp: //???
			break;
		default:
			keyMacroParseError(err_Expr_Expected);
			break;
	}
}
Exemplo n.º 11
0
static TToken getToken()
{
	oSrcString = sSrcString;
	int ch = getNextChar();
	bool verbStr=false;

	switch (ch)
	{
		case EOFCH:
		case 0:    currTok = tEnd;    break;
		case L',': currTok = tComma;  break;
		case L'+': currTok = tPlus;   break;
		case L'-': currTok = tMinus;  break;
		case L'*': currTok = tMul;    break;
		case L'/': currTok = tDiv;    break;
		case L'(': currTok = tLp;     break;
		case L')': currTok = tRp;     break;
		case L'^':

			if ((ch = getChar()) == L'^')
				currTok = tBoolXor;
			else
			{
				putBack(ch);
				currTok = tBitXor;
			}

			break;
		case L'~':

			if ((ch = getChar()) != L' ')
			{
				putBack(ch);
				currTok = tBitNot;
				break;
			}

			putBack(ch);   //????
			currTok = tEnd;
			break;
		case L'|':

			if ((ch = getChar()) == L'|')
				currTok = tBoolOr;
			else
			{
				putBack(ch);
				currTok = tBitOr;
			}

			break;
		case L'&':

			if ((ch = getChar()) == L'&')
				currTok = tBoolAnd;
			else
			{
				putBack(ch);
				currTok = tBitAnd;
			}

			break;
		case L'=':

			if ((ch = getChar()) == L'=')
				currTok = tEq;
			else
			{
				putBack(ch);
				currTok = tLet;
			}

			break;
		case L'>':

			switch ((ch = getChar()))
			{
				case L'=': currTok = tGe;     break;
				case L'>': currTok = tBitShr; break;
				default:
					putBack(ch);
					currTok = tGt;
					break;
			}

			break;
		case L'<':

			switch (ch = getChar())
			{
				case L'=': currTok = tLe;     break;
				case L'<': currTok = tBitShl; break;
				default:
					putBack(ch);
					currTok = tLt;
					break;
			}

			break;
		case L'!':

			if ((ch = getChar()) != L'=')
			{
				putBack(ch);
				currTok = tNot;
				break;
			}
			else
				currTok = tNe;

			break;

		case L'@':

			ch = getChar();
			if (ch != L'"')
			{
				putBack(ch);
				break;
			}
			verbStr=true;

    	case L'\"':
		{
			TToken __currTok = tNo;
			currVar = L"";

			while (((ch = getChar()) != EOFCH))
			{
				if (ch == L'\"')
				{
					if (verbStr)
					{
						ch = getChar();
						if (ch != L'\"')
						{
							putBack(ch);
							break;
						}
					}
					else
						break;
				}

				if (ch == L'\\' && !verbStr)
				{
					switch (ch = getChar())
					{
						case L'a' : ch = L'\a'; break;
						case L'b' : ch = L'\b'; break;
						case L'f' : ch = L'\f'; break;
						case L'n' : ch = L'\n'; break;
						case L'r' : ch = L'\r'; break;
						case L't' : ch = L'\t'; break;
						case L'v' : ch = L'\v'; break;
						case L'\'': ch = L'\''; break;
						case L'\"': ch = L'\"'; break;
						case L'\\': ch = L'\\'; break;
						case L'0': case L'1': case L'2': case L'3': case L'4': case L'5': case L'6': case L'7': // octal: \d \dd \ddd
						{
							BYTE n = ch - L'0';

							if ((unsigned int)(ch = getChar()) >= L'0' && (unsigned int)ch < L'8')
							{
								n = 8 * n + ch - L'0';

								if ((unsigned int)(ch = getChar()) >= L'0' && (unsigned int)ch < L'8')
									n = 8 * n + ch - L'0';
								else
									putBack(ch);
							}
							else
								putBack(ch);

							ch = n;
							break;
						}
						case L'x':
						{
							if (iswxdigit(ch = getChar()))
							{
								wchar_t value=hex2ch(ch);

								for (int ii=0; ii<3; ii++)
								{
									if (iswxdigit(ch = getChar()))
									{
										value=(value<<4)|hex2ch(ch);
									}
									else
									{
										putBack(ch);
										break;
									}
								}

								ch = value;
							}
							else
							{
								keyMacroParseError(err_Bad_Hex_Control_Char,--sSrcString,pSrcString);
								__currTok = tEnd;
							}

							break;
						}
						default:
						{
							keyMacroParseError(err_Bad_Control_Char,--sSrcString,pSrcString);
							__currTok = tEnd;
							break;
						}
					}
				}

				if (__currTok != tNo)
					break;

				currVar.AppendStr((wchar_t)ch);
			}

			if (__currTok == tNo)
				currTok = tStr;
			else
				currTok = __currTok;

			break;
		}
		case L'.':
		{
			ch = getChar();

			if (iswdigit(ch))
			{
				putBack(ch);
				ch=L'.';
			}
			else
			{
				currTok = tEnd; //???
				break;
			}
		}
		case L'0': case L'1': case L'2': case L'3': case L'4':
		case L'5': case L'6': case L'7': case L'8': case L'9':
		{
			static wchar_t buffer[256];
			wchar_t *ptrbuffer=buffer;
			bool isNum   = false;
			bool isHex   = false;
			bool isE     = false;
			bool isPoint = false;
			int ch2;

			for (;;)
			{
				*ptrbuffer++=(wchar_t)ch;

				switch (ch)
				{
					case L'x':
					case L'X':

						if (ptrbuffer == buffer + 2)
						{
							ch = getChar();

							if (iswxdigit(ch))
							{
								isHex=true;
								putBack(ch);
							}
							else
							{
								putBack(ch);
								isNum=true;
								break;
							}
						}

						break;
					case L'.':

						if (isPoint || isE)
						{
							isNum=true;
							break;
						}

						isPoint=true;
						break;
					case L'e':
					case L'E':

						if (isHex)
							break;

						if (isE)
						{
							isNum=true;
							break;
						}

						isE=true;
						ch2 = getChar();

						if (ch2 == L'-' || ch2 == L'+')
						{
							int ch3=getChar();

							if (iswdigit(ch3))
							{
								*ptrbuffer++=(wchar_t)ch2;
								*ptrbuffer++=(wchar_t)ch3;
							}
							else
							{
								putBack(ch3);  // !iswdigit
								putBack(ch2);  // -+
								putBack(ch);   // eE
							}
						}
						else if (!iswdigit(ch2))
						{
							putBack(ch2); // !iswdigit
							putBack(ch);  // eE
						}
						else
							putBack(ch);

						break;
					case L'a': case L'A':
					case L'b': case L'B':
					case L'c': case L'C':
					case L'd': case L'D':
					case L'f': case L'F':

						if (!isHex)
						{
							isNum=true;
							break;
						}

					case L'0': case L'1': case L'2': case L'3': case L'4':
					case L'5': case L'6': case L'7': case L'8': case L'9':
						//isNum=true;
						break;
					default:
						isNum=true;
						break;
				}

				if (isNum)
					break;

				ch = getChar();
			}

			if (ch != EOFCH)
				putBack(ch);

			*ptrbuffer++=(wchar_t)0;
			bool CheckIntNumber=true;

			if (buffer[0])
			{
				if (!(buffer[1] == L'x' || buffer[1] == L'X'))
				{
					for (ptrbuffer=buffer; *ptrbuffer ; ptrbuffer++)
					{
						if (*ptrbuffer == L'e' || *ptrbuffer == L'E' || *ptrbuffer == L'.')
						{
							CheckIntNumber=false;
							break;
						}
						else if (!iswdigit(*ptrbuffer))
							break;
					}
				}
			}
			else
				CheckIntNumber=false;

			if (CheckIntNumber)
			{
				currVar = _wcstoi64(buffer,&ptrbuffer,0);
				currTok = tInt;
			}
			else
			{
				currVar = wcstod(buffer,&ptrbuffer);
				currTok = tFloat;
			}

			break;
		}
		case L'%':
			ch = getChar();

			if ((IsAlphaNum(ch) || ch == L'_') || (ch == L'%'  && (IsAlphaNum(*sSrcString) || *sSrcString == L'_')))
			{
				getVarName(ch);
				putBack(ch);
				currTok = tVar;
			}
			else
				keyMacroParseError(err_Var_Expected,L""); // BUG nameString

			break;
		default:
		{
			if (IsAlpha(ch))   // || ch == L'_' ????
			{
				TToken __currTok = tNo;
				getFarName(ch);

				if (ch == L' ')
				{
					while (ch == L' ')
						ch = getNextChar();
				}

				if (ch == L'(')   //!!!! а пробелы пропустить? ДА!
					__currTok = tFunc;
				else
				{
					putBack(ch);

					for (int i = 0 ; i < MKeywordsSize ; i++)
						if (!StrCmpI(nameString, MKeywords[i].Name))
						{
							FARVar = MKeywords[i].Value;
							__currTok = tFARVar;
							break;
						}

					if (__currTok == tNo)
					{
						if (IsProcessFunc || currTok == tFunc || currTok == tLt) // TODO: уточнить
						{
							if (KeyNameMacroToKey(nameString) == -1 && KeyNameToKey(nameString) == -1 && checkMacroConst(nameString))
								__currTok = tConst;
							else
							{
								DWORD k=KeyNameToKey(nameString);

								if (k != (DWORD)-1)
								{
									currVar = (__int64)k;
									__currTok = tInt; //??
								}
								else
								{
									keyMacroParseError(err_Var_Expected,oSrcString,pSrcString,nameString);
								}
							}
						}
						else
						{
							if (KeyNameMacroToKey(nameString) == -1)
							{
								if (KeyNameToKey(nameString) == -1)
								{
									if (checkMacroConst(nameString))
										__currTok = tConst;
									else
										keyMacroParseError(err_Unrecognized_keyword,nameString);
								}
								else
								{
									currVar = (__int64)KeyNameToKey(nameString);
									__currTok = tInt; //??
								}
							}
						}
					}
				}

				if (__currTok != tNo)
					currTok=__currTok;
			}
			else
				currTok = tEnd;

			break;
		}
	}

	return currTok;
}
Exemplo n.º 12
0
bool XMLexport::writeHost(Host* pHost)
{
    bool isOk = true;
    writeStartElement("Host");

    writeAttribute("autoClearCommandLineAfterSend", pHost->mAutoClearCommandLineAfterSend ? "yes" : "no");
    writeAttribute("disableAutoCompletion", pHost->mDisableAutoCompletion ? "yes" : "no");
    writeAttribute("printCommand", pHost->mPrintCommand ? "yes" : "no");
    writeAttribute("USE_IRE_DRIVER_BUGFIX", pHost->mUSE_IRE_DRIVER_BUGFIX ? "yes" : "no");
    writeAttribute("mUSE_FORCE_LF_AFTER_PROMPT", pHost->mUSE_FORCE_LF_AFTER_PROMPT ? "yes" : "no");
    writeAttribute("mUSE_UNIX_EOL", pHost->mUSE_UNIX_EOL ? "yes" : "no");
    writeAttribute("mNoAntiAlias", pHost->mNoAntiAlias ? "yes" : "no");
    writeAttribute("mEchoLuaErrors", pHost->mEchoLuaErrors ? "yes" : "no");
    // FIXME: Change to a string or integer property when possible to support more
    // than false (perhaps 0 or "PlainText") or true (perhaps 1 or "HTML") in the
    // future - phpBB code might be useful if it can be done.
    writeAttribute("mRawStreamDump", pHost->mIsNextLogFileInHtmlFormat ? "yes" : "no");
    writeAttribute("mIsLoggingTimestamps", pHost->mIsLoggingTimestamps ? "yes" : "no");
    writeAttribute("mAlertOnNewData", pHost->mAlertOnNewData ? "yes" : "no");
    writeAttribute("mFORCE_NO_COMPRESSION", pHost->mFORCE_NO_COMPRESSION ? "yes" : "no");
    writeAttribute("mFORCE_GA_OFF", pHost->mFORCE_GA_OFF ? "yes" : "no");
    writeAttribute("mFORCE_SAVE_ON_EXIT", pHost->mFORCE_SAVE_ON_EXIT ? "yes" : "no");
    writeAttribute("mEnableGMCP", pHost->mEnableGMCP ? "yes" : "no");
    writeAttribute("mEnableMSDP", pHost->mEnableMSDP ? "yes" : "no");
    writeAttribute("mMapStrongHighlight", pHost->mMapStrongHighlight ? "yes" : "no");
    writeAttribute("mLogStatus", pHost->mLogStatus ? "yes" : "no");
    writeAttribute("mEnableSpellCheck", pHost->mEnableSpellCheck ? "yes" : "no");
    writeAttribute("mShowInfo", pHost->mShowInfo ? "yes" : "no");
    writeAttribute("mAcceptServerGUI", pHost->mAcceptServerGUI ? "yes" : "no");
    writeAttribute("mMapperUseAntiAlias", pHost->mMapperUseAntiAlias ? "yes" : "no");
    writeAttribute("mFORCE_MXP_NEGOTIATION_OFF", pHost->mFORCE_MXP_NEGOTIATION_OFF ? "yes" : "no");
    writeAttribute("mRoomSize", QString::number(pHost->mRoomSize, 'f', 1));
    writeAttribute("mLineSize", QString::number(pHost->mLineSize, 'f', 1));
    writeAttribute("mBubbleMode", pHost->mBubbleMode ? "yes" : "no");
    writeAttribute("mShowRoomIDs", pHost->mShowRoomID ? "yes" : "no");
    writeAttribute("mShowPanel", pHost->mShowPanel ? "yes" : "no");
    writeAttribute("mHaveMapperScript", pHost->mHaveMapperScript ? "yes" : "no");
    QString ignore;
    QSetIterator<QChar> it(pHost->mDoubleClickIgnore);
    while (it.hasNext()) {
        ignore = ignore.append(it.next());
    }
    writeAttribute("mDoubleClickIgnore", ignore);

    { // Blocked so that indentation reflects that of the XML file
        writeTextElement("name", pHost->mHostName);

        writeStartElement("mInstalledPackages");
        for (int i = 0; i < pHost->mInstalledPackages.size(); ++i) {
            writeTextElement("string", pHost->mInstalledPackages.at(i));
        }
        writeEndElement(); // </mInstalledPackages>

        if (pHost->mInstalledModules.size()) {
            writeStartElement("mInstalledModules");
            QMapIterator<QString, QStringList> it(pHost->mInstalledModules);
            pHost->modulesToWrite.clear();
            while (it.hasNext()) {
                it.next();
                writeTextElement("key", it.key());
                QStringList entry = it.value();
                writeTextElement("filepath", entry.at(0));
                writeTextElement("globalSave", entry.at(1));
                if (entry.at(1).toInt()) {
                    pHost->modulesToWrite.insert(it.key(), entry);
                }
                writeTextElement("priority", QString::number(pHost->mModulePriorities.value(it.key())));
            }
            writeEndElement(); // </mInstalledModules>
        }
// CHECK: Do we need:
//        else {
//            writeEmptyElement( "mInstalledModules" ); // i.e. <mInstalledModules />
//        }

        writeTextElement("url", pHost->mUrl);
        writeTextElement("serverPackageName", pHost->mServerGUI_Package_name);
        writeTextElement("serverPackageVersion", QString::number(pHost->mServerGUI_Package_version));
        writeTextElement("port", QString::number(pHost->mPort));
        writeTextElement("borderTopHeight", QString::number(pHost->mBorderTopHeight));
        writeTextElement("borderBottomHeight", QString::number(pHost->mBorderBottomHeight));
        writeTextElement("borderLeftWidth", QString::number(pHost->mBorderLeftWidth));
        writeTextElement("borderRightWidth", QString::number(pHost->mBorderRightWidth));
        writeTextElement("wrapAt", QString::number(pHost->mWrapAt));
        writeTextElement("wrapIndentCount", QString::number(pHost->mWrapIndentCount));
        writeTextElement("mFgColor", pHost->mFgColor.name());
        writeTextElement("mBgColor", pHost->mBgColor.name());
        writeTextElement("mCommandFgColor", pHost->mCommandFgColor.name());
        writeTextElement("mCommandBgColor", pHost->mCommandBgColor.name());
        writeTextElement("mCommandLineFgColor", pHost->mCommandLineFgColor.name());
        writeTextElement("mCommandLineBgColor", pHost->mCommandLineBgColor.name());
        writeTextElement("mBlack", pHost->mBlack.name());
        writeTextElement("mLightBlack", pHost->mLightBlack.name());
        writeTextElement("mRed", pHost->mRed.name());
        writeTextElement("mLightRed", pHost->mLightRed.name());
        writeTextElement("mBlue", pHost->mBlue.name());
        writeTextElement("mLightBlue", pHost->mLightBlue.name());
        writeTextElement("mGreen", pHost->mGreen.name());
        writeTextElement("mLightGreen", pHost->mLightGreen.name());
        writeTextElement("mYellow", pHost->mYellow.name());
        writeTextElement("mLightYellow", pHost->mLightYellow.name());
        writeTextElement("mCyan", pHost->mCyan.name());
        writeTextElement("mLightCyan", pHost->mLightCyan.name());
        writeTextElement("mMagenta", pHost->mMagenta.name());
        writeTextElement("mLightMagenta", pHost->mLightMagenta.name());
        writeTextElement("mWhite", pHost->mWhite.name());
        writeTextElement("mLightWhite", pHost->mLightWhite.name());
        writeTextElement("mDisplayFont", pHost->mDisplayFont.toString());
        writeTextElement("mCommandLineFont", pHost->mCommandLineFont.toString());
        // There was a mis-spelt duplicate commandSeperator above but it is now gone
        writeTextElement("mCommandSeparator", pHost->mCommandSeparator);
        writeTextElement("commandLineMinimumHeight", QString::number(pHost->commandLineMinimumHeight));

        writeTextElement("mFgColor2", pHost->mFgColor_2.name());
        writeTextElement("mBgColor2", pHost->mBgColor_2.name());
        writeTextElement("mBlack2", pHost->mBlack_2.name());
        writeTextElement("mLightBlack2", pHost->mLightBlack_2.name());
        writeTextElement("mRed2", pHost->mRed_2.name());
        writeTextElement("mLightRed2", pHost->mLightRed_2.name());
        writeTextElement("mBlue2", pHost->mBlue_2.name());
        writeTextElement("mLightBlue2", pHost->mLightBlue_2.name());
        writeTextElement("mGreen2", pHost->mGreen_2.name());
        writeTextElement("mLightGreen2", pHost->mLightGreen_2.name());
        writeTextElement("mYellow2", pHost->mYellow_2.name());
        writeTextElement("mLightYellow2", pHost->mLightYellow_2.name());
        writeTextElement("mCyan2", pHost->mCyan_2.name());
        writeTextElement("mLightCyan2", pHost->mLightCyan_2.name());
        writeTextElement("mMagenta2", pHost->mMagenta_2.name());
        writeTextElement("mLightMagenta2", pHost->mLightMagenta_2.name());
        writeTextElement("mWhite2", pHost->mWhite_2.name());
        writeTextElement("mLightWhite2", pHost->mLightWhite_2.name());
        writeTextElement("mSpellDic", pHost->mSpellDic);
        // TODO: Consider removing these sub-elements that duplicate the same
        // attributes - which WERE bugged - when we update the XML format, must leave
        // them in place for now even though we no longer use them for compatibility
        // with older version of Mudlet
        writeTextElement("mLineSize", QString::number(pHost->mLineSize, 'f', 1));
        writeTextElement("mRoomSize", QString::number(pHost->mRoomSize, 'f', 1));

        writeEndElement(); // </Host>
    }

    writeEndElement(); // </HostPackage>

    if (hasError()) {
        isOk = false;
    }

    // Use if() to block each XXXXPackage element to limit scope of iterator so
    // we can use more of the same code in each block - and to escape quicker on
    // error...
    if (isOk) {
        writeStartElement("TriggerPackage");
        for (auto it = pHost->mTriggerUnit.mTriggerRootNodeList.begin(); isOk && it != pHost->mTriggerUnit.mTriggerRootNodeList.end(); ++it) {
            if (!(*it) || (*it)->mModuleMember) {
                continue;
            }
            if (!(*it)->isTempTrigger()) {
                if (!writeTrigger(*it)) {
                    isOk = false;
                }
            }
        }
        writeEndElement(); // </TriggerPackage>
    }

    if (isOk) {
        writeStartElement("TimerPackage");
        for (auto it = pHost->mTimerUnit.mTimerRootNodeList.begin(); isOk && it != pHost->mTimerUnit.mTimerRootNodeList.end(); ++it) {
            if (!(*it) || (*it)->mModuleMember) {
                continue;
            }
            if (!(*it)->isTempTimer()) {
                if (!writeTimer(*it)) {
                    isOk = false;
                }
            }
        }
        writeEndElement(); // </TimerPackage>
    }

    if (isOk) {
        writeStartElement("AliasPackage");
        for (auto it = pHost->mAliasUnit.mAliasRootNodeList.begin(); isOk && it != pHost->mAliasUnit.mAliasRootNodeList.end(); ++it) {
            if (!(*it) || (*it)->mModuleMember) {
                continue;
            }
            if (!(*it)->isTempAlias()) {
                if (!writeAlias(*it)) {
                    isOk = false;
                }
            }
        }
        writeEndElement(); // </AliasPackage>
    }

    if (isOk) {
        writeStartElement("ActionPackage");
        for (auto it = pHost->mActionUnit.mActionRootNodeList.begin(); isOk && it != pHost->mActionUnit.mActionRootNodeList.end(); ++it) {
            if (!(*it) || (*it)->mModuleMember) {
                continue;
            }
            if (!writeAction(*it)) {
                isOk = false;
            }
        }
        writeEndElement(); // </ActionPackage>
    }

    if (isOk) {
        writeStartElement("ScriptPackage");
        for (auto it = pHost->mScriptUnit.mScriptRootNodeList.begin(); isOk && it != pHost->mScriptUnit.mScriptRootNodeList.end(); ++it) {
            if (!(*it) || (*it)->mModuleMember) {
                continue;
            }
            if (!writeScript(*it)) {
                isOk = false;
            }
        }
        writeEndElement(); // </ScriptPackage>
    }

    if (isOk) {
        writeStartElement("KeyPackage");
        for (auto it = pHost->mKeyUnit.mKeyRootNodeList.begin(); isOk && it != pHost->mKeyUnit.mKeyRootNodeList.end(); ++it) {
            if (!(*it) || (*it)->mModuleMember) {
                continue;
            }
            if (!writeKey(*it)) {
                isOk = false;
            }
        }
        writeEndElement(); // </KeyPackage>
    }

    if (isOk) {
        writeStartElement("VariablePackage");
        LuaInterface* lI = pHost->getLuaInterface();
        VarUnit* vu = lI->getVarUnit();
        //do hidden variables first
        { // Blocked so that indentation reflects that of the XML file
            writeStartElement("HiddenVariables");
            QSetIterator<QString> itHiddenVariableName(vu->hiddenByUser);
            while (itHiddenVariableName.hasNext()) {
                writeTextElement("name", itHiddenVariableName.next());
            }
            writeEndElement(); // </HiddenVariables>
        }

        TVar* base = vu->getBase();
        if (!base) {
            lI->getVars(false);
            base = vu->getBase();
        }

        if (base) {
            QListIterator<TVar*> itVariable(base->getChildren(false));
            while (isOk && itVariable.hasNext()) {
                if (!writeVariable(itVariable.next(), lI, vu)) {
                    isOk = false;
                }
            }
        }
        writeEndElement(); // </VariablePackage>
    }

    return (isOk && (!hasError()));
}