Exemple #1
0
const char *Rowop::opcodeString(int code)
{
	const char *def = "?";
	const char *res = enum2string(opcodes, code, def);
	if (res == def) {
		// for the unknown opcodes, get at least the general sense
		if (isInsert(code) && isDelete(code))
			return "[ID]";
		else if (isInsert(code))
			return "[I]";
		else if (isDelete(code))
			return "[D]";
		else
			return "[NOP]";
	} else {
		return res;
	}
}
// Main processing loop for the shell
int main(int argc, char **argv) {
	printf("SMUsh Version 0.1.234\n");

	// Allocate outside of the loop for efficiency
	char *command = NULL;
	char *param1 = NULL;
	char *param2 = NULL;
	char sep[] = " ";
	char *result = NULL;
	char part[3][255] = {0};
	char input[256] = {0};

	// Begin the command processing loop
	while(true)
	{
		// Clear out the storage at the beginning of each loop
		int i = 0;
		input[0] = '\0';
		part[0][0] = '\0';
		part[1][0] = '\0';
		part[2][0] = '\0';
		
		// Capture command line input
		printf("SMUsh> ");
		scanf("%255[^\n]%*c", input);

		// parse the input into three separate arguments

		// Pull the first token from the input
		result = strtok(input, sep);

		// Loop through remaining tokens until there are none left
		while( result != NULL )
		{
			// Copy the result into the argument array
			strcpy(part[i],result);
			result = strtok( NULL, sep );
			i++;
		}

		// Transfer the parts into named storage
		command = part[0];
		param1 = part[1];
		param2 = part[2];

		// Evaluate the command types and pass the appropriate parameters
		if(isExit(command))
		{
			printf("Exiting... Thanks for using SMUsh - Scott's Shell.\n");
			break;
		}
		else if (isCopy(command))
		{
			copy(param1, param2);
		}
		else if (isDelete(command))
		{
			delete(param1);
		}
		else if (isType(command))
		{
			type(param1);
		}
		else if (isExecutable(command))
		{
			execute(command);
		}
		else
		{
			displayError(command);
		}
	}

	return 0;
}