Пример #1
0
void DungeonQuest::processInput(std::string& input) {
    std::string cmd;
    std::string arg;
    splitInput(input, cmd, arg);

    if(cmd == "quit") {
        stop();
        return;
    }

    if(cmd == "walk") {
        m_player->walk(arg);
        displayLocation();
    }

    if(cmd == "loot") {
        m_player->loot();
    }

    if(cmd == "inventory") {
        m_player->displayInventory();
    }

    if(cmd == "attack") {
        m_player->attack();
    }
}
int main(void)
{
    // Initialization.
    int numArr[11] , pos = 0;
    int arrSize = sizeof(numArr) / sizeof(int);
    char number[11];

    // Take input.
    printf("Enter your number > ");
    scanf("%s", number);
    splitInput(numArr, arrSize, number);

    // Display our Current array.
    printf("Our Current Array: ");
    displayarr(arrSize, numArr);

    // Shifting the non zero numbers to front.
    for(int i = 0; i < arrSize; i++){
        if(numArr[i] != 0){             // Checking if it is a non-zero number.
            numArr[pos] = numArr[i];    // Putting the non-zero number in position of our cursor.
            numArr[i] = 0;              // Putting zero in the previous place of the non-zero number.
            pos++;                      // Setting our cursor to the next position.
        }
    }
    displayarr(arrSize, numArr);        // Display our sorted array.
}
Пример #3
0
void QPxIODevice::setIODevice(QIODevice* iio)
{
#ifdef QPXIO_DEBUG
	qDebug("STA: QPxIODevice::setIODevice()");
#endif
	buf = "";
	io = iio;
	if (io) {
		if ( typeid(*io) == typeid(QProcess) )
			connect(io, SIGNAL(readyReadStandardOutput()), this, SLOT(splitInput()));
		else if ( typeid(*io) == typeid(QTcpSocket) )
			connect(io, SIGNAL(readyRead()), this, SLOT(splitInput()));
	}
#ifdef QPXIO_DEBUG
	qDebug("END: QPxIODevice::setIODevice()");
#endif
}
Пример #4
0
/* Assemble function to use the others to generate the actual object code. Starts by splitting the input string into its components, then find out which operation is to be performed.  This will determine the number of registers involved and whether there's an address or a constant, and Assemble calls the some combination of the three functions above based on that. At the end, we sum all of the parts of object_code together to get the decimal representation.  Note that the components that are unused for that operation are initialized to 0 in the constructor, and will not affect this sum. */
std::string Assembler::Assemble(std::string inputProgram){
	ofstream objFile;

	getInput(inputProgram);
	outputFile(inputProgram);
	objFile.open(outFile);
	for (int i = 0; i < assemblyInstructs.size()-1; i++){
		isAddr = 0;
		immediate = 0;
		addr = 0;
		destReg = 0;
		srcReg = 0;
		splitInput(assemblyInstructs[i], instructParts);
        if (invalidNumArguments == 1){
            object_code = -1;
			invalidNumArguments = 0;
        }
        getOperation(instructParts.at(0));
        if (invalidInstruct == 1){
            object_code = -1;
			invalidInstruct = 0;
        }
        if (numRegisters > 0){
            getDestRegister(instructParts.at(1));
            if (numRegisters == 2){
                getSrcRegister(instructParts.at(2));
            }
        }
        if (invalidRegister == 1){
            object_code = -1;
			invalidRegister = 0;
        }
        if ((isAddr == 1)||(isConst==1)){
            if (numRegisters == 1){
                getAddressOrConstant(instructParts.at(2));
            }
            else {
                getAddressOrConstant(instructParts.at(1));
            }
			isAddr = 0;
			isConst = 0;
        }
        if (invalidConstOrAddr==1){
            object_code = -1;
        }
		object_code = opcode + immediate + srcReg + destReg + addr;
		objFile << object_code << endl;
		instructParts.clear();
	}
    return outFile;
}
Пример #5
0
//handles all user input
userInput(){
	//Clear input fields
	command = NULL;
	memset(&input,'\0',sizeof(input));
	memset(&first,'\0',sizeof(first));
	memset(&second,'\0',sizeof(second));
	memset(&third,'\0',sizeof(third));

	//Take input from user
	printf("nsh3_WesJos$ ");
	fgets(input,80,stdin);


	commentfilter(input);//removes the text after a comment but not inside a complex string from a command.

	//Split the input the user provides
	splitInput(input);



	//Make sure command or alias exists
	if ((nshFind(alias,first) == NULL) && (nshFind(native,first) == NULL))
	{
		printf("\tCommand not found.\n");
		userInput();
	}
	else
	{
		//Checks if alias or native command passed fail test
		if (nshFind(alias,first) == NULL)
			command = nshFind(native,first);
		else
		{
			command = nshFind(alias,first);
			handleAlias(command->value);
		}
		//Check command
		if ((strcmp(command->value,"set")==0) || (strcmp(first,"set") == 0))
			commandSet(&var,second,third);
		if ((strcmp(command->value,"alias")==0) || (strcmp(first,"alias") == 0))
			commandSet(&alias,second,third);
		if ((strcmp(command->value,"tes") == 0) || (strcmp(first,"tes") == 0))
			nshDelete(&var,second);
		if ((strcmp(command->value,"saila") == 0) || (strcmp(first,"saila") == 0))
			nshDelete(&alias,second);
		if ((strcmp(command->value,"exit") == 0) || (strcmp(first,"exit") == 0))
			cont = 0;
	}

}
Пример #6
0
std::vector<Token> Parser::tokenize()
{
	std::vector<Token> tokens;

	spacifyInput();
	std::vector<std::string> words = splitInput();

	int i = 0;
	while (i < words.size()) {
		if (words[i] == "\\") {
			if (i+1 >= words.size())
				throw std::runtime_error("Invalid token");

			if (words[i+1] == "pi") {
				tokens.push_back(Token{CMD_BEG, "pi"});
				tokens.push_back(Token{CMD_END, ""});
				i += 2;
			} else {
				if (i+2 >= words.size() ||
					words[i+2] != "{" ||
					!validCommand(words[i+1]))
					throw std::runtime_error("Invalid token");
				tokens.push_back(Token{CMD_BEG, words[i+1]});
				i += 3;
			}
		} else if (words[i] == "{") {
			tokens.push_back(Token{CMD_CNT, ""});
			i++;
		} else if (words[i] == "}") {
			tokens.push_back(Token{CMD_END, ""});
			i++;
		} else if (words[i] == "^" || words[i] == "_") {
			if (i+1 >= words.size() || words[i+1] != "{")
				throw std::runtime_error("Invalid token");
			tokens.push_back(Token{CMD_BEG, words[i]});
			i += 2;
		} else {
			/* Default case: treat word as raw token */
			tokens.push_back(Token{RAW, words[i]});
			i++;
		}
	}

	return tokens;
}
Пример #7
0
void _PlanOperation::refreshInput() {
  /*
    size_t numberOfDependencies = getDependencyCount();
    addDependencyPerformanceData(numberOfDependencies);
    for (size_t i = 0; i < numberOfDependencies; ++i)
    {
    _PlanOperation *dependency = getDependency<_PlanOperation>(i);
    input.mergeWith(dependency->output, true);
    }
  */
  size_t numberOfDependencies = _dependencies.size();
  for (size_t i = 0; i < numberOfDependencies; ++i) {
    const auto& dependency = std::dynamic_pointer_cast<_PlanOperation>(_dependencies[i]);
    input.mergeWith(dependency->output);
  }

  splitInput();
}
Пример #8
0
//Checks to see if an alias has a complex string as a value
handleAlias(char * calias){

	//If alias value leads with complex string symbol, process the function
	if(calias[0] == '{')
	{
		//Removes the leading '{'
		calias = calias + 1;

		//removes the '}'
		strtok(calias,"}");

		//Recombine the input to process again. Add spaces where appropriate
		strcat(calias," ");
		strcat(calias,second);
		strcat(calias," ");
		strcat(calias,third);

		//Process the modified input string
		splitInput(calias);
	}
}
Пример #9
0
void ParallelizablePlanOperation::refreshInput() {
  PlanOperation::refreshInput();
  splitInput();
}