示例#1
0
static void DedicatedHandleKeyInput()
{
	static char input_line[1024] = "";

	if (!InputWaiting()) return;

	if (_exit_game) return;

#if defined(UNIX) || defined(__OS2__) || defined(PSP)
	if (fgets(input_line, lengthof(input_line), stdin) == NULL) return;
#else
	/* Handle console input, and singal console thread, it can accept input again */
	assert_compile(lengthof(_win_console_thread_buffer) <= lengthof(input_line));
	strecpy(input_line, _win_console_thread_buffer, lastof(input_line));
	SetEvent(_hWaitForInputHandling);
#endif

	/* strtok() does not 'forget' \r\n if the string starts with it,
	 * so we have to manually remove that! */
	strtok(input_line, "\r\n");
	for (char *c = input_line; *c != '\0'; c++) {
		if (*c == '\n' || *c == '\r' || c == lastof(input_line)) {
			*c = '\0';
			break;
		}
	}
	str_validate(input_line, lastof(input_line));

	IConsoleCmdExec(input_line); // execute command
}
示例#2
0
static void DedicatedHandleKeyInput()
{
	static char input_line[1024] = "";

	if (!InputWaiting()) return;

	if (_exit_game) return;

#if defined(UNIX) || defined(__OS2__) || defined(PSP)
	if (fgets(input_line, lengthof(input_line), stdin) == NULL) return;
#else
	/* Handle console input, and signal console thread, it can accept input again */
	assert_compile(lengthof(_win_console_thread_buffer) <= lengthof(input_line));
	strecpy(input_line, _win_console_thread_buffer, lastof(input_line));
	SetEvent(_hWaitForInputHandling);
#endif

	/* Remove trailing \r or \n */
	for (char *c = input_line; *c != '\0'; c++) {
		if (*c == '\n' || *c == '\r' || c == lastof(input_line)) {
			*c = '\0';
			break;
		}
	}
	str_validate(input_line, lastof(input_line));

	IConsoleCmdExec(input_line); // execute command
}
示例#3
0
文件: misc.c 项目: Cubitect/cep
// checks if input is in stdin
// if so it stops the search and stores the input in the global string 'intStr'
void CheckInput(searchinfo_t *sinfo)
{
	int i;

	if(InputWaiting()){
		sinfo->stop = true;

		for(i = 0; i < 128; i++){
			if(read(0, &intStr[i], 1) <= 0) break;
			if(intStr[i] == '\n'){
				intStr[i] = '\0';
				break;
			}
		}

		if(strstr(intStr, "quit") != NULL) sinfo->quit = true;
	}
}
示例#4
0
void ReadInput(S_SEARCHINFO *info) {

  int             bytes;

  char            input[256] = "", *endc;



    if (InputWaiting()) {    

    info->stopped = TRUE;

    do {

      bytes=read(fileno(stdin),input,256);

    } while (bytes<0);

    endc = strchr(input,'\n');

    if (endc) *endc=0;



    if (strlen(input) > 0) {

      if (!strncmp(input, "quit", 4))    {

        info->quit = TRUE;

      }

    }

    return;

    }

}