Alien-SVN
view release on metacpan or search on metacpan
src/subversion/subversion/libsvn_subr/prompt.c view on Meta::CPAN
#endif
/* Close terminal handles. */
if (close_handles && terminal->close_handles)
{
apr_file_t *const infd = terminal->infd;
apr_file_t *const outfd = terminal->outfd;
if (infd)
{
terminal->infd = NULL;
status = apr_file_close(infd);
}
if (!status && outfd && outfd != infd)
{
terminal->outfd = NULL;
status = apr_file_close(terminal->outfd);
}
}
return status;
}
/* Normal pool cleanup for a terminal. */
static apr_status_t terminal_plain_cleanup(void *baton)
{
return terminal_cleanup_handler(baton, FALSE, TRUE);
}
/* Child pool cleanup for a terminal -- does not restore echo state. */
static apr_status_t terminal_child_cleanup(void *baton)
{
return terminal_cleanup_handler(baton, FALSE, FALSE);
}
/* Explicitly close the terminal, removing its cleanup handlers. */
static svn_error_t *
terminal_close(terminal_handle_t *terminal)
{
apr_status_t status;
/* apr_pool_cleanup_kill() removes both normal and child cleanup */
apr_pool_cleanup_kill(terminal->pool, terminal, terminal_plain_cleanup);
status = terminal_cleanup_handler(terminal, TRUE, TRUE);
if (status)
return svn_error_create(status, NULL, _("Can't close terminal"));
return SVN_NO_ERROR;
}
/* Allocate and open *TERMINAL. If NOECHO is TRUE, try to turn off
terminal echo. Use POOL for all allocations.*/
static svn_error_t *
terminal_open(terminal_handle_t **terminal, svn_boolean_t noecho,
apr_pool_t *pool)
{
apr_status_t status;
#ifdef WIN32
/* On Windows, we'll use the console API directly if the process has
a console attached; otherwise we'll just use stdin and stderr. */
const HANDLE conin = CreateFileW(L"CONIN$", GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, NULL);
*terminal = apr_palloc(pool, sizeof(terminal_handle_t));
if (conin != INVALID_HANDLE_VALUE)
{
/* The process has a console. */
CloseHandle(conin);
terminal_handle_init(*terminal, NULL, NULL, noecho, FALSE, NULL);
return SVN_NO_ERROR;
}
#else /* !WIN32 */
/* Without evidence to the contrary, we'll assume this is *nix and
try to open /dev/tty. If that fails, we'll use stdin for input
and stderr for prompting. */
apr_file_t *tmpfd;
status = apr_file_open(&tmpfd, "/dev/tty",
APR_READ | APR_WRITE,
APR_OS_DEFAULT, pool);
*terminal = apr_palloc(pool, sizeof(terminal_handle_t));
if (!status)
{
/* We have a terminal handle that we can use for input and output. */
terminal_handle_init(*terminal, tmpfd, tmpfd, FALSE, TRUE, pool);
}
#endif /* !WIN32 */
else
{
/* There is no terminal. Sigh. */
apr_file_t *infd;
apr_file_t *outfd;
status = apr_file_open_stdin(&infd, pool);
if (status)
return svn_error_wrap_apr(status, _("Can't open stdin"));
status = apr_file_open_stderr(&outfd, pool);
if (status)
return svn_error_wrap_apr(status, _("Can't open stderr"));
terminal_handle_init(*terminal, infd, outfd, FALSE, FALSE, pool);
}
#ifdef HAVE_TERMIOS_H
/* Set terminal state */
if (0 == apr_os_file_get(&(*terminal)->osinfd, (*terminal)->infd))
{
if (0 == tcgetattr((*terminal)->osinfd, &(*terminal)->attr))
{
struct termios attr = (*terminal)->attr;
/* Turn off signal handling and canonical input mode */
attr.c_lflag &= ~(ISIG | ICANON);
attr.c_cc[VMIN] = 1; /* Read one byte at a time */
attr.c_cc[VTIME] = 0; /* No timeout, wait indefinitely */
attr.c_lflag &= ~(ECHO); /* Turn off echo */
if (0 == tcsetattr((*terminal)->osinfd, TCSAFLUSH, &attr))
{
(*terminal)->noecho = noecho;
(*terminal)->restore_state = TRUE;
}
}
( run in 0.676 second using v1.01-cache-2.11-cpan-e1769b4cff6 )