110dd2532Schristos /*
210dd2532Schristos * Copyright (c) 1984 through 2008, William LeFebvre
310dd2532Schristos * All rights reserved.
410dd2532Schristos *
510dd2532Schristos * Redistribution and use in source and binary forms, with or without
610dd2532Schristos * modification, are permitted provided that the following conditions are met:
710dd2532Schristos *
810dd2532Schristos * * Redistributions of source code must retain the above copyright
910dd2532Schristos * notice, this list of conditions and the following disclaimer.
1010dd2532Schristos *
1110dd2532Schristos * * Redistributions in binary form must reproduce the above
1210dd2532Schristos * copyright notice, this list of conditions and the following disclaimer
1310dd2532Schristos * in the documentation and/or other materials provided with the
1410dd2532Schristos * distribution.
1510dd2532Schristos *
1610dd2532Schristos * * Neither the name of William LeFebvre nor the names of other
1710dd2532Schristos * contributors may be used to endorse or promote products derived from
1810dd2532Schristos * this software without specific prior written permission.
1910dd2532Schristos *
2010dd2532Schristos * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2110dd2532Schristos * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2210dd2532Schristos * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2310dd2532Schristos * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2410dd2532Schristos * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2510dd2532Schristos * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2610dd2532Schristos * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2710dd2532Schristos * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2810dd2532Schristos * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2910dd2532Schristos * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3010dd2532Schristos * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3110dd2532Schristos */
3210dd2532Schristos
3310dd2532Schristos /*
3410dd2532Schristos * Top users/processes display for Unix
3510dd2532Schristos * Version 3
3610dd2532Schristos */
3710dd2532Schristos
3810dd2532Schristos /* This file contains the routines that interface to termcap and stty/gtty.
3910dd2532Schristos *
4010dd2532Schristos * Paul Vixie, February 1987: converted to use ioctl() instead of stty/gtty.
4110dd2532Schristos *
4210dd2532Schristos * I put in code to turn on the TOSTOP bit while top was running, but I
4310dd2532Schristos * didn't really like the results. If you desire it, turn on the
4410dd2532Schristos * preprocessor variable "TOStop". --wnl
4510dd2532Schristos */
4610dd2532Schristos
4710dd2532Schristos #include "os.h"
4810dd2532Schristos #include "top.h"
4910dd2532Schristos
5010dd2532Schristos #if HAVE_CURSES_H && HAVE_TERM_H
5110dd2532Schristos #include <curses.h>
5210dd2532Schristos #include <term.h>
5310dd2532Schristos #else
5410dd2532Schristos #if HAVE_TERMCAP_H
5510dd2532Schristos #include <termcap.h>
5610dd2532Schristos #else
5710dd2532Schristos #if HAVE_CURSES_H
5810dd2532Schristos #include <curses.h>
5910dd2532Schristos #endif
6010dd2532Schristos #endif
6110dd2532Schristos #endif
6210dd2532Schristos
6310dd2532Schristos #if !HAVE_DECL_TPUTS
6410dd2532Schristos int tputs(const char *, int, int (*)(int));
6510dd2532Schristos #endif
6610dd2532Schristos #if !HAVE_DECL_TGOTO
6710dd2532Schristos char *tgoto(const char *, int, int);
6810dd2532Schristos #endif
6910dd2532Schristos #if !HAVE_DECL_TGETENT
7010dd2532Schristos int tgetent(const char *, char *);
7110dd2532Schristos #endif
7210dd2532Schristos #if !HAVE_DECL_TGETFLAG
7310dd2532Schristos int tgetflag(const char *);
7410dd2532Schristos #endif
7510dd2532Schristos #if !HAVE_DECL_TGETNUM
7610dd2532Schristos int tgetnum(const char *);
7710dd2532Schristos #endif
7810dd2532Schristos #if !HAVE_DECL_TGETSTR
7910dd2532Schristos char *tgetstr(const char *, char **);
8010dd2532Schristos #endif
8110dd2532Schristos
8210dd2532Schristos #include <sys/ioctl.h>
8310dd2532Schristos #ifdef CBREAK
8410dd2532Schristos # include <sgtty.h>
8510dd2532Schristos # define USE_SGTTY
8610dd2532Schristos #else
8710dd2532Schristos # ifdef TCGETA
8810dd2532Schristos # define USE_TERMIO
8910dd2532Schristos # include <termio.h>
9010dd2532Schristos # else
9110dd2532Schristos # define USE_TERMIOS
9210dd2532Schristos # include <termios.h>
9310dd2532Schristos # endif
9410dd2532Schristos #endif
9510dd2532Schristos #if defined(USE_TERMIO) || defined(USE_TERMIOS)
9610dd2532Schristos # ifndef TAB3
9710dd2532Schristos # ifdef OXTABS
9810dd2532Schristos # define TAB3 OXTABS
9910dd2532Schristos # else
10010dd2532Schristos # define TAB3 0
10110dd2532Schristos # endif
10210dd2532Schristos # endif
10310dd2532Schristos #endif
10410dd2532Schristos
10510dd2532Schristos #include "screen.h"
10610dd2532Schristos #include "boolean.h"
10710dd2532Schristos
1085a8a518eSgmcgarry #define putcap(str) ((str) != NULL ? (void)tputs(str, 1, putstdout) : (void)0)
10910dd2532Schristos
11010dd2532Schristos extern char *myname;
11110dd2532Schristos
11210dd2532Schristos char ch_erase;
11310dd2532Schristos char ch_kill;
11410dd2532Schristos char ch_werase;
11510dd2532Schristos char smart_terminal;
11610dd2532Schristos int screen_length;
11710dd2532Schristos int screen_width;
11810dd2532Schristos
11910dd2532Schristos char PC;
12010dd2532Schristos
12110dd2532Schristos static int tc_overstrike;
12210dd2532Schristos static char termcap_buf[1024];
12310dd2532Schristos static char string_buffer[1024];
12410dd2532Schristos static char home[15];
12510dd2532Schristos static char lower_left[15];
12610dd2532Schristos static char *tc_clear_line;
12710dd2532Schristos static char *tc_clear_screen;
12810dd2532Schristos static char *tc_clear_to_end;
12910dd2532Schristos static char *tc_cursor_motion;
13010dd2532Schristos static char *tc_start_standout;
13110dd2532Schristos static char *tc_end_standout;
13210dd2532Schristos static char *terminal_init;
13310dd2532Schristos static char *terminal_end;
13410dd2532Schristos
13510dd2532Schristos #ifdef USE_SGTTY
13610dd2532Schristos static struct sgttyb old_settings;
13710dd2532Schristos static struct sgttyb new_settings;
13810dd2532Schristos #endif
13910dd2532Schristos #ifdef USE_TERMIO
14010dd2532Schristos static struct termio old_settings;
14110dd2532Schristos static struct termio new_settings;
14210dd2532Schristos #endif
14310dd2532Schristos #ifdef USE_TERMIOS
14410dd2532Schristos static struct termios old_settings;
14510dd2532Schristos static struct termios new_settings;
14610dd2532Schristos #endif
14710dd2532Schristos static char is_a_terminal = No;
14810dd2532Schristos #ifdef TOStop
14910dd2532Schristos static int old_lword;
15010dd2532Schristos static int new_lword;
15110dd2532Schristos #endif
15210dd2532Schristos
15310dd2532Schristos #define STDIN 0
15410dd2532Schristos #define STDOUT 1
15510dd2532Schristos #define STDERR 2
15610dd2532Schristos
15710dd2532Schristos /* This has to be defined as a subroutine for tputs (instead of a macro) */
15810dd2532Schristos
15910dd2532Schristos static int
putstdout(TPUTS_PUTC_ARGTYPE ch)16010dd2532Schristos putstdout(TPUTS_PUTC_ARGTYPE ch)
16110dd2532Schristos
16210dd2532Schristos {
16310dd2532Schristos return putchar((int)ch);
16410dd2532Schristos }
16510dd2532Schristos
16610dd2532Schristos void
screen_getsize()16710dd2532Schristos screen_getsize()
16810dd2532Schristos
16910dd2532Schristos {
170cc349219Schristos char *go;
17110dd2532Schristos #ifdef TIOCGWINSZ
17210dd2532Schristos
17310dd2532Schristos struct winsize ws;
17410dd2532Schristos
17510dd2532Schristos if (ioctl (1, TIOCGWINSZ, &ws) != -1)
17610dd2532Schristos {
17710dd2532Schristos if (ws.ws_row != 0)
17810dd2532Schristos {
17910dd2532Schristos screen_length = ws.ws_row;
18010dd2532Schristos }
18110dd2532Schristos if (ws.ws_col != 0)
18210dd2532Schristos {
18310dd2532Schristos screen_width = ws.ws_col - 1;
18410dd2532Schristos }
18510dd2532Schristos }
18610dd2532Schristos
18710dd2532Schristos #else
18810dd2532Schristos #ifdef TIOCGSIZE
18910dd2532Schristos
19010dd2532Schristos struct ttysize ts;
19110dd2532Schristos
19210dd2532Schristos if (ioctl (1, TIOCGSIZE, &ts) != -1)
19310dd2532Schristos {
19410dd2532Schristos if (ts.ts_lines != 0)
19510dd2532Schristos {
19610dd2532Schristos screen_length = ts.ts_lines;
19710dd2532Schristos }
19810dd2532Schristos if (ts.ts_cols != 0)
19910dd2532Schristos {
20010dd2532Schristos screen_width = ts.ts_cols - 1;
20110dd2532Schristos }
20210dd2532Schristos }
20310dd2532Schristos
20410dd2532Schristos #endif /* TIOCGSIZE */
20510dd2532Schristos #endif /* TIOCGWINSZ */
20610dd2532Schristos
207cc349219Schristos if ((go = tgoto(tc_cursor_motion, 0, screen_length - 1)) != NULL)
208cc349219Schristos (void) strcpy(lower_left, go);
209cc349219Schristos else
210cc349219Schristos lower_left[0] = '\0';
21110dd2532Schristos }
21210dd2532Schristos
21310dd2532Schristos int
screen_readtermcap(int interactive)21410dd2532Schristos screen_readtermcap(int interactive)
21510dd2532Schristos
21610dd2532Schristos {
21710dd2532Schristos char *bufptr;
21810dd2532Schristos char *PCptr;
21910dd2532Schristos char *term_name;
220cc349219Schristos char *go;
22110dd2532Schristos int status;
22210dd2532Schristos
22310dd2532Schristos /* set defaults in case we aren't smart */
22410dd2532Schristos screen_width = MAX_COLS;
22510dd2532Schristos screen_length = 0;
22610dd2532Schristos
22710dd2532Schristos if (interactive == No)
22810dd2532Schristos {
22910dd2532Schristos /* pretend we have a dumb terminal */
23010dd2532Schristos smart_terminal = No;
23110dd2532Schristos return No;
23210dd2532Schristos }
23310dd2532Schristos
23410dd2532Schristos /* assume we have a smart terminal until proven otherwise */
23510dd2532Schristos smart_terminal = Yes;
23610dd2532Schristos
23710dd2532Schristos /* get the terminal name */
23810dd2532Schristos term_name = getenv("TERM");
23910dd2532Schristos
24010dd2532Schristos /* if there is no TERM, assume it's a dumb terminal */
24110dd2532Schristos /* patch courtesy of Sam Horrocks at telegraph.ics.uci.edu */
24210dd2532Schristos if (term_name == NULL)
24310dd2532Schristos {
24410dd2532Schristos smart_terminal = No;
24510dd2532Schristos return No;
24610dd2532Schristos }
24710dd2532Schristos
24810dd2532Schristos /* now get the termcap entry */
24910dd2532Schristos if ((status = tgetent(termcap_buf, term_name)) != 1)
25010dd2532Schristos {
25110dd2532Schristos if (status == -1)
25210dd2532Schristos {
25310dd2532Schristos fprintf(stderr, "%s: can't open termcap file\n", myname);
25410dd2532Schristos }
25510dd2532Schristos else
25610dd2532Schristos {
25710dd2532Schristos fprintf(stderr, "%s: no termcap entry for a `%s' terminal\n",
25810dd2532Schristos myname, term_name);
25910dd2532Schristos }
26010dd2532Schristos
26110dd2532Schristos /* pretend it's dumb and proceed */
26210dd2532Schristos smart_terminal = No;
26310dd2532Schristos return No;
26410dd2532Schristos }
26510dd2532Schristos
26610dd2532Schristos /* "hardcopy" immediately indicates a very stupid terminal */
26710dd2532Schristos if (tgetflag("hc"))
26810dd2532Schristos {
26910dd2532Schristos smart_terminal = No;
27010dd2532Schristos return No;
27110dd2532Schristos }
27210dd2532Schristos
27310dd2532Schristos /* set up common terminal capabilities */
27410dd2532Schristos if ((screen_length = tgetnum("li")) <= 0)
27510dd2532Schristos {
276*af358e55Sroy screen_length = 0;
27710dd2532Schristos }
27810dd2532Schristos
27910dd2532Schristos /* screen_width is a little different */
28010dd2532Schristos if ((screen_width = tgetnum("co")) == -1)
28110dd2532Schristos {
28210dd2532Schristos screen_width = 79;
28310dd2532Schristos }
28410dd2532Schristos else
28510dd2532Schristos {
28610dd2532Schristos screen_width -= 1;
28710dd2532Schristos }
28810dd2532Schristos
28910dd2532Schristos /* terminals that overstrike need special attention */
29010dd2532Schristos tc_overstrike = tgetflag("os");
29110dd2532Schristos
29210dd2532Schristos /* initialize the pointer into the termcap string buffer */
29310dd2532Schristos bufptr = string_buffer;
29410dd2532Schristos
29510dd2532Schristos /* get "ce", clear to end */
29610dd2532Schristos if (!tc_overstrike)
29710dd2532Schristos {
29810dd2532Schristos tc_clear_line = tgetstr("ce", &bufptr);
29910dd2532Schristos }
30010dd2532Schristos
30110dd2532Schristos /* get necessary capabilities */
30210dd2532Schristos if ((tc_clear_screen = tgetstr("cl", &bufptr)) == NULL ||
30310dd2532Schristos (tc_cursor_motion = tgetstr("cm", &bufptr)) == NULL)
30410dd2532Schristos {
30510dd2532Schristos smart_terminal = No;
30610dd2532Schristos return No;
30710dd2532Schristos }
30810dd2532Schristos
30910dd2532Schristos /* get some more sophisticated stuff -- these are optional */
31010dd2532Schristos tc_clear_to_end = tgetstr("cd", &bufptr);
31110dd2532Schristos terminal_init = tgetstr("ti", &bufptr);
31210dd2532Schristos terminal_end = tgetstr("te", &bufptr);
31310dd2532Schristos tc_start_standout = tgetstr("so", &bufptr);
31410dd2532Schristos tc_end_standout = tgetstr("se", &bufptr);
31510dd2532Schristos
31610dd2532Schristos /* pad character */
31710dd2532Schristos PC = (PCptr = tgetstr("pc", &bufptr)) ? *PCptr : 0;
31810dd2532Schristos
31910dd2532Schristos /* set convenience strings */
320cc349219Schristos if ((go = tgoto(tc_cursor_motion, 0, 0)) != NULL)
321cc349219Schristos (void) strcpy(home, go);
322cc349219Schristos else
323cc349219Schristos home[0] = '\0';
32410dd2532Schristos /* (lower_left is set in screen_getsize) */
32510dd2532Schristos
32610dd2532Schristos /* get the actual screen size with an ioctl, if needed */
32710dd2532Schristos /* This may change screen_width and screen_length, and it always
32810dd2532Schristos sets lower_left. */
32910dd2532Schristos screen_getsize();
33010dd2532Schristos
331*af358e55Sroy /* If screen_length is 0 from both termcap and ioctl then we are dumb */
332*af358e55Sroy if (screen_length == 0)
333*af358e55Sroy {
334*af358e55Sroy smart_terminal = No;
335*af358e55Sroy return No;
336*af358e55Sroy }
337*af358e55Sroy
33810dd2532Schristos /* if stdout is not a terminal, pretend we are a dumb terminal */
33910dd2532Schristos #ifdef USE_SGTTY
34010dd2532Schristos if (ioctl(STDOUT, TIOCGETP, &old_settings) == -1)
34110dd2532Schristos {
34210dd2532Schristos smart_terminal = No;
34310dd2532Schristos }
34410dd2532Schristos #endif
34510dd2532Schristos #ifdef USE_TERMIO
34610dd2532Schristos if (ioctl(STDOUT, TCGETA, &old_settings) == -1)
34710dd2532Schristos {
34810dd2532Schristos smart_terminal = No;
34910dd2532Schristos }
35010dd2532Schristos #endif
35110dd2532Schristos #ifdef USE_TERMIOS
35210dd2532Schristos if (tcgetattr(STDOUT, &old_settings) == -1)
35310dd2532Schristos {
35410dd2532Schristos smart_terminal = No;
35510dd2532Schristos }
35610dd2532Schristos #endif
35710dd2532Schristos
35810dd2532Schristos return smart_terminal;
35910dd2532Schristos }
36010dd2532Schristos
36110dd2532Schristos void
screen_init()36210dd2532Schristos screen_init()
36310dd2532Schristos
36410dd2532Schristos {
36510dd2532Schristos /* get the old settings for safe keeping */
36610dd2532Schristos #ifdef USE_SGTTY
36710dd2532Schristos if (ioctl(STDOUT, TIOCGETP, &old_settings) != -1)
36810dd2532Schristos {
36910dd2532Schristos /* copy the settings so we can modify them */
37010dd2532Schristos new_settings = old_settings;
37110dd2532Schristos
37210dd2532Schristos /* turn on CBREAK and turn off character echo and tab expansion */
37310dd2532Schristos new_settings.sg_flags |= CBREAK;
37410dd2532Schristos new_settings.sg_flags &= ~(ECHO|XTABS);
37510dd2532Schristos (void) ioctl(STDOUT, TIOCSETP, &new_settings);
37610dd2532Schristos
37710dd2532Schristos /* remember the erase and kill characters */
37810dd2532Schristos ch_erase = old_settings.sg_erase;
37910dd2532Schristos ch_kill = old_settings.sg_kill;
38010dd2532Schristos ch_werase = old_settings.sg_werase;
38110dd2532Schristos
38210dd2532Schristos #ifdef TOStop
38310dd2532Schristos /* get the local mode word */
38410dd2532Schristos (void) ioctl(STDOUT, TIOCLGET, &old_lword);
38510dd2532Schristos
38610dd2532Schristos /* modify it */
38710dd2532Schristos new_lword = old_lword | LTOSTOP;
38810dd2532Schristos (void) ioctl(STDOUT, TIOCLSET, &new_lword);
38910dd2532Schristos #endif
39010dd2532Schristos /* remember that it really is a terminal */
39110dd2532Schristos is_a_terminal = Yes;
39210dd2532Schristos
39310dd2532Schristos /* send the termcap initialization string */
39410dd2532Schristos putcap(terminal_init);
39510dd2532Schristos }
39610dd2532Schristos #endif
39710dd2532Schristos #ifdef USE_TERMIO
39810dd2532Schristos if (ioctl(STDOUT, TCGETA, &old_settings) != -1)
39910dd2532Schristos {
40010dd2532Schristos /* copy the settings so we can modify them */
40110dd2532Schristos new_settings = old_settings;
40210dd2532Schristos
40310dd2532Schristos /* turn off ICANON, character echo and tab expansion */
40410dd2532Schristos new_settings.c_lflag &= ~(ICANON|ECHO);
40510dd2532Schristos new_settings.c_oflag &= ~(TAB3);
40610dd2532Schristos new_settings.c_cc[VMIN] = 1;
40710dd2532Schristos new_settings.c_cc[VTIME] = 0;
40810dd2532Schristos (void) ioctl(STDOUT, TCSETA, &new_settings);
40910dd2532Schristos
41010dd2532Schristos /* remember the erase and kill characters */
41110dd2532Schristos ch_erase = old_settings.c_cc[VERASE];
41210dd2532Schristos ch_kill = old_settings.c_cc[VKILL];
41310dd2532Schristos ch_werase = old_settings.c_cc[VWERASE];
41410dd2532Schristos
41510dd2532Schristos /* remember that it really is a terminal */
41610dd2532Schristos is_a_terminal = Yes;
41710dd2532Schristos
41810dd2532Schristos /* send the termcap initialization string */
41910dd2532Schristos putcap(terminal_init);
42010dd2532Schristos }
42110dd2532Schristos #endif
42210dd2532Schristos #ifdef USE_TERMIOS
42310dd2532Schristos if (tcgetattr(STDOUT, &old_settings) != -1)
42410dd2532Schristos {
42510dd2532Schristos /* copy the settings so we can modify them */
42610dd2532Schristos new_settings = old_settings;
42710dd2532Schristos
42810dd2532Schristos /* turn off ICANON, character echo and tab expansion */
42910dd2532Schristos new_settings.c_lflag &= ~(ICANON|ECHO);
43010dd2532Schristos new_settings.c_oflag &= ~(TAB3);
43110dd2532Schristos new_settings.c_cc[VMIN] = 1;
43210dd2532Schristos new_settings.c_cc[VTIME] = 0;
43310dd2532Schristos (void) tcsetattr(STDOUT, TCSADRAIN, &new_settings);
43410dd2532Schristos
43510dd2532Schristos /* remember the erase and kill characters */
43610dd2532Schristos ch_erase = old_settings.c_cc[VERASE];
43710dd2532Schristos ch_kill = old_settings.c_cc[VKILL];
43810dd2532Schristos ch_werase = old_settings.c_cc[VWERASE];
43910dd2532Schristos
44010dd2532Schristos /* remember that it really is a terminal */
44110dd2532Schristos is_a_terminal = Yes;
44210dd2532Schristos
44310dd2532Schristos /* send the termcap initialization string */
44410dd2532Schristos putcap(terminal_init);
44510dd2532Schristos }
44610dd2532Schristos #endif
44710dd2532Schristos
44810dd2532Schristos if (!is_a_terminal)
44910dd2532Schristos {
45010dd2532Schristos /* not a terminal at all---consider it dumb */
45110dd2532Schristos smart_terminal = No;
45210dd2532Schristos }
45310dd2532Schristos }
45410dd2532Schristos
45510dd2532Schristos void
screen_end()45610dd2532Schristos screen_end()
45710dd2532Schristos
45810dd2532Schristos {
45910dd2532Schristos /* move to the lower left, clear the line and send "te" */
46010dd2532Schristos if (smart_terminal)
46110dd2532Schristos {
46210dd2532Schristos putcap(lower_left);
46310dd2532Schristos putcap(tc_clear_line);
46410dd2532Schristos fflush(stdout);
46510dd2532Schristos putcap(terminal_end);
46610dd2532Schristos }
46710dd2532Schristos
46810dd2532Schristos /* if we have settings to reset, then do so */
46910dd2532Schristos if (is_a_terminal)
47010dd2532Schristos {
47110dd2532Schristos #ifdef USE_SGTTY
47210dd2532Schristos (void) ioctl(STDOUT, TIOCSETP, &old_settings);
47310dd2532Schristos #ifdef TOStop
47410dd2532Schristos (void) ioctl(STDOUT, TIOCLSET, &old_lword);
47510dd2532Schristos #endif
47610dd2532Schristos #endif
47710dd2532Schristos #ifdef USE_TERMIO
47810dd2532Schristos (void) ioctl(STDOUT, TCSETA, &old_settings);
47910dd2532Schristos #endif
48010dd2532Schristos #ifdef USE_TERMIOS
48110dd2532Schristos (void) tcsetattr(STDOUT, TCSADRAIN, &old_settings);
48210dd2532Schristos #endif
48310dd2532Schristos }
48410dd2532Schristos }
48510dd2532Schristos
48610dd2532Schristos void
screen_reinit()48710dd2532Schristos screen_reinit()
48810dd2532Schristos
48910dd2532Schristos {
49010dd2532Schristos /* install our settings if it is a terminal */
49110dd2532Schristos if (is_a_terminal)
49210dd2532Schristos {
49310dd2532Schristos #ifdef USE_SGTTY
49410dd2532Schristos (void) ioctl(STDOUT, TIOCSETP, &new_settings);
49510dd2532Schristos #ifdef TOStop
49610dd2532Schristos (void) ioctl(STDOUT, TIOCLSET, &new_lword);
49710dd2532Schristos #endif
49810dd2532Schristos #endif
49910dd2532Schristos #ifdef USE_TERMIO
50010dd2532Schristos (void) ioctl(STDOUT, TCSETA, &new_settings);
50110dd2532Schristos #endif
50210dd2532Schristos #ifdef USE_TERMIOS
50310dd2532Schristos (void) tcsetattr(STDOUT, TCSADRAIN, &new_settings);
50410dd2532Schristos #endif
50510dd2532Schristos }
50610dd2532Schristos
50710dd2532Schristos /* send init string */
50810dd2532Schristos if (smart_terminal)
50910dd2532Schristos {
51010dd2532Schristos putcap(terminal_init);
51110dd2532Schristos }
51210dd2532Schristos }
51310dd2532Schristos
51410dd2532Schristos void
screen_move(int x,int y)51510dd2532Schristos screen_move(int x, int y)
51610dd2532Schristos
51710dd2532Schristos {
518cc349219Schristos char *go = tgoto(tc_cursor_motion, x, y);
519cc349219Schristos if (go)
520cc349219Schristos tputs(go, 1, putstdout);
52110dd2532Schristos }
52210dd2532Schristos
52310dd2532Schristos void
screen_standout(const char * msg)524213e7ef1Schristos screen_standout(const char *msg)
52510dd2532Schristos
52610dd2532Schristos {
52710dd2532Schristos if (smart_terminal)
52810dd2532Schristos {
52910dd2532Schristos putcap(tc_start_standout);
53010dd2532Schristos fputs(msg, stdout);
53110dd2532Schristos putcap(tc_end_standout);
53210dd2532Schristos }
53310dd2532Schristos else
53410dd2532Schristos {
53510dd2532Schristos fputs(msg, stdout);
53610dd2532Schristos }
53710dd2532Schristos }
53810dd2532Schristos
53910dd2532Schristos void
screen_clear(void)540213e7ef1Schristos screen_clear(void)
54110dd2532Schristos
54210dd2532Schristos {
54310dd2532Schristos if (smart_terminal)
54410dd2532Schristos {
54510dd2532Schristos putcap(tc_clear_screen);
54610dd2532Schristos }
54710dd2532Schristos }
54810dd2532Schristos
54910dd2532Schristos int
screen_cte(void)550213e7ef1Schristos screen_cte(void)
55110dd2532Schristos
55210dd2532Schristos {
55310dd2532Schristos if (smart_terminal)
55410dd2532Schristos {
55510dd2532Schristos if (tc_clear_to_end)
55610dd2532Schristos {
55710dd2532Schristos putcap(tc_clear_to_end);
55810dd2532Schristos return(Yes);
55910dd2532Schristos }
56010dd2532Schristos }
56110dd2532Schristos return(No);
56210dd2532Schristos }
56310dd2532Schristos
56410dd2532Schristos void
screen_cleareol(int len)56510dd2532Schristos screen_cleareol(int len)
56610dd2532Schristos
56710dd2532Schristos {
56810dd2532Schristos int i;
56910dd2532Schristos
57010dd2532Schristos if (smart_terminal && !tc_overstrike && len > 0)
57110dd2532Schristos {
57210dd2532Schristos if (tc_clear_line)
57310dd2532Schristos {
57410dd2532Schristos putcap(tc_clear_line);
57510dd2532Schristos return;
57610dd2532Schristos }
57710dd2532Schristos else
57810dd2532Schristos {
57910dd2532Schristos i = 0;
58010dd2532Schristos while (i++ < 0)
58110dd2532Schristos {
58210dd2532Schristos putchar(' ');
58310dd2532Schristos }
58410dd2532Schristos i = 0;
58510dd2532Schristos while (i++ < 0)
58610dd2532Schristos {
58710dd2532Schristos putchar('\b');
58810dd2532Schristos }
58910dd2532Schristos return;
59010dd2532Schristos }
59110dd2532Schristos }
59210dd2532Schristos return;
59310dd2532Schristos }
59410dd2532Schristos
59510dd2532Schristos void
screen_home(void)596213e7ef1Schristos screen_home(void)
59710dd2532Schristos
59810dd2532Schristos {
59910dd2532Schristos if (smart_terminal)
60010dd2532Schristos {
60110dd2532Schristos putcap(home);
60210dd2532Schristos }
60310dd2532Schristos }
60410dd2532Schristos
60510dd2532Schristos
606