Beispiel #1
0
static void write_char(struct pty *pty, uint8_t c)
{
	if(c == '\n' && (pty->term.c_oflag & ONLCR)) {
		uint8_t d = '\r';
		charbuffer_write(&pty->output, &d, 1, false);
	}
	charbuffer_write(&pty->output, &c, 1, false);
}
Beispiel #2
0
static size_t pty_write_slave(struct pty *pty, uint8_t *buffer, size_t length, bool block)
{
	for(size_t i=0;i<length;i++) {
		if(*buffer == '\n' && (pty->term.c_oflag & ONLCR)) {
			charbuffer_write(&pty->output, (uint8_t *)"\r", 1, block);
		}
		charbuffer_write(&pty->output, buffer++, 1, block);
	}
	return length;
}
Beispiel #3
0
static size_t pty_write_master(struct pty *pty, uint8_t *buffer, size_t length, bool block)
{
	if(pty->term.c_lflag & ICANON) {
		mutex_acquire(&pty->cbuf_lock);
		for(size_t i = 0;i<length;i++) {
			process_input(pty, *buffer++);
		}
		mutex_release(&pty->cbuf_lock);
		return length;
	} else {
		if(pty->term.c_lflag & ECHO)
			charbuffer_write(&pty->output, buffer, length, block);
		return charbuffer_write(&pty->input, buffer, length, block);
	}
}
Beispiel #4
0
static void process_input(struct pty *pty, uint8_t c)
{
	if(pty->cbuf_pos < (PTY_CBUF_SIZE - 1)) {
		if(c == pty->term.c_cc[VINTR]) {
			__raise_action(pty, SIGINT);
			if(pty->term.c_lflag & ECHO) {
				write_char(pty, '^');
				write_char(pty, 'C');
				write_char(pty, '\n');
			}
		} else if(c == pty->term.c_cc[VERASE]) {
			if(pty->cbuf_pos > 0) {
				pty->cbuf[pty->cbuf_pos--] = 0;
				if(pty->term.c_lflag & ECHO) {
					write_char(pty, '\b');
					write_char(pty, ' ');
					write_char(pty, '\b');
				}
			}
		} else if(c == pty->term.c_cc[VSUSP]) {
			__raise_action(pty, SIGTSTP);
			if(pty->term.c_lflag & ECHO) {
				write_char(pty, '^');
				write_char(pty, 'Z');
				write_char(pty, '\n');
			}
		} else if(c == pty->term.c_cc[VEOF]) {
			if(pty->cbuf_pos > 0) {
				charbuffer_write(&pty->input, pty->cbuf, pty->cbuf_pos, true);
				pty->cbuf_pos = 0;
			} else {
				pty->input.eof = 1;
				tm_blocklist_wakeall(&pty->input.readers);
			}
		} else {
			if(c == 27) /* escape */
				c = '^';
			pty->cbuf[pty->cbuf_pos++] = c;
			if(pty->term.c_lflag & ECHO)
				write_char(pty, c);
			if(c == '\n') {
				charbuffer_write(&pty->input, pty->cbuf, pty->cbuf_pos, true);
				pty->cbuf_pos = 0;
			}
		}
	}
}
Beispiel #5
0
int putchar(int c)
{
	char tmp[2];
	tmp[0]=c;
	tmp[1]=0;
	charbuffer_write(tmp);
	return 1;
}
Beispiel #6
0
int puts(const char *str)
{
	charbuffer_write(str);
	return 0;
}