Esempio n. 1
0
static const char *basic_gets(int *cnt)
{
	int x = 0;
#ifdef _MSC_VER
	int read, key;
	char keys[CMD_BUFLEN];
	HANDLE stdinHandle;
	if (global_profile->batch_mode) {
#endif
	printf("%s", prompt_str);
	if (global_profile->batch_mode) fflush(stdout);
	memset(&command_buf, 0, sizeof(command_buf));
	for (x = 0; x < (sizeof(command_buf) - 1); x++) {
		int c = getchar();
		if (c < 0) {
			if (fgets(command_buf, sizeof(command_buf) - 1, stdin) != command_buf) {
				break;
			}
			command_buf[strlen(command_buf)-1] = '\0'; /* remove endline */
			break;
		}
		command_buf[x] = (char) c;
		if (command_buf[x] == '\n') {
			command_buf[x] = '\0';
			break;
		}
	}
	*cnt = x;
#ifdef _MSC_VER
	} else {
		stdinHandle = GetStdHandle(STD_INPUT_HANDLE);
		console_bufferInput (0, 0, prompt_str, PROMPT_OP);
		printf("%s", prompt_str);
		if (global_profile->batch_mode) fflush(stdout);
		*cnt = 0;
		memset(&command_buf, 0, sizeof(command_buf));
		while (!*cnt) {
			if (console_readConsole(stdinHandle, keys, (int)sizeof(keys), &read, &key)) {
				*cnt = console_bufferInput(keys, read, command_buf, key);
				if (global_profile->batch_mode) fflush(stdout);
				if (!strcmp(command_buf, "Empty")) {
					command_buf[0] = 0;
				}
			}
			sleep_ms(20);
		}
	}
#endif
	return command_buf;
}
Esempio n. 2
0
static const char *basic_gets(int *cnt)
{
#ifndef _MSC_VER
	int x = 0;

	printf("%s", prompt_str);

	memset(&command_buf, 0, sizeof(command_buf));
	for (x = 0; x < (sizeof(command_buf) - 1); x++) {
		int c = getchar();
		if (c < 0) {
			int y = read(fileno(stdin), command_buf, sizeof(command_buf) - 1);
			command_buf[y - 1] = '\0';
			break;
		}
		
		command_buf[x] = (char) c;
		
		if (command_buf[x] == '\n') {
			command_buf[x] = '\0';
			break;
		}
	}

	*cnt = x;
#else
	int read, key;
	char keys[CMD_BUFLEN];
	HANDLE stdinHandle = GetStdHandle(STD_INPUT_HANDLE);

	console_bufferInput (0, 0, prompt_str, PROMPT_OP);
	printf("%s", prompt_str);

	*cnt = 0;
	memset(&command_buf, 0, sizeof(command_buf));

	while (!*cnt) {
		if (console_readConsole(stdinHandle, keys, (int)sizeof(keys), &read, &key)) {
			*cnt = console_bufferInput(keys, read, command_buf, key);
			if (!strcmp(command_buf, "Empty")) {
				command_buf[0] = 0;
			}
		}
		Sleep(20);
	}

	return command_buf;
#endif
}
Esempio n. 3
0
static unsigned char esl_console_complete(const char *buffer, const char *cursor)
{
	char cmd_str[2048] = "";
	unsigned char ret = CC_REDISPLAY;
	char *dup = strdup(buffer);
	char *buf = dup;
	int pos = 0, sc = 0;
	char *p;

	if (!esl_strlen_zero(cursor) && !esl_strlen_zero(buffer)) {
		pos = (int)(cursor - buffer);
	}
	if (pos > 0) {
		*(buf + pos) = '\0';
	}

	if ((p = strchr(buf, '\r')) || (p = strchr(buf, '\n'))) {
		*p = '\0';
	}

	while (*buf == ' ') {
		buf++;
		sc++;
	}

#ifdef HAVE_EDITLINE
	if (!*buf && sc) {
		el_deletestr(el, sc);
	}
#endif

	sc = 0;

	p = end_of_p(buf);
	while(p >= buf && *p == ' ') {
		sc++;
		p--;
	}

#ifdef HAVE_EDITLINE
	if (sc > 1) {
		el_deletestr(el, sc - 1);
		*(p + 2) = '\0';
	}
#endif
	

	if (*cursor) {
		snprintf(cmd_str, sizeof(cmd_str), "api console_complete c=%ld;%s\n\n", (long)pos, buf);
	} else {
		snprintf(cmd_str, sizeof(cmd_str), "api console_complete %s\n\n", buf);
	}

	esl_send_recv(global_handle, cmd_str);


	if (global_handle->last_sr_event && global_handle->last_sr_event->body) {
		char *r = global_handle->last_sr_event->body;
		char *w, *p1;
		
		if (r) {
			if ((w = strstr(r, "\n\nwrite="))) {
				int len = 0;
				*w = '\0';
				w += 8;

				len = atoi(w);

				if ((p1= strchr(w, ':'))) {
					w = p1+ 1;
				}
				
				printf("%s\n\n\n", r);

#ifdef HAVE_EDITLINE
				el_deletestr(el, len);
				el_insertstr(el, w);
#else
#ifdef _MSC_VER
				console_bufferInput(0, len, (char*)buffer, DELETE_REFRESH_OP);
				console_bufferInput(w, (int)strlen(w), (char*)buffer, 0);
#endif
#endif
				
			} else {
				printf("%s\n", r);
#ifdef _MSC_VER
				console_bufferInput(0, 0, (char*)buffer, DELETE_REFRESH_OP);
#endif
			}
		}

		fflush(stdout);
	}	

	esl_safe_free(dup);

	return ret;
}