/*-
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
* Reset the terminal mode bits to a sensible state. Very useful after
* a child program dies in raw mode.
*/
void
reset_mode(void)
{
tcgetattr(STDERR_FILENO, &mode);
/*
* Determine the erase, interrupt, and kill characters from the terminfo
* entry and command line and update their values in 'mode'.
*/
void
set_control_chars(int erasechar, int intrchar, int killchar)
{
int bs_char;
/*
* Set up various conversions in 'mode', including parity, tabs, returns,
* echo, and case, according to the terminfo entry. If the program we're
* running was named with a leading upper-case character, map external
* uppercase to internal lowercase.
*/
void
set_conversions(int usingupper)
{
if (isreset) {
if (reset_1string) {
tputs(reset_1string, 0, outc);
settle = 1;
}
if (reset_2string) {
tputs(reset_2string, 0, outc);
settle = 1;
}
if ((bp = reset_file) || (bp = init_file)) {
tset_cat(bp);
settle = 1;
}
}
if (settle) {
(void)putc('\r', stderr);
(void)fflush(stderr);
(void)sleep(1); /* Settle the terminal. */
}
}
/*
* Set the hardware tabs on the terminal, using the ct (clear all tabs),
* st (set one tab) and ch (horizontal cursor addressing) capabilities.
* This is done before if and is, so they can patch in case we blow this.
* Return nonzero if we set any tab stops, zero if not.
*/
static int
set_tabs(void)
{
int c;
char *out;
if (set_tab) {
if (clear_all_tabs) {
(void)putc('\r', stderr); /* Force to left margin. */
tputs(clear_all_tabs, 0, outc);
}
for (c = 8; c < ncolumns; c += 8) {
if (column_address)
out = tiparm(column_address, c);
else
out = NULL;
if (out)
tputs(out, 1, outc);
else
(void)fprintf(stderr, "%s", " ");
/* Set the tab. */
tputs(set_tab, 0, outc);
}
putc('\r', stderr);
return (1);
}
return (0);
}