int main()
{
	int arr[] = {12, 1, 12, 3, 12, 1, 1, 2, 3, 2, 2, 3, 7};
	int n = sizeof(arr) / sizeof(arr[0]);
	printf("The element with single occurrence is %d ",
			getSingle(arr, n));
	return 0;
}
//功能:判断一条语句是否是带参数的宏定义语句
//返回值:是返回true
bool isComplexMacroDef(string test)
{
	string single[255] = {""};
	int slen = 0;
	string tempSingle[255] = {""};
	int templen = 0;
	slen = getSingle(test, single);

	if("#define" == single[0]) // 形如 #define MAX(a, b) ((a)*(b))
	{
		templen = covertCmd(single[1], tempSingle);  // 将带参的宏打散
		if(isIn("(", tempSingle, templen))   // 存左括号,说明这是一个带参的宏的定义
		{
			return true;
		}
	}
	return false;
}
//功能:不带参数的宏替换,#define MAX (100*100)
void macroSimpleReplace()
{
	int i, j, k;
	string macroName = "";
	string macroValue = "";

	int pos[10] = {-1};
	int posCount = -1;

	string temp = "";
	string single[255] = {""};
	int slen = 0;
	for(i=0; i<cmdCount; i++)
	{
		temp = command[i];
		slen = getSingle(temp, single);
		if("#define" == single[0] && 3 == slen) // 形如 #define MAX (100*100)
		{
			macroName = single[1];
			macroValue = single[2];

			for(j=i+1; j<cmdCount; j++)
			{
				temp = command[j];
				slen = covertCmd(temp, single);
				posCount = isContain(macroName, single, slen, pos);
				if(-1 != posCount) // 说明含有宏,要替换
				{
					for(k=0; k<posCount; k++)
					{
						single[pos[k]] = " " + macroValue + " ";
					}
					command[j] = "";
					//将替换后的字符串拼回命令行中
					for(k=0; k<slen; k++)
					{
						single[k] = " " + single[k] + " ";
						command[j] = command[j] + single[k];
					}
				}
			}
		}
	}
}
Exemple #4
0
bool SmartIODBox::nextCommand()
{
    if( p->queue.isEmpty() )
        return false;

    SmartIODBoxSingle *s = getSingle();
    if( !s )
        return false;

    p->actived = true;
    const SmartIODBoxCommand & cmd = p->queue.takeFirst();
    switch( static_cast<int>(cmd.command) )
    {
    case SmartIODBoxCommand::pushPaper:
        QMetaObject::invokeMethod(s, "pushPaper", Qt::QueuedConnection, Q_ARG(QString,cmd.uuid), Q_ARG(qint64,cmd.revision), Q_ARG(QString,cmd.dest) );
        break;
    case SmartIODBoxCommand::fetchPaper:
        QMetaObject::invokeMethod(s, "fetchPaper", Qt::QueuedConnection, Q_ARG(QString,cmd.uuid), Q_ARG(qint64,cmd.revision), Q_ARG(QString,cmd.path) );
        break;
    case SmartIODBoxCommand::pushFile:
        QMetaObject::invokeMethod(s, "pushFile", Qt::QueuedConnection, Q_ARG(QString,cmd.path), Q_ARG(QString,cmd.dest) );
        break;
    case SmartIODBoxCommand::fetchFile:
        QMetaObject::invokeMethod(s, "fetchFile", Qt::QueuedConnection, Q_ARG(QString,cmd.path), Q_ARG(QString,cmd.dest) );
        break;
    case SmartIODBoxCommand::pushGroups:
        QMetaObject::invokeMethod(s, "pushGroups", Qt::QueuedConnection, Q_ARG(QString,cmd.path), Q_ARG(qint64,cmd.revision) );
        break;
    case SmartIODBoxCommand::fetchGroups:
        QMetaObject::invokeMethod(s, "fetchGroups", Qt::QueuedConnection, Q_ARG(QString,cmd.path), Q_ARG(qint64,cmd.revision) );
        break;
    case SmartIODBoxCommand::setDeleted:
        QMetaObject::invokeMethod(s, "setDeleted", Qt::QueuedConnection, Q_ARG(QString,cmd.path) );
        break;
    default:
        p->threadsQueue << s;
        p->actived = false;
        break;
    }

    return p->actived;
}