2012-02-05 11:35:58 -05:00
|
|
|
/****************************************************************
|
|
|
|
* *
|
2012-03-24 14:06:46 -04:00
|
|
|
* Copyright 2001, 2012 Fidelity Information Services, Inc *
|
2012-02-05 11:35:58 -05:00
|
|
|
* *
|
|
|
|
* This source code contains the intellectual property *
|
|
|
|
* of its copyright holder(s), and is made available *
|
|
|
|
* under a license. If you do not know the terms of *
|
|
|
|
* the license, please stop and do not read further. *
|
|
|
|
* *
|
|
|
|
****************************************************************/
|
|
|
|
|
|
|
|
#include "mdef.h"
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include "gtm_stdio.h"
|
|
|
|
#include "gtm_unistd.h"
|
2012-03-24 14:06:46 -04:00
|
|
|
#include "gtm_termios.h"
|
|
|
|
|
2012-02-05 11:35:58 -05:00
|
|
|
#include "eintr_wrappers.h"
|
|
|
|
#include "mu_term_setup.h"
|
|
|
|
|
|
|
|
#define STDIN_FILENO 0
|
|
|
|
#define STDOUT_FILENO 1
|
|
|
|
#define STDERR_FILENO 2
|
|
|
|
|
|
|
|
static struct termios term_in;
|
|
|
|
static struct termios term_out;
|
|
|
|
static struct termios term_err;
|
|
|
|
|
|
|
|
static boolean_t get_stdin_charc_pass = TRUE;
|
|
|
|
static boolean_t get_stdout_charc_pass = TRUE;
|
|
|
|
static boolean_t get_stderr_charc_pass = TRUE;
|
|
|
|
|
|
|
|
void mu_get_term_characterstics(void)
|
|
|
|
{
|
|
|
|
if ((get_stdin_charc_pass = isatty(STDIN_FILENO)) && (tcgetattr(STDIN_FILENO, &term_in) == -1))
|
|
|
|
{
|
|
|
|
get_stdin_charc_pass = FALSE;
|
|
|
|
PERROR("tcgetattr :");
|
|
|
|
FPRINTF(stderr, "Unable to get terminal characterstics for standard in\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((get_stdout_charc_pass = isatty(STDOUT_FILENO)) && (tcgetattr(STDOUT_FILENO, &term_out) == -1))
|
|
|
|
{
|
|
|
|
get_stdout_charc_pass = FALSE;
|
|
|
|
PERROR("tcgetattr :");
|
|
|
|
FPRINTF(stderr, "Unable to get terminal characterstics for standard out\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((get_stderr_charc_pass = isatty(STDERR_FILENO)) && (tcgetattr(STDERR_FILENO, &term_err) == -1))
|
|
|
|
{
|
|
|
|
get_stderr_charc_pass = FALSE;
|
|
|
|
PERROR("tcgetattr :");
|
|
|
|
FPRINTF(stderr, "Unable to get terminal characterstics for standard err\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void mu_reset_term_characterstics(void)
|
|
|
|
{
|
|
|
|
int tcsetattr_res;
|
|
|
|
|
2012-03-24 14:06:46 -04:00
|
|
|
/* Do not use TCSAFLUSH as it drains all buffered (but yet unprocessed) input in the terminal
|
|
|
|
* even if that was for the next command at the shell prompt. TCSANOW seems to do what we want
|
|
|
|
* (which is to reset terminal characteristics right away).
|
|
|
|
*/
|
|
|
|
Tcsetattr(STDIN_FILENO, TCSANOW, &term_in, tcsetattr_res);
|
2012-02-05 11:35:58 -05:00
|
|
|
if (get_stdin_charc_pass && (-1 == tcsetattr_res))
|
|
|
|
{
|
|
|
|
PERROR("tcsetattr :");
|
|
|
|
FPRINTF(stderr, "Unable to set terminal characterstics for standard in\n");
|
|
|
|
}
|
|
|
|
|
2012-03-24 14:06:46 -04:00
|
|
|
Tcsetattr(STDOUT_FILENO, TCSANOW, &term_out, tcsetattr_res);
|
2012-02-05 11:35:58 -05:00
|
|
|
if (get_stdout_charc_pass && (-1 == tcsetattr_res))
|
|
|
|
{
|
|
|
|
PERROR("tcsetattr :");
|
|
|
|
FPRINTF(stderr, "Unable to set terminal characterstics for standard out\n");
|
|
|
|
}
|
|
|
|
|
2012-03-24 14:06:46 -04:00
|
|
|
Tcsetattr(STDERR_FILENO, TCSANOW, &term_err, tcsetattr_res);
|
2012-02-05 11:35:58 -05:00
|
|
|
if (get_stderr_charc_pass && (-1 == tcsetattr_res))
|
|
|
|
{
|
|
|
|
PERROR("tcsetattr :");
|
|
|
|
FPRINTF(stderr, "Unable to set terminal characterstics for standard err\n");
|
|
|
|
}
|
|
|
|
}
|