void exec_line( char* line, char* end )
{
	int token_count = tokenise_line( line, end, NULL, 0 );
	if( token_count >  0 )
	{
		char** argv = malloc( sizeof(char*) * token_count );
		tokenise_line( line, end, argv, token_count );
		//match command against cmd list
		unsigned short i = 0;
		for( ; i < CMDS_SIZE; i++ )
		{
			if( strcmp( commands[i].command, argv[0] ) == 0)
			{
				commands[i].exec( telnet_handle, argv, token_count);
				break;
			}
		}
		if(  i == CMDS_SIZE ) //fell out of loop without a match
		{
			file_puts("Unknown command: ", telnet_handle);
			file_puts(argv[0], telnet_handle );
			file_puts(CRLF, telnet_handle );
		}
		free( argv );
	}
}
Beispiel #2
0
void Processor::z_read() {
	zchar buffer[INPUT_BUFFER_SIZE];
	zword addr;
	zchar key;
	zbyte max, size;
	zbyte c;
	int i;

	// Supply default arguments
	if (zargc < 3)
		zargs[2] = 0;

	// Get maximum input size
	addr = zargs[0];

	LOW_BYTE(addr, max);

	if (h_version <= V4)
		max--;

	if (max >= INPUT_BUFFER_SIZE)
		max = INPUT_BUFFER_SIZE - 1;

	// Get initial input size
	if (h_version >= V5) {
		addr++;
		LOW_BYTE(addr, size);
	} else {
		size = 0;
	}

	// Copy initial input to local buffer
	for (i = 0; i < size; i++) {
		addr++;
		LOW_BYTE(addr, c);
		buffer[i] = translate_from_zscii(c);
	}
	buffer[i] = 0;

	// Draw status line for V1 to V3 games
	if (h_version <= V3)
		z_show_status();

	// Read input from current input stream
	key = stream_read_input(
		max, buffer,		// buffer and size
		zargs[2],			// timeout value
		zargs[3],			// timeout routine
		false,				// enable hot keys
		h_version == V6		// no script in V6
	);

	if (key == ZC_BAD)
		return;

	// Perform save_undo for V1 to V4 games
	if (h_version <= V4)
		save_undo();

	// Copy local buffer back to dynamic memory
	for (i = 0; buffer[i] != 0; i++) {
		if (key == ZC_RETURN) {
			buffer[i] = unicode_tolower (buffer[i]);
		}

		storeb((zword)(zargs[0] + ((h_version <= V4) ? 1 : 2) + i), translate_to_zscii(buffer[i]));
	}

	// Add null character (V1-V4) or write input length into 2nd byte
	if (h_version <= V4)
		storeb((zword)(zargs[0] + 1 + i), 0);
	else
		storeb((zword)(zargs[0] + 1), i);

	// Tokenise line if a token buffer is present
	if (key == ZC_RETURN && zargs[1] != 0)
		tokenise_line (zargs[0], zargs[1], 0, false);

	// Store key
	if (h_version >= V5)
		store(translate_to_zscii(key));
}