当前位置: 首页>>代码示例>>C++>>正文


C++ Executer::setCount方法代码示例

本文整理汇总了C++中Executer::setCount方法的典型用法代码示例。如果您正苦于以下问题:C++ Executer::setCount方法的具体用法?C++ Executer::setCount怎么用?C++ Executer::setCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Executer的用法示例。


在下文中一共展示了Executer::setCount方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: execute

int Parser::execute()
{
	// If I use my imagination hard enough
	// this will magically work
	// every odd number is a connector (besides the last one);
	// 0 and even numbers are the commands
	int status = 0;	
	unsigned int i = 0;
	Executer E;

	// if user puts "ls test ||" or "echo test &&", etc
	// then prompt the user ">" and another command
	if ((cmd.size() != 1) && ((cmd.back() == "||") || (cmd.back() == "&&")))
	{
		string cmd;
		cout << ">";
		getline(cin, cmd);
		setCommand(cmd);
		parse();
	}

	//for(unsigned int i = 0; i < cmd.size(); i++)
	//	cout << i << ": " << cmd.at(i) << endl;

	//for(unsigned int i = 0; i < test.size(); i++)
	//	cout << test[i] << endl;

	//for(unsigned int i = 0; i < cmd.size(); i++)
	//	cout << cmd[i] << endl;

	// this loop analyzes the connectors
	// and determines what gets runned
	while(i < cmd.size())
	{
		E.setCount(i);						
		this->bPtr = &E;		

		status = bPtr->execute();			
		if(status == -1)		// if status is -1 then "exit was inputted"
		{						// so we want to exit rshell program
			return status;
		}
		// should on on connector now
		// b/c connectors are on odd numbers
		i++;	
		
		if(i >= cmd.size())
		{
			return status;
		}

		if(cmd.at(i) == ";")
		{
			//cout << "Before i++" << endl;
			i++;
			//cout << "After i++" << endl;
		}
		// if next one is && move to the next one if 
		// previous worked
		else if(cmd.at(i) == "&&")
		{
			// if previous worked
			if(status == 0)
			{
				i++;	 // go to the next command
			}
			else
			{
				i+=3;   // moves on to next connector		
			}
		}
		else if(cmd.at(i) == "||")
		{
			// if previous failed
			if(status == 149)
			{
				i++;	// go to the next command
			}
			else
			{
				i+=3;
			}
		}

		//cout << "i after everything: " << i << endl;
		if(isOdd(i) || i > cmd.size())
		{
			//cout << "goes here" << endl;
			return status;
		}
	}	
	return status;
}
开发者ID:nnguy072,项目名称:rshell,代码行数:93,代码来源:Parser.cpp


注:本文中的Executer::setCount方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。