#include "vc_struct.h"
#include "vt.h"
#include "tty.h"
#include "video_driver.h"
#include "tty_queue.h"
#include <verify_area.h>
#include <segment.h>
#include <errno.h>
#include <enums.h>
#include <util.h>
#define INTR 0003
#define QUIT 0034
#define ERASE 0177
#define KILL 0025
#define EOF 0004
#define TIME 0
#define MIN 1
#define START 0021
#define STOP 0023
#define SUSP 0032
#define EOL 0000
void vc_tty_do_output(struct tty_struct *tty, struct tty_queue_struct *tty_queue)
{
struct vc_struct *vc;
vc = downcast(struct vc_struct, tty, tty);
if (!tty_queue_is_empty(&vc->tty.output_queue)) {
vc->vt.driver->history_cancel();
vt_write(&vc->vt, &vc->tty.output_queue, &vc->tty);
}
}
void vc_tty_do_stop(struct tty_struct *tty)
{
struct vc_struct *vc;
vc = downcast(struct vc_struct, tty, tty);
vc->lockstate |= SCROLL_LOCK;
vc->vptr->do_stopped_changed(vc);
}
void vc_tty_do_start(struct tty_struct *tty)
{
struct vc_struct *vc;
vc = downcast(struct vc_struct, tty, tty);
vc->lockstate &= ~SCROLL_LOCK;
vc->vptr->do_stopped_changed(vc);
}
int vc_tty_do_ioctl(struct tty_struct *tty, int request, void *fs_arg)
{
struct vc_struct *vc;
vc = downcast(struct vc_struct, tty, tty);
switch (request) {
case TGETWSZ:
if (!verify_area(fs_arg, sizeof (struct winsize_struct), PF_WRITE))
return -EFAULT;
put_fs_word(vc->vt.driver->get_lines(), (short *)&((struct winsize_struct *)fs_arg)->height);
put_fs_word(vc->vt.driver->get_columns(), (short *)&((struct winsize_struct *)fs_arg)->width);
return 0;
case TGETCT:
if (!verify_area(fs_arg, sizeof (int), PF_WRITE))
return -EFAULT;
put_fs_long(vc->vt.driver->get_cursor_type(), fs_arg);
return 0;
case TSETCT:
if (!verify_area(fs_arg, sizeof (int), PF_READ))
return -EFAULT;
vc->vt.driver->set_cursor_type(get_fs_long(fs_arg));
return 0;
default:
return tty_do_ioctl(&vc->tty, request, fs_arg);
}
}
void vc_init(struct vc_struct *vc, unsigned short line, unsigned short col)
{
unsigned long iflags;
unsigned long oflags;
unsigned long lflags;
unsigned char cc[NCCS];
iflags = ICRNL | IXON;
oflags = OPOST | ONLCR;
lflags = ECHO | ECHOE | ECHOK | ECHOCTL | ECHOKE | ICANON | ISIG;
cc[VINTR] = INTR;
cc[VQUIT] = QUIT;
cc[VERASE] = ERASE;
cc[VKILL] = KILL;
cc[VEOF] = EOF;
cc[VTIME] = TIME;
cc[VMIN] = MIN;
cc[VSTART] = START;
cc[VSTOP] = STOP;
cc[VSUSP] = SUSP;
cc[VEOL] = EOL;
tty_init(&vc->tty, iflags, oflags, lflags, cc, col);
vt_init(&vc->vt, line, col);
vc->lockstate = 0;
}
void vc_history_up(const struct vc_struct *vc)
{
vc->vt.driver->history_scroll(1);
}
void vc_history_down(const struct vc_struct *vc)
{
vc->vt.driver->history_scroll(-1);
}
void vc_history_pgup(const struct vc_struct *vc)
{
vc->vt.driver->history_scroll(vc->vt.driver->get_lines() / 2);
}
void vc_history_pgdn(const struct vc_struct *vc)
{
vc->vt.driver->history_scroll(-(vc->vt.driver->get_lines() / 2));
}
void vc_history_cancel(const struct vc_struct *vc)
{
vc->vt.driver->history_cancel();
}