/* Console virtuelle */
/* Copyright (C) 2008 Emmanuel Varoquaux
This file is part of XOS.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see . */
#include "vc_struct.h"
#include "vt.h"
#include "tty.h"
#include "video_driver.h"
#include "tty_queue.h"
#include
#include
#include
#include
#include
/* valeurs par defaut */
#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
/* Fonctions virtuelles de tty */
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);
}
}
/* Fonctions sur les consoles virtuelles */
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];
/* positionnement des drapeaux aux valeurs par defaut pour une console virtuelle */
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);
/* initialisation de vc->modifiers a la charge du pilote de clavier */
vc->lockstate = 0; /* valeur par defaut */
}
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();
}