2011-10-15 14:56:47 +04:00
|
|
|
/*
|
|
|
|
Client interface for General purpose Linux console save/restore server
|
|
|
|
|
2007-09-26 14:22:25 +04:00
|
|
|
Copyright (C) 1994, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
|
2011-10-15 14:56:47 +04:00
|
|
|
2006, 2007, 2011
|
|
|
|
The Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
This file is part of the Midnight Commander.
|
2010-04-30 17:31:06 +04:00
|
|
|
|
2011-10-15 14:56:47 +04:00
|
|
|
The Midnight Commander 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.
|
2010-04-30 17:31:06 +04:00
|
|
|
|
2011-10-15 14:56:47 +04:00
|
|
|
The Midnight Commander is distributed in the hope that it will be useful,
|
1998-02-27 07:54:42 +03:00
|
|
|
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
|
2011-10-15 14:56:47 +04:00
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2009-02-05 21:28:18 +03:00
|
|
|
/** \file cons.handler.c
|
2009-02-06 17:46:15 +03:00
|
|
|
* \brief Source: client %interface for General purpose Linux console save/restore server
|
2009-02-05 21:28:18 +03:00
|
|
|
*/
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
#include <config.h>
|
|
|
|
|
2009-02-06 02:30:45 +03:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/wait.h>
|
1998-02-27 07:54:42 +03:00
|
|
|
#include <signal.h>
|
2003-03-05 12:29:31 +03:00
|
|
|
#include <stdio.h>
|
2009-02-06 02:30:45 +03:00
|
|
|
#include <fcntl.h>
|
2005-02-08 12:04:03 +03:00
|
|
|
#include <sys/types.h>
|
2003-02-26 22:14:52 +03:00
|
|
|
#ifdef __FreeBSD__
|
2010-11-09 14:02:28 +03:00
|
|
|
#include <sys/consio.h>
|
|
|
|
#include <sys/ioctl.h>
|
2005-02-08 12:04:03 +03:00
|
|
|
#endif
|
|
|
|
#include <unistd.h>
|
2003-02-26 22:14:52 +03:00
|
|
|
|
2010-01-20 18:11:52 +03:00
|
|
|
#include "lib/global.h"
|
2009-06-03 23:07:06 +04:00
|
|
|
|
2010-01-08 17:47:19 +03:00
|
|
|
#include "lib/tty/tty.h"
|
2010-04-30 17:31:06 +04:00
|
|
|
#include "lib/skin.h" /* tty_set_normal_attrs */
|
2010-01-08 17:47:19 +03:00
|
|
|
#include "lib/tty/win.h"
|
2011-11-09 01:10:51 +04:00
|
|
|
#include "lib/util.h" /* mc_build_filename() */
|
2009-06-03 23:07:06 +04:00
|
|
|
|
2010-01-21 17:20:11 +03:00
|
|
|
#include "consaver/cons.saver.h"
|
2001-06-23 03:29:18 +04:00
|
|
|
|
2010-11-09 14:02:28 +03:00
|
|
|
/*** global variables ****************************************************************************/
|
|
|
|
|
2003-02-27 07:57:58 +03:00
|
|
|
#ifdef __linux__
|
2010-11-09 14:02:28 +03:00
|
|
|
int cons_saver_pid = 1;
|
|
|
|
#endif /* __linux__ */
|
|
|
|
|
|
|
|
/*** file scope macro definitions ****************************************************************/
|
|
|
|
|
|
|
|
#if defined(__FreeBSD__)
|
|
|
|
#define FD_OUT 1
|
|
|
|
#define cursor_to(x, y) \
|
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
printf("\x1B[%d;%df", (y) + 1, (x) + 1); \
|
|
|
|
fflush(stdout); \
|
|
|
|
} while (0)
|
|
|
|
#endif /* __linux__ */
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2010-11-09 14:02:28 +03:00
|
|
|
/*** file scope type declarations ****************************************************************/
|
|
|
|
|
|
|
|
/*** file scope variables ************************************************************************/
|
|
|
|
|
|
|
|
#ifdef __linux__
|
2003-02-26 22:14:52 +03:00
|
|
|
/* The cons saver can't have a pid of 1, used to prevent bunches of
|
|
|
|
* #ifdef linux */
|
2003-02-27 07:57:58 +03:00
|
|
|
static int pipefd1[2] = { -1, -1 };
|
|
|
|
static int pipefd2[2] = { -1, -1 };
|
2010-11-09 14:02:28 +03:00
|
|
|
#elif defined(__FreeBSD__)
|
|
|
|
static struct scrshot screen_shot;
|
|
|
|
static struct vid_info screen_info;
|
|
|
|
#endif /* __linux__ */
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2010-11-09 14:02:28 +03:00
|
|
|
/*** file scope functions ************************************************************************/
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
#ifdef __linux__
|
2003-02-27 07:57:58 +03:00
|
|
|
static void
|
2010-04-30 17:31:06 +04:00
|
|
|
show_console_contents_linux (int starty, unsigned char begin_line, unsigned char end_line)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
unsigned char message = 0;
|
|
|
|
unsigned short bytes = 0;
|
|
|
|
int i;
|
2012-07-18 09:41:00 +04:00
|
|
|
ssize_t ret;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
/* Is tty console? */
|
2011-09-14 02:07:31 +04:00
|
|
|
if (mc_global.tty.console_flag == '\0')
|
2010-04-30 17:31:06 +04:00
|
|
|
return;
|
1998-02-27 07:54:42 +03:00
|
|
|
/* Paranoid: Is the cons.saver still running? */
|
2010-04-30 17:31:06 +04:00
|
|
|
if (cons_saver_pid < 1 || kill (cons_saver_pid, SIGCONT))
|
|
|
|
{
|
|
|
|
cons_saver_pid = 0;
|
2011-02-10 18:02:54 +03:00
|
|
|
mc_global.tty.console_flag = '\0';
|
2010-04-30 17:31:06 +04:00
|
|
|
return;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Send command to the console handler */
|
|
|
|
message = CONSOLE_CONTENTS;
|
2012-07-18 09:41:00 +04:00
|
|
|
ret = write (pipefd1[1], &message, 1);
|
1998-02-27 07:54:42 +03:00
|
|
|
/* Check for outdated cons.saver */
|
2012-07-18 09:41:00 +04:00
|
|
|
ret = read (pipefd2[0], &message, 1);
|
1998-02-27 07:54:42 +03:00
|
|
|
if (message != CONSOLE_CONTENTS)
|
2010-04-30 17:31:06 +04:00
|
|
|
return;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
/* Send the range of lines that we want */
|
2012-07-18 09:41:00 +04:00
|
|
|
ret = write (pipefd1[1], &begin_line, 1);
|
|
|
|
ret = write (pipefd1[1], &end_line, 1);
|
1998-02-27 07:54:42 +03:00
|
|
|
/* Read the corresponding number of bytes */
|
2012-07-18 09:41:00 +04:00
|
|
|
ret = read (pipefd2[0], &bytes, 2);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
/* Read the bytes and output them */
|
2010-04-30 17:31:06 +04:00
|
|
|
for (i = 0; i < bytes; i++)
|
|
|
|
{
|
|
|
|
if ((i % COLS) == 0)
|
|
|
|
tty_gotoyx (starty + (i / COLS), 0);
|
2012-07-18 09:41:00 +04:00
|
|
|
ret = read (pipefd2[0], &message, 1);
|
2010-04-30 17:31:06 +04:00
|
|
|
tty_print_char (message);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
2011-02-10 18:02:54 +03:00
|
|
|
/* Read the value of the mc_global.tty.console_flag */
|
2012-07-18 09:41:00 +04:00
|
|
|
ret = read (pipefd2[0], &message, 1);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
2010-11-09 14:02:28 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2003-02-27 07:57:58 +03:00
|
|
|
static void
|
2011-09-14 02:07:31 +04:00
|
|
|
handle_console_linux (console_action_t action)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
char *tty_name;
|
1998-08-27 00:23:10 +04:00
|
|
|
char *mc_conssaver;
|
1998-02-27 07:54:42 +03:00
|
|
|
int status;
|
|
|
|
|
2010-04-30 17:31:06 +04:00
|
|
|
switch (action)
|
|
|
|
{
|
1998-02-27 07:54:42 +03:00
|
|
|
case CONSOLE_INIT:
|
2010-04-30 17:31:06 +04:00
|
|
|
/* Close old pipe ends in case it is the 2nd time we run cons.saver */
|
|
|
|
status = close (pipefd1[1]);
|
|
|
|
status = close (pipefd2[0]);
|
|
|
|
/* Create two pipes for communication */
|
|
|
|
if (!((pipe (pipefd1) == 0) && ((pipe (pipefd2)) == 0)))
|
|
|
|
{
|
2011-02-10 18:02:54 +03:00
|
|
|
mc_global.tty.console_flag = '\0';
|
2010-04-30 17:31:06 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* Get the console saver running */
|
|
|
|
cons_saver_pid = fork ();
|
|
|
|
if (cons_saver_pid < 0)
|
|
|
|
{
|
|
|
|
/* Cannot fork */
|
|
|
|
/* Delete pipes */
|
|
|
|
status = close (pipefd1[1]);
|
|
|
|
status = close (pipefd1[0]);
|
|
|
|
status = close (pipefd2[1]);
|
|
|
|
status = close (pipefd2[0]);
|
2011-02-10 18:02:54 +03:00
|
|
|
mc_global.tty.console_flag = '\0';
|
2010-04-30 17:31:06 +04:00
|
|
|
}
|
|
|
|
else if (cons_saver_pid > 0)
|
|
|
|
{
|
|
|
|
/* Parent */
|
|
|
|
/* Close the extra pipe ends */
|
|
|
|
status = close (pipefd1[0]);
|
|
|
|
status = close (pipefd2[1]);
|
|
|
|
/* Was the child successful? */
|
2011-02-10 18:02:54 +03:00
|
|
|
status = read (pipefd2[0], &mc_global.tty.console_flag, 1);
|
2011-09-14 02:07:31 +04:00
|
|
|
if (mc_global.tty.console_flag == '\0')
|
2010-04-30 17:31:06 +04:00
|
|
|
{
|
|
|
|
pid_t ret;
|
|
|
|
status = close (pipefd1[1]);
|
|
|
|
status = close (pipefd2[0]);
|
|
|
|
ret = waitpid (cons_saver_pid, &status, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Child */
|
|
|
|
/* Close the extra pipe ends */
|
|
|
|
status = close (pipefd1[1]);
|
|
|
|
status = close (pipefd2[0]);
|
|
|
|
tty_name = ttyname (0);
|
|
|
|
/* Bind the pipe 0 to the standard input */
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (dup2 (pipefd1[0], 0) == -1)
|
|
|
|
break;
|
|
|
|
status = close (pipefd1[0]);
|
|
|
|
/* Bind the pipe 1 to the standard output */
|
|
|
|
if (dup2 (pipefd2[1], 1) == -1)
|
|
|
|
break;
|
|
|
|
|
|
|
|
status = close (pipefd2[1]);
|
|
|
|
/* Bind standard error to /dev/null */
|
|
|
|
status = open ("/dev/null", O_WRONLY);
|
|
|
|
if (dup2 (status, 2) == -1)
|
|
|
|
break;
|
|
|
|
status = close (status);
|
|
|
|
if (tty_name)
|
|
|
|
{
|
|
|
|
/* Exec the console save/restore handler */
|
2011-11-09 01:10:51 +04:00
|
|
|
mc_conssaver = mc_build_filename (SAVERDIR, "cons.saver", NULL);
|
2010-04-30 17:31:06 +04:00
|
|
|
execl (mc_conssaver, "cons.saver", tty_name, (char *) NULL);
|
|
|
|
}
|
|
|
|
/* Console is not a tty or execl() failed */
|
|
|
|
}
|
|
|
|
while (0);
|
2011-02-10 18:02:54 +03:00
|
|
|
mc_global.tty.console_flag = '\0';
|
|
|
|
status = write (1, &mc_global.tty.console_flag, 1);
|
2010-04-30 17:31:06 +04:00
|
|
|
_exit (3);
|
|
|
|
} /* if (cons_saver_pid ...) */
|
|
|
|
break;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
case CONSOLE_DONE:
|
|
|
|
case CONSOLE_SAVE:
|
|
|
|
case CONSOLE_RESTORE:
|
2010-04-30 17:31:06 +04:00
|
|
|
/* Is tty console? */
|
2011-09-14 02:07:31 +04:00
|
|
|
if (mc_global.tty.console_flag == '\0')
|
2010-04-30 17:31:06 +04:00
|
|
|
return;
|
|
|
|
/* Paranoid: Is the cons.saver still running? */
|
|
|
|
if (cons_saver_pid < 1 || kill (cons_saver_pid, SIGCONT))
|
|
|
|
{
|
|
|
|
cons_saver_pid = 0;
|
2011-02-10 18:02:54 +03:00
|
|
|
mc_global.tty.console_flag = '\0';
|
2010-04-30 17:31:06 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* Send command to the console handler */
|
|
|
|
status = write (pipefd1[1], &action, 1);
|
|
|
|
if (action != CONSOLE_DONE)
|
|
|
|
{
|
|
|
|
/* Wait the console handler to do its job */
|
2011-02-10 18:02:54 +03:00
|
|
|
status = read (pipefd2[0], &mc_global.tty.console_flag, 1);
|
2010-04-30 17:31:06 +04:00
|
|
|
}
|
2011-09-14 02:07:31 +04:00
|
|
|
if (action == CONSOLE_DONE || mc_global.tty.console_flag == '\0')
|
2010-04-30 17:31:06 +04:00
|
|
|
{
|
|
|
|
/* We are done -> Let's clean up */
|
2012-07-18 09:41:00 +04:00
|
|
|
pid_t ret;
|
2010-04-30 17:31:06 +04:00
|
|
|
close (pipefd1[1]);
|
|
|
|
close (pipefd2[0]);
|
2012-07-18 09:41:00 +04:00
|
|
|
ret = waitpid (cons_saver_pid, &status, 0);
|
2011-02-10 18:02:54 +03:00
|
|
|
mc_global.tty.console_flag = '\0';
|
2010-04-30 17:31:06 +04:00
|
|
|
}
|
|
|
|
break;
|
2011-09-14 02:07:31 +04:00
|
|
|
default:
|
|
|
|
break;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-02-26 22:14:52 +03:00
|
|
|
#elif defined(__FreeBSD__)
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2010-11-09 14:02:28 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/**
|
2003-02-26 22:14:52 +03:00
|
|
|
* FreeBSD support copyright (C) 2003 Alexander Serkov <serkov@ukrpost.net>.
|
|
|
|
* Support for screenmaps by Max Khon <fjoe@FreeBSD.org>
|
|
|
|
*/
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2003-02-26 22:14:52 +03:00
|
|
|
static void
|
|
|
|
console_init (void)
|
|
|
|
{
|
2011-09-14 02:07:31 +04:00
|
|
|
if (mc_global.tty.console_flag != '\0')
|
2010-04-30 17:31:06 +04:00
|
|
|
return;
|
2003-02-26 22:14:52 +03:00
|
|
|
|
|
|
|
screen_info.size = sizeof (screen_info);
|
|
|
|
if (ioctl (FD_OUT, CONS_GETINFO, &screen_info) == -1)
|
2010-04-30 17:31:06 +04:00
|
|
|
return;
|
2003-02-26 22:14:52 +03:00
|
|
|
|
2003-02-27 07:57:58 +03:00
|
|
|
memset (&screen_shot, 0, sizeof (screen_shot));
|
2003-02-26 22:14:52 +03:00
|
|
|
screen_shot.xsize = screen_info.mv_csz;
|
|
|
|
screen_shot.ysize = screen_info.mv_rsz;
|
2009-12-12 13:54:22 +03:00
|
|
|
screen_shot.buf = g_try_malloc (screen_info.mv_csz * screen_info.mv_rsz * 2);
|
|
|
|
if (screen_shot.buf != NULL)
|
2011-02-10 18:02:54 +03:00
|
|
|
mc_global.tty.console_flag = '\001';
|
2003-02-26 22:14:52 +03:00
|
|
|
}
|
|
|
|
|
2010-11-09 14:02:28 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2003-02-26 22:14:52 +03:00
|
|
|
static void
|
|
|
|
set_attr (unsigned attr)
|
|
|
|
{
|
2003-03-05 12:29:31 +03:00
|
|
|
/*
|
|
|
|
* Convert color indices returned by SCRSHOT (red=4, green=2, blue=1)
|
|
|
|
* to indices for ANSI sequences (red=1, green=2, blue=4).
|
|
|
|
*/
|
|
|
|
static const int color_map[8] = { 0, 4, 2, 6, 1, 5, 3, 7 };
|
2003-02-26 22:14:52 +03:00
|
|
|
int bc, tc;
|
|
|
|
|
|
|
|
tc = attr & 0xF;
|
|
|
|
bc = (attr >> 4) & 0xF;
|
|
|
|
|
2003-03-05 22:38:50 +03:00
|
|
|
printf ("\x1B[%d;%d;3%d;4%dm", (bc & 8) ? 5 : 25, (tc & 8) ? 1 : 22,
|
2010-04-30 17:31:06 +04:00
|
|
|
color_map[tc & 7], color_map[bc & 7]);
|
2003-02-26 22:14:52 +03:00
|
|
|
}
|
|
|
|
|
2010-11-09 14:02:28 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2003-02-26 22:14:52 +03:00
|
|
|
|
|
|
|
static void
|
|
|
|
console_restore (void)
|
|
|
|
{
|
|
|
|
int i, last;
|
|
|
|
|
2011-09-14 02:07:31 +04:00
|
|
|
if (mc_global.tty.console_flag == '\0')
|
2010-04-30 17:31:06 +04:00
|
|
|
return;
|
2003-02-26 22:14:52 +03:00
|
|
|
|
|
|
|
cursor_to (0, 0);
|
|
|
|
|
|
|
|
/* restoring all content up to cursor position */
|
|
|
|
last = screen_info.mv_row * screen_info.mv_csz + screen_info.mv_col;
|
2010-04-30 17:31:06 +04:00
|
|
|
for (i = 0; i < last; ++i)
|
|
|
|
{
|
|
|
|
set_attr ((screen_shot.buf[i] >> 8) & 0xFF);
|
|
|
|
putc (screen_shot.buf[i] & 0xFF, stdout);
|
2003-02-26 22:14:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* restoring cursor color */
|
|
|
|
set_attr ((screen_shot.buf[last] >> 8) & 0xFF);
|
|
|
|
|
|
|
|
fflush (stdout);
|
|
|
|
}
|
|
|
|
|
2010-11-09 14:02:28 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2003-02-26 22:14:52 +03:00
|
|
|
static void
|
|
|
|
console_shutdown (void)
|
|
|
|
{
|
2011-09-14 02:07:31 +04:00
|
|
|
if (mc_global.tty.console_flag == '\0')
|
2010-04-30 17:31:06 +04:00
|
|
|
return;
|
2003-02-26 22:14:52 +03:00
|
|
|
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (screen_shot.buf);
|
2003-02-26 22:14:52 +03:00
|
|
|
|
2011-02-10 18:02:54 +03:00
|
|
|
mc_global.tty.console_flag = '\0';
|
2003-02-26 22:14:52 +03:00
|
|
|
}
|
|
|
|
|
2010-11-09 14:02:28 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2003-02-26 22:14:52 +03:00
|
|
|
static void
|
|
|
|
console_save (void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
scrmap_t map;
|
|
|
|
scrmap_t revmap;
|
|
|
|
|
2011-09-14 02:07:31 +04:00
|
|
|
if (mc_global.tty.console_flag == '\0')
|
2010-04-30 17:31:06 +04:00
|
|
|
return;
|
2003-02-26 22:14:52 +03:00
|
|
|
|
|
|
|
/* screen_info.size is already set in console_init() */
|
2010-04-30 17:31:06 +04:00
|
|
|
if (ioctl (FD_OUT, CONS_GETINFO, &screen_info) == -1)
|
|
|
|
{
|
|
|
|
console_shutdown ();
|
|
|
|
return;
|
2003-02-26 22:14:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* handle console resize */
|
2010-04-30 17:31:06 +04:00
|
|
|
if (screen_info.mv_csz != screen_shot.xsize || screen_info.mv_rsz != screen_shot.ysize)
|
|
|
|
{
|
|
|
|
console_shutdown ();
|
|
|
|
console_init ();
|
2003-02-26 22:14:52 +03:00
|
|
|
}
|
|
|
|
|
2010-04-30 17:31:06 +04:00
|
|
|
if (ioctl (FD_OUT, CONS_SCRSHOT, &screen_shot) == -1)
|
|
|
|
{
|
|
|
|
console_shutdown ();
|
|
|
|
return;
|
2003-02-26 22:14:52 +03:00
|
|
|
}
|
|
|
|
|
2010-04-30 17:31:06 +04:00
|
|
|
if (ioctl (FD_OUT, GIO_SCRNMAP, &map) == -1)
|
|
|
|
{
|
|
|
|
console_shutdown ();
|
|
|
|
return;
|
2003-02-26 22:14:52 +03:00
|
|
|
}
|
|
|
|
|
2010-04-30 17:31:06 +04:00
|
|
|
for (i = 0; i < 256; i++)
|
|
|
|
{
|
|
|
|
char *p = memchr (map.scrmap, i, 256);
|
|
|
|
revmap.scrmap[i] = p ? p - map.scrmap : i;
|
2003-02-26 22:14:52 +03:00
|
|
|
}
|
|
|
|
|
2010-04-30 17:31:06 +04:00
|
|
|
for (i = 0; i < screen_shot.xsize * screen_shot.ysize; i++)
|
|
|
|
{
|
2012-07-06 14:56:29 +04:00
|
|
|
/* *INDENT-OFF* */
|
|
|
|
screen_shot.buf[i] = (screen_shot.buf[i] & 0xff00)
|
|
|
|
| (unsigned char) revmap.scrmap[screen_shot.buf[i] & 0xff];
|
|
|
|
/* *INDENT-ON* */
|
2003-02-26 22:14:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-09 14:02:28 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2003-02-27 07:57:58 +03:00
|
|
|
static void
|
2010-04-30 17:31:06 +04:00
|
|
|
show_console_contents_freebsd (int starty, unsigned char begin_line, unsigned char end_line)
|
2003-02-26 22:14:52 +03:00
|
|
|
{
|
2003-03-05 12:29:31 +03:00
|
|
|
int col, line;
|
|
|
|
char c;
|
2003-02-26 22:14:52 +03:00
|
|
|
|
2011-09-14 02:07:31 +04:00
|
|
|
if (mc_global.tty.console_flag == '\0')
|
2010-04-30 17:31:06 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
for (line = begin_line; line <= end_line; line++)
|
|
|
|
{
|
|
|
|
tty_gotoyx (starty + line - begin_line, 0);
|
|
|
|
for (col = 0; col < min (COLS, screen_info.mv_csz); col++)
|
|
|
|
{
|
|
|
|
c = screen_shot.buf[line * screen_info.mv_csz + col] & 0xFF;
|
|
|
|
tty_print_char (c);
|
|
|
|
}
|
2003-02-26 22:14:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-09 14:02:28 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2003-02-27 07:57:58 +03:00
|
|
|
static void
|
2011-09-14 02:07:31 +04:00
|
|
|
handle_console_freebsd (console_action_t action)
|
2003-02-26 22:14:52 +03:00
|
|
|
{
|
2010-04-30 17:31:06 +04:00
|
|
|
switch (action)
|
|
|
|
{
|
2003-02-26 22:14:52 +03:00
|
|
|
case CONSOLE_INIT:
|
2010-04-30 17:31:06 +04:00
|
|
|
console_init ();
|
|
|
|
break;
|
2003-02-26 22:14:52 +03:00
|
|
|
|
|
|
|
case CONSOLE_DONE:
|
2010-04-30 17:31:06 +04:00
|
|
|
console_shutdown ();
|
|
|
|
break;
|
2003-02-26 22:14:52 +03:00
|
|
|
|
|
|
|
case CONSOLE_SAVE:
|
2010-04-30 17:31:06 +04:00
|
|
|
console_save ();
|
|
|
|
break;
|
2003-02-26 22:14:52 +03:00
|
|
|
|
|
|
|
case CONSOLE_RESTORE:
|
2010-04-30 17:31:06 +04:00
|
|
|
console_restore ();
|
|
|
|
break;
|
2011-09-14 02:07:31 +04:00
|
|
|
default:
|
|
|
|
break;
|
2003-02-26 22:14:52 +03:00
|
|
|
}
|
|
|
|
}
|
2010-04-30 17:31:06 +04:00
|
|
|
#endif /* __FreeBSD__ */
|
2003-02-26 22:14:52 +03:00
|
|
|
|
2010-11-09 14:02:28 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/*** public functions ****************************************************************************/
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2003-02-26 22:14:52 +03:00
|
|
|
void
|
2010-04-30 17:31:06 +04:00
|
|
|
show_console_contents (int starty, unsigned char begin_line, unsigned char end_line)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2009-06-02 08:55:07 +04:00
|
|
|
tty_set_normal_attrs ();
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2010-04-30 17:31:06 +04:00
|
|
|
if (look_for_rxvt_extensions ())
|
|
|
|
{
|
|
|
|
show_rxvt_contents (starty, begin_line, end_line);
|
|
|
|
return;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
2003-02-27 07:57:58 +03:00
|
|
|
#ifdef __linux__
|
|
|
|
show_console_contents_linux (starty, begin_line, end_line);
|
|
|
|
#elif defined (__FreeBSD__)
|
|
|
|
show_console_contents_freebsd (starty, begin_line, end_line);
|
|
|
|
#else
|
2011-02-10 18:02:54 +03:00
|
|
|
mc_global.tty.console_flag = '\0';
|
2003-02-27 07:57:58 +03:00
|
|
|
#endif
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
2010-11-09 14:02:28 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2003-02-26 22:14:52 +03:00
|
|
|
void
|
2011-09-14 02:07:31 +04:00
|
|
|
handle_console (console_action_t action)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2005-02-09 01:33:52 +03:00
|
|
|
(void) action;
|
|
|
|
|
2003-02-27 07:57:58 +03:00
|
|
|
if (look_for_rxvt_extensions ())
|
2010-04-30 17:31:06 +04:00
|
|
|
return;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2003-02-27 07:57:58 +03:00
|
|
|
#ifdef __linux__
|
|
|
|
handle_console_linux (action);
|
|
|
|
#elif defined (__FreeBSD__)
|
|
|
|
handle_console_freebsd (action);
|
|
|
|
#endif
|
|
|
|
}
|
2010-11-09 14:02:28 +03:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|