2013-04-23 00:42:35 +00:00
|
|
|
/*
|
|
|
|
* BIRD Client - Light variant I/O
|
|
|
|
*
|
|
|
|
* (c) 1999--2004 Martin Mares <mj@ucw.cz>
|
|
|
|
* (c) 2013 Tomas Hlavacek <tomas.hlavacek@nic.cz>
|
|
|
|
*
|
|
|
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <termios.h>
|
2016-05-12 19:29:04 +00:00
|
|
|
#include <errno.h>
|
2013-04-23 00:42:35 +00:00
|
|
|
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <signal.h>
|
|
|
|
|
|
|
|
#include "nest/bird.h"
|
|
|
|
#include "lib/resource.h"
|
|
|
|
#include "lib/string.h"
|
|
|
|
#include "client/client.h"
|
|
|
|
#include "sysdep/unix/unix.h"
|
|
|
|
|
|
|
|
struct termios tty_save;
|
|
|
|
|
|
|
|
void
|
|
|
|
input_start_list(void)
|
|
|
|
{
|
|
|
|
/* Empty in non-ncurses version. */
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
input_stop_list(void)
|
|
|
|
{
|
|
|
|
/* Empty in non-ncurses version. */
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
input_notify(int prompt)
|
|
|
|
{
|
|
|
|
/* No ncurses -> no status to reveal/hide, print prompt manually. */
|
2016-04-15 09:41:08 +00:00
|
|
|
if (!prompt || !interactive)
|
2013-04-23 00:42:35 +00:00
|
|
|
return;
|
|
|
|
|
2016-04-15 09:41:08 +00:00
|
|
|
printf("\rbird> ");
|
2013-04-23 00:42:35 +00:00
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
input_read(void)
|
|
|
|
{
|
2016-04-15 09:41:08 +00:00
|
|
|
simple_input_read();
|
2013-04-23 00:42:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct termios stored_tty;
|
|
|
|
static int more_active = 0;
|
|
|
|
|
|
|
|
void
|
|
|
|
more_begin(void)
|
|
|
|
{
|
|
|
|
static struct termios tty;
|
|
|
|
|
|
|
|
tty = stored_tty;
|
|
|
|
tty.c_lflag &= (~ECHO);
|
|
|
|
tty.c_lflag &= (~ICANON);
|
|
|
|
|
|
|
|
if (tcsetattr (0, TCSANOW, &tty) < 0)
|
2016-05-12 19:29:04 +00:00
|
|
|
DIE("tcsetattr");
|
2013-04-23 00:42:35 +00:00
|
|
|
|
|
|
|
more_active = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
more_end(void)
|
|
|
|
{
|
|
|
|
more_active = 0;
|
|
|
|
|
|
|
|
if (tcsetattr (0, TCSANOW, &stored_tty) < 0)
|
2016-05-12 19:29:04 +00:00
|
|
|
DIE("tcsetattr");
|
2013-04-23 00:42:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-10-14 13:37:04 +00:00
|
|
|
sig_handler(int signal UNUSED)
|
2013-04-23 00:42:35 +00:00
|
|
|
{
|
|
|
|
cleanup();
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
input_init(void)
|
|
|
|
{
|
|
|
|
if (!interactive)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (tcgetattr(0, &stored_tty) < 0)
|
2016-05-12 19:29:04 +00:00
|
|
|
DIE("tcgetattr");
|
2013-04-23 00:42:35 +00:00
|
|
|
|
|
|
|
if (signal(SIGINT, sig_handler) == SIG_IGN)
|
|
|
|
signal(SIGINT, SIG_IGN);
|
|
|
|
if (signal(SIGTERM, sig_handler) == SIG_IGN)
|
|
|
|
signal(SIGTERM, SIG_IGN);
|
|
|
|
|
|
|
|
struct winsize tws;
|
|
|
|
if (ioctl(0, TIOCGWINSZ, &tws) == 0)
|
|
|
|
{
|
|
|
|
term_lns = tws.ws_row;
|
|
|
|
term_cls = tws.ws_col;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cleanup(void)
|
|
|
|
{
|
|
|
|
if (more_active)
|
|
|
|
more_end();
|
|
|
|
}
|